Decl.cpp revision 2243288c4826905b5a0837f6f21d9d821688652e
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Decl.cpp - Declaration AST Node Implementation -------------------===// 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// 10e184baeaa112ceac32420f8ca127b8d4d152d109Argyrios Kyrtzidis// This file implements the Decl subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Decl.h" 152a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor#include "clang/AST/DeclCXX.h" 160de21fd85d79bccd32f04256f5b3328ab5ed7c95Steve Naroff#include "clang/AST/DeclObjC.h" 177da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor#include "clang/AST/DeclTemplate.h" 186c2b6eb8d836da19007f7540709e16d5e39a1cbaChris Lattner#include "clang/AST/ASTContext.h" 19b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#include "clang/AST/TypeLoc.h" 20e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar#include "clang/AST/Stmt.h" 2199f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes#include "clang/AST/Expr.h" 22337cba4b3e17b98cfa512dfd12e57f4ccb0859beAnders Carlsson#include "clang/AST/ExprCXX.h" 23d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h" 241b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 25e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar#include "clang/Basic/IdentifierTable.h" 26f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall#include "clang/Parse/DeclSpec.h" 27f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall#include "llvm/Support/ErrorHandling.h" 2847b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor#include <vector> 2927f8a28bee33bb0e857cfe1a61c281bbc234b338Ted Kremenek 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 32b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Return the TypeLoc wrapper for the type source info. 33a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCallTypeLoc TypeSourceInfo::getTypeLoc() const { 34b735471f3848065120d7210e557b5f0d37ed4c43Argyrios Kyrtzidis return TypeLoc(Ty, (void*)(this + 1)); 35b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis} 360b2b6e1cb1573bb295c0a65813dc4df8d57f305bChris Lattner 37d3b9065ec7052ec4741783d2fb4130d13c766933Chris Lattner//===----------------------------------------------------------------------===// 384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor// NamedDecl Implementation 395239304ff761b8b03eefb772bd5d830a9b9f1aeaArgyrios Kyrtzidis//===----------------------------------------------------------------------===// 405239304ff761b8b03eefb772bd5d830a9b9f1aeaArgyrios Kyrtzidis 410b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor/// \brief Get the most restrictive linkage for the types in the given 420b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor/// template parameter list. 430b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregorstatic Linkage 440b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas GregorgetLinkageForTemplateParameterList(const TemplateParameterList *Params) { 450b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Linkage L = ExternalLinkage; 460b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor for (TemplateParameterList::const_iterator P = Params->begin(), 470b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor PEnd = Params->end(); 480b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor P != PEnd; ++P) { 490b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) 500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (!NTTP->getType()->isDependentType()) { 510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, NTTP->getType()->getLinkage()); 520b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor continue; 530b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 540b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 550b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (TemplateTemplateParmDecl *TTP 560b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor = dyn_cast<TemplateTemplateParmDecl>(*P)) { 570b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, 580b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor getLinkageForTemplateParameterList(TTP->getTemplateParameters())); 590b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 600b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 610b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 620b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return L; 630b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 640b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 650b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor/// \brief Get the most restrictive linkage for the types and 660b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor/// declarations in the given template argument list. 670b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregorstatic Linkage getLinkageForTemplateArgumentList(const TemplateArgument *Args, 680b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor unsigned NumArgs) { 690b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Linkage L = ExternalLinkage; 700b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 710b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor for (unsigned I = 0; I != NumArgs; ++I) { 720b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor switch (Args[I].getKind()) { 730b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor case TemplateArgument::Null: 740b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor case TemplateArgument::Integral: 750b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor case TemplateArgument::Expression: 760b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor break; 770b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 780b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor case TemplateArgument::Type: 790b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, Args[I].getAsType()->getLinkage()); 800b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor break; 810b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 820b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor case TemplateArgument::Declaration: 830b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (NamedDecl *ND = dyn_cast<NamedDecl>(Args[I].getAsDecl())) 840b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, ND->getLinkage()); 850b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (ValueDecl *VD = dyn_cast<ValueDecl>(Args[I].getAsDecl())) 860b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, VD->getType()->getLinkage()); 870b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor break; 880b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 890b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor case TemplateArgument::Template: 900b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (TemplateDecl *Template 910b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor = Args[I].getAsTemplate().getAsTemplateDecl()) 920b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, Template->getLinkage()); 930b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor break; 940b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 950b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor case TemplateArgument::Pack: 960b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, 970b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor getLinkageForTemplateArgumentList(Args[I].pack_begin(), 980b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Args[I].pack_size())); 990b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor break; 1000b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 1010b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 1020b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1030b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return L; 1040b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 1050b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1060b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregorstatic Linkage getLinkageForNamespaceScopeDecl(const NamedDecl *D) { 107d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor assert(D->getDeclContext()->getLookupContext()->isFileContext() && 108d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor "Not a name having namespace scope"); 109d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor ASTContext &Context = D->getASTContext(); 110d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 111d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // C++ [basic.link]p3: 112d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // A name having namespace scope (3.3.6) has internal linkage if it 113d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // is the name of 114d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - an object, reference, function or function template that is 115d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // explicitly declared static; or, 116d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // (This bullet corresponds to C99 6.2.2p3.) 117d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (const VarDecl *Var = dyn_cast<VarDecl>(D)) { 118d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // Explicitly declared static. 119d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (Var->getStorageClass() == VarDecl::Static) 1200b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return InternalLinkage; 121d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 122d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - an object or reference that is explicitly declared const 123d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // and neither explicitly declared extern nor previously 124d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // declared to have external linkage; or 125d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // (there is no equivalent in C99) 126d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (Context.getLangOptions().CPlusPlus && 127e9d6554ba78fb81e810fdaec9b2c98ab96526e83Eli Friedman Var->getType().isConstant(Context) && 128d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor Var->getStorageClass() != VarDecl::Extern && 129d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor Var->getStorageClass() != VarDecl::PrivateExtern) { 130d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor bool FoundExtern = false; 131d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor for (const VarDecl *PrevVar = Var->getPreviousDeclaration(); 132d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor PrevVar && !FoundExtern; 133d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor PrevVar = PrevVar->getPreviousDeclaration()) 1340b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (isExternalLinkage(PrevVar->getLinkage())) 135d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor FoundExtern = true; 136d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 137d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (!FoundExtern) 1380b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return InternalLinkage; 139d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 140d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } else if (isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)) { 1410b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // C++ [temp]p4: 1420b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // A non-member function template can have internal linkage; any 1430b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // other template name shall have external linkage. 144d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor const FunctionDecl *Function = 0; 145d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (const FunctionTemplateDecl *FunTmpl 146d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor = dyn_cast<FunctionTemplateDecl>(D)) 147d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor Function = FunTmpl->getTemplatedDecl(); 148d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor else 149d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor Function = cast<FunctionDecl>(D); 150d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 151d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // Explicitly declared static. 152d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (Function->getStorageClass() == FunctionDecl::Static) 1530b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return InternalLinkage; 154d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } else if (const FieldDecl *Field = dyn_cast<FieldDecl>(D)) { 155d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - a data member of an anonymous union. 156d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (cast<RecordDecl>(Field->getDeclContext())->isAnonymousStructOrUnion()) 1570b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return InternalLinkage; 158d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 159d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 160d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // C++ [basic.link]p4: 161d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 162d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // A name having namespace scope has external linkage if it is the 163d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // name of 164d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // 165d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - an object or reference, unless it has internal linkage; or 166d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (const VarDecl *Var = dyn_cast<VarDecl>(D)) { 167d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (!Context.getLangOptions().CPlusPlus && 168d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor (Var->getStorageClass() == VarDecl::Extern || 169d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor Var->getStorageClass() == VarDecl::PrivateExtern)) { 170d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // C99 6.2.2p4: 171d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // For an identifier declared with the storage-class specifier 172d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // extern in a scope in which a prior declaration of that 173d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // identifier is visible, if the prior declaration specifies 174d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // internal or external linkage, the linkage of the identifier 175d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // at the later declaration is the same as the linkage 176d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // specified at the prior declaration. If no prior declaration 177d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // is visible, or if the prior declaration specifies no 178d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // linkage, then the identifier has external linkage. 179d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (const VarDecl *PrevVar = Var->getPreviousDeclaration()) { 1800b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (Linkage L = PrevVar->getLinkage()) 181d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor return L; 182d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 183d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 184d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 185d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // C99 6.2.2p5: 186d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // If the declaration of an identifier for an object has file 187d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // scope and no storage-class specifier, its linkage is 188d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // external. 1890b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (Var->isInAnonymousNamespace()) 1900b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return UniqueExternalLinkage; 1910b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1920b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ExternalLinkage; 193d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 194d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 195d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - a function, unless it has internal linkage; or 196d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { 197d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // C99 6.2.2p5: 198d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // If the declaration of an identifier for a function has no 199d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // storage-class specifier, its linkage is determined exactly 200d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // as if it were declared with the storage-class specifier 201d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // extern. 202d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (!Context.getLangOptions().CPlusPlus && 203d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor (Function->getStorageClass() == FunctionDecl::Extern || 204d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor Function->getStorageClass() == FunctionDecl::PrivateExtern || 205d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor Function->getStorageClass() == FunctionDecl::None)) { 206d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // C99 6.2.2p4: 207d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // For an identifier declared with the storage-class specifier 208d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // extern in a scope in which a prior declaration of that 209d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // identifier is visible, if the prior declaration specifies 210d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // internal or external linkage, the linkage of the identifier 211d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // at the later declaration is the same as the linkage 212d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // specified at the prior declaration. If no prior declaration 213d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // is visible, or if the prior declaration specifies no 214d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // linkage, then the identifier has external linkage. 215d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (const FunctionDecl *PrevFunc = Function->getPreviousDeclaration()) { 2160b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (Linkage L = PrevFunc->getLinkage()) 217d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor return L; 218d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 219d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 220d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 2210b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (Function->isInAnonymousNamespace()) 2220b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return UniqueExternalLinkage; 2230b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2240b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (FunctionTemplateSpecializationInfo *SpecInfo 2250b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor = Function->getTemplateSpecializationInfo()) { 2260b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Linkage L = SpecInfo->getTemplate()->getLinkage(); 2270b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor const TemplateArgumentList &TemplateArgs = *SpecInfo->TemplateArguments; 2280b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, 2290b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor getLinkageForTemplateArgumentList( 2300b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor TemplateArgs.getFlatArgumentList(), 2310b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor TemplateArgs.flat_size())); 2320b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return L; 2330b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 2340b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2350b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ExternalLinkage; 236d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 237d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 238d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - a named class (Clause 9), or an unnamed class defined in a 239d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // typedef declaration in which the class has the typedef name 240d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // for linkage purposes (7.1.3); or 241d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - a named enumeration (7.2), or an unnamed enumeration 242d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // defined in a typedef declaration in which the enumeration 243d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // has the typedef name for linkage purposes (7.1.3); or 244d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (const TagDecl *Tag = dyn_cast<TagDecl>(D)) 2450b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (Tag->getDeclName() || Tag->getTypedefForAnonDecl()) { 2460b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (Tag->isInAnonymousNamespace()) 2470b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return UniqueExternalLinkage; 2480b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2490b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // If this is a class template specialization, consider the 2500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // linkage of the template and template arguments. 2510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (const ClassTemplateSpecializationDecl *Spec 2520b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor = dyn_cast<ClassTemplateSpecializationDecl>(Tag)) { 2530b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); 2540b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Linkage L = getLinkageForTemplateArgumentList( 2550b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor TemplateArgs.getFlatArgumentList(), 2560b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor TemplateArgs.flat_size()); 2570b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return minLinkage(L, Spec->getSpecializedTemplate()->getLinkage()); 2580b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 2590b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2600b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ExternalLinkage; 2610b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 262d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 263d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - an enumerator belonging to an enumeration with external linkage; 2640b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (isa<EnumConstantDecl>(D)) { 2650b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Linkage L = cast<NamedDecl>(D->getDeclContext())->getLinkage(); 2660b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (isExternalLinkage(L)) 2670b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return L; 2680b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 269d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 270d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - a template, unless it is a function template that has 271d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // internal linkage (Clause 14); 2720b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (const TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) { 2730b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (D->isInAnonymousNamespace()) 2740b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return UniqueExternalLinkage; 2750b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2760b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return getLinkageForTemplateParameterList( 2770b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Template->getTemplateParameters()); 2780b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 279d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 280d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // - a namespace (7.3), unless it is declared within an unnamed 281d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // namespace. 282d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (isa<NamespaceDecl>(D) && !D->isInAnonymousNamespace()) 2830b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ExternalLinkage; 284d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 2850b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return NoLinkage; 286d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor} 287d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 2880b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas GregorLinkage NamedDecl::getLinkage() const { 289d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // Handle linkage for namespace-scope names. 290d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (getDeclContext()->getLookupContext()->isFileContext()) 291d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (Linkage L = getLinkageForNamespaceScopeDecl(this)) 292d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor return L; 293d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 294d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // C++ [basic.link]p5: 295d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // In addition, a member function, static data member, a named 296d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // class or enumeration of class scope, or an unnamed class or 297d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // enumeration defined in a class-scope typedef declaration such 298d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // that the class or enumeration has the typedef name for linkage 299d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // purposes (7.1.3), has external linkage if the name of the class 300d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // has external linkage. 301d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (getDeclContext()->isRecord() && 302d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor (isa<CXXMethodDecl>(this) || isa<VarDecl>(this) || 303d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor (isa<TagDecl>(this) && 3040b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor (getDeclName() || cast<TagDecl>(this)->getTypedefForAnonDecl())))) { 3050b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Linkage L = cast<RecordDecl>(getDeclContext())->getLinkage(); 3060b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (isExternalLinkage(L)) 3070b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return L; 3080b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 309d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 310d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // C++ [basic.link]p6: 311d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // The name of a function declared in block scope and the name of 312d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // an object declared by a block scope extern declaration have 313d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // linkage. If there is a visible declaration of an entity with 314d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // linkage having the same name and type, ignoring entities 315d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // declared outside the innermost enclosing namespace scope, the 316d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // block scope declaration declares that same entity and receives 317d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // the linkage of the previous declaration. If there is more than 318d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // one such matching entity, the program is ill-formed. Otherwise, 319d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // if no matching entity is found, the block scope entity receives 320d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // external linkage. 321d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (getLexicalDeclContext()->isFunctionOrMethod()) { 322d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(this)) { 323d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (Function->getPreviousDeclaration()) 324d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (Linkage L = Function->getPreviousDeclaration()->getLinkage()) 325d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor return L; 326d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 3270b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (Function->isInAnonymousNamespace()) 3280b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return UniqueExternalLinkage; 3290b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 330d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor return ExternalLinkage; 331d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 332d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 333d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (const VarDecl *Var = dyn_cast<VarDecl>(this)) 334d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (Var->getStorageClass() == VarDecl::Extern || 335d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor Var->getStorageClass() == VarDecl::PrivateExtern) { 336d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (Var->getPreviousDeclaration()) 337d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor if (Linkage L = Var->getPreviousDeclaration()->getLinkage()) 338d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor return L; 339d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 3400b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (Var->isInAnonymousNamespace()) 3410b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return UniqueExternalLinkage; 3420b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 343d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor return ExternalLinkage; 344d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 345d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor } 346d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 347d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // C++ [basic.link]p6: 348d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor // Names not covered by these rules have no linkage. 349d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor return NoLinkage; 3500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor } 351d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor 35247b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregorstd::string NamedDecl::getQualifiedNameAsString() const { 3533a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return getQualifiedNameAsString(getASTContext().getLangOptions()); 3543a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 3553a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3563a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlssonstd::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const { 357e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar // FIXME: Collect contexts, then accumulate names to avoid unnecessary 358e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar // std::string thrashing. 35947b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor std::vector<std::string> Names; 36047b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor std::string QualName; 36147b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor const DeclContext *Ctx = getDeclContext(); 36247b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor 36347b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor if (Ctx->isFunctionOrMethod()) 36447b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor return getNameAsString(); 36547b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor 36647b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor while (Ctx) { 3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const ClassTemplateSpecializationDecl *Spec 368f3e7ce4bd9837cdab6a096235922865f95467d3dDouglas Gregor = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { 369f3e7ce4bd9837cdab6a096235922865f95467d3dDouglas Gregor const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); 370f3e7ce4bd9837cdab6a096235922865f95467d3dDouglas Gregor std::string TemplateArgsStr 371f3e7ce4bd9837cdab6a096235922865f95467d3dDouglas Gregor = TemplateSpecializationType::PrintTemplateArgumentList( 372f3e7ce4bd9837cdab6a096235922865f95467d3dDouglas Gregor TemplateArgs.getFlatArgumentList(), 373d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor TemplateArgs.flat_size(), 3743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson P); 375e013d685c6689ac7ae103ee88acf573422d1ed6aDaniel Dunbar Names.push_back(Spec->getIdentifier()->getNameStart() + TemplateArgsStr); 3766be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig } else if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(Ctx)) { 3776be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig if (ND->isAnonymousNamespace()) 3786be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig Names.push_back("<anonymous namespace>"); 3796be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig else 3806be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig Names.push_back(ND->getNameAsString()); 3816be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig } else if (const RecordDecl *RD = dyn_cast<RecordDecl>(Ctx)) { 3826be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig if (!RD->getIdentifier()) { 3836be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig std::string RecordString = "<anonymous "; 3846be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig RecordString += RD->getKindName(); 3856be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig RecordString += ">"; 3866be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig Names.push_back(RecordString); 3876be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig } else { 3886be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig Names.push_back(RD->getNameAsString()); 3896be112049b24ffaa8508646aa695834b4b5ca2b2Sam Weinig } 3903521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Ctx)) { 3913521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig std::string Proto = FD->getNameAsString(); 3923521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig 3933521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig const FunctionProtoType *FT = 0; 3943521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig if (FD->hasWrittenPrototype()) 3953521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig FT = dyn_cast<FunctionProtoType>(FD->getType()->getAs<FunctionType>()); 3963521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig 3973521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig Proto += "("; 3983521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig if (FT) { 3993521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig llvm::raw_string_ostream POut(Proto); 4003521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig unsigned NumParams = FD->getNumParams(); 4013521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig for (unsigned i = 0; i < NumParams; ++i) { 4023521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig if (i) 4033521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig POut << ", "; 4043521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig std::string Param; 4053521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig FD->getParamDecl(i)->getType().getAsStringInternal(Param, P); 4063521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig POut << Param; 4073521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig } 4083521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig 4093521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig if (FT->isVariadic()) { 4103521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig if (NumParams > 0) 4113521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig POut << ", "; 4123521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig POut << "..."; 4133521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig } 4143521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig } 4153521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig Proto += ")"; 4163521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig 4173521d01aed2f55b66c7ce2ad47541a9974079699Sam Weinig Names.push_back(Proto); 418f3e7ce4bd9837cdab6a096235922865f95467d3dDouglas Gregor } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(Ctx)) 41947b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor Names.push_back(ND->getNameAsString()); 42047b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor else 42147b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor break; 42247b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor 42347b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor Ctx = Ctx->getParent(); 42447b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor } 42547b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor 42647b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor std::vector<std::string>::reverse_iterator 42747b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor I = Names.rbegin(), 42847b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor End = Names.rend(); 42947b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor 43047b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor for (; I!=End; ++I) 43147b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor QualName += *I + "::"; 43247b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor 4338472af4df9292e02fb25c952d25a81f3ca296252John McCall if (getDeclName()) 4348472af4df9292e02fb25c952d25a81f3ca296252John McCall QualName += getNameAsString(); 4358472af4df9292e02fb25c952d25a81f3ca296252John McCall else 4368472af4df9292e02fb25c952d25a81f3ca296252John McCall QualName += "<anonymous>"; 43747b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor 43847b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor return QualName; 43947b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor} 44047b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor 4414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorbool NamedDecl::declarationReplaces(NamedDecl *OldD) const { 4426ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch"); 4436ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor 4442a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor // UsingDirectiveDecl's are not really NamedDecl's, and all have same name. 4452a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor // We want to keep it, unless it nominates same namespace. 4462a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor if (getKind() == Decl::UsingDirective) { 4472a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor return cast<UsingDirectiveDecl>(this)->getNominatedNamespace() == 4482a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor cast<UsingDirectiveDecl>(OldD)->getNominatedNamespace(); 4492a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor } 4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4516ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) 4526ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor // For function declarations, we keep track of redeclarations. 4536ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor return FD->getPreviousDeclaration() == OldD; 4546ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor 455e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor // For function templates, the underlying function declarations are linked. 456e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor if (const FunctionTemplateDecl *FunctionTemplate 457e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor = dyn_cast<FunctionTemplateDecl>(this)) 458e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor if (const FunctionTemplateDecl *OldFunctionTemplate 459e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor = dyn_cast<FunctionTemplateDecl>(OldD)) 460e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor return FunctionTemplate->getTemplatedDecl() 461e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor ->declarationReplaces(OldFunctionTemplate->getTemplatedDecl()); 4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4630de21fd85d79bccd32f04256f5b3328ab5ed7c95Steve Naroff // For method declarations, we keep track of redeclarations. 4640de21fd85d79bccd32f04256f5b3328ab5ed7c95Steve Naroff if (isa<ObjCMethodDecl>(this)) 4650de21fd85d79bccd32f04256f5b3328ab5ed7c95Steve Naroff return false; 4661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 467f36e02d4aff98bf2e52e342e0038d4172fbb5e64John McCall if (isa<ObjCInterfaceDecl>(this) && isa<ObjCCompatibleAliasDecl>(OldD)) 468f36e02d4aff98bf2e52e342e0038d4172fbb5e64John McCall return true; 469f36e02d4aff98bf2e52e342e0038d4172fbb5e64John McCall 4709488ea120e093068021f944176c3d610dd540914John McCall if (isa<UsingShadowDecl>(this) && isa<UsingShadowDecl>(OldD)) 4719488ea120e093068021f944176c3d610dd540914John McCall return cast<UsingShadowDecl>(this)->getTargetDecl() == 4729488ea120e093068021f944176c3d610dd540914John McCall cast<UsingShadowDecl>(OldD)->getTargetDecl(); 4739488ea120e093068021f944176c3d610dd540914John McCall 4746ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor // For non-function declarations, if the declarations are of the 4756ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor // same kind then this must be a redeclaration, or semantic analysis 4766ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor // would not have given us the new declaration. 4776ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor return this->getKind() == OldD->getKind(); 4786ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor} 4796ed40e351a7c1fb3084434f1db19216b79623cf0Douglas Gregor 480d6f7e9dccd0fa8a5a15d7478324c0ae229fc5e1eDouglas Gregorbool NamedDecl::hasLinkage() const { 481d85b5b9b8fcf53906d9a61649b3657ca0d902017Douglas Gregor return getLinkage() != NoLinkage; 482d6f7e9dccd0fa8a5a15d7478324c0ae229fc5e1eDouglas Gregor} 4834afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 484e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders CarlssonNamedDecl *NamedDecl::getUnderlyingDecl() { 485e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson NamedDecl *ND = this; 486e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson while (true) { 4879488ea120e093068021f944176c3d610dd540914John McCall if (UsingShadowDecl *UD = dyn_cast<UsingShadowDecl>(ND)) 488e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson ND = UD->getTargetDecl(); 489e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson else if (ObjCCompatibleAliasDecl *AD 490e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson = dyn_cast<ObjCCompatibleAliasDecl>(ND)) 491e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson return AD->getClassInterface(); 492e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson else 493e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson return ND; 494e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson } 495e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson} 496e136e0e1b74760d7ec3ede38e0e739d5c52a3c0aAnders Carlsson 4975239304ff761b8b03eefb772bd5d830a9b9f1aeaArgyrios Kyrtzidis//===----------------------------------------------------------------------===// 498a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis// DeclaratorDecl Implementation 499a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 500a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis 501b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCallDeclaratorDecl::~DeclaratorDecl() {} 502b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCallvoid DeclaratorDecl::Destroy(ASTContext &C) { 503b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall if (hasExtInfo()) 504b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall C.Deallocate(getExtInfo()); 505b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall ValueDecl::Destroy(C); 506b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall} 507b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall 508a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios KyrtzidisSourceLocation DeclaratorDecl::getTypeSpecStartLoc() const { 50951bd803fbdade51d674598ed45da3d54190a656cJohn McCall if (DeclInfo) { 510b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall TypeLoc TL = getTypeSourceInfo()->getTypeLoc(); 51151bd803fbdade51d674598ed45da3d54190a656cJohn McCall while (true) { 51251bd803fbdade51d674598ed45da3d54190a656cJohn McCall TypeLoc NextTL = TL.getNextTypeLoc(); 51351bd803fbdade51d674598ed45da3d54190a656cJohn McCall if (!NextTL) 51451bd803fbdade51d674598ed45da3d54190a656cJohn McCall return TL.getSourceRange().getBegin(); 51551bd803fbdade51d674598ed45da3d54190a656cJohn McCall TL = NextTL; 51651bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 51751bd803fbdade51d674598ed45da3d54190a656cJohn McCall } 518a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis return SourceLocation(); 519a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis} 520a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis 521b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCallvoid DeclaratorDecl::setQualifierInfo(NestedNameSpecifier *Qualifier, 522b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall SourceRange QualifierRange) { 523b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall if (Qualifier) { 524b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Make sure the extended decl info is allocated. 525b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall if (!hasExtInfo()) { 526b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Save (non-extended) type source info pointer. 527b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall TypeSourceInfo *savedTInfo = DeclInfo.get<TypeSourceInfo*>(); 528b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Allocate external info struct. 529b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall DeclInfo = new (getASTContext()) ExtInfo; 530b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Restore savedTInfo into (extended) decl info. 531b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall getExtInfo()->TInfo = savedTInfo; 532b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall } 533b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Set qualifier info. 534b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall getExtInfo()->NNS = Qualifier; 535b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall getExtInfo()->NNSRange = QualifierRange; 536b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall } 537b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall else { 538b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Here Qualifier == 0, i.e., we are removing the qualifier (if any). 539b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall assert(QualifierRange.isInvalid()); 540b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall if (hasExtInfo()) { 541b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Save type source info pointer. 542b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall TypeSourceInfo *savedTInfo = getExtInfo()->TInfo; 543b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Deallocate the extended decl info. 544b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall getASTContext().Deallocate(getExtInfo()); 545b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Restore savedTInfo into (non-extended) decl info. 546b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall DeclInfo = savedTInfo; 547b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall } 548b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall } 549b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall} 550b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall 551a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 55299f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes// VarDecl Implementation 55399f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes//===----------------------------------------------------------------------===// 55499f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes 5557783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redlconst char *VarDecl::getStorageClassSpecifierString(StorageClass SC) { 5567783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl switch (SC) { 5577783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl case VarDecl::None: break; 5587783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl case VarDecl::Auto: return "auto"; break; 5597783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl case VarDecl::Extern: return "extern"; break; 5607783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl case VarDecl::PrivateExtern: return "__private_extern__"; break; 5617783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl case VarDecl::Register: return "register"; break; 5627783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl case VarDecl::Static: return "static"; break; 5637783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl } 5647783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 5657783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl assert(0 && "Invalid storage class"); 5667783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return 0; 5677783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 5687783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 5694afa39deaa245592977136d367251ee2c173dd8dDouglas GregorVarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, 570a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, 571a5d82000f7b173a0a5ce34dc8c09a03f98d9e439Argyrios Kyrtzidis StorageClass S) { 572a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return new (C) VarDecl(Var, DC, L, Id, T, TInfo, S); 57399f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes} 57499f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes 57599f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopesvoid VarDecl::Destroy(ASTContext& C) { 576df2d3cf2be8b91e1e21234ff5a3aa4f820e7001aSebastian Redl Expr *Init = getInit(); 57778d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor if (Init) { 578df2d3cf2be8b91e1e21234ff5a3aa4f820e7001aSebastian Redl Init->Destroy(C); 57978d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor if (EvaluatedStmt *Eval = this->Init.dyn_cast<EvaluatedStmt *>()) { 58078d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor Eval->~EvaluatedStmt(); 58178d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor C.Deallocate(Eval); 58278d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor } 58378d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor } 58499f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes this->~VarDecl(); 585b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall DeclaratorDecl::Destroy(C); 58699f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes} 58799f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes 58899f06ba988922ea721035a89e6d3c66ba100ba8aNuno LopesVarDecl::~VarDecl() { 58999f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes} 59099f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes 59155d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios KyrtzidisSourceRange VarDecl::getSourceRange() const { 59233e9abd21083a0191a7676a04b497006d2da184dDouglas Gregor SourceLocation Start = getTypeSpecStartLoc(); 59333e9abd21083a0191a7676a04b497006d2da184dDouglas Gregor if (Start.isInvalid()) 59433e9abd21083a0191a7676a04b497006d2da184dDouglas Gregor Start = getLocation(); 59533e9abd21083a0191a7676a04b497006d2da184dDouglas Gregor 59655d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis if (getInit()) 59733e9abd21083a0191a7676a04b497006d2da184dDouglas Gregor return SourceRange(Start, getInit()->getLocEnd()); 59833e9abd21083a0191a7676a04b497006d2da184dDouglas Gregor return SourceRange(Start, getLocation()); 59955d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis} 60055d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 6017783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redlbool VarDecl::isExternC() const { 6027783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl ASTContext &Context = getASTContext(); 6037783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (!Context.getLangOptions().CPlusPlus) 6047783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return (getDeclContext()->isTranslationUnit() && 6057783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl getStorageClass() != Static) || 6067783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl (getDeclContext()->isFunctionOrMethod() && hasExternalStorage()); 6077783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 6087783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); 6097783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl DC = DC->getParent()) { 6107783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { 6117783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) 6127783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return getStorageClass() != Static; 6137783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 6147783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl break; 6157783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl } 6167783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 6177783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (DC->isFunctionOrMethod()) 6187783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return false; 6197783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl } 6207783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 6217783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return false; 6227783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 6237783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 6247783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlVarDecl *VarDecl::getCanonicalDecl() { 6257783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return getFirstDeclaration(); 6267783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 6277783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 628e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian RedlVarDecl::DefinitionKind VarDecl::isThisDeclarationADefinition() const { 629e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // C++ [basic.def]p2: 630e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // A declaration is a definition unless [...] it contains the 'extern' 631e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // specifier or a linkage-specification and neither an initializer [...], 632e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // it declares a static data member in a class declaration [...]. 633e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // C++ [temp.expl.spec]p15: 634e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // An explicit specialization of a static data member of a template is a 635e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // definition if the declaration includes an initializer; otherwise, it is 636e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // a declaration. 637e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if (isStaticDataMember()) { 638e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if (isOutOfLine() && (hasInit() || 639e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl getTemplateSpecializationKind() != TSK_ExplicitSpecialization)) 640e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return Definition; 641e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl else 642e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return DeclarationOnly; 643e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl } 644e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // C99 6.7p5: 645e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // A definition of an identifier is a declaration for that identifier that 646e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // [...] causes storage to be reserved for that object. 647e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // Note: that applies for all non-file-scope objects. 648e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // C99 6.9.2p1: 649e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // If the declaration of an identifier for an object has file scope and an 650e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // initializer, the declaration is an external definition for the identifier 651e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if (hasInit()) 652e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return Definition; 653e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // AST for 'extern "C" int foo;' is annotated with 'extern'. 654e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if (hasExternalStorage()) 655e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return DeclarationOnly; 656e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl 657e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // C99 6.9.2p2: 658e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // A declaration of an object that has file scope without an initializer, 659e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // and without a storage class specifier or the scs 'static', constitutes 660e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // a tentative definition. 661e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // No such thing in C++. 662e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if (!getASTContext().getLangOptions().CPlusPlus && isFileVarDecl()) 663e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return TentativeDefinition; 664e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl 665e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // What's left is (in C, block-scope) declarations without initializers or 666e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl // external storage. These are definitions. 667e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return Definition; 668e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl} 669e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl 670e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian RedlVarDecl *VarDecl::getActingDefinition() { 671e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl DefinitionKind Kind = isThisDeclarationADefinition(); 672e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if (Kind != TentativeDefinition) 673e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return 0; 674e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl 675e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl VarDecl *LastTentative = false; 676e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl VarDecl *First = getFirstDeclaration(); 677e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl for (redecl_iterator I = First->redecls_begin(), E = First->redecls_end(); 678e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl I != E; ++I) { 679e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl Kind = (*I)->isThisDeclarationADefinition(); 680e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if (Kind == Definition) 681e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return 0; 682e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl else if (Kind == TentativeDefinition) 683e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl LastTentative = *I; 684e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl } 685e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return LastTentative; 686e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl} 687e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl 688e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redlbool VarDecl::isTentativeDefinitionNow() const { 689e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl DefinitionKind Kind = isThisDeclarationADefinition(); 690e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if (Kind != TentativeDefinition) 691e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return false; 692e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl 693e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) { 694e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if ((*I)->isThisDeclarationADefinition() == Definition) 695e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl return false; 696e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl } 69731310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl return true; 69831310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl} 69931310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl 70031310a21fb2a9f13950f864f681c86080b05d5b2Sebastian RedlVarDecl *VarDecl::getDefinition() { 701e2c52d29e483b4167bd5d8e3265c2fb7c38fbcd5Sebastian Redl VarDecl *First = getFirstDeclaration(); 702e2c52d29e483b4167bd5d8e3265c2fb7c38fbcd5Sebastian Redl for (redecl_iterator I = First->redecls_begin(), E = First->redecls_end(); 703e2c52d29e483b4167bd5d8e3265c2fb7c38fbcd5Sebastian Redl I != E; ++I) { 70431310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl if ((*I)->isThisDeclarationADefinition() == Definition) 70531310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl return *I; 70631310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl } 70731310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl return 0; 708e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl} 709e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl 71031310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redlconst Expr *VarDecl::getAnyInitializer(const VarDecl *&D) const { 7117783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl redecl_iterator I = redecls_begin(), E = redecls_end(); 7127783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl while (I != E && !I->getInit()) 7137783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl ++I; 7147783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 7157783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (I != E) { 71631310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl D = *I; 7177783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return I->getInit(); 7187783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl } 7197783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return 0; 7207783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 7217783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 7221028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregorbool VarDecl::isOutOfLine() const { 7231028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor if (Decl::isOutOfLine()) 7241028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor return true; 7258761d680eaa7386e03f51286f4b84a1ffe575e2eChandler Carruth 7268761d680eaa7386e03f51286f4b84a1ffe575e2eChandler Carruth if (!isStaticDataMember()) 7278761d680eaa7386e03f51286f4b84a1ffe575e2eChandler Carruth return false; 7288761d680eaa7386e03f51286f4b84a1ffe575e2eChandler Carruth 7291028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor // If this static data member was instantiated from a static data member of 7301028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor // a class template, check whether that static data member was defined 7311028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor // out-of-line. 7321028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor if (VarDecl *VD = getInstantiatedFromStaticDataMember()) 7331028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor return VD->isOutOfLine(); 7341028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor 7351028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor return false; 7361028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor} 7371028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas Gregor 7380d03514da06dffb39a260a1228ea3fd01d196fa4Douglas GregorVarDecl *VarDecl::getOutOfLineDefinition() { 7390d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor if (!isStaticDataMember()) 7400d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor return 0; 7410d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor 7420d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor for (VarDecl::redecl_iterator RD = redecls_begin(), RDEnd = redecls_end(); 7430d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor RD != RDEnd; ++RD) { 7440d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor if (RD->getLexicalDeclContext()->isFileContext()) 7450d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor return *RD; 7460d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor } 7470d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor 7480d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor return 0; 7490d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor} 7500d03514da06dffb39a260a1228ea3fd01d196fa4Douglas Gregor 751838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregorvoid VarDecl::setInit(Expr *I) { 7527783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) { 7537783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl Eval->~EvaluatedStmt(); 754838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor getASTContext().Deallocate(Eval); 7557783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl } 7567783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 7577783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl Init = I; 7587783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 7597783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 7601028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas GregorVarDecl *VarDecl::getInstantiatedFromStaticDataMember() const { 761b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) 762251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor return cast<VarDecl>(MSI->getInstantiatedFrom()); 763251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor 764251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor return 0; 765251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor} 766251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor 767663b5a0be7261c29bc4c526a71cffcfa02d4153eDouglas GregorTemplateSpecializationKind VarDecl::getTemplateSpecializationKind() const { 768e9d12b6c50c1e9b05443db099e21026c5991a93bSebastian Redl if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo()) 769251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor return MSI->getTemplateSpecializationKind(); 770251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor 771251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor return TSK_Undeclared; 772251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor} 773251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor 7741028c9f0afc1cc5f4951b39b7067fa57c1fea07bDouglas GregorMemberSpecializationInfo *VarDecl::getMemberSpecializationInfo() const { 775b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor return getASTContext().getInstantiatedFromStaticDataMember(this); 776b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor} 777b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 7780a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregorvoid VarDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK, 7790a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor SourceLocation PointOfInstantiation) { 780b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor MemberSpecializationInfo *MSI = getMemberSpecializationInfo(); 781251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor assert(MSI && "Not an instantiated static data member?"); 782251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor MSI->setTemplateSpecializationKind(TSK); 7830a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor if (TSK != TSK_ExplicitSpecialization && 7840a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor PointOfInstantiation.isValid() && 7850a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor MSI->getPointOfInstantiation().isInvalid()) 7860a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor MSI->setPointOfInstantiation(PointOfInstantiation); 7877caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 7887caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 7897783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl//===----------------------------------------------------------------------===// 7907783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl// ParmVarDecl Implementation 7917783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl//===----------------------------------------------------------------------===// 792275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregor 7937783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, 7947783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl SourceLocation L, IdentifierInfo *Id, 7957783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl QualType T, TypeSourceInfo *TInfo, 7967783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl StorageClass S, Expr *DefArg) { 7977783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return new (C) ParmVarDecl(ParmVar, DC, L, Id, T, TInfo, S, DefArg); 798275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregor} 799275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregor 8007783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlExpr *ParmVarDecl::getDefaultArg() { 8017783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!"); 8027783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl assert(!hasUninstantiatedDefaultArg() && 8037783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl "Default argument is not yet instantiated!"); 8047783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 8057783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl Expr *Arg = getInit(); 8067783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (CXXExprWithTemporaries *E = dyn_cast_or_null<CXXExprWithTemporaries>(Arg)) 8077783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return E->getSubExpr(); 8087783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 8097783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return Arg; 8107783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 8117783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 8127783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redlunsigned ParmVarDecl::getNumDefaultArgTemporaries() const { 8137783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (const CXXExprWithTemporaries *E = 8147783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl dyn_cast<CXXExprWithTemporaries>(getInit())) 8157783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return E->getNumTemporaries(); 816275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregor 817c37929c9e0dba89770dc5f0fbcfa0c9046da0b06Argyrios Kyrtzidis return 0; 818275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregor} 819275a369f003f25bd22c00c1c0fc0251c7208caf4Douglas Gregor 8207783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlCXXTemporary *ParmVarDecl::getDefaultArgTemporary(unsigned i) { 8217783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl assert(getNumDefaultArgTemporaries() && 8227783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl "Default arguments does not have any temporaries!"); 8237783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 8247783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl CXXExprWithTemporaries *E = cast<CXXExprWithTemporaries>(getInit()); 8257783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return E->getTemporary(i); 8267783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 8277783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 8287783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlSourceRange ParmVarDecl::getDefaultArgRange() const { 8297783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (const Expr *E = getInit()) 8307783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return E->getSourceRange(); 8317783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 8327783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (hasUninstantiatedDefaultArg()) 8337783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return getUninstantiatedDefaultArg()->getSourceRange(); 8347783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 8357783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return SourceRange(); 836fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis} 837fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis 83899f06ba988922ea721035a89e6d3c66ba100ba8aNuno Lopes//===----------------------------------------------------------------------===// 8398a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner// FunctionDecl Implementation 8408a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner//===----------------------------------------------------------------------===// 8418a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner 84227f8a28bee33bb0e857cfe1a61c281bbc234b338Ted Kremenekvoid FunctionDecl::Destroy(ASTContext& C) { 843250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor if (Body && Body.isOffset()) 844250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor Body.get(C.getExternalSource())->Destroy(C); 845b65cf41707d190d5ce3d48b9e5bd2dc9d7b4a4c0Ted Kremenek 846b65cf41707d190d5ce3d48b9e5bd2dc9d7b4a4c0Ted Kremenek for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) 847b65cf41707d190d5ce3d48b9e5bd2dc9d7b4a4c0Ted Kremenek (*I)->Destroy(C); 848460b0ac80382fa73337d21dd052c1f18b27435d8Nuno Lopes 8492db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor FunctionTemplateSpecializationInfo *FTSInfo 8502db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>(); 8512db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor if (FTSInfo) 8522db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor C.Deallocate(FTSInfo); 8532db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 8542db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor MemberSpecializationInfo *MSInfo 8552db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>(); 8562db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor if (MSInfo) 8572db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor C.Deallocate(MSInfo); 8582db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 8593e9704981d7691fdd44913bf1786e8d760d8a627Steve Naroff C.Deallocate(ParamInfo); 860460b0ac80382fa73337d21dd052c1f18b27435d8Nuno Lopes 861b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall DeclaratorDecl::Destroy(C); 86227f8a28bee33bb0e857cfe1a61c281bbc234b338Ted Kremenek} 86327f8a28bee33bb0e857cfe1a61c281bbc234b338Ted Kremenek 864136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCallvoid FunctionDecl::getNameForDiagnostic(std::string &S, 865136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall const PrintingPolicy &Policy, 866136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall bool Qualified) const { 867136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall NamedDecl::getNameForDiagnostic(S, Policy, Qualified); 868136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs(); 869136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall if (TemplateArgs) 870136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall S += TemplateSpecializationType::PrintTemplateArgumentList( 871136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall TemplateArgs->getFlatArgumentList(), 872136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall TemplateArgs->flat_size(), 873136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall Policy); 874136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall 875136a6988960ac3aeb96f298da7a1a182db7217cdJohn McCall} 87627f8a28bee33bb0e857cfe1a61c281bbc234b338Ted Kremenek 8776fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios KyrtzidisStmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const { 878c37929c9e0dba89770dc5f0fbcfa0c9046da0b06Argyrios Kyrtzidis for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) { 879c37929c9e0dba89770dc5f0fbcfa0c9046da0b06Argyrios Kyrtzidis if (I->Body) { 880c37929c9e0dba89770dc5f0fbcfa0c9046da0b06Argyrios Kyrtzidis Definition = *I; 881c37929c9e0dba89770dc5f0fbcfa0c9046da0b06Argyrios Kyrtzidis return I->Body.get(getASTContext().getExternalSource()); 882f009795057dc8ca254f5618c80a0a90f07cd44b4Douglas Gregor } 883f009795057dc8ca254f5618c80a0a90f07cd44b4Douglas Gregor } 884f009795057dc8ca254f5618c80a0a90f07cd44b4Douglas Gregor 885f009795057dc8ca254f5618c80a0a90f07cd44b4Douglas Gregor return 0; 8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 88855d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidisvoid FunctionDecl::setBody(Stmt *B) { 88955d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis Body = B; 8901a5364e0fa0482d8d477d6f136d52e503bbe13f4Argyrios Kyrtzidis if (B) 89155d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis EndRangeLoc = B->getLocEnd(); 89255d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis} 89355d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 89448a83b5e7ae4051c7c11680ac00c1fa02d610a62Douglas Gregorbool FunctionDecl::isMain() const { 89548a83b5e7ae4051c7c11680ac00c1fa02d610a62Douglas Gregor ASTContext &Context = getASTContext(); 89607a5c22bb6fb0674c95205ae189365bf8e1b695eJohn McCall return !Context.getLangOptions().Freestanding && 89707a5c22bb6fb0674c95205ae189365bf8e1b695eJohn McCall getDeclContext()->getLookupContext()->isTranslationUnit() && 89804495c859f81e440748a9b86baa2913461652bb0Douglas Gregor getIdentifier() && getIdentifier()->isStr("main"); 89904495c859f81e440748a9b86baa2913461652bb0Douglas Gregor} 90004495c859f81e440748a9b86baa2913461652bb0Douglas Gregor 90148a83b5e7ae4051c7c11680ac00c1fa02d610a62Douglas Gregorbool FunctionDecl::isExternC() const { 90248a83b5e7ae4051c7c11680ac00c1fa02d610a62Douglas Gregor ASTContext &Context = getASTContext(); 9036393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor // In C, any non-static, non-overloadable function has external 9046393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor // linkage. 9056393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor if (!Context.getLangOptions().CPlusPlus) 90640b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis return getStorageClass() != Static && !getAttr<OverloadableAttr>(); 9076393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); 9096393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor DC = DC->getParent()) { 9106393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { 9116393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) 9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getStorageClass() != Static && 91340b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis !getAttr<OverloadableAttr>(); 9146393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor 9156393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor break; 9166393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor } 9176393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor } 9186393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor 9196393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor return false; 9206393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor} 9216393519272ce727f4d26e71bbefb5de712274d0eDouglas Gregor 9228499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregorbool FunctionDecl::isGlobal() const { 9238499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(this)) 9248499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor return Method->isStatic(); 9258499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor 9268499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor if (getStorageClass() == Static) 9278499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor return false; 9288499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor 9291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (const DeclContext *DC = getDeclContext(); 9308499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor DC->isNamespace(); 9318499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor DC = DC->getParent()) { 9328499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor if (const NamespaceDecl *Namespace = cast<NamespaceDecl>(DC)) { 9338499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor if (!Namespace->getDeclName()) 9348499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor return false; 9358499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor break; 9368499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor } 9378499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor } 9388499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor 9398499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor return true; 9408499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor} 9418499f3f5ff8d5f95ece8047780030a3daad1b6faDouglas Gregor 9427783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redlvoid 9437783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlFunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) { 9447783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl redeclarable_base::setPreviousDeclaration(PrevDecl); 9457783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 9467783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (FunctionTemplateDecl *FunTmpl = getDescribedFunctionTemplate()) { 9477783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl FunctionTemplateDecl *PrevFunTmpl 9487783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl = PrevDecl? PrevDecl->getDescribedFunctionTemplate() : 0; 9497783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl assert((!PrevDecl || PrevFunTmpl) && "Function/function template mismatch"); 9507783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl FunTmpl->setPreviousDeclaration(PrevFunTmpl); 9517783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl } 9527783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 9537783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 9547783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redlconst FunctionDecl *FunctionDecl::getCanonicalDecl() const { 9557783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return getFirstDeclaration(); 9567783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 9577783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 9587783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlFunctionDecl *FunctionDecl::getCanonicalDecl() { 9597783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return getFirstDeclaration(); 9607783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 9617783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 9623e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor/// \brief Returns a value indicating whether this function 9633e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor/// corresponds to a builtin function. 9643e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor/// 9653e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor/// The function corresponds to a built-in function if it is 9663e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor/// declared at translation scope or within an extern "C" block and 9673e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor/// its name matches with the name of a builtin. The returned value 9683e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor/// will be 0 for functions that do not correspond to a builtin, a 9691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// value of type \c Builtin::ID if in the target-independent range 9703e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor/// \c [1,Builtin::First), or a target-specific builtin value. 9717814e6d6645d587891293d59ecf6576defcfac92Douglas Gregorunsigned FunctionDecl::getBuiltinID() const { 9727814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor ASTContext &Context = getASTContext(); 9733c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor if (!getIdentifier() || !getIdentifier()->getBuiltinID()) 9743c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor return 0; 9753c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor 9763c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor unsigned BuiltinID = getIdentifier()->getBuiltinID(); 9773c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) 9783c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor return BuiltinID; 9793c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor 9803c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor // This function has the name of a known C library 9813c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor // function. Determine whether it actually refers to the C library 9823c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor // function or whether it just has the same name. 9833c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor 9849add31798f621f843233dbff8bba103fca64447bDouglas Gregor // If this is a static function, it's not a builtin. 9859add31798f621f843233dbff8bba103fca64447bDouglas Gregor if (getStorageClass() == Static) 9869add31798f621f843233dbff8bba103fca64447bDouglas Gregor return 0; 9879add31798f621f843233dbff8bba103fca64447bDouglas Gregor 9883c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor // If this function is at translation-unit scope and we're not in 9893c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor // C++, it refers to the C library function. 9903c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor if (!Context.getLangOptions().CPlusPlus && 9913c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor getDeclContext()->isTranslationUnit()) 9923c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor return BuiltinID; 9933c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor 9943c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor // If the function is in an extern "C" linkage specification and is 9953c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor // not marked "overloadable", it's the real function. 9963c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor if (isa<LinkageSpecDecl>(getDeclContext()) && 9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump cast<LinkageSpecDecl>(getDeclContext())->getLanguage() 9983c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor == LinkageSpecDecl::lang_c && 99940b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis !getAttr<OverloadableAttr>()) 10003c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor return BuiltinID; 10013c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor 10023c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor // Not a builtin 10033e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor return 0; 10043e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor} 10053e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor 10063e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor 10071ad9b28e3217c2349a04f3d3bf14f9c73a99afa7Chris Lattner/// getNumParams - Return the number of parameters this function must have 10082dbd285f5033ca6dea25babfd1c43d9fec35e7e5Chris Lattner/// based on its FunctionType. This is the length of the PararmInfo array 10091ad9b28e3217c2349a04f3d3bf14f9c73a99afa7Chris Lattner/// after it has been created. 10101ad9b28e3217c2349a04f3d3bf14f9c73a99afa7Chris Lattnerunsigned FunctionDecl::getNumParams() const { 1011183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *FT = getType()->getAs<FunctionType>(); 101272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor if (isa<FunctionNoProtoType>(FT)) 1013d3b9065ec7052ec4741783d2fb4130d13c766933Chris Lattner return 0; 101472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return cast<FunctionProtoType>(FT)->getNumArgs(); 10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1018838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregorvoid FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) { 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(ParamInfo == 0 && "Already has param info!"); 10202dbd285f5033ca6dea25babfd1c43d9fec35e7e5Chris Lattner assert(NumParams == getNumParams() && "Parameter count mismatch!"); 10211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Zero params -> null pointer. 10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (NumParams) { 1024838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor void *Mem = getASTContext().Allocate(sizeof(ParmVarDecl*)*NumParams); 1025fc767615bc67d3a7587b1fb2e0494c32c9dbd7a5Ted Kremenek ParamInfo = new (Mem) ParmVarDecl*[NumParams]; 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); 102755d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 102896888cc2515e55c9b5dd6798063bf4be2c22983aArgyrios Kyrtzidis // Update source range. The check below allows us to set EndRangeLoc before 102996888cc2515e55c9b5dd6798063bf4be2c22983aArgyrios Kyrtzidis // setting the parameters. 1030cb5f8f59322c352f51714c3de5d8047e70895165Argyrios Kyrtzidis if (EndRangeLoc.isInvalid() || EndRangeLoc == getLocation()) 103155d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis EndRangeLoc = NewParamInfo[NumParams-1]->getLocEnd(); 10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10358123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner/// getMinRequiredArguments - Returns the minimum number of arguments 10368123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner/// needed to call this function. This may be fewer than the number of 10378123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner/// function parameters, if some of the parameters have default 10389e979557eea3875c9e3d100c68188233dd7f46c0Chris Lattner/// arguments (in C++). 10398123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattnerunsigned FunctionDecl::getMinRequiredArguments() const { 10408123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner unsigned NumRequiredArgs = getNumParams(); 10418123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner while (NumRequiredArgs > 0 1042ae0b4e7be78cf0dc2a6a333e865c2be9265774f9Anders Carlsson && getParamDecl(NumRequiredArgs-1)->hasDefaultArg()) 10438123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner --NumRequiredArgs; 10448123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner 10458123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner return NumRequiredArgs; 10468123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner} 10478123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner 10487ced9c8529b734e313f62a3b81189d6f402f6713Douglas Gregorbool FunctionDecl::isInlined() const { 104948eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson // FIXME: This is not enough. Consider: 105048eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson // 105148eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson // inline void f(); 105248eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson // void f() { } 105348eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson // 105448eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson // f is inlined, but does not have inline specified. 105548eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson // To fix this we should add an 'inline' flag to FunctionDecl. 105648eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson if (isInlineSpecified()) 10577d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor return true; 105848eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson 105948eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson if (isa<CXXMethodDecl>(this)) { 106048eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson if (!isOutOfLine() || getCanonicalDecl()->isInlineSpecified()) 106148eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson return true; 106248eda2c5d6d2a5c95775a1a3a8a22428bb6869c6Anders Carlsson } 10637d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor 10647d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor switch (getTemplateSpecializationKind()) { 10657d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor case TSK_Undeclared: 10667d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor case TSK_ExplicitSpecialization: 10677d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor return false; 10687d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor 10697d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor case TSK_ImplicitInstantiation: 10707d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor case TSK_ExplicitInstantiationDeclaration: 10717d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor case TSK_ExplicitInstantiationDefinition: 10727d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor // Handle below. 10737d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor break; 10747d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor } 10757d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor 10767d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor const FunctionDecl *PatternDecl = getTemplateInstantiationPattern(); 10777d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor Stmt *Pattern = 0; 10787d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor if (PatternDecl) 10797d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor Pattern = PatternDecl->getBody(PatternDecl); 10807d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor 10817d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor if (Pattern && PatternDecl) 10827d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor return PatternDecl->isInlined(); 10837d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor 10847d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor return false; 10857ced9c8529b734e313f62a3b81189d6f402f6713Douglas Gregor} 10867ced9c8529b734e313f62a3b81189d6f402f6713Douglas Gregor 10877d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor/// \brief For an inline function definition in C or C++, determine whether the 10881fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// definition will be externally visible. 10891fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// 10901fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// Inline function definitions are always available for inlining optimizations. 10911fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// However, depending on the language dialect, declaration specifiers, and 10921fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// attributes, the definition of an inline function may or may not be 10931fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// "externally" visible to other translation units in the program. 10941fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// 10951fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// In C99, inline definitions are not externally visible by default. However, 10961e5fd7f8e90e0953e5c59cbbbc130633d84a1e37Mike Stump/// if even one of the global-scope declarations is marked "extern inline", the 10971fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// inline definition becomes externally visible (C99 6.7.4p6). 10981fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// 10991fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// In GNU89 mode, or if the gnu_inline attribute is attached to the function 11001fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// definition, we use the GNU semantics for inline, which are nearly the 11011fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// opposite of C99 semantics. In particular, "inline" by itself will create 11021fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// an externally visible symbol, but "extern inline" will not create an 11031fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor/// externally visible symbol. 11041fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregorbool FunctionDecl::isInlineDefinitionExternallyVisible() const { 11051fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor assert(isThisDeclarationADefinition() && "Must have the function definition"); 11067ced9c8529b734e313f62a3b81189d6f402f6713Douglas Gregor assert(isInlined() && "Function must be inline"); 11077d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor ASTContext &Context = getASTContext(); 11081fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor 11097d9c3c92c90ae36d58ec21bc53c4c08e02ac3555Douglas Gregor if (!Context.getLangOptions().C99 || hasAttr<GNUInlineAttr>()) { 11101fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // GNU inline semantics. Based on a number of examples, we came up with the 11111fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // following heuristic: if the "inline" keyword is present on a 11121fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // declaration of the function but "extern" is not present on that 11131fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // declaration, then the symbol is externally visible. Otherwise, the GNU 11141fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // "extern inline" semantics applies and the symbol is not externally 11151fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // visible. 11161fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor for (redecl_iterator Redecl = redecls_begin(), RedeclEnd = redecls_end(); 11171fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor Redecl != RedeclEnd; 11181fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor ++Redecl) { 11190130f3cc4ccd5f46361c48d5fe94133d74619424Douglas Gregor if (Redecl->isInlineSpecified() && Redecl->getStorageClass() != Extern) 11201fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor return true; 11211fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor } 11221fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor 11231fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // GNU "extern inline" semantics; no externally visible symbol. 11249f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor return false; 11251fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor } 11261fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor 11271fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // C99 6.7.4p6: 11281fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // [...] If all of the file scope declarations for a function in a 11291fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // translation unit include the inline function specifier without extern, 11301fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // then the definition in that translation unit is an inline definition. 11311fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor for (redecl_iterator Redecl = redecls_begin(), RedeclEnd = redecls_end(); 11321fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor Redecl != RedeclEnd; 11331fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor ++Redecl) { 11341fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // Only consider file-scope declarations in this test. 11351fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor if (!Redecl->getLexicalDeclContext()->isTranslationUnit()) 11361fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor continue; 11371fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor 11380130f3cc4ccd5f46361c48d5fe94133d74619424Douglas Gregor if (!Redecl->isInlineSpecified() || Redecl->getStorageClass() == Extern) 11391fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor return true; // Not an inline definition 11401fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor } 11411fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor 11421fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // C99 6.7.4p6: 11431fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // An inline definition does not provide an external definition for the 11441fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // function, and does not forbid an external definition in another 11451fc09a92d0bffda20e06fa882388c01e192e2069Douglas Gregor // translation unit. 11469f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor return false; 11479f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor} 11489f9bf258f8ebae30bfb70feb9d797d6eb67b0460Douglas Gregor 11491cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor/// getOverloadedOperator - Which C++ overloaded operator this 11501cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor/// function represents, if any. 11511cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas GregorOverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { 1152e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName) 1153e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor return getDeclName().getCXXOverloadedOperator(); 11541cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor else 11551cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor return OO_None; 11561cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor} 11571cd1b1e987f5e2f060d7972b13d83239b36d77d6Douglas Gregor 1158a6c058dd75c5563cced821fc16766a7cc179e00cSean Hunt/// getLiteralIdentifier - The literal suffix identifier this function 1159a6c058dd75c5563cced821fc16766a7cc179e00cSean Hunt/// represents, if any. 1160a6c058dd75c5563cced821fc16766a7cc179e00cSean Huntconst IdentifierInfo *FunctionDecl::getLiteralIdentifier() const { 1161a6c058dd75c5563cced821fc16766a7cc179e00cSean Hunt if (getDeclName().getNameKind() == DeclarationName::CXXLiteralOperatorName) 1162a6c058dd75c5563cced821fc16766a7cc179e00cSean Hunt return getDeclName().getCXXLiteralIdentifier(); 1163a6c058dd75c5563cced821fc16766a7cc179e00cSean Hunt else 1164a6c058dd75c5563cced821fc16766a7cc179e00cSean Hunt return 0; 1165a6c058dd75c5563cced821fc16766a7cc179e00cSean Hunt} 1166a6c058dd75c5563cced821fc16766a7cc179e00cSean Hunt 11672db323294ac02296125e1e0beb4c3595992e75bbDouglas GregorFunctionDecl *FunctionDecl::getInstantiatedFromMemberFunction() const { 1168b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor if (MemberSpecializationInfo *Info = getMemberSpecializationInfo()) 11692db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor return cast<FunctionDecl>(Info->getInstantiatedFrom()); 11702db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 11712db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor return 0; 11722db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor} 11732db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 1174b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas GregorMemberSpecializationInfo *FunctionDecl::getMemberSpecializationInfo() const { 1175b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor return TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>(); 1176b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor} 1177b3ae4fcd4314a9c1c46d41b200883599c32025b4Douglas Gregor 11782db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregorvoid 11792db323294ac02296125e1e0beb4c3595992e75bbDouglas GregorFunctionDecl::setInstantiationOfMemberFunction(FunctionDecl *FD, 11802db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor TemplateSpecializationKind TSK) { 11812db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor assert(TemplateOrSpecialization.isNull() && 11822db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor "Member function is already a specialization"); 11832db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor MemberSpecializationInfo *Info 11842db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor = new (getASTContext()) MemberSpecializationInfo(FD, TSK); 11852db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor TemplateOrSpecialization = Info; 11862db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor} 11872db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 11883b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregorbool FunctionDecl::isImplicitlyInstantiable() const { 11893b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // If this function already has a definition or is invalid, it can't be 11903b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // implicitly instantiated. 11913b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor if (isInvalidDecl() || getBody()) 11923b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor return false; 11933b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 11943b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor switch (getTemplateSpecializationKind()) { 11953b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor case TSK_Undeclared: 11963b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor case TSK_ExplicitSpecialization: 11973b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor case TSK_ExplicitInstantiationDefinition: 11983b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor return false; 11993b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 12003b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor case TSK_ImplicitInstantiation: 12013b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor return true; 12023b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 12033b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor case TSK_ExplicitInstantiationDeclaration: 12043b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // Handled below. 12053b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor break; 12063b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor } 12073b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 12083b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // Find the actual template from which we will instantiate. 12093b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor const FunctionDecl *PatternDecl = getTemplateInstantiationPattern(); 12103b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor Stmt *Pattern = 0; 12113b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor if (PatternDecl) 12123b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor Pattern = PatternDecl->getBody(PatternDecl); 12133b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 12143b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // C++0x [temp.explicit]p9: 12153b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // Except for inline functions, other explicit instantiation declarations 12163b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // have the effect of suppressing the implicit instantiation of the entity 12173b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // to which they refer. 12183b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor if (!Pattern || !PatternDecl) 12193b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor return true; 12203b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 12217ced9c8529b734e313f62a3b81189d6f402f6713Douglas Gregor return PatternDecl->isInlined(); 12223b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor} 12233b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 12243b846b6c252972a6f142aa226c1e65aebd0feecaDouglas GregorFunctionDecl *FunctionDecl::getTemplateInstantiationPattern() const { 12253b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor if (FunctionTemplateDecl *Primary = getPrimaryTemplate()) { 12263b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor while (Primary->getInstantiatedFromMemberTemplate()) { 12273b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // If we have hit a point where the user provided a specialization of 12283b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor // this template, we're done looking. 12293b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor if (Primary->isMemberSpecialization()) 12303b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor break; 12313b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 12323b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor Primary = Primary->getInstantiatedFromMemberTemplate(); 12333b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor } 12343b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 12353b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor return Primary->getTemplatedDecl(); 12363b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor } 12373b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 12383b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor return getInstantiatedFromMemberFunction(); 12393b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor} 12403b846b6c252972a6f142aa226c1e65aebd0feecaDouglas Gregor 124116e8be2ac532358d4e413fdfa2643b1876edda78Douglas GregorFunctionTemplateDecl *FunctionDecl::getPrimaryTemplate() const { 12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionTemplateSpecializationInfo *Info 124316e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor = TemplateOrSpecialization 124416e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor .dyn_cast<FunctionTemplateSpecializationInfo*>()) { 12451fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor return Info->Template.getPointer(); 124616e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor } 124716e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor return 0; 124816e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor} 124916e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor 125016e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregorconst TemplateArgumentList * 125116e8be2ac532358d4e413fdfa2643b1876edda78Douglas GregorFunctionDecl::getTemplateSpecializationArgs() const { 12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionTemplateSpecializationInfo *Info 1253fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor = TemplateOrSpecialization 1254fd056bc86a8b22a9421b5d921bbca276d0f9d0f7Douglas Gregor .dyn_cast<FunctionTemplateSpecializationInfo*>()) { 125516e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor return Info->TemplateArguments; 125616e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor } 125716e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor return 0; 125816e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor} 125916e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor 12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 1261838db383b69b9fb55f55c8e9546477df198a4faaDouglas GregorFunctionDecl::setFunctionTemplateSpecialization(FunctionTemplateDecl *Template, 1262127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor const TemplateArgumentList *TemplateArgs, 1263b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor void *InsertPos, 1264b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor TemplateSpecializationKind TSK) { 1265b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor assert(TSK != TSK_Undeclared && 1266b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor "Must specify the type of function template specialization"); 12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FunctionTemplateSpecializationInfo *Info 126816e8be2ac532358d4e413fdfa2643b1876edda78Douglas Gregor = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>(); 12691637be727f2a0434c1ed7aa385ea1c18328b0ccdDouglas Gregor if (!Info) 1270838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor Info = new (getASTContext()) FunctionTemplateSpecializationInfo; 12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1272127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor Info->Function = this; 12731fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor Info->Template.setPointer(Template); 1274b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor Info->Template.setInt(TSK - 1); 12751637be727f2a0434c1ed7aa385ea1c18328b0ccdDouglas Gregor Info->TemplateArguments = TemplateArgs; 12761637be727f2a0434c1ed7aa385ea1c18328b0ccdDouglas Gregor TemplateOrSpecialization = Info; 12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1278127102b5196ffe04bdb70fd553fe62c265ab10a9Douglas Gregor // Insert this function template specialization into the set of known 1279b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor // function template specializations. 1280b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor if (InsertPos) 1281b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor Template->getSpecializations().InsertNode(Info, InsertPos); 1282b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor else { 1283b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor // Try to insert the new node. If there is an existing node, remove it 1284b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor // first. 1285b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor FunctionTemplateSpecializationInfo *Existing 1286b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor = Template->getSpecializations().GetOrInsertNode(Info); 1287b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor if (Existing) { 1288b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor Template->getSpecializations().RemoveNode(Existing); 1289b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor Template->getSpecializations().GetOrInsertNode(Info); 1290b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor } 1291b9aa6b214c8fbc3e081dde575eef1f0913d48bdcDouglas Gregor } 12921637be727f2a0434c1ed7aa385ea1c18328b0ccdDouglas Gregor} 12931637be727f2a0434c1ed7aa385ea1c18328b0ccdDouglas Gregor 1294d0e3daf2b980b505e535d35b432c938c6d0208efDouglas GregorTemplateSpecializationKind FunctionDecl::getTemplateSpecializationKind() const { 12951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // For a function template specialization, query the specialization 1296d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor // information object. 12972db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor FunctionTemplateSpecializationInfo *FTSInfo 12981fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>(); 12992db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor if (FTSInfo) 13002db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor return FTSInfo->getTemplateSpecializationKind(); 1301d0e3daf2b980b505e535d35b432c938c6d0208efDouglas Gregor 13022db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor MemberSpecializationInfo *MSInfo 13032db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>(); 13042db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor if (MSInfo) 13052db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor return MSInfo->getTemplateSpecializationKind(); 13062db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor 13072db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor return TSK_Undeclared; 13081fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor} 13091fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor 13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 13110a897e32a09d290aa5b375444fe33928e47168bbDouglas GregorFunctionDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK, 13120a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor SourceLocation PointOfInstantiation) { 13132db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor if (FunctionTemplateSpecializationInfo *FTSInfo 13142db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor = TemplateOrSpecialization.dyn_cast< 13150a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor FunctionTemplateSpecializationInfo*>()) { 13162db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor FTSInfo->setTemplateSpecializationKind(TSK); 13170a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor if (TSK != TSK_ExplicitSpecialization && 13180a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor PointOfInstantiation.isValid() && 13190a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor FTSInfo->getPointOfInstantiation().isInvalid()) 13200a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor FTSInfo->setPointOfInstantiation(PointOfInstantiation); 13210a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor } else if (MemberSpecializationInfo *MSInfo 13220a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>()) { 13232db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor MSInfo->setTemplateSpecializationKind(TSK); 13240a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor if (TSK != TSK_ExplicitSpecialization && 13250a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor PointOfInstantiation.isValid() && 13260a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor MSInfo->getPointOfInstantiation().isInvalid()) 13270a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor MSInfo->setPointOfInstantiation(PointOfInstantiation); 13280a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor } else 13292db323294ac02296125e1e0beb4c3595992e75bbDouglas Gregor assert(false && "Function cannot have a template specialization kind"); 13301fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor} 13311fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5Douglas Gregor 13320a897e32a09d290aa5b375444fe33928e47168bbDouglas GregorSourceLocation FunctionDecl::getPointOfInstantiation() const { 13330a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor if (FunctionTemplateSpecializationInfo *FTSInfo 13340a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor = TemplateOrSpecialization.dyn_cast< 13350a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor FunctionTemplateSpecializationInfo*>()) 13360a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor return FTSInfo->getPointOfInstantiation(); 13370a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor else if (MemberSpecializationInfo *MSInfo 13380a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>()) 13390a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor return MSInfo->getPointOfInstantiation(); 13400a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor 13410a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor return SourceLocation(); 13420a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor} 13430a897e32a09d290aa5b375444fe33928e47168bbDouglas Gregor 13449f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregorbool FunctionDecl::isOutOfLine() const { 13459f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor if (Decl::isOutOfLine()) 13469f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor return true; 13479f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor 13489f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor // If this function was instantiated from a member function of a 13499f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor // class template, check whether that member function was defined out-of-line. 13509f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor if (FunctionDecl *FD = getInstantiatedFromMemberFunction()) { 13519f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor const FunctionDecl *Definition; 13529f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor if (FD->getBody(Definition)) 13539f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor return Definition->isOutOfLine(); 13549f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor } 13559f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor 13569f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor // If this function was instantiated from a function template, 13579f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor // check whether that function template was defined out-of-line. 13589f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor if (FunctionTemplateDecl *FunTmpl = getPrimaryTemplate()) { 13599f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor const FunctionDecl *Definition; 13609f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor if (FunTmpl->getTemplatedDecl()->getBody(Definition)) 13619f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor return Definition->isOutOfLine(); 13629f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor } 13639f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor 13649f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor return false; 13659f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor} 13669f185076dc8b79c8240b20a8746da96beb3f147bDouglas Gregor 13678a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner//===----------------------------------------------------------------------===// 13687783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl// FieldDecl Implementation 13697783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl//===----------------------------------------------------------------------===// 13707783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 13717783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlFieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, 13727783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl IdentifierInfo *Id, QualType T, 13737783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl TypeSourceInfo *TInfo, Expr *BW, bool Mutable) { 13747783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return new (C) FieldDecl(Decl::Field, DC, L, Id, T, TInfo, BW, Mutable); 13757783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 13767783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 13777783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redlbool FieldDecl::isAnonymousStructOrUnion() const { 13787783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (!isImplicit() || getDeclName()) 13797783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return false; 13807783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 13817783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (const RecordType *Record = getType()->getAs<RecordType>()) 13827783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return Record->getDecl()->isAnonymousStructOrUnion(); 13837783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 13847783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return false; 13857783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 13867783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 13877783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl//===----------------------------------------------------------------------===// 1388bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor// TagDecl Implementation 13894b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek//===----------------------------------------------------------------------===// 13904b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek 1391b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCallvoid TagDecl::Destroy(ASTContext &C) { 1392b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall if (hasExtInfo()) 1393b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall C.Deallocate(getExtInfo()); 1394b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall TypeDecl::Destroy(C); 1395b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall} 1396b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall 1397f602c8b6ce1a269c0bf8b3f049e923f4ea5c18e2Argyrios KyrtzidisSourceRange TagDecl::getSourceRange() const { 1398f602c8b6ce1a269c0bf8b3f049e923f4ea5c18e2Argyrios Kyrtzidis SourceLocation E = RBraceLoc.isValid() ? RBraceLoc : getLocation(); 1399741dd9a7e1d63e4e385b657e4ce11c5d96d44f72Douglas Gregor return SourceRange(TagKeywordLoc, E); 1400f602c8b6ce1a269c0bf8b3f049e923f4ea5c18e2Argyrios Kyrtzidis} 1401f602c8b6ce1a269c0bf8b3f049e923f4ea5c18e2Argyrios Kyrtzidis 1402b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios KyrtzidisTagDecl* TagDecl::getCanonicalDecl() { 14038e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor return getFirstDeclaration(); 1404b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis} 1405b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis 14060b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregorvoid TagDecl::startDefinition() { 14078e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor if (TagType *TagT = const_cast<TagType *>(TypeForDecl->getAs<TagType>())) { 14088e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor TagT->decl.setPointer(this); 14098e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor TagT->decl.setInt(1); 14108e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor } 141186ff308724171494395a840fd2efbe25e62f352eJohn McCall 141286ff308724171494395a840fd2efbe25e62f352eJohn McCall if (isa<CXXRecordDecl>(this)) { 141386ff308724171494395a840fd2efbe25e62f352eJohn McCall CXXRecordDecl *D = cast<CXXRecordDecl>(this); 141486ff308724171494395a840fd2efbe25e62f352eJohn McCall struct CXXRecordDecl::DefinitionData *Data = 141586ff308724171494395a840fd2efbe25e62f352eJohn McCall new (getASTContext()) struct CXXRecordDecl::DefinitionData(D); 14162243288c4826905b5a0837f6f21d9d821688652eJohn McCall for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) 14172243288c4826905b5a0837f6f21d9d821688652eJohn McCall cast<CXXRecordDecl>(*I)->DefinitionData = Data; 141886ff308724171494395a840fd2efbe25e62f352eJohn McCall } 14190b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor} 14200b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 14210b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregorvoid TagDecl::completeDefinition() { 14225cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall assert((!isa<CXXRecordDecl>(this) || 14235cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall cast<CXXRecordDecl>(this)->hasDefinition()) && 14245cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall "definition completed but not started"); 14255cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall 14260b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor IsDefinition = true; 14278e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor if (TagType *TagT = const_cast<TagType *>(TypeForDecl->getAs<TagType>())) { 14288e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor assert(TagT->decl.getPointer() == this && 14298e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor "Attempt to redefine a tag definition?"); 14308e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor TagT->decl.setInt(0); 14318e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor } 14320b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor} 14330b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 1434952b017601f9c82b51119c3a1600f1312a833db9Douglas GregorTagDecl* TagDecl::getDefinition() const { 14358e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor if (isDefinition()) 14368e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor return const_cast<TagDecl *>(this); 14371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (redecl_iterator R = redecls_begin(), REnd = redecls_end(); 14398e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor R != REnd; ++R) 14408e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor if (R->isDefinition()) 14418e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor return *R; 14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14438e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor return 0; 14444b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek} 14454b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek 1446f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCallTagDecl::TagKind TagDecl::getTagKindForTypeSpec(unsigned TypeSpec) { 1447f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall switch (TypeSpec) { 14489f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin default: llvm_unreachable("unexpected type specifier"); 1449f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall case DeclSpec::TST_struct: return TK_struct; 1450f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall case DeclSpec::TST_class: return TK_class; 1451f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall case DeclSpec::TST_union: return TK_union; 1452f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall case DeclSpec::TST_enum: return TK_enum; 1453f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall } 1454f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall} 1455f1bbbb49f06a7462476cd88166fccda5feb15cabJohn McCall 1456b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCallvoid TagDecl::setQualifierInfo(NestedNameSpecifier *Qualifier, 1457b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall SourceRange QualifierRange) { 1458b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall if (Qualifier) { 1459b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Make sure the extended qualifier info is allocated. 1460b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall if (!hasExtInfo()) 1461b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall TypedefDeclOrQualifier = new (getASTContext()) ExtInfo; 1462b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Set qualifier info. 1463b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall getExtInfo()->NNS = Qualifier; 1464b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall getExtInfo()->NNSRange = QualifierRange; 1465b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall } 1466b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall else { 1467b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall // Here Qualifier == 0, i.e., we are removing the qualifier (if any). 1468b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall assert(QualifierRange.isInvalid()); 1469b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall if (hasExtInfo()) { 1470b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall getASTContext().Deallocate(getExtInfo()); 1471b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall TypedefDeclOrQualifier = (TypedefDecl*) 0; 1472b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall } 1473b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall } 1474b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall} 1475b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall 14764b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek//===----------------------------------------------------------------------===// 14777783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl// EnumDecl Implementation 14787783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl//===----------------------------------------------------------------------===// 14797783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 14807783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlEnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, 14817783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl IdentifierInfo *Id, SourceLocation TKL, 14827783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl EnumDecl *PrevDecl) { 14837783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl EnumDecl *Enum = new (C) EnumDecl(DC, L, Id, PrevDecl, TKL); 14847783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl C.getTypeDeclType(Enum, PrevDecl); 14857783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return Enum; 14867783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 14877783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 14887783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redlvoid EnumDecl::Destroy(ASTContext& C) { 1489b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall TagDecl::Destroy(C); 14907783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 14917783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 1492838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregorvoid EnumDecl::completeDefinition(QualType NewType, 14937783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl QualType NewPromotionType) { 14947783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl assert(!isDefinition() && "Cannot redefine enums!"); 14957783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl IntegerType = NewType; 14967783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl PromotionType = NewPromotionType; 14977783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl TagDecl::completeDefinition(); 14987783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 14997783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 15007783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl//===----------------------------------------------------------------------===// 15018a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner// RecordDecl Implementation 15028a934233d1582b5bde9d270bc0705aa81e471a79Chris Lattner//===----------------------------------------------------------------------===// 15035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 150435bc0821c4f80041724cd4c5c4889b2581546a41Argyrios KyrtzidisRecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L, 15058e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor IdentifierInfo *Id, RecordDecl *PrevDecl, 15068e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor SourceLocation TKL) 15078e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor : TagDecl(DK, TK, DC, L, Id, PrevDecl, TKL) { 15086359792ca92e7ca2f416cb804c6604358174e994Ted Kremenek HasFlexibleArrayMember = false; 1509bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor AnonymousStructOrUnion = false; 1510082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian HasObjectMember = false; 15116359792ca92e7ca2f416cb804c6604358174e994Ted Kremenek assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!"); 15126359792ca92e7ca2f416cb804c6604358174e994Ted Kremenek} 15136359792ca92e7ca2f416cb804c6604358174e994Ted Kremenek 15146359792ca92e7ca2f416cb804c6604358174e994Ted KremenekRecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, 15154b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek SourceLocation L, IdentifierInfo *Id, 1516741dd9a7e1d63e4e385b657e4ce11c5d96d44f72Douglas Gregor SourceLocation TKL, RecordDecl* PrevDecl) { 15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15188e9e9ef5348bce1a8f0741a5684fac3de9701c28Douglas Gregor RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id, PrevDecl, TKL); 15194b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek C.getTypeDeclType(R, PrevDecl); 15204b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek return R; 15216359792ca92e7ca2f416cb804c6604358174e994Ted Kremenek} 15226359792ca92e7ca2f416cb804c6604358174e994Ted Kremenek 1523997b6c6d73541f010afc81e28191c8eae7b24f77Argyrios KyrtzidisRecordDecl::~RecordDecl() { 1524997b6c6d73541f010afc81e28191c8eae7b24f77Argyrios Kyrtzidis} 1525997b6c6d73541f010afc81e28191c8eae7b24f77Argyrios Kyrtzidis 1526997b6c6d73541f010afc81e28191c8eae7b24f77Argyrios Kyrtzidisvoid RecordDecl::Destroy(ASTContext& C) { 1527997b6c6d73541f010afc81e28191c8eae7b24f77Argyrios Kyrtzidis TagDecl::Destroy(C); 1528997b6c6d73541f010afc81e28191c8eae7b24f77Argyrios Kyrtzidis} 1529997b6c6d73541f010afc81e28191c8eae7b24f77Argyrios Kyrtzidis 1530c9b5b4074bd73d4af76e69cccf8ecd365fdd1008Douglas Gregorbool RecordDecl::isInjectedClassName() const { 15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return isImplicit() && getDeclName() && getDeclContext()->isRecord() && 1532c9b5b4074bd73d4af76e69cccf8ecd365fdd1008Douglas Gregor cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName(); 1533c9b5b4074bd73d4af76e69cccf8ecd365fdd1008Douglas Gregor} 1534c9b5b4074bd73d4af76e69cccf8ecd365fdd1008Douglas Gregor 153544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor/// completeDefinition - Notes that the definition of this type is now 153644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor/// complete. 1537838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregorvoid RecordDecl::completeDefinition() { 15385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isDefinition() && "Cannot redefine record!"); 15390b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl::completeDefinition(); 15405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 154256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff//===----------------------------------------------------------------------===// 154356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff// BlockDecl Implementation 154456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff//===----------------------------------------------------------------------===// 154556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 154656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffBlockDecl::~BlockDecl() { 154756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 154856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 154956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffvoid BlockDecl::Destroy(ASTContext& C) { 155056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff if (Body) 155156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Body->Destroy(C); 155256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 155356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) 155456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff (*I)->Destroy(C); 15551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump C.Deallocate(ParamInfo); 155756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Decl::Destroy(C); 155856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 1559e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff 1560838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregorvoid BlockDecl::setParams(ParmVarDecl **NewParamInfo, 1561e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff unsigned NParms) { 1562e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff assert(ParamInfo == 0 && "Already has param info!"); 15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1564e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff // Zero params -> null pointer. 1565e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff if (NParms) { 1566e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff NumParams = NParms; 1567838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor void *Mem = getASTContext().Allocate(sizeof(ParmVarDecl*)*NumParams); 1568e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff ParamInfo = new (Mem) ParmVarDecl*[NumParams]; 1569e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); 1570e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff } 1571e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff} 1572e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff 1573e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroffunsigned BlockDecl::getNumParams() const { 1574e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff return NumParams; 1575e78b809bbcd92928a63da81f2cd843faad3e4dfdSteve Naroff} 15767783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 15777783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 15787783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl//===----------------------------------------------------------------------===// 15797783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl// Other Decl Allocation/Deallocation Method Implementations 15807783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl//===----------------------------------------------------------------------===// 15817783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 15827783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlTranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) { 15837783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return new (C) TranslationUnitDecl(C); 15847783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 15857783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 15867783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlNamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, 15877783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl SourceLocation L, IdentifierInfo *Id) { 15887783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return new (C) NamespaceDecl(DC, L, Id); 15897783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 15907783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 15917783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redlvoid NamespaceDecl::Destroy(ASTContext& C) { 15927783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl // NamespaceDecl uses "NextDeclarator" to chain namespace declarations 15937783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl // together. They are all top-level Decls. 15947783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 15957783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl this->~NamespaceDecl(); 1596b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall Decl::Destroy(C); 15977783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 15987783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 15997783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 16007783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, 16017783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl SourceLocation L, IdentifierInfo *Id, QualType T) { 16027783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return new (C) ImplicitParamDecl(ImplicitParam, DC, L, Id, T); 16037783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 16047783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 16057783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlFunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, 16067783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl SourceLocation L, 16077783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl DeclarationName N, QualType T, 16087783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl TypeSourceInfo *TInfo, 16097783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl StorageClass S, bool isInline, 16107783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl bool hasWrittenPrototype) { 16117783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl FunctionDecl *New 16127783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl = new (C) FunctionDecl(Function, DC, L, N, T, TInfo, S, isInline); 16137783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl New->HasWrittenPrototype = hasWrittenPrototype; 16147783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return New; 16157783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 16167783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 16177783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlBlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { 16187783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return new (C) BlockDecl(DC, L); 16197783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 16207783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 16217783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlEnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, 16227783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl SourceLocation L, 16237783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl IdentifierInfo *Id, QualType T, 16247783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl Expr *E, const llvm::APSInt &V) { 16257783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return new (C) EnumConstantDecl(CD, L, Id, T, E, V); 16267783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 16277783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 16287783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redlvoid EnumConstantDecl::Destroy(ASTContext& C) { 16297783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl if (Init) Init->Destroy(C); 1630b6217665c6a987f2d6c8665fd70365d7719ac4dfJohn McCall ValueDecl::Destroy(C); 16317783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 16327783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 16337783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlTypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, 16347783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl SourceLocation L, IdentifierInfo *Id, 16357783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl TypeSourceInfo *TInfo) { 16367783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return new (C) TypedefDecl(DC, L, Id, TInfo); 16377783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 16387783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 16397783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl// Anchor TypedefDecl's vtable here. 16407783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlTypedefDecl::~TypedefDecl() {} 16417783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl 16427783bfc066776a63d6a2cd28329d4d149647bfdcSebastian RedlFileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC, 16437783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl SourceLocation L, 16447783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl StringLiteral *Str) { 16457783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl return new (C) FileScopeAsmDecl(DC, L, Str); 16467783bfc066776a63d6a2cd28329d4d149647bfdcSebastian Redl} 1647