ASTContext.cpp revision b9d0b76e42fd2d4cdfd135220302458d03ad09fe
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" 168d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko#include "clang/AST/CommentLexer.h" 178d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko#include "clang/AST/CommentSema.h" 188d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko#include "clang/AST/CommentParser.h" 1949aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis#include "clang/AST/DeclCXX.h" 20980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/DeclObjC.h" 21aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 22b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#include "clang/AST/TypeLoc.h" 23e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar#include "clang/AST/Expr.h" 24ea1471e0e967548c596a71469702f8846dbaf3c0John McCall#include "clang/AST/ExprCXX.h" 252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/ExternalASTSource.h" 267b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis#include "clang/AST/ASTMutationListener.h" 2719cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h" 2814110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne#include "clang/AST/Mangle.h" 291b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 30a9376d470ccb0eac74fe09a6b2a18a890f1d17c4Chris Lattner#include "clang/Basic/SourceManager.h" 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/TargetInfo.h" 32f5942a44880be26878592eb052b737579349411eBenjamin Kramer#include "llvm/ADT/SmallString.h" 3385f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson#include "llvm/ADT/StringExtras.h" 346fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman#include "llvm/Support/MathExtras.h" 35f5942a44880be26878592eb052b737579349411eBenjamin Kramer#include "llvm/Support/raw_ostream.h" 360c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek#include "llvm/Support/Capacity.h" 37071cc7deffad608165b1ddd5263e8bf181861520Charles Davis#include "CXXABI.h" 382636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis#include <map> 3929445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 421827403a7138946305c0058f262e02b595cf882fDouglas Gregorunsigned ASTContext::NumImplicitDefaultConstructors; 431827403a7138946305c0058f262e02b595cf882fDouglas Gregorunsigned ASTContext::NumImplicitDefaultConstructorsDeclared; 44225843186e3972ce798d3de00f86da9008b15a0eDouglas Gregorunsigned ASTContext::NumImplicitCopyConstructors; 45225843186e3972ce798d3de00f86da9008b15a0eDouglas Gregorunsigned ASTContext::NumImplicitCopyConstructorsDeclared; 46ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveConstructors; 47ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveConstructorsDeclared; 48a376d10acfacf19d6dfa41069f7929739a18dd7aDouglas Gregorunsigned ASTContext::NumImplicitCopyAssignmentOperators; 49a376d10acfacf19d6dfa41069f7929739a18dd7aDouglas Gregorunsigned ASTContext::NumImplicitCopyAssignmentOperatorsDeclared; 50ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveAssignmentOperators; 51ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveAssignmentOperatorsDeclared; 524923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregorunsigned ASTContext::NumImplicitDestructors; 534923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregorunsigned ASTContext::NumImplicitDestructorsDeclared; 544923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregor 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerenum FloatingRank { 56aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov HalfRank, FloatRank, DoubleRank, LongDoubleRank 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 59a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri GribenkoRawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { 60aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (!CommentsLoaded && ExternalSource) { 61aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko ExternalSource->ReadComments(); 62aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko CommentsLoaded = true; 63aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 64aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 65aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko assert(D); 66aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 67c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko // User can not attach documentation to implicit declarations. 68c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko if (D->isImplicit()) 69c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko return NULL; 70c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko 71aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // TODO: handle comments for function parameters properly. 72aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (isa<ParmVarDecl>(D)) 73aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 74aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 75811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko ArrayRef<RawComment *> RawComments = Comments.getComments(); 76aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 77aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // If there are no comments anywhere, we won't find anything. 78aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (RawComments.empty()) 79aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 80aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 81abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // Find declaration location. 82abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // For Objective-C declarations we generally don't expect to have multiple 83abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // declarators, thus use declaration starting location as the "declaration 84abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // location". 85abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // For all other declarations multiple declarators are used quite frequently, 86abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // so we use the location of the identifier as the "declaration location". 87abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko SourceLocation DeclLoc; 88abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko if (isa<ObjCMethodDecl>(D) || isa<ObjCContainerDecl>(D) || 89abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko isa<ObjCPropertyDecl>(D)) 90abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko DeclLoc = D->getLocStart(); 91abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko else 92abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko DeclLoc = D->getLocation(); 93abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko 94aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // If the declaration doesn't map directly to a location in a file, we 95aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // can't find the comment. 96aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (DeclLoc.isInvalid() || !DeclLoc.isFileID()) 97aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 98aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 99aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Find the comment that occurs just after this declaration. 100a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko ArrayRef<RawComment *>::iterator Comment; 101a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko { 102a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // When searching for comments during parsing, the comment we are looking 103a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // for is usually among the last two comments we parsed -- check them 104a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // first. 105a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko RawComment CommentAtDeclLoc(SourceMgr, SourceRange(DeclLoc)); 106a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko BeforeThanCompare<RawComment> Compare(SourceMgr); 107a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko ArrayRef<RawComment *>::iterator MaybeBeforeDecl = RawComments.end() - 1; 108a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko bool Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc); 109a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko if (!Found && RawComments.size() >= 2) { 110a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko MaybeBeforeDecl--; 111a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc); 112a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } 113a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko 114a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko if (Found) { 115a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko Comment = MaybeBeforeDecl + 1; 116a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko assert(Comment == std::lower_bound(RawComments.begin(), RawComments.end(), 117a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko &CommentAtDeclLoc, Compare)); 118a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } else { 119a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // Slow path. 120a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko Comment = std::lower_bound(RawComments.begin(), RawComments.end(), 121a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko &CommentAtDeclLoc, Compare); 122a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } 123a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } 124aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 125aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Decompose the location for the declaration and find the beginning of the 126aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // file buffer. 127aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko std::pair<FileID, unsigned> DeclLocDecomp = SourceMgr.getDecomposedLoc(DeclLoc); 128aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 129aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // First check whether we have a trailing comment. 130aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (Comment != RawComments.end() && 131811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko (*Comment)->isDocumentation() && (*Comment)->isTrailingComment() && 1329c00676f2393335dc60c61faf944d4f8f622fac6Dmitri Gribenko (isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || isa<VarDecl>(D))) { 133aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko std::pair<FileID, unsigned> CommentBeginDecomp 134811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getBegin()); 135aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Check that Doxygen trailing comment comes after the declaration, starts 136aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // on the same line and in the same file as the declaration. 137aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (DeclLocDecomp.first == CommentBeginDecomp.first && 138aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko SourceMgr.getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second) 139aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko == SourceMgr.getLineNumber(CommentBeginDecomp.first, 140aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko CommentBeginDecomp.second)) { 141811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko return *Comment; 142aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 143aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 144aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 145aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // The comment just after the declaration was not a trailing comment. 146aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Let's look at the previous comment. 147aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (Comment == RawComments.begin()) 148aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 149aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko --Comment; 150aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 151aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Check that we actually have a non-member Doxygen comment. 152811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko if (!(*Comment)->isDocumentation() || (*Comment)->isTrailingComment()) 153aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 154aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 155aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Decompose the end of the comment. 156aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko std::pair<FileID, unsigned> CommentEndDecomp 157811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getEnd()); 158aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 159aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // If the comment and the declaration aren't in the same file, then they 160aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // aren't related. 161aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (DeclLocDecomp.first != CommentEndDecomp.first) 162aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 163aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 164aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Get the corresponding buffer. 165aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko bool Invalid = false; 166aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko const char *Buffer = SourceMgr.getBufferData(DeclLocDecomp.first, 167aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko &Invalid).data(); 168aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (Invalid) 169aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 170aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 171aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Extract text between the comment and declaration. 172aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko StringRef Text(Buffer + CommentEndDecomp.second, 173aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko DeclLocDecomp.second - CommentEndDecomp.second); 174aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 1758bdb58a7835a9a90dd9b9791fccf269cbc1dcef3Dmitri Gribenko // There should be no other declarations or preprocessor directives between 1768bdb58a7835a9a90dd9b9791fccf269cbc1dcef3Dmitri Gribenko // comment and declaration. 177abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko if (Text.find_first_of(",;{}#@") != StringRef::npos) 178aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 179aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 180811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko return *Comment; 181aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko} 182aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 183aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenkoconst RawComment *ASTContext::getRawCommentForDecl(const Decl *D) const { 184aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Check whether we have cached a comment string for this declaration 185aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // already. 1868d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko llvm::DenseMap<const Decl *, RawAndParsedComment>::iterator Pos 187aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko = DeclComments.find(D); 1888d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko if (Pos != DeclComments.end()) { 1898d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko RawAndParsedComment C = Pos->second; 1908d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko return C.first; 1918d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko } 192aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 193a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri Gribenko RawComment *RC = getRawCommentForDeclNoCache(D); 1948376f5934a18b950ac7323d8a38ed231623010faDmitri Gribenko // If we found a comment, it should be a documentation comment. 1958376f5934a18b950ac7323d8a38ed231623010faDmitri Gribenko assert(!RC || RC->isDocumentation()); 1969bf997e63d4e4004588b374e702a5e64da5ebb49Dmitri Gribenko DeclComments[D] = 1979bf997e63d4e4004588b374e702a5e64da5ebb49Dmitri Gribenko RawAndParsedComment(RC, static_cast<comments::FullComment *>(NULL)); 198a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri Gribenko if (RC) 199a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri Gribenko RC->setAttached(); 200aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return RC; 201aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko} 202aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 2038d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenkocomments::FullComment *ASTContext::getCommentForDecl(const Decl *D) const { 2048d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko llvm::DenseMap<const Decl *, RawAndParsedComment>::iterator Pos 2058d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko = DeclComments.find(D); 2068d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko const RawComment *RC; 2078d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko if (Pos != DeclComments.end()) { 2088d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko RawAndParsedComment C = Pos->second; 2098d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko if (comments::FullComment *FC = C.second) 2108d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko return FC; 2118d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko RC = C.first; 2128d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko } else 2138d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko RC = getRawCommentForDecl(D); 2148d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko 2158d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko if (!RC) 2168d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko return NULL; 2178d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko 2188d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko const StringRef RawText = RC->getRawText(SourceMgr); 2198d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko comments::Lexer L(RC->getSourceRange().getBegin(), comments::CommentOptions(), 2208d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko RawText.begin(), RawText.end()); 2218d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko 222a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri Gribenko comments::Sema S(getAllocator(), getSourceManager(), getDiagnostics()); 223a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri Gribenko S.setDecl(D); 224a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri Gribenko comments::Parser P(L, S, getAllocator(), getSourceManager(), 225a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri Gribenko getDiagnostics()); 2268d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko 2278d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko comments::FullComment *FC = P.parseFullComment(); 2288d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko DeclComments[D].second = FC; 2298d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko return FC; 2308d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko} 2318d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko 2323e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregorvoid 2333e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas GregorASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &ID, 2343e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTemplateParmDecl *Parm) { 2353e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(Parm->getDepth()); 2363e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(Parm->getPosition()); 23761c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor ID.AddBoolean(Parm->isParameterPack()); 2383e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 2393e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateParameterList *Params = Parm->getTemplateParameters(); 2403e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(Params->size()); 2413e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor for (TemplateParameterList::const_iterator P = Params->begin(), 2423e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor PEnd = Params->end(); 2433e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor P != PEnd; ++P) { 2443e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) { 2453e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(0); 2463e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddBoolean(TTP->isParameterPack()); 2473e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor continue; 2483e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 2493e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 2503e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) { 2513e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(1); 25261c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor ID.AddBoolean(NTTP->isParameterPack()); 2539e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman ID.AddPointer(NTTP->getType().getCanonicalType().getAsOpaquePtr()); 2546952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor if (NTTP->isExpandedParameterPack()) { 2556952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ID.AddBoolean(true); 2566952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ID.AddInteger(NTTP->getNumExpansionTypes()); 2579e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman for (unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) { 2589e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman QualType T = NTTP->getExpansionType(I); 2599e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman ID.AddPointer(T.getCanonicalType().getAsOpaquePtr()); 2609e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman } 2616952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } else 2626952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ID.AddBoolean(false); 2633e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor continue; 2643e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 2653e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 2663e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P); 2673e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(2); 2683e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Profile(ID, TTP); 2693e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 2703e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor} 2713e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 2723e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas GregorTemplateTemplateParmDecl * 2733e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas GregorASTContext::getCanonicalTemplateTemplateParmDecl( 2744ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad TemplateTemplateParmDecl *TTP) const { 2753e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Check if we already have a canonical template template parameter. 2763e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor llvm::FoldingSetNodeID ID; 2773e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonicalTemplateTemplateParm::Profile(ID, TTP); 2783e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor void *InsertPos = 0; 2793e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonicalTemplateTemplateParm *Canonical 2803e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); 2813e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (Canonical) 2823e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor return Canonical->getParam(); 2833e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 2843e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Build a canonical template parameter list. 2853e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateParameterList *Params = TTP->getTemplateParameters(); 2865f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<NamedDecl *, 4> CanonParams; 2873e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.reserve(Params->size()); 2883e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor for (TemplateParameterList::const_iterator P = Params->begin(), 2893e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor PEnd = Params->end(); 2903e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor P != PEnd; ++P) { 2913e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) 2923e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.push_back( 2933e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTypeParmDecl::Create(*this, getTranslationUnitDecl(), 294344577e6b58f42d18dc8118c8903b49a85dc005eAbramo Bagnara SourceLocation(), 295344577e6b58f42d18dc8118c8903b49a85dc005eAbramo Bagnara SourceLocation(), 296344577e6b58f42d18dc8118c8903b49a85dc005eAbramo Bagnara TTP->getDepth(), 2973e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TTP->getIndex(), 0, false, 2983e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TTP->isParameterPack())); 2993e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor else if (NonTypeTemplateParmDecl *NTTP 3006952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor = dyn_cast<NonTypeTemplateParmDecl>(*P)) { 3016952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor QualType T = getCanonicalType(NTTP->getType()); 3026952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(T); 3036952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NonTypeTemplateParmDecl *Param; 3046952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor if (NTTP->isExpandedParameterPack()) { 3055f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 2> ExpandedTypes; 3065f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TypeSourceInfo *, 2> ExpandedTInfos; 3076952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor for (unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) { 3086952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTypes.push_back(getCanonicalType(NTTP->getExpansionType(I))); 3096952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTInfos.push_back( 3106952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor getTrivialTypeSourceInfo(ExpandedTypes.back())); 3116952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } 3126952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor 3136952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor Param = NonTypeTemplateParmDecl::Create(*this, getTranslationUnitDecl(), 314ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 315ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 3166952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getDepth(), 3176952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getPosition(), 0, 3186952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor T, 3196952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor TInfo, 3206952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTypes.data(), 3216952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTypes.size(), 3226952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTInfos.data()); 3236952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } else { 3246952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor Param = NonTypeTemplateParmDecl::Create(*this, getTranslationUnitDecl(), 325ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 326ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 3276952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getDepth(), 3286952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getPosition(), 0, 3296952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor T, 3306952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->isParameterPack(), 3316952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor TInfo); 3326952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } 3336952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor CanonParams.push_back(Param); 3346952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor 3356952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } else 3363e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.push_back(getCanonicalTemplateTemplateParmDecl( 3373e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor cast<TemplateTemplateParmDecl>(*P))); 3383e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 3393e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 3403e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTemplateParmDecl *CanonTTP 3413e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor = TemplateTemplateParmDecl::Create(*this, getTranslationUnitDecl(), 3423e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor SourceLocation(), TTP->getDepth(), 34361c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor TTP->getPosition(), 34461c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor TTP->isParameterPack(), 34561c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor 0, 3463e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateParameterList::Create(*this, SourceLocation(), 3473e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor SourceLocation(), 3483e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.data(), 3493e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.size(), 3503e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor SourceLocation())); 3513e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 3523e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Get the new insert position for the node we care about. 3533e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); 3543e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor assert(Canonical == 0 && "Shouldn't be in the map!"); 3553e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor (void)Canonical; 3563e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 3573e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Create the canonical template template parameter entry. 3583e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Canonical = new (*this) CanonicalTemplateTemplateParm(CanonTTP); 3593e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonTemplateTemplateParms.InsertNode(Canonical, InsertPos); 3603e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor return CanonTTP; 3613e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor} 3623e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 363071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCXXABI *ASTContext::createCXXABI(const TargetInfo &T) { 364ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall if (!LangOpts.CPlusPlus) return 0; 365ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall 36620cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis switch (T.getCXXABI()) { 367ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall case CXXABI_ARM: 368ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall return CreateARMCXXABI(*this); 369ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall case CXXABI_Itanium: 370071cc7deffad608165b1ddd5263e8bf181861520Charles Davis return CreateItaniumCXXABI(*this); 37120cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis case CXXABI_Microsoft: 37220cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis return CreateMicrosoftCXXABI(*this); 37320cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis } 3747530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid CXXABI type!"); 375071cc7deffad608165b1ddd5263e8bf181861520Charles Davis} 376071cc7deffad608165b1ddd5263e8bf181861520Charles Davis 377bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregorstatic const LangAS::Map *getAddressSpaceMap(const TargetInfo &T, 378207f4d8543529221932af82836016a2ef066c917Peter Collingbourne const LangOptions &LOpts) { 379207f4d8543529221932af82836016a2ef066c917Peter Collingbourne if (LOpts.FakeAddressSpaceMap) { 380207f4d8543529221932af82836016a2ef066c917Peter Collingbourne // The fake address space map must have a distinct entry for each 381207f4d8543529221932af82836016a2ef066c917Peter Collingbourne // language-specific address space. 382207f4d8543529221932af82836016a2ef066c917Peter Collingbourne static const unsigned FakeAddrSpaceMap[] = { 383207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 1, // opencl_global 384207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 2, // opencl_local 3854dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 3, // opencl_constant 3864dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 4, // cuda_device 3874dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 5, // cuda_constant 3884dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 6 // cuda_shared 389207f4d8543529221932af82836016a2ef066c917Peter Collingbourne }; 390bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return &FakeAddrSpaceMap; 391207f4d8543529221932af82836016a2ef066c917Peter Collingbourne } else { 392bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return &T.getAddressSpaceMap(); 393207f4d8543529221932af82836016a2ef066c917Peter Collingbourne } 394207f4d8543529221932af82836016a2ef066c917Peter Collingbourne} 395207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 3963e3cd93b2fd9644e970c389e715c13883faf68b6Douglas GregorASTContext::ASTContext(LangOptions& LOpts, SourceManager &SM, 397bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor const TargetInfo *t, 398e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar IdentifierTable &idents, SelectorTable &sels, 3991b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner Builtin::Context &builtins, 400bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor unsigned size_reserve, 401bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor bool DelayInitialization) 402bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor : FunctionProtoTypes(this_()), 403bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor TemplateSpecializationTypes(this_()), 404bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor DependentTemplateSpecializationTypes(this_()), 405bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor SubstTemplateTemplateParmPacks(this_()), 406bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor GlobalNestedNameSpecifier(0), 407bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Int128Decl(0), UInt128Decl(0), 408c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge BuiltinVaListDecl(0), 409a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor ObjCIdDecl(0), ObjCSelDecl(0), ObjCClassDecl(0), ObjCProtocolClassDecl(0), 410e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor CFConstantStringTypeDecl(0), ObjCInstanceTypeDecl(0), 411bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor FILEDecl(0), 412e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola jmp_bufDecl(0), sigjmp_bufDecl(0), ucontext_tDecl(0), 413e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola BlockDescriptorType(0), BlockDescriptorExtendedType(0), 414e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola cudaConfigureCallDecl(0), 415e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor NullTypeSourceInfo(QualType()), 416e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor FirstLocalImport(), LastLocalImport(), 417bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor SourceMgr(SM), LangOpts(LOpts), 41830c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor AddrSpaceMap(0), Target(t), PrintingPolicy(LOpts), 419bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Idents(idents), Selectors(sels), 420bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor BuiltinInfo(builtins), 421bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor DeclarationNames(*this), 42230c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor ExternalSource(0), Listener(0), 423aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko Comments(SM), CommentsLoaded(false), 424bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor LastSDM(0, 0), 425bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor UniqueBlockByRefTypeID(0) 426bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor{ 4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (size_reserve > 0) Types.reserve(size_reserve); 428e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar TUDecl = TranslationUnitDecl::Create(*this); 429bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor 430bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor if (!DelayInitialization) { 431bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor assert(t && "No target supplied for ASTContext initialization"); 432bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor InitBuiltinTypes(*t); 433bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor } 434e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar} 435e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerASTContext::~ASTContext() { 4373478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek // Release the DenseMaps associated with DeclContext objects. 4383478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek // FIXME: Is this the ideal solution? 4393478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek ReleaseDeclContextMaps(); 4407d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 44163fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor // Call all of the deallocation functions. 44263fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor for (unsigned I = 0, N = Deallocations.size(); I != N; ++I) 44363fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor Deallocations[I].first(Deallocations[I].second); 4440054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor 445dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek // ASTRecordLayout objects in ASTRecordLayouts must always be destroyed 44663fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor // because they can contain DenseMaps. 44763fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor for (llvm::DenseMap<const ObjCContainerDecl*, 44863fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor const ASTRecordLayout*>::iterator 44963fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) 45063fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor // Increment in loop to prevent using deallocated memory. 45163fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second)) 45263fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor R->Destroy(*this); 45363fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor 454dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator 455dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { 456dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek // Increment in loop to prevent using deallocated memory. 457dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second)) 458dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek R->Destroy(*this); 459dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek } 4606320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 4616320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor for (llvm::DenseMap<const Decl*, AttrVec*>::iterator A = DeclAttrs.begin(), 4626320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor AEnd = DeclAttrs.end(); 4636320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor A != AEnd; ++A) 4646320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor A->second->~AttrVec(); 4656320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor} 466ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor 4670054531488928a424666ac11fcdc6bcc5112de52Douglas Gregorvoid ASTContext::AddDeallocation(void (*Callback)(void*), void *Data) { 4680054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor Deallocations.push_back(std::make_pair(Callback, Data)); 4690054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor} 4700054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor 4711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 4726f42b62b6194f53bcbc349f5d17388e1936535d7Dylan NoblesmithASTContext::setExternalSource(OwningPtr<ExternalASTSource> &Source) { 4732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource.reset(Source.take()); 4742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 4752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencervoid ASTContext::PrintStats() const { 477cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << "\n*** AST Context Stats:\n"; 478cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << " " << Types.size() << " types total.\n"; 4797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 480dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned counts[] = { 4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump#define TYPE(Name, Parent) 0, 482dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 483dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 484dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor 0 // Extra 485dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor }; 486c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0, e = Types.size(); i != e; ++i) { 4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *T = Types[i]; 489dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor counts[(unsigned)T->getTypeClass()]++; 4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 492dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned Idx = 0; 493dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned TotalBytes = 0; 494dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define TYPE(Name, Parent) \ 495dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor if (counts[Idx]) \ 496cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << " " << counts[Idx] << " " << #Name \ 497cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " types\n"; \ 498dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor TotalBytes += counts[Idx] * sizeof(Name##Type); \ 499dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor ++Idx; 500dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 501dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 5021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 503cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << "Total bytes = " << TotalBytes << "\n"; 504cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth 5054923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregor // Implicit special member functions. 506cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitDefaultConstructorsDeclared << "/" 507cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitDefaultConstructors 508cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit default constructors created\n"; 509cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitCopyConstructorsDeclared << "/" 510cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitCopyConstructors 511cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit copy constructors created\n"; 5124e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 513cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitMoveConstructorsDeclared << "/" 514cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitMoveConstructors 515cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit move constructors created\n"; 516cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitCopyAssignmentOperatorsDeclared << "/" 517cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitCopyAssignmentOperators 518cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit copy assignment operators created\n"; 5194e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 520cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitMoveAssignmentOperatorsDeclared << "/" 521cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitMoveAssignmentOperators 522cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit move assignment operators created\n"; 523cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitDestructorsDeclared << "/" 524cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitDestructors 525cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit destructors created\n"; 526cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth 5272cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor if (ExternalSource.get()) { 528cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << "\n"; 5292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource->PrintStats(); 5302cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 531cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth 53263fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor BumpAlloc.PrintStats(); 5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 535772eeaefef2c883aabe35caf4543e7e32d290183Douglas GregorTypedefDecl *ASTContext::getInt128Decl() const { 536772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor if (!Int128Decl) { 537772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(Int128Ty); 538772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor Int128Decl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 539772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor getTranslationUnitDecl(), 540772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 541772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 542772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor &Idents.get("__int128_t"), 543772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TInfo); 544772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor } 545772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor 546772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor return Int128Decl; 547772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor} 548772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor 549772eeaefef2c883aabe35caf4543e7e32d290183Douglas GregorTypedefDecl *ASTContext::getUInt128Decl() const { 550772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor if (!UInt128Decl) { 551772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(UnsignedInt128Ty); 552772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor UInt128Decl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 553772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor getTranslationUnitDecl(), 554772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 555772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 556772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor &Idents.get("__uint128_t"), 557772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TInfo); 558772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor } 559772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor 560772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor return UInt128Decl; 561772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor} 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 563e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCallvoid ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) { 5646b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall BuiltinType *Ty = new (*this, TypeAlignment) BuiltinType(K); 565e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCall R = CanQualType::CreateUnsafe(QualType(Ty, 0)); 5666b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Types.push_back(Ty); 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 569bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregorvoid ASTContext::InitBuiltinTypes(const TargetInfo &Target) { 570bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor assert((!this->Target || this->Target == &Target) && 571bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor "Incorrect target reinitialization"); 5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(VoidTy.isNull() && "Context reinitialized?"); 5731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 574bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor this->Target = &Target; 575bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor 576bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor ABI.reset(createCXXABI(Target)); 577bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor AddrSpaceMap = getAddressSpaceMap(Target, LangOpts); 578bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor 5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p19. 5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(VoidTy, BuiltinType::Void); 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p2. 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(BoolTy, BuiltinType::Bool); 5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p3. 58515b91764d08e886391c865c4a444d7b51141c284Eli Friedman if (LangOpts.CharIsSigned) 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_S); 5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_U); 5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p4. 5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(SignedCharTy, BuiltinType::SChar); 5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(ShortTy, BuiltinType::Short); 5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(IntTy, BuiltinType::Int); 5935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongTy, BuiltinType::Long); 5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongLongTy, BuiltinType::LongLong); 5951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p6. 5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedCharTy, BuiltinType::UChar); 5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedShortTy, BuiltinType::UShort); 5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedIntTy, BuiltinType::UInt); 6005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongTy, BuiltinType::ULong); 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongLongTy, BuiltinType::ULongLong); 6021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p10. 6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(FloatTy, BuiltinType::Float); 6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(DoubleTy, BuiltinType::Double); 6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongDoubleTy, BuiltinType::LongDouble); 60764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 6082df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner // GNU extension, 128-bit integers. 6092df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(Int128Ty, BuiltinType::Int128); 6102df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(UnsignedInt128Ty, BuiltinType::UInt128); 6112df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner 6123f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner if (LangOpts.CPlusPlus) { // C++ 3.9.1p5 613d3d77cd138f8e830f6547b6f83fcd5721ccf5f5dEli Friedman if (TargetInfo::isTypeSigned(Target.getWCharType())) 6143f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner InitBuiltinType(WCharTy, BuiltinType::WChar_S); 6153f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner else // -fshort-wchar makes wchar_t be unsigned. 6163f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner InitBuiltinType(WCharTy, BuiltinType::WChar_U); 6173f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner } else // C99 6183a2503227c3db04a3619735127483263c1075ef7Chris Lattner WCharTy = getFromTargetType(Target.getWCharType()); 61964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 620392da48160bd92ceb486792780467cbfdb2d0e8cJames Molloy WIntTy = getFromTargetType(Target.getWIntType()); 621392da48160bd92ceb486792780467cbfdb2d0e8cJames Molloy 622f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 623f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char16Ty, BuiltinType::Char16); 624f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 625f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16Ty = getFromTargetType(Target.getChar16Type()); 626f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 627f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 628f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char32Ty, BuiltinType::Char32); 629f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 630f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32Ty = getFromTargetType(Target.getChar32Type()); 631f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 632898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Placeholder type for type-dependent expressions whose type is 633898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // completely unknown. No code should ever check a type against 634898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // DependentTy and users should never see it; however, it is here to 635898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // help diagnose failures to properly check for type-dependent 636898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // expressions. 637898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor InitBuiltinType(DependentTy, BuiltinType::Dependent); 6388e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 6392a984cad5ac3fdceeff2bd99daa7b90979313475John McCall // Placeholder type for functions. 6402a984cad5ac3fdceeff2bd99daa7b90979313475John McCall InitBuiltinType(OverloadTy, BuiltinType::Overload); 6412a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 642864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // Placeholder type for bound members. 643864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall InitBuiltinType(BoundMemberTy, BuiltinType::BoundMember); 644864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 6453c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // Placeholder type for pseudo-objects. 6463c3b7f90a863af43fa63043d396553ecf205351cJohn McCall InitBuiltinType(PseudoObjectTy, BuiltinType::PseudoObject); 6473c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 6481de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall // "any" type; useful for debugger-like clients. 6491de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall InitBuiltinType(UnknownAnyTy, BuiltinType::UnknownAny); 6501de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall 6510ddaeb9b031070ec64afe92d9892875ac44df427John McCall // Placeholder type for unbridged ARC casts. 6520ddaeb9b031070ec64afe92d9892875ac44df427John McCall InitBuiltinType(ARCUnbridgedCastTy, BuiltinType::ARCUnbridgedCast); 6530ddaeb9b031070ec64afe92d9892875ac44df427John McCall 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p11. 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FloatComplexTy = getComplexType(FloatTy); 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DoubleComplexTy = getComplexType(DoubleTy); 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongDoubleComplexTy = getComplexType(LongDoubleTy); 6588e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 65913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian // Builtin types for 'id', 'Class', and 'SEL'. 660de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId); 661de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass); 66213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel); 663ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 664ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Builtin type for __objc_yes and __objc_no 66593a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ? 66693a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian SignedCharTy : BoolTy); 667ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 668a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = QualType(); 6691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // void * type 67133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian VoidPtrTy = getPointerType(VoidTy); 6726e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 6736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // nullptr type (C++0x 2.14.7) 6746e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl InitBuiltinType(NullPtrTy, BuiltinType::NullPtr); 675aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov 676aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov // half type (OpenCL 6.1.1.1) / ARM NEON __fp16 677aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov InitBuiltinType(HalfTy, BuiltinType::Half); 678fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge 679fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge // Builtin type used to help define __builtin_va_list. 680fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge VaListTagTy = QualType(); 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 683d6471f7c1921c7802804ce3ff6fe9768310f72b9David BlaikieDiagnosticsEngine &ASTContext::getDiagnostics() const { 68478a916ec5ff5b66adec3c499e1b9af7b87668309Argyrios Kyrtzidis return SourceMgr.getDiagnostics(); 68578a916ec5ff5b66adec3c499e1b9af7b87668309Argyrios Kyrtzidis} 68678a916ec5ff5b66adec3c499e1b9af7b87668309Argyrios Kyrtzidis 6876320064d0c60fa8683f5623881c9394fd4aa7689Douglas GregorAttrVec& ASTContext::getDeclAttrs(const Decl *D) { 6886320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor AttrVec *&Result = DeclAttrs[D]; 6896320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor if (!Result) { 6906320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor void *Mem = Allocate(sizeof(AttrVec)); 6916320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor Result = new (Mem) AttrVec; 6926320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor } 6936320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 6946320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor return *Result; 6956320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor} 6966320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 6976320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor/// \brief Erase the attributes corresponding to the given declaration. 6986320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregorvoid ASTContext::eraseDeclAttrs(const Decl *D) { 6996320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor llvm::DenseMap<const Decl*, AttrVec*>::iterator Pos = DeclAttrs.find(D); 7006320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor if (Pos != DeclAttrs.end()) { 7016320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor Pos->second->~AttrVec(); 7026320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor DeclAttrs.erase(Pos); 7036320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor } 7046320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor} 7056320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 706251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas GregorMemberSpecializationInfo * 707663b5a0be7261c29bc4c526a71cffcfa02d4153eDouglas GregorASTContext::getInstantiatedFromStaticDataMember(const VarDecl *Var) { 7087caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Var->isStaticDataMember() && "Not a static data member"); 709663b5a0be7261c29bc4c526a71cffcfa02d4153eDouglas Gregor llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *>::iterator Pos 7107caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor = InstantiatedFromStaticDataMember.find(Var); 7117caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor if (Pos == InstantiatedFromStaticDataMember.end()) 7127caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return 0; 7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7147caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return Pos->second; 7157caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 7167caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 7171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 718251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas GregorASTContext::setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, 7199421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis TemplateSpecializationKind TSK, 7209421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis SourceLocation PointOfInstantiation) { 7217caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Inst->isStaticDataMember() && "Not a static data member"); 7227caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Tmpl->isStaticDataMember() && "Not a static data member"); 7237caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(!InstantiatedFromStaticDataMember[Inst] && 7247caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor "Already noted what static data member was instantiated from"); 725251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor InstantiatedFromStaticDataMember[Inst] 7269421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis = new (*this) MemberSpecializationInfo(Tmpl, TSK, PointOfInstantiation); 7277caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 7287caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 729af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois PichetFunctionDecl *ASTContext::getClassScopeSpecializationPattern( 730af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet const FunctionDecl *FD){ 731af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet assert(FD && "Specialization is 0"); 732af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet llvm::DenseMap<const FunctionDecl*, FunctionDecl *>::const_iterator Pos 7330d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet = ClassScopeSpecializationPattern.find(FD); 7340d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet if (Pos == ClassScopeSpecializationPattern.end()) 735af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet return 0; 736af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet 737af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet return Pos->second; 738af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet} 739af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet 740af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichetvoid ASTContext::setClassScopeSpecializationPattern(FunctionDecl *FD, 741af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet FunctionDecl *Pattern) { 742af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet assert(FD && "Specialization is 0"); 743af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet assert(Pattern && "Class scope specialization pattern is 0"); 7440d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet ClassScopeSpecializationPattern[FD] = Pattern; 745af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet} 746af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet 7477ba107a1863ddfa1664555854f0d7bdb3c491c92John McCallNamedDecl * 748ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::getInstantiatedFromUsingDecl(UsingDecl *UUD) { 7497ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall llvm::DenseMap<UsingDecl *, NamedDecl *>::const_iterator Pos 750ed97649e9574b9d854fa4d6109c9333ae0993554John McCall = InstantiatedFromUsingDecl.find(UUD); 751ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Pos == InstantiatedFromUsingDecl.end()) 7520d8df780aef1acda5962347a32591efc629b6748Anders Carlsson return 0; 7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7540d8df780aef1acda5962347a32591efc629b6748Anders Carlsson return Pos->second; 7550d8df780aef1acda5962347a32591efc629b6748Anders Carlsson} 7560d8df780aef1acda5962347a32591efc629b6748Anders Carlsson 7570d8df780aef1acda5962347a32591efc629b6748Anders Carlssonvoid 758ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern) { 759ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert((isa<UsingDecl>(Pattern) || 760ed97649e9574b9d854fa4d6109c9333ae0993554John McCall isa<UnresolvedUsingValueDecl>(Pattern) || 761ed97649e9574b9d854fa4d6109c9333ae0993554John McCall isa<UnresolvedUsingTypenameDecl>(Pattern)) && 762ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "pattern decl is not a using decl"); 763ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(!InstantiatedFromUsingDecl[Inst] && "pattern already exists"); 764ed97649e9574b9d854fa4d6109c9333ae0993554John McCall InstantiatedFromUsingDecl[Inst] = Pattern; 765ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 766ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 767ed97649e9574b9d854fa4d6109c9333ae0993554John McCallUsingShadowDecl * 768ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst) { 769ed97649e9574b9d854fa4d6109c9333ae0993554John McCall llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>::const_iterator Pos 770ed97649e9574b9d854fa4d6109c9333ae0993554John McCall = InstantiatedFromUsingShadowDecl.find(Inst); 771ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Pos == InstantiatedFromUsingShadowDecl.end()) 772ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return 0; 773ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 774ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Pos->second; 775ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 776ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 777ed97649e9574b9d854fa4d6109c9333ae0993554John McCallvoid 778ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, 779ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingShadowDecl *Pattern) { 780ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(!InstantiatedFromUsingShadowDecl[Inst] && "pattern already exists"); 781ed97649e9574b9d854fa4d6109c9333ae0993554John McCall InstantiatedFromUsingShadowDecl[Inst] = Pattern; 7820d8df780aef1acda5962347a32591efc629b6748Anders Carlsson} 7830d8df780aef1acda5962347a32591efc629b6748Anders Carlsson 784d8b285fee4471f393da8ee30f552ceacdc362afaAnders CarlssonFieldDecl *ASTContext::getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field) { 785d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson llvm::DenseMap<FieldDecl *, FieldDecl *>::iterator Pos 786d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson = InstantiatedFromUnnamedFieldDecl.find(Field); 787d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (Pos == InstantiatedFromUnnamedFieldDecl.end()) 788d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return 0; 7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 790d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return Pos->second; 791d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson} 792d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson 793d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlssonvoid ASTContext::setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, 794d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson FieldDecl *Tmpl) { 795d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!Inst->getDeclName() && "Instantiated field decl is not unnamed"); 796d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!Tmpl->getDeclName() && "Template field decl is not unnamed"); 797d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!InstantiatedFromUnnamedFieldDecl[Inst] && 798d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson "Already noted what unnamed field was instantiated from"); 7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 800d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl; 801d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson} 802d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson 80314d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanianbool ASTContext::ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD, 80414d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian const FieldDecl *LastFD) const { 80514d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian return (FD->isBitField() && LastFD && !LastFD->isBitField() && 806a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this) == 0); 80714d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian} 80814d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian 809340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanianbool ASTContext::ZeroBitfieldFollowsBitfield(const FieldDecl *FD, 810340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian const FieldDecl *LastFD) const { 811340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian return (FD->isBitField() && LastFD && LastFD->isBitField() && 812a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this) == 0 && 813a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith LastFD->getBitWidthValue(*this) != 0); 814340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian} 815340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian 8169b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanianbool ASTContext::BitfieldFollowsBitfield(const FieldDecl *FD, 8179b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian const FieldDecl *LastFD) const { 8189b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian return (FD->isBitField() && LastFD && LastFD->isBitField() && 819a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this) && 820a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith LastFD->getBitWidthValue(*this)); 8219b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian} 8229b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian 823dd7fddb5b6883326e52b278a9b7e9cefea29aae0Chad Rosierbool ASTContext::NonBitfieldFollowsBitfield(const FieldDecl *FD, 82452bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian const FieldDecl *LastFD) const { 82552bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian return (!FD->isBitField() && LastFD && LastFD->isBitField() && 826a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith LastFD->getBitWidthValue(*this)); 82752bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian} 82852bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian 829dd7fddb5b6883326e52b278a9b7e9cefea29aae0Chad Rosierbool ASTContext::BitfieldFollowsNonBitfield(const FieldDecl *FD, 83052bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian const FieldDecl *LastFD) const { 83152bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian return (FD->isBitField() && LastFD && !LastFD->isBitField() && 832a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this)); 83352bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian} 83452bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian 8357d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_cxx_method_iterator 8367d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_methods_begin(const CXXMethodDecl *Method) const { 8377d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos 8387d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor = OverriddenMethods.find(Method); 8397d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor if (Pos == OverriddenMethods.end()) 8407d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return 0; 8417d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 8427d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return Pos->second.begin(); 8437d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor} 8447d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 8457d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_cxx_method_iterator 8467d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_methods_end(const CXXMethodDecl *Method) const { 8477d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos 8487d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor = OverriddenMethods.find(Method); 8497d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor if (Pos == OverriddenMethods.end()) 8507d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return 0; 8517d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 8527d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return Pos->second.end(); 8537d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor} 8547d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 855c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidisunsigned 856c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios KyrtzidisASTContext::overridden_methods_size(const CXXMethodDecl *Method) const { 857c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos 858c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis = OverriddenMethods.find(Method); 859c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis if (Pos == OverriddenMethods.end()) 860c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis return 0; 861c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis 862c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis return Pos->second.size(); 863c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis} 864c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis 8657d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregorvoid ASTContext::addOverriddenMethod(const CXXMethodDecl *Method, 8667d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor const CXXMethodDecl *Overridden) { 8677d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor OverriddenMethods[Method].push_back(Overridden); 8687d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor} 8697d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 870e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregorvoid ASTContext::addedLocalImportDecl(ImportDecl *Import) { 871e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor assert(!Import->NextLocalImport && "Import declaration already in the chain"); 872e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor assert(!Import->isFromASTFile() && "Non-local import declaration"); 873e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor if (!FirstLocalImport) { 874e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor FirstLocalImport = Import; 875e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor LastLocalImport = Import; 876e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor return; 877e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor } 878e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor 879e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor LastLocalImport->NextLocalImport = Import; 880e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor LastLocalImport = Import; 881e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor} 882e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor 883464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 884464175bba1318bef7905122e9fda20cff926df78Chris Lattner// Type Sizing and Analysis 885464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 886a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 887b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 888b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// scalar floating point type. 889b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattnerconst llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { 890183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const BuiltinType *BT = T->getAs<BuiltinType>(); 891b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(BT && "Not a floating point type!"); 892b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner switch (BT->getKind()) { 893b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not a floating point type!"); 894aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case BuiltinType::Half: return Target->getHalfFormat(); 895bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor case BuiltinType::Float: return Target->getFloatFormat(); 896bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor case BuiltinType::Double: return Target->getDoubleFormat(); 897bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor case BuiltinType::LongDouble: return Target->getLongDoubleFormat(); 898b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 899b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner} 900b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 9018b752f10c394b140f9ef89e049cbad1a7676fc25Ken Dyck/// getDeclAlign - Return a conservative estimate of the alignment of the 902af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// specified decl. Note that bitfields do not have a valid alignment, so 903af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// this method will assert on them. 9045d484e8cf710207010720589d89602233de61d01Sebastian Redl/// If @p RefAsPointee, references are treated like their underlying type 9055d484e8cf710207010720589d89602233de61d01Sebastian Redl/// (for alignof), else they're treated like pointers (for CodeGen). 9064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) const { 907bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor unsigned Align = Target->getCharWidth(); 908dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 9094081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall bool UseAlignAttrOnly = false; 9104081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall if (unsigned AlignFromAttr = D->getMaxAlignment()) { 9114081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall Align = AlignFromAttr; 9124081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall 9134081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // __attribute__((aligned)) can increase or decrease alignment 9144081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // *except* on a struct or struct member, where it only increases 9154081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // alignment unless 'packed' is also specified. 9164081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // 91782d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne // It is an error for alignas to decrease alignment, so we can 9184081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // ignore that possibility; Sema should diagnose it. 9194081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall if (isa<FieldDecl>(D)) { 9204081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall UseAlignAttrOnly = D->hasAttr<PackedAttr>() || 9214081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>(); 9224081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } else { 9234081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall UseAlignAttrOnly = true; 9244081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } 9254081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } 92678a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian else if (isa<FieldDecl>(D)) 92778a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian UseAlignAttrOnly = 92878a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian D->hasAttr<PackedAttr>() || 92978a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>(); 930dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 931ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // If we're using the align attribute only, just ignore everything 932ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // else about the declaration and its type. 9334081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall if (UseAlignAttrOnly) { 934ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // do nothing 935ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 9364081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } else if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { 937af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner QualType T = VD->getType(); 9386217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType* RT = T->getAs<ReferenceType>()) { 9395d484e8cf710207010720589d89602233de61d01Sebastian Redl if (RefAsPointee) 9405d484e8cf710207010720589d89602233de61d01Sebastian Redl T = RT->getPointeeType(); 9415d484e8cf710207010720589d89602233de61d01Sebastian Redl else 9425d484e8cf710207010720589d89602233de61d01Sebastian Redl T = getPointerType(RT->getPointeeType()); 9435d484e8cf710207010720589d89602233de61d01Sebastian Redl } 9445d484e8cf710207010720589d89602233de61d01Sebastian Redl if (!T->isIncompleteType() && !T->isFunctionType()) { 9453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Adjust alignments of declarations with array type by the 9463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // large-array alignment on the target. 947bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor unsigned MinWidth = Target->getLargeArrayMinWidth(); 9483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ArrayType *arrayType; 9493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (MinWidth && (arrayType = getAsArrayType(T))) { 9503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (isa<VariableArrayType>(arrayType)) 951bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = std::max(Align, Target->getLargeArrayAlign()); 9523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall else if (isa<ConstantArrayType>(arrayType) && 9533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall MinWidth <= getTypeSize(cast<ConstantArrayType>(arrayType))) 954bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = std::max(Align, Target->getLargeArrayAlign()); 9553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 9563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Walk through any array types while we're at it. 9573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall T = getBaseElementType(arrayType); 9586deecb0d46bcfd048e651d2db7c4fb0d6407da96Rafael Espindola } 9599f1210c3280104417a4ad30f0a00825ac8fa718aChad Rosier Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); 960dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman } 961ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 962ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Fields can be subject to extra alignment constraints, like if 963ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // the field is packed, the struct is packed, or the struct has a 964ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // a max-field-alignment constraint (#pragma pack). So calculate 965ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // the actual alignment of the field within the struct, and then 966ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // (as we're expected to) constrain that by the alignment of the type. 967ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall if (const FieldDecl *field = dyn_cast<FieldDecl>(VD)) { 968ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // So calculate the alignment of the field. 969ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall const ASTRecordLayout &layout = getASTRecordLayout(field->getParent()); 970ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 971ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Start with the record's overall alignment. 972dac54c124e302d6f028ea5723c425b7f66fc7c71Ken Dyck unsigned fieldAlign = toBits(layout.getAlignment()); 973ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 974ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Use the GCD of that and the offset within the record. 975ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall uint64_t offset = layout.getFieldOffset(field->getFieldIndex()); 976ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall if (offset > 0) { 977ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Alignment is always a power of 2, so the GCD will be a power of 2, 978ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // which means we get to do this crazy thing instead of Euclid's. 979ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall uint64_t lowBitOfOffset = offset & (~offset + 1); 980ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall if (lowBitOfOffset < fieldAlign) 981ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall fieldAlign = static_cast<unsigned>(lowBitOfOffset); 982ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall } 983ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 984ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall Align = std::min(Align, fieldAlign); 98505f62474dd2b0f1cb69adbe0787f2868788aa949Charles Davis } 986af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner } 987dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 988eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(Align); 989af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner} 990b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 991ea1471e0e967548c596a71469702f8846dbaf3c0John McCallstd::pair<CharUnits, CharUnits> 992bee5a79fc95e3003d755031e3d2bb4410a71e1c1Ken DyckASTContext::getTypeInfoInChars(const Type *T) const { 993ea1471e0e967548c596a71469702f8846dbaf3c0John McCall std::pair<uint64_t, unsigned> Info = getTypeInfo(T); 994eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return std::make_pair(toCharUnitsFromBits(Info.first), 995eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck toCharUnitsFromBits(Info.second)); 996ea1471e0e967548c596a71469702f8846dbaf3c0John McCall} 997ea1471e0e967548c596a71469702f8846dbaf3c0John McCall 998ea1471e0e967548c596a71469702f8846dbaf3c0John McCallstd::pair<CharUnits, CharUnits> 999bee5a79fc95e3003d755031e3d2bb4410a71e1c1Ken DyckASTContext::getTypeInfoInChars(QualType T) const { 1000ea1471e0e967548c596a71469702f8846dbaf3c0John McCall return getTypeInfoInChars(T.getTypePtr()); 1001ea1471e0e967548c596a71469702f8846dbaf3c0John McCall} 1002ea1471e0e967548c596a71469702f8846dbaf3c0John McCall 1003bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbarstd::pair<uint64_t, unsigned> ASTContext::getTypeInfo(const Type *T) const { 1004bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar TypeInfoMap::iterator it = MemoizedTypeInfo.find(T); 1005bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar if (it != MemoizedTypeInfo.end()) 1006bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar return it->second; 1007bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar 1008bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar std::pair<uint64_t, unsigned> Info = getTypeInfoImpl(T); 1009bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar MemoizedTypeInfo.insert(std::make_pair(T, Info)); 1010bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar return Info; 1011bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar} 1012bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar 1013bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar/// getTypeInfoImpl - Return the size of the specified type, in bits. This 1014bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar/// method does not work on incomplete types. 10150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 10160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// FIXME: Pointers into different addr spaces could have different sizes and 10170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// alignment requirements: getPointerInfo should take an AddrSpace, this 10180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// should take a QualType, &c. 1019d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattnerstd::pair<uint64_t, unsigned> 1020bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel DunbarASTContext::getTypeInfoImpl(const Type *T) const { 10215e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump uint64_t Width=0; 10225e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump unsigned Align=8; 1023a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (T->getTypeClass()) { 102472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 102572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 102618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor#define NON_CANONICAL_TYPE(Class, Base) 102772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 102872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 1029d3d49bb27c7ffd9accc0a6c00e887111c0348845John McCall llvm_unreachable("Should not see dependent types"); 103072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 10315d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionNoProto: 10325d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionProto: 103318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(function) = 32 bits 103418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 103518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 32; 103618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 103718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 103872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 1039fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::VariableArray: 104018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 104118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = getTypeAlign(cast<ArrayType>(T)->getElementType()); 104218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 104318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 1044fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::ConstantArray: { 10451d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ConstantArrayType *CAT = cast<ConstantArrayType>(T); 10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104798be4943e8dc4f3905629a7102668960873cf863Chris Lattner std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType()); 1048fea966a4103ed9c018d1494b95e9d09b161f5a70Abramo Bagnara uint64_t Size = CAT->getSize().getZExtValue(); 1049bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar assert((Size == 0 || EltInfo.first <= (uint64_t)(-1)/Size) && 1050bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar "Overflow in array type bit size evaluation"); 1051fea966a4103ed9c018d1494b95e9d09b161f5a70Abramo Bagnara Width = EltInfo.first*Size; 1052030d8846c7e520330007087e949f621989876e3aChris Lattner Align = EltInfo.second; 1053cd88b4171753dcb2bc0a21d78f1597c796bb8a20Argyrios Kyrtzidis Width = llvm::RoundUpToAlignment(Width, Align); 1054030d8846c7e520330007087e949f621989876e3aChris Lattner break; 10555c09a02a5db85e08a432b6eeced9aa656349710dChristopher Lamb } 1056213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman case Type::ExtVector: 1057030d8846c7e520330007087e949f621989876e3aChris Lattner case Type::Vector: { 10589fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner const VectorType *VT = cast<VectorType>(T); 10599fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(VT->getElementType()); 10609fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner Width = EltInfo.first*VT->getNumElements(); 10614bd998bbc228915d2b9cae5b67879de48940d05eEli Friedman Align = Width; 10626fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // If the alignment is not a power of 2, round up to the next power of 2. 10636fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // This happens for non-power-of-2 length vectors. 10648eefcd353c1d06a10104f69e5079ebab3183f9a3Dan Gohman if (Align & (Align-1)) { 10659fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner Align = llvm::NextPowerOf2(Align); 10669fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner Width = llvm::RoundUpToAlignment(Width, Align); 10679fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner } 1068f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier // Adjust the alignment based on the target max. 1069f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier uint64_t TargetVectorAlign = Target->getMaxVectorAlign(); 1070f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier if (TargetVectorAlign && TargetVectorAlign < Align) 1071f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier Align = TargetVectorAlign; 1072030d8846c7e520330007087e949f621989876e3aChris Lattner break; 1073030d8846c7e520330007087e949f621989876e3aChris Lattner } 10745d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner 10759e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner case Type::Builtin: 1076a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 1077b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unknown builtin type!"); 1078d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner case BuiltinType::Void: 107918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(void) = 8 bits. 108018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 108118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 8; 108218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 108318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 10846f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Bool: 1085bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getBoolWidth(); 1086bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getBoolAlign(); 10876f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1088692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_S: 1089692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_U: 1090692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UChar: 10916f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::SChar: 1092bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getCharWidth(); 1093bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getCharAlign(); 10946f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 10953f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 10963f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 1097bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getWCharWidth(); 1098bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getWCharAlign(); 109964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis break; 1100f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char16: 1101bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getChar16Width(); 1102bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getChar16Align(); 1103f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 1104f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char32: 1105bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getChar32Width(); 1106bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getChar32Align(); 1107f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 1108692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UShort: 11096f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Short: 1110bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getShortWidth(); 1111bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getShortAlign(); 11126f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1113692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UInt: 11146f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Int: 1115bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getIntWidth(); 1116bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getIntAlign(); 11176f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1118692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULong: 11196f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Long: 1120bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getLongWidth(); 1121bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getLongAlign(); 11226f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1123692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULongLong: 11246f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongLong: 1125bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getLongLongWidth(); 1126bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getLongLongAlign(); 11276f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1128ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::Int128: 1129ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::UInt128: 1130ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Width = 128; 1131ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Align = 128; // int128_t is 128-bit aligned on all targets. 1132ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner break; 1133aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case BuiltinType::Half: 1134aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov Width = Target->getHalfWidth(); 1135aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov Align = Target->getHalfAlign(); 1136aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov break; 11376f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Float: 1138bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getFloatWidth(); 1139bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getFloatAlign(); 11406f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 11416f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Double: 1142bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getDoubleWidth(); 1143bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getDoubleAlign(); 11446f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 11456f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongDouble: 1146bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getLongDoubleWidth(); 1147bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getLongDoubleAlign(); 11486f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 11496e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case BuiltinType::NullPtr: 1150bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(0); // C++ 3.9.1p11: sizeof(nullptr_t) 1151bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(0); // == sizeof(void*) 11521590d9c0fec4c710c2962e4bb71f76979b5163d3Sebastian Redl break; 1153e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian case BuiltinType::ObjCId: 1154e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian case BuiltinType::ObjCClass: 1155e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian case BuiltinType::ObjCSel: 1156bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(0); 1157bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(0); 1158e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian break; 1159a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 1160bfef6d7c67831a135d6ab79931f010f750a730adChris Lattner break; 1161d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case Type::ObjCObjectPointer: 1162bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(0); 1163bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(0); 11646f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1165485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff case Type::BlockPointer: { 1166207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned AS = getTargetAddressSpace( 1167207f4d8543529221932af82836016a2ef066c917Peter Collingbourne cast<BlockPointerType>(T)->getPointeeType()); 1168bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(AS); 1169bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(AS); 1170485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff break; 1171485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff } 11725d484e8cf710207010720589d89602233de61d01Sebastian Redl case Type::LValueReference: 11735d484e8cf710207010720589d89602233de61d01Sebastian Redl case Type::RValueReference: { 11745d484e8cf710207010720589d89602233de61d01Sebastian Redl // alignof and sizeof should never enter this code path here, so we go 11755d484e8cf710207010720589d89602233de61d01Sebastian Redl // the pointer route. 1176207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned AS = getTargetAddressSpace( 1177207f4d8543529221932af82836016a2ef066c917Peter Collingbourne cast<ReferenceType>(T)->getPointeeType()); 1178bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(AS); 1179bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(AS); 11805d484e8cf710207010720589d89602233de61d01Sebastian Redl break; 11815d484e8cf710207010720589d89602233de61d01Sebastian Redl } 1182f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner case Type::Pointer: { 1183207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned AS = getTargetAddressSpace(cast<PointerType>(T)->getPointeeType()); 1184bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(AS); 1185bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(AS); 1186f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner break; 1187f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner } 1188f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case Type::MemberPointer: { 1189071cc7deffad608165b1ddd5263e8bf181861520Charles Davis const MemberPointerType *MPT = cast<MemberPointerType>(T); 11901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<uint64_t, unsigned> PtrDiffInfo = 11911cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson getTypeInfo(getPointerDiffType()); 1192071cc7deffad608165b1ddd5263e8bf181861520Charles Davis Width = PtrDiffInfo.first * ABI->getMemberPointerSize(MPT); 11931cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson Align = PtrDiffInfo.second; 11941cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson break; 1195f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 11965d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::Complex: { 11975d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // Complex types have the same alignment as their elements, but twice the 11985d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // size. 11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<uint64_t, unsigned> EltInfo = 120098be4943e8dc4f3905629a7102668960873cf863Chris Lattner getTypeInfo(cast<ComplexType>(T)->getElementType()); 12019e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = EltInfo.first*2; 12025d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner Align = EltInfo.second; 12035d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner break; 12045d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner } 1205c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case Type::ObjCObject: 1206c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getTypeInfo(cast<ObjCObjectType>(T)->getBaseType().getTypePtr()); 120744a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel case Type::ObjCInterface: { 12081d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T); 120944a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); 1210dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck Width = toBits(Layout.getSize()); 1211dac54c124e302d6f028ea5723c425b7f66fc7c71Ken Dyck Align = toBits(Layout.getAlignment()); 121244a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel break; 121344a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel } 121472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 121572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: { 12161d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const TagType *TT = cast<TagType>(T); 12171d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar 12181d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (TT->getDecl()->isInvalidDecl()) { 121922ce41d9fc8509da65858c75bf5b3c4dae2d8c04Douglas Gregor Width = 8; 122022ce41d9fc8509da65858c75bf5b3c4dae2d8c04Douglas Gregor Align = 8; 12218389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner break; 12228389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner } 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12241d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (const EnumType *ET = dyn_cast<EnumType>(TT)) 12257176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner return getTypeInfo(ET->getDecl()->getIntegerType()); 12267176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner 12271d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const RecordType *RT = cast<RecordType>(TT); 12287176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); 1229dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck Width = toBits(Layout.getSize()); 1230dac54c124e302d6f028ea5723c425b7f66fc7c71Ken Dyck Align = toBits(Layout.getAlignment()); 1231dc0d73e6495404418acf8548875aeaff07791a74Chris Lattner break; 1232a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 12337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 12349fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner case Type::SubstTemplateTypeParm: 123549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return getTypeInfo(cast<SubstTemplateTypeParmType>(T)-> 123649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall getReplacementType().getTypePtr()); 123749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 123834b41d939a1328f484511c6002ba2456db879a29Richard Smith case Type::Auto: { 123934b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *A = cast<AutoType>(T); 124034b41d939a1328f484511c6002ba2456db879a29Richard Smith assert(A->isDeduced() && "Cannot request the size of a dependent type"); 1241dc856aff4428380baa9afb5577ea04f8fb6beb13Matt Beaumont-Gay return getTypeInfo(A->getDeducedType().getTypePtr()); 124234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 124334b41d939a1328f484511c6002ba2456db879a29Richard Smith 1244075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case Type::Paren: 1245075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr()); 1246075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 124718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::Typedef: { 1248162e1c1b487352434552147967c3dd296ebee2f7Richard Smith const TypedefNameDecl *Typedef = cast<TypedefType>(T)->getDecl(); 1249df1367af26cb2959775e9511108f12dcd2370a27Douglas Gregor std::pair<uint64_t, unsigned> Info 1250df1367af26cb2959775e9511108f12dcd2370a27Douglas Gregor = getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); 1251c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner // If the typedef has an aligned attribute on it, it overrides any computed 1252c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner // alignment we have. This violates the GCC documentation (which says that 1253c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner // attribute(aligned) can only round up) but matches its implementation. 1254c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner if (unsigned AttrAlign = Typedef->getMaxAlignment()) 1255c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner Align = AttrAlign; 1256c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner else 1257c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner Align = Info.second; 1258df1367af26cb2959775e9511108f12dcd2370a27Douglas Gregor Width = Info.first; 12597532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor break; 12607176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner } 126118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 126218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOfExpr: 126318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType() 126418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor .getTypePtr()); 126518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 126618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOf: 126718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfType>(T)->getUnderlyingType().getTypePtr()); 126818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 1269395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson case Type::Decltype: 1270395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return getTypeInfo(cast<DecltypeType>(T)->getUnderlyingExpr()->getType() 1271395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson .getTypePtr()); 1272395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 1273ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt case Type::UnaryTransform: 1274ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return getTypeInfo(cast<UnaryTransformType>(T)->getUnderlyingType()); 1275ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1276465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Type::Elaborated: 1277465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return getTypeInfo(cast<ElaboratedType>(T)->getNamedType().getTypePtr()); 12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall case Type::Attributed: 12809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return getTypeInfo( 12819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall cast<AttributedType>(T)->getEquivalentType().getTypePtr()); 12829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 12833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith case Type::TemplateSpecialization: { 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(getCanonicalType(T) != T && 128518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor "Cannot request the size of a dependent type"); 12863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith const TemplateSpecializationType *TST = cast<TemplateSpecializationType>(T); 12873e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // A type alias template specialization may refer to a typedef with the 12883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // aligned attribute on it. 12893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (TST->isTypeAlias()) 12903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return getTypeInfo(TST->getAliasedType().getTypePtr()); 12913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith else 12923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return getTypeInfo(getCanonicalType(T)); 12933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 12943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 1295b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: { 12962be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman std::pair<uint64_t, unsigned> Info 12972be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman = getTypeInfo(cast<AtomicType>(T)->getValueType()); 12982be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman Width = Info.first; 12992be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman Align = Info.second; 13002be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman if (Width != 0 && Width <= Target->getMaxAtomicPromoteWidth() && 13012be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman llvm::isPowerOf2_64(Width)) { 13022be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // We can potentially perform lock-free atomic operations for this 13032be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // type; promote the alignment appropriately. 13042be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // FIXME: We could potentially promote the width here as well... 13052be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // is that worthwhile? (Non-struct atomic types generally have 13062be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // power-of-two size anyway, but structs might not. Requires a bit 13072be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // of implementation work to make sure we zero out the extra bits.) 13082be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman Align = static_cast<unsigned>(Width); 13092be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman } 1310b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1311b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 131218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor } 13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13142be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman assert(llvm::isPowerOf2_32(Align) && "Alignment must be power of 2"); 13159e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner return std::make_pair(Width, Align); 1316a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner} 1317a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 1318eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck/// toCharUnitsFromBits - Convert a size in bits to a size in characters. 1319eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen DyckCharUnits ASTContext::toCharUnitsFromBits(int64_t BitSize) const { 1320eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return CharUnits::fromQuantity(BitSize / getCharWidth()); 1321eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck} 1322eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck 1323dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck/// toBits - Convert a size in characters to a size in characters. 1324dd76a9ab9ea675671200f94b18ce95766841952bKen Dyckint64_t ASTContext::toBits(CharUnits CharSize) const { 1325dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck return CharSize.getQuantity() * getCharWidth(); 1326dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck} 1327dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck 1328bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck/// getTypeSizeInChars - Return the size of the specified type, in characters. 1329bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck/// This method does not work on incomplete types. 13304ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeSizeInChars(QualType T) const { 1331eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeSize(T)); 1332bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck} 13334ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeSizeInChars(const Type *T) const { 1334eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeSize(T)); 1335bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck} 1336bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck 133716e20cce43385001f33f8e3f90ee345609c805d1Ken Dyck/// getTypeAlignInChars - Return the ABI-specified alignment of a type, in 133886fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck/// characters. This method does not work on incomplete types. 13394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeAlignInChars(QualType T) const { 1340eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeAlign(T)); 134186fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck} 13424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeAlignInChars(const Type *T) const { 1343eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeAlign(T)); 134486fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck} 134586fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck 134634ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// getPreferredTypeAlign - Return the "preferred" alignment of the specified 134734ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// type for the current target in bits. This can be different than the ABI 134834ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// alignment in cases where it is beneficial for performance to overalign 134934ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// a data type. 13504ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned ASTContext::getPreferredTypeAlign(const Type *T) const { 135134ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner unsigned ABIAlign = getTypeAlign(T); 13521eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 13531eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman // Double and long long should be naturally aligned if possible. 1354183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType* CT = T->getAs<ComplexType>()) 13551eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman T = CT->getElementType().getTypePtr(); 13561eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman if (T->isSpecificBuiltinType(BuiltinType::Double) || 1357cde7a1dc68af2eb063a039b5a31c3b7dd92b1aa9Chad Rosier T->isSpecificBuiltinType(BuiltinType::LongLong) || 1358cde7a1dc68af2eb063a039b5a31c3b7dd92b1aa9Chad Rosier T->isSpecificBuiltinType(BuiltinType::ULongLong)) 13591eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman return std::max(ABIAlign, (unsigned)getTypeSize(T)); 13601eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 136134ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner return ABIAlign; 136234ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner} 136334ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner 13642c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// DeepCollectObjCIvars - 13652c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// This routine first collects all declared, but not synthesized, ivars in 13662c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// super class and then collects all ivars, including those synthesized for 13672c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// current class. This routine is used for implementation of current class 13682c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// when all ivars, declared and synthesized are known. 13699820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian/// 13702c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanianvoid ASTContext::DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, 13712c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian bool leafClass, 1372db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const { 13732c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian if (const ObjCInterfaceDecl *SuperClass = OI->getSuperClass()) 13742c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian DeepCollectObjCIvars(SuperClass, false, Ivars); 13752c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian if (!leafClass) { 13762c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(), 13772c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian E = OI->ivar_end(); I != E; ++I) 1378581deb3da481053c4993c7600f97acf7768caac5David Blaikie Ivars.push_back(*I); 13793060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 1380bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian ObjCInterfaceDecl *IDecl = const_cast<ObjCInterfaceDecl *>(OI); 1381db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose for (const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv; 1382bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian Iv= Iv->getNextIvar()) 1383bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian Ivars.push_back(Iv); 1384bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian } 13859820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian} 13869820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian 1387e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// CollectInheritedProtocols - Collect all protocols in current class and 1388e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// those inherited by it. 1389e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanianvoid ASTContext::CollectInheritedProtocols(const Decl *CDecl, 1390432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols) { 1391e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (const ObjCInterfaceDecl *OI = dyn_cast<ObjCInterfaceDecl>(CDecl)) { 139253b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek // We can use protocol_iterator here instead of 139353b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek // all_referenced_protocol_iterator since we are walking all categories. 139453b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek for (ObjCInterfaceDecl::all_protocol_iterator P = OI->all_referenced_protocol_begin(), 139553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek PE = OI->all_referenced_protocol_end(); P != PE; ++P) { 1396e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian ObjCProtocolDecl *Proto = (*P); 13973fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert(Proto->getCanonicalDecl()); 1398e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(), 1399b2f812165676230bce5d0215e49a4749c451ca9cFariborz Jahanian PE = Proto->protocol_end(); P != PE; ++P) { 14003fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert((*P)->getCanonicalDecl()); 1401e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(*P, Protocols); 1402e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1403b2f812165676230bce5d0215e49a4749c451ca9cFariborz Jahanian } 1404e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 1405e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian // Categories of this Interface. 1406e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (const ObjCCategoryDecl *CDeclChain = OI->getCategoryList(); 1407e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CDeclChain; CDeclChain = CDeclChain->getNextClassCategory()) 1408e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(CDeclChain, Protocols); 1409e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (ObjCInterfaceDecl *SD = OI->getSuperClass()) 1410e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian while (SD) { 1411e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(SD, Protocols); 1412e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian SD = SD->getSuperClass(); 1413e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1414b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer } else if (const ObjCCategoryDecl *OC = dyn_cast<ObjCCategoryDecl>(CDecl)) { 141553b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek for (ObjCCategoryDecl::protocol_iterator P = OC->protocol_begin(), 1416e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = OC->protocol_end(); P != PE; ++P) { 1417e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian ObjCProtocolDecl *Proto = (*P); 14183fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert(Proto->getCanonicalDecl()); 1419e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(), 1420e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = Proto->protocol_end(); P != PE; ++P) 1421e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(*P, Protocols); 1422e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1423b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer } else if (const ObjCProtocolDecl *OP = dyn_cast<ObjCProtocolDecl>(CDecl)) { 1424e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = OP->protocol_begin(), 1425e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = OP->protocol_end(); P != PE; ++P) { 1426e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian ObjCProtocolDecl *Proto = (*P); 14273fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert(Proto->getCanonicalDecl()); 1428e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(), 1429e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = Proto->protocol_end(); P != PE; ++P) 1430e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(*P, Protocols); 1431e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1432e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1433e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian} 1434e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 14354ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned ASTContext::CountNonClassIvars(const ObjCInterfaceDecl *OI) const { 14363bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian unsigned count = 0; 14373bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian // Count ivars declared in class extension. 143880aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian for (const ObjCCategoryDecl *CDecl = OI->getFirstClassExtension(); CDecl; 143980aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian CDecl = CDecl->getNextClassExtension()) 1440b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer count += CDecl->ivar_size(); 1441b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer 14423bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian // Count ivar defined in this class's implementation. This 14433bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian // includes synthesized ivars. 14443bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) 1445b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer count += ImplDecl->ivar_size(); 1446b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer 14478e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian return count; 14488e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian} 14498e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 14508deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidisbool ASTContext::isSentinelNullExpr(const Expr *E) { 14518deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (!E) 14528deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis return false; 14538deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 14548deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis // nullptr_t is always treated as null. 14558deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (E->getType()->isNullPtrType()) return true; 14568deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 14578deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (E->getType()->isAnyPointerType() && 14588deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis E->IgnoreParenCasts()->isNullPointerConstant(*this, 14598deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis Expr::NPC_ValueDependentIsNull)) 14608deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis return true; 14618deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 14628deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis // Unfortunately, __null has type 'int'. 14638deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (isa<GNUNullExpr>(E)) return true; 14648deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 14658deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis return false; 14668deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis} 14678deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 14688a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists. 14698a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCImplementationDecl *ASTContext::getObjCImplementation(ObjCInterfaceDecl *D) { 14708a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 14718a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 14728a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 14738a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCImplementationDecl>(I->second); 14748a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 14758a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 14768a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists. 14778a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCCategoryImplDecl *ASTContext::getObjCImplementation(ObjCCategoryDecl *D) { 14788a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 14798a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 14808a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 14818a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCCategoryImplDecl>(I->second); 14828a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 14838a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 14848a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 14858a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCInterfaceDecl. 14868a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCInterfaceDecl *IFaceD, 14878a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImplementationDecl *ImplD) { 14888a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(IFaceD && ImplD && "Passed null params"); 14898a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[IFaceD] = ImplD; 14908a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 14918a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCCategoryDecl. 14928a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCCategoryDecl *CatD, 14938a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCCategoryImplDecl *ImplD) { 14948a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(CatD && ImplD && "Passed null params"); 14958a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[CatD] = ImplD; 14968a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 14978a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 149887ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios KyrtzidisObjCInterfaceDecl *ASTContext::getObjContainingInterface(NamedDecl *ND) const { 149987ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ND->getDeclContext())) 150087ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return ID; 150187ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(ND->getDeclContext())) 150287ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return CD->getClassInterface(); 150387ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(ND->getDeclContext())) 150487ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return IMD->getClassInterface(); 150587ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis 150687ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return 0; 150787ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis} 150887ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis 15091ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian/// \brief Get the copy initialization expression of VarDecl,or NULL if 15101ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian/// none exists. 1511830937bc1100fba7682f7c32c40512085870f50cFariborz JahanianExpr *ASTContext::getBlockVarCopyInits(const VarDecl*VD) { 1512d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian assert(VD && "Passed null params"); 1513d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian assert(VD->hasAttr<BlocksAttr>() && 1514d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian "getBlockVarCopyInits - not __block var"); 1515830937bc1100fba7682f7c32c40512085870f50cFariborz Jahanian llvm::DenseMap<const VarDecl*, Expr*>::iterator 1516d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian I = BlockVarCopyInits.find(VD); 15171ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian return (I != BlockVarCopyInits.end()) ? cast<Expr>(I->second) : 0; 15181ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian} 15191ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian 15201ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian/// \brief Set the copy inialization expression of a block var decl. 15211ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanianvoid ASTContext::setBlockVarCopyInits(VarDecl*VD, Expr* Init) { 15221ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian assert(VD && Init && "Passed null params"); 1523d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian assert(VD->hasAttr<BlocksAttr>() && 1524d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian "setBlockVarCopyInits - not __block var"); 15251ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian BlockVarCopyInits[VD] = Init; 15261ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian} 15271ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian 1528a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCallTypeSourceInfo *ASTContext::CreateTypeSourceInfo(QualType T, 15294ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned DataSize) const { 1530109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall if (!DataSize) 1531109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall DataSize = TypeLoc::getFullDataSizeForType(T); 1532109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall else 1533109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall assert(DataSize == TypeLoc::getFullDataSizeForType(T) && 1534a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall "incorrect data size provided to CreateTypeSourceInfo!"); 1535109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall 1536a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *TInfo = 1537a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall (TypeSourceInfo*)BumpAlloc.Allocate(sizeof(TypeSourceInfo) + DataSize, 8); 1538a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall new (TInfo) TypeSourceInfo(T); 1539a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TInfo; 1540b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis} 1541b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1542a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCallTypeSourceInfo *ASTContext::getTrivialTypeSourceInfo(QualType T, 15436952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor SourceLocation L) const { 1544a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = CreateTypeSourceInfo(T); 1545c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor DI->getTypeLoc().initialize(const_cast<ASTContext &>(*this), L); 1546a4eb74d4dfe126c686dc708fec444c85ffb73b47John McCall return DI; 1547a4eb74d4dfe126c686dc708fec444c85ffb73b47John McCall} 1548a4eb74d4dfe126c686dc708fec444c85ffb73b47John McCall 1549b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 15504ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const { 1551b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D, 0); 1552b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 1553b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 1554b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 15554ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getASTObjCImplementationLayout( 15564ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ObjCImplementationDecl *D) const { 1557b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D->getClassInterface(), D); 1558b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 1559b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 1560a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 1561a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner// Type creation/memoization methods 1562a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 1563a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 15644ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 15653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallASTContext::getExtQualType(const Type *baseType, Qualifiers quals) const { 15663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned fastQuals = quals.getFastQualifiers(); 15673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall quals.removeFastQualifiers(); 15680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 15690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Check if we've already instantiated this type. 15700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::FoldingSetNodeID ID; 15713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals::Profile(ID, baseType, quals); 15723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void *insertPos = 0; 15733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (ExtQuals *eq = ExtQualNodes.FindNodeOrInsertPos(ID, insertPos)) { 15743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(eq->getQualifiers() == quals); 15753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(eq, fastQuals); 15760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 15770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 15783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the base type is not canonical, make the appropriate canonical type. 15793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon; 15803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!baseType->isCanonicalUnqualified()) { 15813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = baseType->getCanonicalTypeInternal().split(); 1582200fa53fd420aa8369586f569dbece04930ad6a3John McCall canonSplit.Quals.addConsistentQualifiers(quals); 1583200fa53fd420aa8369586f569dbece04930ad6a3John McCall canon = getExtQualType(canonSplit.Ty, canonSplit.Quals); 15843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 15853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Re-find the insert position. 15863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos); 15873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 15883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 15893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals *eq = new (*this, TypeAlignment) ExtQuals(baseType, canon, quals); 15903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQualNodes.InsertNode(eq, insertPos); 15913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(eq, fastQuals); 15920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 15930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 15944ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 15954ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getAddrSpaceQualType(QualType T, unsigned AddressSpace) const { 1596f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType CanT = getCanonicalType(T); 1597f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner if (CanT.getAddressSpace() == AddressSpace) 1598f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return T; 1599b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner 16000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If we are composing extended qualifiers together, merge together 16010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into one ExtQuals node. 16020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 16030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *TypeNode = Quals.strip(T); 16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this type already has an address space specified, it cannot get 16060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // another one. 16070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasAddressSpace() && 16080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "Type cannot be in multiple addr spaces!"); 16090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addAddressSpace(AddressSpace); 16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getExtQualType(TypeNode, Quals); 1612ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1613ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1614b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris LattnerQualType ASTContext::getObjCGCQualType(QualType T, 16154ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Qualifiers::GC GCAttr) const { 1616d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CanT = getCanonicalType(T); 1617b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner if (CanT.getObjCGCAttr() == GCAttr) 1618d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return T; 16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16207f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (const PointerType *ptr = T->getAs<PointerType>()) { 16217f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall QualType Pointee = ptr->getPointeeType(); 162258f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff if (Pointee->isAnyPointerType()) { 16234027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian QualType ResultType = getObjCGCQualType(Pointee, GCAttr); 16244027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian return getPointerType(ResultType); 16254027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 16264027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If we are composing extended qualifiers together, merge together 16290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into one ExtQuals node. 16300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 16310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *TypeNode = Quals.strip(T); 16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this type already has an ObjCGC specified, it cannot get 16340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // another one. 16350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasObjCGCAttr() && 16360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "Type cannot have multiple ObjCGCs!"); 16370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addObjCGCAttr(GCAttr); 16381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getExtQualType(TypeNode, Quals); 1640d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 1641a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 1642e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCallconst FunctionType *ASTContext::adjustFunctionType(const FunctionType *T, 1643e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FunctionType::ExtInfo Info) { 1644e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (T->getExtInfo() == Info) 1645e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return T; 1646e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 1647e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType Result; 1648e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (const FunctionNoProtoType *FNPT = dyn_cast<FunctionNoProtoType>(T)) { 1649e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Result = getFunctionNoProtoType(FNPT->getResultType(), Info); 1650e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } else { 1651e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 1652e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); 1653e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall EPI.ExtInfo = Info; 1654e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Result = getFunctionType(FPT->getResultType(), FPT->arg_type_begin(), 1655e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FPT->getNumArgs(), EPI); 1656e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 1657e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 1658e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return cast<FunctionType>(Result.getTypePtr()); 1659e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall} 1660e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 16615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getComplexType - Return the uniqued reference to the type for a complex 16625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// number with the specified element type. 16634ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getComplexType(QualType T) const { 16645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 16655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 16675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType::Profile(ID, T); 16681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 16705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos)) 16715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(CT, 0); 16721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 16745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 16755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 1676467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!T.isCanonical()) { 1677f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getComplexType(getCanonicalType(T)); 16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 16805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos); 1681c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 16825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16836b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ComplexType *New = new (*this, TypeAlignment) ComplexType(T, Canonical); 16845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 16855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexTypes.InsertNode(New, InsertPos); 16865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 16875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getPointerType - Return the uniqued reference to the type for a pointer to 16905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the specified type. 16914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getPointerType(QualType T) const { 16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 16945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 16955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType::Profile(ID, T); 16961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 16985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 16995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(PT, 0); 17001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 17025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 17035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 1704467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!T.isCanonical()) { 1705f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getPointerType(getCanonicalType(T)); 17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 17085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1709c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 17105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17116b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall PointerType *New = new (*this, TypeAlignment) PointerType(T, Canonical); 17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 17135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerTypes.InsertNode(New, InsertPos); 17145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 17155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getBlockPointerType - Return the uniqued reference to the type for 17185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// a pointer to the specified block. 17194ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getBlockPointerType(QualType T) const { 1720296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff assert(T->isFunctionType() && "block of function types only"); 1721296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // Unique pointers, to guarantee there is only one block of a particular 17225618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // structure. 17235618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff llvm::FoldingSetNodeID ID; 17245618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType::Profile(ID, T); 17251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void *InsertPos = 0; 17275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff if (BlockPointerType *PT = 17285618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 17295618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(PT, 0); 17301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the block pointee type isn't canonical, this won't be a canonical 17325618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // type either so fill in the canonical type field. 17335618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType Canonical; 1734467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!T.isCanonical()) { 17355618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Canonical = getBlockPointerType(getCanonicalType(T)); 17361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17375618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the new insert position for the node we care about. 17385618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType *NewIP = 17395618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1740c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 17415618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 17426b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall BlockPointerType *New 17436b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) BlockPointerType(T, Canonical); 17445618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Types.push_back(New); 17455618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.InsertNode(New, InsertPos); 17465618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(New, 0); 17475618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 17485618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 17497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getLValueReferenceType - Return the uniqued reference to the type for an 17507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// lvalue reference to the specified type. 17514ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 17524ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const { 17539625e44c0252485277a340746ed8ac950686156fDouglas Gregor assert(getCanonicalType(T) != OverloadTy && 17549625e44c0252485277a340746ed8ac950686156fDouglas Gregor "Unresolved overloaded function type"); 17559625e44c0252485277a340746ed8ac950686156fDouglas Gregor 17565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 17575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 175954e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType::Profile(ID, T, SpelledAsLValue); 17605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 17627c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (LValueReferenceType *RT = 17637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 17645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(RT, 0); 17657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 176654e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *InnerRef = T->getAs<ReferenceType>(); 176754e14c4db764c0636160d26c5bbf491637c83a76John McCall 17685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the referencee type isn't canonical, this won't be a canonical type 17695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // either, so fill in the canonical type field. 17705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 177154e14c4db764c0636160d26c5bbf491637c83a76John McCall if (!SpelledAsLValue || InnerRef || !T.isCanonical()) { 177254e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T); 177354e14c4db764c0636160d26c5bbf491637c83a76John McCall Canonical = getLValueReferenceType(getCanonicalType(PointeeType)); 17747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 17757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Get the new insert position for the node we care about. 17767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType *NewIP = 17777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 1778c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 17797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 17807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 17816b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall LValueReferenceType *New 178254e14c4db764c0636160d26c5bbf491637c83a76John McCall = new (*this, TypeAlignment) LValueReferenceType(T, Canonical, 178354e14c4db764c0636160d26c5bbf491637c83a76John McCall SpelledAsLValue); 17847c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Types.push_back(New); 17857c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.InsertNode(New, InsertPos); 178654e14c4db764c0636160d26c5bbf491637c83a76John McCall 17877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(New, 0); 17887c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 17897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 17907c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getRValueReferenceType - Return the uniqued reference to the type for an 17917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// rvalue reference to the specified type. 17924ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getRValueReferenceType(QualType T) const { 17937c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 17947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // structure. 17957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl llvm::FoldingSetNodeID ID; 179654e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType::Profile(ID, T, false); 17977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 17987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl void *InsertPos = 0; 17997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (RValueReferenceType *RT = 18007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 18017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(RT, 0); 18027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 180354e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *InnerRef = T->getAs<ReferenceType>(); 180454e14c4db764c0636160d26c5bbf491637c83a76John McCall 18057c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // If the referencee type isn't canonical, this won't be a canonical type 18067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // either, so fill in the canonical type field. 18077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl QualType Canonical; 180854e14c4db764c0636160d26c5bbf491637c83a76John McCall if (InnerRef || !T.isCanonical()) { 180954e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T); 181054e14c4db764c0636160d26c5bbf491637c83a76John McCall Canonical = getRValueReferenceType(getCanonicalType(PointeeType)); 18117c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 18125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 18137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType *NewIP = 18147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 1815c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 18165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18186b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall RValueReferenceType *New 18196b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) RValueReferenceType(T, Canonical); 18205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 18217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.InsertNode(New, InsertPos); 18225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 18235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 18245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1825f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// getMemberPointerType - Return the uniqued reference to the type for a 1826f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// member pointer to the specified type, in the specified class. 18274ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getMemberPointerType(QualType T, const Type *Cls) const { 1828f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 1829f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // structure. 1830f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl llvm::FoldingSetNodeID ID; 1831f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType::Profile(ID, T, Cls); 1832f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1833f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void *InsertPos = 0; 1834f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (MemberPointerType *PT = 1835f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 1836f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(PT, 0); 1837f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1838f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // If the pointee or class type isn't canonical, this won't be a canonical 1839f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // type either, so fill in the canonical type field. 1840f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType Canonical; 184187c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor if (!T.isCanonical() || !Cls->isCanonicalUnqualified()) { 1842f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Canonical = getMemberPointerType(getCanonicalType(T),getCanonicalType(Cls)); 1843f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1844f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Get the new insert position for the node we care about. 1845f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType *NewIP = 1846f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1847c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 1848f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 18496b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall MemberPointerType *New 18506b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) MemberPointerType(T, Cls, Canonical); 1851f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Types.push_back(New); 1852f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.InsertNode(New, InsertPos); 1853f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(New, 0); 1854f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1855f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 18561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getConstantArrayType - Return the unique reference to the type for an 1857fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff/// array of the specified element type. 18581eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getConstantArrayType(QualType EltTy, 185938aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner const llvm::APInt &ArySizeIn, 1860c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 186163e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara unsigned IndexTypeQuals) const { 1862923d56d436f750bc1f29db50e641078725558a1bSebastian Redl assert((EltTy->isDependentType() || 1863923d56d436f750bc1f29db50e641078725558a1bSebastian Redl EltTy->isIncompleteType() || EltTy->isConstantSizeType()) && 1864587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman "Constant array of VLAs is illegal!"); 1865587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman 186638aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // Convert the array size into a canonical width matching the pointer size for 186738aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // the target. 186838aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner llvm::APInt ArySize(ArySizeIn); 18699f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad ArySize = 1870bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor ArySize.zextOrTrunc(Target->getPointerWidth(getTargetAddressSpace(EltTy))); 18711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 187363e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara ConstantArrayType::Profile(ID, EltTy, ArySize, ASM, IndexTypeQuals); 18741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 18761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (ConstantArrayType *ATP = 18777192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) 18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(ATP, 0); 18791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the element type isn't canonical or has qualifiers, this won't 18813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // be a canonical type either, so fill in the canonical type field. 18823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType Canon; 18833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) { 18843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = getCanonicalType(EltTy).split(); 1885200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getConstantArrayType(QualType(canonSplit.Ty, 0), ArySize, 188663e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara ASM, IndexTypeQuals); 1887200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getQualifiedType(Canon, canonSplit.Quals); 18883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 18901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ConstantArrayType *NewIP = 18917192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos); 1892c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 18935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18956b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ConstantArrayType *New = new(*this,TypeAlignment) 189663e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara ConstantArrayType(EltTy, Canon, ArySize, ASM, IndexTypeQuals); 18977192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.InsertNode(New, InsertPos); 18985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 18995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 19005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 19015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1902ce8890371fcdb983ae487c87fa40606a34896ff7John McCall/// getVariableArrayDecayedType - Turns the given type, which may be 1903ce8890371fcdb983ae487c87fa40606a34896ff7John McCall/// variably-modified, into the corresponding type with all the known 1904ce8890371fcdb983ae487c87fa40606a34896ff7John McCall/// sizes replaced with [*]. 1905ce8890371fcdb983ae487c87fa40606a34896ff7John McCallQualType ASTContext::getVariableArrayDecayedType(QualType type) const { 1906ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Vastly most common case. 1907ce8890371fcdb983ae487c87fa40606a34896ff7John McCall if (!type->isVariablyModifiedType()) return type; 1908ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 1909ce8890371fcdb983ae487c87fa40606a34896ff7John McCall QualType result; 1910ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 1911ce8890371fcdb983ae487c87fa40606a34896ff7John McCall SplitQualType split = type.getSplitDesugaredType(); 1912200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Type *ty = split.Ty; 1913ce8890371fcdb983ae487c87fa40606a34896ff7John McCall switch (ty->getTypeClass()) { 1914ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#define TYPE(Class, Base) 1915ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#define ABSTRACT_TYPE(Class, Base) 1916ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 1917ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#include "clang/AST/TypeNodes.def" 1918ce8890371fcdb983ae487c87fa40606a34896ff7John McCall llvm_unreachable("didn't desugar past all non-canonical types?"); 1919ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 1920ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // These types should never be variably-modified. 1921ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Builtin: 1922ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Complex: 1923ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Vector: 1924ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ExtVector: 1925ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentSizedExtVector: 1926ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ObjCObject: 1927ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ObjCInterface: 1928ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ObjCObjectPointer: 1929ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Record: 1930ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Enum: 1931ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::UnresolvedUsing: 1932ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TypeOfExpr: 1933ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TypeOf: 1934ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Decltype: 1935ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt case Type::UnaryTransform: 1936ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentName: 1937ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::InjectedClassName: 1938ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TemplateSpecialization: 1939ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentTemplateSpecialization: 1940ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TemplateTypeParm: 1941ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::SubstTemplateTypeParmPack: 194234b41d939a1328f484511c6002ba2456db879a29Richard Smith case Type::Auto: 1943ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::PackExpansion: 1944ce8890371fcdb983ae487c87fa40606a34896ff7John McCall llvm_unreachable("type should never be variably-modified"); 1945ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 1946ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // These types can be variably-modified but should never need to 1947ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // further decay. 1948ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::FunctionNoProto: 1949ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::FunctionProto: 1950ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::BlockPointer: 1951ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::MemberPointer: 1952ce8890371fcdb983ae487c87fa40606a34896ff7John McCall return type; 1953ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 1954ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // These types can be variably-modified. All these modifications 1955ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // preserve structure except as noted by comments. 1956ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // TODO: if we ever care about optimizing VLAs, there are no-op 1957ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // optimizations available here. 1958ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Pointer: 1959ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getPointerType(getVariableArrayDecayedType( 1960ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cast<PointerType>(ty)->getPointeeType())); 1961ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 1962ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 1963ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::LValueReference: { 1964ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const LValueReferenceType *lv = cast<LValueReferenceType>(ty); 1965ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getLValueReferenceType( 1966ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(lv->getPointeeType()), 1967ce8890371fcdb983ae487c87fa40606a34896ff7John McCall lv->isSpelledAsLValue()); 1968ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 1969745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 1970ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 1971ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::RValueReference: { 1972ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const RValueReferenceType *lv = cast<RValueReferenceType>(ty); 1973ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getRValueReferenceType( 1974ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(lv->getPointeeType())); 1975ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 1976745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 1977745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 1978b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: { 1979b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman const AtomicType *at = cast<AtomicType>(ty); 1980b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman result = getAtomicType(getVariableArrayDecayedType(at->getValueType())); 1981b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman break; 1982b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1983b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 1984ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ConstantArray: { 1985ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const ConstantArrayType *cat = cast<ConstantArrayType>(ty); 1986ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getConstantArrayType( 1987ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(cat->getElementType()), 1988ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cat->getSize(), 1989ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cat->getSizeModifier(), 1990ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cat->getIndexTypeCVRQualifiers()); 1991ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 1992745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 1993745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 1994ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentSizedArray: { 1995ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const DependentSizedArrayType *dat = cast<DependentSizedArrayType>(ty); 1996ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getDependentSizedArrayType( 1997ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(dat->getElementType()), 1998ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getSizeExpr(), 1999ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getSizeModifier(), 2000ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getIndexTypeCVRQualifiers(), 2001ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getBracketsRange()); 2002ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2003ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2004ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2005ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Turn incomplete types into [*] types. 2006ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::IncompleteArray: { 2007ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const IncompleteArrayType *iat = cast<IncompleteArrayType>(ty); 2008ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getVariableArrayType( 2009ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(iat->getElementType()), 2010ce8890371fcdb983ae487c87fa40606a34896ff7John McCall /*size*/ 0, 2011ce8890371fcdb983ae487c87fa40606a34896ff7John McCall ArrayType::Normal, 2012ce8890371fcdb983ae487c87fa40606a34896ff7John McCall iat->getIndexTypeCVRQualifiers(), 2013ce8890371fcdb983ae487c87fa40606a34896ff7John McCall SourceRange()); 2014ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2015ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2016ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2017ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Turn VLA types into [*] types. 2018ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::VariableArray: { 2019ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const VariableArrayType *vat = cast<VariableArrayType>(ty); 2020ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getVariableArrayType( 2021ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(vat->getElementType()), 2022ce8890371fcdb983ae487c87fa40606a34896ff7John McCall /*size*/ 0, 2023ce8890371fcdb983ae487c87fa40606a34896ff7John McCall ArrayType::Star, 2024ce8890371fcdb983ae487c87fa40606a34896ff7John McCall vat->getIndexTypeCVRQualifiers(), 2025ce8890371fcdb983ae487c87fa40606a34896ff7John McCall vat->getBracketsRange()); 2026ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2027ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2028ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2029ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2030ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Apply the top-level qualifiers from the original. 2031200fa53fd420aa8369586f569dbece04930ad6a3John McCall return getQualifiedType(result, split.Quals); 2032ce8890371fcdb983ae487c87fa40606a34896ff7John McCall} 2033745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 2034bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// getVariableArrayType - Returns a non-unique reference to the type for a 2035bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// variable array of the specified element type. 20367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType ASTContext::getVariableArrayType(QualType EltTy, 20377e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *NumElts, 2038c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 203963e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara unsigned IndexTypeQuals, 20404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad SourceRange Brackets) const { 2041c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Since we don't unique expressions, it isn't possible to unique VLA's 2042c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // that have an expression provided for their size. 20433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType Canon; 2044715e9c8a39437347e838aa108df443fe1086d359Douglas Gregor 20453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Be sure to pull qualifiers off the element type. 20463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) { 20473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = getCanonicalType(EltTy).split(); 2048200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getVariableArrayType(QualType(canonSplit.Ty, 0), NumElts, ASM, 204963e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara IndexTypeQuals, Brackets); 2050200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getQualifiedType(Canon, canonSplit.Quals); 2051715e9c8a39437347e838aa108df443fe1086d359Douglas Gregor } 2052715e9c8a39437347e838aa108df443fe1086d359Douglas Gregor 20536b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VariableArrayType *New = new(*this, TypeAlignment) 205463e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals, Brackets); 2055c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2056c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman VariableArrayTypes.push_back(New); 2057c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman Types.push_back(New); 2058c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return QualType(New, 0); 2059c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman} 2060c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2061898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// getDependentSizedArrayType - Returns a non-unique reference to 2062898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// the type for a dependently-sized array of the specified element 206304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor/// type. 20643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getDependentSizedArrayType(QualType elementType, 20653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *numElements, 2066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ArrayType::ArraySizeModifier ASM, 20673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned elementTypeQuals, 20683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SourceRange brackets) const { 20693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert((!numElements || numElements->isTypeDependent() || 20703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall numElements->isValueDependent()) && 2071898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor "Size must be type- or value-dependent!"); 2072898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 20733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Dependently-sized array types that do not have a specified number 20743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // of elements will have their sizes deduced from a dependent 20753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // initializer. We do no canonicalization here at all, which is okay 20763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // because they can't be used in most locations. 20773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!numElements) { 20783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType *newType 20793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = new (*this, TypeAlignment) 20803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType(*this, elementType, QualType(), 20813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall numElements, ASM, elementTypeQuals, 20823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall brackets); 20833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(newType); 20843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(newType, 0); 2085cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor } 2086cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor 20873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Otherwise, we actually build a new type every time, but we 20883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // also build a canonical type. 20891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonElementType = getCanonicalType(elementType).split(); 2091898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 20923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void *insertPos = 0; 20933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall llvm::FoldingSetNodeID ID; 20943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType::Profile(ID, *this, 2095200fa53fd420aa8369586f569dbece04930ad6a3John McCall QualType(canonElementType.Ty, 0), 20963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ASM, elementTypeQuals, numElements); 20973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 20983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Look for an existing type with these properties. 20993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType *canonTy = 21003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayTypes.FindNodeOrInsertPos(ID, insertPos); 21013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 21023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If we don't have one, build one. 21033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!canonTy) { 21043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canonTy = new (*this, TypeAlignment) 2105200fa53fd420aa8369586f569dbece04930ad6a3John McCall DependentSizedArrayType(*this, QualType(canonElementType.Ty, 0), 21063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType(), numElements, ASM, elementTypeQuals, 21073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall brackets); 21083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayTypes.InsertNode(canonTy, insertPos); 21093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(canonTy); 21103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 21113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 21123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Apply qualifiers from the element type to the array. 21133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon = getQualifiedType(QualType(canonTy,0), 2114200fa53fd420aa8369586f569dbece04930ad6a3John McCall canonElementType.Quals); 21153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 21163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If we didn't need extra canonicalization for the element type, 21173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // then just use that as our result. 2118200fa53fd420aa8369586f569dbece04930ad6a3John McCall if (QualType(canonElementType.Ty, 0) == elementType) 21193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return canon; 21203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 21213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Otherwise, we need to build a type which follows the spelling 21223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // of the element type. 21233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType *sugaredType 21243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = new (*this, TypeAlignment) 21253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType(*this, elementType, canon, numElements, 21263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ASM, elementTypeQuals, brackets); 21273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(sugaredType); 21283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(sugaredType, 0); 21293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 21303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 21313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getIncompleteArrayType(QualType elementType, 2132c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArrayType::ArraySizeModifier ASM, 21333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned elementTypeQuals) const { 2134c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman llvm::FoldingSetNodeID ID; 21353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType::Profile(ID, elementType, ASM, elementTypeQuals); 2136c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 21373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void *insertPos = 0; 21383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (IncompleteArrayType *iat = 21393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos)) 21403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(iat, 0); 2141c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2142c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // If the element type isn't canonical, this won't be a canonical type 21433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // either, so fill in the canonical type field. We also have to pull 21443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // qualifiers off the element type. 21453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon; 2146c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 21473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!elementType.isCanonical() || elementType.hasLocalQualifiers()) { 21483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = getCanonicalType(elementType).split(); 2149200fa53fd420aa8369586f569dbece04930ad6a3John McCall canon = getIncompleteArrayType(QualType(canonSplit.Ty, 0), 21503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ASM, elementTypeQuals); 2151200fa53fd420aa8369586f569dbece04930ad6a3John McCall canon = getQualifiedType(canon, canonSplit.Quals); 2152c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2153c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Get the new insert position for the node we care about. 21543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType *existing = 21553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos); 21563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!existing && "Shouldn't be in the map!"); (void) existing; 21572bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 2158c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 21593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType *newType = new (*this, TypeAlignment) 21603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType(elementType, canon, ASM, elementTypeQuals); 2161c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 21623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayTypes.InsertNode(newType, insertPos); 21633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(newType); 21643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(newType, 0); 2165fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff} 2166fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 216773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// getVectorType - Return the unique reference to a vector type of 216873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 216982287d19ded35248c4ce6a425ce74116a13ce44eJohn ThompsonQualType ASTContext::getVectorType(QualType vecType, unsigned NumElts, 21704ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad VectorType::VectorKind VecKind) const { 21713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(vecType->isBuiltinType()); 21721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Check if we've already instantiated a vector of this type. 21745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 2175e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::Profile(ID, vecType, NumElts, Type::Vector, VecKind); 2176788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner 21775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 21785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 21795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(VTP, 0); 21805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the element type isn't canonical, this won't be a canonical type either, 21825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 21835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 2184255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor if (!vecType.isCanonical()) { 2185231da7eb3dd13007e5e40fffe48998e5ef284e06Bob Wilson Canonical = getVectorType(getCanonicalType(vecType), NumElts, VecKind); 21861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 21885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 2189c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 21905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21916b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VectorType *New = new (*this, TypeAlignment) 2192e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType(vecType, NumElts, Canonical, VecKind); 21935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorTypes.InsertNode(New, InsertPos); 21945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 21955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 21965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 21975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2198213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// getExtVectorType - Return the unique reference to an extended vector type of 219973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 22004ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 22014ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getExtVectorType(QualType vecType, unsigned NumElts) const { 22024ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor assert(vecType->isBuiltinType() || vecType->isDependentType()); 22031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 220473322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Check if we've already instantiated a vector of this type. 220573322924127c873c13101b705dd823f5539ffa5fSteve Naroff llvm::FoldingSetNodeID ID; 2206788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner VectorType::Profile(ID, vecType, NumElts, Type::ExtVector, 2207e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::GenericVector); 220873322924127c873c13101b705dd823f5539ffa5fSteve Naroff void *InsertPos = 0; 220973322924127c873c13101b705dd823f5539ffa5fSteve Naroff if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 221073322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(VTP, 0); 221173322924127c873c13101b705dd823f5539ffa5fSteve Naroff 221273322924127c873c13101b705dd823f5539ffa5fSteve Naroff // If the element type isn't canonical, this won't be a canonical type either, 221373322924127c873c13101b705dd823f5539ffa5fSteve Naroff // so fill in the canonical type field. 221473322924127c873c13101b705dd823f5539ffa5fSteve Naroff QualType Canonical; 2215467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!vecType.isCanonical()) { 2216213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman Canonical = getExtVectorType(getCanonicalType(vecType), NumElts); 22171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 221873322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Get the new insert position for the node we care about. 221973322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 2220c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 222173322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 22226b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ExtVectorType *New = new (*this, TypeAlignment) 22236b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ExtVectorType(vecType, NumElts, Canonical); 222473322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorTypes.InsertNode(New, InsertPos); 222573322924127c873c13101b705dd823f5539ffa5fSteve Naroff Types.push_back(New); 222673322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(New, 0); 222773322924127c873c13101b705dd823f5539ffa5fSteve Naroff} 222873322924127c873c13101b705dd823f5539ffa5fSteve Naroff 22294ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 22304ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getDependentSizedExtVectorType(QualType vecType, 22314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *SizeExpr, 22324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad SourceLocation AttrLoc) const { 22332ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor llvm::FoldingSetNodeID ID; 22341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedExtVectorType::Profile(ID, *this, getCanonicalType(vecType), 22352ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr); 22361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22372ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void *InsertPos = 0; 22382ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *Canon 22392ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); 22402ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *New; 22412ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (Canon) { 22422ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // We already have a canonical version of this array type; use it as 22432ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // the canonical type for a newly-built type. 22446b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 22456b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, QualType(Canon, 0), 22466b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall SizeExpr, AttrLoc); 22472ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 22482ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType CanonVecTy = getCanonicalType(vecType); 22492ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (CanonVecTy == vecType) { 22506b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 22516b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, QualType(), SizeExpr, 22526b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall AttrLoc); 2253789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 2254789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentSizedExtVectorType *CanonCheck 2255789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); 2256789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!CanonCheck && "Dependent-sized ext_vector canonical type broken"); 2257789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CanonCheck; 22582ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorTypes.InsertNode(New, InsertPos); 22592ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 22602ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType Canon = getDependentSizedExtVectorType(CanonVecTy, SizeExpr, 22612ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SourceLocation()); 22626b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 22636b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, Canon, SizeExpr, AttrLoc); 22642ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 22652ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 22661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22679cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Types.push_back(New); 22689cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return QualType(New, 0); 22699cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor} 22709cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 227172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getFunctionNoProtoType - Return a K&R style C function type like 'int()'. 22725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 22734ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 22744ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getFunctionNoProtoType(QualType ResultTy, 22754ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const FunctionType::ExtInfo &Info) const { 2276cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv DefaultCC = Info.getCC(); 2277cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv CallConv = (LangOpts.MRTD && DefaultCC == CC_Default) ? 2278cfe9af250f466e7e38becea4428990448ae07737Roman Divacky CC_X86StdCall : DefaultCC; 22795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 22805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 22815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 2282264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionNoProtoType::Profile(ID, ResultTy, Info); 22831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 22851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionNoProtoType *FT = 228672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 22875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FT, 0); 22881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 2290ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor if (!ResultTy.isCanonical() || 229104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall getCanonicalCallConv(CallConv) != CallConv) { 2292264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Canonical = 2293264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola getFunctionNoProtoType(getCanonicalType(ResultTy), 2294264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Info.withCallingConv(getCanonicalCallConv(CallConv))); 22951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 229772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType *NewIP = 229872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 2299c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 23005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2302cfe9af250f466e7e38becea4428990448ae07737Roman Divacky FunctionProtoType::ExtInfo newInfo = Info.withCallingConv(CallConv); 23036b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall FunctionNoProtoType *New = new (*this, TypeAlignment) 2304cfe9af250f466e7e38becea4428990448ae07737Roman Divacky FunctionNoProtoType(ResultTy, Canonical, newInfo); 23055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 230672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.InsertNode(New, InsertPos); 23075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 23085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 23095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFunctionType - Return a normal function type with a typed argument 23115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// list. isVariadic indicates whether the argument list includes '...'. 23124ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 23134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getFunctionType(QualType ResultTy, 23144ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const QualType *ArgArray, unsigned NumArgs, 23154ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const FunctionProtoType::ExtProtoInfo &EPI) const { 23165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 23175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 23185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 23198026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl FunctionProtoType::Profile(ID, ResultTy, ArgArray, NumArgs, EPI, *this); 23205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 23221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionProtoType *FTP = 232372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 23245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 2325465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2326465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Determine whether the type being created is already canonical or not. 2327eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith bool isCanonical = 2328eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith EPI.ExceptionSpecType == EST_None && ResultTy.isCanonical() && 2329eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith !EPI.HasTrailingReturn; 23305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs && isCanonical; ++i) 233154e14c4db764c0636160d26c5bbf491637c83a76John McCall if (!ArgArray[i].isCanonicalAsParam()) 23325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer isCanonical = false; 23335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2334cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv DefaultCC = EPI.ExtInfo.getCC(); 2335cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv CallConv = (LangOpts.MRTD && DefaultCC == CC_Default) ? 2336cfe9af250f466e7e38becea4428990448ae07737Roman Divacky CC_X86StdCall : DefaultCC; 2337e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 23385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If this type isn't canonical, get the canonical version of it. 2339465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // The exception spec is not part of the canonical type. 23405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 234104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall if (!isCanonical || getCanonicalCallConv(CallConv) != CallConv) { 23425f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 16> CanonicalArgs; 23435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CanonicalArgs.reserve(NumArgs); 23445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 234554e14c4db764c0636160d26c5bbf491637c83a76John McCall CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i])); 2346465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2347e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI; 2348eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith CanonicalEPI.HasTrailingReturn = false; 23498b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl CanonicalEPI.ExceptionSpecType = EST_None; 23508b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl CanonicalEPI.NumExceptions = 0; 2351e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall CanonicalEPI.ExtInfo 2352e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall = CanonicalEPI.ExtInfo.withCallingConv(getCanonicalCallConv(CallConv)); 2353e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2354f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getFunctionType(getCanonicalType(ResultTy), 2355beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad CanonicalArgs.data(), NumArgs, 2356e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall CanonicalEPI); 2357465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 23585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 235972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType *NewIP = 236072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 2361c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 23625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2363465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2364f85e193739c953358c865005855253af4f68a497John McCall // FunctionProtoType objects are allocated with extra bytes after 2365f85e193739c953358c865005855253af4f68a497John McCall // them for three variable size arrays at the end: 2366f85e193739c953358c865005855253af4f68a497John McCall // - parameter types 2367f85e193739c953358c865005855253af4f68a497John McCall // - exception types 2368f85e193739c953358c865005855253af4f68a497John McCall // - consumed-arguments flags 2369f85e193739c953358c865005855253af4f68a497John McCall // Instead of the exception types, there could be a noexcept 2370b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // expression, or information used to resolve the exception 2371b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // specification. 2372e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall size_t Size = sizeof(FunctionProtoType) + 237360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NumArgs * sizeof(QualType); 2374b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith if (EPI.ExceptionSpecType == EST_Dynamic) { 237560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Size += EPI.NumExceptions * sizeof(QualType); 2376b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) { 23778026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl Size += sizeof(Expr*); 2378e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith } else if (EPI.ExceptionSpecType == EST_Uninstantiated) { 237913bffc532bafd45d4a77867993c1afb83c7661beRichard Smith Size += 2 * sizeof(FunctionDecl*); 2380b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (EPI.ExceptionSpecType == EST_Unevaluated) { 2381b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith Size += sizeof(FunctionDecl*); 238260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2383f85e193739c953358c865005855253af4f68a497John McCall if (EPI.ConsumedArguments) 2384f85e193739c953358c865005855253af4f68a497John McCall Size += NumArgs * sizeof(bool); 2385f85e193739c953358c865005855253af4f68a497John McCall 2386e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType *FTP = (FunctionProtoType*) Allocate(Size, TypeAlignment); 2387cfe9af250f466e7e38becea4428990448ae07737Roman Divacky FunctionProtoType::ExtProtoInfo newEPI = EPI; 2388cfe9af250f466e7e38becea4428990448ae07737Roman Divacky newEPI.ExtInfo = EPI.ExtInfo.withCallingConv(CallConv); 23898026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl new (FTP) FunctionProtoType(ResultTy, ArgArray, NumArgs, Canonical, newEPI); 23905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(FTP); 239172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.InsertNode(FTP, InsertPos); 23925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 23935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 23945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23953cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall#ifndef NDEBUG 23963cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallstatic bool NeedsInjectedClassNameType(const RecordDecl *D) { 23973cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!isa<CXXRecordDecl>(D)) return false; 23983cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall const CXXRecordDecl *RD = cast<CXXRecordDecl>(D); 23993cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (isa<ClassTemplatePartialSpecializationDecl>(RD)) 24003cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return true; 24013cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (RD->getDescribedClassTemplate() && 24023cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall !isa<ClassTemplateSpecializationDecl>(RD)) 24033cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return true; 24043cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return false; 24053cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 24063cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall#endif 24073cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 24083cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// getInjectedClassNameType - Return the unique reference to the 24093cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// injected class name type for the specified templated declaration. 24103cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType ASTContext::getInjectedClassNameType(CXXRecordDecl *Decl, 24114ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType TST) const { 24123cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(NeedsInjectedClassNameType(Decl)); 24133cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (Decl->TypeForDecl) { 24143cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<InjectedClassNameType>(Decl->TypeForDecl)); 2415ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor } else if (CXXRecordDecl *PrevDecl = Decl->getPreviousDecl()) { 24163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(PrevDecl->TypeForDecl && "previous declaration has no type"); 24173cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl->TypeForDecl = PrevDecl->TypeForDecl; 24183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<InjectedClassNameType>(Decl->TypeForDecl)); 24193cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } else { 2420f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Type *newType = 242131f17ecbef57b5679c017c375db330546b7b5145John McCall new (*this, TypeAlignment) InjectedClassNameType(Decl, TST); 2422f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2423f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 24243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 24253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return QualType(Decl->TypeForDecl, 0); 24263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 24273cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 24282ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// getTypeDeclType - Return the unique reference to the type for the 24292ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// specified type declaration. 24304ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const { 24311e6759e9e33dcaa73ce14c8a908ac9f87ac16463Argyrios Kyrtzidis assert(Decl && "Passed null for Decl param"); 2432becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall assert(!Decl->TypeForDecl && "TypeForDecl present in slow case"); 24331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2434162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (const TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Decl)) 24352ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor return getTypedefType(Typedef); 2436becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall 2437becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall assert(!isa<TemplateTypeParmDecl>(Decl) && 2438becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall "Template type parameter types are always available."); 2439becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall 244019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall if (const RecordDecl *Record = dyn_cast<RecordDecl>(Decl)) { 2441ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor assert(!Record->getPreviousDecl() && 2442becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall "struct/union has previous declaration"); 2443becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall assert(!NeedsInjectedClassNameType(Record)); 2444400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return getRecordType(Record); 244519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall } else if (const EnumDecl *Enum = dyn_cast<EnumDecl>(Decl)) { 2446ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor assert(!Enum->getPreviousDecl() && 2447becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall "enum has previous declaration"); 2448400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return getEnumType(Enum); 244919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall } else if (const UnresolvedUsingTypenameDecl *Using = 2450ed97649e9574b9d854fa4d6109c9333ae0993554John McCall dyn_cast<UnresolvedUsingTypenameDecl>(Decl)) { 2451f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Type *newType = new (*this, TypeAlignment) UnresolvedUsingType(Using); 2452f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2453f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 24549fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else 2455becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall llvm_unreachable("TypeDecl without a type?"); 245649aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis 245749aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis return QualType(Decl->TypeForDecl, 0); 24582ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor} 24592ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 24605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTypedefType - Return the unique reference to the type for the 2461162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// specified typedef name decl. 24629763e221e16026ddf487d2564ed349d2c874a1a1Argyrios KyrtzidisQualType 2463162e1c1b487352434552147967c3dd296ebee2f7Richard SmithASTContext::getTypedefType(const TypedefNameDecl *Decl, 2464162e1c1b487352434552147967c3dd296ebee2f7Richard Smith QualType Canonical) const { 24655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 24661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24679763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis if (Canonical.isNull()) 24689763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Canonical = getCanonicalType(Decl->getUnderlyingType()); 2469f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall TypedefType *newType = new(*this, TypeAlignment) 24706b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypedefType(Type::Typedef, Decl, Canonical); 2471f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2472f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 2473f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(newType, 0); 24745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 24755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getRecordType(const RecordDecl *Decl) const { 2477400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 2478400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2479ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor if (const RecordDecl *PrevDecl = Decl->getPreviousDecl()) 2480400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (PrevDecl->TypeForDecl) 2481400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); 2482400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2483f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall RecordType *newType = new (*this, TypeAlignment) RecordType(Decl); 2484f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2485f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 2486f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(newType, 0); 2487400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis} 2488400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 24894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getEnumType(const EnumDecl *Decl) const { 2490400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 2491400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2492ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor if (const EnumDecl *PrevDecl = Decl->getPreviousDecl()) 2493400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (PrevDecl->TypeForDecl) 2494400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); 2495400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2496f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall EnumType *newType = new (*this, TypeAlignment) EnumType(Decl); 2497f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2498f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 2499f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(newType, 0); 2500400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis} 2501400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 25029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType ASTContext::getAttributedType(AttributedType::Kind attrKind, 25039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType, 25049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType) { 25059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall llvm::FoldingSetNodeID id; 25069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType::Profile(id, attrKind, modifiedType, equivalentType); 25079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 25089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void *insertPos = 0; 25099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType *type = AttributedTypes.FindNodeOrInsertPos(id, insertPos); 25109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (type) return QualType(type, 0); 25119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 25129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType canon = getCanonicalType(equivalentType); 25139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall type = new (*this, TypeAlignment) 25149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType(canon, attrKind, modifiedType, equivalentType); 25159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 25169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Types.push_back(type); 25179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypes.InsertNode(type, insertPos); 25189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 25199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(type, 0); 25209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 25219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 25229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 252349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Retrieve a substitution-result type. 252449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType 252549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallASTContext::getSubstTemplateTypeParmType(const TemplateTypeParmType *Parm, 25264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType Replacement) const { 2527467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall assert(Replacement.isCanonical() 252849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall && "replacement types must always be canonical"); 252949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 253049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall llvm::FoldingSetNodeID ID; 253149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType::Profile(ID, Parm, Replacement); 253249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall void *InsertPos = 0; 253349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType *SubstParm 253449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall = SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 253549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 253649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall if (!SubstParm) { 253749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstParm = new (*this, TypeAlignment) 253849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType(Parm, Replacement); 253949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Types.push_back(SubstParm); 254049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos); 254149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 254249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 254349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return QualType(SubstParm, 0); 254449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 254549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 2546c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Retrieve a 2547c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType ASTContext::getSubstTemplateTypeParmPackType( 2548c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Parm, 2549c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) { 2550c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor#ifndef NDEBUG 2551c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(), 2552c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor PEnd = ArgPack.pack_end(); 2553c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor P != PEnd; ++P) { 2554c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor assert(P->getKind() == TemplateArgument::Type &&"Pack contains a non-type"); 2555c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor assert(P->getAsType().isCanonical() && "Pack contains non-canonical type"); 2556c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 2557c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor#endif 2558c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2559c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor llvm::FoldingSetNodeID ID; 2560c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackType::Profile(ID, Parm, ArgPack); 2561c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor void *InsertPos = 0; 2562c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor if (SubstTemplateTypeParmPackType *SubstParm 2563c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor = SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos)) 2564c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return QualType(SubstParm, 0); 2565c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2566c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon; 2567c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor if (!Parm->isCanonicalUnqualified()) { 2568c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Canon = getCanonicalType(QualType(Parm, 0)); 2569c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Canon = getSubstTemplateTypeParmPackType(cast<TemplateTypeParmType>(Canon), 2570c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ArgPack); 2571c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos); 2572c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 2573c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2574c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackType *SubstParm 2575c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor = new (*this, TypeAlignment) SubstTemplateTypeParmPackType(Parm, Canon, 2576c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ArgPack); 2577c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Types.push_back(SubstParm); 2578c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos); 2579c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return QualType(SubstParm, 0); 2580c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 2581c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2582fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor/// \brief Retrieve the template type parameter type for a template 25831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// parameter or parameter pack with the given depth, index, and (optionally) 258476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson/// name. 25851eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index, 258676e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool ParameterPack, 25874fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *TTPDecl) const { 2588fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor llvm::FoldingSetNodeID ID; 25894fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmType::Profile(ID, Depth, Index, ParameterPack, TTPDecl); 2590fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void *InsertPos = 0; 25911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType *TypeParm 2592fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 2593fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 2594fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor if (TypeParm) 2595fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 25961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25974fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth if (TTPDecl) { 259876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson QualType Canon = getTemplateTypeParmType(Depth, Index, ParameterPack); 25994fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TypeParm = new (*this, TypeAlignment) TemplateTypeParmType(TTPDecl, Canon); 2600789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 2601789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor TemplateTypeParmType *TypeCheck 2602789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 2603789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!TypeCheck && "Template type parameter canonical type broken"); 2604789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)TypeCheck; 260576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson } else 26066b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeParm = new (*this, TypeAlignment) 26076b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TemplateTypeParmType(Depth, Index, ParameterPack); 2608fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 2609fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Types.push_back(TypeParm); 2610fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos); 2611fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 2612fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 2613fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor} 2614fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 26153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallTypeSourceInfo * 26163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallASTContext::getTemplateSpecializationTypeInfo(TemplateName Name, 26173cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall SourceLocation NameLoc, 26183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall const TemplateArgumentListInfo &Args, 26193e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Underlying) const { 26207c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Name.getAsDependentTemplateName() && 26217c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 26223e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType TST = getTemplateSpecializationType(Name, Args, Underlying); 26233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 26243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeSourceInfo *DI = CreateTypeSourceInfo(TST); 26253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TemplateSpecializationTypeLoc TL 26263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall = cast<TemplateSpecializationTypeLoc>(DI->getTypeLoc()); 262755d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara TL.setTemplateKeywordLoc(SourceLocation()); 26283cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setTemplateNameLoc(NameLoc); 26293cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setLAngleLoc(Args.getLAngleLoc()); 26303cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setRAngleLoc(Args.getRAngleLoc()); 26313cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) 26323cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setArgLocInfo(i, Args[i].getLocInfo()); 26333cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return DI; 26343cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 26353cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 26361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 26377532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorASTContext::getTemplateSpecializationType(TemplateName Template, 2638d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Args, 26393e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Underlying) const { 26407c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Template.getAsDependentTemplateName() && 26417c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 26427c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor 2643d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall unsigned NumArgs = Args.size(); 2644d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 26455f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 4> ArgVec; 2646833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall ArgVec.reserve(NumArgs); 2647833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != NumArgs; ++i) 2648833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall ArgVec.push_back(Args[i].getArgument()); 2649833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 265031f17ecbef57b5679c017c375db330546b7b5145John McCall return getTemplateSpecializationType(Template, ArgVec.data(), NumArgs, 26513e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Underlying); 2652833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2653833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2654b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor#ifndef NDEBUG 2655b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregorstatic bool hasAnyPackExpansions(const TemplateArgument *Args, 2656b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor unsigned NumArgs) { 2657b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) 2658b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor if (Args[I].isPackExpansion()) 2659b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor return true; 2660b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor 2661b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor return true; 2662b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor} 2663b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor#endif 2664b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor 2665833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType 2666833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallASTContext::getTemplateSpecializationType(TemplateName Template, 26677532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 26687532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, 26693e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Underlying) const { 26707c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Template.getAsDependentTemplateName() && 26717c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 26720f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor // Look through qualified template names. 26730f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 26740f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor Template = TemplateName(QTN->getTemplateDecl()); 26757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor 2676b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor bool IsTypeAlias = 26773e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Template.getAsTemplateDecl() && 26783e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith isa<TypeAliasTemplateDecl>(Template.getAsTemplateDecl()); 26793e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType CanonType; 26803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (!Underlying.isNull()) 26813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith CanonType = getCanonicalType(Underlying); 26823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith else { 2683b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor // We can get here with an alias template when the specialization contains 2684b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor // a pack expansion that does not match up with a parameter pack. 2685b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor assert((!IsTypeAlias || hasAnyPackExpansions(Args, NumArgs)) && 2686b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor "Caller must compute aliased type"); 2687b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor IsTypeAlias = false; 26883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith CanonType = getCanonicalTemplateSpecializationType(Template, Args, 26893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NumArgs); 26903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 2691fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor 26921275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Allocate the (non-canonical) template specialization type, but don't 26931275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // try to unique it: these types typically have location information that 26941275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // we don't unique and don't want to lose. 26953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith void *Mem = Allocate(sizeof(TemplateSpecializationType) + 26963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith sizeof(TemplateArgument) * NumArgs + 2697b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor (IsTypeAlias? sizeof(QualType) : 0), 26986b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignment); 26991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateSpecializationType *Spec 2700b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor = new (Mem) TemplateSpecializationType(Template, Args, NumArgs, CanonType, 2701b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor IsTypeAlias ? Underlying : QualType()); 27021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 270355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor Types.push_back(Spec); 27041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(Spec, 0); 270555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 270655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 27071eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 27089763e221e16026ddf487d2564ed349d2c874a1a1Argyrios KyrtzidisASTContext::getCanonicalTemplateSpecializationType(TemplateName Template, 27099763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis const TemplateArgument *Args, 27104ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned NumArgs) const { 27117c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Template.getAsDependentTemplateName() && 27127c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 27133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 27140f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor // Look through qualified template names. 27150f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 27160f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor Template = TemplateName(QTN->getTemplateDecl()); 27177c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor 27189763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // Build the canonical template specialization type. 27199763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateName CanonTemplate = getCanonicalTemplateName(Template); 27205f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 4> CanonArgs; 27219763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.reserve(NumArgs); 27229763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis for (unsigned I = 0; I != NumArgs; ++I) 27239763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.push_back(getCanonicalTemplateArgument(Args[I])); 27249763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 27259763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // Determine whether this canonical template specialization type already 27269763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // exists. 27279763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis llvm::FoldingSetNodeID ID; 27289763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateSpecializationType::Profile(ID, CanonTemplate, 27299763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.data(), NumArgs, *this); 27309763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 27319763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis void *InsertPos = 0; 27329763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateSpecializationType *Spec 27339763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 27349763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 27359763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis if (!Spec) { 27369763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // Allocate a new canonical template specialization type. 27379763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis void *Mem = Allocate((sizeof(TemplateSpecializationType) + 27389763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis sizeof(TemplateArgument) * NumArgs), 27399763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TypeAlignment); 27409763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Spec = new (Mem) TemplateSpecializationType(CanonTemplate, 27419763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.data(), NumArgs, 27423e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType(), QualType()); 27439763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Types.push_back(Spec); 27449763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateSpecializationTypes.InsertNode(Spec, InsertPos); 27459763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis } 27469763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 27479763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis assert(Spec->isDependentType() && 27489763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis "Non-dependent template-id type must have a canonical type"); 27499763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis return QualType(Spec, 0); 27509763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis} 27519763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 27529763e221e16026ddf487d2564ed349d2c874a1a1Argyrios KyrtzidisQualType 2753465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraASTContext::getElaboratedType(ElaboratedTypeKeyword Keyword, 2754465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS, 27554ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType NamedType) const { 2756e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor llvm::FoldingSetNodeID ID; 2757465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType::Profile(ID, Keyword, NNS, NamedType); 2758e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2759e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void *InsertPos = 0; 2760465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType *T = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos); 2761e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor if (T) 2762e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 2763e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2764789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor QualType Canon = NamedType; 2765789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor if (!Canon.isCanonical()) { 2766789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor Canon = getCanonicalType(NamedType); 2767465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType *CheckT = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos); 2768465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara assert(!CheckT && "Elaborated canonical type broken"); 2769789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CheckT; 2770789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor } 2771789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 2772465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara T = new (*this) ElaboratedType(Keyword, NNS, NamedType, Canon); 2773e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor Types.push_back(T); 2774465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypes.InsertNode(T, InsertPos); 2775e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 2776e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor} 2777e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2778075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 27794ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getParenType(QualType InnerType) const { 2780075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara llvm::FoldingSetNodeID ID; 2781075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType::Profile(ID, InnerType); 2782075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 2783075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void *InsertPos = 0; 2784075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType *T = ParenTypes.FindNodeOrInsertPos(ID, InsertPos); 2785075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (T) 2786075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(T, 0); 2787075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 2788075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Canon = InnerType; 2789075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (!Canon.isCanonical()) { 2790075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Canon = getCanonicalType(InnerType); 2791075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType *CheckT = ParenTypes.FindNodeOrInsertPos(ID, InsertPos); 2792075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara assert(!CheckT && "Paren canonical type broken"); 2793075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara (void)CheckT; 2794075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 2795075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 2796075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara T = new (*this) ParenType(InnerType, Canon); 2797075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Types.push_back(T); 2798075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypes.InsertNode(T, InsertPos); 2799075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(T, 0); 2800075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 2801075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 28024a2023f5014e82389d5980d307b89c545dbbac81Douglas GregorQualType ASTContext::getDependentNameType(ElaboratedTypeKeyword Keyword, 28034a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor NestedNameSpecifier *NNS, 28044a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const IdentifierInfo *Name, 28054ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType Canon) const { 2806d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && "nested-name-specifier must be dependent"); 2807d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2808d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (Canon.isNull()) { 2809d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 28104a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ElaboratedTypeKeyword CanonKeyword = Keyword; 28114a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor if (Keyword == ETK_None) 28124a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor CanonKeyword = ETK_Typename; 28134a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor 28144a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor if (CanonNNS != NNS || CanonKeyword != Keyword) 28154a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor Canon = getDependentNameType(CanonKeyword, CanonNNS, Name); 2816d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2817d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2818d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor llvm::FoldingSetNodeID ID; 28194a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor DependentNameType::Profile(ID, Keyword, NNS, Name); 2820d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2821d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void *InsertPos = 0; 28224714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor DependentNameType *T 28234714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor = DependentNameTypes.FindNodeOrInsertPos(ID, InsertPos); 2824d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (T) 2825d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return QualType(T, 0); 2826d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 28274a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor T = new (*this) DependentNameType(Keyword, NNS, Name, Canon); 2828d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Types.push_back(T); 28294714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor DependentNameTypes.InsertNode(T, InsertPos); 28301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(T, 0); 2831d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 2832d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 28331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 283433500955d731c73717af52088b7fc0e7a85681e7John McCallASTContext::getDependentTemplateSpecializationType( 283533500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 28364a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor NestedNameSpecifier *NNS, 283733500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 28384ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const TemplateArgumentListInfo &Args) const { 283933500955d731c73717af52088b7fc0e7a85681e7John McCall // TODO: avoid this copy 28405f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 16> ArgCopy; 284133500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0, E = Args.size(); I != E; ++I) 284233500955d731c73717af52088b7fc0e7a85681e7John McCall ArgCopy.push_back(Args[I].getArgument()); 284333500955d731c73717af52088b7fc0e7a85681e7John McCall return getDependentTemplateSpecializationType(Keyword, NNS, Name, 284433500955d731c73717af52088b7fc0e7a85681e7John McCall ArgCopy.size(), 284533500955d731c73717af52088b7fc0e7a85681e7John McCall ArgCopy.data()); 284633500955d731c73717af52088b7fc0e7a85681e7John McCall} 284733500955d731c73717af52088b7fc0e7a85681e7John McCall 284833500955d731c73717af52088b7fc0e7a85681e7John McCallQualType 284933500955d731c73717af52088b7fc0e7a85681e7John McCallASTContext::getDependentTemplateSpecializationType( 285033500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 285133500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, 285233500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 285333500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 28544ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const TemplateArgument *Args) const { 2855aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor assert((!NNS || NNS->isDependent()) && 2856aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor "nested-name-specifier must be dependent"); 28571734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 2858789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor llvm::FoldingSetNodeID ID; 285933500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationType::Profile(ID, *this, Keyword, NNS, 286033500955d731c73717af52088b7fc0e7a85681e7John McCall Name, NumArgs, Args); 2861789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 2862789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor void *InsertPos = 0; 286333500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationType *T 286433500955d731c73717af52088b7fc0e7a85681e7John McCall = DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 2865789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor if (T) 2866789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor return QualType(T, 0); 2867789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 286833500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 286933500955d731c73717af52088b7fc0e7a85681e7John McCall 287033500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword CanonKeyword = Keyword; 287133500955d731c73717af52088b7fc0e7a85681e7John McCall if (Keyword == ETK_None) CanonKeyword = ETK_Typename; 28721734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 287333500955d731c73717af52088b7fc0e7a85681e7John McCall bool AnyNonCanonArgs = false; 28745f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 16> CanonArgs(NumArgs); 287533500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0; I != NumArgs; ++I) { 287633500955d731c73717af52088b7fc0e7a85681e7John McCall CanonArgs[I] = getCanonicalTemplateArgument(Args[I]); 287733500955d731c73717af52088b7fc0e7a85681e7John McCall if (!CanonArgs[I].structurallyEquals(Args[I])) 287833500955d731c73717af52088b7fc0e7a85681e7John McCall AnyNonCanonArgs = true; 2879789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor } 28801734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 288133500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon; 288233500955d731c73717af52088b7fc0e7a85681e7John McCall if (AnyNonCanonArgs || CanonNNS != NNS || CanonKeyword != Keyword) { 288333500955d731c73717af52088b7fc0e7a85681e7John McCall Canon = getDependentTemplateSpecializationType(CanonKeyword, CanonNNS, 288433500955d731c73717af52088b7fc0e7a85681e7John McCall Name, NumArgs, 288533500955d731c73717af52088b7fc0e7a85681e7John McCall CanonArgs.data()); 288633500955d731c73717af52088b7fc0e7a85681e7John McCall 288733500955d731c73717af52088b7fc0e7a85681e7John McCall // Find the insert position again. 288833500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 288933500955d731c73717af52088b7fc0e7a85681e7John McCall } 289033500955d731c73717af52088b7fc0e7a85681e7John McCall 289133500955d731c73717af52088b7fc0e7a85681e7John McCall void *Mem = Allocate((sizeof(DependentTemplateSpecializationType) + 289233500955d731c73717af52088b7fc0e7a85681e7John McCall sizeof(TemplateArgument) * NumArgs), 289333500955d731c73717af52088b7fc0e7a85681e7John McCall TypeAlignment); 2894ef99001908e799c388f1363b1e607dad5f5b57d3John McCall T = new (Mem) DependentTemplateSpecializationType(Keyword, NNS, 289533500955d731c73717af52088b7fc0e7a85681e7John McCall Name, NumArgs, Args, Canon); 28961734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor Types.push_back(T); 289733500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypes.InsertNode(T, InsertPos); 28981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(T, 0); 28991734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor} 29001734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 2901cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas GregorQualType ASTContext::getPackExpansionType(QualType Pattern, 2902cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 29037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor llvm::FoldingSetNodeID ID; 2904cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor PackExpansionType::Profile(ID, Pattern, NumExpansions); 29057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 29067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor assert(Pattern->containsUnexpandedParameterPack() && 29077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor "Pack expansions must expand one or more parameter packs"); 29087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor void *InsertPos = 0; 29097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionType *T 29107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor = PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos); 29117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor if (T) 29127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return QualType(T, 0); 29137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 29147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType Canon; 29157536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor if (!Pattern.isCanonical()) { 2916d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith Canon = getCanonicalType(Pattern); 2917d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // The canonical type might not contain an unexpanded parameter pack, if it 2918d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // contains an alias template specialization which ignores one of its 2919d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // parameters. 2920d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith if (Canon->containsUnexpandedParameterPack()) { 2921d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith Canon = getPackExpansionType(getCanonicalType(Pattern), NumExpansions); 2922d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith 2923d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // Find the insert position again, in case we inserted an element into 2924d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // PackExpansionTypes and invalidated our insert position. 2925d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos); 2926d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith } 29277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 29287536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 2929cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor T = new (*this) PackExpansionType(Pattern, Canon, NumExpansions); 29307536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Types.push_back(T); 29317536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypes.InsertNode(T, InsertPos); 29327536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return QualType(T, 0); 29337536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 29347536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 293588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// CmpProtocolNames - Comparison predicate for sorting protocols 293688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// alphabetically. 293788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattnerstatic bool CmpProtocolNames(const ObjCProtocolDecl *LHS, 293888cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner const ObjCProtocolDecl *RHS) { 29392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS->getDeclName() < RHS->getDeclName(); 294088cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 294188cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 2942c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallstatic bool areSortedAndUniqued(ObjCProtocolDecl * const *Protocols, 294354e14c4db764c0636160d26c5bbf491637c83a76John McCall unsigned NumProtocols) { 294454e14c4db764c0636160d26c5bbf491637c83a76John McCall if (NumProtocols == 0) return true; 294554e14c4db764c0636160d26c5bbf491637c83a76John McCall 294661cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor if (Protocols[0]->getCanonicalDecl() != Protocols[0]) 294761cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor return false; 294861cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor 294954e14c4db764c0636160d26c5bbf491637c83a76John McCall for (unsigned i = 1; i != NumProtocols; ++i) 295061cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor if (!CmpProtocolNames(Protocols[i-1], Protocols[i]) || 295161cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor Protocols[i]->getCanonicalDecl() != Protocols[i]) 295254e14c4db764c0636160d26c5bbf491637c83a76John McCall return false; 295354e14c4db764c0636160d26c5bbf491637c83a76John McCall return true; 295454e14c4db764c0636160d26c5bbf491637c83a76John McCall} 295554e14c4db764c0636160d26c5bbf491637c83a76John McCall 295654e14c4db764c0636160d26c5bbf491637c83a76John McCallstatic void SortAndUniqueProtocols(ObjCProtocolDecl **Protocols, 295788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner unsigned &NumProtocols) { 295888cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ObjCProtocolDecl **ProtocolsEnd = Protocols+NumProtocols; 29591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 296088cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Sort protocols, keyed by name. 296188cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner std::sort(Protocols, Protocols+NumProtocols, CmpProtocolNames); 296288cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 296361cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor // Canonicalize. 296461cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor for (unsigned I = 0, N = NumProtocols; I != N; ++I) 296561cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor Protocols[I] = Protocols[I]->getCanonicalDecl(); 296661cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor 296788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Remove duplicates. 296888cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ProtocolsEnd = std::unique(Protocols, ProtocolsEnd); 296988cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner NumProtocols = ProtocolsEnd-Protocols; 297088cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 297188cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 2972c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType ASTContext::getObjCObjectType(QualType BaseType, 2973c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 29744ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned NumProtocols) const { 2975c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If the base type is an interface and there aren't any protocols 2976c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // to add, then the interface type will do just fine. 2977c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!NumProtocols && isa<ObjCInterfaceType>(BaseType)) 2978c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return BaseType; 2979d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 2980c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Look in the folding set for an existing type. 2981c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall llvm::FoldingSetNodeID ID; 2982c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeImpl::Profile(ID, BaseType, Protocols, NumProtocols); 2983d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff void *InsertPos = 0; 2984c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (ObjCObjectType *QT = ObjCObjectTypes.FindNodeOrInsertPos(ID, InsertPos)) 2985c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return QualType(QT, 0); 2986d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 2987c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Build the canonical type, which has the canonical base type and 2988c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // a sorted-and-uniqued list of protocols. 298954e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Canonical; 2990c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool ProtocolsSorted = areSortedAndUniqued(Protocols, NumProtocols); 2991c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!ProtocolsSorted || !BaseType.isCanonical()) { 2992c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!ProtocolsSorted) { 29935f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<ObjCProtocolDecl*, 8> Sorted(Protocols, 29940237941e0beb0c929934b66ad29443b484d987feBenjamin Kramer Protocols + NumProtocols); 299554e14c4db764c0636160d26c5bbf491637c83a76John McCall unsigned UniqueCount = NumProtocols; 299654e14c4db764c0636160d26c5bbf491637c83a76John McCall 299754e14c4db764c0636160d26c5bbf491637c83a76John McCall SortAndUniqueProtocols(&Sorted[0], UniqueCount); 2998c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Canonical = getObjCObjectType(getCanonicalType(BaseType), 2999c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall &Sorted[0], UniqueCount); 300054e14c4db764c0636160d26c5bbf491637c83a76John McCall } else { 3001c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Canonical = getObjCObjectType(getCanonicalType(BaseType), 3002c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Protocols, NumProtocols); 300354e14c4db764c0636160d26c5bbf491637c83a76John McCall } 300454e14c4db764c0636160d26c5bbf491637c83a76John McCall 300554e14c4db764c0636160d26c5bbf491637c83a76John McCall // Regenerate InsertPos. 3006c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypes.FindNodeOrInsertPos(ID, InsertPos); 300754e14c4db764c0636160d26c5bbf491637c83a76John McCall } 300854e14c4db764c0636160d26c5bbf491637c83a76John McCall 3009c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned Size = sizeof(ObjCObjectTypeImpl); 3010c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Size += NumProtocols * sizeof(ObjCProtocolDecl *); 3011fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor void *Mem = Allocate(Size, TypeAlignment); 3012c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeImpl *T = 3013c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall new (Mem) ObjCObjectTypeImpl(Canonical, BaseType, Protocols, NumProtocols); 30141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3015c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Types.push_back(T); 3016c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypes.InsertNode(T, InsertPos); 3017c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return QualType(T, 0); 3018d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 301988cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 3020c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// getObjCObjectPointerType - Return a ObjCObjectPointerType type for 3021c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// the given object type. 30224ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getObjCObjectPointerType(QualType ObjectT) const { 30234b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian llvm::FoldingSetNodeID ID; 3024c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType::Profile(ID, ObjectT); 30251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30264b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void *InsertPos = 0; 3027c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (ObjCObjectPointerType *QT = 3028c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 30294b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return QualType(QT, 0); 30301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3031c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Find the canonical object type. 303254e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Canonical; 3033c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!ObjectT.isCanonical()) { 3034c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Canonical = getObjCObjectPointerType(getCanonicalType(ObjectT)); 303554e14c4db764c0636160d26c5bbf491637c83a76John McCall 3036c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Regenerate InsertPos. 3037c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 303854e14c4db764c0636160d26c5bbf491637c83a76John McCall } 303954e14c4db764c0636160d26c5bbf491637c83a76John McCall 3040c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // No match. 3041c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void *Mem = Allocate(sizeof(ObjCObjectPointerType), TypeAlignment); 3042c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType *QType = 3043c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall new (Mem) ObjCObjectPointerType(Canonical, ObjectT); 304424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 304524fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis Types.push_back(QType); 3046c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypes.InsertNode(QType, InsertPos); 304724fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis return QualType(QType, 0); 304824fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 304924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 3050deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor/// getObjCInterfaceType - Return the unique reference to the type for the 3051deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor/// specified ObjC interface decl. The list of protocols is optional. 30520af550115df1f57f17a4f125ff0e8b34820c65d1Douglas GregorQualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl, 30530af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor ObjCInterfaceDecl *PrevDecl) const { 3054deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor if (Decl->TypeForDecl) 3055deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor return QualType(Decl->TypeForDecl, 0); 305674c730ad1f6818b676b0bad46d806a9176950328Sebastian Redl 30570af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor if (PrevDecl) { 30580af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl"); 30590af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor Decl->TypeForDecl = PrevDecl->TypeForDecl; 30600af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor return QualType(PrevDecl->TypeForDecl, 0); 30610af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor } 30620af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor 30638d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor // Prefer the definition, if there is one. 30648d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor if (const ObjCInterfaceDecl *Def = Decl->getDefinition()) 30658d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor Decl = Def; 30668d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor 3067deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor void *Mem = Allocate(sizeof(ObjCInterfaceType), TypeAlignment); 3068deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor ObjCInterfaceType *T = new (Mem) ObjCInterfaceType(Decl); 3069deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor Decl->TypeForDecl = T; 3070deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor Types.push_back(T); 3071deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor return QualType(T, 0); 3072c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3073c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 307472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getTypeOfExprType - Unlike many "get<Type>" functions, we can't unique 307572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType AST's (since expression's are never shared). For example, 30769752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// multiple declarations that refer to "typeof(x)" all contain different 30771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// DeclRefExpr's. This doesn't effect the type checker, since it operates 30789752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 30794ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTypeOfExprType(Expr *tofExpr) const { 3080dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType *toe; 3081b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (tofExpr->isTypeDependent()) { 3082b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor llvm::FoldingSetNodeID ID; 3083b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType::Profile(ID, *this, tofExpr); 30841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3085b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void *InsertPos = 0; 3086b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType *Canon 3087b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor = DependentTypeOfExprTypes.FindNodeOrInsertPos(ID, InsertPos); 3088b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (Canon) { 3089b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // We already have a "canonical" version of an identical, dependent 3090b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // typeof(expr) type. Use that as our canonical type. 30916b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, 3092b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor QualType((TypeOfExprType*)Canon, 0)); 30933060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 3094b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // Build a new, canonical typeof(expr) type. 30956b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Canon 30966b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) DependentTypeOfExprType(*this, tofExpr); 3097b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprTypes.InsertNode(Canon, InsertPos); 3098b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor toe = Canon; 3099b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 3100b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } else { 3101dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor QualType Canonical = getCanonicalType(tofExpr->getType()); 31026b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, Canonical); 3103dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 31049752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(toe); 31059752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(toe, 0); 3106d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 3107d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 31089752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// getTypeOfType - Unlike many "get<Type>" functions, we don't unique 31099752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// TypeOfType AST's. The only motivation to unique these nodes would be 31109752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// memory savings. Since typeof(t) is fairly uncommon, space shouldn't be 31111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an issue. This doesn't effect the type checker, since it operates 31129752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 31134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTypeOfType(QualType tofType) const { 3114f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType Canonical = getCanonicalType(tofType); 31156b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeOfType *tot = new (*this, TypeAlignment) TypeOfType(tofType, Canonical); 31169752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(tot); 31179752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(tot, 0); 3118d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 3119d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 312060a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson 3121395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// getDecltypeType - Unlike many "get<Type>" functions, we don't unique 3122395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType AST's. The only motivation to unique these nodes would be 3123395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// memory savings. Since decltype(t) is fairly uncommon, space shouldn't be 31241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an issue. This doesn't effect the type checker, since it operates 312539e02032b01874a0d02ba85a4cd3922adda81376David Blaikie/// on canonical types (which are always unique). 3126f8af98286022f72157d84951b48fde5fb369ab29Douglas GregorQualType ASTContext::getDecltypeType(Expr *e, QualType UnderlyingType) const { 3127dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor DecltypeType *dt; 3128561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 3129561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // C++0x [temp.type]p2: 3130561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // If an expression e involves a template parameter, decltype(e) denotes a 3131561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // unique dependent type. Two such decltype-specifiers refer to the same 3132561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // type only if their expressions are equivalent (14.5.6.1). 3133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (e->isInstantiationDependent()) { 31349d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor llvm::FoldingSetNodeID ID; 31359d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType::Profile(ID, *this, e); 31361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31379d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void *InsertPos = 0; 31389d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType *Canon 31399d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor = DependentDecltypeTypes.FindNodeOrInsertPos(ID, InsertPos); 31409d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor if (Canon) { 31419d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // We already have a "canonical" version of an equivalent, dependent 31429d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // decltype type. Use that as our canonical type. 31436b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall dt = new (*this, TypeAlignment) DecltypeType(e, DependentTy, 31449d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor QualType((DecltypeType*)Canon, 0)); 31453060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 31469d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // Build a new, canonical typeof(expr) type. 31476b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Canon = new (*this, TypeAlignment) DependentDecltypeType(*this, e); 31489d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeTypes.InsertNode(Canon, InsertPos); 31499d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor dt = Canon; 31509d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 31519d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } else { 3152f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregor dt = new (*this, TypeAlignment) DecltypeType(e, UnderlyingType, 3153f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregor getCanonicalType(UnderlyingType)); 3154dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 3155395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Types.push_back(dt); 3156395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return QualType(dt, 0); 3157395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 3158395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 3159ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// getUnaryTransformationType - We don't unique these, since the memory 3160ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// savings are minimal and these are rare. 3161ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType ASTContext::getUnaryTransformType(QualType BaseType, 3162ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType UnderlyingType, 3163ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind Kind) 3164ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt const { 3165ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType *Ty = 316669d9775da47a4b9f165dbc33277f02982928a94eDouglas Gregor new (*this, TypeAlignment) UnaryTransformType (BaseType, UnderlyingType, 316769d9775da47a4b9f165dbc33277f02982928a94eDouglas Gregor Kind, 316869d9775da47a4b9f165dbc33277f02982928a94eDouglas Gregor UnderlyingType->isDependentType() ? 316912fc4b0624706b474fa10308631fa8daf92f340fPeter Collingbourne QualType() : getCanonicalType(UnderlyingType)); 3170ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Types.push_back(Ty); 3171ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(Ty, 0); 3172ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 3173ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3174483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith/// getAutoType - We only unique auto types after they've been deduced. 317534b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType ASTContext::getAutoType(QualType DeducedType) const { 3176483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith void *InsertPos = 0; 3177483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith if (!DeducedType.isNull()) { 3178483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith // Look in the folding set for an existing type. 3179483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith llvm::FoldingSetNodeID ID; 3180483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith AutoType::Profile(ID, DeducedType); 3181483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos)) 3182483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith return QualType(AT, 0); 3183483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith } 3184483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith 3185483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith AutoType *AT = new (*this, TypeAlignment) AutoType(DeducedType); 3186483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith Types.push_back(AT); 3187483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith if (InsertPos) 3188483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith AutoTypes.InsertNode(AT, InsertPos); 3189483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith return QualType(AT, 0); 319034b41d939a1328f484511c6002ba2456db879a29Richard Smith} 319134b41d939a1328f484511c6002ba2456db879a29Richard Smith 3192b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman/// getAtomicType - Return the uniqued reference to the atomic type for 3193b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman/// the given value type. 3194b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType ASTContext::getAtomicType(QualType T) const { 3195b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // Unique pointers, to guarantee there is only one pointer of a particular 3196b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // structure. 3197b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman llvm::FoldingSetNodeID ID; 3198b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType::Profile(ID, T); 3199b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3200b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void *InsertPos = 0; 3201b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (AtomicType *AT = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos)) 3202b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(AT, 0); 3203b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3204b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // If the atomic value type isn't canonical, this won't be a canonical type 3205b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // either, so fill in the canonical type field. 3206b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType Canonical; 3207b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (!T.isCanonical()) { 3208b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Canonical = getAtomicType(getCanonicalType(T)); 3209b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3210b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // Get the new insert position for the node we care about. 3211b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType *NewIP = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos); 3212b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 3213b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 3214b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType *New = new (*this, TypeAlignment) AtomicType(T, Canonical); 3215b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Types.push_back(New); 3216b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypes.InsertNode(New, InsertPos); 3217b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(New, 0); 3218b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 3219b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3220ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// getAutoDeductType - Get type pattern for deducing against 'auto'. 3221ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithQualType ASTContext::getAutoDeductType() const { 3222ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (AutoDeductTy.isNull()) 3223ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith AutoDeductTy = getAutoType(QualType()); 3224ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith assert(!AutoDeductTy.isNull() && "can't build 'auto' pattern"); 3225ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return AutoDeductTy; 3226ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 3227ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 3228ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// getAutoRRefDeductType - Get type pattern for deducing against 'auto &&'. 3229ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithQualType ASTContext::getAutoRRefDeductType() const { 3230ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (AutoRRefDeductTy.isNull()) 3231ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith AutoRRefDeductTy = getRValueReferenceType(getAutoDeductType()); 3232ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith assert(!AutoRRefDeductTy.isNull() && "can't build 'auto &&' pattern"); 3233ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return AutoRRefDeductTy; 3234ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 3235ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 32365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTagDeclType - Return the unique reference to the type for the 32375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified TagDecl (struct/union/class/enum) decl. 32384ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTagDeclType(const TagDecl *Decl) const { 3239d778f88d32b96a74c9edb7342c81357606a7cdc0Ted Kremenek assert (Decl); 3240e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // FIXME: What is the design on getTagDeclType when it requires casting 3241e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // away const? mutable? 3242e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump return getTypeDeclType(const_cast<TagDecl*>(Decl)); 32435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 32445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 32451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getSizeType - Return the unique type for "size_t" (C99 7.17), the result 32461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and 32471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// needs to agree with the definition in <stddef.h>. 3248a3ccda58913cc1a4b8564e349448b12acc462da7Anders CarlssonCanQualType ASTContext::getSizeType() const { 3249bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return getFromTargetType(Target->getSizeType()); 32505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 32515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 325229e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg/// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5). 325329e97cb35fab314388f62b68fefa78947e93c1dcHans WennborgCanQualType ASTContext::getIntMaxType() const { 325429e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg return getFromTargetType(Target->getIntMaxType()); 325529e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg} 325629e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg 325729e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg/// getUIntMaxType - Return the unique type for "uintmax_t" (C99 7.18.1.5). 325829e97cb35fab314388f62b68fefa78947e93c1dcHans WennborgCanQualType ASTContext::getUIntMaxType() const { 325929e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg return getFromTargetType(Target->getUIntMaxType()); 326029e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg} 326129e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg 326264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getSignedWCharType - Return the type of "signed wchar_t". 326364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 326464c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getSignedWCharType() const { 326564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 326664c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return WCharTy; 326764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 326864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 326964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getUnsignedWCharType - Return the type of "unsigned wchar_t". 327064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 327164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getUnsignedWCharType() const { 327264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 327364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return UnsignedIntTy; 327464c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 327564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 327629e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg/// getPointerDiffType - Return the unique type for "ptrdiff_t" (C99 7.17) 32778b9023ba35a86838789e2c9034a6128728c547aaChris Lattner/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 32788b9023ba35a86838789e2c9034a6128728c547aaChris LattnerQualType ASTContext::getPointerDiffType() const { 3279bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return getFromTargetType(Target->getPtrDiffType(0)); 32808b9023ba35a86838789e2c9034a6128728c547aaChris Lattner} 32818b9023ba35a86838789e2c9034a6128728c547aaChris Lattner 3282e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 3283e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner// Type Operators 3284e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 3285e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 32864ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCanQualType ASTContext::getCanonicalParamType(QualType T) const { 328754e14c4db764c0636160d26c5bbf491637c83a76John McCall // Push qualifiers into arrays, and then discard any remaining 328854e14c4db764c0636160d26c5bbf491637c83a76John McCall // qualifiers. 328954e14c4db764c0636160d26c5bbf491637c83a76John McCall T = getCanonicalType(T); 3290745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian T = getVariableArrayDecayedType(T); 329154e14c4db764c0636160d26c5bbf491637c83a76John McCall const Type *Ty = T.getTypePtr(); 329254e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Result; 329354e14c4db764c0636160d26c5bbf491637c83a76John McCall if (isa<ArrayType>(Ty)) { 329454e14c4db764c0636160d26c5bbf491637c83a76John McCall Result = getArrayDecayedType(QualType(Ty,0)); 329554e14c4db764c0636160d26c5bbf491637c83a76John McCall } else if (isa<FunctionType>(Ty)) { 329654e14c4db764c0636160d26c5bbf491637c83a76John McCall Result = getPointerType(QualType(Ty, 0)); 329754e14c4db764c0636160d26c5bbf491637c83a76John McCall } else { 329854e14c4db764c0636160d26c5bbf491637c83a76John McCall Result = QualType(Ty, 0); 329954e14c4db764c0636160d26c5bbf491637c83a76John McCall } 330054e14c4db764c0636160d26c5bbf491637c83a76John McCall 330154e14c4db764c0636160d26c5bbf491637c83a76John McCall return CanQualType::CreateUnsafe(Result); 330254e14c4db764c0636160d26c5bbf491637c83a76John McCall} 330354e14c4db764c0636160d26c5bbf491637c83a76John McCall 330462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallQualType ASTContext::getUnqualifiedArrayType(QualType type, 330562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers &quals) { 330662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall SplitQualType splitType = type.getSplitUnqualifiedType(); 330762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 330862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // FIXME: getSplitUnqualifiedType() actually walks all the way to 330962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // the unqualified desugared type and then drops it on the floor. 331062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // We then have to strip that sugar back off with 331162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // getUnqualifiedDesugaredType(), which is silly. 331262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall const ArrayType *AT = 3313200fa53fd420aa8369586f569dbece04930ad6a3John McCall dyn_cast<ArrayType>(splitType.Ty->getUnqualifiedDesugaredType()); 331462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 331562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // If we don't have an array, just use the results in splitType. 33169dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (!AT) { 3317200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals = splitType.Quals; 3318200fa53fd420aa8369586f569dbece04930ad6a3John McCall return QualType(splitType.Ty, 0); 331928e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth } 332028e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 332162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, recurse on the array's element type. 332262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType elementType = AT->getElementType(); 332362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType unqualElementType = getUnqualifiedArrayType(elementType, quals); 332462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 332562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // If that didn't change the element type, AT has no qualifiers, so we 332662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // can just use the results in splitType. 332762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (elementType == unqualElementType) { 332862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall assert(quals.empty()); // from the recursive call 3329200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals = splitType.Quals; 3330200fa53fd420aa8369586f569dbece04930ad6a3John McCall return QualType(splitType.Ty, 0); 333162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 333262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 333362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, add in the qualifiers from the outermost type, then 333462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // build the type back up. 3335200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals.addConsistentQualifiers(splitType.Quals); 333628e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 33379dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) { 333862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getConstantArrayType(unqualElementType, CAT->getSize(), 333928e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth CAT->getSizeModifier(), 0); 334028e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth } 334128e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 33429dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) { 334362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getIncompleteArrayType(unqualElementType, IAT->getSizeModifier(), 0); 334428e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth } 334528e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 33469dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(AT)) { 334762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getVariableArrayType(unqualElementType, 33483fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall VAT->getSizeExpr(), 33499dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor VAT->getSizeModifier(), 33509dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor VAT->getIndexTypeCVRQualifiers(), 33519dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor VAT->getBracketsRange()); 33529dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor } 33539dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor 33549dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor const DependentSizedArrayType *DSAT = cast<DependentSizedArrayType>(AT); 335562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getDependentSizedArrayType(unqualElementType, DSAT->getSizeExpr(), 335628e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth DSAT->getSizeModifier(), 0, 335728e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth SourceRange()); 335828e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth} 335928e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 33605a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// UnwrapSimilarPointerTypes - If T1 and T2 are pointer types that 33615a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// may be similar (C++ 4.4), replaces T1 and T2 with the type that 33625a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// they point to and return true. If T1 and T2 aren't pointer types 33635a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// or pointer-to-member types, or if they are not similar at this 33645a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// level, returns false and leaves T1 and T2 unchanged. Top-level 33655a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// qualifiers on T1 and T2 are ignored. This function will typically 33665a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// be called in a loop that successively "unwraps" pointer and 33675a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// pointer-to-member types to compare them at each level. 33685a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregorbool ASTContext::UnwrapSimilarPointerTypes(QualType &T1, QualType &T2) { 33695a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor const PointerType *T1PtrType = T1->getAs<PointerType>(), 33705a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor *T2PtrType = T2->getAs<PointerType>(); 33715a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor if (T1PtrType && T2PtrType) { 33725a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T1 = T1PtrType->getPointeeType(); 33735a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T2 = T2PtrType->getPointeeType(); 33745a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return true; 33755a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 33765a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 33775a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor const MemberPointerType *T1MPType = T1->getAs<MemberPointerType>(), 33785a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor *T2MPType = T2->getAs<MemberPointerType>(); 33795a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor if (T1MPType && T2MPType && 33805a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor hasSameUnqualifiedType(QualType(T1MPType->getClass(), 0), 33815a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor QualType(T2MPType->getClass(), 0))) { 33825a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T1 = T1MPType->getPointeeType(); 33835a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T2 = T2MPType->getPointeeType(); 33845a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return true; 33855a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 33865a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 33874e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().ObjC1) { 33885a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor const ObjCObjectPointerType *T1OPType = T1->getAs<ObjCObjectPointerType>(), 33895a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor *T2OPType = T2->getAs<ObjCObjectPointerType>(); 33905a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor if (T1OPType && T2OPType) { 33915a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T1 = T1OPType->getPointeeType(); 33925a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T2 = T2OPType->getPointeeType(); 33935a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return true; 33945a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 33955a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 33965a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 33975a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor // FIXME: Block pointers, too? 33985a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 33995a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return false; 34005a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor} 34015a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 34024ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDeclarationNameInfo 34034ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getNameForTemplate(TemplateName Name, 34044ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad SourceLocation NameLoc) const { 3405146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall switch (Name.getKind()) { 3406146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::QualifiedTemplate: 3407146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::Template: 34082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // DNInfo work in progress: CHECKME: what about DNLoc? 3409146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo(Name.getAsTemplateDecl()->getDeclName(), 3410146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall NameLoc); 34112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3412146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::OverloadedTemplate: { 3413146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall OverloadedTemplateStorage *Storage = Name.getAsOverloadedTemplate(); 3414146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall // DNInfo work in progress: CHECKME: what about DNLoc? 3415146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo((*Storage->begin())->getDeclName(), NameLoc); 3416146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3417146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3418146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::DependentTemplate: { 3419146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall DependentTemplateName *DTN = Name.getAsDependentTemplateName(); 34202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName DName; 342180ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall if (DTN->isIdentifier()) { 34222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DName = DeclarationNames.getIdentifier(DTN->getIdentifier()); 34232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(DName, NameLoc); 342480ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall } else { 34252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DName = DeclarationNames.getCXXOperatorName(DTN->getOperator()); 34262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // DNInfo work in progress: FIXME: source locations? 34272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 34282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DNLoc.CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding(); 34292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DNLoc.CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding(); 34302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(DName, NameLoc, DNLoc); 343180ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall } 343280ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall } 343380ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall 3434146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParm: { 3435146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 3436146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParm(); 3437146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo(subst->getParameter()->getDeclName(), 3438146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall NameLoc); 3439146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3440146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3441146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParmPack: { 3442146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmPackStorage *subst 3443146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParmPack(); 3444146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo(subst->getParameterPack()->getDeclName(), 3445146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall NameLoc); 3446146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3447146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3448146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3449146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm_unreachable("bad template name kind!"); 345080ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall} 345180ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall 34524ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) const { 3453146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall switch (Name.getKind()) { 3454146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::QualifiedTemplate: 3455146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::Template: { 3456146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateDecl *Template = Name.getAsTemplateDecl(); 34573e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (TemplateTemplateParmDecl *TTP 3458146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = dyn_cast<TemplateTemplateParmDecl>(Template)) 34593e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Template = getCanonicalTemplateTemplateParmDecl(TTP); 34603e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 34613e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // The canonical template name is the canonical template declaration. 346297fbaa2a38804268a024f1a104b43fcf8b4411b0Argyrios Kyrtzidis return TemplateName(cast<TemplateDecl>(Template->getCanonicalDecl())); 34633e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 346425a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 3465146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::OverloadedTemplate: 3466146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm_unreachable("cannot canonicalize overloaded template"); 3467146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3468146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::DependentTemplate: { 3469146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall DependentTemplateName *DTN = Name.getAsDependentTemplateName(); 3470146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall assert(DTN && "Non-dependent template names must refer to template decls."); 3471146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DTN->CanonicalTemplateName; 3472146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3473146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3474146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParm: { 3475146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 3476146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParm(); 3477146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return getCanonicalTemplateName(subst->getReplacement()); 34781aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 34791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3480146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParmPack: { 3481146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmPackStorage *subst 3482146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParmPack(); 3483146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateTemplateParmDecl *canonParameter 3484146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = getCanonicalTemplateTemplateParmDecl(subst->getParameterPack()); 3485146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateArgument canonArgPack 3486146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = getCanonicalTemplateArgument(subst->getArgumentPack()); 3487146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return getSubstTemplateTemplateParmPack(canonParameter, canonArgPack); 3488146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3489146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3490146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3491146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm_unreachable("bad template name!"); 349225a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor} 349325a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 3494db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregorbool ASTContext::hasSameTemplateName(TemplateName X, TemplateName Y) { 3495db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor X = getCanonicalTemplateName(X); 3496db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor Y = getCanonicalTemplateName(Y); 3497db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor return X.getAsVoidPointer() == Y.getAsVoidPointer(); 3498db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor} 3499db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor 35001eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateArgument 35014ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const { 35021275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor switch (Arg.getKind()) { 35031275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Null: 35041275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 35051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35061275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Expression: 35071275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 35081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3509d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor case TemplateArgument::Declaration: { 3510d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor if (Decl *D = Arg.getAsDecl()) 3511d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor return TemplateArgument(D->getCanonicalDecl()); 3512d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor return TemplateArgument((Decl*)0); 3513d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor } 35141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3515788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 3516788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate())); 3517a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 3518a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 3519a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgument(getCanonicalTemplateName( 3520a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Arg.getAsTemplateOrTemplatePattern()), 35212be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor Arg.getNumTemplateExpansions()); 3522a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 35231275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Integral: 3524855243789cb44799c03f4c7216d3d6308805f549Benjamin Kramer return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType())); 35251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35261275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Type: 3527833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return TemplateArgument(getCanonicalType(Arg.getAsType())); 35281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35291275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Pack: { 353087dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor if (Arg.pack_size() == 0) 353187dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor return Arg; 353287dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor 3533910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *CanonArgs 3534910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (*this) TemplateArgument[Arg.pack_size()]; 35351275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor unsigned Idx = 0; 35361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 35371275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor AEnd = Arg.pack_end(); 35381275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor A != AEnd; (void)++A, ++Idx) 35391275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs[Idx] = getCanonicalTemplateArgument(*A); 35401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3541910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor return TemplateArgument(CanonArgs, Arg.pack_size()); 35421275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 35431275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 35441275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 35451275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Silence GCC warning 3546b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unhandled template argument kind"); 35471275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor} 35481275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 3549d57959af02b4af695276f4204443afe6e5d86bd8Douglas GregorNestedNameSpecifier * 35504ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const { 35511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (!NNS) 3552d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return 0; 3553d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3554d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor switch (NNS->getKind()) { 3555d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Identifier: 3556d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // Canonicalize the prefix but keep the identifier the same. 35571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return NestedNameSpecifier::Create(*this, 3558d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor getCanonicalNestedNameSpecifier(NNS->getPrefix()), 3559d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NNS->getAsIdentifier()); 3560d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3561d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Namespace: 3562d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // A namespace is canonical; build a nested-name-specifier with 3563d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // this namespace and no prefix. 356414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor return NestedNameSpecifier::Create(*this, 0, 356514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NNS->getAsNamespace()->getOriginalNamespace()); 356614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 356714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor case NestedNameSpecifier::NamespaceAlias: 356814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor // A namespace is canonical; build a nested-name-specifier with 356914aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor // this namespace and no prefix. 357014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor return NestedNameSpecifier::Create(*this, 0, 357114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NNS->getAsNamespaceAlias()->getNamespace() 357214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor ->getOriginalNamespace()); 3573d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3574d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpec: 3575d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: { 3576d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType T = getCanonicalType(QualType(NNS->getAsType(), 0)); 3577264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor 3578264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // If we have some kind of dependent-named type (e.g., "typename T::type"), 3579264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // break it apart into its prefix and identifier, then reconsititute those 3580264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // as the canonical nested-name-specifier. This is required to canonicalize 3581264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // a dependent nested-name-specifier involving typedefs of dependent-name 3582264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // types, e.g., 3583264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // typedef typename T::type T1; 3584264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // typedef typename T1::type T2; 358516412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman if (const DependentNameType *DNT = T->getAs<DependentNameType>()) 358616412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman return NestedNameSpecifier::Create(*this, DNT->getQualifier(), 3587264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor const_cast<IdentifierInfo *>(DNT->getIdentifier())); 3588264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor 358916412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman // Otherwise, just canonicalize the type, and force it to be a TypeSpec. 359016412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman // FIXME: Why are TypeSpec and TypeSpecWithTemplate distinct in the 359116412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman // first place? 35923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return NestedNameSpecifier::Create(*this, 0, false, 35933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const_cast<Type*>(T.getTypePtr())); 3594d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3595d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3596d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Global: 3597d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // The global specifier is canonical and unique. 3598d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return NNS; 3599d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3600d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 36017530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid NestedNameSpecifier::Kind!"); 3602d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 3603d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3604c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 36054ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadconst ArrayType *ASTContext::getAsArrayType(QualType T) const { 3606c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the non-qualified case efficiently. 3607a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (!T.hasLocalQualifiers()) { 3608c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the common positive case fast. 3609c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(T)) 3610c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT; 3611c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 36121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Handle the common negative case fast. 36143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isa<ArrayType>(T.getCanonicalType())) 3615c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 36161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Apply any qualifiers from the array type to the element type. This 3618c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // implements C99 6.7.3p8: "If the specification of an array type includes 3619c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // any type qualifiers, the element type is so qualified, not the array type." 36201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3621c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we get here, we either have type qualifiers on the type, or we have 3622c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // sugar such as a typedef in the way. If we have type qualifiers on the type 362350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor // we must propagate them down into the element type. 36240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 36253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split = T.getSplitDesugaredType(); 3626200fa53fd420aa8369586f569dbece04930ad6a3John McCall Qualifiers qs = split.Quals; 36271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3628c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we have a simple case, just return now. 3629200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ArrayType *ATy = dyn_cast<ArrayType>(split.Ty); 36303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (ATy == 0 || qs.empty()) 3631c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy; 36321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3633c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Otherwise, we have an array and we have qualifiers on it. Push the 3634c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // qualifiers into the array element type and return a new array type. 36353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType NewEltTy = getQualifiedType(ATy->getElementType(), qs); 36361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3637c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(ATy)) 3638c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getConstantArrayType(NewEltTy, CAT->getSize(), 3639c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner CAT->getSizeModifier(), 36400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CAT->getIndexTypeCVRQualifiers())); 3641c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(ATy)) 3642c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getIncompleteArrayType(NewEltTy, 3643c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner IAT->getSizeModifier(), 36440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall IAT->getIndexTypeCVRQualifiers())); 3645898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 36461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const DependentSizedArrayType *DSAT 3647898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor = dyn_cast<DependentSizedArrayType>(ATy)) 3648898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return cast<ArrayType>( 36491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDependentSizedArrayType(NewEltTy, 36503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall DSAT->getSizeExpr(), 3651898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DSAT->getSizeModifier(), 36520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall DSAT->getIndexTypeCVRQualifiers(), 36537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor DSAT->getBracketsRange())); 36541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3655c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const VariableArrayType *VAT = cast<VariableArrayType>(ATy); 36567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return cast<ArrayType>(getVariableArrayType(NewEltTy, 36573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall VAT->getSizeExpr(), 3658c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner VAT->getSizeModifier(), 36590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall VAT->getIndexTypeCVRQualifiers(), 36607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor VAT->getBracketsRange())); 366177c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner} 366277c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner 3663ad9689f3531c49e4bff467d9469993606800068cAbramo BagnaraQualType ASTContext::getAdjustedParameterType(QualType T) const { 366479e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // C99 6.7.5.3p7: 366579e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // A declaration of a parameter as "array of type" shall be 366679e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // adjusted to "qualified pointer to type", where the type 366779e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // qualifiers (if any) are those specified within the [ and ] of 366879e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // the array type derivation. 366979e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor if (T->isArrayType()) 367079e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return getArrayDecayedType(T); 367179e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 367279e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // C99 6.7.5.3p8: 367379e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // A declaration of a parameter as "function returning type" 367479e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // shall be adjusted to "pointer to function returning type", as 367579e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // in 6.3.2.1. 367679e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor if (T->isFunctionType()) 367779e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return getPointerType(T); 367879e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 367979e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return T; 368079e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor} 368179e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 3682ad9689f3531c49e4bff467d9469993606800068cAbramo BagnaraQualType ASTContext::getSignatureParameterType(QualType T) const { 368379e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor T = getVariableArrayDecayedType(T); 368479e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor T = getAdjustedParameterType(T); 368579e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return T.getUnqualifiedType(); 368679e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor} 368779e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 3688e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// getArrayDecayedType - Return the properly qualified result of decaying the 3689e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// specified array type to a pointer. This operation is non-trivial when 3690e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// handling typedefs etc. The canonical type of "T" must be an array type, 3691e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// this returns a pointer to a properly qualified element of the array. 3692e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// 3693e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 36944ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getArrayDecayedType(QualType Ty) const { 3695c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Get the element type with 'getAsArrayType' so that we don't lose any 3696c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // typedefs in the element type of the array. This also handles propagation 3697c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // of type qualifiers from the array type into the element type if present 3698c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // (C99 6.7.3p8). 3699c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const ArrayType *PrettyArrayType = getAsArrayType(Ty); 3700c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner assert(PrettyArrayType && "Not an array type!"); 37011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3702c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType PtrTy = getPointerType(PrettyArrayType->getElementType()); 3703e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 3704e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner // int x[restrict 4] -> int *restrict 37050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getQualifiedType(PtrTy, PrettyArrayType->getIndexTypeQualifiers()); 3706e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner} 3707e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 37083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getBaseElementType(const ArrayType *array) const { 37093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getBaseElementType(array->getElementType()); 37105e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 37115e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 37123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getBaseElementType(QualType type) const { 37133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers qs; 37143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall while (true) { 37153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split = type.getSplitDesugaredType(); 3716200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ArrayType *array = split.Ty->getAsArrayTypeUnsafe(); 37173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!array) break; 37181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall type = array->getElementType(); 3720200fa53fd420aa8369586f569dbece04930ad6a3John McCall qs.addConsistentQualifiers(split.Quals); 37213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 37221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiedType(type, qs); 37246183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson} 37256183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson 37260de78998e7bda473b408437053e48661b510d453Fariborz Jahanian/// getConstantArrayElementCount - Returns number of constant array elements. 37271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpuint64_t 37280de78998e7bda473b408437053e48661b510d453Fariborz JahanianASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) const { 37290de78998e7bda473b408437053e48661b510d453Fariborz Jahanian uint64_t ElementCount = 1; 37300de78998e7bda473b408437053e48661b510d453Fariborz Jahanian do { 37310de78998e7bda473b408437053e48661b510d453Fariborz Jahanian ElementCount *= CA->getSize().getZExtValue(); 37320de78998e7bda473b408437053e48661b510d453Fariborz Jahanian CA = dyn_cast<ConstantArrayType>(CA->getElementType()); 37330de78998e7bda473b408437053e48661b510d453Fariborz Jahanian } while (CA); 37340de78998e7bda473b408437053e48661b510d453Fariborz Jahanian return ElementCount; 37350de78998e7bda473b408437053e48661b510d453Fariborz Jahanian} 37360de78998e7bda473b408437053e48661b510d453Fariborz Jahanian 37375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFloatingRank - Return a relative rank for floating point types. 37385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// This routine will assert if passed a built-in type that isn't a float. 3739a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattnerstatic FloatingRank getFloatingRank(QualType T) { 3740183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType *CT = T->getAs<ComplexType>()) 37415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getFloatingRank(CT->getElementType()); 3742a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner 3743183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall assert(T->getAs<BuiltinType>() && "getFloatingRank(): not a floating type"); 3744183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall switch (T->getAs<BuiltinType>()->getKind()) { 3745b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("getFloatingRank(): not a floating type"); 3746aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case BuiltinType::Half: return HalfRank; 37475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Float: return FloatRank; 37485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Double: return DoubleRank; 37495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::LongDouble: return LongDoubleRank; 37505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 37515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 37525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 37531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getFloatingTypeOfSizeWithinDomain - Returns a real floating 37541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// point or a complex type (based on typeDomain/typeSize). 3755716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeDomain' is a real floating point or complex type. 3756716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeSize' is a real floating point or complex type. 37571361b11066239ea15764a2a844405352d87296b3Chris LattnerQualType ASTContext::getFloatingTypeOfSizeWithinDomain(QualType Size, 37581361b11066239ea15764a2a844405352d87296b3Chris Lattner QualType Domain) const { 37591361b11066239ea15764a2a844405352d87296b3Chris Lattner FloatingRank EltRank = getFloatingRank(Size); 37601361b11066239ea15764a2a844405352d87296b3Chris Lattner if (Domain->isComplexType()) { 37611361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 3762561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie case HalfRank: llvm_unreachable("Complex half is not supported"); 3763f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case FloatRank: return FloatComplexTy; 3764f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case DoubleRank: return DoubleComplexTy; 3765f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case LongDoubleRank: return LongDoubleComplexTy; 3766f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 3767f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 37681361b11066239ea15764a2a844405352d87296b3Chris Lattner 37691361b11066239ea15764a2a844405352d87296b3Chris Lattner assert(Domain->isRealFloatingType() && "Unknown domain!"); 37701361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 3771561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie case HalfRank: llvm_unreachable("Half ranks are not valid here"); 37721361b11066239ea15764a2a844405352d87296b3Chris Lattner case FloatRank: return FloatTy; 37731361b11066239ea15764a2a844405352d87296b3Chris Lattner case DoubleRank: return DoubleTy; 37741361b11066239ea15764a2a844405352d87296b3Chris Lattner case LongDoubleRank: return LongDoubleTy; 37755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3776561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie llvm_unreachable("getFloatingRank(): illegal value for rank"); 37775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 37785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 37797cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// getFloatingTypeOrder - Compare the rank of the two specified floating 37807cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// point types, ignoring the domain of the type (i.e. 'double' == 37817cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If 37821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// LHS < RHS, return -1. 37834ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadint ASTContext::getFloatingTypeOrder(QualType LHS, QualType RHS) const { 3784a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank LHSR = getFloatingRank(LHS); 3785a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank RHSR = getFloatingRank(RHS); 37861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3787a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR == RHSR) 3788fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 0; 3789a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR > RHSR) 3790fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 1; 3791fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return -1; 37925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 37935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3794f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This 3795f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// routine will assert if passed a built-in type that isn't an integer or enum, 3796f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// or if it is not canonicalized. 3797f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCallunsigned ASTContext::getIntegerRank(const Type *T) const { 3798467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall assert(T->isCanonicalUnqualified() && "T should be canonicalized"); 3799f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 3800f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 3801b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("getIntegerRank(): not a built-in integer"); 38027cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Bool: 3803f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 1 + (getIntWidth(BoolTy) << 3); 38047cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_S: 38057cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_U: 38067cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::SChar: 38077cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UChar: 3808f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 2 + (getIntWidth(CharTy) << 3); 38097cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Short: 38107cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UShort: 3811f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 3 + (getIntWidth(ShortTy) << 3); 38127cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Int: 38137cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UInt: 3814f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 4 + (getIntWidth(IntTy) << 3); 38157cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Long: 38167cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULong: 3817f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 5 + (getIntWidth(LongTy) << 3); 38187cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::LongLong: 38197cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULongLong: 3820f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 6 + (getIntWidth(LongLongTy) << 3); 38212df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 38222df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::UInt128: 38232df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return 7 + (getIntWidth(Int128Ty) << 3); 3824f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner } 3825f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner} 3826f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner 382704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \brief Whether this is a promotable bitfield reference according 382804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 382904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// 383004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \returns the type this bit-field will promote to, or NULL if no 383104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// promotion occurs. 38324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::isPromotableBitField(Expr *E) const { 3833ceafbdeb93ecf323cca74e660bf54504c86f3b71Douglas Gregor if (E->isTypeDependent() || E->isValueDependent()) 3834ceafbdeb93ecf323cca74e660bf54504c86f3b71Douglas Gregor return QualType(); 3835ceafbdeb93ecf323cca74e660bf54504c86f3b71Douglas Gregor 383604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman FieldDecl *Field = E->getBitField(); 383704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (!Field) 383804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 383904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 384004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman QualType FT = Field->getType(); 384104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 3842a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith uint64_t BitWidth = Field->getBitWidthValue(*this); 384304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 384404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // GCC extension compatibility: if the bit-field size is less than or equal 384504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // to the size of int, it gets promoted no matter what its type is. 384604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // For instance, unsigned long bf : 4 gets promoted to signed int. 384704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth < IntSize) 384804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return IntTy; 384904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 385004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth == IntSize) 385104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return FT->isSignedIntegerType() ? IntTy : UnsignedIntTy; 385204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 385304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // Types bigger than int are not subject to promotions, and therefore act 385404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // like the base type. 385504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // FIXME: This doesn't quite match what gcc does, but what gcc does here 385604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // is ridiculous. 385704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 385804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman} 385904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 3860a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// getPromotedIntegerType - Returns the type that Promotable will 3861a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable 3862a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// integer type. 38634ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getPromotedIntegerType(QualType Promotable) const { 3864a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(!Promotable.isNull()); 3865a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isPromotableIntegerType()); 3866842aef8d942a880eeb9535d40de31a86838264cbJohn McCall if (const EnumType *ET = Promotable->getAs<EnumType>()) 3867842aef8d942a880eeb9535d40de31a86838264cbJohn McCall return ET->getDecl()->getPromotionType(); 386868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman 386968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman if (const BuiltinType *BT = Promotable->getAs<BuiltinType>()) { 387068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // C++ [conv.prom]: A prvalue of type char16_t, char32_t, or wchar_t 387168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // (3.9.1) can be converted to a prvalue of the first of the following 387268a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // types that can represent all the values of its underlying type: 387368a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // int, unsigned int, long int, unsigned long int, long long int, or 387468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // unsigned long long int [...] 387568a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // FIXME: Is there some better way to compute this? 387668a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman if (BT->getKind() == BuiltinType::WChar_S || 387768a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman BT->getKind() == BuiltinType::WChar_U || 387868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman BT->getKind() == BuiltinType::Char16 || 387968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman BT->getKind() == BuiltinType::Char32) { 388068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman bool FromIsSigned = BT->getKind() == BuiltinType::WChar_S; 388168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman uint64_t FromSize = getTypeSize(BT); 388268a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman QualType PromoteTypes[] = { IntTy, UnsignedIntTy, LongTy, UnsignedLongTy, 388368a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman LongLongTy, UnsignedLongLongTy }; 388468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman for (size_t Idx = 0; Idx < llvm::array_lengthof(PromoteTypes); ++Idx) { 388568a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman uint64_t ToSize = getTypeSize(PromoteTypes[Idx]); 388668a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman if (FromSize < ToSize || 388768a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman (FromSize == ToSize && 388868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) 388968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman return PromoteTypes[Idx]; 389068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman } 389168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman llvm_unreachable("char type should fit into long long"); 389268a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman } 389368a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman } 389468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman 389568a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // At this point, we should have a signed or unsigned integer type. 3896a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (Promotable->isSignedIntegerType()) 3897a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return IntTy; 3898a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t PromotableSize = getTypeSize(Promotable); 3899a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 3900a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isUnsignedIntegerType() && PromotableSize <= IntSize); 3901a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy; 3902a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman} 3903a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 390431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis/// \brief Recurses in pointer/array types until it finds an objc retainable 390531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis/// type and returns its ownership. 390631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios KyrtzidisQualifiers::ObjCLifetime ASTContext::getInnerObjCOwnership(QualType T) const { 390731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis while (!T.isNull()) { 390831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (T.getObjCLifetime() != Qualifiers::OCL_None) 390931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return T.getObjCLifetime(); 391031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (T->isArrayType()) 391131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis T = getBaseElementType(T); 391231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis else if (const PointerType *PT = T->getAs<PointerType>()) 391331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis T = PT->getPointeeType(); 391431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 391528445f0b62f6aed851ff87ce64d9b19200d3211fArgyrios Kyrtzidis T = RT->getPointeeType(); 391631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis else 391731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis break; 391831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } 391931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 392031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return Qualifiers::OCL_None; 392131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis} 392231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 39231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getIntegerTypeOrder - Returns the highest ranked integer type: 39247cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If 39251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// LHS < RHS, return -1. 39264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadint ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const { 3927f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *LHSC = getCanonicalType(LHS).getTypePtr(); 3928f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *RHSC = getCanonicalType(RHS).getTypePtr(); 39297cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSC == RHSC) return 0; 39301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3931f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool LHSUnsigned = LHSC->isUnsignedIntegerType(); 3932f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool RHSUnsigned = RHSC->isUnsignedIntegerType(); 39331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39347cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned LHSRank = getIntegerRank(LHSC); 39357cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned RHSRank = getIntegerRank(RHSC); 39361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39377cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned == RHSUnsigned) { // Both signed or both unsigned. 39387cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank == RHSRank) return 0; 39397cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return LHSRank > RHSRank ? 1 : -1; 39407cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 39411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39427cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // Otherwise, the LHS is signed and the RHS is unsigned or visa versa. 39437cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned) { 39447cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [LHS] type is larger, return it. 39457cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank >= RHSRank) 39467cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 39471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39487cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 39497cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 39501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // powers of two larger than each other, this is always safe. 39517cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 39527cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 39537cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner 39547cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [RHS] type is larger, return it. 39557cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (RHSRank >= LHSRank) 39567cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 39571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39587cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 39597cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 39601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // powers of two larger than each other, this is always safe. 39617cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 39625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 396371993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson 396479cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlssonstatic RecordDecl * 3965ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo BagnaraCreateRecordDecl(const ASTContext &Ctx, RecordDecl::TagKind TK, 3966ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara DeclContext *DC, IdentifierInfo *Id) { 3967ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara SourceLocation Loc; 39684e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Ctx.getLangOpts().CPlusPlus) 3969ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara return CXXRecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id); 397079cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson else 3971ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara return RecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id); 397279cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson} 3973ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara 39741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// getCFConstantStringType - Return the type used for constant CFStrings. 39754ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getCFConstantStringType() const { 397671993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson if (!CFConstantStringTypeDecl) { 39771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CFConstantStringTypeDecl = 3978ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara CreateRecordDecl(*this, TTK_Struct, TUDecl, 397979cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson &Idents.get("NSConstantString")); 39805cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall CFConstantStringTypeDecl->startDefinition(); 398179cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson 3982f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson QualType FieldTypes[4]; 39831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 398471993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const int *isa; 39850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FieldTypes[0] = getPointerType(IntTy.withConst()); 3986f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson // int flags; 3987f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson FieldTypes[1] = IntTy; 398871993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const char *str; 39890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FieldTypes[2] = getPointerType(CharTy.withConst()); 399071993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // long length; 39911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FieldTypes[3] = LongTy; 39921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 399344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor // Create fields 399444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor for (unsigned i = 0; i < 4; ++i) { 39951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl, 3996ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 399744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor SourceLocation(), 0, 3998a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 39991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /*BitWidth=*/0, 40007a614d8380297fcd2bc23986241905d97222948cRichard Smith /*Mutable=*/false, 4001ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 40022888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 400317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis CFConstantStringTypeDecl->addDecl(Field); 400444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 400544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4006838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor CFConstantStringTypeDecl->completeDefinition(); 400771993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson } 40081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 400971993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson return getTagDeclType(CFConstantStringTypeDecl); 40108467583c2704e7a9691ea56939a029015f0ade0aGabor Greif} 4011b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson 4012319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregorvoid ASTContext::setCFConstantStringType(QualType T) { 40136217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek const RecordType *Rec = T->getAs<RecordType>(); 4014319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor assert(Rec && "Invalid CFConstantStringType"); 4015319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor CFConstantStringTypeDecl = Rec->getDecl(); 4016319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor} 4017319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor 40184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getBlockDescriptorType() const { 4019adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump if (BlockDescriptorType) 4020adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump return getTagDeclType(BlockDescriptorType); 4021adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4022adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump RecordDecl *T; 4023adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump // FIXME: Needs the FlagAppleBlock bit. 4024ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara T = CreateRecordDecl(*this, TTK_Struct, TUDecl, 402579cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson &Idents.get("__block_descriptor")); 40265cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall T->startDefinition(); 4027adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4028adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump QualType FieldTypes[] = { 4029adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump UnsignedLongTy, 4030adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump UnsignedLongTy, 4031adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump }; 4032adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4033adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump const char *FieldNames[] = { 4034adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump "reserved", 4035083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "Size" 4036adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump }; 4037adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4038adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump for (size_t i = 0; i < 2; ++i) { 4039ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara FieldDecl *Field = FieldDecl::Create(*this, T, SourceLocation(), 4040adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump SourceLocation(), 4041adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump &Idents.get(FieldNames[i]), 4042a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 4043adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump /*BitWidth=*/0, 40447a614d8380297fcd2bc23986241905d97222948cRichard Smith /*Mutable=*/false, 4045ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 40462888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 4047adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump T->addDecl(Field); 4048adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump } 4049adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4050838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor T->completeDefinition(); 4051adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4052adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump BlockDescriptorType = T; 4053adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4054adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump return getTagDeclType(BlockDescriptorType); 4055adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump} 4056adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 40574ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getBlockDescriptorExtendedType() const { 4058083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump if (BlockDescriptorExtendedType) 4059083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump return getTagDeclType(BlockDescriptorExtendedType); 4060083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4061083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump RecordDecl *T; 4062083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump // FIXME: Needs the FlagAppleBlock bit. 4063ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara T = CreateRecordDecl(*this, TTK_Struct, TUDecl, 406479cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson &Idents.get("__block_descriptor_withcopydispose")); 40655cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall T->startDefinition(); 4066083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4067083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump QualType FieldTypes[] = { 4068083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump UnsignedLongTy, 4069083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump UnsignedLongTy, 4070083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump getPointerType(VoidPtrTy), 4071083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump getPointerType(VoidPtrTy) 4072083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump }; 4073083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4074083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump const char *FieldNames[] = { 4075083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "reserved", 4076083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "Size", 4077083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "CopyFuncPtr", 4078083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "DestroyFuncPtr" 4079083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump }; 4080083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4081083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump for (size_t i = 0; i < 4; ++i) { 4082ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara FieldDecl *Field = FieldDecl::Create(*this, T, SourceLocation(), 4083083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump SourceLocation(), 4084083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump &Idents.get(FieldNames[i]), 4085a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 4086083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump /*BitWidth=*/0, 40877a614d8380297fcd2bc23986241905d97222948cRichard Smith /*Mutable=*/false, 4088ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 40892888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 4090083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump T->addDecl(Field); 4091083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump } 4092083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4093838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor T->completeDefinition(); 4094083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4095083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump BlockDescriptorExtendedType = T; 4096083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4097083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump return getTagDeclType(BlockDescriptorExtendedType); 4098083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump} 4099083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 41004ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ASTContext::BlockRequiresCopying(QualType Ty) const { 4101f85e193739c953358c865005855253af4f68a497John McCall if (Ty->isObjCRetainableType()) 4102af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump return true; 41034e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) { 4104e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian if (const RecordType *RT = Ty->getAs<RecordType>()) { 4105e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); 4106ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Hunt return RD->hasConstCopyConstructor(); 4107e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian 4108e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian } 4109e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian } 4110af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump return false; 4111af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump} 4112af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 41134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 41145f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerASTContext::BuildByRefType(StringRef DeclName, QualType Ty) const { 4115af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // type = struct __Block_byref_1_X { 4116ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // void *__isa; 4117af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // struct __Block_byref_1_X *__forwarding; 4118ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // unsigned int __flags; 4119ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // unsigned int __size; 4120a7e6845660f91ec611427e1db842780e1ec12bdbEli Friedman // void *__copy_helper; // as needed 4121a7e6845660f91ec611427e1db842780e1ec12bdbEli Friedman // void *__destroy_help // as needed 4122af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // int X; 4123ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // } * 4124ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump 4125af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump bool HasCopyAndDispose = BlockRequiresCopying(Ty); 4126af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4127af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // FIXME: Move up 4128f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<36> Name; 4129f5942a44880be26878592eb052b737579349411eBenjamin Kramer llvm::raw_svector_ostream(Name) << "__Block_byref_" << 4130f5942a44880be26878592eb052b737579349411eBenjamin Kramer ++UniqueBlockByRefTypeID << '_' << DeclName; 4131af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump RecordDecl *T; 4132ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara T = CreateRecordDecl(*this, TTK_Struct, TUDecl, &Idents.get(Name.str())); 4133af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump T->startDefinition(); 4134af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump QualType Int32Ty = IntTy; 4135af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump assert(getIntWidth(IntTy) == 32 && "non-32bit int not supported"); 4136af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump QualType FieldTypes[] = { 4137af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(VoidPtrTy), 4138af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(getTagDeclType(T)), 4139af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump Int32Ty, 4140af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump Int32Ty, 4141af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(VoidPtrTy), 4142af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(VoidPtrTy), 4143af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump Ty 4144af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump }; 4145af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 41465f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef FieldNames[] = { 4147af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__isa", 4148af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__forwarding", 4149af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__flags", 4150af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__size", 4151af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__copy_helper", 4152af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__destroy_helper", 4153af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump DeclName, 4154af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump }; 4155af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4156af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump for (size_t i = 0; i < 7; ++i) { 4157af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump if (!HasCopyAndDispose && i >=4 && i <= 5) 4158af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump continue; 4159af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump FieldDecl *Field = FieldDecl::Create(*this, T, SourceLocation(), 4160ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 4161af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump &Idents.get(FieldNames[i]), 4162a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 41637a614d8380297fcd2bc23986241905d97222948cRichard Smith /*BitWidth=*/0, /*Mutable=*/false, 4164ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 41652888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 4166af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump T->addDecl(Field); 4167af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump } 4168af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4169838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor T->completeDefinition(); 4170af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4171af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump return getPointerType(getTagDeclType(T)); 4172ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump} 4173ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump 4174e97179c675b341927807c718be215c8d1aab8acbDouglas GregorTypedefDecl *ASTContext::getObjCInstanceTypeDecl() { 4175e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor if (!ObjCInstanceTypeDecl) 4176e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor ObjCInstanceTypeDecl = TypedefDecl::Create(*this, 4177e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor getTranslationUnitDecl(), 4178e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor SourceLocation(), 4179e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor SourceLocation(), 4180e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor &Idents.get("instancetype"), 4181e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor getTrivialTypeSourceInfo(getObjCIdType())); 4182e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor return ObjCInstanceTypeDecl; 4183e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor} 4184e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor 4185e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// This returns true if a type has been typedefed to BOOL: 4186e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// typedef <type> BOOL; 41872d99833e8c956775f2183601cd120b65b569c867Chris Lattnerstatic bool isTypeTypedefedAsBOOL(QualType T) { 4188e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (const TypedefType *TT = dyn_cast<TypedefType>(T)) 4189bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner if (IdentifierInfo *II = TT->getDecl()->getIdentifier()) 4190bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner return II->isStr("BOOL"); 41911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 419285f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return false; 419385f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 419485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 4195a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingTypeSize returns size of type for objective-c encoding 419633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// purpose. 41974ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getObjCEncodingTypeSize(QualType type) const { 4198f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor if (!type->isIncompleteArrayType() && type->isIncompleteType()) 4199f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor return CharUnits::Zero(); 4200f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor 4201199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits sz = getTypeSizeInChars(type); 42021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 420333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Make all integer and enum types at least as large as an int 42042ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (sz.isPositive() && type->isIntegralOrEnumerationType()) 4205199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck sz = std::max(sz, getTypeSizeInChars(IntTy)); 420633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Treat arrays as pointers, since that's how they're passed in. 420733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian else if (type->isArrayType()) 4208199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck sz = getTypeSizeInChars(VoidPtrTy); 4209aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck return sz; 4210199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck} 4211199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck 4212199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyckstatic inline 4213199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyckstd::string charUnitsToString(const CharUnits &CU) { 4214199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck return llvm::itostr(CU.getQuantity()); 421533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 421633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 42176b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// getObjCEncodingForBlock - Return the encoded type for this block 42185e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall/// declaration. 42196b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCallstd::string ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr) const { 42206b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall std::string S; 42216b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall 42225e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall const BlockDecl *Decl = Expr->getBlockDecl(); 42235e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall QualType BlockTy = 42245e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall Expr->getType()->getAs<BlockPointerType>()->getPointeeType(); 42255e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Encode result type. 4226c71a4915ca216847599d03cab4ed1c5086b0eb43John McCall getObjCEncodingForType(BlockTy->getAs<FunctionType>()->getResultType(), S); 42275e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Compute size of all parameters. 42285e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Start with computing size of a pointer in number of bytes. 42295e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // FIXME: There might(should) be a better way of doing this computation! 42305e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall SourceLocation Loc; 4231199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits PtrSize = getTypeSizeInChars(VoidPtrTy); 4232199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits ParmOffset = PtrSize; 42336f46c2653c1545cc3fef0c0df996d18160160ce8Fariborz Jahanian for (BlockDecl::param_const_iterator PI = Decl->param_begin(), 42345e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall E = Decl->param_end(); PI != E; ++PI) { 42355e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall QualType PType = (*PI)->getType(); 4236aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck CharUnits sz = getObjCEncodingTypeSize(PType); 4237075a54354dc6e3644b12206e5127855091783fd6Fariborz Jahanian if (sz.isZero()) 4238075a54354dc6e3644b12206e5127855091783fd6Fariborz Jahanian continue; 4239199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck assert (sz.isPositive() && "BlockExpr - Incomplete param type"); 42405e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall ParmOffset += sz; 42415e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall } 42425e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Size of the argument frame 4243199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 42445e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Block pointer and offset. 42455e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall S += "@?0"; 42465e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall 42475e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Argument types. 42485e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall ParmOffset = PtrSize; 42495e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall for (BlockDecl::param_const_iterator PI = Decl->param_begin(), E = 42505e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall Decl->param_end(); PI != E; ++PI) { 42515e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall ParmVarDecl *PVDecl = *PI; 42525e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall QualType PType = PVDecl->getOriginalType(); 42535e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall if (const ArrayType *AT = 42545e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 42555e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Use array's original type only if it has known number of 42565389f48b24937ad7b4093307128b3cbf25235654David Chisnall // elements. 42575389f48b24937ad7b4093307128b3cbf25235654David Chisnall if (!isa<ConstantArrayType>(AT)) 42585389f48b24937ad7b4093307128b3cbf25235654David Chisnall PType = PVDecl->getType(); 42595389f48b24937ad7b4093307128b3cbf25235654David Chisnall } else if (PType->isFunctionType()) 42605389f48b24937ad7b4093307128b3cbf25235654David Chisnall PType = PVDecl->getType(); 42615389f48b24937ad7b4093307128b3cbf25235654David Chisnall getObjCEncodingForType(PType, S); 42625389f48b24937ad7b4093307128b3cbf25235654David Chisnall S += charUnitsToString(ParmOffset); 42635389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmOffset += getObjCEncodingTypeSize(PType); 42645389f48b24937ad7b4093307128b3cbf25235654David Chisnall } 42656b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall 42666b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall return S; 42675389f48b24937ad7b4093307128b3cbf25235654David Chisnall} 42685389f48b24937ad7b4093307128b3cbf25235654David Chisnall 4269f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregorbool ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, 42705389f48b24937ad7b4093307128b3cbf25235654David Chisnall std::string& S) { 42715389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Encode result type. 42725389f48b24937ad7b4093307128b3cbf25235654David Chisnall getObjCEncodingForType(Decl->getResultType(), S); 42735389f48b24937ad7b4093307128b3cbf25235654David Chisnall CharUnits ParmOffset; 42745389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Compute size of all parameters. 42755389f48b24937ad7b4093307128b3cbf25235654David Chisnall for (FunctionDecl::param_const_iterator PI = Decl->param_begin(), 42765389f48b24937ad7b4093307128b3cbf25235654David Chisnall E = Decl->param_end(); PI != E; ++PI) { 42775389f48b24937ad7b4093307128b3cbf25235654David Chisnall QualType PType = (*PI)->getType(); 42785389f48b24937ad7b4093307128b3cbf25235654David Chisnall CharUnits sz = getObjCEncodingTypeSize(PType); 4279f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor if (sz.isZero()) 42807e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian continue; 42817e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian 42825389f48b24937ad7b4093307128b3cbf25235654David Chisnall assert (sz.isPositive() && 4283f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor "getObjCEncodingForFunctionDecl - Incomplete param type"); 42845389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmOffset += sz; 42855389f48b24937ad7b4093307128b3cbf25235654David Chisnall } 42865389f48b24937ad7b4093307128b3cbf25235654David Chisnall S += charUnitsToString(ParmOffset); 42875389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmOffset = CharUnits::Zero(); 42885389f48b24937ad7b4093307128b3cbf25235654David Chisnall 42895389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Argument types. 42905389f48b24937ad7b4093307128b3cbf25235654David Chisnall for (FunctionDecl::param_const_iterator PI = Decl->param_begin(), 42915389f48b24937ad7b4093307128b3cbf25235654David Chisnall E = Decl->param_end(); PI != E; ++PI) { 42925389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmVarDecl *PVDecl = *PI; 42935389f48b24937ad7b4093307128b3cbf25235654David Chisnall QualType PType = PVDecl->getOriginalType(); 42945389f48b24937ad7b4093307128b3cbf25235654David Chisnall if (const ArrayType *AT = 42955389f48b24937ad7b4093307128b3cbf25235654David Chisnall dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 42965389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Use array's original type only if it has known number of 42975e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // elements. 42985e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall if (!isa<ConstantArrayType>(AT)) 42995e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall PType = PVDecl->getType(); 43005e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall } else if (PType->isFunctionType()) 43015e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall PType = PVDecl->getType(); 43025e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall getObjCEncodingForType(PType, S); 4303199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 4304aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck ParmOffset += getObjCEncodingTypeSize(PType); 43055e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall } 4306f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor 4307f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor return false; 43085e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall} 43095e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall 4310dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson/// getObjCEncodingForMethodParameter - Return the encoded type for a single 4311dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson/// method parameter or return type. If Extended, include class names and 4312dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson/// block object types. 4313dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilsonvoid ASTContext::getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT, 4314dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson QualType T, std::string& S, 4315dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool Extended) const { 4316dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Encode type qualifer, 'in', 'inout', etc. for the parameter. 4317dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeQualifier(QT, S); 4318dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Encode parameter type. 4319dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeImpl(T, S, true, true, 0, 4320dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson true /*OutermostType*/, 4321dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /*EncodingProperty*/, 4322dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /*StructField*/, 4323dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson Extended /*EncodeBlockParameters*/, 4324dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson Extended /*EncodeClassNames*/); 4325dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson} 4326dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson 4327a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingForMethodDecl - Return the encoded type for this method 432833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// declaration. 4329f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregorbool ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, 4330dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson std::string& S, 4331dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool Extended) const { 4332c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 4333dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Encode return type. 4334dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForMethodParameter(Decl->getObjCDeclQualifier(), 4335dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson Decl->getResultType(), S, Extended); 433633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Compute size of all parameters. 433733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Start with computing size of a pointer in number of bytes. 433833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // FIXME: There might(should) be a better way of doing this computation! 433933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian SourceLocation Loc; 4340199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits PtrSize = getTypeSizeInChars(VoidPtrTy); 434133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // The first two arguments (self and _cmd) are pointers; account for 434233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // their size. 4343199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits ParmOffset = 2 * PtrSize; 4344491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(), 43457732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian E = Decl->sel_param_end(); PI != E; ++PI) { 434689951a86b594513c2a013532ed45d197413b1087Chris Lattner QualType PType = (*PI)->getType(); 4347aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck CharUnits sz = getObjCEncodingTypeSize(PType); 4348f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor if (sz.isZero()) 43497e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian continue; 43507e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian 4351199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck assert (sz.isPositive() && 4352199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck "getObjCEncodingForMethodDecl - Incomplete param type"); 435333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset += sz; 435433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 4355199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 435633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += "@0:"; 4357199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(PtrSize); 43581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 435933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Argument types. 436033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset = 2 * PtrSize; 4361491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(), 43627732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian E = Decl->sel_param_end(); PI != E; ++PI) { 4363491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis const ParmVarDecl *PVDecl = *PI; 43641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType PType = PVDecl->getOriginalType(); 43654306d3cb9116605728252e2738df24b9f6ab53c3Fariborz Jahanian if (const ArrayType *AT = 4366ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 4367ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // Use array's original type only if it has known number of 4368ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // elements. 4369bb3fde337fb712c0e6da8790d431621be4793048Steve Naroff if (!isa<ConstantArrayType>(AT)) 4370ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 4371ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff } else if (PType->isFunctionType()) 4372ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 4373dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForMethodParameter(PVDecl->getObjCDeclQualifier(), 4374dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson PType, S, Extended); 4375199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 4376aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck ParmOffset += getObjCEncodingTypeSize(PType); 437733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 4378f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor 4379f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor return false; 438033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 438133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 4382c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// getObjCEncodingForPropertyDecl - Return the encoded type for this 438383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// property declaration. If non-NULL, Container must be either an 4384c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// ObjCCategoryImplDecl or ObjCImplementationDecl; it should only be 4385c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// NULL when getting encodings for protocol properties. 43861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Property attributes are stored as a comma-delimited C string. The simple 43871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// attributes readonly and bycopy are encoded as single characters. The 43881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// parametrized attributes, getter=name, setter=name, and ivar=name, are 43891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// encoded as single characters, followed by an identifier. Property types 43901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// are also encoded as a parametrized attribute. The characters used to encode 439183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// these attributes are defined by the following enumeration: 439283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @code 439383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// enum PropertyAttributes { 439483bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyReadOnly = 'R', // property is read-only. 439583bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyBycopy = 'C', // property is a copy of the value last assigned 439683bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyByref = '&', // property is a reference to the value last assigned 439783bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyDynamic = 'D', // property is dynamic 439883bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyGetter = 'G', // followed by getter selector name 439983bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertySetter = 'S', // followed by setter selector name 440083bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyInstanceVariable = 'V' // followed by instance variable name 44010d4cb85130d91da61c45aecb9fd31c7097a7cfccBob Wilson/// kPropertyType = 'T' // followed by old-style type encoding. 440283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyWeak = 'W' // 'weak' property 440383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyStrong = 'P' // property GC'able 440483bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyNonAtomic = 'N' // property non-atomic 440583bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// }; 440683bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @endcode 44071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 4408c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const Decl *Container, 44094ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad std::string& S) const { 4410c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Collect information from the property implementation decl(s). 4411c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar bool Dynamic = false; 4412c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar ObjCPropertyImplDecl *SynthesizePID = 0; 4413c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4414c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: Duplicated code due to poor abstraction. 4415c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Container) { 44161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const ObjCCategoryImplDecl *CID = 4417c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar dyn_cast<ObjCCategoryImplDecl>(Container)) { 4418c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 441917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = CID->propimpl_begin(), e = CID->propimpl_end(); 4420653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 4421581deb3da481053c4993c7600f97acf7768caac5David Blaikie ObjCPropertyImplDecl *PID = *i; 4422c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 4423c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 4424c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 4425c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 4426c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 4427c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4428c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4429c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4430c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 443161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container); 4432c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 443317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = OID->propimpl_begin(), e = OID->propimpl_end(); 4434653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 4435581deb3da481053c4993c7600f97acf7768caac5David Blaikie ObjCPropertyImplDecl *PID = *i; 4436c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 4437c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 4438c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 4439c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 4440c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 4441c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4442c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 44431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 4444c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4445c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4446c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4447c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 4448c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S = "T"; 4449c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4450c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Encode result type. 4451090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // GCC has some special rules regarding encoding of properties which 4452090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // closely resembles encoding of ivars. 44531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PD->getType(), S, true, true, 0, 4454090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* outermost type */, 4455090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* encoding for property */); 4456c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4457c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->isReadOnly()) { 4458c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",R"; 4459c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 4460c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar switch (PD->getSetterKind()) { 4461c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Assign: break; 4462c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Copy: S += ",C"; break; 44631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case ObjCPropertyDecl::Retain: S += ",&"; break; 44643a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian case ObjCPropertyDecl::Weak: S += ",W"; break; 4465c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4466c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4467c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4468c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // It really isn't clear at all what this means, since properties 4469c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // are "dynamic by default". 4470c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Dynamic) 4471c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",D"; 4472c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4473090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic) 4474090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian S += ",N"; 44751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4476c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { 4477c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",G"; 4478077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getGetterName().getAsString(); 4479c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4480c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4481c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { 4482c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",S"; 4483077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getSetterName().getAsString(); 4484c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4485c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4486c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (SynthesizePID) { 4487c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const ObjCIvarDecl *OID = SynthesizePID->getPropertyIvarDecl(); 4488c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",V"; 448939f34e97d6a468f0a7dfa5664c61217cffc65b74Chris Lattner S += OID->getNameAsString(); 4490c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4491c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4492c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: OBJCGC: weak & strong 4493c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar} 4494c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4495a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// getLegacyIntegralTypeEncoding - 44961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Another legacy compatibility encoding: 32-bit longs are encoded as 44971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 'l' or 'L' , but not always. For typedefs, we need to use 4498a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 'i' or 'I' instead if encoding a struct field, or a pointer! 4499a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 4500a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanianvoid ASTContext::getLegacyIntegralTypeEncoding (QualType &PointeeTy) const { 45018e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(PointeeTy.getTypePtr())) { 4502183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = PointeeTy->getAs<BuiltinType>()) { 45034ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad if (BT->getKind() == BuiltinType::ULong && getIntWidth(PointeeTy) == 32) 4504a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = UnsignedIntTy; 45051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump else 45064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad if (BT->getKind() == BuiltinType::Long && getIntWidth(PointeeTy) == 32) 4507a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = IntTy; 4508a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4509a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4510a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian} 4511a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 45127d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanianvoid ASTContext::getObjCEncodingForType(QualType T, std::string& S, 45134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const FieldDecl *Field) const { 451482a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // We follow the behavior of gcc, expanding structures which are 451582a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // directly pointed to, and expanding embedded structures. Note that 451682a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // these rules are sufficient to prevent recursive encoding of the 451782a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // same type. 45181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(T, S, true, true, Field, 45195b8c7d9fb620ba3a71e996d61e7b9bdf763b5c09Fariborz Jahanian true /* outermost type */); 452082a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar} 452182a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar 452264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnallstatic char ObjCEncodingForPrimitiveKind(const ASTContext *C, QualType T) { 452364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall switch (T->getAs<BuiltinType>()->getKind()) { 4524b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unhandled builtin type kind"); 452564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Void: return 'v'; 452664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Bool: return 'B'; 452764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Char_U: 452864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UChar: return 'C'; 452964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UShort: return 'S'; 453064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UInt: return 'I'; 453164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::ULong: 45324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad return C->getIntWidth(T) == 32 ? 'L' : 'Q'; 453364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UInt128: return 'T'; 453464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::ULongLong: return 'Q'; 453564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Char_S: 453664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::SChar: return 'c'; 453764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Short: return 's'; 45383f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 45393f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 454064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Int: return 'i'; 454164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Long: 45424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad return C->getIntWidth(T) == 32 ? 'l' : 'q'; 454364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::LongLong: return 'q'; 454464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Int128: return 't'; 454564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Float: return 'f'; 454664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Double: return 'd'; 45473a0be84b2aed8563150cdbd976a98838afa261ebDaniel Dunbar case BuiltinType::LongDouble: return 'D'; 454864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall } 454964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall} 455064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall 45515471bc85b69912e3b448de004498a80c0de32296Douglas Gregorstatic char ObjCEncodingForEnumType(const ASTContext *C, const EnumType *ET) { 45525471bc85b69912e3b448de004498a80c0de32296Douglas Gregor EnumDecl *Enum = ET->getDecl(); 45535471bc85b69912e3b448de004498a80c0de32296Douglas Gregor 45545471bc85b69912e3b448de004498a80c0de32296Douglas Gregor // The encoding of an non-fixed enum type is always 'i', regardless of size. 45555471bc85b69912e3b448de004498a80c0de32296Douglas Gregor if (!Enum->isFixed()) 45565471bc85b69912e3b448de004498a80c0de32296Douglas Gregor return 'i'; 45575471bc85b69912e3b448de004498a80c0de32296Douglas Gregor 45585471bc85b69912e3b448de004498a80c0de32296Douglas Gregor // The encoding of a fixed enum type matches its fixed underlying type. 45595471bc85b69912e3b448de004498a80c0de32296Douglas Gregor return ObjCEncodingForPrimitiveKind(C, Enum->getIntegerType()); 45605471bc85b69912e3b448de004498a80c0de32296Douglas Gregor} 45615471bc85b69912e3b448de004498a80c0de32296Douglas Gregor 45624ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadstatic void EncodeBitField(const ASTContext *Ctx, std::string& S, 456364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall QualType T, const FieldDecl *FD) { 4564a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith assert(FD->isBitField() && "not a bitfield - getObjCEncodingForTypeImpl"); 45658b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian S += 'b'; 456664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // The NeXT runtime encodes bit fields as b followed by the number of bits. 456764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // The GNU runtime requires more information; bitfields are encoded as b, 456864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // then the offset (in bits) of the first element, then the type of the 456964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // bitfield, then the size in bits. For example, in this structure: 457064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // 457164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // struct 457264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // { 457364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // int integer; 457464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // int flags:2; 457564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // }; 457664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // On a 32-bit system, the encoding for flags would be b2 for the NeXT 457764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // runtime, but b32i2 for the GNU runtime. The reason for this extra 457864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // information is not especially sensible, but we're stuck with it for 457964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // compatibility with GCC, although providing it breaks anything that 458064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // actually uses runtime introspection and wants to work on both runtimes... 4581260611a32535c851237926bfcf78869b13c07d5bJohn McCall if (Ctx->getLangOpts().ObjCRuntime.isGNUFamily()) { 458264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall const RecordDecl *RD = FD->getParent(); 458364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall const ASTRecordLayout &RL = Ctx->getASTRecordLayout(RD); 458482905749d5c8d8b4edec11de754a73349cb96603Eli Friedman S += llvm::utostr(RL.getFieldOffset(FD->getFieldIndex())); 45855471bc85b69912e3b448de004498a80c0de32296Douglas Gregor if (const EnumType *ET = T->getAs<EnumType>()) 45865471bc85b69912e3b448de004498a80c0de32296Douglas Gregor S += ObjCEncodingForEnumType(Ctx, ET); 4587c7ff82c2040f45eaad2eddea0e4461dddc972cd1David Chisnall else 45884ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad S += ObjCEncodingForPrimitiveKind(Ctx, T); 458964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall } 4590a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith S += llvm::utostr(FD->getBitWidthValue(*Ctx)); 45918b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian} 45928b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian 459301eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar// FIXME: Use SmallString for accumulating string. 459482a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbarvoid ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, 459582a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandPointedToStructures, 459682a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandStructures, 4597153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar const FieldDecl *FD, 4598090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian bool OutermostType, 45992636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis bool EncodingProperty, 4600dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool StructField, 4601dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool EncodeBlockParameters, 4602dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool EncodeClassNames) const { 460364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall if (T->getAs<BuiltinType>()) { 4604ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (FD && FD->isBitField()) 460564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall return EncodeBitField(this, S, T, FD); 460664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall S += ObjCEncodingForPrimitiveKind(this, T); 4607ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4608ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 46091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4610183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType *CT = T->getAs<ComplexType>()) { 4611c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson S += 'j'; 46121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(CT->getElementType(), S, false, false, 0, false, 4613c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson false); 4614ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4615ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 461660bce3ef20a4c9684e3825cdd739fefb9810327dFariborz Jahanian 4617aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian // encoding for pointer or r3eference types. 4618aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian QualType PointeeTy; 46196217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = T->getAs<PointerType>()) { 46208d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian if (PT->isObjCSelType()) { 46218d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian S += ':'; 46228d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian return; 46238d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian } 4624aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian PointeeTy = PT->getPointeeType(); 4625aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian } 4626aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 4627aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian PointeeTy = RT->getPointeeType(); 4628aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian if (!PointeeTy.isNull()) { 4629a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian bool isReadOnly = false; 4630a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // For historical/compatibility reasons, the read-only qualifier of the 4631a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // pointee gets emitted _before_ the '^'. The read-only qualifier of 4632a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // the pointer itself gets ignored, _unless_ we are looking at a typedef! 46331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Also, do not emit the 'r' for anything but the outermost type! 46348e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(T.getTypePtr())) { 4635a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (OutermostType && T.isConstQualified()) { 4636a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 4637a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 4638a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 46399fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else if (OutermostType) { 4640a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian QualType P = PointeeTy; 46416217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek while (P->getAs<PointerType>()) 46426217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek P = P->getAs<PointerType>()->getPointeeType(); 4643a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (P.isConstQualified()) { 4644a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 4645a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 4646a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4647a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4648a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (isReadOnly) { 4649a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Another legacy compatibility encoding. Some ObjC qualifier and type 4650a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // combinations need to be rearranged. 4651a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Rewrite "in const" from "nr" to "rn" 46525f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner if (StringRef(S).endswith("nr")) 46530237941e0beb0c929934b66ad29443b484d987feBenjamin Kramer S.replace(S.end()-2, S.end(), "rn"); 4654a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 46551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 465685f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson if (PointeeTy->isCharType()) { 465785f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // char pointer types should be encoded as '*' unless it is a 465885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // type that has been typedef'd to 'BOOL'. 4659e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (!isTypeTypedefedAsBOOL(PointeeTy)) { 466085f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '*'; 466185f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return; 466285f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 46636217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek } else if (const RecordType *RTy = PointeeTy->getAs<RecordType>()) { 46649533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_class *" to "#". 46659533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_class")) { 46669533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '#'; 46679533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 46689533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 46699533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_object *" to "@". 46709533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_object")) { 46719533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '@'; 46729533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 46739533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 46749533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // fall through... 467585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 467685f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '^'; 4677a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian getLegacyIntegralTypeEncoding(PointeeTy); 4678a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 46791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PointeeTy, S, false, ExpandPointedToStructures, 468043822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian NULL); 4681ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4682ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 4683aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian 4684ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (const ArrayType *AT = 4685ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Ignore type qualifiers etc. 4686ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner dyn_cast<ArrayType>(T->getCanonicalTypeInternal())) { 46872636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (isa<IncompleteArrayType>(AT) && !StructField) { 4688559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson // Incomplete arrays are encoded as a pointer to the array element. 4689559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '^'; 4690559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson 46911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(AT->getElementType(), S, 4692559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 4693559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } else { 4694559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '['; 46951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 46962636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) { 46972636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (getTypeSize(CAT->getElementType()) == 0) 46982636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '0'; 46992636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis else 47002636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += llvm::utostr(CAT->getSize().getZExtValue()); 47012636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 4702559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson //Variable length arrays are encoded as a regular array with 0 elements. 47032636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert((isa<VariableArrayType>(AT) || isa<IncompleteArrayType>(AT)) && 47042636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis "Unknown array type!"); 4705559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '0'; 4706559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 47071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 47081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(AT->getElementType(), S, 4709559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 4710559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += ']'; 4711559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 4712ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4713ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 47141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4715183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (T->getAs<FunctionType>()) { 4716c0a87b7db06643178ad2cbce0767548c139ea387Anders Carlsson S += '?'; 4717ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4718ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 47191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 47206217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RTy = T->getAs<RecordType>()) { 472182a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar RecordDecl *RDecl = RTy->getDecl(); 4722d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? '(' : '{'; 4723502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar // Anonymous structures print as '?' 4724502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar if (const IdentifierInfo *II = RDecl->getIdentifier()) { 4725502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += II->getName(); 47266fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian if (ClassTemplateSpecializationDecl *Spec 47276fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian = dyn_cast<ClassTemplateSpecializationDecl>(RDecl)) { 47286fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); 47296fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian std::string TemplateArgsStr 47306fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian = TemplateSpecializationType::PrintTemplateArgumentList( 4731910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgs.data(), 4732910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgs.size(), 473330c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor (*this).getPrintingPolicy()); 47346fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian 47356fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian S += TemplateArgsStr; 47366fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian } 4737502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } else { 4738502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += '?'; 4739502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } 47400d504c1da852e58ff802545c823ecff3b6c654b8Daniel Dunbar if (ExpandStructures) { 47417d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian S += '='; 47422636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!RDecl->isUnion()) { 47432636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForStructureImpl(RDecl, S, FD); 47442636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 47452636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (RecordDecl::field_iterator Field = RDecl->field_begin(), 47462636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldEnd = RDecl->field_end(); 47472636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis Field != FieldEnd; ++Field) { 47482636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (FD) { 47492636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 47502636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += Field->getNameAsString(); 47512636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 47522636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 47531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 47542636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // Special case bit-fields. 47552636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (Field->isBitField()) { 47562636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForTypeImpl(Field->getType(), S, false, true, 4757581deb3da481053c4993c7600f97acf7768caac5David Blaikie *Field); 47582636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 47592636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis QualType qt = Field->getType(); 47602636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getLegacyIntegralTypeEncoding(qt); 47612636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForTypeImpl(qt, S, false, true, 47622636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FD, /*OutermostType*/false, 47632636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*EncodingProperty*/false, 47642636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*StructField*/true); 47652636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 4766d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar } 47677d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian } 47686de88a873a4cbe06d72602eef57d68006730a80bFariborz Jahanian } 4769d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? ')' : '}'; 4770ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4771ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 4772e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian 47735471bc85b69912e3b448de004498a80c0de32296Douglas Gregor if (const EnumType *ET = T->getAs<EnumType>()) { 47748b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian if (FD && FD->isBitField()) 477564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall EncodeBitField(this, S, T, FD); 47768b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian else 47775471bc85b69912e3b448de004498a80c0de32296Douglas Gregor S += ObjCEncodingForEnumType(this, ET); 4778ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4779ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 47801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4781dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) { 478221a98b188857d690aa4510c52ac4317ffa0908a8Steve Naroff S += "@?"; // Unlike a pointer-to-function, which is "^?". 4783dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (EncodeBlockParameters) { 4784dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson const FunctionType *FT = BT->getPointeeType()->getAs<FunctionType>(); 4785dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson 4786dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson S += '<'; 4787dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Block return type 4788dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeImpl(FT->getResultType(), S, 4789dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson ExpandPointedToStructures, ExpandStructures, 4790dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson FD, 4791dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* OutermostType */, 4792dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodingProperty, 4793dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* StructField */, 4794dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeBlockParameters, 4795dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeClassNames); 4796dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Block self 4797dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson S += "@?"; 4798dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Block parameters 4799dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) { 4800dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson for (FunctionProtoType::arg_type_iterator I = FPT->arg_type_begin(), 4801dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson E = FPT->arg_type_end(); I && (I != E); ++I) { 4802dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeImpl(*I, S, 4803dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson ExpandPointedToStructures, 4804dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson ExpandStructures, 4805dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson FD, 4806dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* OutermostType */, 4807dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodingProperty, 4808dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* StructField */, 4809dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeBlockParameters, 4810dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeClassNames); 4811dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson } 4812dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson } 4813dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson S += '>'; 4814dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson } 4815ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4816ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 48171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4818c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Ignore protocol qualifiers when mangling at this level. 4819c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *OT = T->getAs<ObjCObjectType>()) 4820c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T = OT->getBaseType(); 4821c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 48220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ObjCInterfaceType *OIT = T->getAs<ObjCInterfaceType>()) { 482343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian // @encode(class_name) 48240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ObjCInterfaceDecl *OI = OIT->getDecl(); 482543822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '{'; 482643822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian const IdentifierInfo *II = OI->getIdentifier(); 482743822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += II->getName(); 482843822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '='; 4829db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose SmallVector<const ObjCIvarDecl*, 32> Ivars; 48302c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian DeepCollectObjCIvars(OI, true, Ivars); 48312c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian for (unsigned i = 0, e = Ivars.size(); i != e; ++i) { 4832db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose const FieldDecl *Field = cast<FieldDecl>(Ivars[i]); 48332c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian if (Field->isBitField()) 48342c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian getObjCEncodingForTypeImpl(Field->getType(), S, false, true, Field); 483543822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian else 48362c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian getObjCEncodingForTypeImpl(Field->getType(), S, false, true, FD); 483743822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 483843822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '}'; 4839ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 484043822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 48411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4842183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = T->getAs<ObjCObjectPointerType>()) { 484314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->isObjCIdType()) { 484414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '@'; 484514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 4846ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 48471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 484827d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType()) { 484927d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff // FIXME: Consider if we need to output qualifiers for 'Class<p>'. 485027d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff // Since this is a binary compatibility issue, need to consult with runtime 485127d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff // folks. Fortunately, this is a *very* obsure construct. 485214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '#'; 485314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 4854ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 48551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4856ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (OPT->isObjCQualifiedIdType()) { 48571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(getObjCIdType(), S, 485814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandPointedToStructures, 485914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandStructures, FD); 4860dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (FD || EncodingProperty || EncodeClassNames) { 486114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Note that we do extended encoding of protocol qualifer list 486214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Only when doing ivar or property encoding. 486314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 486467ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 486567ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 486614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '<'; 486714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += (*I)->getNameAsString(); 486814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '>'; 486914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 487014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 487114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 487214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 4873ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 48741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4875ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner QualType PointeeTy = OPT->getPointeeType(); 4876ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (!EncodingProperty && 4877ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner isa<TypedefType>(PointeeTy.getTypePtr())) { 4878ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Another historical/compatibility reason. 48791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // We encode the underlying type which comes out as 4880ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // {...}; 4881ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '^'; 48821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PointeeTy, S, 48831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump false, ExpandPointedToStructures, 4884ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner NULL); 488514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 488614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 4887ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 4888ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '@'; 4889dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (OPT->getInterfaceDecl() && 4890dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson (FD || EncodingProperty || EncodeClassNames)) { 4891ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 489227d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff S += OPT->getInterfaceDecl()->getIdentifier()->getName(); 489367ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 489467ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 4895ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '<'; 4896ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += (*I)->getNameAsString(); 4897ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '>'; 48981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 4899ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 4900ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 4901ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4902ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 49031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4904532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall // gcc just blithely ignores member pointers. 4905532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall // TODO: maybe there should be a mangling for these 4906532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall if (T->getAs<MemberPointerType>()) 4907532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall return; 4908e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian 4909e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian if (T->isVectorType()) { 4910e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian // This matches gcc's encoding, even though technically it is 4911e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian // insufficient. 4912e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian // FIXME. We should do a better job than gcc. 4913e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian return; 4914e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian } 4915e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian 4916b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("@encode for type not implemented!"); 491785f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 491885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 49192636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidisvoid ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl, 49202636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::string &S, 49212636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis const FieldDecl *FD, 49222636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis bool includeVBases) const { 49232636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert(RDecl && "Expected non-null RecordDecl"); 49242636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert(!RDecl->isUnion() && "Should not be called for unions"); 49252636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!RDecl->getDefinition()) 49262636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis return; 49272636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 49282636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(RDecl); 49292636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::multimap<uint64_t, NamedDecl *> FieldOrBaseOffsets; 49302636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis const ASTRecordLayout &layout = getASTRecordLayout(RDecl); 49312636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 49322636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRec) { 49332636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (CXXRecordDecl::base_class_iterator 49342636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BI = CXXRec->bases_begin(), 49352636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BE = CXXRec->bases_end(); BI != BE; ++BI) { 49362636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!BI->isVirtual()) { 49372636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CXXRecordDecl *base = BI->getType()->getAsCXXRecordDecl(); 4938829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis if (base->isEmpty()) 4939829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis continue; 4940d4f5198ae07d9a4958d8191bac694ded12173ad9Benjamin Kramer uint64_t offs = toBits(layout.getBaseClassOffset(base)); 49412636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), 49422636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::make_pair(offs, base)); 49432636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49442636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49452636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49462636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 49472636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis unsigned i = 0; 49482636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (RecordDecl::field_iterator Field = RDecl->field_begin(), 49492636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldEnd = RDecl->field_end(); 49502636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis Field != FieldEnd; ++Field, ++i) { 49512636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t offs = layout.getFieldOffset(i); 49522636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), 4953581deb3da481053c4993c7600f97acf7768caac5David Blaikie std::make_pair(offs, *Field)); 49542636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49552636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 49562636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRec && includeVBases) { 49572636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (CXXRecordDecl::base_class_iterator 49582636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BI = CXXRec->vbases_begin(), 49592636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BE = CXXRec->vbases_end(); BI != BE; ++BI) { 49602636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CXXRecordDecl *base = BI->getType()->getAsCXXRecordDecl(); 4961829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis if (base->isEmpty()) 4962829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis continue; 4963d4f5198ae07d9a4958d8191bac694ded12173ad9Benjamin Kramer uint64_t offs = toBits(layout.getVBaseClassOffset(base)); 496419aa8609a5d04eed9b81aa1c4608e8a4f3df6ccdArgyrios Kyrtzidis if (FieldOrBaseOffsets.find(offs) == FieldOrBaseOffsets.end()) 496519aa8609a5d04eed9b81aa1c4608e8a4f3df6ccdArgyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.end(), 496619aa8609a5d04eed9b81aa1c4608e8a4f3df6ccdArgyrios Kyrtzidis std::make_pair(offs, base)); 49672636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49682636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49692636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 49702636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CharUnits size; 49712636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRec) { 49722636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis size = includeVBases ? layout.getSize() : layout.getNonVirtualSize(); 49732636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 49742636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis size = layout.getSize(); 49752636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49762636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 49772636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t CurOffs = 0; 49782636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::multimap<uint64_t, NamedDecl *>::iterator 49792636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurLayObj = FieldOrBaseOffsets.begin(); 49802636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 498158db7a575efc9a2f35266fe240feac3cf317753dDouglas Gregor if (CXXRec && CXXRec->isDynamicClass() && 498258db7a575efc9a2f35266fe240feac3cf317753dDouglas Gregor (CurLayObj == FieldOrBaseOffsets.end() || CurLayObj->first != 0)) { 49832636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (FD) { 49842636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += "\"_vptr$"; 49852636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::string recname = CXXRec->getNameAsString(); 49862636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (recname.empty()) recname = "?"; 49872636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += recname; 49882636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 49892636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49902636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += "^^?"; 49912636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurOffs += getTypeSize(VoidPtrTy); 49922636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49932636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 49942636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!RDecl->hasFlexibleArrayMember()) { 49952636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // Mark the end of the structure. 49962636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t offs = toBits(size); 49972636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), 49982636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::make_pair(offs, (NamedDecl*)0)); 49992636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 50002636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 50012636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (; CurLayObj != FieldOrBaseOffsets.end(); ++CurLayObj) { 50022636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert(CurOffs <= CurLayObj->first); 50032636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 50042636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CurOffs < CurLayObj->first) { 50052636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t padding = CurLayObj->first - CurOffs; 50062636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // FIXME: There doesn't seem to be a way to indicate in the encoding that 50072636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // packing/alignment of members is different that normal, in which case 50082636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // the encoding will be out-of-sync with the real layout. 50092636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // If the runtime switches to just consider the size of types without 50102636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // taking into account alignment, we could make padding explicit in the 50112636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // encoding (e.g. using arrays of chars). The encoding strings would be 50122636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // longer then though. 50132636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurOffs += padding; 50142636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 50152636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 50162636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis NamedDecl *dcl = CurLayObj->second; 50172636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (dcl == 0) 50182636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis break; // reached end of structure. 50192636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 50202636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRecordDecl *base = dyn_cast<CXXRecordDecl>(dcl)) { 50212636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // We expand the bases without their virtual bases since those are going 50222636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // in the initial structure. Note that this differs from gcc which 50232636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // expands virtual bases each time one is encountered in the hierarchy, 50242636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // making the encoding type bigger than it really is. 50252636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForStructureImpl(base, S, FD, /*includeVBases*/false); 5026829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis assert(!base->isEmpty()); 5027829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis CurOffs += toBits(getASTRecordLayout(base).getNonVirtualSize()); 50282636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 50292636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldDecl *field = cast<FieldDecl>(dcl); 50302636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (FD) { 50312636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 50322636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += field->getNameAsString(); 50332636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 50342636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 50352636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 50362636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (field->isBitField()) { 50372636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis EncodeBitField(this, S, field->getType(), field); 5038a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith CurOffs += field->getBitWidthValue(*this); 50392636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 50402636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis QualType qt = field->getType(); 50412636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getLegacyIntegralTypeEncoding(qt); 50422636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForTypeImpl(qt, S, false, true, FD, 50432636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*OutermostType*/false, 50442636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*EncodingProperty*/false, 50452636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*StructField*/true); 50462636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurOffs += getTypeSize(field->getType()); 50472636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 50482636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 50492636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 50502636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis} 50512636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 50521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid ASTContext::getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 5053ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian std::string& S) const { 5054ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_In) 5055ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'n'; 5056ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Inout) 5057ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'N'; 5058ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Out) 5059ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'o'; 5060ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Bycopy) 5061ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'O'; 5062ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Byref) 5063ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'R'; 5064ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Oneway) 5065ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'V'; 5066ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian} 5067ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian 50684dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas GregorTypedefDecl *ASTContext::getObjCIdDecl() const { 50694dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor if (!ObjCIdDecl) { 50704dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor QualType T = getObjCObjectType(ObjCBuiltinIdTy, 0, 0); 50714dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor T = getObjCObjectPointerType(T); 50724dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor TypeSourceInfo *IdInfo = getTrivialTypeSourceInfo(T); 50734dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor ObjCIdDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 50744dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor getTranslationUnitDecl(), 50754dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor SourceLocation(), SourceLocation(), 50764dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor &Idents.get("id"), IdInfo); 50774dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor } 50784dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor 50794dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor return ObjCIdDecl; 50807e219e47de26346885d667131977bd9ca2d7662aSteve Naroff} 50817e219e47de26346885d667131977bd9ca2d7662aSteve Naroff 50827a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas GregorTypedefDecl *ASTContext::getObjCSelDecl() const { 50837a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor if (!ObjCSelDecl) { 50847a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor QualType SelT = getPointerType(ObjCBuiltinSelTy); 50857a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor TypeSourceInfo *SelInfo = getTrivialTypeSourceInfo(SelT); 50867a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor ObjCSelDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 50877a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor getTranslationUnitDecl(), 50887a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor SourceLocation(), SourceLocation(), 50897a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor &Idents.get("SEL"), SelInfo); 50907a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor } 50917a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor return ObjCSelDecl; 5092b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian} 5093b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 509479d6726921897811232554ed94c5d77b5b7b3fc0Douglas GregorTypedefDecl *ASTContext::getObjCClassDecl() const { 509579d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor if (!ObjCClassDecl) { 509679d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor QualType T = getObjCObjectType(ObjCBuiltinClassTy, 0, 0); 509779d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor T = getObjCObjectPointerType(T); 509879d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor TypeSourceInfo *ClassInfo = getTrivialTypeSourceInfo(T); 509979d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor ObjCClassDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 510079d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor getTranslationUnitDecl(), 510179d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor SourceLocation(), SourceLocation(), 510279d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor &Idents.get("Class"), ClassInfo); 510379d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor } 510479d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor 510579d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor return ObjCClassDecl; 5106a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor} 5107a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor 5108a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas GregorObjCInterfaceDecl *ASTContext::getObjCProtocolDecl() const { 5109a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor if (!ObjCProtocolClassDecl) { 5110a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor ObjCProtocolClassDecl 5111a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor = ObjCInterfaceDecl::Create(*this, getTranslationUnitDecl(), 5112a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor SourceLocation(), 5113a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor &Idents.get("Protocol"), 5114a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor /*PrevDecl=*/0, 5115a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor SourceLocation(), true); 5116a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor } 5117a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor 5118a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor return ObjCProtocolClassDecl; 51198baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson} 51208baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson 5121c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge//===----------------------------------------------------------------------===// 5122c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge// __builtin_va_list Construction Functions 5123c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge//===----------------------------------------------------------------------===// 5124c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5125c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreateCharPtrBuiltinVaListDecl(const ASTContext *Context) { 5126c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef char* __builtin_va_list; 5127c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType CharPtrType = Context->getPointerType(Context->CharTy); 5128c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5129c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(CharPtrType); 5130c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5131c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypeDecl 5132c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5133c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5134c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5135c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5136c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5137c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypeDecl; 5138c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5139c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5140c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) { 5141c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef void* __builtin_va_list; 5142c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VoidPtrType = Context->getPointerType(Context->VoidTy); 5143c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5144c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(VoidPtrType); 5145c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5146c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypeDecl 5147c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5148c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5149c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5150c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5151c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5152c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypeDecl; 5153c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5154c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5155c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) { 5156c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef struct __va_list_tag { 5157c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge RecordDecl *VaListTagDecl; 5158c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5159c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct, 5160c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5161c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag")); 5162c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->startDefinition(); 5163c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5164c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const size_t NumFields = 5; 5165c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType FieldTypes[NumFields]; 5166c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const char *FieldNames[NumFields]; 5167c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5168c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned char gpr; 5169c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[0] = Context->UnsignedCharTy; 5170c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[0] = "gpr"; 5171c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5172c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned char fpr; 5173c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[1] = Context->UnsignedCharTy; 5174c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[1] = "fpr"; 5175c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5176c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned short reserved; 5177c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[2] = Context->UnsignedShortTy; 5178c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[2] = "reserved"; 5179c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5180c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* overflow_arg_area; 5181c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[3] = Context->getPointerType(Context->VoidTy); 5182c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[3] = "overflow_arg_area"; 5183c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5184c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* reg_save_area; 5185c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[4] = Context->getPointerType(Context->VoidTy); 5186c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[4] = "reg_save_area"; 5187c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5188c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // Create fields 5189c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge for (unsigned i = 0; i < NumFields; ++i) { 5190c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldDecl *Field = FieldDecl::Create(*Context, VaListTagDecl, 5191c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5192c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5193c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get(FieldNames[i]), 5194c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[i], /*TInfo=*/0, 5195c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*BitWidth=*/0, 5196c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*Mutable=*/false, 5197c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge ICIS_NoInit); 5198c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Field->setAccess(AS_public); 5199c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->addDecl(Field); 5200c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge } 5201c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->completeDefinition(); 5202c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagType = Context->getRecordType(VaListTagDecl); 5203fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge Context->VaListTagTy = VaListTagType; 5204c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5205c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // } __va_list_tag; 5206c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTagTypedefDecl 5207c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5208c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5209c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5210c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag"), 5211c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTrivialTypeSourceInfo(VaListTagType)); 5212c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagTypedefType = 5213c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTypedefType(VaListTagTypedefDecl); 5214c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5215c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef __va_list_tag __builtin_va_list[1]; 5216c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); 5217c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagArrayType 5218c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getConstantArrayType(VaListTagTypedefType, 5219c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Size, ArrayType::Normal, 0); 5220c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5221c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(VaListTagArrayType); 5222c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypedefDecl 5223c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5224c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5225c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5226c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5227c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5228c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5229c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypedefDecl; 5230c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5231c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5232c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl * 5233c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador IngeCreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) { 5234c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef struct __va_list_tag { 5235c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge RecordDecl *VaListTagDecl; 5236c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct, 5237c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5238c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag")); 5239c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->startDefinition(); 5240c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5241c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const size_t NumFields = 4; 5242c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType FieldTypes[NumFields]; 5243c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const char *FieldNames[NumFields]; 5244c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5245c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned gp_offset; 5246c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[0] = Context->UnsignedIntTy; 5247c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[0] = "gp_offset"; 5248c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5249c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned fp_offset; 5250c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[1] = Context->UnsignedIntTy; 5251c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[1] = "fp_offset"; 5252c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5253c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* overflow_arg_area; 5254c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[2] = Context->getPointerType(Context->VoidTy); 5255c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[2] = "overflow_arg_area"; 5256c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5257c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* reg_save_area; 5258c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[3] = Context->getPointerType(Context->VoidTy); 5259c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[3] = "reg_save_area"; 5260c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5261c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // Create fields 5262c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge for (unsigned i = 0; i < NumFields; ++i) { 5263c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context), 5264c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl, 5265c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5266c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5267c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get(FieldNames[i]), 5268c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[i], /*TInfo=*/0, 5269c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*BitWidth=*/0, 5270c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*Mutable=*/false, 5271c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge ICIS_NoInit); 5272c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Field->setAccess(AS_public); 5273c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->addDecl(Field); 5274c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge } 5275c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->completeDefinition(); 5276c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagType = Context->getRecordType(VaListTagDecl); 5277fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge Context->VaListTagTy = VaListTagType; 5278c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5279c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // } __va_list_tag; 5280c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTagTypedefDecl 5281c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5282c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5283c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5284c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag"), 5285c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTrivialTypeSourceInfo(VaListTagType)); 5286c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagTypedefType = 5287c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTypedefType(VaListTagTypedefDecl); 5288c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5289c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef __va_list_tag __builtin_va_list[1]; 5290c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); 5291c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagArrayType 5292c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getConstantArrayType(VaListTagTypedefType, 5293c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Size, ArrayType::Normal,0); 5294c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5295c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(VaListTagArrayType); 5296c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypedefDecl 5297c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5298c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5299c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5300c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5301c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5302c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5303c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypedefDecl; 5304c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5305c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5306c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreatePNaClABIBuiltinVaListDecl(const ASTContext *Context) { 5307c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef int __builtin_va_list[4]; 5308c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 4); 5309c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType IntArrayType 5310c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getConstantArrayType(Context->IntTy, 5311c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Size, ArrayType::Normal, 0); 5312c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypedefDecl 5313c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5314c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5315c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5316c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5317c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTrivialTypeSourceInfo(IntArrayType)); 5318c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5319c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypedefDecl; 5320c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5321c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5322c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreateVaListDecl(const ASTContext *Context, 5323c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TargetInfo::BuiltinVaListKind Kind) { 5324c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge switch (Kind) { 5325c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::CharPtrBuiltinVaList: 5326c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreateCharPtrBuiltinVaListDecl(Context); 5327c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::VoidPtrBuiltinVaList: 5328c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreateVoidPtrBuiltinVaListDecl(Context); 5329c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::PowerABIBuiltinVaList: 5330c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreatePowerABIBuiltinVaListDecl(Context); 5331c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::X86_64ABIBuiltinVaList: 5332c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreateX86_64ABIBuiltinVaListDecl(Context); 5333c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::PNaClABIBuiltinVaList: 5334c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreatePNaClABIBuiltinVaListDecl(Context); 5335c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge } 5336c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5337c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm_unreachable("Unhandled __builtin_va_list type kind"); 5338c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5339c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5340c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador IngeTypedefDecl *ASTContext::getBuiltinVaListDecl() const { 5341c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge if (!BuiltinVaListDecl) 5342c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge BuiltinVaListDecl = CreateVaListDecl(this, Target->getBuiltinVaListKind()); 5343c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5344c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return BuiltinVaListDecl; 5345c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5346c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5347fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador IngeQualType ASTContext::getVaListTagType() const { 5348fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge // Force the creation of VaListTagTy by building the __builtin_va_list 5349fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge // declaration. 5350fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge if (VaListTagTy.isNull()) 5351fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge (void) getBuiltinVaListDecl(); 5352fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge 5353fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge return VaListTagTy; 5354fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge} 5355fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge 5356a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) { 53571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(ObjCConstantStringType.isNull() && 53582198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff "'NSConstantString' type already set!"); 53591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5360a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = getObjCInterfaceType(Decl); 53612198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff} 53622198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff 53630bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall/// \brief Retrieve the template name that corresponds to a non-empty 53640bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall/// lookup. 53654ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName 53664ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getOverloadedTemplateName(UnresolvedSetIterator Begin, 53674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad UnresolvedSetIterator End) const { 53680bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall unsigned size = End - Begin; 53690bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall assert(size > 1 && "set is not overloaded!"); 53707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 53710bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall void *memory = Allocate(sizeof(OverloadedTemplateStorage) + 53720bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall size * sizeof(FunctionTemplateDecl*)); 53730bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall OverloadedTemplateStorage *OT = new(memory) OverloadedTemplateStorage(size); 53740bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall 53750bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall NamedDecl **Storage = OT->getStorage(); 5376eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall for (UnresolvedSetIterator I = Begin; I != End; ++I) { 53770bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall NamedDecl *D = *I; 53780bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall assert(isa<FunctionTemplateDecl>(D) || 53790bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall (isa<UsingShadowDecl>(D) && 53800bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall isa<FunctionTemplateDecl>(D->getUnderlyingDecl()))); 53810bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall *Storage++ = D; 53827532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 53837532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 53840bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall return TemplateName(OT); 53857532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 53867532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 5387d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// \brief Retrieve the template name that represents a qualified 5388d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// template name such as \c std::vector. 53894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName 53904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, 53914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool TemplateKeyword, 53924ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad TemplateDecl *Template) const { 53930f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor assert(NNS && "Missing nested-name-specifier in qualified template name"); 53940f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor 5395789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor // FIXME: Canonicalization? 5396d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor llvm::FoldingSetNodeID ID; 5397d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName::Profile(ID, NNS, TemplateKeyword, Template); 53981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5399d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor void *InsertPos = 0; 5400d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName *QTN = 54010bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall QualifiedTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5402d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor if (!QTN) { 5403d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QTN = new (*this,4) QualifiedTemplateName(NNS, TemplateKeyword, Template); 5404d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateNames.InsertNode(QTN, InsertPos); 5405d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor } 54061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5407d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor return TemplateName(QTN); 5408d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor} 5409d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor 54107532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Retrieve the template name that represents a dependent 54117532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template name such as \c MetaFun::template apply. 54124ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName 54134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, 54144ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const IdentifierInfo *Name) const { 54151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!NNS || NNS->isDependent()) && 54163b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor "Nested name specifier must be dependent"); 54177532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 54187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor llvm::FoldingSetNodeID ID; 54197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName::Profile(ID, NNS, Name); 54207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 54217532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor void *InsertPos = 0; 54227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName *QTN = 54237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 54247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 54257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (QTN) 54267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 54277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 54287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 54297532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (CanonNNS == NNS) { 54307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QTN = new (*this,4) DependentTemplateName(NNS, Name); 54317532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } else { 54327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Canon = getDependentTemplateName(CanonNNS, Name); 54337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QTN = new (*this,4) DependentTemplateName(NNS, Name, Canon); 5434789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateName *CheckQTN = 5435789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5436789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!CheckQTN && "Dependent type name canonicalization broken"); 5437789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CheckQTN; 54387532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 54397532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 54407532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.InsertNode(QTN, InsertPos); 54417532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 54427532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 54437532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 5444ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \brief Retrieve the template name that represents a dependent 5445ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// template name such as \c MetaFun::template operator+. 5446ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 5447ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, 54484ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad OverloadedOperatorKind Operator) const { 5449ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor assert((!NNS || NNS->isDependent()) && 5450ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor "Nested name specifier must be dependent"); 5451ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5452ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor llvm::FoldingSetNodeID ID; 5453ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor DependentTemplateName::Profile(ID, NNS, Operator); 5454ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5455ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor void *InsertPos = 0; 5456789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateName *QTN 5457789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5458ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5459ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (QTN) 5460ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return TemplateName(QTN); 5461ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5462ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 5463ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (CanonNNS == NNS) { 5464ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QTN = new (*this,4) DependentTemplateName(NNS, Operator); 5465ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } else { 5466ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor TemplateName Canon = getDependentTemplateName(CanonNNS, Operator); 5467ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QTN = new (*this,4) DependentTemplateName(NNS, Operator, Canon); 5468789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 5469789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateName *CheckQTN 5470789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5471789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!CheckQTN && "Dependent template name canonicalization broken"); 5472789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CheckQTN; 5473ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 5474ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5475ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor DependentTemplateNames.InsertNode(QTN, InsertPos); 5476ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return TemplateName(QTN); 5477ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 5478ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 54791aee05d08b2184acadeb36de300e216390780d6cDouglas GregorTemplateName 5480146060435c3efce95c95a092c7a1eb651cfb9ae0John McCallASTContext::getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, 5481146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateName replacement) const { 5482146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm::FoldingSetNodeID ID; 5483146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage::Profile(ID, param, replacement); 5484146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5485146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall void *insertPos = 0; 5486146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 5487146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = SubstTemplateTemplateParms.FindNodeOrInsertPos(ID, insertPos); 5488146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5489146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall if (!subst) { 5490146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall subst = new (*this) SubstTemplateTemplateParmStorage(param, replacement); 5491146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParms.InsertNode(subst, insertPos); 5492146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 5493146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5494146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return TemplateName(subst); 5495146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall} 5496146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5497146060435c3efce95c95a092c7a1eb651cfb9ae0John McCallTemplateName 54981aee05d08b2184acadeb36de300e216390780d6cDouglas GregorASTContext::getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, 54991aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor const TemplateArgument &ArgPack) const { 55001aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor ASTContext &Self = const_cast<ASTContext &>(*this); 55011aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor llvm::FoldingSetNodeID ID; 55021aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPackStorage::Profile(ID, Self, Param, ArgPack); 55031aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 55041aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor void *InsertPos = 0; 55051aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPackStorage *Subst 55061aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor = SubstTemplateTemplateParmPacks.FindNodeOrInsertPos(ID, InsertPos); 55071aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 55081aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor if (!Subst) { 5509146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall Subst = new (*this) SubstTemplateTemplateParmPackStorage(Param, 55101aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor ArgPack.pack_size(), 55111aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor ArgPack.pack_begin()); 55121aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPacks.InsertNode(Subst, InsertPos); 55131aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 55141aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 55151aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return TemplateName(Subst); 55161aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor} 55171aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 5518b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor/// getFromTargetType - Given one of the integer types provided by 5519d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// TargetInfo, produce the corresponding type. The unsigned @p Type 5520d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// is actually a value of type @c TargetInfo::IntType. 5521e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCallCanQualType ASTContext::getFromTargetType(unsigned Type) const { 5522b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor switch (Type) { 5523e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCall case TargetInfo::NoInt: return CanQualType(); 5524b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedShort: return ShortTy; 5525b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedShort: return UnsignedShortTy; 5526b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedInt: return IntTy; 5527b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedInt: return UnsignedIntTy; 5528b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLong: return LongTy; 5529b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLong: return UnsignedLongTy; 5530b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLongLong: return LongLongTy; 5531b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLongLong: return UnsignedLongLongTy; 5532b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor } 5533b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor 5534b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unhandled TargetInfo::IntType value"); 5535b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor} 5536b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 5537b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 5538b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek// Type Predicates. 5539b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 5540b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 55414fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's 55424fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// garbage collection attribute. 55434fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// 5544ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCallQualifiers::GC ASTContext::getObjCGCAttrKind(QualType Ty) const { 55454e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().getGC() == LangOptions::NonGC) 5546ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall return Qualifiers::GCNone; 5547ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall 55484e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie assert(getLangOpts().ObjC1); 5549ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall Qualifiers::GC GCAttrs = Ty.getObjCGCAttr(); 5550ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall 5551ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // Default behaviour under objective-C's gc is for ObjC pointers 5552ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // (or pointers to them) be treated as though they were declared 5553ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // as __strong. 5554ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall if (GCAttrs == Qualifiers::GCNone) { 5555ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall if (Ty->isObjCObjectPointerType() || Ty->isBlockPointerType()) 5556ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall return Qualifiers::Strong; 5557ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall else if (Ty->isPointerType()) 5558ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall return getObjCGCAttrKind(Ty->getAs<PointerType>()->getPointeeType()); 5559ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall } else { 5560ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // It's not valid to set GC attributes on anything that isn't a 5561ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // pointer. 5562ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall#ifndef NDEBUG 5563ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall QualType CT = Ty->getCanonicalTypeInternal(); 5564ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall while (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 5565ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall CT = AT->getElementType(); 5566ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall assert(CT->isAnyPointerType() || CT->isBlockPointerType()); 5567ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall#endif 55684fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian } 5569b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner return GCAttrs; 55704fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian} 55714fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian 55726ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 55736ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner// Type Compatibility Testing 55746ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 5575770951b5bb6028a8d326ddb4a13cef7d4a128162Chris Lattner 55761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// areCompatVectorTypes - Return true if the two specified vector types are 55776ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner/// compatible. 55786ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattnerstatic bool areCompatVectorTypes(const VectorType *LHS, 55796ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner const VectorType *RHS) { 5580467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall assert(LHS->isCanonicalUnqualified() && RHS->isCanonicalUnqualified()); 55816ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return LHS->getElementType() == RHS->getElementType() && 558261710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner LHS->getNumElements() == RHS->getNumElements(); 55836ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 55846ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 5585255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregorbool ASTContext::areCompatibleVectorTypes(QualType FirstVec, 5586255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor QualType SecondVec) { 5587255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor assert(FirstVec->isVectorType() && "FirstVec should be a vector type"); 5588255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor assert(SecondVec->isVectorType() && "SecondVec should be a vector type"); 5589255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 5590255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor if (hasSameUnqualifiedType(FirstVec, SecondVec)) 5591255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor return true; 5592255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 5593f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson // Treat Neon vector types and most AltiVec vector types as if they are the 5594f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson // equivalent GCC vector types. 5595255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor const VectorType *First = FirstVec->getAs<VectorType>(); 5596255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor const VectorType *Second = SecondVec->getAs<VectorType>(); 5597f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson if (First->getNumElements() == Second->getNumElements() && 5598255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor hasSameType(First->getElementType(), Second->getElementType()) && 5599f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson First->getVectorKind() != VectorType::AltiVecPixel && 5600f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson First->getVectorKind() != VectorType::AltiVecBool && 5601f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson Second->getVectorKind() != VectorType::AltiVecPixel && 5602f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson Second->getVectorKind() != VectorType::AltiVecBool) 5603255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor return true; 5604255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 5605255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor return false; 5606255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor} 5607255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 56084084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 56094084c306635b70f37029dca938444e6013f08684Steve Naroff// ObjCQualifiedIdTypesAreCompatible - Compatibility testing for qualified id's. 56104084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 56114084c306635b70f37029dca938444e6013f08684Steve Naroff 56124084c306635b70f37029dca938444e6013f08684Steve Naroff/// ProtocolCompatibleWithProtocol - return 'true' if 'lProto' is in the 56134084c306635b70f37029dca938444e6013f08684Steve Naroff/// inheritance hierarchy of 'rProto'. 56144ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool 56154ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 56164ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad ObjCProtocolDecl *rProto) const { 56173fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor if (declaresSameEntity(lProto, rProto)) 561814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return true; 56194084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCProtocolDecl::protocol_iterator PI = rProto->protocol_begin(), 56204084c306635b70f37029dca938444e6013f08684Steve Naroff E = rProto->protocol_end(); PI != E; ++PI) 56214084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lProto, *PI)) 56224084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 56234084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 56244084c306635b70f37029dca938444e6013f08684Steve Naroff} 562514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 56264084c306635b70f37029dca938444e6013f08684Steve Naroff/// QualifiedIdConformsQualifiedId - compare id<p,...> with id<p1,...> 56274084c306635b70f37029dca938444e6013f08684Steve Naroff/// return true if lhs's protocols conform to rhs's protocol; false 56284084c306635b70f37029dca938444e6013f08684Steve Naroff/// otherwise. 56294084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::QualifiedIdConformsQualifiedId(QualType lhs, QualType rhs) { 56304084c306635b70f37029dca938444e6013f08684Steve Naroff if (lhs->isObjCQualifiedIdType() && rhs->isObjCQualifiedIdType()) 56314084c306635b70f37029dca938444e6013f08684Steve Naroff return ObjCQualifiedIdTypesAreCompatible(lhs, rhs, false); 56324084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 56334084c306635b70f37029dca938444e6013f08684Steve Naroff} 56344084c306635b70f37029dca938444e6013f08684Steve Naroff 5635a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian/// ObjCQualifiedClassTypesAreCompatible - compare Class<p,...> and 5636a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian/// Class<p1, ...>. 5637a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanianbool ASTContext::ObjCQualifiedClassTypesAreCompatible(QualType lhs, 5638a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian QualType rhs) { 5639a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian const ObjCObjectPointerType *lhsQID = lhs->getAs<ObjCObjectPointerType>(); 5640a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian const ObjCObjectPointerType *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); 5641a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian assert ((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible"); 5642a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 5643a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 5644a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian E = lhsQID->qual_end(); I != E; ++I) { 5645a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian bool match = false; 5646a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian ObjCProtocolDecl *lhsProto = *I; 5647a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), 5648a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian E = rhsOPT->qual_end(); J != E; ++J) { 5649a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian ObjCProtocolDecl *rhsProto = *J; 5650a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto)) { 5651a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian match = true; 5652a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian break; 5653a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian } 5654a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian } 5655a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian if (!match) 5656a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian return false; 5657a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian } 5658a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian return true; 5659a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian} 5660a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 56614084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an 56624084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIDType. 56634084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, 56644084c306635b70f37029dca938444e6013f08684Steve Naroff bool compare) { 56654084c306635b70f37029dca938444e6013f08684Steve Naroff // Allow id<P..> and an 'id' or void* type in all cases. 56661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (lhs->isVoidPointerType() || 56674084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->isObjCIdType() || lhs->isObjCClassType()) 56684084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 56691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump else if (rhs->isVoidPointerType() || 56704084c306635b70f37029dca938444e6013f08684Steve Naroff rhs->isObjCIdType() || rhs->isObjCClassType()) 56714084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 56724084c306635b70f37029dca938444e6013f08684Steve Naroff 56734084c306635b70f37029dca938444e6013f08684Steve Naroff if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) { 5674183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); 56751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56764084c306635b70f37029dca938444e6013f08684Steve Naroff if (!rhsOPT) return false; 56771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 56784084c306635b70f37029dca938444e6013f08684Steve Naroff if (rhsOPT->qual_empty()) { 56791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the RHS is a unqualified interface pointer "NSString*", 56804084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 56814084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 56824084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 56834084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 56844084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 56854084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 56864084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 56870fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (!rhsID->ClassImplementsProtocol(*I, true)) 56884084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 56894084c306635b70f37029dca938444e6013f08684Steve Naroff } 56904084c306635b70f37029dca938444e6013f08684Steve Naroff } 56914084c306635b70f37029dca938444e6013f08684Steve Naroff // If there are no qualifiers and no interface, we have an 'id'. 56924084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 56934084c306635b70f37029dca938444e6013f08684Steve Naroff } 56941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Both the right and left sides have qualifiers. 56954084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 56964084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 56974084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 56984084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 5699de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff 5700de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // when comparing an id<P> on lhs with a static type on rhs, 5701de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // see if static class implements all of id's protocols, directly or 5702de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // through its super class and categories. 57034084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), 57044084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsOPT->qual_end(); J != E; ++J) { 57054084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 57064084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 57074084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 57084084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 57098f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 57108f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 5711de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 57121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the RHS is a qualified interface pointer "NSString<P>*", 57134084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 57144084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 57154084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 57164084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 57174084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 57184084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 57194084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 57200fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (rhsID->ClassImplementsProtocol(*I, true)) { 57214084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 57224084c306635b70f37029dca938444e6013f08684Steve Naroff break; 57234084c306635b70f37029dca938444e6013f08684Steve Naroff } 57244084c306635b70f37029dca938444e6013f08684Steve Naroff } 57254084c306635b70f37029dca938444e6013f08684Steve Naroff } 57264084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 5727de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return false; 5728de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 57291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5730de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return true; 5731de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 57321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57334084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *rhsQID = rhs->getAsObjCQualifiedIdType(); 57344084c306635b70f37029dca938444e6013f08684Steve Naroff assert(rhsQID && "One of the LHS/RHS should be id<x>"); 57354084c306635b70f37029dca938444e6013f08684Steve Naroff 57361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const ObjCObjectPointerType *lhsOPT = 57374084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->getAsObjCInterfacePointerType()) { 5738de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // If both the right and left sides have qualifiers. 57394084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsOPT->qual_begin(), 57404084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsOPT->qual_end(); I != E; ++I) { 57414084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 57424084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 57434084c306635b70f37029dca938444e6013f08684Steve Naroff 5744de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // when comparing an id<P> on rhs with a static type on lhs, 57454084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 57464084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 5747de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // First, lhs protocols in the qualifier list must be found, direct 5748de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // or indirect in rhs's qualifier list or it is a mismatch. 57494084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), 57504084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsQID->qual_end(); J != E; ++J) { 57514084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 57524084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 57534084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 57544084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 57554084c306635b70f37029dca938444e6013f08684Steve Naroff break; 57564084c306635b70f37029dca938444e6013f08684Steve Naroff } 57574084c306635b70f37029dca938444e6013f08684Steve Naroff } 57584084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 57594084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 57604084c306635b70f37029dca938444e6013f08684Steve Naroff } 5761de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian 5762de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // Static class's protocols, or its super class or category protocols 5763de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // must be found, direct or indirect in rhs's qualifier list or it is a mismatch. 5764de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (ObjCInterfaceDecl *lhsID = lhsOPT->getInterfaceDecl()) { 5765de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> LHSInheritedProtocols; 5766de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian CollectInheritedProtocols(lhsID, LHSInheritedProtocols); 5767de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // This is rather dubious but matches gcc's behavior. If lhs has 5768de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // no type qualifier and its class has no static protocol(s) 5769de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // assume that it is mismatch. 5770de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (LHSInheritedProtocols.empty() && lhsOPT->qual_empty()) 5771de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian return false; 5772de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 5773de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian LHSInheritedProtocols.begin(), 5774de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian E = LHSInheritedProtocols.end(); I != E; ++I) { 5775de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian bool match = false; 5776de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian ObjCProtocolDecl *lhsProto = (*I); 5777de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), 5778de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian E = rhsQID->qual_end(); J != E; ++J) { 5779de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian ObjCProtocolDecl *rhsProto = *J; 5780de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 5781de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 5782de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian match = true; 5783de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian break; 5784de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 5785de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 5786de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (!match) 5787de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian return false; 5788de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 5789de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 57904084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 57914084c306635b70f37029dca938444e6013f08684Steve Naroff } 57924084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 57934084c306635b70f37029dca938444e6013f08684Steve Naroff} 57944084c306635b70f37029dca938444e6013f08684Steve Naroff 57954084c306635b70f37029dca938444e6013f08684Steve Naroff/// canAssignObjCInterfaces - Return true if the two interface types are 57964084c306635b70f37029dca938444e6013f08684Steve Naroff/// compatible for assignment from RHS to LHS. This handles validation of any 57974084c306635b70f37029dca938444e6013f08684Steve Naroff/// protocol qualifiers on the LHS or RHS. 57984084c306635b70f37029dca938444e6013f08684Steve Naroff/// 57994084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 58004084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *RHSOPT) { 5801c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* LHS = LHSOPT->getObjectType(); 5802c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* RHS = RHSOPT->getObjectType(); 5803c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 58044084c306635b70f37029dca938444e6013f08684Steve Naroff // If either type represents the built-in 'id' or 'Class' types, return true. 5805c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHS->isObjCUnqualifiedIdOrClass() || 5806c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall RHS->isObjCUnqualifiedIdOrClass()) 58074084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 58084084c306635b70f37029dca938444e6013f08684Steve Naroff 5809c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHS->isObjCQualifiedId() || RHS->isObjCQualifiedId()) 58101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), 58111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType(RHSOPT,0), 58124084c306635b70f37029dca938444e6013f08684Steve Naroff false); 5813a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 5814a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian if (LHS->isObjCQualifiedClass() && RHS->isObjCQualifiedClass()) 5815a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian return ObjCQualifiedClassTypesAreCompatible(QualType(LHSOPT,0), 5816a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian QualType(RHSOPT,0)); 5817a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 5818c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If we have 2 user-defined types, fall into that path. 5819c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHS->getInterface() && RHS->getInterface()) 58204084c306635b70f37029dca938444e6013f08684Steve Naroff return canAssignObjCInterfaces(LHS, RHS); 58211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58224084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 582314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 582414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 5825132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// canAssignObjCInterfacesInBlockPointer - This routine is specifically written 5826fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// for providing type-safety for objective-c pointers used to pass/return 5827132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// arguments in block literals. When passed as arguments, passing 'A*' where 5828132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// 'id' is expected is not OK. Passing 'Sub *" where 'Super *" is expected is 5829132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// not OK. For the return type, the opposite is not OK. 5830132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanianbool ASTContext::canAssignObjCInterfacesInBlockPointer( 5831132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian const ObjCObjectPointerType *LHSOPT, 5832a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian const ObjCObjectPointerType *RHSOPT, 5833a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian bool BlockReturnType) { 5834a98344869c278295f38e106583906377520079b8Fariborz Jahanian if (RHSOPT->isObjCBuiltinType() || LHSOPT->isObjCIdType()) 5835132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return true; 5836132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 5837132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHSOPT->isObjCBuiltinType()) { 5838132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return RHSOPT->isObjCBuiltinType() || RHSOPT->isObjCQualifiedIdType(); 5839132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 5840132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 5841a98344869c278295f38e106583906377520079b8Fariborz Jahanian if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) 5842132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), 5843132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian QualType(RHSOPT,0), 5844132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian false); 5845132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 5846132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType(); 5847132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType(); 5848132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHS && RHS) { // We have 2 user-defined types. 5849132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHS != RHS) { 5850132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHS->getDecl()->isSuperClassOf(RHS->getDecl())) 5851a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian return BlockReturnType; 5852132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (RHS->getDecl()->isSuperClassOf(LHS->getDecl())) 5853a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian return !BlockReturnType; 5854132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 5855132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian else 5856132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return true; 5857132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 5858132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return false; 5859132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian} 5860132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 5861e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// getIntersectionOfProtocols - This routine finds the intersection of set 5862e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// of protocols inherited from two distinct objective-c pointer objects. 5863e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// It is used to build composite qualifier list of the composite type of 5864e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// the conditional expression involving two objective-c pointer objects. 5865e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanianstatic 5866e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanianvoid getIntersectionOfProtocols(ASTContext &Context, 5867e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian const ObjCObjectPointerType *LHSOPT, 5868e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian const ObjCObjectPointerType *RHSOPT, 58695f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<ObjCProtocolDecl *> &IntersectionOfProtocols) { 5870e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 5871c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* LHS = LHSOPT->getObjectType(); 5872c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* RHS = RHSOPT->getObjectType(); 5873c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(LHS->getInterface() && "LHS must have an interface base"); 5874c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(RHS->getInterface() && "RHS must have an interface base"); 5875e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 5876e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> InheritedProtocolSet; 5877e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian unsigned LHSNumProtocols = LHS->getNumProtocols(); 5878e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (LHSNumProtocols > 0) 5879e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian InheritedProtocolSet.insert(LHS->qual_begin(), LHS->qual_end()); 5880e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian else { 5881432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> LHSInheritedProtocols; 5882c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Context.CollectInheritedProtocols(LHS->getInterface(), 5883c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall LHSInheritedProtocols); 5884e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian InheritedProtocolSet.insert(LHSInheritedProtocols.begin(), 5885e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian LHSInheritedProtocols.end()); 5886e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 5887e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 5888e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian unsigned RHSNumProtocols = RHS->getNumProtocols(); 5889e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (RHSNumProtocols > 0) { 5890cb421fa690da545b58a720abe5f1c49b166dbde7Dan Gohman ObjCProtocolDecl **RHSProtocols = 5891cb421fa690da545b58a720abe5f1c49b166dbde7Dan Gohman const_cast<ObjCProtocolDecl **>(RHS->qual_begin()); 5892e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (unsigned i = 0; i < RHSNumProtocols; ++i) 5893e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (InheritedProtocolSet.count(RHSProtocols[i])) 5894e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian IntersectionOfProtocols.push_back(RHSProtocols[i]); 58953060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 5896432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> RHSInheritedProtocols; 5897c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Context.CollectInheritedProtocols(RHS->getInterface(), 5898c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall RHSInheritedProtocols); 5899432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 5900432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian RHSInheritedProtocols.begin(), 5901432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian E = RHSInheritedProtocols.end(); I != E; ++I) 5902432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian if (InheritedProtocolSet.count((*I))) 5903432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian IntersectionOfProtocols.push_back((*I)); 5904e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 5905e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian} 5906e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 5907db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// areCommonBaseCompatible - Returns common base class of the two classes if 5908db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// one found. Note that this is O'2 algorithm. But it will be called as the 5909db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// last type comparison in a ?-exp of ObjC pointer types before a 5910db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// warning is issued. So, its invokation is extremely rare. 5911db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz JahanianQualType ASTContext::areCommonBaseCompatible( 5912c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectPointerType *Lptr, 5913c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectPointerType *Rptr) { 5914c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *LHS = Lptr->getObjectType(); 5915c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *RHS = Rptr->getObjectType(); 5916c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCInterfaceDecl* LDecl = LHS->getInterface(); 5917c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCInterfaceDecl* RDecl = RHS->getInterface(); 591860ef308e51c71b760d7f598c1b763ceb7b768148Douglas Gregor if (!LDecl || !RDecl || (declaresSameEntity(LDecl, RDecl))) 5919db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian return QualType(); 5920db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian 59217c2bdcb4d30f2d370b4367664e6a11b075ce2cb3Fariborz Jahanian do { 5922c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall LHS = cast<ObjCInterfaceType>(getObjCInterfaceType(LDecl)); 5923e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (canAssignObjCInterfaces(LHS, RHS)) { 59245f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<ObjCProtocolDecl *, 8> Protocols; 5925c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getIntersectionOfProtocols(*this, Lptr, Rptr, Protocols); 5926c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 5927c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType Result = QualType(LHS, 0); 5928c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!Protocols.empty()) 5929c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = getObjCObjectType(Result, Protocols.data(), Protocols.size()); 5930c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = getObjCObjectPointerType(Result); 5931c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return Result; 5932e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 59337c2bdcb4d30f2d370b4367664e6a11b075ce2cb3Fariborz Jahanian } while ((LDecl = LDecl->getSuperClass())); 5934db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian 5935db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian return QualType(); 5936db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian} 5937db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian 5938c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallbool ASTContext::canAssignObjCInterfaces(const ObjCObjectType *LHS, 5939c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *RHS) { 5940c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(LHS->getInterface() && "LHS is not an interface type"); 5941c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(RHS->getInterface() && "RHS is not an interface type"); 5942c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 59436ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // Verify that the base decls are compatible: the RHS must be a subclass of 59446ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // the LHS. 5945c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!LHS->getInterface()->isSuperClassOf(RHS->getInterface())) 59466ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return false; 59471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59486ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // RHS must have a superset of the protocols in the LHS. If the LHS is not 59496ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // protocol qualified at all, then we are good. 5950c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (LHS->getNumProtocols() == 0) 59516ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return true; 59521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5953b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // Okay, we know the LHS has protocol qualifiers. If the RHS doesn't, 5954b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // more detailed analysis is required. 5955b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (RHS->getNumProtocols() == 0) { 5956b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // OK, if LHS is a superclass of RHS *and* 5957b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // this superclass is assignment compatible with LHS. 5958b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // false otherwise. 5959627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian bool IsSuperClass = 5960627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian LHS->getInterface()->isSuperClassOf(RHS->getInterface()); 5961627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian if (IsSuperClass) { 5962b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // OK if conversion of LHS to SuperClass results in narrowing of types 5963b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // ; i.e., SuperClass may implement at least one of the protocols 5964b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // in LHS's protocol list. Example, SuperObj<P1> = lhs<P1,P2> is ok. 5965b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // But not SuperObj<P1,P2,P3> = lhs<P1,P2>. 5966b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> SuperClassInheritedProtocols; 5967627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian CollectInheritedProtocols(RHS->getInterface(), SuperClassInheritedProtocols); 5968b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // If super class has no protocols, it is not a match. 5969b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (SuperClassInheritedProtocols.empty()) 5970b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return false; 5971b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian 5972b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian for (ObjCObjectType::qual_iterator LHSPI = LHS->qual_begin(), 5973b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian LHSPE = LHS->qual_end(); 5974b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian LHSPI != LHSPE; LHSPI++) { 5975b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian bool SuperImplementsProtocol = false; 5976b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian ObjCProtocolDecl *LHSProto = (*LHSPI); 5977b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian 5978b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 5979b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian SuperClassInheritedProtocols.begin(), 5980b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian E = SuperClassInheritedProtocols.end(); I != E; ++I) { 5981b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian ObjCProtocolDecl *SuperClassProto = (*I); 5982b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (SuperClassProto->lookupProtocolNamed(LHSProto->getIdentifier())) { 5983b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian SuperImplementsProtocol = true; 5984b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian break; 5985b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 5986b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 5987b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (!SuperImplementsProtocol) 5988b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return false; 5989b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 5990b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return true; 5991b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 5992b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return false; 5993b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 59941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5995c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (ObjCObjectType::qual_iterator LHSPI = LHS->qual_begin(), 5996c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall LHSPE = LHS->qual_end(); 599791b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff LHSPI != LHSPE; LHSPI++) { 599891b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff bool RHSImplementsProtocol = false; 599991b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff 600091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // If the RHS doesn't implement the protocol on the left, the types 600191b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // are incompatible. 6002c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (ObjCObjectType::qual_iterator RHSPI = RHS->qual_begin(), 6003c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall RHSPE = RHS->qual_end(); 60048f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff RHSPI != RHSPE; RHSPI++) { 60058f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff if ((*RHSPI)->lookupProtocolNamed((*LHSPI)->getIdentifier())) { 600691b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff RHSImplementsProtocol = true; 60078f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 60088f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 600991b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 601091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // FIXME: For better diagnostics, consider passing back the protocol name. 601191b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff if (!RHSImplementsProtocol) 601291b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return false; 601391b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 601491b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // The RHS implements all protocols listed on the LHS. 601591b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return true; 60166ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 60176ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 6018389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroffbool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { 6019389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff // get the "pointed to" types 6020183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *LHSOPT = LHS->getAs<ObjCObjectPointerType>(); 6021183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *RHSOPT = RHS->getAs<ObjCObjectPointerType>(); 60221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 602314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (!LHSOPT || !RHSOPT) 6024389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff return false; 602514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 602614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return canAssignObjCInterfaces(LHSOPT, RHSOPT) || 602714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff canAssignObjCInterfaces(RHSOPT, LHSOPT); 6028389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff} 6029389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff 6030569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorbool ASTContext::canBindObjCObjectType(QualType To, QualType From) { 6031569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return canAssignObjCInterfaces( 6032569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor getObjCObjectPointerType(To)->getAs<ObjCObjectPointerType>(), 6033569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor getObjCObjectPointerType(From)->getAs<ObjCObjectPointerType>()); 6034569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor} 6035569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor 60361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typesAreCompatible - C99 6.7.3p9: For two qualified types to be compatible, 6037ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// both shall have the identically qualified version of a compatible type. 60381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// C99 6.2.7p1: Two types have compatible types if their types are the 6039ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// same. See 6.7.[2,3,5] for additional rules. 6040447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregorbool ASTContext::typesAreCompatible(QualType LHS, QualType RHS, 6041447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool CompareUnqualified) { 60424e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 60430e709abafbd939326850501f795cc7a92c88a354Douglas Gregor return hasSameType(LHS, RHS); 60440e709abafbd939326850501f795cc7a92c88a354Douglas Gregor 6045447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor return !mergeTypes(LHS, RHS, false, CompareUnqualified).isNull(); 60463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 60473d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6048c286f3835eb6001c61664cef5d610dfaf80a6e9bFariborz Jahanianbool ASTContext::propertyTypesAreCompatible(QualType LHS, QualType RHS) { 604982378391dfc3b2fc22f63dbf1552bd9aed39dc42Fariborz Jahanian return typesAreCompatible(LHS, RHS); 6050c286f3835eb6001c61664cef5d610dfaf80a6e9bFariborz Jahanian} 6051c286f3835eb6001c61664cef5d610dfaf80a6e9bFariborz Jahanian 6052132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanianbool ASTContext::typesAreBlockPointerCompatible(QualType LHS, QualType RHS) { 6053132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return !mergeTypes(LHS, RHS, true).isNull(); 6054132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian} 6055132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 60564846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// mergeTransparentUnionType - if T is a transparent union type and a member 60574846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// of T is compatible with SubType, return the merged type, else return 60584846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// QualType() 60594846675e0e42d1802b0ffd8972a45e72aeb3758dPeter CollingbourneQualType ASTContext::mergeTransparentUnionType(QualType T, QualType SubType, 60604846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool OfBlockPointer, 60614846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool Unqualified) { 60624846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (const RecordType *UT = T->getAsUnionType()) { 60634846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne RecordDecl *UD = UT->getDecl(); 60644846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (UD->hasAttr<TransparentUnionAttr>()) { 60654846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne for (RecordDecl::field_iterator it = UD->field_begin(), 60664846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne itend = UD->field_end(); it != itend; ++it) { 6067f91d7572ee7fa6f2926c8e7e816039a1154a59f8Peter Collingbourne QualType ET = it->getType().getUnqualifiedType(); 60684846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType MT = mergeTypes(ET, SubType, OfBlockPointer, Unqualified); 60694846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (!MT.isNull()) 60704846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return MT; 60714846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne } 60724846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne } 60734846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne } 60744846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 60754846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return QualType(); 60764846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne} 60774846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 60784846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// mergeFunctionArgumentTypes - merge two types which appear as function 60794846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// argument types 60804846675e0e42d1802b0ffd8972a45e72aeb3758dPeter CollingbourneQualType ASTContext::mergeFunctionArgumentTypes(QualType lhs, QualType rhs, 60814846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool OfBlockPointer, 60824846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool Unqualified) { 60834846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne // GNU extension: two types are compatible if they appear as a function 60844846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne // argument, one of the types is a transparent union type and the other 60854846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne // type is compatible with a union member 60864846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType lmerge = mergeTransparentUnionType(lhs, rhs, OfBlockPointer, 60874846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne Unqualified); 60884846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (!lmerge.isNull()) 60894846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return lmerge; 60904846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 60914846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType rmerge = mergeTransparentUnionType(rhs, lhs, OfBlockPointer, 60924846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne Unqualified); 60934846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (!rmerge.isNull()) 60944846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return rmerge; 60954846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 60964846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return mergeTypes(lhs, rhs, OfBlockPointer, Unqualified); 60974846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne} 60984846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 6099132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz JahanianQualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, 6100447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool OfBlockPointer, 6101447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool Unqualified) { 6102183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *lbase = lhs->getAs<FunctionType>(); 6103183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *rbase = rhs->getAs<FunctionType>(); 610472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *lproto = dyn_cast<FunctionProtoType>(lbase); 610572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *rproto = dyn_cast<FunctionProtoType>(rbase); 61063d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allLTypes = true; 61073d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allRTypes = true; 61083d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 61093d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check return type 6110132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian QualType retType; 6111d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian if (OfBlockPointer) { 6112d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian QualType RHS = rbase->getResultType(); 6113d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian QualType LHS = lbase->getResultType(); 6114d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian bool UnqualifiedResult = Unqualified; 6115d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian if (!UnqualifiedResult) 6116d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian UnqualifiedResult = (!RHS.hasQualifiers() && LHS.hasQualifiers()); 6117a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian retType = mergeTypes(LHS, RHS, true, UnqualifiedResult, true); 6118d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian } 6119132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian else 61208cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall retType = mergeTypes(lbase->getResultType(), rbase->getResultType(), false, 61218cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall Unqualified); 61223d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (retType.isNull()) return QualType(); 6123447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6124447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) 6125447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor retType = retType.getUnqualifiedType(); 6126447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6127447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor CanQualType LRetType = getCanonicalType(lbase->getResultType()); 6128447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor CanQualType RRetType = getCanonicalType(rbase->getResultType()); 6129447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6130447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LRetType = LRetType.getUnqualifiedType(); 6131447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RRetType = RRetType.getUnqualifiedType(); 6132447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6133447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6134447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (getCanonicalType(retType) != LRetType) 613561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 6136447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (getCanonicalType(retType) != RRetType) 613761710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 61388cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 61396a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // FIXME: double check this 61406a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // FIXME: should we error if lbase->getRegParmAttr() != 0 && 61416a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // rbase->getRegParmAttr() != 0 && 61426a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // lbase->getRegParmAttr() != rbase->getRegParmAttr()? 6143264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionType::ExtInfo lbaseInfo = lbase->getExtInfo(); 6144264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionType::ExtInfo rbaseInfo = rbase->getExtInfo(); 61458cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 61468cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall // Compatible functions must have compatible calling conventions 61478cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall if (!isSameCallConv(lbaseInfo.getCC(), rbaseInfo.getCC())) 61488cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall return QualType(); 61498cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 61508cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall // Regparm is part of the calling convention. 6151a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman if (lbaseInfo.getHasRegParm() != rbaseInfo.getHasRegParm()) 6152a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman return QualType(); 61538cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall if (lbaseInfo.getRegParm() != rbaseInfo.getRegParm()) 61548cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall return QualType(); 61558cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 6156f85e193739c953358c865005855253af4f68a497John McCall if (lbaseInfo.getProducesResult() != rbaseInfo.getProducesResult()) 6157f85e193739c953358c865005855253af4f68a497John McCall return QualType(); 6158f85e193739c953358c865005855253af4f68a497John McCall 615953c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian // functypes which return are preferred over those that do not. 616053c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian if (lbaseInfo.getNoReturn() && !rbaseInfo.getNoReturn()) 61616a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar allLTypes = false; 616253c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian else if (!lbaseInfo.getNoReturn() && rbaseInfo.getNoReturn()) 61636a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar allRTypes = false; 616453c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian // FIXME: some uses, e.g. conditional exprs, really want this to be 'both'. 616553c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian bool NoReturn = lbaseInfo.getNoReturn() || rbaseInfo.getNoReturn(); 61661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6167f85e193739c953358c865005855253af4f68a497John McCall FunctionType::ExtInfo einfo = lbaseInfo.withNoReturn(NoReturn); 6168e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 61693d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto && rproto) { // two C99 style function prototypes 6170465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() && 6171465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl "C++ shouldn't be here"); 61723d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned lproto_nargs = lproto->getNumArgs(); 61733d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned rproto_nargs = rproto->getNumArgs(); 61743d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 61753d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Compatible functions must have the same number of arguments 61763d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto_nargs != rproto_nargs) 61773d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 61783d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 61793d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Variadic and non-variadic functions aren't compatible 61803d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto->isVariadic() != rproto->isVariadic()) 61813d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 61823d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 61837fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis if (lproto->getTypeQuals() != rproto->getTypeQuals()) 61847fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis return QualType(); 61857fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis 618678213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (LangOpts.ObjCAutoRefCount && 618778213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian !FunctionTypesMatchOnNSConsumedAttrs(rproto, lproto)) 618878213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return QualType(); 618978213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian 61903d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check argument compatibility 61915f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 10> types; 61923d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < lproto_nargs; i++) { 61933d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType largtype = lproto->getArgType(i).getUnqualifiedType(); 61943d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType rargtype = rproto->getArgType(i).getUnqualifiedType(); 61954846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType argtype = mergeFunctionArgumentTypes(largtype, rargtype, 61964846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne OfBlockPointer, 61974846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne Unqualified); 61983d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argtype.isNull()) return QualType(); 6199447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6200447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) 6201447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor argtype = argtype.getUnqualifiedType(); 6202447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 62033d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman types.push_back(argtype); 6204447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6205447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor largtype = largtype.getUnqualifiedType(); 6206447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor rargtype = rargtype.getUnqualifiedType(); 6207447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6208447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 620961710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(largtype)) 621061710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 621161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(rargtype)) 621261710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 62133d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 621478213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian 62153d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 62163d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 6217e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 6218e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI = lproto->getExtProtoInfo(); 6219e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = einfo; 6220e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return getFunctionType(retType, types.begin(), types.size(), EPI); 62213d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 62223d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 62233d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto) allRTypes = false; 62243d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (rproto) allLTypes = false; 62253d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 622672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *proto = lproto ? lproto : rproto; 62273d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto) { 6228465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!proto->hasExceptionSpec() && "C++ shouldn't be here"); 62293d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto->isVariadic()) return QualType(); 62303d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check that the types are compatible with the types that 62313d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // would result from default argument promotions (C99 6.7.5.3p15). 62323d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // The only types actually affected are promotable integer 62333d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // types and floats, which would be passed as a different 62343d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // type depending on whether the prototype is visible. 62353d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned proto_nargs = proto->getNumArgs(); 62363d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < proto_nargs; ++i) { 62373d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType argTy = proto->getArgType(i); 6238b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor 6239b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor // Look at the promotion type of enum types, since that is the type used 6240b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor // to pass enum values. 6241b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor if (const EnumType *Enum = argTy->getAs<EnumType>()) 6242b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor argTy = Enum->getDecl()->getPromotionType(); 6243b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor 62443d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argTy->isPromotableIntegerType() || 62453d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman getCanonicalType(argTy).getUnqualifiedType() == FloatTy) 62463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 62473d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 62483d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 62493d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 62503d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 6251e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 6252e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI = proto->getExtProtoInfo(); 6253e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = einfo; 62543d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getFunctionType(retType, proto->arg_type_begin(), 6255e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall proto->getNumArgs(), EPI); 62563d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 62573d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 62583d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 62593d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 62608cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall return getFunctionNoProtoType(retType, einfo); 62613d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 62623d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6263132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz JahanianQualType ASTContext::mergeTypes(QualType LHS, QualType RHS, 6264447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool OfBlockPointer, 6265a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian bool Unqualified, bool BlockReturnType) { 626643d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // C++ [expr]: If an expression initially has the type "reference to T", the 626743d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // type is adjusted to "T" prior to any further analysis, the expression 626843d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // designates the object or function denoted by the reference, and the 62697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // expression is an lvalue unless the reference is an rvalue reference and 62707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // the expression is a function call (possibly inside parentheses). 62710e709abafbd939326850501f795cc7a92c88a354Douglas Gregor assert(!LHS->getAs<ReferenceType>() && "LHS is a reference type?"); 62720e709abafbd939326850501f795cc7a92c88a354Douglas Gregor assert(!RHS->getAs<ReferenceType>() && "RHS is a reference type?"); 6273447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6274447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6275447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHS = LHS.getUnqualifiedType(); 6276447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHS = RHS.getUnqualifiedType(); 6277447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 62780e709abafbd939326850501f795cc7a92c88a354Douglas Gregor 62793d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSCan = getCanonicalType(LHS), 62803d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman RHSCan = getCanonicalType(RHS); 62813d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6282f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner // If two types are identical, they are compatible. 62833d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LHSCan == RHSCan) 62843d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 62853d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 62860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If the qualifiers are different, the types aren't compatible... mostly. 6287a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers LQuals = LHSCan.getLocalQualifiers(); 6288a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers RQuals = RHSCan.getLocalQualifiers(); 62890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (LQuals != RQuals) { 62900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If any of these qualifiers are different, we have a type 62910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // mismatch. 62920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || 6293f85e193739c953358c865005855253af4f68a497John McCall LQuals.getAddressSpace() != RQuals.getAddressSpace() || 6294f85e193739c953358c865005855253af4f68a497John McCall LQuals.getObjCLifetime() != RQuals.getObjCLifetime()) 62950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(); 62960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 62970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Exactly one GC qualifier difference is allowed: __strong is 62980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // okay if the other type has no GC qualifier but is an Objective 62990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // C object pointer (i.e. implicitly strong by default). We fix 63000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // this by pretending that the unqualified type was actually 63010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualified __strong. 63020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GC_L = LQuals.getObjCGCAttr(); 63030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GC_R = RQuals.getObjCGCAttr(); 63040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements"); 63050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 63060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) 63070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(); 63080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 63090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_L == Qualifiers::Strong && RHSCan->isObjCObjectPointerType()) { 63100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return mergeTypes(LHS, getObjCGCQualType(RHS, Qualifiers::Strong)); 63110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 63120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_R == Qualifiers::Strong && LHSCan->isObjCObjectPointerType()) { 63130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return mergeTypes(getObjCGCQualType(LHS, Qualifiers::Strong), RHS); 63140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 63153d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 63160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 63170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 63180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Okay, qualifiers are equal. 63193d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6320852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass LHSClass = LHSCan->getTypeClass(); 6321852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass RHSClass = RHSCan->getTypeClass(); 6322f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner 63231adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // We want to consider the two function types to be the same for these 63241adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // comparisons, just force one to the other. 63251adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (LHSClass == Type::FunctionProto) LHSClass = Type::FunctionNoProto; 63261adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (RHSClass == Type::FunctionProto) RHSClass = Type::FunctionNoProto; 63274c721d381fb279899337d120edd4a24d405e56b2Eli Friedman 63284c721d381fb279899337d120edd4a24d405e56b2Eli Friedman // Same as above for arrays 6329a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (LHSClass == Type::VariableArray || LHSClass == Type::IncompleteArray) 6330a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner LHSClass = Type::ConstantArray; 6331a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (RHSClass == Type::VariableArray || RHSClass == Type::IncompleteArray) 6332a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner RHSClass = Type::ConstantArray; 63331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6334c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCInterfaces are just specialized ObjCObjects. 6335c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHSClass == Type::ObjCInterface) LHSClass = Type::ObjCObject; 6336c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (RHSClass == Type::ObjCInterface) RHSClass = Type::ObjCObject; 6337c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 6338213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman // Canonicalize ExtVector -> Vector. 6339213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (LHSClass == Type::ExtVector) LHSClass = Type::Vector; 6340213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (RHSClass == Type::ExtVector) RHSClass = Type::Vector; 63411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63424e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff // If the canonical type classes don't match. 63434e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff if (LHSClass != RHSClass) { 63441adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // C99 6.7.2.2p4: Each enumerated type shall be compatible with char, 63451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // a signed integer type, or an unsigned integer type. 6346842aef8d942a880eeb9535d40de31a86838264cbJohn McCall // Compatibility is based on the underlying type, not the promotion 6347842aef8d942a880eeb9535d40de31a86838264cbJohn McCall // type. 6348183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const EnumType* ETy = LHS->getAs<EnumType>()) { 6349b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian QualType TINT = ETy->getDecl()->getIntegerType(); 6350b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian if (!TINT.isNull() && hasSameType(TINT, RHSCan.getUnqualifiedType())) 63513d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 6352bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 6353183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const EnumType* ETy = RHS->getAs<EnumType>()) { 6354b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian QualType TINT = ETy->getDecl()->getIntegerType(); 6355b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian if (!TINT.isNull() && hasSameType(TINT, LHSCan.getUnqualifiedType())) 63563d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 6357bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 6358e7cff2c00c3d74e38984a4db5c48d7e303d3ab8eFariborz Jahanian // allow block pointer type to match an 'id' type. 6359419636316c04d570c183b4797fc811932c588358Fariborz Jahanian if (OfBlockPointer && !BlockReturnType) { 6360419636316c04d570c183b4797fc811932c588358Fariborz Jahanian if (LHS->isObjCIdType() && RHS->isBlockPointerType()) 6361419636316c04d570c183b4797fc811932c588358Fariborz Jahanian return LHS; 6362419636316c04d570c183b4797fc811932c588358Fariborz Jahanian if (RHS->isObjCIdType() && LHS->isBlockPointerType()) 6363419636316c04d570c183b4797fc811932c588358Fariborz Jahanian return RHS; 6364419636316c04d570c183b4797fc811932c588358Fariborz Jahanian } 6365e7cff2c00c3d74e38984a4db5c48d7e303d3ab8eFariborz Jahanian 63663d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 6367ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 63683d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 63694a74678ed6c3dedac05d02b1ee341f1db869f049Steve Naroff // The canonical type classes match. 63701adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner switch (LHSClass) { 637172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 637272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 6373ad5e73887052193afda72db8efcb812bd083a4a8John McCall#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class: 637472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 637572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 637672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 6377b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Non-canonical and dependent types shouldn't get here"); 637872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 63797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::LValueReference: 63807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::RValueReference: 638172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::MemberPointer: 6382b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("C++ should never be in mergeTypes"); 638372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 6384c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case Type::ObjCInterface: 638572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 638672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::VariableArray: 638772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::FunctionProto: 638872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::ExtVector: 6389b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Types are eliminated above"); 639072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 63911adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Pointer: 63923d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 63933d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Merge two pointer types, while trying to preserve typedef info 63946217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<PointerType>()->getPointeeType(); 63956217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<PointerType>()->getPointeeType(); 6396447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6397447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHSPointee = LHSPointee.getUnqualifiedType(); 6398447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHSPointee = RHSPointee.getUnqualifiedType(); 6399447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6400447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor QualType ResultType = mergeTypes(LHSPointee, RHSPointee, false, 6401447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor Unqualified); 64023d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 640307d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 640461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 640507d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 640661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 64073d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getPointerType(ResultType); 64083d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 6409c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff case Type::BlockPointer: 6410c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff { 6411c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff // Merge two block pointer types, while trying to preserve typedef info 64126217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<BlockPointerType>()->getPointeeType(); 64136217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<BlockPointerType>()->getPointeeType(); 6414447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6415447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHSPointee = LHSPointee.getUnqualifiedType(); 6416447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHSPointee = RHSPointee.getUnqualifiedType(); 6417447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6418447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor QualType ResultType = mergeTypes(LHSPointee, RHSPointee, OfBlockPointer, 6419447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor Unqualified); 6420c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (ResultType.isNull()) return QualType(); 6421c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 6422c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return LHS; 6423c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 6424c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return RHS; 6425c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return getBlockPointerType(ResultType); 6426c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff } 6427b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: 6428b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman { 6429b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // Merge two pointer types, while trying to preserve typedef info 6430b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType LHSValue = LHS->getAs<AtomicType>()->getValueType(); 6431b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType RHSValue = RHS->getAs<AtomicType>()->getValueType(); 6432b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (Unqualified) { 6433b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman LHSValue = LHSValue.getUnqualifiedType(); 6434b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman RHSValue = RHSValue.getUnqualifiedType(); 6435b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 6436b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ResultType = mergeTypes(LHSValue, RHSValue, false, 6437b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Unqualified); 6438b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (ResultType.isNull()) return QualType(); 6439b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getCanonicalType(LHSValue) == getCanonicalType(ResultType)) 6440b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return LHS; 6441b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getCanonicalType(RHSValue) == getCanonicalType(ResultType)) 6442b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return RHS; 6443b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return getAtomicType(ResultType); 6444b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 64451adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::ConstantArray: 64463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 64473d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* LCAT = getAsConstantArrayType(LHS); 64483d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* RCAT = getAsConstantArrayType(RHS); 64493d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LCAT && RCAT && RCAT->getSize() != LCAT->getSize()) 64503d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 64513d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 64523d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSElem = getAsArrayType(LHS)->getElementType(); 64533d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType RHSElem = getAsArrayType(RHS)->getElementType(); 6454447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6455447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHSElem = LHSElem.getUnqualifiedType(); 6456447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHSElem = RHSElem.getUnqualifiedType(); 6457447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6458447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6459447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor QualType ResultType = mergeTypes(LHSElem, RHSElem, false, Unqualified); 64603d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 646161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LCAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 646261710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 646361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RCAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 646461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 64653bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (LCAT) return getConstantArrayType(ResultType, LCAT->getSize(), 64663bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 64673bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (RCAT) return getConstantArrayType(ResultType, RCAT->getSize(), 64683bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 64693d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* LVAT = getAsVariableArrayType(LHS); 64703d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* RVAT = getAsVariableArrayType(RHS); 647161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LVAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 647261710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 647361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RVAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 647461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 64753d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LVAT) { 64763d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 64773d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of LHS, but the type 64783d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 64793d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 64803d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 64813d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (RVAT) { 64823d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 64833d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of RHS, but the type 64843d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 64853d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 64863d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 64873bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS; 64883bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS; 64897e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return getIncompleteArrayType(ResultType, 64907e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArrayType::ArraySizeModifier(), 0); 64913d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 64921adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::FunctionNoProto: 6493447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor return mergeFunctionTypes(LHS, RHS, OfBlockPointer, Unqualified); 649472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 649572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: 64963d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 64971adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Builtin: 64983cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner // Only exactly equal builtin types are compatible, which is tested above. 64993d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 650064cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar case Type::Complex: 650164cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar // Distinct complex types are incompatible. 650264cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar return QualType(); 65033cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner case Type::Vector: 65045a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: The merged type should be an ExtVector! 65051c471f3e1c0ec8cbc82447bb35908dfc55463e46John McCall if (areCompatVectorTypes(LHSCan->getAs<VectorType>(), 65061c471f3e1c0ec8cbc82447bb35908dfc55463e46John McCall RHSCan->getAs<VectorType>())) 65073d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 650861710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return QualType(); 6509c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case Type::ObjCObject: { 6510c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Check if the types are assignment compatible. 65115a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: This should be type compatibility, e.g. whether 65125a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // "LHS x; RHS x;" at global scope is legal. 6513c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* LHSIface = LHS->getAs<ObjCObjectType>(); 6514c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* RHSIface = RHS->getAs<ObjCObjectType>(); 6515c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (canAssignObjCInterfaces(LHSIface, RHSIface)) 65165fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff return LHS; 65175fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff 65183d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 651961490e9a965cfee8a78c12c6802138844f04250dCedric Venet } 652014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case Type::ObjCObjectPointer: { 6521132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (OfBlockPointer) { 6522132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (canAssignObjCInterfacesInBlockPointer( 6523132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian LHS->getAs<ObjCObjectPointerType>(), 6524a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian RHS->getAs<ObjCObjectPointerType>(), 6525a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian BlockReturnType)) 65267530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie return LHS; 6527132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return QualType(); 6528132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 6529183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (canAssignObjCInterfaces(LHS->getAs<ObjCObjectPointerType>(), 6530183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall RHS->getAs<ObjCObjectPointerType>())) 653114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return LHS; 653214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 6533bc76dd06eb881c70c9775b74bab8b88cd747f173Steve Naroff return QualType(); 65347530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie } 6535ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 653672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 65377530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid Type::Class!"); 6538ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff} 65397192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek 654078213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanianbool ASTContext::FunctionTypesMatchOnNSConsumedAttrs( 654178213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian const FunctionProtoType *FromFunctionType, 654278213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian const FunctionProtoType *ToFunctionType) { 654378213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (FromFunctionType->hasAnyConsumedArgs() != 654478213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ToFunctionType->hasAnyConsumedArgs()) 654578213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return false; 654678213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian FunctionProtoType::ExtProtoInfo FromEPI = 654778213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian FromFunctionType->getExtProtoInfo(); 654878213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian FunctionProtoType::ExtProtoInfo ToEPI = 654978213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ToFunctionType->getExtProtoInfo(); 655078213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (FromEPI.ConsumedArguments && ToEPI.ConsumedArguments) 655178213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumArgs(); 655278213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ArgIdx != NumArgs; ++ArgIdx) { 655378213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (FromEPI.ConsumedArguments[ArgIdx] != 655478213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ToEPI.ConsumedArguments[ArgIdx]) 655578213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return false; 655678213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian } 655778213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return true; 655878213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian} 655978213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian 65602390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian/// mergeObjCGCQualifiers - This routine merges ObjC's GC attribute of 'LHS' and 65612390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian/// 'RHS' attributes and returns the merged version; including for function 65622390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian/// return types. 65632390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz JahanianQualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { 65642390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType LHSCan = getCanonicalType(LHS), 65652390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian RHSCan = getCanonicalType(RHS); 65662390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // If two types are identical, they are compatible. 65672390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LHSCan == RHSCan) 65682390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return LHS; 65692390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (RHSCan->isFunctionType()) { 65702390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (!LHSCan->isFunctionType()) 65712390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 65722390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType OldReturnType = 65732390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian cast<FunctionType>(RHSCan.getTypePtr())->getResultType(); 65742390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType NewReturnType = 65752390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian cast<FunctionType>(LHSCan.getTypePtr())->getResultType(); 65762390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType ResReturnType = 65772390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian mergeObjCGCQualifiers(NewReturnType, OldReturnType); 65782390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResReturnType.isNull()) 65792390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 65802390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResReturnType == NewReturnType || ResReturnType == OldReturnType) { 65812390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // id foo(); ... __strong id foo(); or: __strong id foo(); ... id foo(); 65822390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // In either case, use OldReturnType to build the new function type. 65832390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian const FunctionType *F = LHS->getAs<FunctionType>(); 65842390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (const FunctionProtoType *FPT = cast<FunctionProtoType>(F)) { 6585e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); 6586e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = getFunctionExtInfo(LHS); 65872390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType ResultType 65882390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian = getFunctionType(OldReturnType, FPT->arg_type_begin(), 6589e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FPT->getNumArgs(), EPI); 65902390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return ResultType; 65912390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 65922390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 65932390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 65942390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 65952390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 65962390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // If the qualifiers are different, the types can still be merged. 65972390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers LQuals = LHSCan.getLocalQualifiers(); 65982390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers RQuals = RHSCan.getLocalQualifiers(); 65992390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LQuals != RQuals) { 66002390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // If any of these qualifiers are different, we have a type mismatch. 66012390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || 66022390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian LQuals.getAddressSpace() != RQuals.getAddressSpace()) 66032390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 66042390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 66052390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // Exactly one GC qualifier difference is allowed: __strong is 66062390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // okay if the other type has no GC qualifier but is an Objective 66072390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // C object pointer (i.e. implicitly strong by default). We fix 66082390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // this by pretending that the unqualified type was actually 66092390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // qualified __strong. 66102390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers::GC GC_L = LQuals.getObjCGCAttr(); 66112390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers::GC GC_R = RQuals.getObjCGCAttr(); 66122390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements"); 66132390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 66142390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) 66152390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 66162390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 66172390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (GC_L == Qualifiers::Strong) 66182390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return LHS; 66192390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (GC_R == Qualifiers::Strong) 66202390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return RHS; 66212390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 66222390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 66232390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 66242390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LHSCan->isObjCObjectPointerType() && RHSCan->isObjCObjectPointerType()) { 66252390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType LHSBaseQT = LHS->getAs<ObjCObjectPointerType>()->getPointeeType(); 66262390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType RHSBaseQT = RHS->getAs<ObjCObjectPointerType>()->getPointeeType(); 66272390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType ResQT = mergeObjCGCQualifiers(LHSBaseQT, RHSBaseQT); 66282390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResQT == LHSBaseQT) 66292390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return LHS; 66302390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResQT == RHSBaseQT) 66312390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return RHS; 66322390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 66332390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 66342390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian} 66352390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 66365426bf6456a5aeac416a9150de157904d101c819Chris Lattner//===----------------------------------------------------------------------===// 6637ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman// Integer Predicates 6638ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman//===----------------------------------------------------------------------===// 663988054dee0402e4d3c1f64e6b697acc47195c0d72Chris Lattner 66404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned ASTContext::getIntWidth(QualType T) const { 6641f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const EnumType *ET = dyn_cast<EnumType>(T)) 664229a7f3342c3c6dd15d914c61ae22246c36d51ce7Eli Friedman T = ET->getDecl()->getIntegerType(); 66431274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (T->isBooleanType()) 66441274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return 1; 6645f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // For builtin types, just use the standard type sizing method 6646ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return (unsigned)getTypeSize(T); 6647ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 6648ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 6649ad74a758189180b8ab8faea648e4766c3bfd7fcbEli FriedmanQualType ASTContext::getCorrespondingUnsignedType(QualType T) { 6650f60946222721d9ba3c059563935c17b84703187aDouglas Gregor assert(T->hasSignedIntegerRepresentation() && "Unexpected type"); 66516a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner 66526a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner // Turn <4 x signed int> -> <4 x unsigned int> 66536a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner if (const VectorType *VTy = T->getAs<VectorType>()) 66546a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()), 6655e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VTy->getNumElements(), VTy->getVectorKind()); 66566a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner 66576a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner // For enums, we return the unsigned version of the base type. 66586a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner if (const EnumType *ETy = T->getAs<EnumType>()) 6659ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman T = ETy->getDecl()->getIntegerType(); 66606a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner 66616a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner const BuiltinType *BTy = T->getAs<BuiltinType>(); 66626a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner assert(BTy && "Unexpected signed integer type"); 6663ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman switch (BTy->getKind()) { 6664ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Char_S: 6665ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::SChar: 6666ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedCharTy; 6667ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Short: 6668ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedShortTy; 6669ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Int: 6670ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedIntTy; 6671ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Long: 6672ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongTy; 6673ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::LongLong: 6674ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongLongTy; 66752df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 66762df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return UnsignedInt128Ty; 6677ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman default: 6678b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unexpected signed integer type"); 6679ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman } 6680ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 6681ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 66827b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios KyrtzidisASTMutationListener::~ASTMutationListener() { } 66837b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 668486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 668586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 668686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner// Builtin Type Computation 668786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 668886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 668986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// DecodeTypeFromStr - This decodes one type descriptor from Str, advancing the 669033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// pointer over the consumed characters. This returns the resultant type. If 669133daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// AllowTypeModifiers is false then modifier like * are not parsed, just basic 669233daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// types. This allows "v2i*" to be parsed as a pointer to a v2i instead of 669333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// a vector of "i*". 669414e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner/// 669514e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner/// RequiresICE is filled in on return to indicate whether the value is required 669614e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner/// to be an Integer Constant Expression. 66974ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadstatic QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, 669886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ASTContext::GetBuiltinTypeError &Error, 669914e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner bool &RequiresICE, 670033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner bool AllowTypeModifiers) { 670186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Modifiers. 670286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner int HowLong = 0; 670386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Signed = false, Unsigned = false; 670414e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE = false; 6705393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner 670633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // Read the prefixed modifiers first. 670786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Done = false; 670886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 670986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 67101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: Done = true; --Str; break; 6711393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner case 'I': 671214e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE = true; 6713393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner break; 671486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'S': 671586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use both 'S' and 'U' modifiers!"); 671686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use 'S' modifier multiple times!"); 671786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Signed = true; 671886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 671986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'U': 672086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use both 'S' and 'U' modifiers!"); 672186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use 'S' modifier multiple times!"); 672286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Unsigned = true; 672386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 672486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'L': 672586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong <= 2 && "Can't have LLLL modifier"); 672686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ++HowLong; 672786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 672886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 672986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 673086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 673186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType Type; 67321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 673386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Read the base type. 673486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 6735b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unknown builtin type letter!"); 673686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'v': 673786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 673886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'v'!"); 673986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.VoidTy; 674086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 674186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'f': 674286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 674386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'f'!"); 674486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.FloatTy; 674586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 674686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'd': 674786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong < 2 && !Signed && !Unsigned && 674886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'd'!"); 674986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong) 675086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.LongDoubleTy; 675186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 675286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.DoubleTy; 675386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 675486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 's': 675586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 's'!"); 675686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Unsigned) 675786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedShortTy; 675886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 675986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.ShortTy; 676086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 676186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'i': 676286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong == 3) 676386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty; 676486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 2) 676586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy; 676686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 1) 676786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy; 676886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 676986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy; 677086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 677186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'c': 677286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 'c'!"); 677386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Signed) 677486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.SignedCharTy; 677586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (Unsigned) 677686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedCharTy; 677786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 677886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.CharTy; 677986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 678086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'b': // boolean 678186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'b'!"); 678286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.BoolTy; 678386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 678486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'z': // size_t. 678586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'z'!"); 678686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getSizeType(); 678786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 678886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'F': 678986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getCFConstantStringType(); 679086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 6791ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian case 'G': 6792ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian Type = Context.getObjCIdType(); 6793ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian break; 6794ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian case 'H': 6795ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian Type = Context.getObjCSelType(); 6796ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian break; 679786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'a': 679886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 679986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 680086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 680186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'A': 680286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // This is a "reference" to a va_list; however, what exactly 680386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // this means depends on how va_list is defined. There are two 680486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // different kinds of va_list: ones passed by value, and ones 680586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // passed by reference. An example of a by-value va_list is 680686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // x86, where va_list is a char*. An example of by-ref va_list 680786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // is x86-64, where va_list is a __va_list_tag[1]. For x86, 680886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // we want this argument to be a char*&; for x86-64, we want 680986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // it to be a __va_list_tag*. 681086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 681186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 681214e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner if (Type->isArrayType()) 681386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getArrayDecayedType(Type); 681414e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner else 681586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getLValueReferenceType(Type); 681686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 681786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'V': { 681886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner char *End; 681986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner unsigned NumElements = strtoul(Str, &End, 10); 682086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(End != Str && "Missing vector size"); 682186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Str = End; 68221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 682314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType ElementType = DecodeTypeFromStr(Str, Context, Error, 682414e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE, false); 682514e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert(!RequiresICE && "Can't require vector ICE"); 682633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner 682733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // TODO: No way to make AltiVec vectors in builtins yet. 6828788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner Type = Context.getVectorType(ElementType, NumElements, 6829e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::GenericVector); 683086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 683186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 6832b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor case 'E': { 6833b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor char *End; 6834b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor 6835b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor unsigned NumElements = strtoul(Str, &End, 10); 6836b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor assert(End != Str && "Missing vector size"); 6837b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor 6838b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor Str = End; 6839b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor 6840b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor QualType ElementType = DecodeTypeFromStr(Str, Context, Error, RequiresICE, 6841b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor false); 6842b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor Type = Context.getExtVectorType(ElementType, NumElements); 6843b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor break; 6844b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor } 6845d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor case 'X': { 684614e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType ElementType = DecodeTypeFromStr(Str, Context, Error, RequiresICE, 684714e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner false); 684814e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert(!RequiresICE && "Can't require complex ICE"); 6849d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor Type = Context.getComplexType(ElementType); 6850d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor break; 6851cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian } 6852cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian case 'Y' : { 6853cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian Type = Context.getPointerDiffType(); 6854cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian break; 6855cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian } 68569a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'P': 6857c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor Type = Context.getFILEType(); 6858c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor if (Type.isNull()) { 6859f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_stdio; 686086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 686186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 6862fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 68639a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'J': 6864f711c41dd9412a8182793259d355c4f6979ed5edMike Stump if (Signed) 6865782fa308a765aeac2acb39c4e697c937ec21185bMike Stump Type = Context.getsigjmp_bufType(); 6866f711c41dd9412a8182793259d355c4f6979ed5edMike Stump else 6867f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Type = Context.getjmp_bufType(); 6868f711c41dd9412a8182793259d355c4f6979ed5edMike Stump 6869fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump if (Type.isNull()) { 6870f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_setjmp; 6871fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump return QualType(); 6872fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump } 6873fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 6874e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola case 'K': 6875e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'K'!"); 6876e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola Type = Context.getucontext_tType(); 6877e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola 6878e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola if (Type.isNull()) { 6879e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola Error = ASTContext::GE_Missing_ucontext; 6880e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola return QualType(); 6881e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola } 6882e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola break; 6883782fa308a765aeac2acb39c4e697c937ec21185bMike Stump } 68841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 688533daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // If there are modifiers and if we're allowed to parse them, go for it. 688633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Done = !AllowTypeModifiers; 688786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 6888187ab37a05b8f7015b9f39cc8cd9129a0c6d0b48John McCall switch (char c = *Str++) { 688933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner default: Done = true; --Str; break; 689033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case '*': 689133daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case '&': { 689233daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // Both pointers and references can have their pointee types 689333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // qualified with an address space. 689433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner char *End; 689533daae66462e8f51ee153463b32bdefd60c801aaChris Lattner unsigned AddrSpace = strtoul(Str, &End, 10); 689633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner if (End != Str && AddrSpace != 0) { 689733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getAddrSpaceQualType(Type, AddrSpace); 689833daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Str = End; 689933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner } 690033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner if (c == '*') 690133daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getPointerType(Type); 690233daae66462e8f51ee153463b32bdefd60c801aaChris Lattner else 690333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getLValueReferenceType(Type); 690433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner break; 690533daae66462e8f51ee153463b32bdefd60c801aaChris Lattner } 690633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // FIXME: There's no way to have a built-in with an rvalue ref arg. 690733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case 'C': 690833daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Type.withConst(); 690933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner break; 691033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case 'D': 691133daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getVolatileType(Type); 691233daae66462e8f51ee153463b32bdefd60c801aaChris Lattner break; 691318932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek case 'R': 691418932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek Type = Type.withRestrict(); 691518932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek break; 691686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 691786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 6918393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner 691914e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert((!RequiresICE || Type->isIntegralOrEnumerationType()) && 6920393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner "Integer constant 'I' type must be an integer"); 69211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 692286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return Type; 692386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 692486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 692586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// GetBuiltinType - Return the type for the specified builtin. 692633daae66462e8f51ee153463b32bdefd60c801aaChris LattnerQualType ASTContext::GetBuiltinType(unsigned Id, 692714e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner GetBuiltinTypeError &Error, 69284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned *IntegerConstantArgs) const { 692933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner const char *TypeStr = BuiltinInfo.GetTypeString(Id); 69301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69315f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 8> ArgTypes; 69321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 693314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner bool RequiresICE = false; 693486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Error = GE_None; 693514e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType ResType = DecodeTypeFromStr(TypeStr, *this, Error, 693614e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE, true); 693786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 693886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 693914e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner 694014e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert(!RequiresICE && "Result of intrinsic cannot be required to be an ICE"); 694114e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner 694286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (TypeStr[0] && TypeStr[0] != '.') { 694314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType Ty = DecodeTypeFromStr(TypeStr, *this, Error, RequiresICE, true); 694486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 694586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 694686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 694714e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner // If this argument is required to be an IntegerConstantExpression and the 694814e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner // caller cares, fill in the bitmask we return. 694914e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner if (RequiresICE && IntegerConstantArgs) 695014e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner *IntegerConstantArgs |= 1 << ArgTypes.size(); 695114e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner 695286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Do array -> pointer decay. The builtin should use the decayed type. 695386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Ty->isArrayType()) 695486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Ty = getArrayDecayedType(Ty); 69551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 695686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ArgTypes.push_back(Ty); 695786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 695886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 695986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert((TypeStr[0] != '.' || TypeStr[1] == 0) && 696086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "'.' should only occur at end of builtin type list!"); 696186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 696200ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall FunctionType::ExtInfo EI; 696300ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall if (BuiltinInfo.isNoReturn(Id)) EI = EI.withNoReturn(true); 696400ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall 696500ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall bool Variadic = (TypeStr[0] == '.'); 696600ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall 696700ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall // We really shouldn't be making a no-proto type here, especially in C++. 696800ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall if (ArgTypes.empty() && Variadic) 696900ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall return getFunctionNoProtoType(ResType, EI); 6970ce056bcaa1c97b89a4b2de2112c62d060863be2bDouglas Gregor 6971e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI; 697200ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall EPI.ExtInfo = EI; 697300ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall EPI.Variadic = Variadic; 6974e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 6975e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return getFunctionType(ResType, ArgTypes.data(), ArgTypes.size(), EPI); 697686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 6977a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 697890e99a84ddd020e8fda79643748243725a2ed071Argyrios KyrtzidisGVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) { 697990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis GVALinkage External = GVA_StrongExternal; 698090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 698190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis Linkage L = FD->getLinkage(); 698290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (L) { 698390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case NoLinkage: 698490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case InternalLinkage: 698590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case UniqueExternalLinkage: 698690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_Internal; 698790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 698890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case ExternalLinkage: 698990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (FD->getTemplateSpecializationKind()) { 699090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_Undeclared: 699190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitSpecialization: 699290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis External = GVA_StrongExternal; 699390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis break; 699490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 699590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDefinition: 699690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_ExplicitTemplateInstantiation; 699790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 699890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDeclaration: 699990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ImplicitInstantiation: 700090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis External = GVA_TemplateInstantiation; 700190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis break; 700290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 700390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 700490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 700590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (!FD->isInlined()) 700690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return External; 700790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 70084e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().CPlusPlus || FD->hasAttr<GNUInlineAttr>()) { 700990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // GNU or C99 inline semantics. Determine whether this symbol should be 701090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // externally visible. 701190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (FD->isInlineDefinitionExternallyVisible()) 701290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return External; 701390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 701490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // C99 inline semantics, where the symbol is not externally visible. 701590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_C99Inline; 701690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 701790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 701890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // C++0x [temp.explicit]p9: 701990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // [ Note: The intent is that an inline function that is the subject of 702090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // an explicit instantiation declaration will still be implicitly 702190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // instantiated when used so that the body can be considered for 702290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // inlining, but that no out-of-line copy of the inline function would be 702390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // generated in the translation unit. -- end note ] 702490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (FD->getTemplateSpecializationKind() 702590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis == TSK_ExplicitInstantiationDeclaration) 702690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_C99Inline; 702790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 702890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_CXXInline; 702990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis} 703090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 703190e99a84ddd020e8fda79643748243725a2ed071Argyrios KyrtzidisGVALinkage ASTContext::GetGVALinkageForVariable(const VarDecl *VD) { 703290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // If this is a static data member, compute the kind of template 703390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // specialization. Otherwise, this variable is not part of a 703490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // template. 703590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis TemplateSpecializationKind TSK = TSK_Undeclared; 703690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (VD->isStaticDataMember()) 703790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis TSK = VD->getTemplateSpecializationKind(); 703890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 703990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis Linkage L = VD->getLinkage(); 70404e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (L == ExternalLinkage && getLangOpts().CPlusPlus && 704190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis VD->getType()->getLinkage() == UniqueExternalLinkage) 704290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis L = UniqueExternalLinkage; 704390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 704490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (L) { 704590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case NoLinkage: 704690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case InternalLinkage: 704790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case UniqueExternalLinkage: 704890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_Internal; 704990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 705090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case ExternalLinkage: 705190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (TSK) { 705290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_Undeclared: 705390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitSpecialization: 705490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_StrongExternal; 705590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 705690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDeclaration: 705790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis llvm_unreachable("Variable should not be instantiated"); 705890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Fall through to treat this like any other instantiation. 705990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 706090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDefinition: 706190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_ExplicitTemplateInstantiation; 706290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 706390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ImplicitInstantiation: 706490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_TemplateInstantiation; 706590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 706690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 706790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 70687530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid Linkage!"); 706990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis} 707090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 70714ac7c0bb39696e92fd220118fedc484c09a69870Argyrios Kyrtzidisbool ASTContext::DeclMustBeEmitted(const Decl *D) { 707290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 707390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (!VD->isFileVarDecl()) 707490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 7075144b38a7995cbe0928e34fbcc865bb2d2be4f7a3Argyrios Kyrtzidis } else if (!isa<FunctionDecl>(D)) 707690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 707790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 7078ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis // Weak references don't produce any output by themselves. 7079ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis if (D->hasAttr<WeakRefAttr>()) 7080ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis return false; 7081ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis 708290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Aliases and used decls are required. 708390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>()) 708490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 708590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 708690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 708790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Forward declarations aren't required. 708810620eb5164e31208fcbf0437cd79ae535ed0559Sean Hunt if (!FD->doesThisDeclarationHaveABody()) 7089dce67a70a86db8758c926a76fdd980f5369d5746Nick Lewycky return FD->doesDeclarationForceExternallyVisibleDefinition(); 709090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 709190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Constructors and destructors are required. 709290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>()) 709390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 709490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 709590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // The key function for a class is required. 709690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 709790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis const CXXRecordDecl *RD = MD->getParent(); 709890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (MD->isOutOfLine() && RD->isDynamicClass()) { 709990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis const CXXMethodDecl *KeyFunc = getKeyFunction(RD); 710090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (KeyFunc && KeyFunc->getCanonicalDecl() == MD->getCanonicalDecl()) 710190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 710290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 710390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 710490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 710590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis GVALinkage Linkage = GetGVALinkageForFunction(FD); 710690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 710790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // static, static inline, always_inline, and extern inline functions can 710890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // always be deferred. Normal inline functions can be deferred in C99/C++. 710990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Implicit template instantiations can also be deferred in C++. 711090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (Linkage == GVA_Internal || Linkage == GVA_C99Inline || 71113a5aca8112e03814f78906dc5d032287adb272b5Anton Yartsev Linkage == GVA_CXXInline || Linkage == GVA_TemplateInstantiation) 711290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 711390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 711490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 711594da1587f7d584fc61df793229d197969f204cd9Douglas Gregor 711690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis const VarDecl *VD = cast<VarDecl>(D); 711790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis assert(VD->isFileVarDecl() && "Expected file scoped var"); 711890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 7119ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly) 7120ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis return false; 7121ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis 712290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Structs that have non-trivial constructors or destructors are required. 712390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 712490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // FIXME: Handle references. 7125023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt // FIXME: Be more selective about which constructors we care about. 712690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const RecordType *RT = VD->getType()->getAs<RecordType>()) { 712790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl())) { 7128023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt if (RD->hasDefinition() && !(RD->hasTrivialDefaultConstructor() && 7129023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt RD->hasTrivialCopyConstructor() && 7130023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt RD->hasTrivialMoveConstructor() && 7131023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt RD->hasTrivialDestructor())) 713290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 713390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 713490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 713590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 713690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis GVALinkage L = GetGVALinkageForVariable(VD); 713790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (L == GVA_Internal || L == GVA_TemplateInstantiation) { 713890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (!(VD->getInit() && VD->getInit()->HasSideEffects(*this))) 713990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 714090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 714190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 714290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 714390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis} 7144071cc7deffad608165b1ddd5263e8bf181861520Charles Davis 71458f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur IskhodzhanovCallingConv ASTContext::getDefaultCXXMethodCallConv(bool isVariadic) { 7146ee743f903858e337434ac0335f147f4de4ecae05Charles Davis // Pass through to the C++ ABI object 71478f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov return ABI->getDefaultMethodCallConv(isVariadic); 71488f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov} 71498f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov 71508f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur IskhodzhanovCallingConv ASTContext::getCanonicalCallConv(CallingConv CC) const { 71518f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov if (CC == CC_C && !LangOpts.MRTD && getTargetInfo().getCXXABI() != CXXABI_Microsoft) 71528f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov return CC_Default; 71538f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov return CC; 7154ee743f903858e337434ac0335f147f4de4ecae05Charles Davis} 7155ee743f903858e337434ac0335f147f4de4ecae05Charles Davis 71564ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ASTContext::isNearlyEmpty(const CXXRecordDecl *RD) const { 7157dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson // Pass through to the C++ ABI object 7158dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson return ABI->isNearlyEmpty(RD); 7159dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson} 7160dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson 716114110477887e3dc168ffc6c191e72d705051f99ePeter CollingbourneMangleContext *ASTContext::createMangleContext() { 7162bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor switch (Target->getCXXABI()) { 716314110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne case CXXABI_ARM: 716414110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne case CXXABI_Itanium: 716514110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne return createItaniumMangleContext(*this, getDiagnostics()); 716614110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne case CXXABI_Microsoft: 716714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne return createMicrosoftMangleContext(*this, getDiagnostics()); 716814110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne } 7169b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unsupported ABI"); 717014110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne} 717114110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne 7172071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCXXABI::~CXXABI() {} 7173ba29bd25515fbd99e98ba0fedb9d93617b27609eTed Kremenek 7174ba29bd25515fbd99e98ba0fedb9d93617b27609eTed Kremeneksize_t ASTContext::getSideTableAllocatedMemory() const { 71750c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek return ASTRecordLayouts.getMemorySize() 71760c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(ObjCLayouts) 71770c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(KeyFunctions) 71780c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(ObjCImpls) 71790c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(BlockVarCopyInits) 71800c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(DeclAttrs) 71810c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromStaticDataMember) 71820c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromUsingDecl) 71830c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromUsingShadowDecl) 71840c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromUnnamedFieldDecl) 71850c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(OverriddenMethods) 71860c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(Types) 7187af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet + llvm::capacity_in_bytes(VariableArrayTypes) 71880d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet + llvm::capacity_in_bytes(ClassScopeSpecializationPattern); 7189ba29bd25515fbd99e98ba0fedb9d93617b27609eTed Kremenek} 7190d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek 71919e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregorunsigned ASTContext::getLambdaManglingNumber(CXXMethodDecl *CallOperator) { 71929e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor CXXRecordDecl *Lambda = CallOperator->getParent(); 71939e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor return LambdaMangleContexts[Lambda->getDeclContext()] 71949e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor .getManglingNumber(CallOperator); 71959e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor} 71969e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor 71979e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor 7198d211cb709510fbe7e75167b9feee0050851d001aTed Kremenekvoid ASTContext::setParameterIndex(const ParmVarDecl *D, unsigned int index) { 7199d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek ParamIndices[D] = index; 7200d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek} 7201d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek 7202d211cb709510fbe7e75167b9feee0050851d001aTed Kremenekunsigned ASTContext::getParameterIndex(const ParmVarDecl *D) const { 7203d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek ParameterIndexTable::const_iterator I = ParamIndices.find(D); 7204d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek assert(I != ParamIndices.end() && 7205d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek "ParmIndices lacks entry set by ParmVarDecl"); 7206d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek return I->second; 7207d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek} 7208