ASTContext.cpp revision 1e905da74dbfd353d77dfc548fc9d6ff420d515a
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" 27bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian#include "clang/AST/Comment.h" 281b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 29a9376d470ccb0eac74fe09a6b2a18a890f1d17c4Chris Lattner#include "clang/Basic/SourceManager.h" 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/TargetInfo.h" 31f5942a44880be26878592eb052b737579349411eBenjamin Kramer#include "llvm/ADT/SmallString.h" 3285f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson#include "llvm/ADT/StringExtras.h" 336fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman#include "llvm/Support/MathExtras.h" 34f5942a44880be26878592eb052b737579349411eBenjamin Kramer#include "llvm/Support/raw_ostream.h" 350c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek#include "llvm/Support/Capacity.h" 36071cc7deffad608165b1ddd5263e8bf181861520Charles Davis#include "CXXABI.h" 372636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis#include <map> 3829445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson 395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 411827403a7138946305c0058f262e02b595cf882fDouglas Gregorunsigned ASTContext::NumImplicitDefaultConstructors; 421827403a7138946305c0058f262e02b595cf882fDouglas Gregorunsigned ASTContext::NumImplicitDefaultConstructorsDeclared; 43225843186e3972ce798d3de00f86da9008b15a0eDouglas Gregorunsigned ASTContext::NumImplicitCopyConstructors; 44225843186e3972ce798d3de00f86da9008b15a0eDouglas Gregorunsigned ASTContext::NumImplicitCopyConstructorsDeclared; 45ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveConstructors; 46ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveConstructorsDeclared; 47a376d10acfacf19d6dfa41069f7929739a18dd7aDouglas Gregorunsigned ASTContext::NumImplicitCopyAssignmentOperators; 48a376d10acfacf19d6dfa41069f7929739a18dd7aDouglas Gregorunsigned ASTContext::NumImplicitCopyAssignmentOperatorsDeclared; 49ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveAssignmentOperators; 50ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveAssignmentOperatorsDeclared; 514923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregorunsigned ASTContext::NumImplicitDestructors; 524923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregorunsigned ASTContext::NumImplicitDestructorsDeclared; 534923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregor 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerenum FloatingRank { 55aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov HalfRank, FloatRank, DoubleRank, LongDoubleRank 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 58a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri GribenkoRawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { 59aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (!CommentsLoaded && ExternalSource) { 60aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko ExternalSource->ReadComments(); 61aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko CommentsLoaded = true; 62aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 63aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 64aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko assert(D); 65aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 66c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko // User can not attach documentation to implicit declarations. 67c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko if (D->isImplicit()) 68c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko return NULL; 69c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko 70c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko // User can not attach documentation to implicit instantiations. 71c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 72c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) 73c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko return NULL; 74c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko } 75c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko 76dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 77dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (VD->isStaticDataMember() && 78dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) 79dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko return NULL; 80dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko } 81dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko 82dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) { 83dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (CRD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) 84dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko return NULL; 85dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko } 86dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko 87dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (const EnumDecl *ED = dyn_cast<EnumDecl>(D)) { 88dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (ED->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) 89dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko return NULL; 90dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko } 91dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko 92aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // TODO: handle comments for function parameters properly. 93aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (isa<ParmVarDecl>(D)) 94aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 95aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 9696b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko // TODO: we could look up template parameter documentation in the template 9796b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko // documentation. 9896b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko if (isa<TemplateTypeParmDecl>(D) || 9996b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko isa<NonTypeTemplateParmDecl>(D) || 10096b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko isa<TemplateTemplateParmDecl>(D)) 10196b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko return NULL; 10296b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko 103811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko ArrayRef<RawComment *> RawComments = Comments.getComments(); 104aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 105aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // If there are no comments anywhere, we won't find anything. 106aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (RawComments.empty()) 107aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 108aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 109abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // Find declaration location. 110abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // For Objective-C declarations we generally don't expect to have multiple 111abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // declarators, thus use declaration starting location as the "declaration 112abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // location". 113abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // For all other declarations multiple declarators are used quite frequently, 114abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // so we use the location of the identifier as the "declaration location". 115abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko SourceLocation DeclLoc; 116abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko if (isa<ObjCMethodDecl>(D) || isa<ObjCContainerDecl>(D) || 11796b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko isa<ObjCPropertyDecl>(D) || 118c27bc80a98b9558513b50956c930eedc9e461ae0Dmitri Gribenko isa<RedeclarableTemplateDecl>(D) || 119c27bc80a98b9558513b50956c930eedc9e461ae0Dmitri Gribenko isa<ClassTemplateSpecializationDecl>(D)) 120abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko DeclLoc = D->getLocStart(); 121abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko else 122abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko DeclLoc = D->getLocation(); 123abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko 124aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // If the declaration doesn't map directly to a location in a file, we 125aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // can't find the comment. 126aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (DeclLoc.isInvalid() || !DeclLoc.isFileID()) 127aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 128aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 129aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Find the comment that occurs just after this declaration. 130a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko ArrayRef<RawComment *>::iterator Comment; 131a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko { 132a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // When searching for comments during parsing, the comment we are looking 133a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // for is usually among the last two comments we parsed -- check them 134a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // first. 135a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko RawComment CommentAtDeclLoc(SourceMgr, SourceRange(DeclLoc)); 136a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko BeforeThanCompare<RawComment> Compare(SourceMgr); 137a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko ArrayRef<RawComment *>::iterator MaybeBeforeDecl = RawComments.end() - 1; 138a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko bool Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc); 139a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko if (!Found && RawComments.size() >= 2) { 140a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko MaybeBeforeDecl--; 141a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc); 142a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } 143a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko 144a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko if (Found) { 145a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko Comment = MaybeBeforeDecl + 1; 146a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko assert(Comment == std::lower_bound(RawComments.begin(), RawComments.end(), 147a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko &CommentAtDeclLoc, Compare)); 148a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } else { 149a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // Slow path. 150a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko Comment = std::lower_bound(RawComments.begin(), RawComments.end(), 151a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko &CommentAtDeclLoc, Compare); 152a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } 153a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } 154aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 155aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Decompose the location for the declaration and find the beginning of the 156aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // file buffer. 157aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko std::pair<FileID, unsigned> DeclLocDecomp = SourceMgr.getDecomposedLoc(DeclLoc); 158aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 159aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // First check whether we have a trailing comment. 160aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (Comment != RawComments.end() && 161811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko (*Comment)->isDocumentation() && (*Comment)->isTrailingComment() && 1629c00676f2393335dc60c61faf944d4f8f622fac6Dmitri Gribenko (isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || isa<VarDecl>(D))) { 163aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko std::pair<FileID, unsigned> CommentBeginDecomp 164811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getBegin()); 165aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Check that Doxygen trailing comment comes after the declaration, starts 166aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // on the same line and in the same file as the declaration. 167aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (DeclLocDecomp.first == CommentBeginDecomp.first && 168aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko SourceMgr.getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second) 169aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko == SourceMgr.getLineNumber(CommentBeginDecomp.first, 170aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko CommentBeginDecomp.second)) { 171811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko return *Comment; 172aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 173aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 174aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 175aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // The comment just after the declaration was not a trailing comment. 176aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Let's look at the previous comment. 177aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (Comment == RawComments.begin()) 178aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 179aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko --Comment; 180aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 181aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Check that we actually have a non-member Doxygen comment. 182811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko if (!(*Comment)->isDocumentation() || (*Comment)->isTrailingComment()) 183aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 184aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 185aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Decompose the end of the comment. 186aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko std::pair<FileID, unsigned> CommentEndDecomp 187811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getEnd()); 188aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 189aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // If the comment and the declaration aren't in the same file, then they 190aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // aren't related. 191aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (DeclLocDecomp.first != CommentEndDecomp.first) 192aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 193aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 194aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Get the corresponding buffer. 195aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko bool Invalid = false; 196aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko const char *Buffer = SourceMgr.getBufferData(DeclLocDecomp.first, 197aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko &Invalid).data(); 198aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (Invalid) 199aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 200aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 201aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Extract text between the comment and declaration. 202aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko StringRef Text(Buffer + CommentEndDecomp.second, 203aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko DeclLocDecomp.second - CommentEndDecomp.second); 204aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 2058bdb58a7835a9a90dd9b9791fccf269cbc1dcef3Dmitri Gribenko // There should be no other declarations or preprocessor directives between 2068bdb58a7835a9a90dd9b9791fccf269cbc1dcef3Dmitri Gribenko // comment and declaration. 207abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko if (Text.find_first_of(",;{}#@") != StringRef::npos) 208aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 209aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 210811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko return *Comment; 211aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko} 212aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 213c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenkonamespace { 214c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko/// If we have a 'templated' declaration for a template, adjust 'D' to 215c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko/// refer to the actual template. 2162125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko/// If we have an implicit instantiation, adjust 'D' to refer to template. 217c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenkoconst Decl *adjustDeclToTemplate(const Decl *D) { 218cd81df2dcff4e13eea6edfbfd52a4458d978d174Douglas Gregor if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 2192125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Is this function declaration part of a function template? 220cd81df2dcff4e13eea6edfbfd52a4458d978d174Douglas Gregor if (const FunctionTemplateDecl *FTD = FD->getDescribedFunctionTemplate()) 2212125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return FTD; 2222125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2232125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Nothing to do if function is not an implicit instantiation. 2242125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (FD->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) 2252125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2262125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2272125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Function is an implicit instantiation of a function template? 2282125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const FunctionTemplateDecl *FTD = FD->getPrimaryTemplate()) 2292125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return FTD; 2302125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2312125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Function is instantiated from a member definition of a class template? 2322125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const FunctionDecl *MemberDecl = 2332125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko FD->getInstantiatedFromMemberFunction()) 2342125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return MemberDecl; 2352125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2362125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2372125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko } 2382125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 2392125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Static data member is instantiated from a member definition of a class 2402125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // template? 2412125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (VD->isStaticDataMember()) 2422125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const VarDecl *MemberDecl = VD->getInstantiatedFromStaticDataMember()) 2432125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return MemberDecl; 2442125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2452125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2462125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko } 2472125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) { 2482125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Is this class declaration part of a class template? 2492125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const ClassTemplateDecl *CTD = CRD->getDescribedClassTemplate()) 2502125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return CTD; 2512125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2522125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Class is an implicit instantiation of a class template or partial 2532125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // specialization? 2542125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const ClassTemplateSpecializationDecl *CTSD = 2552125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko dyn_cast<ClassTemplateSpecializationDecl>(CRD)) { 2562125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (CTSD->getSpecializationKind() != TSK_ImplicitInstantiation) 2572125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2582125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko llvm::PointerUnion<ClassTemplateDecl *, 2592125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko ClassTemplatePartialSpecializationDecl *> 2602125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko PU = CTSD->getSpecializedTemplateOrPartial(); 2612125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return PU.is<ClassTemplateDecl*>() ? 2622125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko static_cast<const Decl*>(PU.get<ClassTemplateDecl *>()) : 2632125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko static_cast<const Decl*>( 2642125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko PU.get<ClassTemplatePartialSpecializationDecl *>()); 2652125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko } 2662125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2672125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Class is instantiated from a member definition of a class template? 2682125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const MemberSpecializationInfo *Info = 2692125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko CRD->getMemberSpecializationInfo()) 2702125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return Info->getInstantiatedFrom(); 2712125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2722125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2732125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko } 2742125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const EnumDecl *ED = dyn_cast<EnumDecl>(D)) { 2752125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Enum is instantiated from a member definition of a class template? 2762125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const EnumDecl *MemberDecl = ED->getInstantiatedFromMemberEnum()) 2772125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return MemberDecl; 2782125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2792125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 280cd81df2dcff4e13eea6edfbfd52a4458d978d174Douglas Gregor } 2812125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // FIXME: Adjust alias templates? 282c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko return D; 283c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko} 284c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko} // unnamed namespace 285c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko 2861599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenkoconst RawComment *ASTContext::getRawCommentForAnyRedecl( 2871599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const Decl *D, 2881599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const Decl **OriginalDecl) const { 289c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko D = adjustDeclToTemplate(D); 290cd81df2dcff4e13eea6edfbfd52a4458d978d174Douglas Gregor 291f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko // Check whether we have cached a comment for this declaration already. 292f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko { 293f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko llvm::DenseMap<const Decl *, RawCommentAndCacheFlags>::iterator Pos = 294f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RedeclComments.find(D); 295f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (Pos != RedeclComments.end()) { 296f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko const RawCommentAndCacheFlags &Raw = Pos->second; 2971599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko if (Raw.getKind() != RawCommentAndCacheFlags::NoCommentInDecl) { 2981599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko if (OriginalDecl) 2991599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko *OriginalDecl = Raw.getOriginalDecl(); 300f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko return Raw.getRaw(); 3011599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko } 302f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 303f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 304f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko 305f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko // Search for comments attached to declarations in the redeclaration chain. 306f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko const RawComment *RC = NULL; 3071599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const Decl *OriginalDeclForRC = NULL; 308f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko for (Decl::redecl_iterator I = D->redecls_begin(), 309f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko E = D->redecls_end(); 310f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko I != E; ++I) { 311f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko llvm::DenseMap<const Decl *, RawCommentAndCacheFlags>::iterator Pos = 312f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RedeclComments.find(*I); 313f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (Pos != RedeclComments.end()) { 314f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko const RawCommentAndCacheFlags &Raw = Pos->second; 315f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (Raw.getKind() != RawCommentAndCacheFlags::NoCommentInDecl) { 316f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RC = Raw.getRaw(); 3171599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko OriginalDeclForRC = Raw.getOriginalDecl(); 318f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko break; 319f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 320f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } else { 321f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RC = getRawCommentForDeclNoCache(*I); 3221599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko OriginalDeclForRC = *I; 323f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RawCommentAndCacheFlags Raw; 324f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (RC) { 325f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setRaw(RC); 326f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setKind(RawCommentAndCacheFlags::FromDecl); 327f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } else 328f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setKind(RawCommentAndCacheFlags::NoCommentInDecl); 3291599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko Raw.setOriginalDecl(*I); 330f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RedeclComments[*I] = Raw; 331f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (RC) 332f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko break; 333f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 3348d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko } 335aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 3368376f5934a18b950ac7323d8a38ed231623010faDmitri Gribenko // If we found a comment, it should be a documentation comment. 3378376f5934a18b950ac7323d8a38ed231623010faDmitri Gribenko assert(!RC || RC->isDocumentation()); 338f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko 3391599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko if (OriginalDecl) 3401599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko *OriginalDecl = OriginalDeclForRC; 3411599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko 342f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko // Update cache for every declaration in the redeclaration chain. 343f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RawCommentAndCacheFlags Raw; 344f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setRaw(RC); 345f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setKind(RawCommentAndCacheFlags::FromRedecl); 3461599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko Raw.setOriginalDecl(OriginalDeclForRC); 347f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko 348f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko for (Decl::redecl_iterator I = D->redecls_begin(), 349f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko E = D->redecls_end(); 350f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko I != E; ++I) { 351f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RawCommentAndCacheFlags &R = RedeclComments[*I]; 352f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (R.getKind() == RawCommentAndCacheFlags::NoCommentInDecl) 353f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko R = Raw; 354f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 355f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko 356aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return RC; 357aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko} 358aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 359bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanianstatic void addRedeclaredMethods(const ObjCMethodDecl *ObjCMethod, 360bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian SmallVectorImpl<const NamedDecl *> &Redeclared) { 361bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian const DeclContext *DC = ObjCMethod->getDeclContext(); 362bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian if (const ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(DC)) { 363bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian const ObjCInterfaceDecl *ID = IMD->getClassInterface(); 364bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian if (!ID) 365bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian return; 366bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian // Add redeclared method here. 367bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian for (const ObjCCategoryDecl *ClsExtDecl = ID->getFirstClassExtension(); 368bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension()) { 369bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian if (ObjCMethodDecl *RedeclaredMethod = 370bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian ClsExtDecl->getMethod(ObjCMethod->getSelector(), 371bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian ObjCMethod->isInstanceMethod())) 372bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian Redeclared.push_back(RedeclaredMethod); 373bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian } 374bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian } 375bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian} 376bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian 377749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahaniancomments::FullComment *ASTContext::cloneFullComment(comments::FullComment *FC, 378749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian const Decl *D) const { 379749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian comments::DeclInfo *ThisDeclInfo = new (*this) comments::DeclInfo; 380749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian ThisDeclInfo->CommentDecl = D; 381749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian ThisDeclInfo->IsFilled = false; 382749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian ThisDeclInfo->fill(); 383749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian ThisDeclInfo->CommentDecl = FC->getDecl(); 384749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian comments::FullComment *CFC = 385749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian new (*this) comments::FullComment(FC->getBlocks(), 386749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian ThisDeclInfo); 387749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian return CFC; 388749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian 389749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian} 390749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian 3911952354bd376062c3ab3d328c0fc6c36530c9309Dmitri Gribenkocomments::FullComment *ASTContext::getCommentForDecl( 3921952354bd376062c3ab3d328c0fc6c36530c9309Dmitri Gribenko const Decl *D, 3931952354bd376062c3ab3d328c0fc6c36530c9309Dmitri Gribenko const Preprocessor *PP) const { 394c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko D = adjustDeclToTemplate(D); 395bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian 396c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko const Decl *Canonical = D->getCanonicalDecl(); 397c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko llvm::DenseMap<const Decl *, comments::FullComment *>::iterator Pos = 398c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko ParsedComments.find(Canonical); 399bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian 400bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian if (Pos != ParsedComments.end()) { 401749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian if (Canonical != D) { 402bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian comments::FullComment *FC = Pos->second; 403749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian comments::FullComment *CFC = cloneFullComment(FC, D); 404bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian return CFC; 405bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian } 406c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko return Pos->second; 407bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian } 408bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian 4091599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const Decl *OriginalDecl; 410bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian 4111599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const RawComment *RC = getRawCommentForAnyRedecl(D, &OriginalDecl); 412bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian if (!RC) { 413bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian if (isa<ObjCMethodDecl>(D) || isa<FunctionDecl>(D)) { 4141e905da74dbfd353d77dfc548fc9d6ff420d515aDmitri Gribenko SmallVector<const NamedDecl*, 8> Overridden; 415bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) 4161e905da74dbfd353d77dfc548fc9d6ff420d515aDmitri Gribenko addRedeclaredMethods(OMD, Overridden); 4171e905da74dbfd353d77dfc548fc9d6ff420d515aDmitri Gribenko getOverriddenMethods(dyn_cast<NamedDecl>(D), Overridden); 4181e905da74dbfd353d77dfc548fc9d6ff420d515aDmitri Gribenko for (unsigned i = 0, e = Overridden.size(); i < e; i++) { 4191e905da74dbfd353d77dfc548fc9d6ff420d515aDmitri Gribenko if (comments::FullComment *FC = getCommentForDecl(Overridden[i], PP)) { 420749ace614b6ea1ae11d194a60b18e1e43e1db243Fariborz Jahanian comments::FullComment *CFC = cloneFullComment(FC, D); 421bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian return CFC; 422bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian } 423bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian } 424bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian } 4258d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko return NULL; 426bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian } 427bf967be66ea8c51b66c61659c23240f762a56dbeFariborz Jahanian 4284b41c65feb93eeb6f6d27b49a2045ea1b72de9d1Dmitri Gribenko // If the RawComment was attached to other redeclaration of this Decl, we 4294b41c65feb93eeb6f6d27b49a2045ea1b72de9d1Dmitri Gribenko // should parse the comment in context of that other Decl. This is important 4304b41c65feb93eeb6f6d27b49a2045ea1b72de9d1Dmitri Gribenko // because comments can contain references to parameter names which can be 4314b41c65feb93eeb6f6d27b49a2045ea1b72de9d1Dmitri Gribenko // different across redeclarations. 4321599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko if (D != OriginalDecl) 4331952354bd376062c3ab3d328c0fc6c36530c9309Dmitri Gribenko return getCommentForDecl(OriginalDecl, PP); 4341599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko 4351952354bd376062c3ab3d328c0fc6c36530c9309Dmitri Gribenko comments::FullComment *FC = RC->parse(*this, PP, D); 436c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko ParsedComments[Canonical] = FC; 437c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko return FC; 4388d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko} 4398d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko 4403e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregorvoid 4413e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas GregorASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &ID, 4423e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTemplateParmDecl *Parm) { 4433e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(Parm->getDepth()); 4443e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(Parm->getPosition()); 44561c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor ID.AddBoolean(Parm->isParameterPack()); 4463e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4473e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateParameterList *Params = Parm->getTemplateParameters(); 4483e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(Params->size()); 4493e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor for (TemplateParameterList::const_iterator P = Params->begin(), 4503e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor PEnd = Params->end(); 4513e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor P != PEnd; ++P) { 4523e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) { 4533e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(0); 4543e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddBoolean(TTP->isParameterPack()); 4553e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor continue; 4563e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 4573e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4583e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) { 4593e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(1); 46061c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor ID.AddBoolean(NTTP->isParameterPack()); 4619e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman ID.AddPointer(NTTP->getType().getCanonicalType().getAsOpaquePtr()); 4626952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor if (NTTP->isExpandedParameterPack()) { 4636952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ID.AddBoolean(true); 4646952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ID.AddInteger(NTTP->getNumExpansionTypes()); 4659e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman for (unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) { 4669e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman QualType T = NTTP->getExpansionType(I); 4679e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman ID.AddPointer(T.getCanonicalType().getAsOpaquePtr()); 4689e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman } 4696952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } else 4706952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ID.AddBoolean(false); 4713e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor continue; 4723e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 4733e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4743e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P); 4753e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(2); 4763e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Profile(ID, TTP); 4773e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 4783e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor} 4793e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4803e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas GregorTemplateTemplateParmDecl * 4813e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas GregorASTContext::getCanonicalTemplateTemplateParmDecl( 4824ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad TemplateTemplateParmDecl *TTP) const { 4833e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Check if we already have a canonical template template parameter. 4843e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor llvm::FoldingSetNodeID ID; 4853e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonicalTemplateTemplateParm::Profile(ID, TTP); 4863e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor void *InsertPos = 0; 4873e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonicalTemplateTemplateParm *Canonical 4883e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); 4893e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (Canonical) 4903e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor return Canonical->getParam(); 4913e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4923e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Build a canonical template parameter list. 4933e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateParameterList *Params = TTP->getTemplateParameters(); 4945f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<NamedDecl *, 4> CanonParams; 4953e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.reserve(Params->size()); 4963e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor for (TemplateParameterList::const_iterator P = Params->begin(), 4973e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor PEnd = Params->end(); 4983e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor P != PEnd; ++P) { 4993e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) 5003e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.push_back( 5013e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTypeParmDecl::Create(*this, getTranslationUnitDecl(), 502344577e6b58f42d18dc8118c8903b49a85dc005eAbramo Bagnara SourceLocation(), 503344577e6b58f42d18dc8118c8903b49a85dc005eAbramo Bagnara SourceLocation(), 504344577e6b58f42d18dc8118c8903b49a85dc005eAbramo Bagnara TTP->getDepth(), 5053e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TTP->getIndex(), 0, false, 5063e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TTP->isParameterPack())); 5073e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor else if (NonTypeTemplateParmDecl *NTTP 5086952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor = dyn_cast<NonTypeTemplateParmDecl>(*P)) { 5096952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor QualType T = getCanonicalType(NTTP->getType()); 5106952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(T); 5116952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NonTypeTemplateParmDecl *Param; 5126952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor if (NTTP->isExpandedParameterPack()) { 5135f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 2> ExpandedTypes; 5145f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TypeSourceInfo *, 2> ExpandedTInfos; 5156952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor for (unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) { 5166952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTypes.push_back(getCanonicalType(NTTP->getExpansionType(I))); 5176952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTInfos.push_back( 5186952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor getTrivialTypeSourceInfo(ExpandedTypes.back())); 5196952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } 5206952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor 5216952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor Param = NonTypeTemplateParmDecl::Create(*this, getTranslationUnitDecl(), 522ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 523ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 5246952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getDepth(), 5256952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getPosition(), 0, 5266952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor T, 5276952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor TInfo, 5286952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTypes.data(), 5296952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTypes.size(), 5306952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTInfos.data()); 5316952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } else { 5326952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor Param = NonTypeTemplateParmDecl::Create(*this, getTranslationUnitDecl(), 533ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 534ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 5356952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getDepth(), 5366952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getPosition(), 0, 5376952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor T, 5386952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->isParameterPack(), 5396952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor TInfo); 5406952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } 5416952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor CanonParams.push_back(Param); 5426952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor 5436952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } else 5443e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.push_back(getCanonicalTemplateTemplateParmDecl( 5453e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor cast<TemplateTemplateParmDecl>(*P))); 5463e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 5473e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 5483e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTemplateParmDecl *CanonTTP 5493e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor = TemplateTemplateParmDecl::Create(*this, getTranslationUnitDecl(), 5503e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor SourceLocation(), TTP->getDepth(), 55161c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor TTP->getPosition(), 55261c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor TTP->isParameterPack(), 55361c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor 0, 5543e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateParameterList::Create(*this, SourceLocation(), 5553e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor SourceLocation(), 5563e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.data(), 5573e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.size(), 5583e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor SourceLocation())); 5593e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 5603e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Get the new insert position for the node we care about. 5613e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); 5623e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor assert(Canonical == 0 && "Shouldn't be in the map!"); 5633e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor (void)Canonical; 5643e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 5653e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Create the canonical template template parameter entry. 5663e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Canonical = new (*this) CanonicalTemplateTemplateParm(CanonTTP); 5673e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonTemplateTemplateParms.InsertNode(Canonical, InsertPos); 5683e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor return CanonTTP; 5693e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor} 5703e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 571071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCXXABI *ASTContext::createCXXABI(const TargetInfo &T) { 572ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall if (!LangOpts.CPlusPlus) return 0; 573ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall 57420cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis switch (T.getCXXABI()) { 575ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall case CXXABI_ARM: 576ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall return CreateARMCXXABI(*this); 577ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall case CXXABI_Itanium: 578071cc7deffad608165b1ddd5263e8bf181861520Charles Davis return CreateItaniumCXXABI(*this); 57920cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis case CXXABI_Microsoft: 58020cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis return CreateMicrosoftCXXABI(*this); 58120cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis } 5827530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid CXXABI type!"); 583071cc7deffad608165b1ddd5263e8bf181861520Charles Davis} 584071cc7deffad608165b1ddd5263e8bf181861520Charles Davis 585bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregorstatic const LangAS::Map *getAddressSpaceMap(const TargetInfo &T, 586207f4d8543529221932af82836016a2ef066c917Peter Collingbourne const LangOptions &LOpts) { 587207f4d8543529221932af82836016a2ef066c917Peter Collingbourne if (LOpts.FakeAddressSpaceMap) { 588207f4d8543529221932af82836016a2ef066c917Peter Collingbourne // The fake address space map must have a distinct entry for each 589207f4d8543529221932af82836016a2ef066c917Peter Collingbourne // language-specific address space. 590207f4d8543529221932af82836016a2ef066c917Peter Collingbourne static const unsigned FakeAddrSpaceMap[] = { 591207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 1, // opencl_global 592207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 2, // opencl_local 5934dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 3, // opencl_constant 5944dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 4, // cuda_device 5954dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 5, // cuda_constant 5964dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 6 // cuda_shared 597207f4d8543529221932af82836016a2ef066c917Peter Collingbourne }; 598bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return &FakeAddrSpaceMap; 599207f4d8543529221932af82836016a2ef066c917Peter Collingbourne } else { 600bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return &T.getAddressSpaceMap(); 601207f4d8543529221932af82836016a2ef066c917Peter Collingbourne } 602207f4d8543529221932af82836016a2ef066c917Peter Collingbourne} 603207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 6043e3cd93b2fd9644e970c389e715c13883faf68b6Douglas GregorASTContext::ASTContext(LangOptions& LOpts, SourceManager &SM, 605bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor const TargetInfo *t, 606e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar IdentifierTable &idents, SelectorTable &sels, 6071b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner Builtin::Context &builtins, 608bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor unsigned size_reserve, 609bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor bool DelayInitialization) 610bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor : FunctionProtoTypes(this_()), 611bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor TemplateSpecializationTypes(this_()), 612bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor DependentTemplateSpecializationTypes(this_()), 613bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor SubstTemplateTemplateParmPacks(this_()), 614bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor GlobalNestedNameSpecifier(0), 615bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Int128Decl(0), UInt128Decl(0), 616c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge BuiltinVaListDecl(0), 617a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor ObjCIdDecl(0), ObjCSelDecl(0), ObjCClassDecl(0), ObjCProtocolClassDecl(0), 618961713055e636170da59d7006a878cb4ba518a5dFariborz Jahanian BOOLDecl(0), 619e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor CFConstantStringTypeDecl(0), ObjCInstanceTypeDecl(0), 620bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor FILEDecl(0), 621e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola jmp_bufDecl(0), sigjmp_bufDecl(0), ucontext_tDecl(0), 622e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola BlockDescriptorType(0), BlockDescriptorExtendedType(0), 623e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola cudaConfigureCallDecl(0), 624e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor NullTypeSourceInfo(QualType()), 625e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor FirstLocalImport(), LastLocalImport(), 626bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor SourceMgr(SM), LangOpts(LOpts), 62730c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor AddrSpaceMap(0), Target(t), PrintingPolicy(LOpts), 628bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Idents(idents), Selectors(sels), 629bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor BuiltinInfo(builtins), 630bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor DeclarationNames(*this), 63130c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor ExternalSource(0), Listener(0), 632aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko Comments(SM), CommentsLoaded(false), 633e4330a302ac20b41b9800267ebd4b5b01f8553f8Dmitri Gribenko CommentCommandTraits(BumpAlloc), 634bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor LastSDM(0, 0), 635bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor UniqueBlockByRefTypeID(0) 636bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor{ 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (size_reserve > 0) Types.reserve(size_reserve); 638e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar TUDecl = TranslationUnitDecl::Create(*this); 639bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor 640bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor if (!DelayInitialization) { 641bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor assert(t && "No target supplied for ASTContext initialization"); 642bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor InitBuiltinTypes(*t); 643bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor } 644e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar} 645e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerASTContext::~ASTContext() { 6473478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek // Release the DenseMaps associated with DeclContext objects. 6483478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek // FIXME: Is this the ideal solution? 6493478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek ReleaseDeclContextMaps(); 6507d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 65163fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor // Call all of the deallocation functions. 65263fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor for (unsigned I = 0, N = Deallocations.size(); I != N; ++I) 65363fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor Deallocations[I].first(Deallocations[I].second); 6540054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor 655dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek // ASTRecordLayout objects in ASTRecordLayouts must always be destroyed 65663fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor // because they can contain DenseMaps. 65763fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor for (llvm::DenseMap<const ObjCContainerDecl*, 65863fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor const ASTRecordLayout*>::iterator 65963fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) 66063fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor // Increment in loop to prevent using deallocated memory. 66163fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second)) 66263fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor R->Destroy(*this); 66363fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor 664dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator 665dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { 666dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek // Increment in loop to prevent using deallocated memory. 667dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second)) 668dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek R->Destroy(*this); 669dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek } 6706320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 6716320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor for (llvm::DenseMap<const Decl*, AttrVec*>::iterator A = DeclAttrs.begin(), 6726320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor AEnd = DeclAttrs.end(); 6736320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor A != AEnd; ++A) 6746320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor A->second->~AttrVec(); 6756320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor} 676ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor 6770054531488928a424666ac11fcdc6bcc5112de52Douglas Gregorvoid ASTContext::AddDeallocation(void (*Callback)(void*), void *Data) { 6780054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor Deallocations.push_back(std::make_pair(Callback, Data)); 6790054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor} 6800054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor 6811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 6826f42b62b6194f53bcbc349f5d17388e1936535d7Dylan NoblesmithASTContext::setExternalSource(OwningPtr<ExternalASTSource> &Source) { 6832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource.reset(Source.take()); 6842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 6852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencervoid ASTContext::PrintStats() const { 687cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << "\n*** AST Context Stats:\n"; 688cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << " " << Types.size() << " types total.\n"; 6897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 690dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned counts[] = { 6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump#define TYPE(Name, Parent) 0, 692dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 693dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 694dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor 0 // Extra 695dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor }; 696c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0, e = Types.size(); i != e; ++i) { 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *T = Types[i]; 699dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor counts[(unsigned)T->getTypeClass()]++; 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 702dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned Idx = 0; 703dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned TotalBytes = 0; 704dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define TYPE(Name, Parent) \ 705dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor if (counts[Idx]) \ 706cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << " " << counts[Idx] << " " << #Name \ 707cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " types\n"; \ 708dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor TotalBytes += counts[Idx] * sizeof(Name##Type); \ 709dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor ++Idx; 710dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 711dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 713cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << "Total bytes = " << TotalBytes << "\n"; 714cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth 7154923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregor // Implicit special member functions. 716cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitDefaultConstructorsDeclared << "/" 717cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitDefaultConstructors 718cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit default constructors created\n"; 719cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitCopyConstructorsDeclared << "/" 720cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitCopyConstructors 721cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit copy constructors created\n"; 7224e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 723cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitMoveConstructorsDeclared << "/" 724cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitMoveConstructors 725cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit move constructors created\n"; 726cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitCopyAssignmentOperatorsDeclared << "/" 727cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitCopyAssignmentOperators 728cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit copy assignment operators created\n"; 7294e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 730cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitMoveAssignmentOperatorsDeclared << "/" 731cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitMoveAssignmentOperators 732cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit move assignment operators created\n"; 733cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitDestructorsDeclared << "/" 734cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitDestructors 735cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit destructors created\n"; 736cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth 7372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor if (ExternalSource.get()) { 738cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << "\n"; 7392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource->PrintStats(); 7402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 741cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth 74263fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor BumpAlloc.PrintStats(); 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 745772eeaefef2c883aabe35caf4543e7e32d290183Douglas GregorTypedefDecl *ASTContext::getInt128Decl() const { 746772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor if (!Int128Decl) { 747772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(Int128Ty); 748772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor Int128Decl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 749772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor getTranslationUnitDecl(), 750772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 751772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 752772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor &Idents.get("__int128_t"), 753772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TInfo); 754772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor } 755772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor 756772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor return Int128Decl; 757772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor} 758772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor 759772eeaefef2c883aabe35caf4543e7e32d290183Douglas GregorTypedefDecl *ASTContext::getUInt128Decl() const { 760772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor if (!UInt128Decl) { 761772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(UnsignedInt128Ty); 762772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor UInt128Decl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 763772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor getTranslationUnitDecl(), 764772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 765772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 766772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor &Idents.get("__uint128_t"), 767772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TInfo); 768772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor } 769772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor 770772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor return UInt128Decl; 771772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor} 7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 773e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCallvoid ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) { 7746b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall BuiltinType *Ty = new (*this, TypeAlignment) BuiltinType(K); 775e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCall R = CanQualType::CreateUnsafe(QualType(Ty, 0)); 7766b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Types.push_back(Ty); 7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 779bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregorvoid ASTContext::InitBuiltinTypes(const TargetInfo &Target) { 780bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor assert((!this->Target || this->Target == &Target) && 781bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor "Incorrect target reinitialization"); 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(VoidTy.isNull() && "Context reinitialized?"); 7831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 784bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor this->Target = &Target; 785bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor 786bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor ABI.reset(createCXXABI(Target)); 787bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor AddrSpaceMap = getAddressSpaceMap(Target, LangOpts); 788bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor 7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p19. 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(VoidTy, BuiltinType::Void); 7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p2. 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(BoolTy, BuiltinType::Bool); 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p3. 79515b91764d08e886391c865c4a444d7b51141c284Eli Friedman if (LangOpts.CharIsSigned) 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_S); 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_U); 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p4. 8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(SignedCharTy, BuiltinType::SChar); 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(ShortTy, BuiltinType::Short); 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(IntTy, BuiltinType::Int); 8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongTy, BuiltinType::Long); 8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongLongTy, BuiltinType::LongLong); 8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p6. 8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedCharTy, BuiltinType::UChar); 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedShortTy, BuiltinType::UShort); 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedIntTy, BuiltinType::UInt); 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongTy, BuiltinType::ULong); 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongLongTy, BuiltinType::ULongLong); 8121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p10. 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(FloatTy, BuiltinType::Float); 8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(DoubleTy, BuiltinType::Double); 8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongDoubleTy, BuiltinType::LongDouble); 81764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 8182df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner // GNU extension, 128-bit integers. 8192df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(Int128Ty, BuiltinType::Int128); 8202df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(UnsignedInt128Ty, BuiltinType::UInt128); 8212df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner 822e75bb61f1b876afaa6b2f4a2b860c2889ea1d050Abramo Bagnara if (LangOpts.CPlusPlus && LangOpts.WChar) { // C++ 3.9.1p5 823d3d77cd138f8e830f6547b6f83fcd5721ccf5f5dEli Friedman if (TargetInfo::isTypeSigned(Target.getWCharType())) 8243f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner InitBuiltinType(WCharTy, BuiltinType::WChar_S); 8253f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner else // -fshort-wchar makes wchar_t be unsigned. 8263f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner InitBuiltinType(WCharTy, BuiltinType::WChar_U); 827e75bb61f1b876afaa6b2f4a2b860c2889ea1d050Abramo Bagnara } else // C99 (or C++ using -fno-wchar) 8283a2503227c3db04a3619735127483263c1075ef7Chris Lattner WCharTy = getFromTargetType(Target.getWCharType()); 82964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 830392da48160bd92ceb486792780467cbfdb2d0e8cJames Molloy WIntTy = getFromTargetType(Target.getWIntType()); 831392da48160bd92ceb486792780467cbfdb2d0e8cJames Molloy 832f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 833f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char16Ty, BuiltinType::Char16); 834f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 835f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16Ty = getFromTargetType(Target.getChar16Type()); 836f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 837f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 838f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char32Ty, BuiltinType::Char32); 839f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 840f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32Ty = getFromTargetType(Target.getChar32Type()); 841f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 842898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Placeholder type for type-dependent expressions whose type is 843898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // completely unknown. No code should ever check a type against 844898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // DependentTy and users should never see it; however, it is here to 845898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // help diagnose failures to properly check for type-dependent 846898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // expressions. 847898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor InitBuiltinType(DependentTy, BuiltinType::Dependent); 8488e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 8492a984cad5ac3fdceeff2bd99daa7b90979313475John McCall // Placeholder type for functions. 8502a984cad5ac3fdceeff2bd99daa7b90979313475John McCall InitBuiltinType(OverloadTy, BuiltinType::Overload); 8512a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 852864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // Placeholder type for bound members. 853864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall InitBuiltinType(BoundMemberTy, BuiltinType::BoundMember); 854864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 8553c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // Placeholder type for pseudo-objects. 8563c3b7f90a863af43fa63043d396553ecf205351cJohn McCall InitBuiltinType(PseudoObjectTy, BuiltinType::PseudoObject); 8573c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 8581de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall // "any" type; useful for debugger-like clients. 8591de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall InitBuiltinType(UnknownAnyTy, BuiltinType::UnknownAny); 8601de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall 8610ddaeb9b031070ec64afe92d9892875ac44df427John McCall // Placeholder type for unbridged ARC casts. 8620ddaeb9b031070ec64afe92d9892875ac44df427John McCall InitBuiltinType(ARCUnbridgedCastTy, BuiltinType::ARCUnbridgedCast); 8630ddaeb9b031070ec64afe92d9892875ac44df427John McCall 864a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman // Placeholder type for builtin functions. 865a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman InitBuiltinType(BuiltinFnTy, BuiltinType::BuiltinFn); 866a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p11. 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FloatComplexTy = getComplexType(FloatTy); 8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DoubleComplexTy = getComplexType(DoubleTy); 8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongDoubleComplexTy = getComplexType(LongDoubleTy); 8718e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 87213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian // Builtin types for 'id', 'Class', and 'SEL'. 873de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId); 874de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass); 87513dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel); 876ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 877ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Builtin type for __objc_yes and __objc_no 87893a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ? 87993a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian SignedCharTy : BoolTy); 880ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 881a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = QualType(); 8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 88333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // void * type 88433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian VoidPtrTy = getPointerType(VoidTy); 8856e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 8866e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // nullptr type (C++0x 2.14.7) 8876e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl InitBuiltinType(NullPtrTy, BuiltinType::NullPtr); 888aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov 889aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov // half type (OpenCL 6.1.1.1) / ARM NEON __fp16 890aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov InitBuiltinType(HalfTy, BuiltinType::Half); 891fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge 892fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge // Builtin type used to help define __builtin_va_list. 893fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge VaListTagTy = QualType(); 8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 896d6471f7c1921c7802804ce3ff6fe9768310f72b9David BlaikieDiagnosticsEngine &ASTContext::getDiagnostics() const { 89778a916ec5ff5b66adec3c499e1b9af7b87668309Argyrios Kyrtzidis return SourceMgr.getDiagnostics(); 89878a916ec5ff5b66adec3c499e1b9af7b87668309Argyrios Kyrtzidis} 89978a916ec5ff5b66adec3c499e1b9af7b87668309Argyrios Kyrtzidis 9006320064d0c60fa8683f5623881c9394fd4aa7689Douglas GregorAttrVec& ASTContext::getDeclAttrs(const Decl *D) { 9016320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor AttrVec *&Result = DeclAttrs[D]; 9026320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor if (!Result) { 9036320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor void *Mem = Allocate(sizeof(AttrVec)); 9046320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor Result = new (Mem) AttrVec; 9056320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor } 9066320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 9076320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor return *Result; 9086320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor} 9096320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 9106320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor/// \brief Erase the attributes corresponding to the given declaration. 9116320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregorvoid ASTContext::eraseDeclAttrs(const Decl *D) { 9126320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor llvm::DenseMap<const Decl*, AttrVec*>::iterator Pos = DeclAttrs.find(D); 9136320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor if (Pos != DeclAttrs.end()) { 9146320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor Pos->second->~AttrVec(); 9156320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor DeclAttrs.erase(Pos); 9166320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor } 9176320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor} 9186320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 919251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas GregorMemberSpecializationInfo * 920663b5a0be7261c29bc4c526a71cffcfa02d4153eDouglas GregorASTContext::getInstantiatedFromStaticDataMember(const VarDecl *Var) { 9217caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Var->isStaticDataMember() && "Not a static data member"); 922663b5a0be7261c29bc4c526a71cffcfa02d4153eDouglas Gregor llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *>::iterator Pos 9237caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor = InstantiatedFromStaticDataMember.find(Var); 9247caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor if (Pos == InstantiatedFromStaticDataMember.end()) 9257caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return 0; 9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9277caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return Pos->second; 9287caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 9297caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 931251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas GregorASTContext::setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, 9329421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis TemplateSpecializationKind TSK, 9339421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis SourceLocation PointOfInstantiation) { 9347caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Inst->isStaticDataMember() && "Not a static data member"); 9357caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Tmpl->isStaticDataMember() && "Not a static data member"); 9367caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(!InstantiatedFromStaticDataMember[Inst] && 9377caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor "Already noted what static data member was instantiated from"); 938251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor InstantiatedFromStaticDataMember[Inst] 9399421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis = new (*this) MemberSpecializationInfo(Tmpl, TSK, PointOfInstantiation); 9407caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 9417caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 942af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois PichetFunctionDecl *ASTContext::getClassScopeSpecializationPattern( 943af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet const FunctionDecl *FD){ 944af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet assert(FD && "Specialization is 0"); 945af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet llvm::DenseMap<const FunctionDecl*, FunctionDecl *>::const_iterator Pos 9460d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet = ClassScopeSpecializationPattern.find(FD); 9470d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet if (Pos == ClassScopeSpecializationPattern.end()) 948af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet return 0; 949af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet 950af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet return Pos->second; 951af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet} 952af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet 953af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichetvoid ASTContext::setClassScopeSpecializationPattern(FunctionDecl *FD, 954af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet FunctionDecl *Pattern) { 955af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet assert(FD && "Specialization is 0"); 956af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet assert(Pattern && "Class scope specialization pattern is 0"); 9570d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet ClassScopeSpecializationPattern[FD] = Pattern; 958af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet} 959af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet 9607ba107a1863ddfa1664555854f0d7bdb3c491c92John McCallNamedDecl * 961ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::getInstantiatedFromUsingDecl(UsingDecl *UUD) { 9627ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall llvm::DenseMap<UsingDecl *, NamedDecl *>::const_iterator Pos 963ed97649e9574b9d854fa4d6109c9333ae0993554John McCall = InstantiatedFromUsingDecl.find(UUD); 964ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Pos == InstantiatedFromUsingDecl.end()) 9650d8df780aef1acda5962347a32591efc629b6748Anders Carlsson return 0; 9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9670d8df780aef1acda5962347a32591efc629b6748Anders Carlsson return Pos->second; 9680d8df780aef1acda5962347a32591efc629b6748Anders Carlsson} 9690d8df780aef1acda5962347a32591efc629b6748Anders Carlsson 9700d8df780aef1acda5962347a32591efc629b6748Anders Carlssonvoid 971ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern) { 972ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert((isa<UsingDecl>(Pattern) || 973ed97649e9574b9d854fa4d6109c9333ae0993554John McCall isa<UnresolvedUsingValueDecl>(Pattern) || 974ed97649e9574b9d854fa4d6109c9333ae0993554John McCall isa<UnresolvedUsingTypenameDecl>(Pattern)) && 975ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "pattern decl is not a using decl"); 976ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(!InstantiatedFromUsingDecl[Inst] && "pattern already exists"); 977ed97649e9574b9d854fa4d6109c9333ae0993554John McCall InstantiatedFromUsingDecl[Inst] = Pattern; 978ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 979ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 980ed97649e9574b9d854fa4d6109c9333ae0993554John McCallUsingShadowDecl * 981ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst) { 982ed97649e9574b9d854fa4d6109c9333ae0993554John McCall llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>::const_iterator Pos 983ed97649e9574b9d854fa4d6109c9333ae0993554John McCall = InstantiatedFromUsingShadowDecl.find(Inst); 984ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Pos == InstantiatedFromUsingShadowDecl.end()) 985ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return 0; 986ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 987ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Pos->second; 988ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 989ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 990ed97649e9574b9d854fa4d6109c9333ae0993554John McCallvoid 991ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, 992ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingShadowDecl *Pattern) { 993ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(!InstantiatedFromUsingShadowDecl[Inst] && "pattern already exists"); 994ed97649e9574b9d854fa4d6109c9333ae0993554John McCall InstantiatedFromUsingShadowDecl[Inst] = Pattern; 9950d8df780aef1acda5962347a32591efc629b6748Anders Carlsson} 9960d8df780aef1acda5962347a32591efc629b6748Anders Carlsson 997d8b285fee4471f393da8ee30f552ceacdc362afaAnders CarlssonFieldDecl *ASTContext::getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field) { 998d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson llvm::DenseMap<FieldDecl *, FieldDecl *>::iterator Pos 999d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson = InstantiatedFromUnnamedFieldDecl.find(Field); 1000d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (Pos == InstantiatedFromUnnamedFieldDecl.end()) 1001d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return 0; 10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1003d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return Pos->second; 1004d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson} 1005d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson 1006d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlssonvoid ASTContext::setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, 1007d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson FieldDecl *Tmpl) { 1008d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!Inst->getDeclName() && "Instantiated field decl is not unnamed"); 1009d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!Tmpl->getDeclName() && "Template field decl is not unnamed"); 1010d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!InstantiatedFromUnnamedFieldDecl[Inst] && 1011d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson "Already noted what unnamed field was instantiated from"); 10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1013d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl; 1014d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson} 1015d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson 101614d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanianbool ASTContext::ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD, 101714d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian const FieldDecl *LastFD) const { 101814d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian return (FD->isBitField() && LastFD && !LastFD->isBitField() && 1019a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this) == 0); 102014d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian} 102114d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian 1022340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanianbool ASTContext::ZeroBitfieldFollowsBitfield(const FieldDecl *FD, 1023340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian const FieldDecl *LastFD) const { 1024340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian return (FD->isBitField() && LastFD && LastFD->isBitField() && 1025a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this) == 0 && 1026a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith LastFD->getBitWidthValue(*this) != 0); 1027340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian} 1028340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian 10299b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanianbool ASTContext::BitfieldFollowsBitfield(const FieldDecl *FD, 10309b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian const FieldDecl *LastFD) const { 10319b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian return (FD->isBitField() && LastFD && LastFD->isBitField() && 1032a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this) && 1033a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith LastFD->getBitWidthValue(*this)); 10349b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian} 10359b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian 1036dd7fddb5b6883326e52b278a9b7e9cefea29aae0Chad Rosierbool ASTContext::NonBitfieldFollowsBitfield(const FieldDecl *FD, 103752bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian const FieldDecl *LastFD) const { 103852bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian return (!FD->isBitField() && LastFD && LastFD->isBitField() && 1039a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith LastFD->getBitWidthValue(*this)); 104052bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian} 104152bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian 1042dd7fddb5b6883326e52b278a9b7e9cefea29aae0Chad Rosierbool ASTContext::BitfieldFollowsNonBitfield(const FieldDecl *FD, 104352bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian const FieldDecl *LastFD) const { 104452bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian return (FD->isBitField() && LastFD && !LastFD->isBitField() && 1045a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this)); 104652bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian} 104752bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian 10487d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_cxx_method_iterator 10497d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_methods_begin(const CXXMethodDecl *Method) const { 10507d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos 105138eb1e161f602ee810dfb8a5a0d8462572f22689Argyrios Kyrtzidis = OverriddenMethods.find(Method->getCanonicalDecl()); 10527d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor if (Pos == OverriddenMethods.end()) 10537d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return 0; 10547d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 10557d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return Pos->second.begin(); 10567d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor} 10577d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 10587d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_cxx_method_iterator 10597d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_methods_end(const CXXMethodDecl *Method) const { 10607d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos 106138eb1e161f602ee810dfb8a5a0d8462572f22689Argyrios Kyrtzidis = OverriddenMethods.find(Method->getCanonicalDecl()); 10627d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor if (Pos == OverriddenMethods.end()) 10637d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return 0; 10647d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 10657d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return Pos->second.end(); 10667d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor} 10677d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 1068c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidisunsigned 1069c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios KyrtzidisASTContext::overridden_methods_size(const CXXMethodDecl *Method) const { 1070c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos 107138eb1e161f602ee810dfb8a5a0d8462572f22689Argyrios Kyrtzidis = OverriddenMethods.find(Method->getCanonicalDecl()); 1072c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis if (Pos == OverriddenMethods.end()) 1073c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis return 0; 1074c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis 1075c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis return Pos->second.size(); 1076c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis} 1077c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis 10787d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregorvoid ASTContext::addOverriddenMethod(const CXXMethodDecl *Method, 10797d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor const CXXMethodDecl *Overridden) { 108038eb1e161f602ee810dfb8a5a0d8462572f22689Argyrios Kyrtzidis assert(Method->isCanonicalDecl() && Overridden->isCanonicalDecl()); 10817d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor OverriddenMethods[Method].push_back(Overridden); 10827d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor} 10837d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 10841e905da74dbfd353d77dfc548fc9d6ff420d515aDmitri Gribenkovoid ASTContext::getOverriddenMethods( 10851e905da74dbfd353d77dfc548fc9d6ff420d515aDmitri Gribenko const NamedDecl *D, 10861e905da74dbfd353d77dfc548fc9d6ff420d515aDmitri Gribenko SmallVectorImpl<const NamedDecl *> &Overridden) const { 108721c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis assert(D); 108821c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis 108921c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis if (const CXXMethodDecl *CXXMethod = dyn_cast<CXXMethodDecl>(D)) { 1090bc0a2bb8dc122f8daae890ec82cecfe2054859ebArgyrios Kyrtzidis Overridden.append(CXXMethod->begin_overridden_methods(), 1091bc0a2bb8dc122f8daae890ec82cecfe2054859ebArgyrios Kyrtzidis CXXMethod->end_overridden_methods()); 109221c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis return; 109321c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis } 109421c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis 109521c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D); 109621c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis if (!Method) 109721c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis return; 109821c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis 1099740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis SmallVector<const ObjCMethodDecl *, 8> OverDecls; 1100740ae67dbf8dac44dbc8d6593a60f4f37a0a2aa5Argyrios Kyrtzidis Method->getOverriddenMethods(OverDecls); 1101bc0a2bb8dc122f8daae890ec82cecfe2054859ebArgyrios Kyrtzidis Overridden.append(OverDecls.begin(), OverDecls.end()); 110221c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis} 110321c3607282550779c9ae5fe784928597807fd110Argyrios Kyrtzidis 1104e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregorvoid ASTContext::addedLocalImportDecl(ImportDecl *Import) { 1105e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor assert(!Import->NextLocalImport && "Import declaration already in the chain"); 1106e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor assert(!Import->isFromASTFile() && "Non-local import declaration"); 1107e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor if (!FirstLocalImport) { 1108e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor FirstLocalImport = Import; 1109e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor LastLocalImport = Import; 1110e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor return; 1111e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor } 1112e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor 1113e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor LastLocalImport->NextLocalImport = Import; 1114e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor LastLocalImport = Import; 1115e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor} 1116e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor 1117464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 1118464175bba1318bef7905122e9fda20cff926df78Chris Lattner// Type Sizing and Analysis 1119464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 1120a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 1121b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 1122b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// scalar floating point type. 1123b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattnerconst llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { 1124183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const BuiltinType *BT = T->getAs<BuiltinType>(); 1125b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(BT && "Not a floating point type!"); 1126b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner switch (BT->getKind()) { 1127b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not a floating point type!"); 1128aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case BuiltinType::Half: return Target->getHalfFormat(); 1129bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor case BuiltinType::Float: return Target->getFloatFormat(); 1130bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor case BuiltinType::Double: return Target->getDoubleFormat(); 1131bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor case BuiltinType::LongDouble: return Target->getLongDoubleFormat(); 1132b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 1133b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner} 1134b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 11358b752f10c394b140f9ef89e049cbad1a7676fc25Ken Dyck/// getDeclAlign - Return a conservative estimate of the alignment of the 1136af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// specified decl. Note that bitfields do not have a valid alignment, so 1137af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// this method will assert on them. 11385d484e8cf710207010720589d89602233de61d01Sebastian Redl/// If @p RefAsPointee, references are treated like their underlying type 11395d484e8cf710207010720589d89602233de61d01Sebastian Redl/// (for alignof), else they're treated like pointers (for CodeGen). 11404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) const { 1141bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor unsigned Align = Target->getCharWidth(); 1142dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 11434081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall bool UseAlignAttrOnly = false; 11444081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall if (unsigned AlignFromAttr = D->getMaxAlignment()) { 11454081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall Align = AlignFromAttr; 11464081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall 11474081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // __attribute__((aligned)) can increase or decrease alignment 11484081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // *except* on a struct or struct member, where it only increases 11494081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // alignment unless 'packed' is also specified. 11504081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // 115182d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne // It is an error for alignas to decrease alignment, so we can 11524081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // ignore that possibility; Sema should diagnose it. 11534081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall if (isa<FieldDecl>(D)) { 11544081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall UseAlignAttrOnly = D->hasAttr<PackedAttr>() || 11554081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>(); 11564081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } else { 11574081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall UseAlignAttrOnly = true; 11584081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } 11594081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } 116078a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian else if (isa<FieldDecl>(D)) 116178a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian UseAlignAttrOnly = 116278a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian D->hasAttr<PackedAttr>() || 116378a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>(); 1164dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 1165ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // If we're using the align attribute only, just ignore everything 1166ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // else about the declaration and its type. 11674081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall if (UseAlignAttrOnly) { 1168ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // do nothing 1169ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 11704081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } else if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { 1171af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner QualType T = VD->getType(); 11726217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType* RT = T->getAs<ReferenceType>()) { 11735d484e8cf710207010720589d89602233de61d01Sebastian Redl if (RefAsPointee) 11745d484e8cf710207010720589d89602233de61d01Sebastian Redl T = RT->getPointeeType(); 11755d484e8cf710207010720589d89602233de61d01Sebastian Redl else 11765d484e8cf710207010720589d89602233de61d01Sebastian Redl T = getPointerType(RT->getPointeeType()); 11775d484e8cf710207010720589d89602233de61d01Sebastian Redl } 11785d484e8cf710207010720589d89602233de61d01Sebastian Redl if (!T->isIncompleteType() && !T->isFunctionType()) { 11793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Adjust alignments of declarations with array type by the 11803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // large-array alignment on the target. 1181bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor unsigned MinWidth = Target->getLargeArrayMinWidth(); 11823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ArrayType *arrayType; 11833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (MinWidth && (arrayType = getAsArrayType(T))) { 11843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (isa<VariableArrayType>(arrayType)) 1185bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = std::max(Align, Target->getLargeArrayAlign()); 11863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall else if (isa<ConstantArrayType>(arrayType) && 11873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall MinWidth <= getTypeSize(cast<ConstantArrayType>(arrayType))) 1188bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = std::max(Align, Target->getLargeArrayAlign()); 11893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 11903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Walk through any array types while we're at it. 11913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall T = getBaseElementType(arrayType); 11926deecb0d46bcfd048e651d2db7c4fb0d6407da96Rafael Espindola } 11939f1210c3280104417a4ad30f0a00825ac8fa718aChad Rosier Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); 1194dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman } 1195ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 1196ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Fields can be subject to extra alignment constraints, like if 1197ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // the field is packed, the struct is packed, or the struct has a 1198ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // a max-field-alignment constraint (#pragma pack). So calculate 1199ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // the actual alignment of the field within the struct, and then 1200ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // (as we're expected to) constrain that by the alignment of the type. 1201ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall if (const FieldDecl *field = dyn_cast<FieldDecl>(VD)) { 1202ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // So calculate the alignment of the field. 1203ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall const ASTRecordLayout &layout = getASTRecordLayout(field->getParent()); 1204ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 1205ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Start with the record's overall alignment. 1206dac54c124e302d6f028ea5723c425b7f66fc7c71Ken Dyck unsigned fieldAlign = toBits(layout.getAlignment()); 1207ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 1208ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Use the GCD of that and the offset within the record. 1209ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall uint64_t offset = layout.getFieldOffset(field->getFieldIndex()); 1210ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall if (offset > 0) { 1211ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Alignment is always a power of 2, so the GCD will be a power of 2, 1212ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // which means we get to do this crazy thing instead of Euclid's. 1213ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall uint64_t lowBitOfOffset = offset & (~offset + 1); 1214ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall if (lowBitOfOffset < fieldAlign) 1215ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall fieldAlign = static_cast<unsigned>(lowBitOfOffset); 1216ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall } 1217ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 1218ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall Align = std::min(Align, fieldAlign); 121905f62474dd2b0f1cb69adbe0787f2868788aa949Charles Davis } 1220af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner } 1221dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 1222eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(Align); 1223af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner} 1224b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 1225929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall// getTypeInfoDataSizeInChars - Return the size of a type, in 1226929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall// chars. If the type is a record, its data size is returned. This is 1227929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall// the size of the memcpy that's performed when assigning this type 1228929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall// using a trivial copy/move assignment operator. 1229929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCallstd::pair<CharUnits, CharUnits> 1230929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCallASTContext::getTypeInfoDataSizeInChars(QualType T) const { 1231929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall std::pair<CharUnits, CharUnits> sizeAndAlign = getTypeInfoInChars(T); 1232929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall 1233929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall // In C++, objects can sometimes be allocated into the tail padding 1234929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall // of a base-class subobject. We decide whether that's possible 1235929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall // during class layout, so here we can just trust the layout results. 1236929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall if (getLangOpts().CPlusPlus) { 1237929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall if (const RecordType *RT = T->getAs<RecordType>()) { 1238929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall const ASTRecordLayout &layout = getASTRecordLayout(RT->getDecl()); 1239929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall sizeAndAlign.first = layout.getDataSize(); 1240929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall } 1241929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall } 1242929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall 1243929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall return sizeAndAlign; 1244929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall} 1245929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall 1246ea1471e0e967548c596a71469702f8846dbaf3c0John McCallstd::pair<CharUnits, CharUnits> 1247bee5a79fc95e3003d755031e3d2bb4410a71e1c1Ken DyckASTContext::getTypeInfoInChars(const Type *T) const { 1248ea1471e0e967548c596a71469702f8846dbaf3c0John McCall std::pair<uint64_t, unsigned> Info = getTypeInfo(T); 1249eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return std::make_pair(toCharUnitsFromBits(Info.first), 1250eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck toCharUnitsFromBits(Info.second)); 1251ea1471e0e967548c596a71469702f8846dbaf3c0John McCall} 1252ea1471e0e967548c596a71469702f8846dbaf3c0John McCall 1253ea1471e0e967548c596a71469702f8846dbaf3c0John McCallstd::pair<CharUnits, CharUnits> 1254bee5a79fc95e3003d755031e3d2bb4410a71e1c1Ken DyckASTContext::getTypeInfoInChars(QualType T) const { 1255ea1471e0e967548c596a71469702f8846dbaf3c0John McCall return getTypeInfoInChars(T.getTypePtr()); 1256ea1471e0e967548c596a71469702f8846dbaf3c0John McCall} 1257ea1471e0e967548c596a71469702f8846dbaf3c0John McCall 1258bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbarstd::pair<uint64_t, unsigned> ASTContext::getTypeInfo(const Type *T) const { 1259bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar TypeInfoMap::iterator it = MemoizedTypeInfo.find(T); 1260bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar if (it != MemoizedTypeInfo.end()) 1261bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar return it->second; 1262bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar 1263bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar std::pair<uint64_t, unsigned> Info = getTypeInfoImpl(T); 1264bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar MemoizedTypeInfo.insert(std::make_pair(T, Info)); 1265bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar return Info; 1266bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar} 1267bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar 1268bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar/// getTypeInfoImpl - Return the size of the specified type, in bits. This 1269bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar/// method does not work on incomplete types. 12700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 12710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// FIXME: Pointers into different addr spaces could have different sizes and 12720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// alignment requirements: getPointerInfo should take an AddrSpace, this 12730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// should take a QualType, &c. 1274d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattnerstd::pair<uint64_t, unsigned> 1275bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel DunbarASTContext::getTypeInfoImpl(const Type *T) const { 12765e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump uint64_t Width=0; 12775e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump unsigned Align=8; 1278a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (T->getTypeClass()) { 127972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 128072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 128118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor#define NON_CANONICAL_TYPE(Class, Base) 128272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 128372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 1284d3d49bb27c7ffd9accc0a6c00e887111c0348845John McCall llvm_unreachable("Should not see dependent types"); 128572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 12865d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionNoProto: 12875d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionProto: 128818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(function) = 32 bits 128918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 129018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 32; 129118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 129218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 129372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 1294fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::VariableArray: 129518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 129618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = getTypeAlign(cast<ArrayType>(T)->getElementType()); 129718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 129818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 1299fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::ConstantArray: { 13001d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ConstantArrayType *CAT = cast<ConstantArrayType>(T); 13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 130298be4943e8dc4f3905629a7102668960873cf863Chris Lattner std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType()); 1303fea966a4103ed9c018d1494b95e9d09b161f5a70Abramo Bagnara uint64_t Size = CAT->getSize().getZExtValue(); 1304bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar assert((Size == 0 || EltInfo.first <= (uint64_t)(-1)/Size) && 1305bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar "Overflow in array type bit size evaluation"); 1306fea966a4103ed9c018d1494b95e9d09b161f5a70Abramo Bagnara Width = EltInfo.first*Size; 1307030d8846c7e520330007087e949f621989876e3aChris Lattner Align = EltInfo.second; 1308cd88b4171753dcb2bc0a21d78f1597c796bb8a20Argyrios Kyrtzidis Width = llvm::RoundUpToAlignment(Width, Align); 1309030d8846c7e520330007087e949f621989876e3aChris Lattner break; 13105c09a02a5db85e08a432b6eeced9aa656349710dChristopher Lamb } 1311213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman case Type::ExtVector: 1312030d8846c7e520330007087e949f621989876e3aChris Lattner case Type::Vector: { 13139fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner const VectorType *VT = cast<VectorType>(T); 13149fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(VT->getElementType()); 13159fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner Width = EltInfo.first*VT->getNumElements(); 13164bd998bbc228915d2b9cae5b67879de48940d05eEli Friedman Align = Width; 13176fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // If the alignment is not a power of 2, round up to the next power of 2. 13186fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // This happens for non-power-of-2 length vectors. 13198eefcd353c1d06a10104f69e5079ebab3183f9a3Dan Gohman if (Align & (Align-1)) { 13209fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner Align = llvm::NextPowerOf2(Align); 13219fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner Width = llvm::RoundUpToAlignment(Width, Align); 13229fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner } 1323f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier // Adjust the alignment based on the target max. 1324f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier uint64_t TargetVectorAlign = Target->getMaxVectorAlign(); 1325f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier if (TargetVectorAlign && TargetVectorAlign < Align) 1326f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier Align = TargetVectorAlign; 1327030d8846c7e520330007087e949f621989876e3aChris Lattner break; 1328030d8846c7e520330007087e949f621989876e3aChris Lattner } 13295d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner 13309e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner case Type::Builtin: 1331a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 1332b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unknown builtin type!"); 1333d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner case BuiltinType::Void: 133418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(void) = 8 bits. 133518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 133618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 8; 133718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 133818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 13396f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Bool: 1340bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getBoolWidth(); 1341bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getBoolAlign(); 13426f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1343692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_S: 1344692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_U: 1345692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UChar: 13466f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::SChar: 1347bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getCharWidth(); 1348bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getCharAlign(); 13496f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 13503f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 13513f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 1352bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getWCharWidth(); 1353bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getWCharAlign(); 135464c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis break; 1355f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char16: 1356bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getChar16Width(); 1357bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getChar16Align(); 1358f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 1359f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char32: 1360bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getChar32Width(); 1361bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getChar32Align(); 1362f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 1363692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UShort: 13646f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Short: 1365bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getShortWidth(); 1366bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getShortAlign(); 13676f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1368692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UInt: 13696f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Int: 1370bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getIntWidth(); 1371bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getIntAlign(); 13726f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1373692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULong: 13746f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Long: 1375bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getLongWidth(); 1376bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getLongAlign(); 13776f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1378692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULongLong: 13796f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongLong: 1380bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getLongLongWidth(); 1381bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getLongLongAlign(); 13826f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1383ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::Int128: 1384ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::UInt128: 1385ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Width = 128; 1386ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Align = 128; // int128_t is 128-bit aligned on all targets. 1387ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner break; 1388aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case BuiltinType::Half: 1389aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov Width = Target->getHalfWidth(); 1390aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov Align = Target->getHalfAlign(); 1391aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov break; 13926f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Float: 1393bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getFloatWidth(); 1394bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getFloatAlign(); 13956f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 13966f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Double: 1397bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getDoubleWidth(); 1398bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getDoubleAlign(); 13996f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 14006f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongDouble: 1401bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getLongDoubleWidth(); 1402bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getLongDoubleAlign(); 14036f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 14046e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case BuiltinType::NullPtr: 1405bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(0); // C++ 3.9.1p11: sizeof(nullptr_t) 1406bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(0); // == sizeof(void*) 14071590d9c0fec4c710c2962e4bb71f76979b5163d3Sebastian Redl break; 1408e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian case BuiltinType::ObjCId: 1409e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian case BuiltinType::ObjCClass: 1410e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian case BuiltinType::ObjCSel: 1411bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(0); 1412bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(0); 1413e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian break; 1414a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 1415bfef6d7c67831a135d6ab79931f010f750a730adChris Lattner break; 1416d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case Type::ObjCObjectPointer: 1417bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(0); 1418bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(0); 14196f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1420485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff case Type::BlockPointer: { 1421207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned AS = getTargetAddressSpace( 1422207f4d8543529221932af82836016a2ef066c917Peter Collingbourne cast<BlockPointerType>(T)->getPointeeType()); 1423bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(AS); 1424bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(AS); 1425485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff break; 1426485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff } 14275d484e8cf710207010720589d89602233de61d01Sebastian Redl case Type::LValueReference: 14285d484e8cf710207010720589d89602233de61d01Sebastian Redl case Type::RValueReference: { 14295d484e8cf710207010720589d89602233de61d01Sebastian Redl // alignof and sizeof should never enter this code path here, so we go 14305d484e8cf710207010720589d89602233de61d01Sebastian Redl // the pointer route. 1431207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned AS = getTargetAddressSpace( 1432207f4d8543529221932af82836016a2ef066c917Peter Collingbourne cast<ReferenceType>(T)->getPointeeType()); 1433bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(AS); 1434bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(AS); 14355d484e8cf710207010720589d89602233de61d01Sebastian Redl break; 14365d484e8cf710207010720589d89602233de61d01Sebastian Redl } 1437f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner case Type::Pointer: { 1438207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned AS = getTargetAddressSpace(cast<PointerType>(T)->getPointeeType()); 1439bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(AS); 1440bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(AS); 1441f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner break; 1442f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner } 1443f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case Type::MemberPointer: { 1444071cc7deffad608165b1ddd5263e8bf181861520Charles Davis const MemberPointerType *MPT = cast<MemberPointerType>(T); 14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<uint64_t, unsigned> PtrDiffInfo = 14461cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson getTypeInfo(getPointerDiffType()); 1447071cc7deffad608165b1ddd5263e8bf181861520Charles Davis Width = PtrDiffInfo.first * ABI->getMemberPointerSize(MPT); 14481cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson Align = PtrDiffInfo.second; 14491cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson break; 1450f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 14515d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::Complex: { 14525d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // Complex types have the same alignment as their elements, but twice the 14535d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // size. 14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<uint64_t, unsigned> EltInfo = 145598be4943e8dc4f3905629a7102668960873cf863Chris Lattner getTypeInfo(cast<ComplexType>(T)->getElementType()); 14569e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = EltInfo.first*2; 14575d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner Align = EltInfo.second; 14585d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner break; 14595d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner } 1460c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case Type::ObjCObject: 1461c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getTypeInfo(cast<ObjCObjectType>(T)->getBaseType().getTypePtr()); 146244a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel case Type::ObjCInterface: { 14631d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T); 146444a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); 1465dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck Width = toBits(Layout.getSize()); 1466dac54c124e302d6f028ea5723c425b7f66fc7c71Ken Dyck Align = toBits(Layout.getAlignment()); 146744a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel break; 146844a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel } 146972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 147072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: { 14711d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const TagType *TT = cast<TagType>(T); 14721d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar 14731d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (TT->getDecl()->isInvalidDecl()) { 147422ce41d9fc8509da65858c75bf5b3c4dae2d8c04Douglas Gregor Width = 8; 147522ce41d9fc8509da65858c75bf5b3c4dae2d8c04Douglas Gregor Align = 8; 14768389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner break; 14778389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner } 14781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14791d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (const EnumType *ET = dyn_cast<EnumType>(TT)) 14807176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner return getTypeInfo(ET->getDecl()->getIntegerType()); 14817176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner 14821d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const RecordType *RT = cast<RecordType>(TT); 14837176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); 1484dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck Width = toBits(Layout.getSize()); 1485dac54c124e302d6f028ea5723c425b7f66fc7c71Ken Dyck Align = toBits(Layout.getAlignment()); 1486dc0d73e6495404418acf8548875aeaff07791a74Chris Lattner break; 1487a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 14887532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 14899fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner case Type::SubstTemplateTypeParm: 149049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return getTypeInfo(cast<SubstTemplateTypeParmType>(T)-> 149149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall getReplacementType().getTypePtr()); 149249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 149334b41d939a1328f484511c6002ba2456db879a29Richard Smith case Type::Auto: { 149434b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *A = cast<AutoType>(T); 149534b41d939a1328f484511c6002ba2456db879a29Richard Smith assert(A->isDeduced() && "Cannot request the size of a dependent type"); 1496dc856aff4428380baa9afb5577ea04f8fb6beb13Matt Beaumont-Gay return getTypeInfo(A->getDeducedType().getTypePtr()); 149734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 149834b41d939a1328f484511c6002ba2456db879a29Richard Smith 1499075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case Type::Paren: 1500075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr()); 1501075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 150218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::Typedef: { 1503162e1c1b487352434552147967c3dd296ebee2f7Richard Smith const TypedefNameDecl *Typedef = cast<TypedefType>(T)->getDecl(); 1504df1367af26cb2959775e9511108f12dcd2370a27Douglas Gregor std::pair<uint64_t, unsigned> Info 1505df1367af26cb2959775e9511108f12dcd2370a27Douglas Gregor = getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); 1506c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner // If the typedef has an aligned attribute on it, it overrides any computed 1507c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner // alignment we have. This violates the GCC documentation (which says that 1508c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner // attribute(aligned) can only round up) but matches its implementation. 1509c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner if (unsigned AttrAlign = Typedef->getMaxAlignment()) 1510c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner Align = AttrAlign; 1511c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner else 1512c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner Align = Info.second; 1513df1367af26cb2959775e9511108f12dcd2370a27Douglas Gregor Width = Info.first; 15147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor break; 15157176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner } 151618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 151718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOfExpr: 151818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType() 151918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor .getTypePtr()); 152018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 152118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOf: 152218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfType>(T)->getUnderlyingType().getTypePtr()); 152318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 1524395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson case Type::Decltype: 1525395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return getTypeInfo(cast<DecltypeType>(T)->getUnderlyingExpr()->getType() 1526395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson .getTypePtr()); 1527395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 1528ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt case Type::UnaryTransform: 1529ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return getTypeInfo(cast<UnaryTransformType>(T)->getUnderlyingType()); 1530ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1531465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Type::Elaborated: 1532465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return getTypeInfo(cast<ElaboratedType>(T)->getNamedType().getTypePtr()); 15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall case Type::Attributed: 15359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return getTypeInfo( 15369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall cast<AttributedType>(T)->getEquivalentType().getTypePtr()); 15379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 15383e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith case Type::TemplateSpecialization: { 15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(getCanonicalType(T) != T && 154018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor "Cannot request the size of a dependent type"); 15413e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith const TemplateSpecializationType *TST = cast<TemplateSpecializationType>(T); 15423e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // A type alias template specialization may refer to a typedef with the 15433e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // aligned attribute on it. 15443e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (TST->isTypeAlias()) 15453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return getTypeInfo(TST->getAliasedType().getTypePtr()); 15463e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith else 15473e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return getTypeInfo(getCanonicalType(T)); 15483e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 15493e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 1550b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: { 15512be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman std::pair<uint64_t, unsigned> Info 15522be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman = getTypeInfo(cast<AtomicType>(T)->getValueType()); 15532be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman Width = Info.first; 15542be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman Align = Info.second; 15552be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman if (Width != 0 && Width <= Target->getMaxAtomicPromoteWidth() && 15562be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman llvm::isPowerOf2_64(Width)) { 15572be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // We can potentially perform lock-free atomic operations for this 15582be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // type; promote the alignment appropriately. 15592be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // FIXME: We could potentially promote the width here as well... 15602be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // is that worthwhile? (Non-struct atomic types generally have 15612be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // power-of-two size anyway, but structs might not. Requires a bit 15622be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // of implementation work to make sure we zero out the extra bits.) 15632be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman Align = static_cast<unsigned>(Width); 15642be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman } 1565b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1566b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 156718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor } 15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15692be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman assert(llvm::isPowerOf2_32(Align) && "Alignment must be power of 2"); 15709e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner return std::make_pair(Width, Align); 1571a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner} 1572a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 1573eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck/// toCharUnitsFromBits - Convert a size in bits to a size in characters. 1574eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen DyckCharUnits ASTContext::toCharUnitsFromBits(int64_t BitSize) const { 1575eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return CharUnits::fromQuantity(BitSize / getCharWidth()); 1576eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck} 1577eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck 1578dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck/// toBits - Convert a size in characters to a size in characters. 1579dd76a9ab9ea675671200f94b18ce95766841952bKen Dyckint64_t ASTContext::toBits(CharUnits CharSize) const { 1580dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck return CharSize.getQuantity() * getCharWidth(); 1581dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck} 1582dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck 1583bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck/// getTypeSizeInChars - Return the size of the specified type, in characters. 1584bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck/// This method does not work on incomplete types. 15854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeSizeInChars(QualType T) const { 1586eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeSize(T)); 1587bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck} 15884ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeSizeInChars(const Type *T) const { 1589eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeSize(T)); 1590bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck} 1591bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck 159216e20cce43385001f33f8e3f90ee345609c805d1Ken Dyck/// getTypeAlignInChars - Return the ABI-specified alignment of a type, in 159386fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck/// characters. This method does not work on incomplete types. 15944ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeAlignInChars(QualType T) const { 1595eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeAlign(T)); 159686fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck} 15974ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeAlignInChars(const Type *T) const { 1598eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeAlign(T)); 159986fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck} 160086fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck 160134ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// getPreferredTypeAlign - Return the "preferred" alignment of the specified 160234ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// type for the current target in bits. This can be different than the ABI 160334ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// alignment in cases where it is beneficial for performance to overalign 160434ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// a data type. 16054ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned ASTContext::getPreferredTypeAlign(const Type *T) const { 160634ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner unsigned ABIAlign = getTypeAlign(T); 16071eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 16081eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman // Double and long long should be naturally aligned if possible. 1609183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType* CT = T->getAs<ComplexType>()) 16101eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman T = CT->getElementType().getTypePtr(); 16111eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman if (T->isSpecificBuiltinType(BuiltinType::Double) || 1612cde7a1dc68af2eb063a039b5a31c3b7dd92b1aa9Chad Rosier T->isSpecificBuiltinType(BuiltinType::LongLong) || 1613cde7a1dc68af2eb063a039b5a31c3b7dd92b1aa9Chad Rosier T->isSpecificBuiltinType(BuiltinType::ULongLong)) 16141eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman return std::max(ABIAlign, (unsigned)getTypeSize(T)); 16151eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 161634ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner return ABIAlign; 161734ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner} 161834ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner 16192c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// DeepCollectObjCIvars - 16202c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// This routine first collects all declared, but not synthesized, ivars in 16212c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// super class and then collects all ivars, including those synthesized for 16222c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// current class. This routine is used for implementation of current class 16232c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// when all ivars, declared and synthesized are known. 16249820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian/// 16252c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanianvoid ASTContext::DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, 16262c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian bool leafClass, 1627db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const { 16282c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian if (const ObjCInterfaceDecl *SuperClass = OI->getSuperClass()) 16292c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian DeepCollectObjCIvars(SuperClass, false, Ivars); 16302c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian if (!leafClass) { 16312c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(), 16322c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian E = OI->ivar_end(); I != E; ++I) 1633581deb3da481053c4993c7600f97acf7768caac5David Blaikie Ivars.push_back(*I); 16343060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 1635bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian ObjCInterfaceDecl *IDecl = const_cast<ObjCInterfaceDecl *>(OI); 1636db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose for (const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv; 1637bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian Iv= Iv->getNextIvar()) 1638bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian Ivars.push_back(Iv); 1639bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian } 16409820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian} 16419820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian 1642e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// CollectInheritedProtocols - Collect all protocols in current class and 1643e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// those inherited by it. 1644e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanianvoid ASTContext::CollectInheritedProtocols(const Decl *CDecl, 1645432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols) { 1646e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (const ObjCInterfaceDecl *OI = dyn_cast<ObjCInterfaceDecl>(CDecl)) { 164753b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek // We can use protocol_iterator here instead of 164853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek // all_referenced_protocol_iterator since we are walking all categories. 164953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek for (ObjCInterfaceDecl::all_protocol_iterator P = OI->all_referenced_protocol_begin(), 165053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek PE = OI->all_referenced_protocol_end(); P != PE; ++P) { 1651e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian ObjCProtocolDecl *Proto = (*P); 16523fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert(Proto->getCanonicalDecl()); 1653e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(), 1654b2f812165676230bce5d0215e49a4749c451ca9cFariborz Jahanian PE = Proto->protocol_end(); P != PE; ++P) { 16553fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert((*P)->getCanonicalDecl()); 1656e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(*P, Protocols); 1657e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1658b2f812165676230bce5d0215e49a4749c451ca9cFariborz Jahanian } 1659e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 1660e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian // Categories of this Interface. 1661e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (const ObjCCategoryDecl *CDeclChain = OI->getCategoryList(); 1662e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CDeclChain; CDeclChain = CDeclChain->getNextClassCategory()) 1663e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(CDeclChain, Protocols); 1664e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (ObjCInterfaceDecl *SD = OI->getSuperClass()) 1665e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian while (SD) { 1666e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(SD, Protocols); 1667e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian SD = SD->getSuperClass(); 1668e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1669b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer } else if (const ObjCCategoryDecl *OC = dyn_cast<ObjCCategoryDecl>(CDecl)) { 167053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek for (ObjCCategoryDecl::protocol_iterator P = OC->protocol_begin(), 1671e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = OC->protocol_end(); P != PE; ++P) { 1672e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian ObjCProtocolDecl *Proto = (*P); 16733fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert(Proto->getCanonicalDecl()); 1674e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(), 1675e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = Proto->protocol_end(); P != PE; ++P) 1676e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(*P, Protocols); 1677e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1678b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer } else if (const ObjCProtocolDecl *OP = dyn_cast<ObjCProtocolDecl>(CDecl)) { 1679e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = OP->protocol_begin(), 1680e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = OP->protocol_end(); P != PE; ++P) { 1681e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian ObjCProtocolDecl *Proto = (*P); 16823fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert(Proto->getCanonicalDecl()); 1683e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(), 1684e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = Proto->protocol_end(); P != PE; ++P) 1685e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(*P, Protocols); 1686e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1687e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1688e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian} 1689e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 16904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned ASTContext::CountNonClassIvars(const ObjCInterfaceDecl *OI) const { 16913bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian unsigned count = 0; 16923bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian // Count ivars declared in class extension. 169380aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian for (const ObjCCategoryDecl *CDecl = OI->getFirstClassExtension(); CDecl; 169480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian CDecl = CDecl->getNextClassExtension()) 1695b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer count += CDecl->ivar_size(); 1696b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer 16973bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian // Count ivar defined in this class's implementation. This 16983bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian // includes synthesized ivars. 16993bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) 1700b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer count += ImplDecl->ivar_size(); 1701b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer 17028e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian return count; 17038e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian} 17048e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 17058deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidisbool ASTContext::isSentinelNullExpr(const Expr *E) { 17068deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (!E) 17078deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis return false; 17088deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 17098deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis // nullptr_t is always treated as null. 17108deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (E->getType()->isNullPtrType()) return true; 17118deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 17128deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (E->getType()->isAnyPointerType() && 17138deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis E->IgnoreParenCasts()->isNullPointerConstant(*this, 17148deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis Expr::NPC_ValueDependentIsNull)) 17158deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis return true; 17168deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 17178deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis // Unfortunately, __null has type 'int'. 17188deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (isa<GNUNullExpr>(E)) return true; 17198deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 17208deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis return false; 17218deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis} 17228deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 17238a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists. 17248a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCImplementationDecl *ASTContext::getObjCImplementation(ObjCInterfaceDecl *D) { 17258a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 17268a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 17278a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 17288a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCImplementationDecl>(I->second); 17298a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 17308a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 17318a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists. 17328a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCCategoryImplDecl *ASTContext::getObjCImplementation(ObjCCategoryDecl *D) { 17338a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 17348a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 17358a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 17368a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCCategoryImplDecl>(I->second); 17378a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 17388a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 17398a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 17408a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCInterfaceDecl. 17418a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCInterfaceDecl *IFaceD, 17428a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImplementationDecl *ImplD) { 17438a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(IFaceD && ImplD && "Passed null params"); 17448a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[IFaceD] = ImplD; 17458a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 17468a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCCategoryDecl. 17478a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCCategoryDecl *CatD, 17488a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCCategoryImplDecl *ImplD) { 17498a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(CatD && ImplD && "Passed null params"); 17508a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[CatD] = ImplD; 17518a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 17528a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 175387ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios KyrtzidisObjCInterfaceDecl *ASTContext::getObjContainingInterface(NamedDecl *ND) const { 175487ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ND->getDeclContext())) 175587ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return ID; 175687ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(ND->getDeclContext())) 175787ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return CD->getClassInterface(); 175887ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(ND->getDeclContext())) 175987ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return IMD->getClassInterface(); 176087ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis 176187ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return 0; 176287ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis} 176387ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis 17641ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian/// \brief Get the copy initialization expression of VarDecl,or NULL if 17651ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian/// none exists. 1766830937bc1100fba7682f7c32c40512085870f50cFariborz JahanianExpr *ASTContext::getBlockVarCopyInits(const VarDecl*VD) { 1767d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian assert(VD && "Passed null params"); 1768d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian assert(VD->hasAttr<BlocksAttr>() && 1769d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian "getBlockVarCopyInits - not __block var"); 1770830937bc1100fba7682f7c32c40512085870f50cFariborz Jahanian llvm::DenseMap<const VarDecl*, Expr*>::iterator 1771d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian I = BlockVarCopyInits.find(VD); 17721ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian return (I != BlockVarCopyInits.end()) ? cast<Expr>(I->second) : 0; 17731ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian} 17741ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian 17751ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian/// \brief Set the copy inialization expression of a block var decl. 17761ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanianvoid ASTContext::setBlockVarCopyInits(VarDecl*VD, Expr* Init) { 17771ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian assert(VD && Init && "Passed null params"); 1778d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian assert(VD->hasAttr<BlocksAttr>() && 1779d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian "setBlockVarCopyInits - not __block var"); 17801ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian BlockVarCopyInits[VD] = Init; 17811ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian} 17821ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian 1783a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCallTypeSourceInfo *ASTContext::CreateTypeSourceInfo(QualType T, 17844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned DataSize) const { 1785109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall if (!DataSize) 1786109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall DataSize = TypeLoc::getFullDataSizeForType(T); 1787109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall else 1788109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall assert(DataSize == TypeLoc::getFullDataSizeForType(T) && 1789a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall "incorrect data size provided to CreateTypeSourceInfo!"); 1790109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall 1791a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *TInfo = 1792a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall (TypeSourceInfo*)BumpAlloc.Allocate(sizeof(TypeSourceInfo) + DataSize, 8); 1793a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall new (TInfo) TypeSourceInfo(T); 1794a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TInfo; 1795b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis} 1796b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1797a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCallTypeSourceInfo *ASTContext::getTrivialTypeSourceInfo(QualType T, 17986952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor SourceLocation L) const { 1799a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = CreateTypeSourceInfo(T); 1800c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor DI->getTypeLoc().initialize(const_cast<ASTContext &>(*this), L); 1801a4eb74d4dfe126c686dc708fec444c85ffb73b47John McCall return DI; 1802a4eb74d4dfe126c686dc708fec444c85ffb73b47John McCall} 1803a4eb74d4dfe126c686dc708fec444c85ffb73b47John McCall 1804b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 18054ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const { 1806b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D, 0); 1807b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 1808b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 1809b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 18104ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getASTObjCImplementationLayout( 18114ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ObjCImplementationDecl *D) const { 1812b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D->getClassInterface(), D); 1813b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 1814b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 1815a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 1816a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner// Type creation/memoization methods 1817a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 1818a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 18194ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 18203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallASTContext::getExtQualType(const Type *baseType, Qualifiers quals) const { 18213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned fastQuals = quals.getFastQualifiers(); 18223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall quals.removeFastQualifiers(); 18230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 18240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Check if we've already instantiated this type. 18250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::FoldingSetNodeID ID; 18263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals::Profile(ID, baseType, quals); 18273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void *insertPos = 0; 18283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (ExtQuals *eq = ExtQualNodes.FindNodeOrInsertPos(ID, insertPos)) { 18293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(eq->getQualifiers() == quals); 18303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(eq, fastQuals); 18310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 18320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 18333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the base type is not canonical, make the appropriate canonical type. 18343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon; 18353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!baseType->isCanonicalUnqualified()) { 18363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = baseType->getCanonicalTypeInternal().split(); 1837200fa53fd420aa8369586f569dbece04930ad6a3John McCall canonSplit.Quals.addConsistentQualifiers(quals); 1838200fa53fd420aa8369586f569dbece04930ad6a3John McCall canon = getExtQualType(canonSplit.Ty, canonSplit.Quals); 18393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 18403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Re-find the insert position. 18413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos); 18423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 18433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 18443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals *eq = new (*this, TypeAlignment) ExtQuals(baseType, canon, quals); 18453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQualNodes.InsertNode(eq, insertPos); 18463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(eq, fastQuals); 18470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 18480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 18494ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 18504ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getAddrSpaceQualType(QualType T, unsigned AddressSpace) const { 1851f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType CanT = getCanonicalType(T); 1852f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner if (CanT.getAddressSpace() == AddressSpace) 1853f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return T; 1854b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner 18550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If we are composing extended qualifiers together, merge together 18560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into one ExtQuals node. 18570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 18580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *TypeNode = Quals.strip(T); 18591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this type already has an address space specified, it cannot get 18610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // another one. 18620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasAddressSpace() && 18630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "Type cannot be in multiple addr spaces!"); 18640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addAddressSpace(AddressSpace); 18651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getExtQualType(TypeNode, Quals); 1867ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1868ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1869b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris LattnerQualType ASTContext::getObjCGCQualType(QualType T, 18704ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Qualifiers::GC GCAttr) const { 1871d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CanT = getCanonicalType(T); 1872b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner if (CanT.getObjCGCAttr() == GCAttr) 1873d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return T; 18741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18757f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (const PointerType *ptr = T->getAs<PointerType>()) { 18767f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall QualType Pointee = ptr->getPointeeType(); 187758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff if (Pointee->isAnyPointerType()) { 18784027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian QualType ResultType = getObjCGCQualType(Pointee, GCAttr); 18794027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian return getPointerType(ResultType); 18804027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 18814027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If we are composing extended qualifiers together, merge together 18840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into one ExtQuals node. 18850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 18860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *TypeNode = Quals.strip(T); 18871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this type already has an ObjCGC specified, it cannot get 18890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // another one. 18900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasObjCGCAttr() && 18910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "Type cannot have multiple ObjCGCs!"); 18920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addObjCGCAttr(GCAttr); 18931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getExtQualType(TypeNode, Quals); 1895d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 1896a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 1897e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCallconst FunctionType *ASTContext::adjustFunctionType(const FunctionType *T, 1898e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FunctionType::ExtInfo Info) { 1899e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (T->getExtInfo() == Info) 1900e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return T; 1901e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 1902e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType Result; 1903e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (const FunctionNoProtoType *FNPT = dyn_cast<FunctionNoProtoType>(T)) { 1904e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Result = getFunctionNoProtoType(FNPT->getResultType(), Info); 1905e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } else { 1906e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 1907e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); 1908e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall EPI.ExtInfo = Info; 1909e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Result = getFunctionType(FPT->getResultType(), FPT->arg_type_begin(), 1910e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FPT->getNumArgs(), EPI); 1911e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 1912e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 1913e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return cast<FunctionType>(Result.getTypePtr()); 1914e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall} 1915e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 19165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getComplexType - Return the uniqued reference to the type for a complex 19175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// number with the specified element type. 19184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getComplexType(QualType T) const { 19195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 19215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 19225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType::Profile(ID, T); 19231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 19255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos)) 19265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(CT, 0); 19271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 19295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 19305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 1931467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!T.isCanonical()) { 1932f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getComplexType(getCanonicalType(T)); 19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 19355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos); 1936c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 19375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ComplexType *New = new (*this, TypeAlignment) ComplexType(T, Canonical); 19395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 19405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexTypes.InsertNode(New, InsertPos); 19415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 19425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 19435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getPointerType - Return the uniqued reference to the type for a pointer to 19455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the specified type. 19464ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getPointerType(QualType T) const { 19475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 19485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 19495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType::Profile(ID, T); 19511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 19535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 19545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(PT, 0); 19551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 19575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 19585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 1959467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!T.isCanonical()) { 1960f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getPointerType(getCanonicalType(T)); 19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 19635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1964c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 19655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19666b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall PointerType *New = new (*this, TypeAlignment) PointerType(T, Canonical); 19675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 19685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerTypes.InsertNode(New, InsertPos); 19695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 19705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 19715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getBlockPointerType - Return the uniqued reference to the type for 19735618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// a pointer to the specified block. 19744ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getBlockPointerType(QualType T) const { 1975296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff assert(T->isFunctionType() && "block of function types only"); 1976296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // Unique pointers, to guarantee there is only one block of a particular 19775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // structure. 19785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff llvm::FoldingSetNodeID ID; 19795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType::Profile(ID, T); 19801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19815618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void *InsertPos = 0; 19825618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff if (BlockPointerType *PT = 19835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 19845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(PT, 0); 19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the block pointee type isn't canonical, this won't be a canonical 19875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // type either so fill in the canonical type field. 19885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType Canonical; 1989467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!T.isCanonical()) { 19905618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Canonical = getBlockPointerType(getCanonicalType(T)); 19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the new insert position for the node we care about. 19935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType *NewIP = 19945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1995c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 19965618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 19976b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall BlockPointerType *New 19986b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) BlockPointerType(T, Canonical); 19995618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Types.push_back(New); 20005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.InsertNode(New, InsertPos); 20015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(New, 0); 20025618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 20035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 20047c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getLValueReferenceType - Return the uniqued reference to the type for an 20057c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// lvalue reference to the specified type. 20064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 20074ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const { 20089625e44c0252485277a340746ed8ac950686156fDouglas Gregor assert(getCanonicalType(T) != OverloadTy && 20099625e44c0252485277a340746ed8ac950686156fDouglas Gregor "Unresolved overloaded function type"); 20109625e44c0252485277a340746ed8ac950686156fDouglas Gregor 20115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 20125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 20135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 201454e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType::Profile(ID, T, SpelledAsLValue); 20155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 20177c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (LValueReferenceType *RT = 20187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 20195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(RT, 0); 20207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 202154e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *InnerRef = T->getAs<ReferenceType>(); 202254e14c4db764c0636160d26c5bbf491637c83a76John McCall 20235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the referencee type isn't canonical, this won't be a canonical type 20245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // either, so fill in the canonical type field. 20255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 202654e14c4db764c0636160d26c5bbf491637c83a76John McCall if (!SpelledAsLValue || InnerRef || !T.isCanonical()) { 202754e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T); 202854e14c4db764c0636160d26c5bbf491637c83a76John McCall Canonical = getLValueReferenceType(getCanonicalType(PointeeType)); 20297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 20307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Get the new insert position for the node we care about. 20317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType *NewIP = 20327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 2033c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 20347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 20357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 20366b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall LValueReferenceType *New 203754e14c4db764c0636160d26c5bbf491637c83a76John McCall = new (*this, TypeAlignment) LValueReferenceType(T, Canonical, 203854e14c4db764c0636160d26c5bbf491637c83a76John McCall SpelledAsLValue); 20397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Types.push_back(New); 20407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.InsertNode(New, InsertPos); 204154e14c4db764c0636160d26c5bbf491637c83a76John McCall 20427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(New, 0); 20437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 20447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 20457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getRValueReferenceType - Return the uniqued reference to the type for an 20467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// rvalue reference to the specified type. 20474ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getRValueReferenceType(QualType T) const { 20487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 20497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // structure. 20507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl llvm::FoldingSetNodeID ID; 205154e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType::Profile(ID, T, false); 20527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 20537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl void *InsertPos = 0; 20547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (RValueReferenceType *RT = 20557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 20567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(RT, 0); 20577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 205854e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *InnerRef = T->getAs<ReferenceType>(); 205954e14c4db764c0636160d26c5bbf491637c83a76John McCall 20607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // If the referencee type isn't canonical, this won't be a canonical type 20617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // either, so fill in the canonical type field. 20627c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl QualType Canonical; 206354e14c4db764c0636160d26c5bbf491637c83a76John McCall if (InnerRef || !T.isCanonical()) { 206454e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T); 206554e14c4db764c0636160d26c5bbf491637c83a76John McCall Canonical = getRValueReferenceType(getCanonicalType(PointeeType)); 20667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 20675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 20687c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType *NewIP = 20697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 2070c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 20715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20736b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall RValueReferenceType *New 20746b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) RValueReferenceType(T, Canonical); 20755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 20767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.InsertNode(New, InsertPos); 20775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 20785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 20795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2080f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// getMemberPointerType - Return the uniqued reference to the type for a 2081f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// member pointer to the specified type, in the specified class. 20824ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getMemberPointerType(QualType T, const Type *Cls) const { 2083f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 2084f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // structure. 2085f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl llvm::FoldingSetNodeID ID; 2086f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType::Profile(ID, T, Cls); 2087f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2088f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void *InsertPos = 0; 2089f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (MemberPointerType *PT = 2090f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 2091f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(PT, 0); 2092f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2093f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // If the pointee or class type isn't canonical, this won't be a canonical 2094f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // type either, so fill in the canonical type field. 2095f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType Canonical; 209687c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor if (!T.isCanonical() || !Cls->isCanonicalUnqualified()) { 2097f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Canonical = getMemberPointerType(getCanonicalType(T),getCanonicalType(Cls)); 2098f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2099f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Get the new insert position for the node we care about. 2100f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType *NewIP = 2101f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 2102c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 2103f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 21046b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall MemberPointerType *New 21056b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) MemberPointerType(T, Cls, Canonical); 2106f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Types.push_back(New); 2107f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.InsertNode(New, InsertPos); 2108f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(New, 0); 2109f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2110f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 21111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getConstantArrayType - Return the unique reference to the type for an 2112fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff/// array of the specified element type. 21131eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getConstantArrayType(QualType EltTy, 211438aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner const llvm::APInt &ArySizeIn, 2115c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 211663e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara unsigned IndexTypeQuals) const { 2117923d56d436f750bc1f29db50e641078725558a1bSebastian Redl assert((EltTy->isDependentType() || 2118923d56d436f750bc1f29db50e641078725558a1bSebastian Redl EltTy->isIncompleteType() || EltTy->isConstantSizeType()) && 2119587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman "Constant array of VLAs is illegal!"); 2120587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman 212138aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // Convert the array size into a canonical width matching the pointer size for 212238aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // the target. 212338aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner llvm::APInt ArySize(ArySizeIn); 21249f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad ArySize = 2125bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor ArySize.zextOrTrunc(Target->getPointerWidth(getTargetAddressSpace(EltTy))); 21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 212863e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara ConstantArrayType::Profile(ID, EltTy, ArySize, ASM, IndexTypeQuals); 21291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (ConstantArrayType *ATP = 21327192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) 21335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(ATP, 0); 21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the element type isn't canonical or has qualifiers, this won't 21363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // be a canonical type either, so fill in the canonical type field. 21373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType Canon; 21383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) { 21393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = getCanonicalType(EltTy).split(); 2140200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getConstantArrayType(QualType(canonSplit.Ty, 0), ArySize, 214163e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara ASM, IndexTypeQuals); 2142200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getQualifiedType(Canon, canonSplit.Quals); 21433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 21445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 21451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ConstantArrayType *NewIP = 21467192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos); 2147c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 21485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21506b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ConstantArrayType *New = new(*this,TypeAlignment) 215163e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara ConstantArrayType(EltTy, Canon, ArySize, ASM, IndexTypeQuals); 21527192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.InsertNode(New, InsertPos); 21535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 21545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 21555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 21565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2157ce8890371fcdb983ae487c87fa40606a34896ff7John McCall/// getVariableArrayDecayedType - Turns the given type, which may be 2158ce8890371fcdb983ae487c87fa40606a34896ff7John McCall/// variably-modified, into the corresponding type with all the known 2159ce8890371fcdb983ae487c87fa40606a34896ff7John McCall/// sizes replaced with [*]. 2160ce8890371fcdb983ae487c87fa40606a34896ff7John McCallQualType ASTContext::getVariableArrayDecayedType(QualType type) const { 2161ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Vastly most common case. 2162ce8890371fcdb983ae487c87fa40606a34896ff7John McCall if (!type->isVariablyModifiedType()) return type; 2163ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2164ce8890371fcdb983ae487c87fa40606a34896ff7John McCall QualType result; 2165ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2166ce8890371fcdb983ae487c87fa40606a34896ff7John McCall SplitQualType split = type.getSplitDesugaredType(); 2167200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Type *ty = split.Ty; 2168ce8890371fcdb983ae487c87fa40606a34896ff7John McCall switch (ty->getTypeClass()) { 2169ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#define TYPE(Class, Base) 2170ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#define ABSTRACT_TYPE(Class, Base) 2171ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 2172ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#include "clang/AST/TypeNodes.def" 2173ce8890371fcdb983ae487c87fa40606a34896ff7John McCall llvm_unreachable("didn't desugar past all non-canonical types?"); 2174ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2175ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // These types should never be variably-modified. 2176ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Builtin: 2177ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Complex: 2178ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Vector: 2179ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ExtVector: 2180ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentSizedExtVector: 2181ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ObjCObject: 2182ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ObjCInterface: 2183ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ObjCObjectPointer: 2184ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Record: 2185ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Enum: 2186ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::UnresolvedUsing: 2187ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TypeOfExpr: 2188ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TypeOf: 2189ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Decltype: 2190ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt case Type::UnaryTransform: 2191ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentName: 2192ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::InjectedClassName: 2193ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TemplateSpecialization: 2194ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentTemplateSpecialization: 2195ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TemplateTypeParm: 2196ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::SubstTemplateTypeParmPack: 219734b41d939a1328f484511c6002ba2456db879a29Richard Smith case Type::Auto: 2198ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::PackExpansion: 2199ce8890371fcdb983ae487c87fa40606a34896ff7John McCall llvm_unreachable("type should never be variably-modified"); 2200ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2201ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // These types can be variably-modified but should never need to 2202ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // further decay. 2203ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::FunctionNoProto: 2204ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::FunctionProto: 2205ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::BlockPointer: 2206ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::MemberPointer: 2207ce8890371fcdb983ae487c87fa40606a34896ff7John McCall return type; 2208ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2209ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // These types can be variably-modified. All these modifications 2210ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // preserve structure except as noted by comments. 2211ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // TODO: if we ever care about optimizing VLAs, there are no-op 2212ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // optimizations available here. 2213ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Pointer: 2214ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getPointerType(getVariableArrayDecayedType( 2215ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cast<PointerType>(ty)->getPointeeType())); 2216ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2217ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2218ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::LValueReference: { 2219ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const LValueReferenceType *lv = cast<LValueReferenceType>(ty); 2220ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getLValueReferenceType( 2221ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(lv->getPointeeType()), 2222ce8890371fcdb983ae487c87fa40606a34896ff7John McCall lv->isSpelledAsLValue()); 2223ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2224745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2225ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2226ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::RValueReference: { 2227ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const RValueReferenceType *lv = cast<RValueReferenceType>(ty); 2228ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getRValueReferenceType( 2229ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(lv->getPointeeType())); 2230ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2231745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2232745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 2233b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: { 2234b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman const AtomicType *at = cast<AtomicType>(ty); 2235b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman result = getAtomicType(getVariableArrayDecayedType(at->getValueType())); 2236b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman break; 2237b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 2238b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 2239ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ConstantArray: { 2240ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const ConstantArrayType *cat = cast<ConstantArrayType>(ty); 2241ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getConstantArrayType( 2242ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(cat->getElementType()), 2243ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cat->getSize(), 2244ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cat->getSizeModifier(), 2245ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cat->getIndexTypeCVRQualifiers()); 2246ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2247745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2248745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 2249ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentSizedArray: { 2250ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const DependentSizedArrayType *dat = cast<DependentSizedArrayType>(ty); 2251ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getDependentSizedArrayType( 2252ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(dat->getElementType()), 2253ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getSizeExpr(), 2254ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getSizeModifier(), 2255ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getIndexTypeCVRQualifiers(), 2256ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getBracketsRange()); 2257ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2258ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2259ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2260ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Turn incomplete types into [*] types. 2261ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::IncompleteArray: { 2262ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const IncompleteArrayType *iat = cast<IncompleteArrayType>(ty); 2263ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getVariableArrayType( 2264ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(iat->getElementType()), 2265ce8890371fcdb983ae487c87fa40606a34896ff7John McCall /*size*/ 0, 2266ce8890371fcdb983ae487c87fa40606a34896ff7John McCall ArrayType::Normal, 2267ce8890371fcdb983ae487c87fa40606a34896ff7John McCall iat->getIndexTypeCVRQualifiers(), 2268ce8890371fcdb983ae487c87fa40606a34896ff7John McCall SourceRange()); 2269ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2270ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2271ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2272ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Turn VLA types into [*] types. 2273ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::VariableArray: { 2274ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const VariableArrayType *vat = cast<VariableArrayType>(ty); 2275ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getVariableArrayType( 2276ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(vat->getElementType()), 2277ce8890371fcdb983ae487c87fa40606a34896ff7John McCall /*size*/ 0, 2278ce8890371fcdb983ae487c87fa40606a34896ff7John McCall ArrayType::Star, 2279ce8890371fcdb983ae487c87fa40606a34896ff7John McCall vat->getIndexTypeCVRQualifiers(), 2280ce8890371fcdb983ae487c87fa40606a34896ff7John McCall vat->getBracketsRange()); 2281ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2282ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2283ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2284ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2285ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Apply the top-level qualifiers from the original. 2286200fa53fd420aa8369586f569dbece04930ad6a3John McCall return getQualifiedType(result, split.Quals); 2287ce8890371fcdb983ae487c87fa40606a34896ff7John McCall} 2288745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 2289bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// getVariableArrayType - Returns a non-unique reference to the type for a 2290bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// variable array of the specified element type. 22917e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType ASTContext::getVariableArrayType(QualType EltTy, 22927e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *NumElts, 2293c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 229463e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara unsigned IndexTypeQuals, 22954ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad SourceRange Brackets) const { 2296c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Since we don't unique expressions, it isn't possible to unique VLA's 2297c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // that have an expression provided for their size. 22983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType Canon; 2299715e9c8a39437347e838aa108df443fe1086d359Douglas Gregor 23003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Be sure to pull qualifiers off the element type. 23013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) { 23023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = getCanonicalType(EltTy).split(); 2303200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getVariableArrayType(QualType(canonSplit.Ty, 0), NumElts, ASM, 230463e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara IndexTypeQuals, Brackets); 2305200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getQualifiedType(Canon, canonSplit.Quals); 2306715e9c8a39437347e838aa108df443fe1086d359Douglas Gregor } 2307715e9c8a39437347e838aa108df443fe1086d359Douglas Gregor 23086b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VariableArrayType *New = new(*this, TypeAlignment) 230963e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals, Brackets); 2310c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2311c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman VariableArrayTypes.push_back(New); 2312c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman Types.push_back(New); 2313c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return QualType(New, 0); 2314c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman} 2315c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2316898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// getDependentSizedArrayType - Returns a non-unique reference to 2317898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// the type for a dependently-sized array of the specified element 231804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor/// type. 23193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getDependentSizedArrayType(QualType elementType, 23203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *numElements, 2321898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ArrayType::ArraySizeModifier ASM, 23223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned elementTypeQuals, 23233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SourceRange brackets) const { 23243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert((!numElements || numElements->isTypeDependent() || 23253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall numElements->isValueDependent()) && 2326898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor "Size must be type- or value-dependent!"); 2327898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 23283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Dependently-sized array types that do not have a specified number 23293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // of elements will have their sizes deduced from a dependent 23303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // initializer. We do no canonicalization here at all, which is okay 23313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // because they can't be used in most locations. 23323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!numElements) { 23333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType *newType 23343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = new (*this, TypeAlignment) 23353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType(*this, elementType, QualType(), 23363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall numElements, ASM, elementTypeQuals, 23373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall brackets); 23383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(newType); 23393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(newType, 0); 2340cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor } 2341cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor 23423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Otherwise, we actually build a new type every time, but we 23433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // also build a canonical type. 23441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonElementType = getCanonicalType(elementType).split(); 2346898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 23473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void *insertPos = 0; 23483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall llvm::FoldingSetNodeID ID; 23493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType::Profile(ID, *this, 2350200fa53fd420aa8369586f569dbece04930ad6a3John McCall QualType(canonElementType.Ty, 0), 23513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ASM, elementTypeQuals, numElements); 23523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Look for an existing type with these properties. 23543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType *canonTy = 23553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayTypes.FindNodeOrInsertPos(ID, insertPos); 23563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If we don't have one, build one. 23583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!canonTy) { 23593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canonTy = new (*this, TypeAlignment) 2360200fa53fd420aa8369586f569dbece04930ad6a3John McCall DependentSizedArrayType(*this, QualType(canonElementType.Ty, 0), 23613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType(), numElements, ASM, elementTypeQuals, 23623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall brackets); 23633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayTypes.InsertNode(canonTy, insertPos); 23643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(canonTy); 23653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 23663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Apply qualifiers from the element type to the array. 23683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon = getQualifiedType(QualType(canonTy,0), 2369200fa53fd420aa8369586f569dbece04930ad6a3John McCall canonElementType.Quals); 23703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If we didn't need extra canonicalization for the element type, 23723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // then just use that as our result. 2373200fa53fd420aa8369586f569dbece04930ad6a3John McCall if (QualType(canonElementType.Ty, 0) == elementType) 23743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return canon; 23753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Otherwise, we need to build a type which follows the spelling 23773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // of the element type. 23783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType *sugaredType 23793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = new (*this, TypeAlignment) 23803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType(*this, elementType, canon, numElements, 23813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ASM, elementTypeQuals, brackets); 23823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(sugaredType); 23833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(sugaredType, 0); 23843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 23853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getIncompleteArrayType(QualType elementType, 2387c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArrayType::ArraySizeModifier ASM, 23883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned elementTypeQuals) const { 2389c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman llvm::FoldingSetNodeID ID; 23903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType::Profile(ID, elementType, ASM, elementTypeQuals); 2391c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 23923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void *insertPos = 0; 23933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (IncompleteArrayType *iat = 23943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos)) 23953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(iat, 0); 2396c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2397c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // If the element type isn't canonical, this won't be a canonical type 23983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // either, so fill in the canonical type field. We also have to pull 23993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // qualifiers off the element type. 24003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon; 2401c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 24023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!elementType.isCanonical() || elementType.hasLocalQualifiers()) { 24033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = getCanonicalType(elementType).split(); 2404200fa53fd420aa8369586f569dbece04930ad6a3John McCall canon = getIncompleteArrayType(QualType(canonSplit.Ty, 0), 24053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ASM, elementTypeQuals); 2406200fa53fd420aa8369586f569dbece04930ad6a3John McCall canon = getQualifiedType(canon, canonSplit.Quals); 2407c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2408c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Get the new insert position for the node we care about. 24093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType *existing = 24103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos); 24113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!existing && "Shouldn't be in the map!"); (void) existing; 24122bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 2413c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 24143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType *newType = new (*this, TypeAlignment) 24153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType(elementType, canon, ASM, elementTypeQuals); 2416c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 24173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayTypes.InsertNode(newType, insertPos); 24183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(newType); 24193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(newType, 0); 2420fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff} 2421fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 242273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// getVectorType - Return the unique reference to a vector type of 242373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 242482287d19ded35248c4ce6a425ce74116a13ce44eJohn ThompsonQualType ASTContext::getVectorType(QualType vecType, unsigned NumElts, 24254ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad VectorType::VectorKind VecKind) const { 24263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(vecType->isBuiltinType()); 24271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Check if we've already instantiated a vector of this type. 24295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 2430e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::Profile(ID, vecType, NumElts, Type::Vector, VecKind); 2431788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner 24325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 24335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 24345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(VTP, 0); 24355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the element type isn't canonical, this won't be a canonical type either, 24375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 24385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 2439255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor if (!vecType.isCanonical()) { 2440231da7eb3dd13007e5e40fffe48998e5ef284e06Bob Wilson Canonical = getVectorType(getCanonicalType(vecType), NumElts, VecKind); 24411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 24435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 2444c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 24455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24466b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VectorType *New = new (*this, TypeAlignment) 2447e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType(vecType, NumElts, Canonical, VecKind); 24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorTypes.InsertNode(New, InsertPos); 24495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 24505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 24515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 24525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2453213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// getExtVectorType - Return the unique reference to an extended vector type of 245473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 24554ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 24564ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getExtVectorType(QualType vecType, unsigned NumElts) const { 24574ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor assert(vecType->isBuiltinType() || vecType->isDependentType()); 24581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 245973322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Check if we've already instantiated a vector of this type. 246073322924127c873c13101b705dd823f5539ffa5fSteve Naroff llvm::FoldingSetNodeID ID; 2461788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner VectorType::Profile(ID, vecType, NumElts, Type::ExtVector, 2462e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::GenericVector); 246373322924127c873c13101b705dd823f5539ffa5fSteve Naroff void *InsertPos = 0; 246473322924127c873c13101b705dd823f5539ffa5fSteve Naroff if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 246573322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(VTP, 0); 246673322924127c873c13101b705dd823f5539ffa5fSteve Naroff 246773322924127c873c13101b705dd823f5539ffa5fSteve Naroff // If the element type isn't canonical, this won't be a canonical type either, 246873322924127c873c13101b705dd823f5539ffa5fSteve Naroff // so fill in the canonical type field. 246973322924127c873c13101b705dd823f5539ffa5fSteve Naroff QualType Canonical; 2470467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!vecType.isCanonical()) { 2471213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman Canonical = getExtVectorType(getCanonicalType(vecType), NumElts); 24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 247373322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Get the new insert position for the node we care about. 247473322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 2475c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 247673322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 24776b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ExtVectorType *New = new (*this, TypeAlignment) 24786b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ExtVectorType(vecType, NumElts, Canonical); 247973322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorTypes.InsertNode(New, InsertPos); 248073322924127c873c13101b705dd823f5539ffa5fSteve Naroff Types.push_back(New); 248173322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(New, 0); 248273322924127c873c13101b705dd823f5539ffa5fSteve Naroff} 248373322924127c873c13101b705dd823f5539ffa5fSteve Naroff 24844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 24854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getDependentSizedExtVectorType(QualType vecType, 24864ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *SizeExpr, 24874ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad SourceLocation AttrLoc) const { 24882ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor llvm::FoldingSetNodeID ID; 24891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedExtVectorType::Profile(ID, *this, getCanonicalType(vecType), 24902ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr); 24911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24922ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void *InsertPos = 0; 24932ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *Canon 24942ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); 24952ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *New; 24962ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (Canon) { 24972ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // We already have a canonical version of this array type; use it as 24982ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // the canonical type for a newly-built type. 24996b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 25006b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, QualType(Canon, 0), 25016b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall SizeExpr, AttrLoc); 25022ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 25032ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType CanonVecTy = getCanonicalType(vecType); 25042ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (CanonVecTy == vecType) { 25056b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 25066b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, QualType(), SizeExpr, 25076b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall AttrLoc); 2508789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 2509789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentSizedExtVectorType *CanonCheck 2510789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); 2511789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!CanonCheck && "Dependent-sized ext_vector canonical type broken"); 2512789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CanonCheck; 25132ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorTypes.InsertNode(New, InsertPos); 25142ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 25152ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType Canon = getDependentSizedExtVectorType(CanonVecTy, SizeExpr, 25162ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SourceLocation()); 25176b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 25186b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, Canon, SizeExpr, AttrLoc); 25192ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 25202ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 25211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25229cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Types.push_back(New); 25239cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return QualType(New, 0); 25249cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor} 25259cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 252672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getFunctionNoProtoType - Return a K&R style C function type like 'int()'. 25275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 25284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 25294ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getFunctionNoProtoType(QualType ResultTy, 25304ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const FunctionType::ExtInfo &Info) const { 2531cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv DefaultCC = Info.getCC(); 2532cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv CallConv = (LangOpts.MRTD && DefaultCC == CC_Default) ? 2533cfe9af250f466e7e38becea4428990448ae07737Roman Divacky CC_X86StdCall : DefaultCC; 25345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 25355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 25365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 2537264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionNoProtoType::Profile(ID, ResultTy, Info); 25381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 25401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionNoProtoType *FT = 254172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 25425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FT, 0); 25431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 2545ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor if (!ResultTy.isCanonical() || 254604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall getCanonicalCallConv(CallConv) != CallConv) { 2547264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Canonical = 2548264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola getFunctionNoProtoType(getCanonicalType(ResultTy), 2549264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Info.withCallingConv(getCanonicalCallConv(CallConv))); 25501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 255272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType *NewIP = 255372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 2554c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 25555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2557cfe9af250f466e7e38becea4428990448ae07737Roman Divacky FunctionProtoType::ExtInfo newInfo = Info.withCallingConv(CallConv); 25586b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall FunctionNoProtoType *New = new (*this, TypeAlignment) 2559cfe9af250f466e7e38becea4428990448ae07737Roman Divacky FunctionNoProtoType(ResultTy, Canonical, newInfo); 25605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 256172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.InsertNode(New, InsertPos); 25625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 25635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 25645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFunctionType - Return a normal function type with a typed argument 25665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// list. isVariadic indicates whether the argument list includes '...'. 25674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 25684ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getFunctionType(QualType ResultTy, 25694ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const QualType *ArgArray, unsigned NumArgs, 25704ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const FunctionProtoType::ExtProtoInfo &EPI) const { 25715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 25725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 25735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 25748026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl FunctionProtoType::Profile(ID, ResultTy, ArgArray, NumArgs, EPI, *this); 25755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 25771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionProtoType *FTP = 257872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 25795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 2580465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2581465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Determine whether the type being created is already canonical or not. 2582eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith bool isCanonical = 2583eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith EPI.ExceptionSpecType == EST_None && ResultTy.isCanonical() && 2584eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith !EPI.HasTrailingReturn; 25855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs && isCanonical; ++i) 258654e14c4db764c0636160d26c5bbf491637c83a76John McCall if (!ArgArray[i].isCanonicalAsParam()) 25875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer isCanonical = false; 25885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2589cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv DefaultCC = EPI.ExtInfo.getCC(); 2590cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv CallConv = (LangOpts.MRTD && DefaultCC == CC_Default) ? 2591cfe9af250f466e7e38becea4428990448ae07737Roman Divacky CC_X86StdCall : DefaultCC; 2592e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 25935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If this type isn't canonical, get the canonical version of it. 2594465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // The exception spec is not part of the canonical type. 25955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 259604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall if (!isCanonical || getCanonicalCallConv(CallConv) != CallConv) { 25975f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 16> CanonicalArgs; 25985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CanonicalArgs.reserve(NumArgs); 25995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 260054e14c4db764c0636160d26c5bbf491637c83a76John McCall CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i])); 2601465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2602e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI; 2603eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith CanonicalEPI.HasTrailingReturn = false; 26048b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl CanonicalEPI.ExceptionSpecType = EST_None; 26058b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl CanonicalEPI.NumExceptions = 0; 2606e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall CanonicalEPI.ExtInfo 2607e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall = CanonicalEPI.ExtInfo.withCallingConv(getCanonicalCallConv(CallConv)); 2608e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2609f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getFunctionType(getCanonicalType(ResultTy), 2610beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad CanonicalArgs.data(), NumArgs, 2611e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall CanonicalEPI); 2612465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 26135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 261472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType *NewIP = 261572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 2616c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 26175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2618465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2619f85e193739c953358c865005855253af4f68a497John McCall // FunctionProtoType objects are allocated with extra bytes after 2620f85e193739c953358c865005855253af4f68a497John McCall // them for three variable size arrays at the end: 2621f85e193739c953358c865005855253af4f68a497John McCall // - parameter types 2622f85e193739c953358c865005855253af4f68a497John McCall // - exception types 2623f85e193739c953358c865005855253af4f68a497John McCall // - consumed-arguments flags 2624f85e193739c953358c865005855253af4f68a497John McCall // Instead of the exception types, there could be a noexcept 2625b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // expression, or information used to resolve the exception 2626b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // specification. 2627e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall size_t Size = sizeof(FunctionProtoType) + 262860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NumArgs * sizeof(QualType); 2629b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith if (EPI.ExceptionSpecType == EST_Dynamic) { 263060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Size += EPI.NumExceptions * sizeof(QualType); 2631b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) { 26328026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl Size += sizeof(Expr*); 2633e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith } else if (EPI.ExceptionSpecType == EST_Uninstantiated) { 263413bffc532bafd45d4a77867993c1afb83c7661beRichard Smith Size += 2 * sizeof(FunctionDecl*); 2635b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (EPI.ExceptionSpecType == EST_Unevaluated) { 2636b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith Size += sizeof(FunctionDecl*); 263760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2638f85e193739c953358c865005855253af4f68a497John McCall if (EPI.ConsumedArguments) 2639f85e193739c953358c865005855253af4f68a497John McCall Size += NumArgs * sizeof(bool); 2640f85e193739c953358c865005855253af4f68a497John McCall 2641e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType *FTP = (FunctionProtoType*) Allocate(Size, TypeAlignment); 2642cfe9af250f466e7e38becea4428990448ae07737Roman Divacky FunctionProtoType::ExtProtoInfo newEPI = EPI; 2643cfe9af250f466e7e38becea4428990448ae07737Roman Divacky newEPI.ExtInfo = EPI.ExtInfo.withCallingConv(CallConv); 26448026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl new (FTP) FunctionProtoType(ResultTy, ArgArray, NumArgs, Canonical, newEPI); 26455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(FTP); 264672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.InsertNode(FTP, InsertPos); 26475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 26485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 26495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26503cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall#ifndef NDEBUG 26513cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallstatic bool NeedsInjectedClassNameType(const RecordDecl *D) { 26523cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!isa<CXXRecordDecl>(D)) return false; 26533cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall const CXXRecordDecl *RD = cast<CXXRecordDecl>(D); 26543cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (isa<ClassTemplatePartialSpecializationDecl>(RD)) 26553cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return true; 26563cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (RD->getDescribedClassTemplate() && 26573cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall !isa<ClassTemplateSpecializationDecl>(RD)) 26583cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return true; 26593cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return false; 26603cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 26613cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall#endif 26623cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 26633cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// getInjectedClassNameType - Return the unique reference to the 26643cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// injected class name type for the specified templated declaration. 26653cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType ASTContext::getInjectedClassNameType(CXXRecordDecl *Decl, 26664ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType TST) const { 26673cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(NeedsInjectedClassNameType(Decl)); 26683cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (Decl->TypeForDecl) { 26693cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<InjectedClassNameType>(Decl->TypeForDecl)); 2670ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor } else if (CXXRecordDecl *PrevDecl = Decl->getPreviousDecl()) { 26713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(PrevDecl->TypeForDecl && "previous declaration has no type"); 26723cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl->TypeForDecl = PrevDecl->TypeForDecl; 26733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<InjectedClassNameType>(Decl->TypeForDecl)); 26743cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } else { 2675f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Type *newType = 267631f17ecbef57b5679c017c375db330546b7b5145John McCall new (*this, TypeAlignment) InjectedClassNameType(Decl, TST); 2677f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2678f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 26793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 26803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return QualType(Decl->TypeForDecl, 0); 26813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 26823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 26832ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// getTypeDeclType - Return the unique reference to the type for the 26842ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// specified type declaration. 26854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const { 26861e6759e9e33dcaa73ce14c8a908ac9f87ac16463Argyrios Kyrtzidis assert(Decl && "Passed null for Decl param"); 2687becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall assert(!Decl->TypeForDecl && "TypeForDecl present in slow case"); 26881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2689162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (const TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Decl)) 26902ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor return getTypedefType(Typedef); 2691becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall 2692becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall assert(!isa<TemplateTypeParmDecl>(Decl) && 2693becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall "Template type parameter types are always available."); 2694becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall 269519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall if (const RecordDecl *Record = dyn_cast<RecordDecl>(Decl)) { 2696ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor assert(!Record->getPreviousDecl() && 2697becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall "struct/union has previous declaration"); 2698becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall assert(!NeedsInjectedClassNameType(Record)); 2699400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return getRecordType(Record); 270019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall } else if (const EnumDecl *Enum = dyn_cast<EnumDecl>(Decl)) { 2701ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor assert(!Enum->getPreviousDecl() && 2702becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall "enum has previous declaration"); 2703400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return getEnumType(Enum); 270419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall } else if (const UnresolvedUsingTypenameDecl *Using = 2705ed97649e9574b9d854fa4d6109c9333ae0993554John McCall dyn_cast<UnresolvedUsingTypenameDecl>(Decl)) { 2706f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Type *newType = new (*this, TypeAlignment) UnresolvedUsingType(Using); 2707f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2708f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 27099fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else 2710becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall llvm_unreachable("TypeDecl without a type?"); 271149aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis 271249aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis return QualType(Decl->TypeForDecl, 0); 27132ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor} 27142ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 27155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTypedefType - Return the unique reference to the type for the 2716162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// specified typedef name decl. 27179763e221e16026ddf487d2564ed349d2c874a1a1Argyrios KyrtzidisQualType 2718162e1c1b487352434552147967c3dd296ebee2f7Richard SmithASTContext::getTypedefType(const TypedefNameDecl *Decl, 2719162e1c1b487352434552147967c3dd296ebee2f7Richard Smith QualType Canonical) const { 27205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 27211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27229763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis if (Canonical.isNull()) 27239763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Canonical = getCanonicalType(Decl->getUnderlyingType()); 2724f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall TypedefType *newType = new(*this, TypeAlignment) 27256b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypedefType(Type::Typedef, Decl, Canonical); 2726f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2727f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 2728f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(newType, 0); 27295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 27305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getRecordType(const RecordDecl *Decl) const { 2732400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 2733400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2734ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor if (const RecordDecl *PrevDecl = Decl->getPreviousDecl()) 2735400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (PrevDecl->TypeForDecl) 2736400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); 2737400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2738f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall RecordType *newType = new (*this, TypeAlignment) RecordType(Decl); 2739f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2740f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 2741f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(newType, 0); 2742400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis} 2743400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 27444ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getEnumType(const EnumDecl *Decl) const { 2745400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 2746400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2747ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor if (const EnumDecl *PrevDecl = Decl->getPreviousDecl()) 2748400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (PrevDecl->TypeForDecl) 2749400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); 2750400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2751f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall EnumType *newType = new (*this, TypeAlignment) EnumType(Decl); 2752f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2753f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 2754f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(newType, 0); 2755400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis} 2756400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 27579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType ASTContext::getAttributedType(AttributedType::Kind attrKind, 27589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType, 27599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType) { 27609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall llvm::FoldingSetNodeID id; 27619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType::Profile(id, attrKind, modifiedType, equivalentType); 27629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 27639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void *insertPos = 0; 27649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType *type = AttributedTypes.FindNodeOrInsertPos(id, insertPos); 27659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (type) return QualType(type, 0); 27669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 27679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType canon = getCanonicalType(equivalentType); 27689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall type = new (*this, TypeAlignment) 27699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType(canon, attrKind, modifiedType, equivalentType); 27709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 27719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Types.push_back(type); 27729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypes.InsertNode(type, insertPos); 27739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 27749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(type, 0); 27759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 27769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 27779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 277849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Retrieve a substitution-result type. 277949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType 278049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallASTContext::getSubstTemplateTypeParmType(const TemplateTypeParmType *Parm, 27814ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType Replacement) const { 2782467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall assert(Replacement.isCanonical() 278349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall && "replacement types must always be canonical"); 278449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 278549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall llvm::FoldingSetNodeID ID; 278649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType::Profile(ID, Parm, Replacement); 278749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall void *InsertPos = 0; 278849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType *SubstParm 278949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall = SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 279049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 279149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall if (!SubstParm) { 279249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstParm = new (*this, TypeAlignment) 279349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType(Parm, Replacement); 279449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Types.push_back(SubstParm); 279549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos); 279649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 279749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 279849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return QualType(SubstParm, 0); 279949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 280049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 2801c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Retrieve a 2802c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType ASTContext::getSubstTemplateTypeParmPackType( 2803c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Parm, 2804c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) { 2805c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor#ifndef NDEBUG 2806c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(), 2807c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor PEnd = ArgPack.pack_end(); 2808c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor P != PEnd; ++P) { 2809c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor assert(P->getKind() == TemplateArgument::Type &&"Pack contains a non-type"); 2810c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor assert(P->getAsType().isCanonical() && "Pack contains non-canonical type"); 2811c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 2812c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor#endif 2813c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2814c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor llvm::FoldingSetNodeID ID; 2815c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackType::Profile(ID, Parm, ArgPack); 2816c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor void *InsertPos = 0; 2817c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor if (SubstTemplateTypeParmPackType *SubstParm 2818c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor = SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos)) 2819c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return QualType(SubstParm, 0); 2820c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2821c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon; 2822c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor if (!Parm->isCanonicalUnqualified()) { 2823c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Canon = getCanonicalType(QualType(Parm, 0)); 2824c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Canon = getSubstTemplateTypeParmPackType(cast<TemplateTypeParmType>(Canon), 2825c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ArgPack); 2826c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos); 2827c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 2828c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2829c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackType *SubstParm 2830c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor = new (*this, TypeAlignment) SubstTemplateTypeParmPackType(Parm, Canon, 2831c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ArgPack); 2832c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Types.push_back(SubstParm); 2833c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos); 2834c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return QualType(SubstParm, 0); 2835c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 2836c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2837fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor/// \brief Retrieve the template type parameter type for a template 28381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// parameter or parameter pack with the given depth, index, and (optionally) 283976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson/// name. 28401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index, 284176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool ParameterPack, 28424fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *TTPDecl) const { 2843fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor llvm::FoldingSetNodeID ID; 28444fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmType::Profile(ID, Depth, Index, ParameterPack, TTPDecl); 2845fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void *InsertPos = 0; 28461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType *TypeParm 2847fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 2848fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 2849fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor if (TypeParm) 2850fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 28511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28524fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth if (TTPDecl) { 285376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson QualType Canon = getTemplateTypeParmType(Depth, Index, ParameterPack); 28544fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TypeParm = new (*this, TypeAlignment) TemplateTypeParmType(TTPDecl, Canon); 2855789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 2856789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor TemplateTypeParmType *TypeCheck 2857789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 2858789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!TypeCheck && "Template type parameter canonical type broken"); 2859789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)TypeCheck; 286076e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson } else 28616b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeParm = new (*this, TypeAlignment) 28626b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TemplateTypeParmType(Depth, Index, ParameterPack); 2863fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 2864fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Types.push_back(TypeParm); 2865fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos); 2866fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 2867fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 2868fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor} 2869fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 28703cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallTypeSourceInfo * 28713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallASTContext::getTemplateSpecializationTypeInfo(TemplateName Name, 28723cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall SourceLocation NameLoc, 28733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall const TemplateArgumentListInfo &Args, 28743e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Underlying) const { 28757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Name.getAsDependentTemplateName() && 28767c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 28773e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType TST = getTemplateSpecializationType(Name, Args, Underlying); 28783cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 28793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeSourceInfo *DI = CreateTypeSourceInfo(TST); 28803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TemplateSpecializationTypeLoc TL 28813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall = cast<TemplateSpecializationTypeLoc>(DI->getTypeLoc()); 288255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara TL.setTemplateKeywordLoc(SourceLocation()); 28833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setTemplateNameLoc(NameLoc); 28843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setLAngleLoc(Args.getLAngleLoc()); 28853cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setRAngleLoc(Args.getRAngleLoc()); 28863cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) 28873cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setArgLocInfo(i, Args[i].getLocInfo()); 28883cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return DI; 28893cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 28903cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 28911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 28927532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorASTContext::getTemplateSpecializationType(TemplateName Template, 2893d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Args, 28943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Underlying) const { 28957c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Template.getAsDependentTemplateName() && 28967c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 28977c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor 2898d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall unsigned NumArgs = Args.size(); 2899d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 29005f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 4> ArgVec; 2901833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall ArgVec.reserve(NumArgs); 2902833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != NumArgs; ++i) 2903833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall ArgVec.push_back(Args[i].getArgument()); 2904833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 290531f17ecbef57b5679c017c375db330546b7b5145John McCall return getTemplateSpecializationType(Template, ArgVec.data(), NumArgs, 29063e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Underlying); 2907833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2908833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2909b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor#ifndef NDEBUG 2910b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregorstatic bool hasAnyPackExpansions(const TemplateArgument *Args, 2911b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor unsigned NumArgs) { 2912b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) 2913b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor if (Args[I].isPackExpansion()) 2914b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor return true; 2915b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor 2916b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor return true; 2917b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor} 2918b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor#endif 2919b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor 2920833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType 2921833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallASTContext::getTemplateSpecializationType(TemplateName Template, 29227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 29237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, 29243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Underlying) const { 29257c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Template.getAsDependentTemplateName() && 29267c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 29270f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor // Look through qualified template names. 29280f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 29290f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor Template = TemplateName(QTN->getTemplateDecl()); 29307c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor 2931b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor bool IsTypeAlias = 29323e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Template.getAsTemplateDecl() && 29333e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith isa<TypeAliasTemplateDecl>(Template.getAsTemplateDecl()); 29343e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType CanonType; 29353e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (!Underlying.isNull()) 29363e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith CanonType = getCanonicalType(Underlying); 29373e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith else { 2938b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor // We can get here with an alias template when the specialization contains 2939b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor // a pack expansion that does not match up with a parameter pack. 2940b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor assert((!IsTypeAlias || hasAnyPackExpansions(Args, NumArgs)) && 2941b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor "Caller must compute aliased type"); 2942b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor IsTypeAlias = false; 29433e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith CanonType = getCanonicalTemplateSpecializationType(Template, Args, 29443e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NumArgs); 29453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 2946fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor 29471275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Allocate the (non-canonical) template specialization type, but don't 29481275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // try to unique it: these types typically have location information that 29491275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // we don't unique and don't want to lose. 29503e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith void *Mem = Allocate(sizeof(TemplateSpecializationType) + 29513e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith sizeof(TemplateArgument) * NumArgs + 2952b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor (IsTypeAlias? sizeof(QualType) : 0), 29536b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignment); 29541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateSpecializationType *Spec 2955b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor = new (Mem) TemplateSpecializationType(Template, Args, NumArgs, CanonType, 2956b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor IsTypeAlias ? Underlying : QualType()); 29571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 295855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor Types.push_back(Spec); 29591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(Spec, 0); 296055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 296155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 29621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 29639763e221e16026ddf487d2564ed349d2c874a1a1Argyrios KyrtzidisASTContext::getCanonicalTemplateSpecializationType(TemplateName Template, 29649763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis const TemplateArgument *Args, 29654ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned NumArgs) const { 29667c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Template.getAsDependentTemplateName() && 29677c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 29683e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 29690f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor // Look through qualified template names. 29700f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 29710f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor Template = TemplateName(QTN->getTemplateDecl()); 29727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor 29739763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // Build the canonical template specialization type. 29749763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateName CanonTemplate = getCanonicalTemplateName(Template); 29755f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 4> CanonArgs; 29769763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.reserve(NumArgs); 29779763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis for (unsigned I = 0; I != NumArgs; ++I) 29789763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.push_back(getCanonicalTemplateArgument(Args[I])); 29799763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 29809763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // Determine whether this canonical template specialization type already 29819763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // exists. 29829763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis llvm::FoldingSetNodeID ID; 29839763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateSpecializationType::Profile(ID, CanonTemplate, 29849763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.data(), NumArgs, *this); 29859763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 29869763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis void *InsertPos = 0; 29879763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateSpecializationType *Spec 29889763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 29899763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 29909763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis if (!Spec) { 29919763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // Allocate a new canonical template specialization type. 29929763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis void *Mem = Allocate((sizeof(TemplateSpecializationType) + 29939763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis sizeof(TemplateArgument) * NumArgs), 29949763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TypeAlignment); 29959763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Spec = new (Mem) TemplateSpecializationType(CanonTemplate, 29969763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.data(), NumArgs, 29973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType(), QualType()); 29989763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Types.push_back(Spec); 29999763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateSpecializationTypes.InsertNode(Spec, InsertPos); 30009763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis } 30019763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 30029763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis assert(Spec->isDependentType() && 30039763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis "Non-dependent template-id type must have a canonical type"); 30049763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis return QualType(Spec, 0); 30059763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis} 30069763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 30079763e221e16026ddf487d2564ed349d2c874a1a1Argyrios KyrtzidisQualType 3008465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraASTContext::getElaboratedType(ElaboratedTypeKeyword Keyword, 3009465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS, 30104ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType NamedType) const { 3011e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor llvm::FoldingSetNodeID ID; 3012465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType::Profile(ID, Keyword, NNS, NamedType); 3013e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3014e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void *InsertPos = 0; 3015465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType *T = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos); 3016e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor if (T) 3017e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 3018e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3019789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor QualType Canon = NamedType; 3020789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor if (!Canon.isCanonical()) { 3021789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor Canon = getCanonicalType(NamedType); 3022465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType *CheckT = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos); 3023465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara assert(!CheckT && "Elaborated canonical type broken"); 3024789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CheckT; 3025789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor } 3026789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 3027465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara T = new (*this) ElaboratedType(Keyword, NNS, NamedType, Canon); 3028e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor Types.push_back(T); 3029465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypes.InsertNode(T, InsertPos); 3030e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 3031e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor} 3032e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 3033075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 30344ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getParenType(QualType InnerType) const { 3035075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara llvm::FoldingSetNodeID ID; 3036075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType::Profile(ID, InnerType); 3037075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 3038075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void *InsertPos = 0; 3039075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType *T = ParenTypes.FindNodeOrInsertPos(ID, InsertPos); 3040075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (T) 3041075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(T, 0); 3042075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 3043075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Canon = InnerType; 3044075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (!Canon.isCanonical()) { 3045075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Canon = getCanonicalType(InnerType); 3046075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType *CheckT = ParenTypes.FindNodeOrInsertPos(ID, InsertPos); 3047075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara assert(!CheckT && "Paren canonical type broken"); 3048075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara (void)CheckT; 3049075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 3050075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 3051075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara T = new (*this) ParenType(InnerType, Canon); 3052075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Types.push_back(T); 3053075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypes.InsertNode(T, InsertPos); 3054075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(T, 0); 3055075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 3056075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 30574a2023f5014e82389d5980d307b89c545dbbac81Douglas GregorQualType ASTContext::getDependentNameType(ElaboratedTypeKeyword Keyword, 30584a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor NestedNameSpecifier *NNS, 30594a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const IdentifierInfo *Name, 30604ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType Canon) const { 3061d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && "nested-name-specifier must be dependent"); 3062d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3063d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (Canon.isNull()) { 3064d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 30654a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ElaboratedTypeKeyword CanonKeyword = Keyword; 30664a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor if (Keyword == ETK_None) 30674a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor CanonKeyword = ETK_Typename; 30684a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor 30694a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor if (CanonNNS != NNS || CanonKeyword != Keyword) 30704a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor Canon = getDependentNameType(CanonKeyword, CanonNNS, Name); 3071d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3072d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3073d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor llvm::FoldingSetNodeID ID; 30744a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor DependentNameType::Profile(ID, Keyword, NNS, Name); 3075d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3076d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void *InsertPos = 0; 30774714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor DependentNameType *T 30784714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor = DependentNameTypes.FindNodeOrInsertPos(ID, InsertPos); 3079d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (T) 3080d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return QualType(T, 0); 3081d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 30824a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor T = new (*this) DependentNameType(Keyword, NNS, Name, Canon); 3083d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Types.push_back(T); 30844714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor DependentNameTypes.InsertNode(T, InsertPos); 30851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(T, 0); 3086d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 3087d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 30881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 308933500955d731c73717af52088b7fc0e7a85681e7John McCallASTContext::getDependentTemplateSpecializationType( 309033500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 30914a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor NestedNameSpecifier *NNS, 309233500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 30934ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const TemplateArgumentListInfo &Args) const { 309433500955d731c73717af52088b7fc0e7a85681e7John McCall // TODO: avoid this copy 30955f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 16> ArgCopy; 309633500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0, E = Args.size(); I != E; ++I) 309733500955d731c73717af52088b7fc0e7a85681e7John McCall ArgCopy.push_back(Args[I].getArgument()); 309833500955d731c73717af52088b7fc0e7a85681e7John McCall return getDependentTemplateSpecializationType(Keyword, NNS, Name, 309933500955d731c73717af52088b7fc0e7a85681e7John McCall ArgCopy.size(), 310033500955d731c73717af52088b7fc0e7a85681e7John McCall ArgCopy.data()); 310133500955d731c73717af52088b7fc0e7a85681e7John McCall} 310233500955d731c73717af52088b7fc0e7a85681e7John McCall 310333500955d731c73717af52088b7fc0e7a85681e7John McCallQualType 310433500955d731c73717af52088b7fc0e7a85681e7John McCallASTContext::getDependentTemplateSpecializationType( 310533500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 310633500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, 310733500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 310833500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 31094ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const TemplateArgument *Args) const { 3110aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor assert((!NNS || NNS->isDependent()) && 3111aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor "nested-name-specifier must be dependent"); 31121734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 3113789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor llvm::FoldingSetNodeID ID; 311433500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationType::Profile(ID, *this, Keyword, NNS, 311533500955d731c73717af52088b7fc0e7a85681e7John McCall Name, NumArgs, Args); 3116789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 3117789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor void *InsertPos = 0; 311833500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationType *T 311933500955d731c73717af52088b7fc0e7a85681e7John McCall = DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 3120789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor if (T) 3121789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor return QualType(T, 0); 3122789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 312333500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 312433500955d731c73717af52088b7fc0e7a85681e7John McCall 312533500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword CanonKeyword = Keyword; 312633500955d731c73717af52088b7fc0e7a85681e7John McCall if (Keyword == ETK_None) CanonKeyword = ETK_Typename; 31271734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 312833500955d731c73717af52088b7fc0e7a85681e7John McCall bool AnyNonCanonArgs = false; 31295f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 16> CanonArgs(NumArgs); 313033500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0; I != NumArgs; ++I) { 313133500955d731c73717af52088b7fc0e7a85681e7John McCall CanonArgs[I] = getCanonicalTemplateArgument(Args[I]); 313233500955d731c73717af52088b7fc0e7a85681e7John McCall if (!CanonArgs[I].structurallyEquals(Args[I])) 313333500955d731c73717af52088b7fc0e7a85681e7John McCall AnyNonCanonArgs = true; 3134789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor } 31351734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 313633500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon; 313733500955d731c73717af52088b7fc0e7a85681e7John McCall if (AnyNonCanonArgs || CanonNNS != NNS || CanonKeyword != Keyword) { 313833500955d731c73717af52088b7fc0e7a85681e7John McCall Canon = getDependentTemplateSpecializationType(CanonKeyword, CanonNNS, 313933500955d731c73717af52088b7fc0e7a85681e7John McCall Name, NumArgs, 314033500955d731c73717af52088b7fc0e7a85681e7John McCall CanonArgs.data()); 314133500955d731c73717af52088b7fc0e7a85681e7John McCall 314233500955d731c73717af52088b7fc0e7a85681e7John McCall // Find the insert position again. 314333500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 314433500955d731c73717af52088b7fc0e7a85681e7John McCall } 314533500955d731c73717af52088b7fc0e7a85681e7John McCall 314633500955d731c73717af52088b7fc0e7a85681e7John McCall void *Mem = Allocate((sizeof(DependentTemplateSpecializationType) + 314733500955d731c73717af52088b7fc0e7a85681e7John McCall sizeof(TemplateArgument) * NumArgs), 314833500955d731c73717af52088b7fc0e7a85681e7John McCall TypeAlignment); 3149ef99001908e799c388f1363b1e607dad5f5b57d3John McCall T = new (Mem) DependentTemplateSpecializationType(Keyword, NNS, 315033500955d731c73717af52088b7fc0e7a85681e7John McCall Name, NumArgs, Args, Canon); 31511734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor Types.push_back(T); 315233500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypes.InsertNode(T, InsertPos); 31531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(T, 0); 31541734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor} 31551734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 3156cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas GregorQualType ASTContext::getPackExpansionType(QualType Pattern, 3157cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 31587536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor llvm::FoldingSetNodeID ID; 3159cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor PackExpansionType::Profile(ID, Pattern, NumExpansions); 31607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 31617536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor assert(Pattern->containsUnexpandedParameterPack() && 31627536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor "Pack expansions must expand one or more parameter packs"); 31637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor void *InsertPos = 0; 31647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionType *T 31657536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor = PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos); 31667536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor if (T) 31677536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return QualType(T, 0); 31687536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 31697536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType Canon; 31707536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor if (!Pattern.isCanonical()) { 3171d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith Canon = getCanonicalType(Pattern); 3172d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // The canonical type might not contain an unexpanded parameter pack, if it 3173d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // contains an alias template specialization which ignores one of its 3174d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // parameters. 3175d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith if (Canon->containsUnexpandedParameterPack()) { 3176d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith Canon = getPackExpansionType(getCanonicalType(Pattern), NumExpansions); 3177d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith 3178d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // Find the insert position again, in case we inserted an element into 3179d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // PackExpansionTypes and invalidated our insert position. 3180d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos); 3181d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith } 31827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 31837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3184cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor T = new (*this) PackExpansionType(Pattern, Canon, NumExpansions); 31857536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Types.push_back(T); 31867536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypes.InsertNode(T, InsertPos); 31877536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return QualType(T, 0); 31887536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 31897536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 319088cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// CmpProtocolNames - Comparison predicate for sorting protocols 319188cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// alphabetically. 319288cb27a160adc305783a44f922ee4b216006ebf9Chris Lattnerstatic bool CmpProtocolNames(const ObjCProtocolDecl *LHS, 319388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner const ObjCProtocolDecl *RHS) { 31942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS->getDeclName() < RHS->getDeclName(); 319588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 319688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 3197c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallstatic bool areSortedAndUniqued(ObjCProtocolDecl * const *Protocols, 319854e14c4db764c0636160d26c5bbf491637c83a76John McCall unsigned NumProtocols) { 319954e14c4db764c0636160d26c5bbf491637c83a76John McCall if (NumProtocols == 0) return true; 320054e14c4db764c0636160d26c5bbf491637c83a76John McCall 320161cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor if (Protocols[0]->getCanonicalDecl() != Protocols[0]) 320261cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor return false; 320361cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor 320454e14c4db764c0636160d26c5bbf491637c83a76John McCall for (unsigned i = 1; i != NumProtocols; ++i) 320561cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor if (!CmpProtocolNames(Protocols[i-1], Protocols[i]) || 320661cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor Protocols[i]->getCanonicalDecl() != Protocols[i]) 320754e14c4db764c0636160d26c5bbf491637c83a76John McCall return false; 320854e14c4db764c0636160d26c5bbf491637c83a76John McCall return true; 320954e14c4db764c0636160d26c5bbf491637c83a76John McCall} 321054e14c4db764c0636160d26c5bbf491637c83a76John McCall 321154e14c4db764c0636160d26c5bbf491637c83a76John McCallstatic void SortAndUniqueProtocols(ObjCProtocolDecl **Protocols, 321288cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner unsigned &NumProtocols) { 321388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ObjCProtocolDecl **ProtocolsEnd = Protocols+NumProtocols; 32141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 321588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Sort protocols, keyed by name. 321688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner std::sort(Protocols, Protocols+NumProtocols, CmpProtocolNames); 321788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 321861cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor // Canonicalize. 321961cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor for (unsigned I = 0, N = NumProtocols; I != N; ++I) 322061cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor Protocols[I] = Protocols[I]->getCanonicalDecl(); 322161cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor 322288cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Remove duplicates. 322388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ProtocolsEnd = std::unique(Protocols, ProtocolsEnd); 322488cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner NumProtocols = ProtocolsEnd-Protocols; 322588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 322688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 3227c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType ASTContext::getObjCObjectType(QualType BaseType, 3228c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 32294ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned NumProtocols) const { 3230c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If the base type is an interface and there aren't any protocols 3231c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // to add, then the interface type will do just fine. 3232c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!NumProtocols && isa<ObjCInterfaceType>(BaseType)) 3233c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return BaseType; 3234d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 3235c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Look in the folding set for an existing type. 3236c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall llvm::FoldingSetNodeID ID; 3237c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeImpl::Profile(ID, BaseType, Protocols, NumProtocols); 3238d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff void *InsertPos = 0; 3239c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (ObjCObjectType *QT = ObjCObjectTypes.FindNodeOrInsertPos(ID, InsertPos)) 3240c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return QualType(QT, 0); 3241d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 3242c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Build the canonical type, which has the canonical base type and 3243c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // a sorted-and-uniqued list of protocols. 324454e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Canonical; 3245c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool ProtocolsSorted = areSortedAndUniqued(Protocols, NumProtocols); 3246c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!ProtocolsSorted || !BaseType.isCanonical()) { 3247c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!ProtocolsSorted) { 32485f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<ObjCProtocolDecl*, 8> Sorted(Protocols, 32490237941e0beb0c929934b66ad29443b484d987feBenjamin Kramer Protocols + NumProtocols); 325054e14c4db764c0636160d26c5bbf491637c83a76John McCall unsigned UniqueCount = NumProtocols; 325154e14c4db764c0636160d26c5bbf491637c83a76John McCall 325254e14c4db764c0636160d26c5bbf491637c83a76John McCall SortAndUniqueProtocols(&Sorted[0], UniqueCount); 3253c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Canonical = getObjCObjectType(getCanonicalType(BaseType), 3254c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall &Sorted[0], UniqueCount); 325554e14c4db764c0636160d26c5bbf491637c83a76John McCall } else { 3256c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Canonical = getObjCObjectType(getCanonicalType(BaseType), 3257c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Protocols, NumProtocols); 325854e14c4db764c0636160d26c5bbf491637c83a76John McCall } 325954e14c4db764c0636160d26c5bbf491637c83a76John McCall 326054e14c4db764c0636160d26c5bbf491637c83a76John McCall // Regenerate InsertPos. 3261c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypes.FindNodeOrInsertPos(ID, InsertPos); 326254e14c4db764c0636160d26c5bbf491637c83a76John McCall } 326354e14c4db764c0636160d26c5bbf491637c83a76John McCall 3264c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned Size = sizeof(ObjCObjectTypeImpl); 3265c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Size += NumProtocols * sizeof(ObjCProtocolDecl *); 3266fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor void *Mem = Allocate(Size, TypeAlignment); 3267c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeImpl *T = 3268c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall new (Mem) ObjCObjectTypeImpl(Canonical, BaseType, Protocols, NumProtocols); 32691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3270c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Types.push_back(T); 3271c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypes.InsertNode(T, InsertPos); 3272c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return QualType(T, 0); 3273d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 327488cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 3275c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// getObjCObjectPointerType - Return a ObjCObjectPointerType type for 3276c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// the given object type. 32774ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getObjCObjectPointerType(QualType ObjectT) const { 32784b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian llvm::FoldingSetNodeID ID; 3279c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType::Profile(ID, ObjectT); 32801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32814b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void *InsertPos = 0; 3282c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (ObjCObjectPointerType *QT = 3283c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 32844b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return QualType(QT, 0); 32851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3286c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Find the canonical object type. 328754e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Canonical; 3288c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!ObjectT.isCanonical()) { 3289c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Canonical = getObjCObjectPointerType(getCanonicalType(ObjectT)); 329054e14c4db764c0636160d26c5bbf491637c83a76John McCall 3291c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Regenerate InsertPos. 3292c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 329354e14c4db764c0636160d26c5bbf491637c83a76John McCall } 329454e14c4db764c0636160d26c5bbf491637c83a76John McCall 3295c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // No match. 3296c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void *Mem = Allocate(sizeof(ObjCObjectPointerType), TypeAlignment); 3297c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType *QType = 3298c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall new (Mem) ObjCObjectPointerType(Canonical, ObjectT); 329924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 330024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis Types.push_back(QType); 3301c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypes.InsertNode(QType, InsertPos); 330224fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis return QualType(QType, 0); 330324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 330424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 3305deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor/// getObjCInterfaceType - Return the unique reference to the type for the 3306deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor/// specified ObjC interface decl. The list of protocols is optional. 33070af550115df1f57f17a4f125ff0e8b34820c65d1Douglas GregorQualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl, 33080af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor ObjCInterfaceDecl *PrevDecl) const { 3309deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor if (Decl->TypeForDecl) 3310deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor return QualType(Decl->TypeForDecl, 0); 331174c730ad1f6818b676b0bad46d806a9176950328Sebastian Redl 33120af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor if (PrevDecl) { 33130af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl"); 33140af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor Decl->TypeForDecl = PrevDecl->TypeForDecl; 33150af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor return QualType(PrevDecl->TypeForDecl, 0); 33160af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor } 33170af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor 33188d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor // Prefer the definition, if there is one. 33198d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor if (const ObjCInterfaceDecl *Def = Decl->getDefinition()) 33208d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor Decl = Def; 33218d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor 3322deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor void *Mem = Allocate(sizeof(ObjCInterfaceType), TypeAlignment); 3323deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor ObjCInterfaceType *T = new (Mem) ObjCInterfaceType(Decl); 3324deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor Decl->TypeForDecl = T; 3325deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor Types.push_back(T); 3326deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor return QualType(T, 0); 3327c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3328c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 332972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getTypeOfExprType - Unlike many "get<Type>" functions, we can't unique 333072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType AST's (since expression's are never shared). For example, 33319752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// multiple declarations that refer to "typeof(x)" all contain different 33321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// DeclRefExpr's. This doesn't effect the type checker, since it operates 33339752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 33344ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTypeOfExprType(Expr *tofExpr) const { 3335dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType *toe; 3336b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (tofExpr->isTypeDependent()) { 3337b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor llvm::FoldingSetNodeID ID; 3338b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType::Profile(ID, *this, tofExpr); 33391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3340b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void *InsertPos = 0; 3341b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType *Canon 3342b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor = DependentTypeOfExprTypes.FindNodeOrInsertPos(ID, InsertPos); 3343b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (Canon) { 3344b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // We already have a "canonical" version of an identical, dependent 3345b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // typeof(expr) type. Use that as our canonical type. 33466b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, 3347b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor QualType((TypeOfExprType*)Canon, 0)); 33483060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 3349b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // Build a new, canonical typeof(expr) type. 33506b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Canon 33516b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) DependentTypeOfExprType(*this, tofExpr); 3352b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprTypes.InsertNode(Canon, InsertPos); 3353b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor toe = Canon; 3354b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 3355b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } else { 3356dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor QualType Canonical = getCanonicalType(tofExpr->getType()); 33576b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, Canonical); 3358dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 33599752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(toe); 33609752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(toe, 0); 3361d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 3362d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 33639752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// getTypeOfType - Unlike many "get<Type>" functions, we don't unique 33649752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// TypeOfType AST's. The only motivation to unique these nodes would be 33659752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// memory savings. Since typeof(t) is fairly uncommon, space shouldn't be 33661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an issue. This doesn't effect the type checker, since it operates 33679752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 33684ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTypeOfType(QualType tofType) const { 3369f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType Canonical = getCanonicalType(tofType); 33706b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeOfType *tot = new (*this, TypeAlignment) TypeOfType(tofType, Canonical); 33719752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(tot); 33729752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(tot, 0); 3373d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 3374d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 337560a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson 3376395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// getDecltypeType - Unlike many "get<Type>" functions, we don't unique 3377395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType AST's. The only motivation to unique these nodes would be 3378395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// memory savings. Since decltype(t) is fairly uncommon, space shouldn't be 33791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an issue. This doesn't effect the type checker, since it operates 338039e02032b01874a0d02ba85a4cd3922adda81376David Blaikie/// on canonical types (which are always unique). 3381f8af98286022f72157d84951b48fde5fb369ab29Douglas GregorQualType ASTContext::getDecltypeType(Expr *e, QualType UnderlyingType) const { 3382dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor DecltypeType *dt; 3383561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 3384561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // C++0x [temp.type]p2: 3385561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // If an expression e involves a template parameter, decltype(e) denotes a 3386561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // unique dependent type. Two such decltype-specifiers refer to the same 3387561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // type only if their expressions are equivalent (14.5.6.1). 3388561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (e->isInstantiationDependent()) { 33899d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor llvm::FoldingSetNodeID ID; 33909d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType::Profile(ID, *this, e); 33911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33929d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void *InsertPos = 0; 33939d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType *Canon 33949d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor = DependentDecltypeTypes.FindNodeOrInsertPos(ID, InsertPos); 33959d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor if (Canon) { 33969d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // We already have a "canonical" version of an equivalent, dependent 33979d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // decltype type. Use that as our canonical type. 33980d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith dt = new (*this, TypeAlignment) DecltypeType(e, UnderlyingType, 33999d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor QualType((DecltypeType*)Canon, 0)); 34003060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 34019d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // Build a new, canonical typeof(expr) type. 34026b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Canon = new (*this, TypeAlignment) DependentDecltypeType(*this, e); 34039d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeTypes.InsertNode(Canon, InsertPos); 34049d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor dt = Canon; 34059d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 34069d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } else { 3407f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregor dt = new (*this, TypeAlignment) DecltypeType(e, UnderlyingType, 3408f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregor getCanonicalType(UnderlyingType)); 3409dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 3410395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Types.push_back(dt); 3411395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return QualType(dt, 0); 3412395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 3413395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 3414ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// getUnaryTransformationType - We don't unique these, since the memory 3415ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// savings are minimal and these are rare. 3416ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType ASTContext::getUnaryTransformType(QualType BaseType, 3417ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType UnderlyingType, 3418ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind Kind) 3419ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt const { 3420ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType *Ty = 342169d9775da47a4b9f165dbc33277f02982928a94eDouglas Gregor new (*this, TypeAlignment) UnaryTransformType (BaseType, UnderlyingType, 342269d9775da47a4b9f165dbc33277f02982928a94eDouglas Gregor Kind, 342369d9775da47a4b9f165dbc33277f02982928a94eDouglas Gregor UnderlyingType->isDependentType() ? 342412fc4b0624706b474fa10308631fa8daf92f340fPeter Collingbourne QualType() : getCanonicalType(UnderlyingType)); 3425ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Types.push_back(Ty); 3426ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(Ty, 0); 3427ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 3428ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3429483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith/// getAutoType - We only unique auto types after they've been deduced. 343034b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType ASTContext::getAutoType(QualType DeducedType) const { 3431483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith void *InsertPos = 0; 3432483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith if (!DeducedType.isNull()) { 3433483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith // Look in the folding set for an existing type. 3434483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith llvm::FoldingSetNodeID ID; 3435483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith AutoType::Profile(ID, DeducedType); 3436483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos)) 3437483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith return QualType(AT, 0); 3438483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith } 3439483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith 3440483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith AutoType *AT = new (*this, TypeAlignment) AutoType(DeducedType); 3441483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith Types.push_back(AT); 3442483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith if (InsertPos) 3443483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith AutoTypes.InsertNode(AT, InsertPos); 3444483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith return QualType(AT, 0); 344534b41d939a1328f484511c6002ba2456db879a29Richard Smith} 344634b41d939a1328f484511c6002ba2456db879a29Richard Smith 3447b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman/// getAtomicType - Return the uniqued reference to the atomic type for 3448b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman/// the given value type. 3449b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType ASTContext::getAtomicType(QualType T) const { 3450b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // Unique pointers, to guarantee there is only one pointer of a particular 3451b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // structure. 3452b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman llvm::FoldingSetNodeID ID; 3453b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType::Profile(ID, T); 3454b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3455b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void *InsertPos = 0; 3456b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (AtomicType *AT = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos)) 3457b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(AT, 0); 3458b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3459b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // If the atomic value type isn't canonical, this won't be a canonical type 3460b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // either, so fill in the canonical type field. 3461b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType Canonical; 3462b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (!T.isCanonical()) { 3463b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Canonical = getAtomicType(getCanonicalType(T)); 3464b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3465b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // Get the new insert position for the node we care about. 3466b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType *NewIP = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos); 3467b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 3468b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 3469b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType *New = new (*this, TypeAlignment) AtomicType(T, Canonical); 3470b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Types.push_back(New); 3471b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypes.InsertNode(New, InsertPos); 3472b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(New, 0); 3473b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 3474b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3475ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// getAutoDeductType - Get type pattern for deducing against 'auto'. 3476ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithQualType ASTContext::getAutoDeductType() const { 3477ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (AutoDeductTy.isNull()) 3478ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith AutoDeductTy = getAutoType(QualType()); 3479ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith assert(!AutoDeductTy.isNull() && "can't build 'auto' pattern"); 3480ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return AutoDeductTy; 3481ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 3482ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 3483ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// getAutoRRefDeductType - Get type pattern for deducing against 'auto &&'. 3484ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithQualType ASTContext::getAutoRRefDeductType() const { 3485ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (AutoRRefDeductTy.isNull()) 3486ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith AutoRRefDeductTy = getRValueReferenceType(getAutoDeductType()); 3487ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith assert(!AutoRRefDeductTy.isNull() && "can't build 'auto &&' pattern"); 3488ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return AutoRRefDeductTy; 3489ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 3490ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 34915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTagDeclType - Return the unique reference to the type for the 34925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified TagDecl (struct/union/class/enum) decl. 34934ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTagDeclType(const TagDecl *Decl) const { 3494d778f88d32b96a74c9edb7342c81357606a7cdc0Ted Kremenek assert (Decl); 3495e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // FIXME: What is the design on getTagDeclType when it requires casting 3496e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // away const? mutable? 3497e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump return getTypeDeclType(const_cast<TagDecl*>(Decl)); 34985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 34995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 35001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getSizeType - Return the unique type for "size_t" (C99 7.17), the result 35011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and 35021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// needs to agree with the definition in <stddef.h>. 3503a3ccda58913cc1a4b8564e349448b12acc462da7Anders CarlssonCanQualType ASTContext::getSizeType() const { 3504bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return getFromTargetType(Target->getSizeType()); 35055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 35065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 350729e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg/// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5). 350829e97cb35fab314388f62b68fefa78947e93c1dcHans WennborgCanQualType ASTContext::getIntMaxType() const { 350929e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg return getFromTargetType(Target->getIntMaxType()); 351029e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg} 351129e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg 351229e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg/// getUIntMaxType - Return the unique type for "uintmax_t" (C99 7.18.1.5). 351329e97cb35fab314388f62b68fefa78947e93c1dcHans WennborgCanQualType ASTContext::getUIntMaxType() const { 351429e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg return getFromTargetType(Target->getUIntMaxType()); 351529e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg} 351629e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg 351764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getSignedWCharType - Return the type of "signed wchar_t". 351864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 351964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getSignedWCharType() const { 352064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 352164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return WCharTy; 352264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 352364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 352464c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getUnsignedWCharType - Return the type of "unsigned wchar_t". 352564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 352664c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getUnsignedWCharType() const { 352764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 352864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return UnsignedIntTy; 352964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 353064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 353129e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg/// getPointerDiffType - Return the unique type for "ptrdiff_t" (C99 7.17) 35328b9023ba35a86838789e2c9034a6128728c547aaChris Lattner/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 35338b9023ba35a86838789e2c9034a6128728c547aaChris LattnerQualType ASTContext::getPointerDiffType() const { 3534bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return getFromTargetType(Target->getPtrDiffType(0)); 35358b9023ba35a86838789e2c9034a6128728c547aaChris Lattner} 35368b9023ba35a86838789e2c9034a6128728c547aaChris Lattner 3537e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 3538e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner// Type Operators 3539e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 3540e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 35414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCanQualType ASTContext::getCanonicalParamType(QualType T) const { 354254e14c4db764c0636160d26c5bbf491637c83a76John McCall // Push qualifiers into arrays, and then discard any remaining 354354e14c4db764c0636160d26c5bbf491637c83a76John McCall // qualifiers. 354454e14c4db764c0636160d26c5bbf491637c83a76John McCall T = getCanonicalType(T); 3545745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian T = getVariableArrayDecayedType(T); 354654e14c4db764c0636160d26c5bbf491637c83a76John McCall const Type *Ty = T.getTypePtr(); 354754e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Result; 354854e14c4db764c0636160d26c5bbf491637c83a76John McCall if (isa<ArrayType>(Ty)) { 354954e14c4db764c0636160d26c5bbf491637c83a76John McCall Result = getArrayDecayedType(QualType(Ty,0)); 355054e14c4db764c0636160d26c5bbf491637c83a76John McCall } else if (isa<FunctionType>(Ty)) { 355154e14c4db764c0636160d26c5bbf491637c83a76John McCall Result = getPointerType(QualType(Ty, 0)); 355254e14c4db764c0636160d26c5bbf491637c83a76John McCall } else { 355354e14c4db764c0636160d26c5bbf491637c83a76John McCall Result = QualType(Ty, 0); 355454e14c4db764c0636160d26c5bbf491637c83a76John McCall } 355554e14c4db764c0636160d26c5bbf491637c83a76John McCall 355654e14c4db764c0636160d26c5bbf491637c83a76John McCall return CanQualType::CreateUnsafe(Result); 355754e14c4db764c0636160d26c5bbf491637c83a76John McCall} 355854e14c4db764c0636160d26c5bbf491637c83a76John McCall 355962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallQualType ASTContext::getUnqualifiedArrayType(QualType type, 356062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers &quals) { 356162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall SplitQualType splitType = type.getSplitUnqualifiedType(); 356262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 356362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // FIXME: getSplitUnqualifiedType() actually walks all the way to 356462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // the unqualified desugared type and then drops it on the floor. 356562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // We then have to strip that sugar back off with 356662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // getUnqualifiedDesugaredType(), which is silly. 356762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall const ArrayType *AT = 3568200fa53fd420aa8369586f569dbece04930ad6a3John McCall dyn_cast<ArrayType>(splitType.Ty->getUnqualifiedDesugaredType()); 356962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 357062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // If we don't have an array, just use the results in splitType. 35719dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (!AT) { 3572200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals = splitType.Quals; 3573200fa53fd420aa8369586f569dbece04930ad6a3John McCall return QualType(splitType.Ty, 0); 357428e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth } 357528e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 357662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, recurse on the array's element type. 357762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType elementType = AT->getElementType(); 357862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType unqualElementType = getUnqualifiedArrayType(elementType, quals); 357962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 358062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // If that didn't change the element type, AT has no qualifiers, so we 358162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // can just use the results in splitType. 358262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (elementType == unqualElementType) { 358362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall assert(quals.empty()); // from the recursive call 3584200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals = splitType.Quals; 3585200fa53fd420aa8369586f569dbece04930ad6a3John McCall return QualType(splitType.Ty, 0); 358662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 358762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 358862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, add in the qualifiers from the outermost type, then 358962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // build the type back up. 3590200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals.addConsistentQualifiers(splitType.Quals); 359128e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 35929dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) { 359362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getConstantArrayType(unqualElementType, CAT->getSize(), 359428e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth CAT->getSizeModifier(), 0); 359528e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth } 359628e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 35979dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) { 359862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getIncompleteArrayType(unqualElementType, IAT->getSizeModifier(), 0); 359928e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth } 360028e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 36019dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(AT)) { 360262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getVariableArrayType(unqualElementType, 36033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall VAT->getSizeExpr(), 36049dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor VAT->getSizeModifier(), 36059dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor VAT->getIndexTypeCVRQualifiers(), 36069dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor VAT->getBracketsRange()); 36079dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor } 36089dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor 36099dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor const DependentSizedArrayType *DSAT = cast<DependentSizedArrayType>(AT); 361062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getDependentSizedArrayType(unqualElementType, DSAT->getSizeExpr(), 361128e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth DSAT->getSizeModifier(), 0, 361228e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth SourceRange()); 361328e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth} 361428e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 36155a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// UnwrapSimilarPointerTypes - If T1 and T2 are pointer types that 36165a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// may be similar (C++ 4.4), replaces T1 and T2 with the type that 36175a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// they point to and return true. If T1 and T2 aren't pointer types 36185a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// or pointer-to-member types, or if they are not similar at this 36195a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// level, returns false and leaves T1 and T2 unchanged. Top-level 36205a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// qualifiers on T1 and T2 are ignored. This function will typically 36215a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// be called in a loop that successively "unwraps" pointer and 36225a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// pointer-to-member types to compare them at each level. 36235a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregorbool ASTContext::UnwrapSimilarPointerTypes(QualType &T1, QualType &T2) { 36245a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor const PointerType *T1PtrType = T1->getAs<PointerType>(), 36255a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor *T2PtrType = T2->getAs<PointerType>(); 36265a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor if (T1PtrType && T2PtrType) { 36275a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T1 = T1PtrType->getPointeeType(); 36285a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T2 = T2PtrType->getPointeeType(); 36295a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return true; 36305a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 36315a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 36325a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor const MemberPointerType *T1MPType = T1->getAs<MemberPointerType>(), 36335a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor *T2MPType = T2->getAs<MemberPointerType>(); 36345a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor if (T1MPType && T2MPType && 36355a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor hasSameUnqualifiedType(QualType(T1MPType->getClass(), 0), 36365a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor QualType(T2MPType->getClass(), 0))) { 36375a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T1 = T1MPType->getPointeeType(); 36385a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T2 = T2MPType->getPointeeType(); 36395a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return true; 36405a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 36415a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 36424e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().ObjC1) { 36435a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor const ObjCObjectPointerType *T1OPType = T1->getAs<ObjCObjectPointerType>(), 36445a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor *T2OPType = T2->getAs<ObjCObjectPointerType>(); 36455a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor if (T1OPType && T2OPType) { 36465a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T1 = T1OPType->getPointeeType(); 36475a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T2 = T2OPType->getPointeeType(); 36485a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return true; 36495a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 36505a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 36515a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 36525a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor // FIXME: Block pointers, too? 36535a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 36545a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return false; 36555a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor} 36565a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 36574ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDeclarationNameInfo 36584ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getNameForTemplate(TemplateName Name, 36594ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad SourceLocation NameLoc) const { 3660146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall switch (Name.getKind()) { 3661146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::QualifiedTemplate: 3662146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::Template: 36632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // DNInfo work in progress: CHECKME: what about DNLoc? 3664146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo(Name.getAsTemplateDecl()->getDeclName(), 3665146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall NameLoc); 36662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3667146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::OverloadedTemplate: { 3668146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall OverloadedTemplateStorage *Storage = Name.getAsOverloadedTemplate(); 3669146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall // DNInfo work in progress: CHECKME: what about DNLoc? 3670146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo((*Storage->begin())->getDeclName(), NameLoc); 3671146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3672146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3673146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::DependentTemplate: { 3674146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall DependentTemplateName *DTN = Name.getAsDependentTemplateName(); 36752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName DName; 367680ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall if (DTN->isIdentifier()) { 36772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DName = DeclarationNames.getIdentifier(DTN->getIdentifier()); 36782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(DName, NameLoc); 367980ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall } else { 36802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DName = DeclarationNames.getCXXOperatorName(DTN->getOperator()); 36812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // DNInfo work in progress: FIXME: source locations? 36822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 36832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DNLoc.CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding(); 36842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DNLoc.CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding(); 36852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(DName, NameLoc, DNLoc); 368680ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall } 368780ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall } 368880ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall 3689146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParm: { 3690146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 3691146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParm(); 3692146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo(subst->getParameter()->getDeclName(), 3693146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall NameLoc); 3694146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3695146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3696146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParmPack: { 3697146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmPackStorage *subst 3698146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParmPack(); 3699146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo(subst->getParameterPack()->getDeclName(), 3700146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall NameLoc); 3701146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3702146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3703146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3704146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm_unreachable("bad template name kind!"); 370580ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall} 370680ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall 37074ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) const { 3708146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall switch (Name.getKind()) { 3709146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::QualifiedTemplate: 3710146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::Template: { 3711146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateDecl *Template = Name.getAsTemplateDecl(); 37123e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (TemplateTemplateParmDecl *TTP 3713146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = dyn_cast<TemplateTemplateParmDecl>(Template)) 37143e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Template = getCanonicalTemplateTemplateParmDecl(TTP); 37153e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 37163e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // The canonical template name is the canonical template declaration. 371797fbaa2a38804268a024f1a104b43fcf8b4411b0Argyrios Kyrtzidis return TemplateName(cast<TemplateDecl>(Template->getCanonicalDecl())); 37183e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 371925a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 3720146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::OverloadedTemplate: 3721146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm_unreachable("cannot canonicalize overloaded template"); 3722146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3723146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::DependentTemplate: { 3724146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall DependentTemplateName *DTN = Name.getAsDependentTemplateName(); 3725146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall assert(DTN && "Non-dependent template names must refer to template decls."); 3726146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DTN->CanonicalTemplateName; 3727146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3728146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3729146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParm: { 3730146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 3731146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParm(); 3732146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return getCanonicalTemplateName(subst->getReplacement()); 37331aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 37341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3735146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParmPack: { 3736146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmPackStorage *subst 3737146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParmPack(); 3738146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateTemplateParmDecl *canonParameter 3739146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = getCanonicalTemplateTemplateParmDecl(subst->getParameterPack()); 3740146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateArgument canonArgPack 3741146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = getCanonicalTemplateArgument(subst->getArgumentPack()); 3742146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return getSubstTemplateTemplateParmPack(canonParameter, canonArgPack); 3743146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3744146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3745146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3746146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm_unreachable("bad template name!"); 374725a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor} 374825a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 3749db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregorbool ASTContext::hasSameTemplateName(TemplateName X, TemplateName Y) { 3750db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor X = getCanonicalTemplateName(X); 3751db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor Y = getCanonicalTemplateName(Y); 3752db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor return X.getAsVoidPointer() == Y.getAsVoidPointer(); 3753db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor} 3754db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor 37551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateArgument 37564ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const { 37571275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor switch (Arg.getKind()) { 37581275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Null: 37591275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 37601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37611275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Expression: 37621275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 37631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3764d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor case TemplateArgument::Declaration: { 3765d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman ValueDecl *D = cast<ValueDecl>(Arg.getAsDecl()->getCanonicalDecl()); 3766d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman return TemplateArgument(D, Arg.isDeclForReferenceParam()); 3767d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor } 37681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3769d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman case TemplateArgument::NullPtr: 3770d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman return TemplateArgument(getCanonicalType(Arg.getNullPtrType()), 3771d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman /*isNullPtr*/true); 3772d7a6b1640e565487d163023a6a2e83f55476ae96Eli Friedman 3773788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 3774788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate())); 3775a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 3776a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 3777a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgument(getCanonicalTemplateName( 3778a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Arg.getAsTemplateOrTemplatePattern()), 37792be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor Arg.getNumTemplateExpansions()); 3780a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 37811275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Integral: 3782855243789cb44799c03f4c7216d3d6308805f549Benjamin Kramer return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType())); 37831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37841275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Type: 3785833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return TemplateArgument(getCanonicalType(Arg.getAsType())); 37861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37871275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Pack: { 378887dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor if (Arg.pack_size() == 0) 378987dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor return Arg; 379087dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor 3791910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *CanonArgs 3792910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (*this) TemplateArgument[Arg.pack_size()]; 37931275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor unsigned Idx = 0; 37941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 37951275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor AEnd = Arg.pack_end(); 37961275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor A != AEnd; (void)++A, ++Idx) 37971275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs[Idx] = getCanonicalTemplateArgument(*A); 37981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3799910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor return TemplateArgument(CanonArgs, Arg.pack_size()); 38001275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 38011275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 38021275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 38031275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Silence GCC warning 3804b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unhandled template argument kind"); 38051275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor} 38061275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 3807d57959af02b4af695276f4204443afe6e5d86bd8Douglas GregorNestedNameSpecifier * 38084ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const { 38091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (!NNS) 3810d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return 0; 3811d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3812d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor switch (NNS->getKind()) { 3813d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Identifier: 3814d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // Canonicalize the prefix but keep the identifier the same. 38151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return NestedNameSpecifier::Create(*this, 3816d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor getCanonicalNestedNameSpecifier(NNS->getPrefix()), 3817d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NNS->getAsIdentifier()); 3818d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3819d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Namespace: 3820d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // A namespace is canonical; build a nested-name-specifier with 3821d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // this namespace and no prefix. 382214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor return NestedNameSpecifier::Create(*this, 0, 382314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NNS->getAsNamespace()->getOriginalNamespace()); 382414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 382514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor case NestedNameSpecifier::NamespaceAlias: 382614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor // A namespace is canonical; build a nested-name-specifier with 382714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor // this namespace and no prefix. 382814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor return NestedNameSpecifier::Create(*this, 0, 382914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NNS->getAsNamespaceAlias()->getNamespace() 383014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor ->getOriginalNamespace()); 3831d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3832d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpec: 3833d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: { 3834d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType T = getCanonicalType(QualType(NNS->getAsType(), 0)); 3835264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor 3836264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // If we have some kind of dependent-named type (e.g., "typename T::type"), 3837264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // break it apart into its prefix and identifier, then reconsititute those 3838264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // as the canonical nested-name-specifier. This is required to canonicalize 3839264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // a dependent nested-name-specifier involving typedefs of dependent-name 3840264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // types, e.g., 3841264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // typedef typename T::type T1; 3842264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // typedef typename T1::type T2; 384316412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman if (const DependentNameType *DNT = T->getAs<DependentNameType>()) 384416412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman return NestedNameSpecifier::Create(*this, DNT->getQualifier(), 3845264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor const_cast<IdentifierInfo *>(DNT->getIdentifier())); 3846264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor 384716412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman // Otherwise, just canonicalize the type, and force it to be a TypeSpec. 384816412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman // FIXME: Why are TypeSpec and TypeSpecWithTemplate distinct in the 384916412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman // first place? 38503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return NestedNameSpecifier::Create(*this, 0, false, 38513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const_cast<Type*>(T.getTypePtr())); 3852d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3853d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3854d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Global: 3855d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // The global specifier is canonical and unique. 3856d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return NNS; 3857d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3858d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 38597530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid NestedNameSpecifier::Kind!"); 3860d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 3861d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3862c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 38634ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadconst ArrayType *ASTContext::getAsArrayType(QualType T) const { 3864c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the non-qualified case efficiently. 3865a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (!T.hasLocalQualifiers()) { 3866c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the common positive case fast. 3867c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(T)) 3868c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT; 3869c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 38701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Handle the common negative case fast. 38723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isa<ArrayType>(T.getCanonicalType())) 3873c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 38741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Apply any qualifiers from the array type to the element type. This 3876c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // implements C99 6.7.3p8: "If the specification of an array type includes 3877c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // any type qualifiers, the element type is so qualified, not the array type." 38781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3879c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we get here, we either have type qualifiers on the type, or we have 3880c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // sugar such as a typedef in the way. If we have type qualifiers on the type 388150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor // we must propagate them down into the element type. 38820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 38833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split = T.getSplitDesugaredType(); 3884200fa53fd420aa8369586f569dbece04930ad6a3John McCall Qualifiers qs = split.Quals; 38851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3886c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we have a simple case, just return now. 3887200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ArrayType *ATy = dyn_cast<ArrayType>(split.Ty); 38883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (ATy == 0 || qs.empty()) 3889c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy; 38901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3891c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Otherwise, we have an array and we have qualifiers on it. Push the 3892c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // qualifiers into the array element type and return a new array type. 38933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType NewEltTy = getQualifiedType(ATy->getElementType(), qs); 38941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3895c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(ATy)) 3896c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getConstantArrayType(NewEltTy, CAT->getSize(), 3897c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner CAT->getSizeModifier(), 38980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CAT->getIndexTypeCVRQualifiers())); 3899c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(ATy)) 3900c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getIncompleteArrayType(NewEltTy, 3901c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner IAT->getSizeModifier(), 39020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall IAT->getIndexTypeCVRQualifiers())); 3903898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 39041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const DependentSizedArrayType *DSAT 3905898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor = dyn_cast<DependentSizedArrayType>(ATy)) 3906898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return cast<ArrayType>( 39071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDependentSizedArrayType(NewEltTy, 39083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall DSAT->getSizeExpr(), 3909898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DSAT->getSizeModifier(), 39100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall DSAT->getIndexTypeCVRQualifiers(), 39117e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor DSAT->getBracketsRange())); 39121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3913c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const VariableArrayType *VAT = cast<VariableArrayType>(ATy); 39147e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return cast<ArrayType>(getVariableArrayType(NewEltTy, 39153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall VAT->getSizeExpr(), 3916c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner VAT->getSizeModifier(), 39170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall VAT->getIndexTypeCVRQualifiers(), 39187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor VAT->getBracketsRange())); 391977c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner} 392077c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner 3921ad9689f3531c49e4bff467d9469993606800068cAbramo BagnaraQualType ASTContext::getAdjustedParameterType(QualType T) const { 392279e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // C99 6.7.5.3p7: 392379e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // A declaration of a parameter as "array of type" shall be 392479e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // adjusted to "qualified pointer to type", where the type 392579e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // qualifiers (if any) are those specified within the [ and ] of 392679e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // the array type derivation. 392779e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor if (T->isArrayType()) 392879e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return getArrayDecayedType(T); 392979e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 393079e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // C99 6.7.5.3p8: 393179e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // A declaration of a parameter as "function returning type" 393279e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // shall be adjusted to "pointer to function returning type", as 393379e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // in 6.3.2.1. 393479e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor if (T->isFunctionType()) 393579e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return getPointerType(T); 393679e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 393779e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return T; 393879e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor} 393979e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 3940ad9689f3531c49e4bff467d9469993606800068cAbramo BagnaraQualType ASTContext::getSignatureParameterType(QualType T) const { 394179e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor T = getVariableArrayDecayedType(T); 394279e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor T = getAdjustedParameterType(T); 394379e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return T.getUnqualifiedType(); 394479e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor} 394579e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 3946e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// getArrayDecayedType - Return the properly qualified result of decaying the 3947e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// specified array type to a pointer. This operation is non-trivial when 3948e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// handling typedefs etc. The canonical type of "T" must be an array type, 3949e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// this returns a pointer to a properly qualified element of the array. 3950e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// 3951e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 39524ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getArrayDecayedType(QualType Ty) const { 3953c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Get the element type with 'getAsArrayType' so that we don't lose any 3954c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // typedefs in the element type of the array. This also handles propagation 3955c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // of type qualifiers from the array type into the element type if present 3956c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // (C99 6.7.3p8). 3957c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const ArrayType *PrettyArrayType = getAsArrayType(Ty); 3958c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner assert(PrettyArrayType && "Not an array type!"); 39591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3960c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType PtrTy = getPointerType(PrettyArrayType->getElementType()); 3961e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 3962e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner // int x[restrict 4] -> int *restrict 39630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getQualifiedType(PtrTy, PrettyArrayType->getIndexTypeQualifiers()); 3964e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner} 3965e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 39663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getBaseElementType(const ArrayType *array) const { 39673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getBaseElementType(array->getElementType()); 39685e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 39695e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 39703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getBaseElementType(QualType type) const { 39713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers qs; 39723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall while (true) { 39733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split = type.getSplitDesugaredType(); 3974200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ArrayType *array = split.Ty->getAsArrayTypeUnsafe(); 39753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!array) break; 39761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall type = array->getElementType(); 3978200fa53fd420aa8369586f569dbece04930ad6a3John McCall qs.addConsistentQualifiers(split.Quals); 39793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 39801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiedType(type, qs); 39826183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson} 39836183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson 39840de78998e7bda473b408437053e48661b510d453Fariborz Jahanian/// getConstantArrayElementCount - Returns number of constant array elements. 39851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpuint64_t 39860de78998e7bda473b408437053e48661b510d453Fariborz JahanianASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) const { 39870de78998e7bda473b408437053e48661b510d453Fariborz Jahanian uint64_t ElementCount = 1; 39880de78998e7bda473b408437053e48661b510d453Fariborz Jahanian do { 39890de78998e7bda473b408437053e48661b510d453Fariborz Jahanian ElementCount *= CA->getSize().getZExtValue(); 39900de78998e7bda473b408437053e48661b510d453Fariborz Jahanian CA = dyn_cast<ConstantArrayType>(CA->getElementType()); 39910de78998e7bda473b408437053e48661b510d453Fariborz Jahanian } while (CA); 39920de78998e7bda473b408437053e48661b510d453Fariborz Jahanian return ElementCount; 39930de78998e7bda473b408437053e48661b510d453Fariborz Jahanian} 39940de78998e7bda473b408437053e48661b510d453Fariborz Jahanian 39955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFloatingRank - Return a relative rank for floating point types. 39965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// This routine will assert if passed a built-in type that isn't a float. 3997a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattnerstatic FloatingRank getFloatingRank(QualType T) { 3998183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType *CT = T->getAs<ComplexType>()) 39995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getFloatingRank(CT->getElementType()); 4000a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner 4001183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall assert(T->getAs<BuiltinType>() && "getFloatingRank(): not a floating type"); 4002183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall switch (T->getAs<BuiltinType>()->getKind()) { 4003b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("getFloatingRank(): not a floating type"); 4004aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case BuiltinType::Half: return HalfRank; 40055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Float: return FloatRank; 40065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Double: return DoubleRank; 40075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::LongDouble: return LongDoubleRank; 40085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 40095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 40105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 40111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getFloatingTypeOfSizeWithinDomain - Returns a real floating 40121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// point or a complex type (based on typeDomain/typeSize). 4013716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeDomain' is a real floating point or complex type. 4014716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeSize' is a real floating point or complex type. 40151361b11066239ea15764a2a844405352d87296b3Chris LattnerQualType ASTContext::getFloatingTypeOfSizeWithinDomain(QualType Size, 40161361b11066239ea15764a2a844405352d87296b3Chris Lattner QualType Domain) const { 40171361b11066239ea15764a2a844405352d87296b3Chris Lattner FloatingRank EltRank = getFloatingRank(Size); 40181361b11066239ea15764a2a844405352d87296b3Chris Lattner if (Domain->isComplexType()) { 40191361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 4020561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie case HalfRank: llvm_unreachable("Complex half is not supported"); 4021f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case FloatRank: return FloatComplexTy; 4022f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case DoubleRank: return DoubleComplexTy; 4023f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case LongDoubleRank: return LongDoubleComplexTy; 4024f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 4025f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 40261361b11066239ea15764a2a844405352d87296b3Chris Lattner 40271361b11066239ea15764a2a844405352d87296b3Chris Lattner assert(Domain->isRealFloatingType() && "Unknown domain!"); 40281361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 4029561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie case HalfRank: llvm_unreachable("Half ranks are not valid here"); 40301361b11066239ea15764a2a844405352d87296b3Chris Lattner case FloatRank: return FloatTy; 40311361b11066239ea15764a2a844405352d87296b3Chris Lattner case DoubleRank: return DoubleTy; 40321361b11066239ea15764a2a844405352d87296b3Chris Lattner case LongDoubleRank: return LongDoubleTy; 40335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4034561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie llvm_unreachable("getFloatingRank(): illegal value for rank"); 40355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 40365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 40377cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// getFloatingTypeOrder - Compare the rank of the two specified floating 40387cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// point types, ignoring the domain of the type (i.e. 'double' == 40397cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If 40401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// LHS < RHS, return -1. 40414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadint ASTContext::getFloatingTypeOrder(QualType LHS, QualType RHS) const { 4042a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank LHSR = getFloatingRank(LHS); 4043a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank RHSR = getFloatingRank(RHS); 40441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4045a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR == RHSR) 4046fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 0; 4047a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR > RHSR) 4048fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 1; 4049fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return -1; 40505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 40515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4052f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This 4053f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// routine will assert if passed a built-in type that isn't an integer or enum, 4054f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// or if it is not canonicalized. 4055f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCallunsigned ASTContext::getIntegerRank(const Type *T) const { 4056467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall assert(T->isCanonicalUnqualified() && "T should be canonicalized"); 4057f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 4058f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 4059b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("getIntegerRank(): not a built-in integer"); 40607cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Bool: 4061f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 1 + (getIntWidth(BoolTy) << 3); 40627cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_S: 40637cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_U: 40647cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::SChar: 40657cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UChar: 4066f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 2 + (getIntWidth(CharTy) << 3); 40677cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Short: 40687cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UShort: 4069f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 3 + (getIntWidth(ShortTy) << 3); 40707cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Int: 40717cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UInt: 4072f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 4 + (getIntWidth(IntTy) << 3); 40737cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Long: 40747cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULong: 4075f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 5 + (getIntWidth(LongTy) << 3); 40767cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::LongLong: 40777cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULongLong: 4078f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 6 + (getIntWidth(LongLongTy) << 3); 40792df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 40802df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::UInt128: 40812df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return 7 + (getIntWidth(Int128Ty) << 3); 4082f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner } 4083f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner} 4084f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner 408504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \brief Whether this is a promotable bitfield reference according 408604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 408704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// 408804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \returns the type this bit-field will promote to, or NULL if no 408904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// promotion occurs. 40904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::isPromotableBitField(Expr *E) const { 4091ceafbdeb93ecf323cca74e660bf54504c86f3b71Douglas Gregor if (E->isTypeDependent() || E->isValueDependent()) 4092ceafbdeb93ecf323cca74e660bf54504c86f3b71Douglas Gregor return QualType(); 4093ceafbdeb93ecf323cca74e660bf54504c86f3b71Douglas Gregor 409404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman FieldDecl *Field = E->getBitField(); 409504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (!Field) 409604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 409704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 409804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman QualType FT = Field->getType(); 409904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 4100a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith uint64_t BitWidth = Field->getBitWidthValue(*this); 410104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 410204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // GCC extension compatibility: if the bit-field size is less than or equal 410304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // to the size of int, it gets promoted no matter what its type is. 410404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // For instance, unsigned long bf : 4 gets promoted to signed int. 410504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth < IntSize) 410604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return IntTy; 410704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 410804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth == IntSize) 410904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return FT->isSignedIntegerType() ? IntTy : UnsignedIntTy; 411004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 411104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // Types bigger than int are not subject to promotions, and therefore act 411204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // like the base type. 411304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // FIXME: This doesn't quite match what gcc does, but what gcc does here 411404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // is ridiculous. 411504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 411604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman} 411704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 4118a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// getPromotedIntegerType - Returns the type that Promotable will 4119a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable 4120a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// integer type. 41214ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getPromotedIntegerType(QualType Promotable) const { 4122a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(!Promotable.isNull()); 4123a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isPromotableIntegerType()); 4124842aef8d942a880eeb9535d40de31a86838264cbJohn McCall if (const EnumType *ET = Promotable->getAs<EnumType>()) 4125842aef8d942a880eeb9535d40de31a86838264cbJohn McCall return ET->getDecl()->getPromotionType(); 412668a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman 412768a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman if (const BuiltinType *BT = Promotable->getAs<BuiltinType>()) { 412868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // C++ [conv.prom]: A prvalue of type char16_t, char32_t, or wchar_t 412968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // (3.9.1) can be converted to a prvalue of the first of the following 413068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // types that can represent all the values of its underlying type: 413168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // int, unsigned int, long int, unsigned long int, long long int, or 413268a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // unsigned long long int [...] 413368a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // FIXME: Is there some better way to compute this? 413468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman if (BT->getKind() == BuiltinType::WChar_S || 413568a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman BT->getKind() == BuiltinType::WChar_U || 413668a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman BT->getKind() == BuiltinType::Char16 || 413768a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman BT->getKind() == BuiltinType::Char32) { 413868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman bool FromIsSigned = BT->getKind() == BuiltinType::WChar_S; 413968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman uint64_t FromSize = getTypeSize(BT); 414068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman QualType PromoteTypes[] = { IntTy, UnsignedIntTy, LongTy, UnsignedLongTy, 414168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman LongLongTy, UnsignedLongLongTy }; 414268a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman for (size_t Idx = 0; Idx < llvm::array_lengthof(PromoteTypes); ++Idx) { 414368a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman uint64_t ToSize = getTypeSize(PromoteTypes[Idx]); 414468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman if (FromSize < ToSize || 414568a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman (FromSize == ToSize && 414668a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) 414768a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman return PromoteTypes[Idx]; 414868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman } 414968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman llvm_unreachable("char type should fit into long long"); 415068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman } 415168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman } 415268a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman 415368a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // At this point, we should have a signed or unsigned integer type. 4154a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (Promotable->isSignedIntegerType()) 4155a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return IntTy; 4156a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t PromotableSize = getTypeSize(Promotable); 4157a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 4158a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isUnsignedIntegerType() && PromotableSize <= IntSize); 4159a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy; 4160a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman} 4161a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 416231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis/// \brief Recurses in pointer/array types until it finds an objc retainable 416331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis/// type and returns its ownership. 416431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios KyrtzidisQualifiers::ObjCLifetime ASTContext::getInnerObjCOwnership(QualType T) const { 416531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis while (!T.isNull()) { 416631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (T.getObjCLifetime() != Qualifiers::OCL_None) 416731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return T.getObjCLifetime(); 416831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (T->isArrayType()) 416931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis T = getBaseElementType(T); 417031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis else if (const PointerType *PT = T->getAs<PointerType>()) 417131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis T = PT->getPointeeType(); 417231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 417328445f0b62f6aed851ff87ce64d9b19200d3211fArgyrios Kyrtzidis T = RT->getPointeeType(); 417431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis else 417531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis break; 417631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } 417731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 417831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return Qualifiers::OCL_None; 417931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis} 418031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 41811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getIntegerTypeOrder - Returns the highest ranked integer type: 41827cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If 41831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// LHS < RHS, return -1. 41844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadint ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const { 4185f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *LHSC = getCanonicalType(LHS).getTypePtr(); 4186f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *RHSC = getCanonicalType(RHS).getTypePtr(); 41877cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSC == RHSC) return 0; 41881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4189f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool LHSUnsigned = LHSC->isUnsignedIntegerType(); 4190f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool RHSUnsigned = RHSC->isUnsignedIntegerType(); 41911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41927cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned LHSRank = getIntegerRank(LHSC); 41937cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned RHSRank = getIntegerRank(RHSC); 41941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41957cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned == RHSUnsigned) { // Both signed or both unsigned. 41967cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank == RHSRank) return 0; 41977cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return LHSRank > RHSRank ? 1 : -1; 41987cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 41991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42007cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // Otherwise, the LHS is signed and the RHS is unsigned or visa versa. 42017cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned) { 42027cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [LHS] type is larger, return it. 42037cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank >= RHSRank) 42047cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 42051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42067cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 42077cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 42081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // powers of two larger than each other, this is always safe. 42097cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 42107cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 42117cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner 42127cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [RHS] type is larger, return it. 42137cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (RHSRank >= LHSRank) 42147cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 42151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42167cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 42177cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 42181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // powers of two larger than each other, this is always safe. 42197cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 42205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 422171993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson 422279cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlssonstatic RecordDecl * 4223ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo BagnaraCreateRecordDecl(const ASTContext &Ctx, RecordDecl::TagKind TK, 4224ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara DeclContext *DC, IdentifierInfo *Id) { 4225ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara SourceLocation Loc; 42264e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Ctx.getLangOpts().CPlusPlus) 4227ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara return CXXRecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id); 422879cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson else 4229ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara return RecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id); 423079cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson} 4231ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara 42321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// getCFConstantStringType - Return the type used for constant CFStrings. 42334ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getCFConstantStringType() const { 423471993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson if (!CFConstantStringTypeDecl) { 42351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CFConstantStringTypeDecl = 4236ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara CreateRecordDecl(*this, TTK_Struct, TUDecl, 423779cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson &Idents.get("NSConstantString")); 42385cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall CFConstantStringTypeDecl->startDefinition(); 423979cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson 4240f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson QualType FieldTypes[4]; 42411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 424271993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const int *isa; 42430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FieldTypes[0] = getPointerType(IntTy.withConst()); 4244f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson // int flags; 4245f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson FieldTypes[1] = IntTy; 424671993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const char *str; 42470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FieldTypes[2] = getPointerType(CharTy.withConst()); 424871993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // long length; 42491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FieldTypes[3] = LongTy; 42501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 425144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor // Create fields 425244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor for (unsigned i = 0; i < 4; ++i) { 42531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl, 4254ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 425544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor SourceLocation(), 0, 4256a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 42571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /*BitWidth=*/0, 42587a614d8380297fcd2bc23986241905d97222948cRichard Smith /*Mutable=*/false, 4259ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 42602888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 426117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis CFConstantStringTypeDecl->addDecl(Field); 426244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 426344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4264838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor CFConstantStringTypeDecl->completeDefinition(); 426571993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson } 42661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 426771993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson return getTagDeclType(CFConstantStringTypeDecl); 42688467583c2704e7a9691ea56939a029015f0ade0aGabor Greif} 4269b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson 4270319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregorvoid ASTContext::setCFConstantStringType(QualType T) { 42716217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek const RecordType *Rec = T->getAs<RecordType>(); 4272319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor assert(Rec && "Invalid CFConstantStringType"); 4273319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor CFConstantStringTypeDecl = Rec->getDecl(); 4274319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor} 4275319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor 42764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getBlockDescriptorType() const { 4277adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump if (BlockDescriptorType) 4278adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump return getTagDeclType(BlockDescriptorType); 4279adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4280adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump RecordDecl *T; 4281adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump // FIXME: Needs the FlagAppleBlock bit. 4282ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara T = CreateRecordDecl(*this, TTK_Struct, TUDecl, 428379cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson &Idents.get("__block_descriptor")); 42845cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall T->startDefinition(); 4285adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4286adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump QualType FieldTypes[] = { 4287adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump UnsignedLongTy, 4288adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump UnsignedLongTy, 4289adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump }; 4290adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4291adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump const char *FieldNames[] = { 4292adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump "reserved", 4293083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "Size" 4294adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump }; 4295adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4296adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump for (size_t i = 0; i < 2; ++i) { 4297ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara FieldDecl *Field = FieldDecl::Create(*this, T, SourceLocation(), 4298adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump SourceLocation(), 4299adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump &Idents.get(FieldNames[i]), 4300a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 4301adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump /*BitWidth=*/0, 43027a614d8380297fcd2bc23986241905d97222948cRichard Smith /*Mutable=*/false, 4303ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 43042888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 4305adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump T->addDecl(Field); 4306adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump } 4307adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4308838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor T->completeDefinition(); 4309adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4310adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump BlockDescriptorType = T; 4311adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4312adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump return getTagDeclType(BlockDescriptorType); 4313adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump} 4314adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 43154ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getBlockDescriptorExtendedType() const { 4316083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump if (BlockDescriptorExtendedType) 4317083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump return getTagDeclType(BlockDescriptorExtendedType); 4318083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4319083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump RecordDecl *T; 4320083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump // FIXME: Needs the FlagAppleBlock bit. 4321ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara T = CreateRecordDecl(*this, TTK_Struct, TUDecl, 432279cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson &Idents.get("__block_descriptor_withcopydispose")); 43235cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall T->startDefinition(); 4324083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4325083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump QualType FieldTypes[] = { 4326083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump UnsignedLongTy, 4327083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump UnsignedLongTy, 4328083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump getPointerType(VoidPtrTy), 4329083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump getPointerType(VoidPtrTy) 4330083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump }; 4331083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4332083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump const char *FieldNames[] = { 4333083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "reserved", 4334083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "Size", 4335083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "CopyFuncPtr", 4336083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "DestroyFuncPtr" 4337083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump }; 4338083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4339083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump for (size_t i = 0; i < 4; ++i) { 4340ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara FieldDecl *Field = FieldDecl::Create(*this, T, SourceLocation(), 4341083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump SourceLocation(), 4342083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump &Idents.get(FieldNames[i]), 4343a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 4344083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump /*BitWidth=*/0, 43457a614d8380297fcd2bc23986241905d97222948cRichard Smith /*Mutable=*/false, 4346ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 43472888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 4348083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump T->addDecl(Field); 4349083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump } 4350083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4351838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor T->completeDefinition(); 4352083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4353083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump BlockDescriptorExtendedType = T; 4354083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4355083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump return getTagDeclType(BlockDescriptorExtendedType); 4356083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump} 4357083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 43584ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ASTContext::BlockRequiresCopying(QualType Ty) const { 4359f85e193739c953358c865005855253af4f68a497John McCall if (Ty->isObjCRetainableType()) 4360af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump return true; 43614e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) { 4362e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian if (const RecordType *RT = Ty->getAs<RecordType>()) { 4363e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); 4364ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Hunt return RD->hasConstCopyConstructor(); 4365e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian 4366e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian } 4367e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian } 4368af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump return false; 4369af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump} 4370af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 43714ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 43725f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerASTContext::BuildByRefType(StringRef DeclName, QualType Ty) const { 4373af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // type = struct __Block_byref_1_X { 4374ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // void *__isa; 4375af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // struct __Block_byref_1_X *__forwarding; 4376ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // unsigned int __flags; 4377ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // unsigned int __size; 4378a7e6845660f91ec611427e1db842780e1ec12bdbEli Friedman // void *__copy_helper; // as needed 4379a7e6845660f91ec611427e1db842780e1ec12bdbEli Friedman // void *__destroy_help // as needed 4380af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // int X; 4381ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // } * 4382ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump 4383af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump bool HasCopyAndDispose = BlockRequiresCopying(Ty); 4384af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4385af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // FIXME: Move up 4386f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<36> Name; 4387f5942a44880be26878592eb052b737579349411eBenjamin Kramer llvm::raw_svector_ostream(Name) << "__Block_byref_" << 4388f5942a44880be26878592eb052b737579349411eBenjamin Kramer ++UniqueBlockByRefTypeID << '_' << DeclName; 4389af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump RecordDecl *T; 4390ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara T = CreateRecordDecl(*this, TTK_Struct, TUDecl, &Idents.get(Name.str())); 4391af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump T->startDefinition(); 4392af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump QualType Int32Ty = IntTy; 4393af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump assert(getIntWidth(IntTy) == 32 && "non-32bit int not supported"); 4394af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump QualType FieldTypes[] = { 4395af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(VoidPtrTy), 4396af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(getTagDeclType(T)), 4397af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump Int32Ty, 4398af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump Int32Ty, 4399af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(VoidPtrTy), 4400af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(VoidPtrTy), 4401af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump Ty 4402af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump }; 4403af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 44045f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef FieldNames[] = { 4405af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__isa", 4406af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__forwarding", 4407af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__flags", 4408af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__size", 4409af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__copy_helper", 4410af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__destroy_helper", 4411af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump DeclName, 4412af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump }; 4413af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4414af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump for (size_t i = 0; i < 7; ++i) { 4415af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump if (!HasCopyAndDispose && i >=4 && i <= 5) 4416af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump continue; 4417af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump FieldDecl *Field = FieldDecl::Create(*this, T, SourceLocation(), 4418ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 4419af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump &Idents.get(FieldNames[i]), 4420a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 44217a614d8380297fcd2bc23986241905d97222948cRichard Smith /*BitWidth=*/0, /*Mutable=*/false, 4422ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 44232888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 4424af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump T->addDecl(Field); 4425af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump } 4426af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4427838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor T->completeDefinition(); 4428af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4429af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump return getPointerType(getTagDeclType(T)); 4430ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump} 4431ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump 4432e97179c675b341927807c718be215c8d1aab8acbDouglas GregorTypedefDecl *ASTContext::getObjCInstanceTypeDecl() { 4433e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor if (!ObjCInstanceTypeDecl) 4434e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor ObjCInstanceTypeDecl = TypedefDecl::Create(*this, 4435e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor getTranslationUnitDecl(), 4436e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor SourceLocation(), 4437e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor SourceLocation(), 4438e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor &Idents.get("instancetype"), 4439e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor getTrivialTypeSourceInfo(getObjCIdType())); 4440e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor return ObjCInstanceTypeDecl; 4441e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor} 4442e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor 4443e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// This returns true if a type has been typedefed to BOOL: 4444e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// typedef <type> BOOL; 44452d99833e8c956775f2183601cd120b65b569c867Chris Lattnerstatic bool isTypeTypedefedAsBOOL(QualType T) { 4446e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (const TypedefType *TT = dyn_cast<TypedefType>(T)) 4447bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner if (IdentifierInfo *II = TT->getDecl()->getIdentifier()) 4448bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner return II->isStr("BOOL"); 44491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 445085f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return false; 445185f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 445285f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 4453a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingTypeSize returns size of type for objective-c encoding 445433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// purpose. 44554ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getObjCEncodingTypeSize(QualType type) const { 4456f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor if (!type->isIncompleteArrayType() && type->isIncompleteType()) 4457f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor return CharUnits::Zero(); 4458f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor 4459199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits sz = getTypeSizeInChars(type); 44601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 446133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Make all integer and enum types at least as large as an int 44622ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (sz.isPositive() && type->isIntegralOrEnumerationType()) 4463199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck sz = std::max(sz, getTypeSizeInChars(IntTy)); 446433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Treat arrays as pointers, since that's how they're passed in. 446533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian else if (type->isArrayType()) 4466199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck sz = getTypeSizeInChars(VoidPtrTy); 4467aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck return sz; 4468199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck} 4469199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck 4470199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyckstatic inline 4471199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyckstd::string charUnitsToString(const CharUnits &CU) { 4472199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck return llvm::itostr(CU.getQuantity()); 447333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 447433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 44756b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// getObjCEncodingForBlock - Return the encoded type for this block 44765e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall/// declaration. 44776b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCallstd::string ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr) const { 44786b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall std::string S; 44796b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall 44805e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall const BlockDecl *Decl = Expr->getBlockDecl(); 44815e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall QualType BlockTy = 44825e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall Expr->getType()->getAs<BlockPointerType>()->getPointeeType(); 44835e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Encode result type. 4484c71a4915ca216847599d03cab4ed1c5086b0eb43John McCall getObjCEncodingForType(BlockTy->getAs<FunctionType>()->getResultType(), S); 44855e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Compute size of all parameters. 44865e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Start with computing size of a pointer in number of bytes. 44875e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // FIXME: There might(should) be a better way of doing this computation! 44885e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall SourceLocation Loc; 4489199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits PtrSize = getTypeSizeInChars(VoidPtrTy); 4490199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits ParmOffset = PtrSize; 44916f46c2653c1545cc3fef0c0df996d18160160ce8Fariborz Jahanian for (BlockDecl::param_const_iterator PI = Decl->param_begin(), 44925e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall E = Decl->param_end(); PI != E; ++PI) { 44935e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall QualType PType = (*PI)->getType(); 4494aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck CharUnits sz = getObjCEncodingTypeSize(PType); 4495075a54354dc6e3644b12206e5127855091783fd6Fariborz Jahanian if (sz.isZero()) 4496075a54354dc6e3644b12206e5127855091783fd6Fariborz Jahanian continue; 4497199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck assert (sz.isPositive() && "BlockExpr - Incomplete param type"); 44985e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall ParmOffset += sz; 44995e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall } 45005e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Size of the argument frame 4501199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 45025e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Block pointer and offset. 45035e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall S += "@?0"; 45045e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall 45055e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Argument types. 45065e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall ParmOffset = PtrSize; 45075e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall for (BlockDecl::param_const_iterator PI = Decl->param_begin(), E = 45085e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall Decl->param_end(); PI != E; ++PI) { 45095e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall ParmVarDecl *PVDecl = *PI; 45105e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall QualType PType = PVDecl->getOriginalType(); 45115e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall if (const ArrayType *AT = 45125e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 45135e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Use array's original type only if it has known number of 45145389f48b24937ad7b4093307128b3cbf25235654David Chisnall // elements. 45155389f48b24937ad7b4093307128b3cbf25235654David Chisnall if (!isa<ConstantArrayType>(AT)) 45165389f48b24937ad7b4093307128b3cbf25235654David Chisnall PType = PVDecl->getType(); 45175389f48b24937ad7b4093307128b3cbf25235654David Chisnall } else if (PType->isFunctionType()) 45185389f48b24937ad7b4093307128b3cbf25235654David Chisnall PType = PVDecl->getType(); 45195389f48b24937ad7b4093307128b3cbf25235654David Chisnall getObjCEncodingForType(PType, S); 45205389f48b24937ad7b4093307128b3cbf25235654David Chisnall S += charUnitsToString(ParmOffset); 45215389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmOffset += getObjCEncodingTypeSize(PType); 45225389f48b24937ad7b4093307128b3cbf25235654David Chisnall } 45236b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall 45246b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall return S; 45255389f48b24937ad7b4093307128b3cbf25235654David Chisnall} 45265389f48b24937ad7b4093307128b3cbf25235654David Chisnall 4527f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregorbool ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, 45285389f48b24937ad7b4093307128b3cbf25235654David Chisnall std::string& S) { 45295389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Encode result type. 45305389f48b24937ad7b4093307128b3cbf25235654David Chisnall getObjCEncodingForType(Decl->getResultType(), S); 45315389f48b24937ad7b4093307128b3cbf25235654David Chisnall CharUnits ParmOffset; 45325389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Compute size of all parameters. 45335389f48b24937ad7b4093307128b3cbf25235654David Chisnall for (FunctionDecl::param_const_iterator PI = Decl->param_begin(), 45345389f48b24937ad7b4093307128b3cbf25235654David Chisnall E = Decl->param_end(); PI != E; ++PI) { 45355389f48b24937ad7b4093307128b3cbf25235654David Chisnall QualType PType = (*PI)->getType(); 45365389f48b24937ad7b4093307128b3cbf25235654David Chisnall CharUnits sz = getObjCEncodingTypeSize(PType); 4537f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor if (sz.isZero()) 45387e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian continue; 45397e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian 45405389f48b24937ad7b4093307128b3cbf25235654David Chisnall assert (sz.isPositive() && 4541f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor "getObjCEncodingForFunctionDecl - Incomplete param type"); 45425389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmOffset += sz; 45435389f48b24937ad7b4093307128b3cbf25235654David Chisnall } 45445389f48b24937ad7b4093307128b3cbf25235654David Chisnall S += charUnitsToString(ParmOffset); 45455389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmOffset = CharUnits::Zero(); 45465389f48b24937ad7b4093307128b3cbf25235654David Chisnall 45475389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Argument types. 45485389f48b24937ad7b4093307128b3cbf25235654David Chisnall for (FunctionDecl::param_const_iterator PI = Decl->param_begin(), 45495389f48b24937ad7b4093307128b3cbf25235654David Chisnall E = Decl->param_end(); PI != E; ++PI) { 45505389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmVarDecl *PVDecl = *PI; 45515389f48b24937ad7b4093307128b3cbf25235654David Chisnall QualType PType = PVDecl->getOriginalType(); 45525389f48b24937ad7b4093307128b3cbf25235654David Chisnall if (const ArrayType *AT = 45535389f48b24937ad7b4093307128b3cbf25235654David Chisnall dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 45545389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Use array's original type only if it has known number of 45555e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // elements. 45565e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall if (!isa<ConstantArrayType>(AT)) 45575e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall PType = PVDecl->getType(); 45585e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall } else if (PType->isFunctionType()) 45595e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall PType = PVDecl->getType(); 45605e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall getObjCEncodingForType(PType, S); 4561199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 4562aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck ParmOffset += getObjCEncodingTypeSize(PType); 45635e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall } 4564f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor 4565f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor return false; 45665e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall} 45675e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall 4568dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson/// getObjCEncodingForMethodParameter - Return the encoded type for a single 4569dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson/// method parameter or return type. If Extended, include class names and 4570dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson/// block object types. 4571dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilsonvoid ASTContext::getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT, 4572dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson QualType T, std::string& S, 4573dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool Extended) const { 4574dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Encode type qualifer, 'in', 'inout', etc. for the parameter. 4575dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeQualifier(QT, S); 4576dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Encode parameter type. 4577dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeImpl(T, S, true, true, 0, 4578dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson true /*OutermostType*/, 4579dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /*EncodingProperty*/, 4580dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /*StructField*/, 4581dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson Extended /*EncodeBlockParameters*/, 4582dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson Extended /*EncodeClassNames*/); 4583dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson} 4584dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson 4585a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingForMethodDecl - Return the encoded type for this method 458633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// declaration. 4587f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregorbool ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, 4588dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson std::string& S, 4589dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool Extended) const { 4590c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 4591dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Encode return type. 4592dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForMethodParameter(Decl->getObjCDeclQualifier(), 4593dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson Decl->getResultType(), S, Extended); 459433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Compute size of all parameters. 459533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Start with computing size of a pointer in number of bytes. 459633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // FIXME: There might(should) be a better way of doing this computation! 459733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian SourceLocation Loc; 4598199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits PtrSize = getTypeSizeInChars(VoidPtrTy); 459933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // The first two arguments (self and _cmd) are pointers; account for 460033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // their size. 4601199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits ParmOffset = 2 * PtrSize; 4602491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(), 46037732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian E = Decl->sel_param_end(); PI != E; ++PI) { 460489951a86b594513c2a013532ed45d197413b1087Chris Lattner QualType PType = (*PI)->getType(); 4605aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck CharUnits sz = getObjCEncodingTypeSize(PType); 4606f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor if (sz.isZero()) 46077e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian continue; 46087e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian 4609199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck assert (sz.isPositive() && 4610199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck "getObjCEncodingForMethodDecl - Incomplete param type"); 461133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset += sz; 461233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 4613199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 461433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += "@0:"; 4615199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(PtrSize); 46161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 461733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Argument types. 461833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset = 2 * PtrSize; 4619491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(), 46207732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian E = Decl->sel_param_end(); PI != E; ++PI) { 4621491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis const ParmVarDecl *PVDecl = *PI; 46221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType PType = PVDecl->getOriginalType(); 46234306d3cb9116605728252e2738df24b9f6ab53c3Fariborz Jahanian if (const ArrayType *AT = 4624ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 4625ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // Use array's original type only if it has known number of 4626ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // elements. 4627bb3fde337fb712c0e6da8790d431621be4793048Steve Naroff if (!isa<ConstantArrayType>(AT)) 4628ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 4629ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff } else if (PType->isFunctionType()) 4630ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 4631dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForMethodParameter(PVDecl->getObjCDeclQualifier(), 4632dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson PType, S, Extended); 4633199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 4634aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck ParmOffset += getObjCEncodingTypeSize(PType); 463533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 4636f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor 4637f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor return false; 463833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 463933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 4640c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// getObjCEncodingForPropertyDecl - Return the encoded type for this 464183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// property declaration. If non-NULL, Container must be either an 4642c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// ObjCCategoryImplDecl or ObjCImplementationDecl; it should only be 4643c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// NULL when getting encodings for protocol properties. 46441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Property attributes are stored as a comma-delimited C string. The simple 46451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// attributes readonly and bycopy are encoded as single characters. The 46461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// parametrized attributes, getter=name, setter=name, and ivar=name, are 46471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// encoded as single characters, followed by an identifier. Property types 46481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// are also encoded as a parametrized attribute. The characters used to encode 464983bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// these attributes are defined by the following enumeration: 465083bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @code 465183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// enum PropertyAttributes { 465283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyReadOnly = 'R', // property is read-only. 465383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyBycopy = 'C', // property is a copy of the value last assigned 465483bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyByref = '&', // property is a reference to the value last assigned 465583bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyDynamic = 'D', // property is dynamic 465683bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyGetter = 'G', // followed by getter selector name 465783bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertySetter = 'S', // followed by setter selector name 465883bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyInstanceVariable = 'V' // followed by instance variable name 46590d4cb85130d91da61c45aecb9fd31c7097a7cfccBob Wilson/// kPropertyType = 'T' // followed by old-style type encoding. 466083bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyWeak = 'W' // 'weak' property 466183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyStrong = 'P' // property GC'able 466283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyNonAtomic = 'N' // property non-atomic 466383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// }; 466483bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @endcode 46651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 4666c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const Decl *Container, 46674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad std::string& S) const { 4668c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Collect information from the property implementation decl(s). 4669c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar bool Dynamic = false; 4670c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar ObjCPropertyImplDecl *SynthesizePID = 0; 4671c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4672c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: Duplicated code due to poor abstraction. 4673c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Container) { 46741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const ObjCCategoryImplDecl *CID = 4675c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar dyn_cast<ObjCCategoryImplDecl>(Container)) { 4676c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 467717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = CID->propimpl_begin(), e = CID->propimpl_end(); 4678653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 4679581deb3da481053c4993c7600f97acf7768caac5David Blaikie ObjCPropertyImplDecl *PID = *i; 4680c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 4681c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 4682c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 4683c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 4684c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 4685c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4686c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4687c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4688c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 468961710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container); 4690c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 469117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = OID->propimpl_begin(), e = OID->propimpl_end(); 4692653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 4693581deb3da481053c4993c7600f97acf7768caac5David Blaikie ObjCPropertyImplDecl *PID = *i; 4694c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 4695c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 4696c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 4697c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 4698c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 4699c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4700c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 47011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 4702c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4703c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4704c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4705c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 4706c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S = "T"; 4707c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4708c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Encode result type. 4709090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // GCC has some special rules regarding encoding of properties which 4710090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // closely resembles encoding of ivars. 47111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PD->getType(), S, true, true, 0, 4712090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* outermost type */, 4713090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* encoding for property */); 4714c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4715c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->isReadOnly()) { 4716c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",R"; 4717c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 4718c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar switch (PD->getSetterKind()) { 4719c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Assign: break; 4720c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Copy: S += ",C"; break; 47211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case ObjCPropertyDecl::Retain: S += ",&"; break; 47223a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian case ObjCPropertyDecl::Weak: S += ",W"; break; 4723c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4724c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4725c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4726c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // It really isn't clear at all what this means, since properties 4727c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // are "dynamic by default". 4728c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Dynamic) 4729c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",D"; 4730c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4731090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic) 4732090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian S += ",N"; 47331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4734c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { 4735c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",G"; 4736077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getGetterName().getAsString(); 4737c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4738c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4739c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { 4740c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",S"; 4741077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getSetterName().getAsString(); 4742c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4743c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4744c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (SynthesizePID) { 4745c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const ObjCIvarDecl *OID = SynthesizePID->getPropertyIvarDecl(); 4746c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",V"; 474739f34e97d6a468f0a7dfa5664c61217cffc65b74Chris Lattner S += OID->getNameAsString(); 4748c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4749c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4750c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: OBJCGC: weak & strong 4751c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar} 4752c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4753a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// getLegacyIntegralTypeEncoding - 47541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Another legacy compatibility encoding: 32-bit longs are encoded as 47551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 'l' or 'L' , but not always. For typedefs, we need to use 4756a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 'i' or 'I' instead if encoding a struct field, or a pointer! 4757a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 4758a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanianvoid ASTContext::getLegacyIntegralTypeEncoding (QualType &PointeeTy) const { 47598e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(PointeeTy.getTypePtr())) { 4760183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = PointeeTy->getAs<BuiltinType>()) { 47614ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad if (BT->getKind() == BuiltinType::ULong && getIntWidth(PointeeTy) == 32) 4762a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = UnsignedIntTy; 47631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump else 47644ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad if (BT->getKind() == BuiltinType::Long && getIntWidth(PointeeTy) == 32) 4765a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = IntTy; 4766a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4767a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4768a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian} 4769a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 47707d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanianvoid ASTContext::getObjCEncodingForType(QualType T, std::string& S, 47714ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const FieldDecl *Field) const { 477282a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // We follow the behavior of gcc, expanding structures which are 477382a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // directly pointed to, and expanding embedded structures. Note that 477482a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // these rules are sufficient to prevent recursive encoding of the 477582a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // same type. 47761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(T, S, true, true, Field, 47775b8c7d9fb620ba3a71e996d61e7b9bdf763b5c09Fariborz Jahanian true /* outermost type */); 477882a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar} 477982a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar 478064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnallstatic char ObjCEncodingForPrimitiveKind(const ASTContext *C, QualType T) { 478164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall switch (T->getAs<BuiltinType>()->getKind()) { 4782b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unhandled builtin type kind"); 478364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Void: return 'v'; 478464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Bool: return 'B'; 478564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Char_U: 478664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UChar: return 'C'; 478764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UShort: return 'S'; 478864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UInt: return 'I'; 478964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::ULong: 47904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad return C->getIntWidth(T) == 32 ? 'L' : 'Q'; 479164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UInt128: return 'T'; 479264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::ULongLong: return 'Q'; 479364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Char_S: 479464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::SChar: return 'c'; 479564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Short: return 's'; 47963f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 47973f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 479864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Int: return 'i'; 479964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Long: 48004ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad return C->getIntWidth(T) == 32 ? 'l' : 'q'; 480164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::LongLong: return 'q'; 480264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Int128: return 't'; 480364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Float: return 'f'; 480464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Double: return 'd'; 48053a0be84b2aed8563150cdbd976a98838afa261ebDaniel Dunbar case BuiltinType::LongDouble: return 'D'; 480664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall } 480764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall} 480864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall 48095471bc85b69912e3b448de004498a80c0de32296Douglas Gregorstatic char ObjCEncodingForEnumType(const ASTContext *C, const EnumType *ET) { 48105471bc85b69912e3b448de004498a80c0de32296Douglas Gregor EnumDecl *Enum = ET->getDecl(); 48115471bc85b69912e3b448de004498a80c0de32296Douglas Gregor 48125471bc85b69912e3b448de004498a80c0de32296Douglas Gregor // The encoding of an non-fixed enum type is always 'i', regardless of size. 48135471bc85b69912e3b448de004498a80c0de32296Douglas Gregor if (!Enum->isFixed()) 48145471bc85b69912e3b448de004498a80c0de32296Douglas Gregor return 'i'; 48155471bc85b69912e3b448de004498a80c0de32296Douglas Gregor 48165471bc85b69912e3b448de004498a80c0de32296Douglas Gregor // The encoding of a fixed enum type matches its fixed underlying type. 48175471bc85b69912e3b448de004498a80c0de32296Douglas Gregor return ObjCEncodingForPrimitiveKind(C, Enum->getIntegerType()); 48185471bc85b69912e3b448de004498a80c0de32296Douglas Gregor} 48195471bc85b69912e3b448de004498a80c0de32296Douglas Gregor 48204ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadstatic void EncodeBitField(const ASTContext *Ctx, std::string& S, 482164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall QualType T, const FieldDecl *FD) { 4822a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith assert(FD->isBitField() && "not a bitfield - getObjCEncodingForTypeImpl"); 48238b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian S += 'b'; 482464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // The NeXT runtime encodes bit fields as b followed by the number of bits. 482564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // The GNU runtime requires more information; bitfields are encoded as b, 482664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // then the offset (in bits) of the first element, then the type of the 482764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // bitfield, then the size in bits. For example, in this structure: 482864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // 482964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // struct 483064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // { 483164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // int integer; 483264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // int flags:2; 483364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // }; 483464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // On a 32-bit system, the encoding for flags would be b2 for the NeXT 483564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // runtime, but b32i2 for the GNU runtime. The reason for this extra 483664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // information is not especially sensible, but we're stuck with it for 483764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // compatibility with GCC, although providing it breaks anything that 483864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // actually uses runtime introspection and wants to work on both runtimes... 4839260611a32535c851237926bfcf78869b13c07d5bJohn McCall if (Ctx->getLangOpts().ObjCRuntime.isGNUFamily()) { 484064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall const RecordDecl *RD = FD->getParent(); 484164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall const ASTRecordLayout &RL = Ctx->getASTRecordLayout(RD); 484282905749d5c8d8b4edec11de754a73349cb96603Eli Friedman S += llvm::utostr(RL.getFieldOffset(FD->getFieldIndex())); 48435471bc85b69912e3b448de004498a80c0de32296Douglas Gregor if (const EnumType *ET = T->getAs<EnumType>()) 48445471bc85b69912e3b448de004498a80c0de32296Douglas Gregor S += ObjCEncodingForEnumType(Ctx, ET); 4845c7ff82c2040f45eaad2eddea0e4461dddc972cd1David Chisnall else 48464ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad S += ObjCEncodingForPrimitiveKind(Ctx, T); 484764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall } 4848a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith S += llvm::utostr(FD->getBitWidthValue(*Ctx)); 48498b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian} 48508b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian 485101eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar// FIXME: Use SmallString for accumulating string. 485282a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbarvoid ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, 485382a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandPointedToStructures, 485482a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandStructures, 4855153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar const FieldDecl *FD, 4856090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian bool OutermostType, 48572636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis bool EncodingProperty, 4858dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool StructField, 4859dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool EncodeBlockParameters, 4860dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool EncodeClassNames) const { 486164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall if (T->getAs<BuiltinType>()) { 4862ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (FD && FD->isBitField()) 486364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall return EncodeBitField(this, S, T, FD); 486464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall S += ObjCEncodingForPrimitiveKind(this, T); 4865ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4866ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 48671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4868183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType *CT = T->getAs<ComplexType>()) { 4869c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson S += 'j'; 48701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(CT->getElementType(), S, false, false, 0, false, 4871c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson false); 4872ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4873ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 487460bce3ef20a4c9684e3825cdd739fefb9810327dFariborz Jahanian 4875aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian // encoding for pointer or r3eference types. 4876aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian QualType PointeeTy; 48776217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = T->getAs<PointerType>()) { 48788d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian if (PT->isObjCSelType()) { 48798d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian S += ':'; 48808d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian return; 48818d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian } 4882aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian PointeeTy = PT->getPointeeType(); 4883aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian } 4884aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 4885aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian PointeeTy = RT->getPointeeType(); 4886aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian if (!PointeeTy.isNull()) { 4887a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian bool isReadOnly = false; 4888a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // For historical/compatibility reasons, the read-only qualifier of the 4889a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // pointee gets emitted _before_ the '^'. The read-only qualifier of 4890a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // the pointer itself gets ignored, _unless_ we are looking at a typedef! 48911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Also, do not emit the 'r' for anything but the outermost type! 48928e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(T.getTypePtr())) { 4893a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (OutermostType && T.isConstQualified()) { 4894a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 4895a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 4896a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 48979fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else if (OutermostType) { 4898a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian QualType P = PointeeTy; 48996217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek while (P->getAs<PointerType>()) 49006217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek P = P->getAs<PointerType>()->getPointeeType(); 4901a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (P.isConstQualified()) { 4902a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 4903a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 4904a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4905a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4906a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (isReadOnly) { 4907a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Another legacy compatibility encoding. Some ObjC qualifier and type 4908a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // combinations need to be rearranged. 4909a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Rewrite "in const" from "nr" to "rn" 49105f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner if (StringRef(S).endswith("nr")) 49110237941e0beb0c929934b66ad29443b484d987feBenjamin Kramer S.replace(S.end()-2, S.end(), "rn"); 4912a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 49131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 491485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson if (PointeeTy->isCharType()) { 491585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // char pointer types should be encoded as '*' unless it is a 491685f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // type that has been typedef'd to 'BOOL'. 4917e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (!isTypeTypedefedAsBOOL(PointeeTy)) { 491885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '*'; 491985f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return; 492085f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 49216217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek } else if (const RecordType *RTy = PointeeTy->getAs<RecordType>()) { 49229533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_class *" to "#". 49239533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_class")) { 49249533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '#'; 49259533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 49269533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 49279533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_object *" to "@". 49289533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_object")) { 49299533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '@'; 49309533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 49319533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 49329533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // fall through... 493385f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 493485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '^'; 4935a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian getLegacyIntegralTypeEncoding(PointeeTy); 4936a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 49371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PointeeTy, S, false, ExpandPointedToStructures, 493843822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian NULL); 4939ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4940ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 4941aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian 4942ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (const ArrayType *AT = 4943ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Ignore type qualifiers etc. 4944ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner dyn_cast<ArrayType>(T->getCanonicalTypeInternal())) { 49452636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (isa<IncompleteArrayType>(AT) && !StructField) { 4946559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson // Incomplete arrays are encoded as a pointer to the array element. 4947559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '^'; 4948559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson 49491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(AT->getElementType(), S, 4950559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 4951559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } else { 4952559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '['; 49531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49542636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) { 49552636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (getTypeSize(CAT->getElementType()) == 0) 49562636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '0'; 49572636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis else 49582636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += llvm::utostr(CAT->getSize().getZExtValue()); 49592636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 4960559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson //Variable length arrays are encoded as a regular array with 0 elements. 49612636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert((isa<VariableArrayType>(AT) || isa<IncompleteArrayType>(AT)) && 49622636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis "Unknown array type!"); 4963559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '0'; 4964559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 49651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(AT->getElementType(), S, 4967559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 4968559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += ']'; 4969559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 4970ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4971ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 49721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4973183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (T->getAs<FunctionType>()) { 4974c0a87b7db06643178ad2cbce0767548c139ea387Anders Carlsson S += '?'; 4975ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4976ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 49771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49786217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RTy = T->getAs<RecordType>()) { 497982a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar RecordDecl *RDecl = RTy->getDecl(); 4980d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? '(' : '{'; 4981502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar // Anonymous structures print as '?' 4982502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar if (const IdentifierInfo *II = RDecl->getIdentifier()) { 4983502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += II->getName(); 49846fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian if (ClassTemplateSpecializationDecl *Spec 49856fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian = dyn_cast<ClassTemplateSpecializationDecl>(RDecl)) { 49866fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); 49876fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian std::string TemplateArgsStr 49886fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian = TemplateSpecializationType::PrintTemplateArgumentList( 4989910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgs.data(), 4990910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgs.size(), 499130c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor (*this).getPrintingPolicy()); 49926fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian 49936fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian S += TemplateArgsStr; 49946fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian } 4995502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } else { 4996502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += '?'; 4997502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } 49980d504c1da852e58ff802545c823ecff3b6c654b8Daniel Dunbar if (ExpandStructures) { 49997d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian S += '='; 50002636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!RDecl->isUnion()) { 50012636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForStructureImpl(RDecl, S, FD); 50022636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 50032636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (RecordDecl::field_iterator Field = RDecl->field_begin(), 50042636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldEnd = RDecl->field_end(); 50052636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis Field != FieldEnd; ++Field) { 50062636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (FD) { 50072636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 50082636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += Field->getNameAsString(); 50092636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 50102636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 50111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50122636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // Special case bit-fields. 50132636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (Field->isBitField()) { 50142636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForTypeImpl(Field->getType(), S, false, true, 5015581deb3da481053c4993c7600f97acf7768caac5David Blaikie *Field); 50162636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 50172636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis QualType qt = Field->getType(); 50182636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getLegacyIntegralTypeEncoding(qt); 50192636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForTypeImpl(qt, S, false, true, 50202636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FD, /*OutermostType*/false, 50212636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*EncodingProperty*/false, 50222636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*StructField*/true); 50232636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 5024d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar } 50257d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian } 50266de88a873a4cbe06d72602eef57d68006730a80bFariborz Jahanian } 5027d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? ')' : '}'; 5028ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 5029ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 5030e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian 50315471bc85b69912e3b448de004498a80c0de32296Douglas Gregor if (const EnumType *ET = T->getAs<EnumType>()) { 50328b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian if (FD && FD->isBitField()) 503364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall EncodeBitField(this, S, T, FD); 50348b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian else 50355471bc85b69912e3b448de004498a80c0de32296Douglas Gregor S += ObjCEncodingForEnumType(this, ET); 5036ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 5037ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 50381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5039dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) { 504021a98b188857d690aa4510c52ac4317ffa0908a8Steve Naroff S += "@?"; // Unlike a pointer-to-function, which is "^?". 5041dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (EncodeBlockParameters) { 5042dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson const FunctionType *FT = BT->getPointeeType()->getAs<FunctionType>(); 5043dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson 5044dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson S += '<'; 5045dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Block return type 5046dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeImpl(FT->getResultType(), S, 5047dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson ExpandPointedToStructures, ExpandStructures, 5048dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson FD, 5049dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* OutermostType */, 5050dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodingProperty, 5051dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* StructField */, 5052dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeBlockParameters, 5053dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeClassNames); 5054dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Block self 5055dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson S += "@?"; 5056dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Block parameters 5057dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) { 5058dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson for (FunctionProtoType::arg_type_iterator I = FPT->arg_type_begin(), 5059dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson E = FPT->arg_type_end(); I && (I != E); ++I) { 5060dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeImpl(*I, S, 5061dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson ExpandPointedToStructures, 5062dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson ExpandStructures, 5063dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson FD, 5064dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* OutermostType */, 5065dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodingProperty, 5066dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* StructField */, 5067dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeBlockParameters, 5068dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeClassNames); 5069dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson } 5070dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson } 5071dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson S += '>'; 5072dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson } 5073ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 5074ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 50751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5076c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Ignore protocol qualifiers when mangling at this level. 5077c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *OT = T->getAs<ObjCObjectType>()) 5078c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T = OT->getBaseType(); 5079c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 50800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ObjCInterfaceType *OIT = T->getAs<ObjCInterfaceType>()) { 508143822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian // @encode(class_name) 50820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ObjCInterfaceDecl *OI = OIT->getDecl(); 508343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '{'; 508443822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian const IdentifierInfo *II = OI->getIdentifier(); 508543822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += II->getName(); 508643822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '='; 5087db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose SmallVector<const ObjCIvarDecl*, 32> Ivars; 50882c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian DeepCollectObjCIvars(OI, true, Ivars); 50892c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian for (unsigned i = 0, e = Ivars.size(); i != e; ++i) { 5090db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose const FieldDecl *Field = cast<FieldDecl>(Ivars[i]); 50912c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian if (Field->isBitField()) 50922c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian getObjCEncodingForTypeImpl(Field->getType(), S, false, true, Field); 509343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian else 50942c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian getObjCEncodingForTypeImpl(Field->getType(), S, false, true, FD); 509543822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 509643822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '}'; 5097ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 509843822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 50991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5100183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = T->getAs<ObjCObjectPointerType>()) { 510114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->isObjCIdType()) { 510214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '@'; 510314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 5104ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 51051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 510627d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType()) { 510727d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff // FIXME: Consider if we need to output qualifiers for 'Class<p>'. 510827d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff // Since this is a binary compatibility issue, need to consult with runtime 510927d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff // folks. Fortunately, this is a *very* obsure construct. 511014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '#'; 511114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 5112ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 51131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5114ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (OPT->isObjCQualifiedIdType()) { 51151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(getObjCIdType(), S, 511614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandPointedToStructures, 511714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandStructures, FD); 5118dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (FD || EncodingProperty || EncodeClassNames) { 511914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Note that we do extended encoding of protocol qualifer list 512014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Only when doing ivar or property encoding. 512114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 512267ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 512367ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 512414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '<'; 512514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += (*I)->getNameAsString(); 512614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '>'; 512714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 512814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 512914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 513014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 5131ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 51321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5133ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner QualType PointeeTy = OPT->getPointeeType(); 5134ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (!EncodingProperty && 5135ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner isa<TypedefType>(PointeeTy.getTypePtr())) { 5136ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Another historical/compatibility reason. 51371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // We encode the underlying type which comes out as 5138ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // {...}; 5139ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '^'; 51401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PointeeTy, S, 51411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump false, ExpandPointedToStructures, 5142ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner NULL); 514314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 514414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 5145ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 5146ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '@'; 5147dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (OPT->getInterfaceDecl() && 5148dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson (FD || EncodingProperty || EncodeClassNames)) { 5149ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 515027d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff S += OPT->getInterfaceDecl()->getIdentifier()->getName(); 515167ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 515267ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 5153ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '<'; 5154ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += (*I)->getNameAsString(); 5155ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '>'; 51561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 5157ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 5158ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 5159ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 5160ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 51611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5162532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall // gcc just blithely ignores member pointers. 5163532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall // TODO: maybe there should be a mangling for these 5164532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall if (T->getAs<MemberPointerType>()) 5165532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall return; 5166e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian 5167e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian if (T->isVectorType()) { 5168e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian // This matches gcc's encoding, even though technically it is 5169e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian // insufficient. 5170e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian // FIXME. We should do a better job than gcc. 5171e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian return; 5172e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian } 5173e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian 5174b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("@encode for type not implemented!"); 517585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 517685f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 51772636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidisvoid ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl, 51782636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::string &S, 51792636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis const FieldDecl *FD, 51802636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis bool includeVBases) const { 51812636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert(RDecl && "Expected non-null RecordDecl"); 51822636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert(!RDecl->isUnion() && "Should not be called for unions"); 51832636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!RDecl->getDefinition()) 51842636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis return; 51852636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51862636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(RDecl); 51872636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::multimap<uint64_t, NamedDecl *> FieldOrBaseOffsets; 51882636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis const ASTRecordLayout &layout = getASTRecordLayout(RDecl); 51892636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51902636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRec) { 51912636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (CXXRecordDecl::base_class_iterator 51922636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BI = CXXRec->bases_begin(), 51932636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BE = CXXRec->bases_end(); BI != BE; ++BI) { 51942636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!BI->isVirtual()) { 51952636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CXXRecordDecl *base = BI->getType()->getAsCXXRecordDecl(); 5196829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis if (base->isEmpty()) 5197829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis continue; 5198d4f5198ae07d9a4958d8191bac694ded12173ad9Benjamin Kramer uint64_t offs = toBits(layout.getBaseClassOffset(base)); 51992636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), 52002636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::make_pair(offs, base)); 52012636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52022636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52032636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52042636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52052636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis unsigned i = 0; 52062636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (RecordDecl::field_iterator Field = RDecl->field_begin(), 52072636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldEnd = RDecl->field_end(); 52082636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis Field != FieldEnd; ++Field, ++i) { 52092636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t offs = layout.getFieldOffset(i); 52102636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), 5211581deb3da481053c4993c7600f97acf7768caac5David Blaikie std::make_pair(offs, *Field)); 52122636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52132636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52142636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRec && includeVBases) { 52152636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (CXXRecordDecl::base_class_iterator 52162636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BI = CXXRec->vbases_begin(), 52172636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BE = CXXRec->vbases_end(); BI != BE; ++BI) { 52182636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CXXRecordDecl *base = BI->getType()->getAsCXXRecordDecl(); 5219829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis if (base->isEmpty()) 5220829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis continue; 5221d4f5198ae07d9a4958d8191bac694ded12173ad9Benjamin Kramer uint64_t offs = toBits(layout.getVBaseClassOffset(base)); 522219aa8609a5d04eed9b81aa1c4608e8a4f3df6ccdArgyrios Kyrtzidis if (FieldOrBaseOffsets.find(offs) == FieldOrBaseOffsets.end()) 522319aa8609a5d04eed9b81aa1c4608e8a4f3df6ccdArgyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.end(), 522419aa8609a5d04eed9b81aa1c4608e8a4f3df6ccdArgyrios Kyrtzidis std::make_pair(offs, base)); 52252636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52262636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52272636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52282636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CharUnits size; 52292636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRec) { 52302636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis size = includeVBases ? layout.getSize() : layout.getNonVirtualSize(); 52312636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 52322636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis size = layout.getSize(); 52332636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52342636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52352636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t CurOffs = 0; 52362636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::multimap<uint64_t, NamedDecl *>::iterator 52372636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurLayObj = FieldOrBaseOffsets.begin(); 52382636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 523958db7a575efc9a2f35266fe240feac3cf317753dDouglas Gregor if (CXXRec && CXXRec->isDynamicClass() && 524058db7a575efc9a2f35266fe240feac3cf317753dDouglas Gregor (CurLayObj == FieldOrBaseOffsets.end() || CurLayObj->first != 0)) { 52412636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (FD) { 52422636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += "\"_vptr$"; 52432636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::string recname = CXXRec->getNameAsString(); 52442636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (recname.empty()) recname = "?"; 52452636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += recname; 52462636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 52472636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52482636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += "^^?"; 52492636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurOffs += getTypeSize(VoidPtrTy); 52502636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52512636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52522636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!RDecl->hasFlexibleArrayMember()) { 52532636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // Mark the end of the structure. 52542636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t offs = toBits(size); 52552636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), 52562636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::make_pair(offs, (NamedDecl*)0)); 52572636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52582636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52592636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (; CurLayObj != FieldOrBaseOffsets.end(); ++CurLayObj) { 52602636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert(CurOffs <= CurLayObj->first); 52612636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52622636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CurOffs < CurLayObj->first) { 52632636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t padding = CurLayObj->first - CurOffs; 52642636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // FIXME: There doesn't seem to be a way to indicate in the encoding that 52652636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // packing/alignment of members is different that normal, in which case 52662636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // the encoding will be out-of-sync with the real layout. 52672636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // If the runtime switches to just consider the size of types without 52682636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // taking into account alignment, we could make padding explicit in the 52692636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // encoding (e.g. using arrays of chars). The encoding strings would be 52702636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // longer then though. 52712636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurOffs += padding; 52722636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52732636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52742636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis NamedDecl *dcl = CurLayObj->second; 52752636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (dcl == 0) 52762636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis break; // reached end of structure. 52772636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52782636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRecordDecl *base = dyn_cast<CXXRecordDecl>(dcl)) { 52792636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // We expand the bases without their virtual bases since those are going 52802636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // in the initial structure. Note that this differs from gcc which 52812636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // expands virtual bases each time one is encountered in the hierarchy, 52822636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // making the encoding type bigger than it really is. 52832636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForStructureImpl(base, S, FD, /*includeVBases*/false); 5284829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis assert(!base->isEmpty()); 5285829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis CurOffs += toBits(getASTRecordLayout(base).getNonVirtualSize()); 52862636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 52872636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldDecl *field = cast<FieldDecl>(dcl); 52882636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (FD) { 52892636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 52902636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += field->getNameAsString(); 52912636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 52922636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52932636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52942636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (field->isBitField()) { 52952636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis EncodeBitField(this, S, field->getType(), field); 5296a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith CurOffs += field->getBitWidthValue(*this); 52972636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 52982636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis QualType qt = field->getType(); 52992636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getLegacyIntegralTypeEncoding(qt); 53002636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForTypeImpl(qt, S, false, true, FD, 53012636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*OutermostType*/false, 53022636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*EncodingProperty*/false, 53032636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*StructField*/true); 53042636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurOffs += getTypeSize(field->getType()); 53052636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 53062636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 53072636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 53082636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis} 53092636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 53101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid ASTContext::getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 5311ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian std::string& S) const { 5312ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_In) 5313ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'n'; 5314ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Inout) 5315ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'N'; 5316ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Out) 5317ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'o'; 5318ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Bycopy) 5319ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'O'; 5320ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Byref) 5321ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'R'; 5322ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Oneway) 5323ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'V'; 5324ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian} 5325ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian 53264dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas GregorTypedefDecl *ASTContext::getObjCIdDecl() const { 53274dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor if (!ObjCIdDecl) { 53284dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor QualType T = getObjCObjectType(ObjCBuiltinIdTy, 0, 0); 53294dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor T = getObjCObjectPointerType(T); 53304dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor TypeSourceInfo *IdInfo = getTrivialTypeSourceInfo(T); 53314dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor ObjCIdDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 53324dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor getTranslationUnitDecl(), 53334dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor SourceLocation(), SourceLocation(), 53344dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor &Idents.get("id"), IdInfo); 53354dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor } 53364dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor 53374dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor return ObjCIdDecl; 53387e219e47de26346885d667131977bd9ca2d7662aSteve Naroff} 53397e219e47de26346885d667131977bd9ca2d7662aSteve Naroff 53407a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas GregorTypedefDecl *ASTContext::getObjCSelDecl() const { 53417a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor if (!ObjCSelDecl) { 53427a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor QualType SelT = getPointerType(ObjCBuiltinSelTy); 53437a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor TypeSourceInfo *SelInfo = getTrivialTypeSourceInfo(SelT); 53447a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor ObjCSelDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 53457a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor getTranslationUnitDecl(), 53467a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor SourceLocation(), SourceLocation(), 53477a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor &Idents.get("SEL"), SelInfo); 53487a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor } 53497a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor return ObjCSelDecl; 5350b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian} 5351b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 535279d6726921897811232554ed94c5d77b5b7b3fc0Douglas GregorTypedefDecl *ASTContext::getObjCClassDecl() const { 535379d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor if (!ObjCClassDecl) { 535479d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor QualType T = getObjCObjectType(ObjCBuiltinClassTy, 0, 0); 535579d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor T = getObjCObjectPointerType(T); 535679d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor TypeSourceInfo *ClassInfo = getTrivialTypeSourceInfo(T); 535779d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor ObjCClassDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 535879d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor getTranslationUnitDecl(), 535979d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor SourceLocation(), SourceLocation(), 536079d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor &Idents.get("Class"), ClassInfo); 536179d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor } 536279d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor 536379d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor return ObjCClassDecl; 5364a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor} 5365a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor 5366a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas GregorObjCInterfaceDecl *ASTContext::getObjCProtocolDecl() const { 5367a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor if (!ObjCProtocolClassDecl) { 5368a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor ObjCProtocolClassDecl 5369a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor = ObjCInterfaceDecl::Create(*this, getTranslationUnitDecl(), 5370a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor SourceLocation(), 5371a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor &Idents.get("Protocol"), 5372a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor /*PrevDecl=*/0, 5373a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor SourceLocation(), true); 5374a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor } 5375a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor 5376a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor return ObjCProtocolClassDecl; 53778baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson} 53788baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson 5379c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge//===----------------------------------------------------------------------===// 5380c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge// __builtin_va_list Construction Functions 5381c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge//===----------------------------------------------------------------------===// 5382c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5383c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreateCharPtrBuiltinVaListDecl(const ASTContext *Context) { 5384c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef char* __builtin_va_list; 5385c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType CharPtrType = Context->getPointerType(Context->CharTy); 5386c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5387c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(CharPtrType); 5388c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5389c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypeDecl 5390c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5391c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5392c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5393c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5394c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5395c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypeDecl; 5396c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5397c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5398c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) { 5399c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef void* __builtin_va_list; 5400c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VoidPtrType = Context->getPointerType(Context->VoidTy); 5401c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5402c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(VoidPtrType); 5403c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5404c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypeDecl 5405c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5406c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5407c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5408c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5409c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5410c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypeDecl; 5411c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5412c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5413c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) { 5414c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef struct __va_list_tag { 5415c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge RecordDecl *VaListTagDecl; 5416c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5417c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct, 5418c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5419c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag")); 5420c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->startDefinition(); 5421c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5422c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const size_t NumFields = 5; 5423c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType FieldTypes[NumFields]; 5424c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const char *FieldNames[NumFields]; 5425c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5426c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned char gpr; 5427c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[0] = Context->UnsignedCharTy; 5428c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[0] = "gpr"; 5429c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5430c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned char fpr; 5431c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[1] = Context->UnsignedCharTy; 5432c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[1] = "fpr"; 5433c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5434c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned short reserved; 5435c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[2] = Context->UnsignedShortTy; 5436c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[2] = "reserved"; 5437c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5438c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* overflow_arg_area; 5439c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[3] = Context->getPointerType(Context->VoidTy); 5440c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[3] = "overflow_arg_area"; 5441c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5442c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* reg_save_area; 5443c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[4] = Context->getPointerType(Context->VoidTy); 5444c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[4] = "reg_save_area"; 5445c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5446c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // Create fields 5447c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge for (unsigned i = 0; i < NumFields; ++i) { 5448c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldDecl *Field = FieldDecl::Create(*Context, VaListTagDecl, 5449c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5450c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5451c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get(FieldNames[i]), 5452c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[i], /*TInfo=*/0, 5453c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*BitWidth=*/0, 5454c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*Mutable=*/false, 5455c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge ICIS_NoInit); 5456c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Field->setAccess(AS_public); 5457c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->addDecl(Field); 5458c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge } 5459c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->completeDefinition(); 5460c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagType = Context->getRecordType(VaListTagDecl); 5461fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge Context->VaListTagTy = VaListTagType; 5462c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5463c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // } __va_list_tag; 5464c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTagTypedefDecl 5465c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5466c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5467c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5468c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag"), 5469c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTrivialTypeSourceInfo(VaListTagType)); 5470c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagTypedefType = 5471c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTypedefType(VaListTagTypedefDecl); 5472c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5473c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef __va_list_tag __builtin_va_list[1]; 5474c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); 5475c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagArrayType 5476c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getConstantArrayType(VaListTagTypedefType, 5477c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Size, ArrayType::Normal, 0); 5478c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5479c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(VaListTagArrayType); 5480c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypedefDecl 5481c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5482c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5483c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5484c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5485c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5486c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5487c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypedefDecl; 5488c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5489c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5490c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl * 5491c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador IngeCreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) { 5492c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef struct __va_list_tag { 5493c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge RecordDecl *VaListTagDecl; 5494c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct, 5495c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5496c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag")); 5497c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->startDefinition(); 5498c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5499c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const size_t NumFields = 4; 5500c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType FieldTypes[NumFields]; 5501c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const char *FieldNames[NumFields]; 5502c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5503c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned gp_offset; 5504c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[0] = Context->UnsignedIntTy; 5505c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[0] = "gp_offset"; 5506c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5507c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned fp_offset; 5508c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[1] = Context->UnsignedIntTy; 5509c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[1] = "fp_offset"; 5510c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5511c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* overflow_arg_area; 5512c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[2] = Context->getPointerType(Context->VoidTy); 5513c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[2] = "overflow_arg_area"; 5514c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5515c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* reg_save_area; 5516c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[3] = Context->getPointerType(Context->VoidTy); 5517c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[3] = "reg_save_area"; 5518c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5519c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // Create fields 5520c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge for (unsigned i = 0; i < NumFields; ++i) { 5521c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context), 5522c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl, 5523c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5524c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5525c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get(FieldNames[i]), 5526c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[i], /*TInfo=*/0, 5527c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*BitWidth=*/0, 5528c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*Mutable=*/false, 5529c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge ICIS_NoInit); 5530c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Field->setAccess(AS_public); 5531c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->addDecl(Field); 5532c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge } 5533c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->completeDefinition(); 5534c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagType = Context->getRecordType(VaListTagDecl); 5535fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge Context->VaListTagTy = VaListTagType; 5536c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5537c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // } __va_list_tag; 5538c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTagTypedefDecl 5539c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5540c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5541c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5542c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag"), 5543c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTrivialTypeSourceInfo(VaListTagType)); 5544c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagTypedefType = 5545c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTypedefType(VaListTagTypedefDecl); 5546c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5547c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef __va_list_tag __builtin_va_list[1]; 5548c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); 5549c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagArrayType 5550c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getConstantArrayType(VaListTagTypedefType, 5551c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Size, ArrayType::Normal,0); 5552c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5553c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(VaListTagArrayType); 5554c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypedefDecl 5555c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5556c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5557c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5558c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5559c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5560c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5561c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypedefDecl; 5562c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5563c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5564c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreatePNaClABIBuiltinVaListDecl(const ASTContext *Context) { 5565c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef int __builtin_va_list[4]; 5566c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 4); 5567c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType IntArrayType 5568c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getConstantArrayType(Context->IntTy, 5569c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Size, ArrayType::Normal, 0); 5570c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypedefDecl 5571c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5572c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5573c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5574c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5575c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTrivialTypeSourceInfo(IntArrayType)); 5576c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5577c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypedefDecl; 5578c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5579c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5580eae5a820bced67465c8517793a1602dfaeed8a06Logan Chienstatic TypedefDecl * 5581eae5a820bced67465c8517793a1602dfaeed8a06Logan ChienCreateAAPCSABIBuiltinVaListDecl(const ASTContext *Context) { 5582eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien RecordDecl *VaListDecl; 5583eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien if (Context->getLangOpts().CPlusPlus) { 5584eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien // namespace std { struct __va_list { 5585eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien NamespaceDecl *NS; 5586eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien NS = NamespaceDecl::Create(const_cast<ASTContext &>(*Context), 5587eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien Context->getTranslationUnitDecl(), 5588eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien /*Inline*/false, SourceLocation(), 5589eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien SourceLocation(), &Context->Idents.get("std"), 5590eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien /*PrevDecl*/0); 5591eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5592eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien VaListDecl = CXXRecordDecl::Create(*Context, TTK_Struct, 5593eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien Context->getTranslationUnitDecl(), 5594eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien SourceLocation(), SourceLocation(), 5595eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien &Context->Idents.get("__va_list")); 5596eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5597eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien VaListDecl->setDeclContext(NS); 5598eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5599eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien } else { 5600eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien // struct __va_list { 5601eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien VaListDecl = CreateRecordDecl(*Context, TTK_Struct, 5602eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien Context->getTranslationUnitDecl(), 5603eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien &Context->Idents.get("__va_list")); 5604eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien } 5605eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5606eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien VaListDecl->startDefinition(); 5607eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5608eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien // void * __ap; 5609eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context), 5610eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien VaListDecl, 5611eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien SourceLocation(), 5612eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien SourceLocation(), 5613eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien &Context->Idents.get("__ap"), 5614eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien Context->getPointerType(Context->VoidTy), 5615eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien /*TInfo=*/0, 5616eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien /*BitWidth=*/0, 5617eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien /*Mutable=*/false, 5618eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien ICIS_NoInit); 5619eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien Field->setAccess(AS_public); 5620eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien VaListDecl->addDecl(Field); 5621eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5622eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien // }; 5623eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien VaListDecl->completeDefinition(); 5624eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5625eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien // typedef struct __va_list __builtin_va_list; 5626eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien TypeSourceInfo *TInfo 5627eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien = Context->getTrivialTypeSourceInfo(Context->getRecordType(VaListDecl)); 5628eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5629eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien TypedefDecl *VaListTypeDecl 5630eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5631eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien Context->getTranslationUnitDecl(), 5632eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien SourceLocation(), SourceLocation(), 5633eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien &Context->Idents.get("__builtin_va_list"), 5634eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien TInfo); 5635eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5636eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien return VaListTypeDecl; 5637eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien} 5638eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien 5639c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreateVaListDecl(const ASTContext *Context, 5640c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TargetInfo::BuiltinVaListKind Kind) { 5641c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge switch (Kind) { 5642c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::CharPtrBuiltinVaList: 5643c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreateCharPtrBuiltinVaListDecl(Context); 5644c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::VoidPtrBuiltinVaList: 5645c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreateVoidPtrBuiltinVaListDecl(Context); 5646c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::PowerABIBuiltinVaList: 5647c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreatePowerABIBuiltinVaListDecl(Context); 5648c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::X86_64ABIBuiltinVaList: 5649c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreateX86_64ABIBuiltinVaListDecl(Context); 5650c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::PNaClABIBuiltinVaList: 5651c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreatePNaClABIBuiltinVaListDecl(Context); 5652eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien case TargetInfo::AAPCSABIBuiltinVaList: 5653eae5a820bced67465c8517793a1602dfaeed8a06Logan Chien return CreateAAPCSABIBuiltinVaListDecl(Context); 5654c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge } 5655c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5656c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm_unreachable("Unhandled __builtin_va_list type kind"); 5657c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5658c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5659c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador IngeTypedefDecl *ASTContext::getBuiltinVaListDecl() const { 5660c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge if (!BuiltinVaListDecl) 5661c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge BuiltinVaListDecl = CreateVaListDecl(this, Target->getBuiltinVaListKind()); 5662c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5663c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return BuiltinVaListDecl; 5664c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5665c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5666fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador IngeQualType ASTContext::getVaListTagType() const { 5667fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge // Force the creation of VaListTagTy by building the __builtin_va_list 5668fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge // declaration. 5669fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge if (VaListTagTy.isNull()) 5670fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge (void) getBuiltinVaListDecl(); 5671fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge 5672fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge return VaListTagTy; 5673fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge} 5674fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge 5675a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) { 56761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(ObjCConstantStringType.isNull() && 56772198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff "'NSConstantString' type already set!"); 56781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5679a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = getObjCInterfaceType(Decl); 56802198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff} 56812198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff 56820bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall/// \brief Retrieve the template name that corresponds to a non-empty 56830bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall/// lookup. 56844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName 56854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getOverloadedTemplateName(UnresolvedSetIterator Begin, 56864ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad UnresolvedSetIterator End) const { 56870bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall unsigned size = End - Begin; 56880bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall assert(size > 1 && "set is not overloaded!"); 56897532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 56900bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall void *memory = Allocate(sizeof(OverloadedTemplateStorage) + 56910bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall size * sizeof(FunctionTemplateDecl*)); 56920bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall OverloadedTemplateStorage *OT = new(memory) OverloadedTemplateStorage(size); 56930bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall 56940bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall NamedDecl **Storage = OT->getStorage(); 5695eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall for (UnresolvedSetIterator I = Begin; I != End; ++I) { 56960bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall NamedDecl *D = *I; 56970bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall assert(isa<FunctionTemplateDecl>(D) || 56980bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall (isa<UsingShadowDecl>(D) && 56990bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall isa<FunctionTemplateDecl>(D->getUnderlyingDecl()))); 57000bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall *Storage++ = D; 57017532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 57027532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 57030bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall return TemplateName(OT); 57047532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 57057532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 5706d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// \brief Retrieve the template name that represents a qualified 5707d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// template name such as \c std::vector. 57084ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName 57094ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, 57104ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool TemplateKeyword, 57114ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad TemplateDecl *Template) const { 57120f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor assert(NNS && "Missing nested-name-specifier in qualified template name"); 57130f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor 5714789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor // FIXME: Canonicalization? 5715d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor llvm::FoldingSetNodeID ID; 5716d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName::Profile(ID, NNS, TemplateKeyword, Template); 57171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5718d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor void *InsertPos = 0; 5719d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName *QTN = 57200bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall QualifiedTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5721d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor if (!QTN) { 57222f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<QualifiedTemplateName>()) 57232f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QualifiedTemplateName(NNS, TemplateKeyword, Template); 5724d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateNames.InsertNode(QTN, InsertPos); 5725d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor } 57261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5727d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor return TemplateName(QTN); 5728d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor} 5729d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor 57307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Retrieve the template name that represents a dependent 57317532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template name such as \c MetaFun::template apply. 57324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName 57334ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, 57344ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const IdentifierInfo *Name) const { 57351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!NNS || NNS->isDependent()) && 57363b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor "Nested name specifier must be dependent"); 57377532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 57387532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor llvm::FoldingSetNodeID ID; 57397532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName::Profile(ID, NNS, Name); 57407532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 57417532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor void *InsertPos = 0; 57427532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName *QTN = 57437532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 57447532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 57457532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (QTN) 57467532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 57477532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 57487532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 57497532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (CanonNNS == NNS) { 57502f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<DependentTemplateName>()) 57512f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith DependentTemplateName(NNS, Name); 57527532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } else { 57537532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Canon = getDependentTemplateName(CanonNNS, Name); 57542f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<DependentTemplateName>()) 57552f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith DependentTemplateName(NNS, Name, Canon); 5756789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateName *CheckQTN = 5757789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5758789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!CheckQTN && "Dependent type name canonicalization broken"); 5759789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CheckQTN; 57607532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 57617532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 57627532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.InsertNode(QTN, InsertPos); 57637532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 57647532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 57657532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 5766ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \brief Retrieve the template name that represents a dependent 5767ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// template name such as \c MetaFun::template operator+. 5768ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 5769ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, 57704ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad OverloadedOperatorKind Operator) const { 5771ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor assert((!NNS || NNS->isDependent()) && 5772ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor "Nested name specifier must be dependent"); 5773ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5774ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor llvm::FoldingSetNodeID ID; 5775ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor DependentTemplateName::Profile(ID, NNS, Operator); 5776ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5777ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor void *InsertPos = 0; 5778789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateName *QTN 5779789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5780ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5781ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (QTN) 5782ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return TemplateName(QTN); 5783ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5784ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 5785ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (CanonNNS == NNS) { 57862f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<DependentTemplateName>()) 57872f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith DependentTemplateName(NNS, Operator); 5788ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } else { 5789ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor TemplateName Canon = getDependentTemplateName(CanonNNS, Operator); 57902f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<DependentTemplateName>()) 57912f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith DependentTemplateName(NNS, Operator, Canon); 5792789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 5793789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateName *CheckQTN 5794789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5795789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!CheckQTN && "Dependent template name canonicalization broken"); 5796789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CheckQTN; 5797ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 5798ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5799ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor DependentTemplateNames.InsertNode(QTN, InsertPos); 5800ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return TemplateName(QTN); 5801ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 5802ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 58031aee05d08b2184acadeb36de300e216390780d6cDouglas GregorTemplateName 5804146060435c3efce95c95a092c7a1eb651cfb9ae0John McCallASTContext::getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, 5805146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateName replacement) const { 5806146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm::FoldingSetNodeID ID; 5807146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage::Profile(ID, param, replacement); 5808146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5809146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall void *insertPos = 0; 5810146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 5811146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = SubstTemplateTemplateParms.FindNodeOrInsertPos(ID, insertPos); 5812146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5813146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall if (!subst) { 5814146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall subst = new (*this) SubstTemplateTemplateParmStorage(param, replacement); 5815146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParms.InsertNode(subst, insertPos); 5816146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 5817146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5818146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return TemplateName(subst); 5819146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall} 5820146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5821146060435c3efce95c95a092c7a1eb651cfb9ae0John McCallTemplateName 58221aee05d08b2184acadeb36de300e216390780d6cDouglas GregorASTContext::getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, 58231aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor const TemplateArgument &ArgPack) const { 58241aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor ASTContext &Self = const_cast<ASTContext &>(*this); 58251aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor llvm::FoldingSetNodeID ID; 58261aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPackStorage::Profile(ID, Self, Param, ArgPack); 58271aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 58281aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor void *InsertPos = 0; 58291aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPackStorage *Subst 58301aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor = SubstTemplateTemplateParmPacks.FindNodeOrInsertPos(ID, InsertPos); 58311aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 58321aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor if (!Subst) { 5833146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall Subst = new (*this) SubstTemplateTemplateParmPackStorage(Param, 58341aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor ArgPack.pack_size(), 58351aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor ArgPack.pack_begin()); 58361aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPacks.InsertNode(Subst, InsertPos); 58371aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 58381aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 58391aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return TemplateName(Subst); 58401aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor} 58411aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 5842b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor/// getFromTargetType - Given one of the integer types provided by 5843d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// TargetInfo, produce the corresponding type. The unsigned @p Type 5844d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// is actually a value of type @c TargetInfo::IntType. 5845e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCallCanQualType ASTContext::getFromTargetType(unsigned Type) const { 5846b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor switch (Type) { 5847e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCall case TargetInfo::NoInt: return CanQualType(); 5848b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedShort: return ShortTy; 5849b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedShort: return UnsignedShortTy; 5850b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedInt: return IntTy; 5851b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedInt: return UnsignedIntTy; 5852b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLong: return LongTy; 5853b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLong: return UnsignedLongTy; 5854b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLongLong: return LongLongTy; 5855b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLongLong: return UnsignedLongLongTy; 5856b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor } 5857b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor 5858b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unhandled TargetInfo::IntType value"); 5859b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor} 5860b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 5861b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 5862b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek// Type Predicates. 5863b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 5864b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 58654fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's 58664fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// garbage collection attribute. 58674fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// 5868ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCallQualifiers::GC ASTContext::getObjCGCAttrKind(QualType Ty) const { 58694e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().getGC() == LangOptions::NonGC) 5870ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall return Qualifiers::GCNone; 5871ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall 58724e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie assert(getLangOpts().ObjC1); 5873ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall Qualifiers::GC GCAttrs = Ty.getObjCGCAttr(); 5874ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall 5875ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // Default behaviour under objective-C's gc is for ObjC pointers 5876ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // (or pointers to them) be treated as though they were declared 5877ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // as __strong. 5878ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall if (GCAttrs == Qualifiers::GCNone) { 5879ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall if (Ty->isObjCObjectPointerType() || Ty->isBlockPointerType()) 5880ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall return Qualifiers::Strong; 5881ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall else if (Ty->isPointerType()) 5882ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall return getObjCGCAttrKind(Ty->getAs<PointerType>()->getPointeeType()); 5883ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall } else { 5884ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // It's not valid to set GC attributes on anything that isn't a 5885ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // pointer. 5886ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall#ifndef NDEBUG 5887ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall QualType CT = Ty->getCanonicalTypeInternal(); 5888ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall while (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 5889ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall CT = AT->getElementType(); 5890ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall assert(CT->isAnyPointerType() || CT->isBlockPointerType()); 5891ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall#endif 58924fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian } 5893b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner return GCAttrs; 58944fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian} 58954fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian 58966ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 58976ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner// Type Compatibility Testing 58986ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 5899770951b5bb6028a8d326ddb4a13cef7d4a128162Chris Lattner 59001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// areCompatVectorTypes - Return true if the two specified vector types are 59016ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner/// compatible. 59026ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattnerstatic bool areCompatVectorTypes(const VectorType *LHS, 59036ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner const VectorType *RHS) { 5904467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall assert(LHS->isCanonicalUnqualified() && RHS->isCanonicalUnqualified()); 59056ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return LHS->getElementType() == RHS->getElementType() && 590661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner LHS->getNumElements() == RHS->getNumElements(); 59076ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 59086ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 5909255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregorbool ASTContext::areCompatibleVectorTypes(QualType FirstVec, 5910255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor QualType SecondVec) { 5911255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor assert(FirstVec->isVectorType() && "FirstVec should be a vector type"); 5912255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor assert(SecondVec->isVectorType() && "SecondVec should be a vector type"); 5913255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 5914255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor if (hasSameUnqualifiedType(FirstVec, SecondVec)) 5915255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor return true; 5916255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 5917f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson // Treat Neon vector types and most AltiVec vector types as if they are the 5918f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson // equivalent GCC vector types. 5919255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor const VectorType *First = FirstVec->getAs<VectorType>(); 5920255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor const VectorType *Second = SecondVec->getAs<VectorType>(); 5921f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson if (First->getNumElements() == Second->getNumElements() && 5922255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor hasSameType(First->getElementType(), Second->getElementType()) && 5923f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson First->getVectorKind() != VectorType::AltiVecPixel && 5924f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson First->getVectorKind() != VectorType::AltiVecBool && 5925f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson Second->getVectorKind() != VectorType::AltiVecPixel && 5926f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson Second->getVectorKind() != VectorType::AltiVecBool) 5927255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor return true; 5928255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 5929255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor return false; 5930255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor} 5931255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 59324084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 59334084c306635b70f37029dca938444e6013f08684Steve Naroff// ObjCQualifiedIdTypesAreCompatible - Compatibility testing for qualified id's. 59344084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 59354084c306635b70f37029dca938444e6013f08684Steve Naroff 59364084c306635b70f37029dca938444e6013f08684Steve Naroff/// ProtocolCompatibleWithProtocol - return 'true' if 'lProto' is in the 59374084c306635b70f37029dca938444e6013f08684Steve Naroff/// inheritance hierarchy of 'rProto'. 59384ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool 59394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 59404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad ObjCProtocolDecl *rProto) const { 59413fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor if (declaresSameEntity(lProto, rProto)) 594214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return true; 59434084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCProtocolDecl::protocol_iterator PI = rProto->protocol_begin(), 59444084c306635b70f37029dca938444e6013f08684Steve Naroff E = rProto->protocol_end(); PI != E; ++PI) 59454084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lProto, *PI)) 59464084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 59474084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 59484084c306635b70f37029dca938444e6013f08684Steve Naroff} 594914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 59504c3b8a3ed28c52dc56d3a1b9670d71e5f7070c62Dmitri Gribenko/// QualifiedIdConformsQualifiedId - compare id<pr,...> with id<pr1,...> 59514084c306635b70f37029dca938444e6013f08684Steve Naroff/// return true if lhs's protocols conform to rhs's protocol; false 59524084c306635b70f37029dca938444e6013f08684Steve Naroff/// otherwise. 59534084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::QualifiedIdConformsQualifiedId(QualType lhs, QualType rhs) { 59544084c306635b70f37029dca938444e6013f08684Steve Naroff if (lhs->isObjCQualifiedIdType() && rhs->isObjCQualifiedIdType()) 59554084c306635b70f37029dca938444e6013f08684Steve Naroff return ObjCQualifiedIdTypesAreCompatible(lhs, rhs, false); 59564084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 59574084c306635b70f37029dca938444e6013f08684Steve Naroff} 59584084c306635b70f37029dca938444e6013f08684Steve Naroff 59594c3b8a3ed28c52dc56d3a1b9670d71e5f7070c62Dmitri Gribenko/// ObjCQualifiedClassTypesAreCompatible - compare Class<pr,...> and 59604c3b8a3ed28c52dc56d3a1b9670d71e5f7070c62Dmitri Gribenko/// Class<pr1, ...>. 5961a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanianbool ASTContext::ObjCQualifiedClassTypesAreCompatible(QualType lhs, 5962a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian QualType rhs) { 5963a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian const ObjCObjectPointerType *lhsQID = lhs->getAs<ObjCObjectPointerType>(); 5964a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian const ObjCObjectPointerType *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); 5965a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian assert ((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible"); 5966a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 5967a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 5968a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian E = lhsQID->qual_end(); I != E; ++I) { 5969a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian bool match = false; 5970a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian ObjCProtocolDecl *lhsProto = *I; 5971a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), 5972a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian E = rhsOPT->qual_end(); J != E; ++J) { 5973a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian ObjCProtocolDecl *rhsProto = *J; 5974a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto)) { 5975a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian match = true; 5976a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian break; 5977a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian } 5978a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian } 5979a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian if (!match) 5980a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian return false; 5981a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian } 5982a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian return true; 5983a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian} 5984a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 59854084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an 59864084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIDType. 59874084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, 59884084c306635b70f37029dca938444e6013f08684Steve Naroff bool compare) { 59894084c306635b70f37029dca938444e6013f08684Steve Naroff // Allow id<P..> and an 'id' or void* type in all cases. 59901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (lhs->isVoidPointerType() || 59914084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->isObjCIdType() || lhs->isObjCClassType()) 59924084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 59931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump else if (rhs->isVoidPointerType() || 59944084c306635b70f37029dca938444e6013f08684Steve Naroff rhs->isObjCIdType() || rhs->isObjCClassType()) 59954084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 59964084c306635b70f37029dca938444e6013f08684Steve Naroff 59974084c306635b70f37029dca938444e6013f08684Steve Naroff if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) { 5998183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); 59991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60004084c306635b70f37029dca938444e6013f08684Steve Naroff if (!rhsOPT) return false; 60011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60024084c306635b70f37029dca938444e6013f08684Steve Naroff if (rhsOPT->qual_empty()) { 60031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the RHS is a unqualified interface pointer "NSString*", 60044084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 60054084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 60064084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 60074084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 60084084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 60094084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 60104084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 60110fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (!rhsID->ClassImplementsProtocol(*I, true)) 60124084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 60134084c306635b70f37029dca938444e6013f08684Steve Naroff } 60144084c306635b70f37029dca938444e6013f08684Steve Naroff } 60154084c306635b70f37029dca938444e6013f08684Steve Naroff // If there are no qualifiers and no interface, we have an 'id'. 60164084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 60174084c306635b70f37029dca938444e6013f08684Steve Naroff } 60181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Both the right and left sides have qualifiers. 60194084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 60204084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 60214084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 60224084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 6023de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff 6024de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // when comparing an id<P> on lhs with a static type on rhs, 6025de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // see if static class implements all of id's protocols, directly or 6026de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // through its super class and categories. 60274084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), 60284084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsOPT->qual_end(); J != E; ++J) { 60294084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 60304084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 60314084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 60324084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 60338f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 60348f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 6035de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 60361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the RHS is a qualified interface pointer "NSString<P>*", 60374084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 60384084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 60394084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 60404084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 60414084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 60424084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 60434084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 60440fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (rhsID->ClassImplementsProtocol(*I, true)) { 60454084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 60464084c306635b70f37029dca938444e6013f08684Steve Naroff break; 60474084c306635b70f37029dca938444e6013f08684Steve Naroff } 60484084c306635b70f37029dca938444e6013f08684Steve Naroff } 60494084c306635b70f37029dca938444e6013f08684Steve Naroff } 60504084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 6051de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return false; 6052de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 60531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6054de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return true; 6055de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 60561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60574084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *rhsQID = rhs->getAsObjCQualifiedIdType(); 60584084c306635b70f37029dca938444e6013f08684Steve Naroff assert(rhsQID && "One of the LHS/RHS should be id<x>"); 60594084c306635b70f37029dca938444e6013f08684Steve Naroff 60601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const ObjCObjectPointerType *lhsOPT = 60614084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->getAsObjCInterfacePointerType()) { 6062de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // If both the right and left sides have qualifiers. 60634084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsOPT->qual_begin(), 60644084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsOPT->qual_end(); I != E; ++I) { 60654084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 60664084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 60674084c306635b70f37029dca938444e6013f08684Steve Naroff 6068de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // when comparing an id<P> on rhs with a static type on lhs, 60694084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 60704084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 6071de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // First, lhs protocols in the qualifier list must be found, direct 6072de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // or indirect in rhs's qualifier list or it is a mismatch. 60734084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), 60744084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsQID->qual_end(); J != E; ++J) { 60754084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 60764084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 60774084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 60784084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 60794084c306635b70f37029dca938444e6013f08684Steve Naroff break; 60804084c306635b70f37029dca938444e6013f08684Steve Naroff } 60814084c306635b70f37029dca938444e6013f08684Steve Naroff } 60824084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 60834084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 60844084c306635b70f37029dca938444e6013f08684Steve Naroff } 6085de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian 6086de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // Static class's protocols, or its super class or category protocols 6087de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // must be found, direct or indirect in rhs's qualifier list or it is a mismatch. 6088de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (ObjCInterfaceDecl *lhsID = lhsOPT->getInterfaceDecl()) { 6089de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> LHSInheritedProtocols; 6090de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian CollectInheritedProtocols(lhsID, LHSInheritedProtocols); 6091de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // This is rather dubious but matches gcc's behavior. If lhs has 6092de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // no type qualifier and its class has no static protocol(s) 6093de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // assume that it is mismatch. 6094de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (LHSInheritedProtocols.empty() && lhsOPT->qual_empty()) 6095de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian return false; 6096de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 6097de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian LHSInheritedProtocols.begin(), 6098de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian E = LHSInheritedProtocols.end(); I != E; ++I) { 6099de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian bool match = false; 6100de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian ObjCProtocolDecl *lhsProto = (*I); 6101de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), 6102de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian E = rhsQID->qual_end(); J != E; ++J) { 6103de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian ObjCProtocolDecl *rhsProto = *J; 6104de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 6105de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 6106de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian match = true; 6107de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian break; 6108de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 6109de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 6110de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (!match) 6111de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian return false; 6112de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 6113de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 61144084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 61154084c306635b70f37029dca938444e6013f08684Steve Naroff } 61164084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 61174084c306635b70f37029dca938444e6013f08684Steve Naroff} 61184084c306635b70f37029dca938444e6013f08684Steve Naroff 61194084c306635b70f37029dca938444e6013f08684Steve Naroff/// canAssignObjCInterfaces - Return true if the two interface types are 61204084c306635b70f37029dca938444e6013f08684Steve Naroff/// compatible for assignment from RHS to LHS. This handles validation of any 61214084c306635b70f37029dca938444e6013f08684Steve Naroff/// protocol qualifiers on the LHS or RHS. 61224084c306635b70f37029dca938444e6013f08684Steve Naroff/// 61234084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 61244084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *RHSOPT) { 6125c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* LHS = LHSOPT->getObjectType(); 6126c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* RHS = RHSOPT->getObjectType(); 6127c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 61284084c306635b70f37029dca938444e6013f08684Steve Naroff // If either type represents the built-in 'id' or 'Class' types, return true. 6129c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHS->isObjCUnqualifiedIdOrClass() || 6130c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall RHS->isObjCUnqualifiedIdOrClass()) 61314084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 61324084c306635b70f37029dca938444e6013f08684Steve Naroff 6133c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHS->isObjCQualifiedId() || RHS->isObjCQualifiedId()) 61341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), 61351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType(RHSOPT,0), 61364084c306635b70f37029dca938444e6013f08684Steve Naroff false); 6137a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 6138a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian if (LHS->isObjCQualifiedClass() && RHS->isObjCQualifiedClass()) 6139a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian return ObjCQualifiedClassTypesAreCompatible(QualType(LHSOPT,0), 6140a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian QualType(RHSOPT,0)); 6141a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 6142c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If we have 2 user-defined types, fall into that path. 6143c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHS->getInterface() && RHS->getInterface()) 61444084c306635b70f37029dca938444e6013f08684Steve Naroff return canAssignObjCInterfaces(LHS, RHS); 61451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61464084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 614714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 614814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 6149132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// canAssignObjCInterfacesInBlockPointer - This routine is specifically written 6150fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// for providing type-safety for objective-c pointers used to pass/return 6151132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// arguments in block literals. When passed as arguments, passing 'A*' where 6152132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// 'id' is expected is not OK. Passing 'Sub *" where 'Super *" is expected is 6153132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// not OK. For the return type, the opposite is not OK. 6154132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanianbool ASTContext::canAssignObjCInterfacesInBlockPointer( 6155132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian const ObjCObjectPointerType *LHSOPT, 6156a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian const ObjCObjectPointerType *RHSOPT, 6157a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian bool BlockReturnType) { 6158a98344869c278295f38e106583906377520079b8Fariborz Jahanian if (RHSOPT->isObjCBuiltinType() || LHSOPT->isObjCIdType()) 6159132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return true; 6160132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 6161132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHSOPT->isObjCBuiltinType()) { 6162132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return RHSOPT->isObjCBuiltinType() || RHSOPT->isObjCQualifiedIdType(); 6163132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 6164132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 6165a98344869c278295f38e106583906377520079b8Fariborz Jahanian if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) 6166132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), 6167132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian QualType(RHSOPT,0), 6168132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian false); 6169132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 6170132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType(); 6171132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType(); 6172132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHS && RHS) { // We have 2 user-defined types. 6173132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHS != RHS) { 6174132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHS->getDecl()->isSuperClassOf(RHS->getDecl())) 6175a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian return BlockReturnType; 6176132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (RHS->getDecl()->isSuperClassOf(LHS->getDecl())) 6177a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian return !BlockReturnType; 6178132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 6179132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian else 6180132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return true; 6181132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 6182132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return false; 6183132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian} 6184132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 6185e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// getIntersectionOfProtocols - This routine finds the intersection of set 6186e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// of protocols inherited from two distinct objective-c pointer objects. 6187e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// It is used to build composite qualifier list of the composite type of 6188e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// the conditional expression involving two objective-c pointer objects. 6189e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanianstatic 6190e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanianvoid getIntersectionOfProtocols(ASTContext &Context, 6191e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian const ObjCObjectPointerType *LHSOPT, 6192e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian const ObjCObjectPointerType *RHSOPT, 61935f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<ObjCProtocolDecl *> &IntersectionOfProtocols) { 6194e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 6195c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* LHS = LHSOPT->getObjectType(); 6196c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* RHS = RHSOPT->getObjectType(); 6197c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(LHS->getInterface() && "LHS must have an interface base"); 6198c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(RHS->getInterface() && "RHS must have an interface base"); 6199e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 6200e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> InheritedProtocolSet; 6201e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian unsigned LHSNumProtocols = LHS->getNumProtocols(); 6202e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (LHSNumProtocols > 0) 6203e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian InheritedProtocolSet.insert(LHS->qual_begin(), LHS->qual_end()); 6204e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian else { 6205432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> LHSInheritedProtocols; 6206c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Context.CollectInheritedProtocols(LHS->getInterface(), 6207c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall LHSInheritedProtocols); 6208e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian InheritedProtocolSet.insert(LHSInheritedProtocols.begin(), 6209e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian LHSInheritedProtocols.end()); 6210e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 6211e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 6212e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian unsigned RHSNumProtocols = RHS->getNumProtocols(); 6213e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (RHSNumProtocols > 0) { 6214cb421fa690da545b58a720abe5f1c49b166dbde7Dan Gohman ObjCProtocolDecl **RHSProtocols = 6215cb421fa690da545b58a720abe5f1c49b166dbde7Dan Gohman const_cast<ObjCProtocolDecl **>(RHS->qual_begin()); 6216e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (unsigned i = 0; i < RHSNumProtocols; ++i) 6217e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (InheritedProtocolSet.count(RHSProtocols[i])) 6218e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian IntersectionOfProtocols.push_back(RHSProtocols[i]); 62193060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 6220432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> RHSInheritedProtocols; 6221c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Context.CollectInheritedProtocols(RHS->getInterface(), 6222c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall RHSInheritedProtocols); 6223432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 6224432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian RHSInheritedProtocols.begin(), 6225432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian E = RHSInheritedProtocols.end(); I != E; ++I) 6226432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian if (InheritedProtocolSet.count((*I))) 6227432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian IntersectionOfProtocols.push_back((*I)); 6228e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 6229e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian} 6230e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 6231db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// areCommonBaseCompatible - Returns common base class of the two classes if 6232db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// one found. Note that this is O'2 algorithm. But it will be called as the 6233db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// last type comparison in a ?-exp of ObjC pointer types before a 6234db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// warning is issued. So, its invokation is extremely rare. 6235db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz JahanianQualType ASTContext::areCommonBaseCompatible( 6236c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectPointerType *Lptr, 6237c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectPointerType *Rptr) { 6238c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *LHS = Lptr->getObjectType(); 6239c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *RHS = Rptr->getObjectType(); 6240c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCInterfaceDecl* LDecl = LHS->getInterface(); 6241c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCInterfaceDecl* RDecl = RHS->getInterface(); 624260ef308e51c71b760d7f598c1b763ceb7b768148Douglas Gregor if (!LDecl || !RDecl || (declaresSameEntity(LDecl, RDecl))) 6243db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian return QualType(); 6244db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian 62457c2bdcb4d30f2d370b4367664e6a11b075ce2cb3Fariborz Jahanian do { 6246c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall LHS = cast<ObjCInterfaceType>(getObjCInterfaceType(LDecl)); 6247e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (canAssignObjCInterfaces(LHS, RHS)) { 62485f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<ObjCProtocolDecl *, 8> Protocols; 6249c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getIntersectionOfProtocols(*this, Lptr, Rptr, Protocols); 6250c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 6251c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType Result = QualType(LHS, 0); 6252c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!Protocols.empty()) 6253c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = getObjCObjectType(Result, Protocols.data(), Protocols.size()); 6254c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = getObjCObjectPointerType(Result); 6255c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return Result; 6256e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 62577c2bdcb4d30f2d370b4367664e6a11b075ce2cb3Fariborz Jahanian } while ((LDecl = LDecl->getSuperClass())); 6258db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian 6259db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian return QualType(); 6260db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian} 6261db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian 6262c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallbool ASTContext::canAssignObjCInterfaces(const ObjCObjectType *LHS, 6263c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *RHS) { 6264c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(LHS->getInterface() && "LHS is not an interface type"); 6265c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(RHS->getInterface() && "RHS is not an interface type"); 6266c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 62676ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // Verify that the base decls are compatible: the RHS must be a subclass of 62686ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // the LHS. 6269c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!LHS->getInterface()->isSuperClassOf(RHS->getInterface())) 62706ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return false; 62711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62726ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // RHS must have a superset of the protocols in the LHS. If the LHS is not 62736ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // protocol qualified at all, then we are good. 6274c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (LHS->getNumProtocols() == 0) 62756ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return true; 62761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6277b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // Okay, we know the LHS has protocol qualifiers. If the RHS doesn't, 6278b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // more detailed analysis is required. 6279b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (RHS->getNumProtocols() == 0) { 6280b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // OK, if LHS is a superclass of RHS *and* 6281b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // this superclass is assignment compatible with LHS. 6282b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // false otherwise. 6283627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian bool IsSuperClass = 6284627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian LHS->getInterface()->isSuperClassOf(RHS->getInterface()); 6285627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian if (IsSuperClass) { 6286b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // OK if conversion of LHS to SuperClass results in narrowing of types 6287b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // ; i.e., SuperClass may implement at least one of the protocols 6288b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // in LHS's protocol list. Example, SuperObj<P1> = lhs<P1,P2> is ok. 6289b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // But not SuperObj<P1,P2,P3> = lhs<P1,P2>. 6290b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> SuperClassInheritedProtocols; 6291627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian CollectInheritedProtocols(RHS->getInterface(), SuperClassInheritedProtocols); 6292b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // If super class has no protocols, it is not a match. 6293b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (SuperClassInheritedProtocols.empty()) 6294b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return false; 6295b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian 6296b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian for (ObjCObjectType::qual_iterator LHSPI = LHS->qual_begin(), 6297b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian LHSPE = LHS->qual_end(); 6298b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian LHSPI != LHSPE; LHSPI++) { 6299b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian bool SuperImplementsProtocol = false; 6300b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian ObjCProtocolDecl *LHSProto = (*LHSPI); 6301b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian 6302b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 6303b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian SuperClassInheritedProtocols.begin(), 6304b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian E = SuperClassInheritedProtocols.end(); I != E; ++I) { 6305b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian ObjCProtocolDecl *SuperClassProto = (*I); 6306b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (SuperClassProto->lookupProtocolNamed(LHSProto->getIdentifier())) { 6307b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian SuperImplementsProtocol = true; 6308b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian break; 6309b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 6310b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 6311b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (!SuperImplementsProtocol) 6312b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return false; 6313b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 6314b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return true; 6315b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 6316b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return false; 6317b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 63181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6319c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (ObjCObjectType::qual_iterator LHSPI = LHS->qual_begin(), 6320c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall LHSPE = LHS->qual_end(); 632191b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff LHSPI != LHSPE; LHSPI++) { 632291b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff bool RHSImplementsProtocol = false; 632391b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff 632491b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // If the RHS doesn't implement the protocol on the left, the types 632591b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // are incompatible. 6326c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (ObjCObjectType::qual_iterator RHSPI = RHS->qual_begin(), 6327c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall RHSPE = RHS->qual_end(); 63288f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff RHSPI != RHSPE; RHSPI++) { 63298f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff if ((*RHSPI)->lookupProtocolNamed((*LHSPI)->getIdentifier())) { 633091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff RHSImplementsProtocol = true; 63318f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 63328f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 633391b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 633491b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // FIXME: For better diagnostics, consider passing back the protocol name. 633591b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff if (!RHSImplementsProtocol) 633691b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return false; 633791b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 633891b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // The RHS implements all protocols listed on the LHS. 633991b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return true; 63406ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 63416ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 6342389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroffbool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { 6343389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff // get the "pointed to" types 6344183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *LHSOPT = LHS->getAs<ObjCObjectPointerType>(); 6345183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *RHSOPT = RHS->getAs<ObjCObjectPointerType>(); 63461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 634714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (!LHSOPT || !RHSOPT) 6348389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff return false; 634914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 635014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return canAssignObjCInterfaces(LHSOPT, RHSOPT) || 635114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff canAssignObjCInterfaces(RHSOPT, LHSOPT); 6352389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff} 6353389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff 6354569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorbool ASTContext::canBindObjCObjectType(QualType To, QualType From) { 6355569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return canAssignObjCInterfaces( 6356569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor getObjCObjectPointerType(To)->getAs<ObjCObjectPointerType>(), 6357569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor getObjCObjectPointerType(From)->getAs<ObjCObjectPointerType>()); 6358569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor} 6359569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor 63601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typesAreCompatible - C99 6.7.3p9: For two qualified types to be compatible, 6361ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// both shall have the identically qualified version of a compatible type. 63621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// C99 6.2.7p1: Two types have compatible types if their types are the 6363ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// same. See 6.7.[2,3,5] for additional rules. 6364447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregorbool ASTContext::typesAreCompatible(QualType LHS, QualType RHS, 6365447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool CompareUnqualified) { 63664e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 63670e709abafbd939326850501f795cc7a92c88a354Douglas Gregor return hasSameType(LHS, RHS); 63680e709abafbd939326850501f795cc7a92c88a354Douglas Gregor 6369447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor return !mergeTypes(LHS, RHS, false, CompareUnqualified).isNull(); 63703d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 63713d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6372c286f3835eb6001c61664cef5d610dfaf80a6e9bFariborz Jahanianbool ASTContext::propertyTypesAreCompatible(QualType LHS, QualType RHS) { 637382378391dfc3b2fc22f63dbf1552bd9aed39dc42Fariborz Jahanian return typesAreCompatible(LHS, RHS); 6374c286f3835eb6001c61664cef5d610dfaf80a6e9bFariborz Jahanian} 6375c286f3835eb6001c61664cef5d610dfaf80a6e9bFariborz Jahanian 6376132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanianbool ASTContext::typesAreBlockPointerCompatible(QualType LHS, QualType RHS) { 6377132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return !mergeTypes(LHS, RHS, true).isNull(); 6378132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian} 6379132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 63804846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// mergeTransparentUnionType - if T is a transparent union type and a member 63814846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// of T is compatible with SubType, return the merged type, else return 63824846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// QualType() 63834846675e0e42d1802b0ffd8972a45e72aeb3758dPeter CollingbourneQualType ASTContext::mergeTransparentUnionType(QualType T, QualType SubType, 63844846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool OfBlockPointer, 63854846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool Unqualified) { 63864846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (const RecordType *UT = T->getAsUnionType()) { 63874846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne RecordDecl *UD = UT->getDecl(); 63884846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (UD->hasAttr<TransparentUnionAttr>()) { 63894846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne for (RecordDecl::field_iterator it = UD->field_begin(), 63904846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne itend = UD->field_end(); it != itend; ++it) { 6391f91d7572ee7fa6f2926c8e7e816039a1154a59f8Peter Collingbourne QualType ET = it->getType().getUnqualifiedType(); 63924846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType MT = mergeTypes(ET, SubType, OfBlockPointer, Unqualified); 63934846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (!MT.isNull()) 63944846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return MT; 63954846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne } 63964846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne } 63974846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne } 63984846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 63994846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return QualType(); 64004846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne} 64014846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 64024846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// mergeFunctionArgumentTypes - merge two types which appear as function 64034846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// argument types 64044846675e0e42d1802b0ffd8972a45e72aeb3758dPeter CollingbourneQualType ASTContext::mergeFunctionArgumentTypes(QualType lhs, QualType rhs, 64054846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool OfBlockPointer, 64064846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool Unqualified) { 64074846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne // GNU extension: two types are compatible if they appear as a function 64084846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne // argument, one of the types is a transparent union type and the other 64094846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne // type is compatible with a union member 64104846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType lmerge = mergeTransparentUnionType(lhs, rhs, OfBlockPointer, 64114846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne Unqualified); 64124846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (!lmerge.isNull()) 64134846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return lmerge; 64144846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 64154846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType rmerge = mergeTransparentUnionType(rhs, lhs, OfBlockPointer, 64164846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne Unqualified); 64174846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (!rmerge.isNull()) 64184846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return rmerge; 64194846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 64204846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return mergeTypes(lhs, rhs, OfBlockPointer, Unqualified); 64214846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne} 64224846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 6423132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz JahanianQualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, 6424447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool OfBlockPointer, 6425447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool Unqualified) { 6426183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *lbase = lhs->getAs<FunctionType>(); 6427183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *rbase = rhs->getAs<FunctionType>(); 642872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *lproto = dyn_cast<FunctionProtoType>(lbase); 642972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *rproto = dyn_cast<FunctionProtoType>(rbase); 64303d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allLTypes = true; 64313d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allRTypes = true; 64323d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 64333d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check return type 6434132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian QualType retType; 6435d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian if (OfBlockPointer) { 6436d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian QualType RHS = rbase->getResultType(); 6437d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian QualType LHS = lbase->getResultType(); 6438d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian bool UnqualifiedResult = Unqualified; 6439d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian if (!UnqualifiedResult) 6440d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian UnqualifiedResult = (!RHS.hasQualifiers() && LHS.hasQualifiers()); 6441a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian retType = mergeTypes(LHS, RHS, true, UnqualifiedResult, true); 6442d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian } 6443132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian else 64448cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall retType = mergeTypes(lbase->getResultType(), rbase->getResultType(), false, 64458cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall Unqualified); 64463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (retType.isNull()) return QualType(); 6447447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6448447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) 6449447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor retType = retType.getUnqualifiedType(); 6450447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6451447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor CanQualType LRetType = getCanonicalType(lbase->getResultType()); 6452447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor CanQualType RRetType = getCanonicalType(rbase->getResultType()); 6453447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6454447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LRetType = LRetType.getUnqualifiedType(); 6455447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RRetType = RRetType.getUnqualifiedType(); 6456447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6457447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6458447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (getCanonicalType(retType) != LRetType) 645961710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 6460447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (getCanonicalType(retType) != RRetType) 646161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 64628cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 64636a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // FIXME: double check this 64646a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // FIXME: should we error if lbase->getRegParmAttr() != 0 && 64656a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // rbase->getRegParmAttr() != 0 && 64666a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // lbase->getRegParmAttr() != rbase->getRegParmAttr()? 6467264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionType::ExtInfo lbaseInfo = lbase->getExtInfo(); 6468264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionType::ExtInfo rbaseInfo = rbase->getExtInfo(); 64698cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 64708cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall // Compatible functions must have compatible calling conventions 64718cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall if (!isSameCallConv(lbaseInfo.getCC(), rbaseInfo.getCC())) 64728cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall return QualType(); 64738cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 64748cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall // Regparm is part of the calling convention. 6475a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman if (lbaseInfo.getHasRegParm() != rbaseInfo.getHasRegParm()) 6476a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman return QualType(); 64778cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall if (lbaseInfo.getRegParm() != rbaseInfo.getRegParm()) 64788cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall return QualType(); 64798cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 6480f85e193739c953358c865005855253af4f68a497John McCall if (lbaseInfo.getProducesResult() != rbaseInfo.getProducesResult()) 6481f85e193739c953358c865005855253af4f68a497John McCall return QualType(); 6482f85e193739c953358c865005855253af4f68a497John McCall 648353c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian // functypes which return are preferred over those that do not. 648453c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian if (lbaseInfo.getNoReturn() && !rbaseInfo.getNoReturn()) 64856a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar allLTypes = false; 648653c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian else if (!lbaseInfo.getNoReturn() && rbaseInfo.getNoReturn()) 64876a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar allRTypes = false; 648853c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian // FIXME: some uses, e.g. conditional exprs, really want this to be 'both'. 648953c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian bool NoReturn = lbaseInfo.getNoReturn() || rbaseInfo.getNoReturn(); 64901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6491f85e193739c953358c865005855253af4f68a497John McCall FunctionType::ExtInfo einfo = lbaseInfo.withNoReturn(NoReturn); 6492e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 64933d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto && rproto) { // two C99 style function prototypes 6494465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() && 6495465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl "C++ shouldn't be here"); 64963d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned lproto_nargs = lproto->getNumArgs(); 64973d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned rproto_nargs = rproto->getNumArgs(); 64983d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 64993d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Compatible functions must have the same number of arguments 65003d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto_nargs != rproto_nargs) 65013d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 65023d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 65033d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Variadic and non-variadic functions aren't compatible 65043d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto->isVariadic() != rproto->isVariadic()) 65053d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 65063d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 65077fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis if (lproto->getTypeQuals() != rproto->getTypeQuals()) 65087fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis return QualType(); 65097fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis 651078213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (LangOpts.ObjCAutoRefCount && 651178213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian !FunctionTypesMatchOnNSConsumedAttrs(rproto, lproto)) 651278213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return QualType(); 651378213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian 65143d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check argument compatibility 65155f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 10> types; 65163d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < lproto_nargs; i++) { 65173d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType largtype = lproto->getArgType(i).getUnqualifiedType(); 65183d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType rargtype = rproto->getArgType(i).getUnqualifiedType(); 65194846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType argtype = mergeFunctionArgumentTypes(largtype, rargtype, 65204846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne OfBlockPointer, 65214846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne Unqualified); 65223d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argtype.isNull()) return QualType(); 6523447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6524447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) 6525447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor argtype = argtype.getUnqualifiedType(); 6526447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 65273d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman types.push_back(argtype); 6528447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6529447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor largtype = largtype.getUnqualifiedType(); 6530447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor rargtype = rargtype.getUnqualifiedType(); 6531447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6532447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 653361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(largtype)) 653461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 653561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(rargtype)) 653661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 65373d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 653878213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian 65393d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 65403d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 6541e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 6542e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI = lproto->getExtProtoInfo(); 6543e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = einfo; 6544e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return getFunctionType(retType, types.begin(), types.size(), EPI); 65453d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 65463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 65473d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto) allRTypes = false; 65483d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (rproto) allLTypes = false; 65493d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 655072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *proto = lproto ? lproto : rproto; 65513d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto) { 6552465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!proto->hasExceptionSpec() && "C++ shouldn't be here"); 65533d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto->isVariadic()) return QualType(); 65543d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check that the types are compatible with the types that 65553d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // would result from default argument promotions (C99 6.7.5.3p15). 65563d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // The only types actually affected are promotable integer 65573d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // types and floats, which would be passed as a different 65583d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // type depending on whether the prototype is visible. 65593d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned proto_nargs = proto->getNumArgs(); 65603d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < proto_nargs; ++i) { 65613d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType argTy = proto->getArgType(i); 6562b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor 6563c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman // Look at the converted type of enum types, since that is the type used 6564b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor // to pass enum values. 6565c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman if (const EnumType *Enum = argTy->getAs<EnumType>()) { 6566c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman argTy = Enum->getDecl()->getIntegerType(); 6567c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman if (argTy.isNull()) 6568c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman return QualType(); 6569c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman } 6570b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor 65713d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argTy->isPromotableIntegerType() || 65723d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman getCanonicalType(argTy).getUnqualifiedType() == FloatTy) 65733d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 65743d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 65753d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 65763d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 65773d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 6578e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 6579e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI = proto->getExtProtoInfo(); 6580e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = einfo; 65813d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getFunctionType(retType, proto->arg_type_begin(), 6582e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall proto->getNumArgs(), EPI); 65833d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 65843d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 65853d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 65863d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 65878cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall return getFunctionNoProtoType(retType, einfo); 65883d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 65893d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6590132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz JahanianQualType ASTContext::mergeTypes(QualType LHS, QualType RHS, 6591447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool OfBlockPointer, 6592a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian bool Unqualified, bool BlockReturnType) { 659343d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // C++ [expr]: If an expression initially has the type "reference to T", the 659443d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // type is adjusted to "T" prior to any further analysis, the expression 659543d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // designates the object or function denoted by the reference, and the 65967c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // expression is an lvalue unless the reference is an rvalue reference and 65977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // the expression is a function call (possibly inside parentheses). 65980e709abafbd939326850501f795cc7a92c88a354Douglas Gregor assert(!LHS->getAs<ReferenceType>() && "LHS is a reference type?"); 65990e709abafbd939326850501f795cc7a92c88a354Douglas Gregor assert(!RHS->getAs<ReferenceType>() && "RHS is a reference type?"); 6600447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6601447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6602447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHS = LHS.getUnqualifiedType(); 6603447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHS = RHS.getUnqualifiedType(); 6604447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 66050e709abafbd939326850501f795cc7a92c88a354Douglas Gregor 66063d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSCan = getCanonicalType(LHS), 66073d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman RHSCan = getCanonicalType(RHS); 66083d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6609f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner // If two types are identical, they are compatible. 66103d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LHSCan == RHSCan) 66113d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 66123d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 66130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If the qualifiers are different, the types aren't compatible... mostly. 6614a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers LQuals = LHSCan.getLocalQualifiers(); 6615a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers RQuals = RHSCan.getLocalQualifiers(); 66160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (LQuals != RQuals) { 66170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If any of these qualifiers are different, we have a type 66180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // mismatch. 66190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || 6620f85e193739c953358c865005855253af4f68a497John McCall LQuals.getAddressSpace() != RQuals.getAddressSpace() || 6621f85e193739c953358c865005855253af4f68a497John McCall LQuals.getObjCLifetime() != RQuals.getObjCLifetime()) 66220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(); 66230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 66240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Exactly one GC qualifier difference is allowed: __strong is 66250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // okay if the other type has no GC qualifier but is an Objective 66260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // C object pointer (i.e. implicitly strong by default). We fix 66270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // this by pretending that the unqualified type was actually 66280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualified __strong. 66290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GC_L = LQuals.getObjCGCAttr(); 66300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GC_R = RQuals.getObjCGCAttr(); 66310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements"); 66320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 66330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) 66340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(); 66350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 66360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_L == Qualifiers::Strong && RHSCan->isObjCObjectPointerType()) { 66370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return mergeTypes(LHS, getObjCGCQualType(RHS, Qualifiers::Strong)); 66380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 66390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_R == Qualifiers::Strong && LHSCan->isObjCObjectPointerType()) { 66400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return mergeTypes(getObjCGCQualType(LHS, Qualifiers::Strong), RHS); 66410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 66423d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 66430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 66440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 66450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Okay, qualifiers are equal. 66463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6647852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass LHSClass = LHSCan->getTypeClass(); 6648852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass RHSClass = RHSCan->getTypeClass(); 6649f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner 66501adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // We want to consider the two function types to be the same for these 66511adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // comparisons, just force one to the other. 66521adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (LHSClass == Type::FunctionProto) LHSClass = Type::FunctionNoProto; 66531adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (RHSClass == Type::FunctionProto) RHSClass = Type::FunctionNoProto; 66544c721d381fb279899337d120edd4a24d405e56b2Eli Friedman 66554c721d381fb279899337d120edd4a24d405e56b2Eli Friedman // Same as above for arrays 6656a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (LHSClass == Type::VariableArray || LHSClass == Type::IncompleteArray) 6657a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner LHSClass = Type::ConstantArray; 6658a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (RHSClass == Type::VariableArray || RHSClass == Type::IncompleteArray) 6659a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner RHSClass = Type::ConstantArray; 66601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6661c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCInterfaces are just specialized ObjCObjects. 6662c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHSClass == Type::ObjCInterface) LHSClass = Type::ObjCObject; 6663c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (RHSClass == Type::ObjCInterface) RHSClass = Type::ObjCObject; 6664c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 6665213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman // Canonicalize ExtVector -> Vector. 6666213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (LHSClass == Type::ExtVector) LHSClass = Type::Vector; 6667213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (RHSClass == Type::ExtVector) RHSClass = Type::Vector; 66681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66694e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff // If the canonical type classes don't match. 66704e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff if (LHSClass != RHSClass) { 66711adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // C99 6.7.2.2p4: Each enumerated type shall be compatible with char, 66721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // a signed integer type, or an unsigned integer type. 6673842aef8d942a880eeb9535d40de31a86838264cbJohn McCall // Compatibility is based on the underlying type, not the promotion 6674842aef8d942a880eeb9535d40de31a86838264cbJohn McCall // type. 6675183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const EnumType* ETy = LHS->getAs<EnumType>()) { 6676b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian QualType TINT = ETy->getDecl()->getIntegerType(); 6677b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian if (!TINT.isNull() && hasSameType(TINT, RHSCan.getUnqualifiedType())) 66783d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 6679bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 6680183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const EnumType* ETy = RHS->getAs<EnumType>()) { 6681b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian QualType TINT = ETy->getDecl()->getIntegerType(); 6682b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian if (!TINT.isNull() && hasSameType(TINT, LHSCan.getUnqualifiedType())) 66833d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 6684bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 6685e7cff2c00c3d74e38984a4db5c48d7e303d3ab8eFariborz Jahanian // allow block pointer type to match an 'id' type. 6686419636316c04d570c183b4797fc811932c588358Fariborz Jahanian if (OfBlockPointer && !BlockReturnType) { 6687419636316c04d570c183b4797fc811932c588358Fariborz Jahanian if (LHS->isObjCIdType() && RHS->isBlockPointerType()) 6688419636316c04d570c183b4797fc811932c588358Fariborz Jahanian return LHS; 6689419636316c04d570c183b4797fc811932c588358Fariborz Jahanian if (RHS->isObjCIdType() && LHS->isBlockPointerType()) 6690419636316c04d570c183b4797fc811932c588358Fariborz Jahanian return RHS; 6691419636316c04d570c183b4797fc811932c588358Fariborz Jahanian } 6692e7cff2c00c3d74e38984a4db5c48d7e303d3ab8eFariborz Jahanian 66933d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 6694ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 66953d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 66964a74678ed6c3dedac05d02b1ee341f1db869f049Steve Naroff // The canonical type classes match. 66971adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner switch (LHSClass) { 669872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 669972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 6700ad5e73887052193afda72db8efcb812bd083a4a8John McCall#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class: 670172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 670272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 670372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 6704b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Non-canonical and dependent types shouldn't get here"); 670572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 67067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::LValueReference: 67077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::RValueReference: 670872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::MemberPointer: 6709b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("C++ should never be in mergeTypes"); 671072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 6711c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case Type::ObjCInterface: 671272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 671372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::VariableArray: 671472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::FunctionProto: 671572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::ExtVector: 6716b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Types are eliminated above"); 671772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 67181adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Pointer: 67193d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 67203d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Merge two pointer types, while trying to preserve typedef info 67216217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<PointerType>()->getPointeeType(); 67226217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<PointerType>()->getPointeeType(); 6723447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6724447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHSPointee = LHSPointee.getUnqualifiedType(); 6725447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHSPointee = RHSPointee.getUnqualifiedType(); 6726447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6727447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor QualType ResultType = mergeTypes(LHSPointee, RHSPointee, false, 6728447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor Unqualified); 67293d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 673007d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 673161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 673207d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 673361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 67343d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getPointerType(ResultType); 67353d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 6736c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff case Type::BlockPointer: 6737c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff { 6738c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff // Merge two block pointer types, while trying to preserve typedef info 67396217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<BlockPointerType>()->getPointeeType(); 67406217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<BlockPointerType>()->getPointeeType(); 6741447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6742447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHSPointee = LHSPointee.getUnqualifiedType(); 6743447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHSPointee = RHSPointee.getUnqualifiedType(); 6744447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6745447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor QualType ResultType = mergeTypes(LHSPointee, RHSPointee, OfBlockPointer, 6746447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor Unqualified); 6747c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (ResultType.isNull()) return QualType(); 6748c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 6749c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return LHS; 6750c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 6751c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return RHS; 6752c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return getBlockPointerType(ResultType); 6753c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff } 6754b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: 6755b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman { 6756b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // Merge two pointer types, while trying to preserve typedef info 6757b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType LHSValue = LHS->getAs<AtomicType>()->getValueType(); 6758b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType RHSValue = RHS->getAs<AtomicType>()->getValueType(); 6759b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (Unqualified) { 6760b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman LHSValue = LHSValue.getUnqualifiedType(); 6761b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman RHSValue = RHSValue.getUnqualifiedType(); 6762b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 6763b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ResultType = mergeTypes(LHSValue, RHSValue, false, 6764b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Unqualified); 6765b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (ResultType.isNull()) return QualType(); 6766b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getCanonicalType(LHSValue) == getCanonicalType(ResultType)) 6767b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return LHS; 6768b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getCanonicalType(RHSValue) == getCanonicalType(ResultType)) 6769b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return RHS; 6770b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return getAtomicType(ResultType); 6771b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 67721adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::ConstantArray: 67733d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 67743d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* LCAT = getAsConstantArrayType(LHS); 67753d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* RCAT = getAsConstantArrayType(RHS); 67763d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LCAT && RCAT && RCAT->getSize() != LCAT->getSize()) 67773d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 67783d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 67793d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSElem = getAsArrayType(LHS)->getElementType(); 67803d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType RHSElem = getAsArrayType(RHS)->getElementType(); 6781447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6782447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHSElem = LHSElem.getUnqualifiedType(); 6783447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHSElem = RHSElem.getUnqualifiedType(); 6784447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6785447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6786447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor QualType ResultType = mergeTypes(LHSElem, RHSElem, false, Unqualified); 67873d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 678861710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LCAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 678961710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 679061710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RCAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 679161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 67923bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (LCAT) return getConstantArrayType(ResultType, LCAT->getSize(), 67933bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 67943bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (RCAT) return getConstantArrayType(ResultType, RCAT->getSize(), 67953bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 67963d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* LVAT = getAsVariableArrayType(LHS); 67973d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* RVAT = getAsVariableArrayType(RHS); 679861710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LVAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 679961710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 680061710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RVAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 680161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 68023d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LVAT) { 68033d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 68043d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of LHS, but the type 68053d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 68063d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 68073d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 68083d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (RVAT) { 68093d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 68103d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of RHS, but the type 68113d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 68123d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 68133d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 68143bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS; 68153bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS; 68167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return getIncompleteArrayType(ResultType, 68177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArrayType::ArraySizeModifier(), 0); 68183d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 68191adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::FunctionNoProto: 6820447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor return mergeFunctionTypes(LHS, RHS, OfBlockPointer, Unqualified); 682172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 682272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: 68233d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 68241adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Builtin: 68253cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner // Only exactly equal builtin types are compatible, which is tested above. 68263d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 682764cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar case Type::Complex: 682864cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar // Distinct complex types are incompatible. 682964cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar return QualType(); 68303cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner case Type::Vector: 68315a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: The merged type should be an ExtVector! 68321c471f3e1c0ec8cbc82447bb35908dfc55463e46John McCall if (areCompatVectorTypes(LHSCan->getAs<VectorType>(), 68331c471f3e1c0ec8cbc82447bb35908dfc55463e46John McCall RHSCan->getAs<VectorType>())) 68343d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 683561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return QualType(); 6836c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case Type::ObjCObject: { 6837c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Check if the types are assignment compatible. 68385a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: This should be type compatibility, e.g. whether 68395a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // "LHS x; RHS x;" at global scope is legal. 6840c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* LHSIface = LHS->getAs<ObjCObjectType>(); 6841c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* RHSIface = RHS->getAs<ObjCObjectType>(); 6842c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (canAssignObjCInterfaces(LHSIface, RHSIface)) 68435fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff return LHS; 68445fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff 68453d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 684661490e9a965cfee8a78c12c6802138844f04250dCedric Venet } 684714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case Type::ObjCObjectPointer: { 6848132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (OfBlockPointer) { 6849132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (canAssignObjCInterfacesInBlockPointer( 6850132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian LHS->getAs<ObjCObjectPointerType>(), 6851a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian RHS->getAs<ObjCObjectPointerType>(), 6852a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian BlockReturnType)) 68537530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie return LHS; 6854132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return QualType(); 6855132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 6856183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (canAssignObjCInterfaces(LHS->getAs<ObjCObjectPointerType>(), 6857183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall RHS->getAs<ObjCObjectPointerType>())) 685814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return LHS; 685914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 6860bc76dd06eb881c70c9775b74bab8b88cd747f173Steve Naroff return QualType(); 68617530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie } 6862ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 686372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 68647530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid Type::Class!"); 6865ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff} 68667192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek 686778213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanianbool ASTContext::FunctionTypesMatchOnNSConsumedAttrs( 686878213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian const FunctionProtoType *FromFunctionType, 686978213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian const FunctionProtoType *ToFunctionType) { 687078213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (FromFunctionType->hasAnyConsumedArgs() != 687178213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ToFunctionType->hasAnyConsumedArgs()) 687278213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return false; 687378213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian FunctionProtoType::ExtProtoInfo FromEPI = 687478213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian FromFunctionType->getExtProtoInfo(); 687578213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian FunctionProtoType::ExtProtoInfo ToEPI = 687678213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ToFunctionType->getExtProtoInfo(); 687778213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (FromEPI.ConsumedArguments && ToEPI.ConsumedArguments) 687878213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumArgs(); 687978213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ArgIdx != NumArgs; ++ArgIdx) { 688078213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (FromEPI.ConsumedArguments[ArgIdx] != 688178213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ToEPI.ConsumedArguments[ArgIdx]) 688278213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return false; 688378213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian } 688478213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return true; 688578213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian} 688678213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian 68872390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian/// mergeObjCGCQualifiers - This routine merges ObjC's GC attribute of 'LHS' and 68882390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian/// 'RHS' attributes and returns the merged version; including for function 68892390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian/// return types. 68902390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz JahanianQualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { 68912390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType LHSCan = getCanonicalType(LHS), 68922390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian RHSCan = getCanonicalType(RHS); 68932390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // If two types are identical, they are compatible. 68942390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LHSCan == RHSCan) 68952390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return LHS; 68962390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (RHSCan->isFunctionType()) { 68972390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (!LHSCan->isFunctionType()) 68982390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 68992390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType OldReturnType = 69002390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian cast<FunctionType>(RHSCan.getTypePtr())->getResultType(); 69012390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType NewReturnType = 69022390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian cast<FunctionType>(LHSCan.getTypePtr())->getResultType(); 69032390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType ResReturnType = 69042390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian mergeObjCGCQualifiers(NewReturnType, OldReturnType); 69052390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResReturnType.isNull()) 69062390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 69072390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResReturnType == NewReturnType || ResReturnType == OldReturnType) { 69082390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // id foo(); ... __strong id foo(); or: __strong id foo(); ... id foo(); 69092390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // In either case, use OldReturnType to build the new function type. 69102390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian const FunctionType *F = LHS->getAs<FunctionType>(); 69112390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (const FunctionProtoType *FPT = cast<FunctionProtoType>(F)) { 6912e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); 6913e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = getFunctionExtInfo(LHS); 69142390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType ResultType 69152390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian = getFunctionType(OldReturnType, FPT->arg_type_begin(), 6916e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FPT->getNumArgs(), EPI); 69172390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return ResultType; 69182390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 69192390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 69202390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 69212390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 69222390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 69232390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // If the qualifiers are different, the types can still be merged. 69242390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers LQuals = LHSCan.getLocalQualifiers(); 69252390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers RQuals = RHSCan.getLocalQualifiers(); 69262390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LQuals != RQuals) { 69272390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // If any of these qualifiers are different, we have a type mismatch. 69282390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || 69292390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian LQuals.getAddressSpace() != RQuals.getAddressSpace()) 69302390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 69312390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 69322390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // Exactly one GC qualifier difference is allowed: __strong is 69332390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // okay if the other type has no GC qualifier but is an Objective 69342390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // C object pointer (i.e. implicitly strong by default). We fix 69352390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // this by pretending that the unqualified type was actually 69362390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // qualified __strong. 69372390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers::GC GC_L = LQuals.getObjCGCAttr(); 69382390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers::GC GC_R = RQuals.getObjCGCAttr(); 69392390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements"); 69402390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 69412390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) 69422390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 69432390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 69442390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (GC_L == Qualifiers::Strong) 69452390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return LHS; 69462390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (GC_R == Qualifiers::Strong) 69472390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return RHS; 69482390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 69492390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 69502390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 69512390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LHSCan->isObjCObjectPointerType() && RHSCan->isObjCObjectPointerType()) { 69522390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType LHSBaseQT = LHS->getAs<ObjCObjectPointerType>()->getPointeeType(); 69532390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType RHSBaseQT = RHS->getAs<ObjCObjectPointerType>()->getPointeeType(); 69542390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType ResQT = mergeObjCGCQualifiers(LHSBaseQT, RHSBaseQT); 69552390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResQT == LHSBaseQT) 69562390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return LHS; 69572390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResQT == RHSBaseQT) 69582390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return RHS; 69592390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 69602390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 69612390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian} 69622390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 69635426bf6456a5aeac416a9150de157904d101c819Chris Lattner//===----------------------------------------------------------------------===// 6964ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman// Integer Predicates 6965ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman//===----------------------------------------------------------------------===// 696688054dee0402e4d3c1f64e6b697acc47195c0d72Chris Lattner 69674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned ASTContext::getIntWidth(QualType T) const { 6968f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const EnumType *ET = dyn_cast<EnumType>(T)) 696929a7f3342c3c6dd15d914c61ae22246c36d51ce7Eli Friedman T = ET->getDecl()->getIntegerType(); 69701274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (T->isBooleanType()) 69711274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return 1; 6972f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // For builtin types, just use the standard type sizing method 6973ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return (unsigned)getTypeSize(T); 6974ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 6975ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 6976762f159c3295552f1f3e5e1af8b66385bfaed786Abramo BagnaraQualType ASTContext::getCorrespondingUnsignedType(QualType T) const { 6977f60946222721d9ba3c059563935c17b84703187aDouglas Gregor assert(T->hasSignedIntegerRepresentation() && "Unexpected type"); 69786a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner 69796a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner // Turn <4 x signed int> -> <4 x unsigned int> 69806a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner if (const VectorType *VTy = T->getAs<VectorType>()) 69816a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()), 6982e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VTy->getNumElements(), VTy->getVectorKind()); 69836a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner 69846a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner // For enums, we return the unsigned version of the base type. 69856a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner if (const EnumType *ETy = T->getAs<EnumType>()) 6986ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman T = ETy->getDecl()->getIntegerType(); 69876a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner 69886a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner const BuiltinType *BTy = T->getAs<BuiltinType>(); 69896a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner assert(BTy && "Unexpected signed integer type"); 6990ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman switch (BTy->getKind()) { 6991ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Char_S: 6992ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::SChar: 6993ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedCharTy; 6994ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Short: 6995ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedShortTy; 6996ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Int: 6997ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedIntTy; 6998ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Long: 6999ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongTy; 7000ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::LongLong: 7001ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongLongTy; 70022df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 70032df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return UnsignedInt128Ty; 7004ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman default: 7005b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unexpected signed integer type"); 7006ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman } 7007ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 7008ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 70097b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios KyrtzidisASTMutationListener::~ASTMutationListener() { } 70107b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 701186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 701286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 701386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner// Builtin Type Computation 701486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 701586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 701686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// DecodeTypeFromStr - This decodes one type descriptor from Str, advancing the 701733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// pointer over the consumed characters. This returns the resultant type. If 701833daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// AllowTypeModifiers is false then modifier like * are not parsed, just basic 701933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// types. This allows "v2i*" to be parsed as a pointer to a v2i instead of 702033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// a vector of "i*". 702114e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner/// 702214e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner/// RequiresICE is filled in on return to indicate whether the value is required 702314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner/// to be an Integer Constant Expression. 70244ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadstatic QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, 702586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ASTContext::GetBuiltinTypeError &Error, 702614e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner bool &RequiresICE, 702733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner bool AllowTypeModifiers) { 702886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Modifiers. 702986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner int HowLong = 0; 703086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Signed = false, Unsigned = false; 703114e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE = false; 7032393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner 703333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // Read the prefixed modifiers first. 703486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Done = false; 703586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 703686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 70371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: Done = true; --Str; break; 7038393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner case 'I': 703914e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE = true; 7040393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner break; 704186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'S': 704286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use both 'S' and 'U' modifiers!"); 704386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use 'S' modifier multiple times!"); 704486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Signed = true; 704586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 704686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'U': 704786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use both 'S' and 'U' modifiers!"); 704886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use 'S' modifier multiple times!"); 704986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Unsigned = true; 705086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 705186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'L': 705286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong <= 2 && "Can't have LLLL modifier"); 705386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ++HowLong; 705486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 705586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 705686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 705786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 705886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType Type; 70591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 706086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Read the base type. 706186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 7062b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unknown builtin type letter!"); 706386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'v': 706486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 706586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'v'!"); 706686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.VoidTy; 706786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 706886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'f': 706986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 707086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'f'!"); 707186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.FloatTy; 707286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 707386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'd': 707486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong < 2 && !Signed && !Unsigned && 707586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'd'!"); 707686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong) 707786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.LongDoubleTy; 707886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 707986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.DoubleTy; 708086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 708186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 's': 708286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 's'!"); 708386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Unsigned) 708486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedShortTy; 708586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 708686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.ShortTy; 708786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 708886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'i': 708986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong == 3) 709086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty; 709186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 2) 709286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy; 709386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 1) 709486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy; 709586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 709686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy; 709786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 709886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'c': 709986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 'c'!"); 710086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Signed) 710186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.SignedCharTy; 710286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (Unsigned) 710386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedCharTy; 710486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 710586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.CharTy; 710686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 710786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'b': // boolean 710886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'b'!"); 710986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.BoolTy; 711086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 711186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'z': // size_t. 711286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'z'!"); 711386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getSizeType(); 711486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 711586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'F': 711686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getCFConstantStringType(); 711786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 7118ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian case 'G': 7119ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian Type = Context.getObjCIdType(); 7120ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian break; 7121ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian case 'H': 7122ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian Type = Context.getObjCSelType(); 7123ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian break; 712486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'a': 712586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 712686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 712786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 712886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'A': 712986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // This is a "reference" to a va_list; however, what exactly 713086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // this means depends on how va_list is defined. There are two 713186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // different kinds of va_list: ones passed by value, and ones 713286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // passed by reference. An example of a by-value va_list is 713386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // x86, where va_list is a char*. An example of by-ref va_list 713486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // is x86-64, where va_list is a __va_list_tag[1]. For x86, 713586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // we want this argument to be a char*&; for x86-64, we want 713686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // it to be a __va_list_tag*. 713786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 713886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 713914e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner if (Type->isArrayType()) 714086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getArrayDecayedType(Type); 714114e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner else 714286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getLValueReferenceType(Type); 714386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 714486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'V': { 714586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner char *End; 714686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner unsigned NumElements = strtoul(Str, &End, 10); 714786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(End != Str && "Missing vector size"); 714886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Str = End; 71491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 715014e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType ElementType = DecodeTypeFromStr(Str, Context, Error, 715114e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE, false); 715214e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert(!RequiresICE && "Can't require vector ICE"); 715333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner 715433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // TODO: No way to make AltiVec vectors in builtins yet. 7155788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner Type = Context.getVectorType(ElementType, NumElements, 7156e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::GenericVector); 715786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 715886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 7159b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor case 'E': { 7160b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor char *End; 7161b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor 7162b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor unsigned NumElements = strtoul(Str, &End, 10); 7163b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor assert(End != Str && "Missing vector size"); 7164b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor 7165b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor Str = End; 7166b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor 7167b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor QualType ElementType = DecodeTypeFromStr(Str, Context, Error, RequiresICE, 7168b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor false); 7169b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor Type = Context.getExtVectorType(ElementType, NumElements); 7170b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor break; 7171b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor } 7172d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor case 'X': { 717314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType ElementType = DecodeTypeFromStr(Str, Context, Error, RequiresICE, 717414e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner false); 717514e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert(!RequiresICE && "Can't require complex ICE"); 7176d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor Type = Context.getComplexType(ElementType); 7177d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor break; 7178cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian } 7179cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian case 'Y' : { 7180cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian Type = Context.getPointerDiffType(); 7181cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian break; 7182cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian } 71839a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'P': 7184c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor Type = Context.getFILEType(); 7185c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor if (Type.isNull()) { 7186f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_stdio; 718786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 718886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 7189fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 71909a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'J': 7191f711c41dd9412a8182793259d355c4f6979ed5edMike Stump if (Signed) 7192782fa308a765aeac2acb39c4e697c937ec21185bMike Stump Type = Context.getsigjmp_bufType(); 7193f711c41dd9412a8182793259d355c4f6979ed5edMike Stump else 7194f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Type = Context.getjmp_bufType(); 7195f711c41dd9412a8182793259d355c4f6979ed5edMike Stump 7196fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump if (Type.isNull()) { 7197f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_setjmp; 7198fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump return QualType(); 7199fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump } 7200fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 7201e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola case 'K': 7202e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'K'!"); 7203e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola Type = Context.getucontext_tType(); 7204e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola 7205e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola if (Type.isNull()) { 7206e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola Error = ASTContext::GE_Missing_ucontext; 7207e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola return QualType(); 7208e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola } 7209e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola break; 7210782fa308a765aeac2acb39c4e697c937ec21185bMike Stump } 72111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 721233daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // If there are modifiers and if we're allowed to parse them, go for it. 721333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Done = !AllowTypeModifiers; 721486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 7215187ab37a05b8f7015b9f39cc8cd9129a0c6d0b48John McCall switch (char c = *Str++) { 721633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner default: Done = true; --Str; break; 721733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case '*': 721833daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case '&': { 721933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // Both pointers and references can have their pointee types 722033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // qualified with an address space. 722133daae66462e8f51ee153463b32bdefd60c801aaChris Lattner char *End; 722233daae66462e8f51ee153463b32bdefd60c801aaChris Lattner unsigned AddrSpace = strtoul(Str, &End, 10); 722333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner if (End != Str && AddrSpace != 0) { 722433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getAddrSpaceQualType(Type, AddrSpace); 722533daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Str = End; 722633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner } 722733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner if (c == '*') 722833daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getPointerType(Type); 722933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner else 723033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getLValueReferenceType(Type); 723133daae66462e8f51ee153463b32bdefd60c801aaChris Lattner break; 723233daae66462e8f51ee153463b32bdefd60c801aaChris Lattner } 723333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // FIXME: There's no way to have a built-in with an rvalue ref arg. 723433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case 'C': 723533daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Type.withConst(); 723633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner break; 723733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case 'D': 723833daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getVolatileType(Type); 723933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner break; 724018932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek case 'R': 724118932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek Type = Type.withRestrict(); 724218932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek break; 724386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 724486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 7245393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner 724614e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert((!RequiresICE || Type->isIntegralOrEnumerationType()) && 7247393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner "Integer constant 'I' type must be an integer"); 72481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 724986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return Type; 725086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 725186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 725286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// GetBuiltinType - Return the type for the specified builtin. 725333daae66462e8f51ee153463b32bdefd60c801aaChris LattnerQualType ASTContext::GetBuiltinType(unsigned Id, 725414e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner GetBuiltinTypeError &Error, 72554ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned *IntegerConstantArgs) const { 725633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner const char *TypeStr = BuiltinInfo.GetTypeString(Id); 72571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72585f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 8> ArgTypes; 72591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 726014e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner bool RequiresICE = false; 726186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Error = GE_None; 726214e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType ResType = DecodeTypeFromStr(TypeStr, *this, Error, 726314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE, true); 726486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 726586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 726614e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner 726714e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert(!RequiresICE && "Result of intrinsic cannot be required to be an ICE"); 726814e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner 726986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (TypeStr[0] && TypeStr[0] != '.') { 727014e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType Ty = DecodeTypeFromStr(TypeStr, *this, Error, RequiresICE, true); 727186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 727286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 727386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 727414e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner // If this argument is required to be an IntegerConstantExpression and the 727514e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner // caller cares, fill in the bitmask we return. 727614e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner if (RequiresICE && IntegerConstantArgs) 727714e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner *IntegerConstantArgs |= 1 << ArgTypes.size(); 727814e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner 727986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Do array -> pointer decay. The builtin should use the decayed type. 728086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Ty->isArrayType()) 728186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Ty = getArrayDecayedType(Ty); 72821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 728386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ArgTypes.push_back(Ty); 728486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 728586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 728686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert((TypeStr[0] != '.' || TypeStr[1] == 0) && 728786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "'.' should only occur at end of builtin type list!"); 728886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 728900ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall FunctionType::ExtInfo EI; 729000ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall if (BuiltinInfo.isNoReturn(Id)) EI = EI.withNoReturn(true); 729100ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall 729200ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall bool Variadic = (TypeStr[0] == '.'); 729300ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall 729400ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall // We really shouldn't be making a no-proto type here, especially in C++. 729500ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall if (ArgTypes.empty() && Variadic) 729600ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall return getFunctionNoProtoType(ResType, EI); 7297ce056bcaa1c97b89a4b2de2112c62d060863be2bDouglas Gregor 7298e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI; 729900ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall EPI.ExtInfo = EI; 730000ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall EPI.Variadic = Variadic; 7301e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 7302e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return getFunctionType(ResType, ArgTypes.data(), ArgTypes.size(), EPI); 730386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 7304a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 730590e99a84ddd020e8fda79643748243725a2ed071Argyrios KyrtzidisGVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) { 730690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis GVALinkage External = GVA_StrongExternal; 730790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 730890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis Linkage L = FD->getLinkage(); 730990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (L) { 731090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case NoLinkage: 731190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case InternalLinkage: 731290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case UniqueExternalLinkage: 731390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_Internal; 731490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 731590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case ExternalLinkage: 731690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (FD->getTemplateSpecializationKind()) { 731790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_Undeclared: 731890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitSpecialization: 731990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis External = GVA_StrongExternal; 732090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis break; 732190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 732290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDefinition: 732390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_ExplicitTemplateInstantiation; 732490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 732590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDeclaration: 732690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ImplicitInstantiation: 732790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis External = GVA_TemplateInstantiation; 732890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis break; 732990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 733090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 733190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 733290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (!FD->isInlined()) 733390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return External; 733490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 73354e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().CPlusPlus || FD->hasAttr<GNUInlineAttr>()) { 733690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // GNU or C99 inline semantics. Determine whether this symbol should be 733790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // externally visible. 733890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (FD->isInlineDefinitionExternallyVisible()) 733990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return External; 734090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 734190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // C99 inline semantics, where the symbol is not externally visible. 734290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_C99Inline; 734390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 734490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 734590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // C++0x [temp.explicit]p9: 734690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // [ Note: The intent is that an inline function that is the subject of 734790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // an explicit instantiation declaration will still be implicitly 734890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // instantiated when used so that the body can be considered for 734990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // inlining, but that no out-of-line copy of the inline function would be 735090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // generated in the translation unit. -- end note ] 735190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (FD->getTemplateSpecializationKind() 735290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis == TSK_ExplicitInstantiationDeclaration) 735390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_C99Inline; 735490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 735590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_CXXInline; 735690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis} 735790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 735890e99a84ddd020e8fda79643748243725a2ed071Argyrios KyrtzidisGVALinkage ASTContext::GetGVALinkageForVariable(const VarDecl *VD) { 735990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // If this is a static data member, compute the kind of template 736090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // specialization. Otherwise, this variable is not part of a 736190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // template. 736290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis TemplateSpecializationKind TSK = TSK_Undeclared; 736390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (VD->isStaticDataMember()) 736490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis TSK = VD->getTemplateSpecializationKind(); 736590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 736690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis Linkage L = VD->getLinkage(); 73674e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (L == ExternalLinkage && getLangOpts().CPlusPlus && 736890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis VD->getType()->getLinkage() == UniqueExternalLinkage) 736990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis L = UniqueExternalLinkage; 737090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 737190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (L) { 737290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case NoLinkage: 737390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case InternalLinkage: 737490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case UniqueExternalLinkage: 737590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_Internal; 737690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 737790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case ExternalLinkage: 737890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (TSK) { 737990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_Undeclared: 738090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitSpecialization: 738190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_StrongExternal; 738290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 738390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDeclaration: 738490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis llvm_unreachable("Variable should not be instantiated"); 738590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Fall through to treat this like any other instantiation. 738690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 738790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDefinition: 738890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_ExplicitTemplateInstantiation; 738990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 739090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ImplicitInstantiation: 739190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_TemplateInstantiation; 739290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 739390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 739490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 73957530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid Linkage!"); 739690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis} 739790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 73984ac7c0bb39696e92fd220118fedc484c09a69870Argyrios Kyrtzidisbool ASTContext::DeclMustBeEmitted(const Decl *D) { 739990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 740090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (!VD->isFileVarDecl()) 740190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 7402144b38a7995cbe0928e34fbcc865bb2d2be4f7a3Argyrios Kyrtzidis } else if (!isa<FunctionDecl>(D)) 740390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 740490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 7405ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis // Weak references don't produce any output by themselves. 7406ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis if (D->hasAttr<WeakRefAttr>()) 7407ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis return false; 7408ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis 740990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Aliases and used decls are required. 741090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>()) 741190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 741290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 741390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 741490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Forward declarations aren't required. 741510620eb5164e31208fcbf0437cd79ae535ed0559Sean Hunt if (!FD->doesThisDeclarationHaveABody()) 7416dce67a70a86db8758c926a76fdd980f5369d5746Nick Lewycky return FD->doesDeclarationForceExternallyVisibleDefinition(); 741790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 741890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Constructors and destructors are required. 741990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>()) 742090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 742190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 742290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // The key function for a class is required. 742390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 742490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis const CXXRecordDecl *RD = MD->getParent(); 742590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (MD->isOutOfLine() && RD->isDynamicClass()) { 742690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis const CXXMethodDecl *KeyFunc = getKeyFunction(RD); 742790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (KeyFunc && KeyFunc->getCanonicalDecl() == MD->getCanonicalDecl()) 742890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 742990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 743090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 743190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 743290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis GVALinkage Linkage = GetGVALinkageForFunction(FD); 743390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 743490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // static, static inline, always_inline, and extern inline functions can 743590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // always be deferred. Normal inline functions can be deferred in C99/C++. 743690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Implicit template instantiations can also be deferred in C++. 743790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (Linkage == GVA_Internal || Linkage == GVA_C99Inline || 74383a5aca8112e03814f78906dc5d032287adb272b5Anton Yartsev Linkage == GVA_CXXInline || Linkage == GVA_TemplateInstantiation) 743990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 744090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 744190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 744294da1587f7d584fc61df793229d197969f204cd9Douglas Gregor 744390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis const VarDecl *VD = cast<VarDecl>(D); 744490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis assert(VD->isFileVarDecl() && "Expected file scoped var"); 744590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 7446ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly) 7447ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis return false; 7448ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis 744990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Structs that have non-trivial constructors or destructors are required. 745090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 745190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // FIXME: Handle references. 7452023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt // FIXME: Be more selective about which constructors we care about. 745390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const RecordType *RT = VD->getType()->getAs<RecordType>()) { 745490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl())) { 7455023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt if (RD->hasDefinition() && !(RD->hasTrivialDefaultConstructor() && 7456023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt RD->hasTrivialCopyConstructor() && 7457023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt RD->hasTrivialMoveConstructor() && 7458023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt RD->hasTrivialDestructor())) 745990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 746090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 746190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 746290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 746390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis GVALinkage L = GetGVALinkageForVariable(VD); 746490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (L == GVA_Internal || L == GVA_TemplateInstantiation) { 746590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (!(VD->getInit() && VD->getInit()->HasSideEffects(*this))) 746690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 746790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 746890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 746990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 747090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis} 7471071cc7deffad608165b1ddd5263e8bf181861520Charles Davis 74728f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur IskhodzhanovCallingConv ASTContext::getDefaultCXXMethodCallConv(bool isVariadic) { 7473ee743f903858e337434ac0335f147f4de4ecae05Charles Davis // Pass through to the C++ ABI object 74748f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov return ABI->getDefaultMethodCallConv(isVariadic); 74758f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov} 74768f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov 74778f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur IskhodzhanovCallingConv ASTContext::getCanonicalCallConv(CallingConv CC) const { 74788f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov if (CC == CC_C && !LangOpts.MRTD && getTargetInfo().getCXXABI() != CXXABI_Microsoft) 74798f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov return CC_Default; 74808f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov return CC; 7481ee743f903858e337434ac0335f147f4de4ecae05Charles Davis} 7482ee743f903858e337434ac0335f147f4de4ecae05Charles Davis 74834ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ASTContext::isNearlyEmpty(const CXXRecordDecl *RD) const { 7484dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson // Pass through to the C++ ABI object 7485dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson return ABI->isNearlyEmpty(RD); 7486dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson} 7487dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson 748814110477887e3dc168ffc6c191e72d705051f99ePeter CollingbourneMangleContext *ASTContext::createMangleContext() { 7489bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor switch (Target->getCXXABI()) { 749014110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne case CXXABI_ARM: 749114110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne case CXXABI_Itanium: 749214110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne return createItaniumMangleContext(*this, getDiagnostics()); 749314110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne case CXXABI_Microsoft: 749414110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne return createMicrosoftMangleContext(*this, getDiagnostics()); 749514110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne } 7496b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unsupported ABI"); 749714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne} 749814110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne 7499071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCXXABI::~CXXABI() {} 7500ba29bd25515fbd99e98ba0fedb9d93617b27609eTed Kremenek 7501ba29bd25515fbd99e98ba0fedb9d93617b27609eTed Kremeneksize_t ASTContext::getSideTableAllocatedMemory() const { 75020c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek return ASTRecordLayouts.getMemorySize() 75030c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(ObjCLayouts) 75040c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(KeyFunctions) 75050c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(ObjCImpls) 75060c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(BlockVarCopyInits) 75070c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(DeclAttrs) 75080c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromStaticDataMember) 75090c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromUsingDecl) 75100c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromUsingShadowDecl) 75110c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromUnnamedFieldDecl) 75120c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(OverriddenMethods) 75130c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(Types) 7514af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet + llvm::capacity_in_bytes(VariableArrayTypes) 75150d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet + llvm::capacity_in_bytes(ClassScopeSpecializationPattern); 7516ba29bd25515fbd99e98ba0fedb9d93617b27609eTed Kremenek} 7517d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek 75189e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregorunsigned ASTContext::getLambdaManglingNumber(CXXMethodDecl *CallOperator) { 75199e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor CXXRecordDecl *Lambda = CallOperator->getParent(); 75209e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor return LambdaMangleContexts[Lambda->getDeclContext()] 75219e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor .getManglingNumber(CallOperator); 75229e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor} 75239e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor 75249e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor 7525d211cb709510fbe7e75167b9feee0050851d001aTed Kremenekvoid ASTContext::setParameterIndex(const ParmVarDecl *D, unsigned int index) { 7526d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek ParamIndices[D] = index; 7527d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek} 7528d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek 7529d211cb709510fbe7e75167b9feee0050851d001aTed Kremenekunsigned ASTContext::getParameterIndex(const ParmVarDecl *D) const { 7530d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek ParameterIndexTable::const_iterator I = ParamIndices.find(D); 7531d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek assert(I != ParamIndices.end() && 7532d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek "ParmIndices lacks entry set by ParmVarDecl"); 7533d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek return I->second; 7534d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek} 7535