1*f4a2713aSLionel Sambuc //===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===// 2*f4a2713aSLionel Sambuc // 3*f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4*f4a2713aSLionel Sambuc // 5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7*f4a2713aSLionel Sambuc // 8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9*f4a2713aSLionel Sambuc // 10*f4a2713aSLionel Sambuc // This file implements the subclesses of Expr class declared in ExprCXX.h 11*f4a2713aSLionel Sambuc // 12*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13*f4a2713aSLionel Sambuc 14*f4a2713aSLionel Sambuc #include "clang/AST/ASTContext.h" 15*f4a2713aSLionel Sambuc #include "clang/AST/Attr.h" 16*f4a2713aSLionel Sambuc #include "clang/AST/DeclCXX.h" 17*f4a2713aSLionel Sambuc #include "clang/AST/DeclTemplate.h" 18*f4a2713aSLionel Sambuc #include "clang/AST/ExprCXX.h" 19*f4a2713aSLionel Sambuc #include "clang/AST/TypeLoc.h" 20*f4a2713aSLionel Sambuc #include "clang/Basic/IdentifierTable.h" 21*f4a2713aSLionel Sambuc using namespace clang; 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 25*f4a2713aSLionel Sambuc // Child Iterators for iterating over subexpressions/substatements 26*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 27*f4a2713aSLionel Sambuc 28*f4a2713aSLionel Sambuc bool CXXTypeidExpr::isPotentiallyEvaluated() const { 29*f4a2713aSLionel Sambuc if (isTypeOperand()) 30*f4a2713aSLionel Sambuc return false; 31*f4a2713aSLionel Sambuc 32*f4a2713aSLionel Sambuc // C++11 [expr.typeid]p3: 33*f4a2713aSLionel Sambuc // When typeid is applied to an expression other than a glvalue of 34*f4a2713aSLionel Sambuc // polymorphic class type, [...] the expression is an unevaluated operand. 35*f4a2713aSLionel Sambuc const Expr *E = getExprOperand(); 36*f4a2713aSLionel Sambuc if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl()) 37*f4a2713aSLionel Sambuc if (RD->isPolymorphic() && E->isGLValue()) 38*f4a2713aSLionel Sambuc return true; 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambuc return false; 41*f4a2713aSLionel Sambuc } 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const { 44*f4a2713aSLionel Sambuc assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 45*f4a2713aSLionel Sambuc Qualifiers Quals; 46*f4a2713aSLionel Sambuc return Context.getUnqualifiedArrayType( 47*f4a2713aSLionel Sambuc Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals); 48*f4a2713aSLionel Sambuc } 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambuc QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const { 51*f4a2713aSLionel Sambuc assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 52*f4a2713aSLionel Sambuc Qualifiers Quals; 53*f4a2713aSLionel Sambuc return Context.getUnqualifiedArrayType( 54*f4a2713aSLionel Sambuc Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals); 55*f4a2713aSLionel Sambuc } 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambuc // static 58*f4a2713aSLionel Sambuc UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT, 59*f4a2713aSLionel Sambuc bool *RDHasMultipleGUIDsPtr) { 60*f4a2713aSLionel Sambuc // Optionally remove one level of pointer, reference or array indirection. 61*f4a2713aSLionel Sambuc const Type *Ty = QT.getTypePtr(); 62*f4a2713aSLionel Sambuc if (QT->isPointerType() || QT->isReferenceType()) 63*f4a2713aSLionel Sambuc Ty = QT->getPointeeType().getTypePtr(); 64*f4a2713aSLionel Sambuc else if (QT->isArrayType()) 65*f4a2713aSLionel Sambuc Ty = Ty->getBaseElementTypeUnsafe(); 66*f4a2713aSLionel Sambuc 67*f4a2713aSLionel Sambuc // Loop all record redeclaration looking for an uuid attribute. 68*f4a2713aSLionel Sambuc CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); 69*f4a2713aSLionel Sambuc if (!RD) 70*f4a2713aSLionel Sambuc return 0; 71*f4a2713aSLionel Sambuc 72*f4a2713aSLionel Sambuc // __uuidof can grab UUIDs from template arguments. 73*f4a2713aSLionel Sambuc if (ClassTemplateSpecializationDecl *CTSD = 74*f4a2713aSLionel Sambuc dyn_cast<ClassTemplateSpecializationDecl>(RD)) { 75*f4a2713aSLionel Sambuc const TemplateArgumentList &TAL = CTSD->getTemplateArgs(); 76*f4a2713aSLionel Sambuc UuidAttr *UuidForRD = 0; 77*f4a2713aSLionel Sambuc 78*f4a2713aSLionel Sambuc for (unsigned I = 0, N = TAL.size(); I != N; ++I) { 79*f4a2713aSLionel Sambuc const TemplateArgument &TA = TAL[I]; 80*f4a2713aSLionel Sambuc bool SeenMultipleGUIDs = false; 81*f4a2713aSLionel Sambuc 82*f4a2713aSLionel Sambuc UuidAttr *UuidForTA = 0; 83*f4a2713aSLionel Sambuc if (TA.getKind() == TemplateArgument::Type) 84*f4a2713aSLionel Sambuc UuidForTA = GetUuidAttrOfType(TA.getAsType(), &SeenMultipleGUIDs); 85*f4a2713aSLionel Sambuc else if (TA.getKind() == TemplateArgument::Declaration) 86*f4a2713aSLionel Sambuc UuidForTA = 87*f4a2713aSLionel Sambuc GetUuidAttrOfType(TA.getAsDecl()->getType(), &SeenMultipleGUIDs); 88*f4a2713aSLionel Sambuc 89*f4a2713aSLionel Sambuc // If the template argument has a UUID, there are three cases: 90*f4a2713aSLionel Sambuc // - This is the first UUID seen for this RecordDecl. 91*f4a2713aSLionel Sambuc // - This is a different UUID than previously seen for this RecordDecl. 92*f4a2713aSLionel Sambuc // - This is the same UUID than previously seen for this RecordDecl. 93*f4a2713aSLionel Sambuc if (UuidForTA) { 94*f4a2713aSLionel Sambuc if (!UuidForRD) 95*f4a2713aSLionel Sambuc UuidForRD = UuidForTA; 96*f4a2713aSLionel Sambuc else if (UuidForRD != UuidForTA) 97*f4a2713aSLionel Sambuc SeenMultipleGUIDs = true; 98*f4a2713aSLionel Sambuc } 99*f4a2713aSLionel Sambuc 100*f4a2713aSLionel Sambuc // Seeing multiple UUIDs means that we couldn't find a UUID 101*f4a2713aSLionel Sambuc if (SeenMultipleGUIDs) { 102*f4a2713aSLionel Sambuc if (RDHasMultipleGUIDsPtr) 103*f4a2713aSLionel Sambuc *RDHasMultipleGUIDsPtr = true; 104*f4a2713aSLionel Sambuc return 0; 105*f4a2713aSLionel Sambuc } 106*f4a2713aSLionel Sambuc } 107*f4a2713aSLionel Sambuc 108*f4a2713aSLionel Sambuc return UuidForRD; 109*f4a2713aSLionel Sambuc } 110*f4a2713aSLionel Sambuc 111*f4a2713aSLionel Sambuc for (CXXRecordDecl::redecl_iterator I = RD->redecls_begin(), 112*f4a2713aSLionel Sambuc E = RD->redecls_end(); 113*f4a2713aSLionel Sambuc I != E; ++I) 114*f4a2713aSLionel Sambuc if (UuidAttr *Uuid = I->getAttr<UuidAttr>()) 115*f4a2713aSLionel Sambuc return Uuid; 116*f4a2713aSLionel Sambuc 117*f4a2713aSLionel Sambuc return 0; 118*f4a2713aSLionel Sambuc } 119*f4a2713aSLionel Sambuc 120*f4a2713aSLionel Sambuc StringRef CXXUuidofExpr::getUuidAsStringRef(ASTContext &Context) const { 121*f4a2713aSLionel Sambuc StringRef Uuid; 122*f4a2713aSLionel Sambuc if (isTypeOperand()) 123*f4a2713aSLionel Sambuc Uuid = CXXUuidofExpr::GetUuidAttrOfType(getTypeOperand(Context))->getGuid(); 124*f4a2713aSLionel Sambuc else { 125*f4a2713aSLionel Sambuc // Special case: __uuidof(0) means an all-zero GUID. 126*f4a2713aSLionel Sambuc Expr *Op = getExprOperand(); 127*f4a2713aSLionel Sambuc if (!Op->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) 128*f4a2713aSLionel Sambuc Uuid = CXXUuidofExpr::GetUuidAttrOfType(Op->getType())->getGuid(); 129*f4a2713aSLionel Sambuc else 130*f4a2713aSLionel Sambuc Uuid = "00000000-0000-0000-0000-000000000000"; 131*f4a2713aSLionel Sambuc } 132*f4a2713aSLionel Sambuc return Uuid; 133*f4a2713aSLionel Sambuc } 134*f4a2713aSLionel Sambuc 135*f4a2713aSLionel Sambuc // CXXScalarValueInitExpr 136*f4a2713aSLionel Sambuc SourceLocation CXXScalarValueInitExpr::getLocStart() const { 137*f4a2713aSLionel Sambuc return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : RParenLoc; 138*f4a2713aSLionel Sambuc } 139*f4a2713aSLionel Sambuc 140*f4a2713aSLionel Sambuc // CXXNewExpr 141*f4a2713aSLionel Sambuc CXXNewExpr::CXXNewExpr(const ASTContext &C, bool globalNew, 142*f4a2713aSLionel Sambuc FunctionDecl *operatorNew, FunctionDecl *operatorDelete, 143*f4a2713aSLionel Sambuc bool usualArrayDeleteWantsSize, 144*f4a2713aSLionel Sambuc ArrayRef<Expr*> placementArgs, 145*f4a2713aSLionel Sambuc SourceRange typeIdParens, Expr *arraySize, 146*f4a2713aSLionel Sambuc InitializationStyle initializationStyle, 147*f4a2713aSLionel Sambuc Expr *initializer, QualType ty, 148*f4a2713aSLionel Sambuc TypeSourceInfo *allocatedTypeInfo, 149*f4a2713aSLionel Sambuc SourceRange Range, SourceRange directInitRange) 150*f4a2713aSLionel Sambuc : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary, 151*f4a2713aSLionel Sambuc ty->isDependentType(), ty->isDependentType(), 152*f4a2713aSLionel Sambuc ty->isInstantiationDependentType(), 153*f4a2713aSLionel Sambuc ty->containsUnexpandedParameterPack()), 154*f4a2713aSLionel Sambuc SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete), 155*f4a2713aSLionel Sambuc AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens), 156*f4a2713aSLionel Sambuc Range(Range), DirectInitRange(directInitRange), 157*f4a2713aSLionel Sambuc GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { 158*f4a2713aSLionel Sambuc assert((initializer != 0 || initializationStyle == NoInit) && 159*f4a2713aSLionel Sambuc "Only NoInit can have no initializer."); 160*f4a2713aSLionel Sambuc StoredInitializationStyle = initializer ? initializationStyle + 1 : 0; 161*f4a2713aSLionel Sambuc AllocateArgsArray(C, arraySize != 0, placementArgs.size(), initializer != 0); 162*f4a2713aSLionel Sambuc unsigned i = 0; 163*f4a2713aSLionel Sambuc if (Array) { 164*f4a2713aSLionel Sambuc if (arraySize->isInstantiationDependent()) 165*f4a2713aSLionel Sambuc ExprBits.InstantiationDependent = true; 166*f4a2713aSLionel Sambuc 167*f4a2713aSLionel Sambuc if (arraySize->containsUnexpandedParameterPack()) 168*f4a2713aSLionel Sambuc ExprBits.ContainsUnexpandedParameterPack = true; 169*f4a2713aSLionel Sambuc 170*f4a2713aSLionel Sambuc SubExprs[i++] = arraySize; 171*f4a2713aSLionel Sambuc } 172*f4a2713aSLionel Sambuc 173*f4a2713aSLionel Sambuc if (initializer) { 174*f4a2713aSLionel Sambuc if (initializer->isInstantiationDependent()) 175*f4a2713aSLionel Sambuc ExprBits.InstantiationDependent = true; 176*f4a2713aSLionel Sambuc 177*f4a2713aSLionel Sambuc if (initializer->containsUnexpandedParameterPack()) 178*f4a2713aSLionel Sambuc ExprBits.ContainsUnexpandedParameterPack = true; 179*f4a2713aSLionel Sambuc 180*f4a2713aSLionel Sambuc SubExprs[i++] = initializer; 181*f4a2713aSLionel Sambuc } 182*f4a2713aSLionel Sambuc 183*f4a2713aSLionel Sambuc for (unsigned j = 0; j != placementArgs.size(); ++j) { 184*f4a2713aSLionel Sambuc if (placementArgs[j]->isInstantiationDependent()) 185*f4a2713aSLionel Sambuc ExprBits.InstantiationDependent = true; 186*f4a2713aSLionel Sambuc if (placementArgs[j]->containsUnexpandedParameterPack()) 187*f4a2713aSLionel Sambuc ExprBits.ContainsUnexpandedParameterPack = true; 188*f4a2713aSLionel Sambuc 189*f4a2713aSLionel Sambuc SubExprs[i++] = placementArgs[j]; 190*f4a2713aSLionel Sambuc } 191*f4a2713aSLionel Sambuc 192*f4a2713aSLionel Sambuc switch (getInitializationStyle()) { 193*f4a2713aSLionel Sambuc case CallInit: 194*f4a2713aSLionel Sambuc this->Range.setEnd(DirectInitRange.getEnd()); break; 195*f4a2713aSLionel Sambuc case ListInit: 196*f4a2713aSLionel Sambuc this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break; 197*f4a2713aSLionel Sambuc default: 198*f4a2713aSLionel Sambuc if (TypeIdParens.isValid()) 199*f4a2713aSLionel Sambuc this->Range.setEnd(TypeIdParens.getEnd()); 200*f4a2713aSLionel Sambuc break; 201*f4a2713aSLionel Sambuc } 202*f4a2713aSLionel Sambuc } 203*f4a2713aSLionel Sambuc 204*f4a2713aSLionel Sambuc void CXXNewExpr::AllocateArgsArray(const ASTContext &C, bool isArray, 205*f4a2713aSLionel Sambuc unsigned numPlaceArgs, bool hasInitializer){ 206*f4a2713aSLionel Sambuc assert(SubExprs == 0 && "SubExprs already allocated"); 207*f4a2713aSLionel Sambuc Array = isArray; 208*f4a2713aSLionel Sambuc NumPlacementArgs = numPlaceArgs; 209*f4a2713aSLionel Sambuc 210*f4a2713aSLionel Sambuc unsigned TotalSize = Array + hasInitializer + NumPlacementArgs; 211*f4a2713aSLionel Sambuc SubExprs = new (C) Stmt*[TotalSize]; 212*f4a2713aSLionel Sambuc } 213*f4a2713aSLionel Sambuc 214*f4a2713aSLionel Sambuc bool CXXNewExpr::shouldNullCheckAllocation(const ASTContext &Ctx) const { 215*f4a2713aSLionel Sambuc return getOperatorNew()->getType()-> 216*f4a2713aSLionel Sambuc castAs<FunctionProtoType>()->isNothrow(Ctx); 217*f4a2713aSLionel Sambuc } 218*f4a2713aSLionel Sambuc 219*f4a2713aSLionel Sambuc // CXXDeleteExpr 220*f4a2713aSLionel Sambuc QualType CXXDeleteExpr::getDestroyedType() const { 221*f4a2713aSLionel Sambuc const Expr *Arg = getArgument(); 222*f4a2713aSLionel Sambuc // The type-to-delete may not be a pointer if it's a dependent type. 223*f4a2713aSLionel Sambuc const QualType ArgType = Arg->getType(); 224*f4a2713aSLionel Sambuc 225*f4a2713aSLionel Sambuc if (ArgType->isDependentType() && !ArgType->isPointerType()) 226*f4a2713aSLionel Sambuc return QualType(); 227*f4a2713aSLionel Sambuc 228*f4a2713aSLionel Sambuc return ArgType->getAs<PointerType>()->getPointeeType(); 229*f4a2713aSLionel Sambuc } 230*f4a2713aSLionel Sambuc 231*f4a2713aSLionel Sambuc // CXXPseudoDestructorExpr 232*f4a2713aSLionel Sambuc PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info) 233*f4a2713aSLionel Sambuc : Type(Info) 234*f4a2713aSLionel Sambuc { 235*f4a2713aSLionel Sambuc Location = Info->getTypeLoc().getLocalSourceRange().getBegin(); 236*f4a2713aSLionel Sambuc } 237*f4a2713aSLionel Sambuc 238*f4a2713aSLionel Sambuc CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(const ASTContext &Context, 239*f4a2713aSLionel Sambuc Expr *Base, bool isArrow, SourceLocation OperatorLoc, 240*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, 241*f4a2713aSLionel Sambuc SourceLocation ColonColonLoc, SourceLocation TildeLoc, 242*f4a2713aSLionel Sambuc PseudoDestructorTypeStorage DestroyedType) 243*f4a2713aSLionel Sambuc : Expr(CXXPseudoDestructorExprClass, 244*f4a2713aSLionel Sambuc Context.getPointerType(Context.getFunctionType( 245*f4a2713aSLionel Sambuc Context.VoidTy, None, 246*f4a2713aSLionel Sambuc FunctionProtoType::ExtProtoInfo( 247*f4a2713aSLionel Sambuc Context.getDefaultCallingConvention(false, true)))), 248*f4a2713aSLionel Sambuc VK_RValue, OK_Ordinary, 249*f4a2713aSLionel Sambuc /*isTypeDependent=*/(Base->isTypeDependent() || 250*f4a2713aSLionel Sambuc (DestroyedType.getTypeSourceInfo() && 251*f4a2713aSLionel Sambuc DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), 252*f4a2713aSLionel Sambuc /*isValueDependent=*/Base->isValueDependent(), 253*f4a2713aSLionel Sambuc (Base->isInstantiationDependent() || 254*f4a2713aSLionel Sambuc (QualifierLoc && 255*f4a2713aSLionel Sambuc QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) || 256*f4a2713aSLionel Sambuc (ScopeType && 257*f4a2713aSLionel Sambuc ScopeType->getType()->isInstantiationDependentType()) || 258*f4a2713aSLionel Sambuc (DestroyedType.getTypeSourceInfo() && 259*f4a2713aSLionel Sambuc DestroyedType.getTypeSourceInfo()->getType() 260*f4a2713aSLionel Sambuc ->isInstantiationDependentType())), 261*f4a2713aSLionel Sambuc // ContainsUnexpandedParameterPack 262*f4a2713aSLionel Sambuc (Base->containsUnexpandedParameterPack() || 263*f4a2713aSLionel Sambuc (QualifierLoc && 264*f4a2713aSLionel Sambuc QualifierLoc.getNestedNameSpecifier() 265*f4a2713aSLionel Sambuc ->containsUnexpandedParameterPack()) || 266*f4a2713aSLionel Sambuc (ScopeType && 267*f4a2713aSLionel Sambuc ScopeType->getType()->containsUnexpandedParameterPack()) || 268*f4a2713aSLionel Sambuc (DestroyedType.getTypeSourceInfo() && 269*f4a2713aSLionel Sambuc DestroyedType.getTypeSourceInfo()->getType() 270*f4a2713aSLionel Sambuc ->containsUnexpandedParameterPack()))), 271*f4a2713aSLionel Sambuc Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), 272*f4a2713aSLionel Sambuc OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), 273*f4a2713aSLionel Sambuc ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), 274*f4a2713aSLionel Sambuc DestroyedType(DestroyedType) { } 275*f4a2713aSLionel Sambuc 276*f4a2713aSLionel Sambuc QualType CXXPseudoDestructorExpr::getDestroyedType() const { 277*f4a2713aSLionel Sambuc if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) 278*f4a2713aSLionel Sambuc return TInfo->getType(); 279*f4a2713aSLionel Sambuc 280*f4a2713aSLionel Sambuc return QualType(); 281*f4a2713aSLionel Sambuc } 282*f4a2713aSLionel Sambuc 283*f4a2713aSLionel Sambuc SourceLocation CXXPseudoDestructorExpr::getLocEnd() const { 284*f4a2713aSLionel Sambuc SourceLocation End = DestroyedType.getLocation(); 285*f4a2713aSLionel Sambuc if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo()) 286*f4a2713aSLionel Sambuc End = TInfo->getTypeLoc().getLocalSourceRange().getEnd(); 287*f4a2713aSLionel Sambuc return End; 288*f4a2713aSLionel Sambuc } 289*f4a2713aSLionel Sambuc 290*f4a2713aSLionel Sambuc // UnresolvedLookupExpr 291*f4a2713aSLionel Sambuc UnresolvedLookupExpr * 292*f4a2713aSLionel Sambuc UnresolvedLookupExpr::Create(const ASTContext &C, 293*f4a2713aSLionel Sambuc CXXRecordDecl *NamingClass, 294*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, 295*f4a2713aSLionel Sambuc SourceLocation TemplateKWLoc, 296*f4a2713aSLionel Sambuc const DeclarationNameInfo &NameInfo, 297*f4a2713aSLionel Sambuc bool ADL, 298*f4a2713aSLionel Sambuc const TemplateArgumentListInfo *Args, 299*f4a2713aSLionel Sambuc UnresolvedSetIterator Begin, 300*f4a2713aSLionel Sambuc UnresolvedSetIterator End) 301*f4a2713aSLionel Sambuc { 302*f4a2713aSLionel Sambuc assert(Args || TemplateKWLoc.isValid()); 303*f4a2713aSLionel Sambuc unsigned num_args = Args ? Args->size() : 0; 304*f4a2713aSLionel Sambuc void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) + 305*f4a2713aSLionel Sambuc ASTTemplateKWAndArgsInfo::sizeFor(num_args)); 306*f4a2713aSLionel Sambuc return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 307*f4a2713aSLionel Sambuc TemplateKWLoc, NameInfo, 308*f4a2713aSLionel Sambuc ADL, /*Overload*/ true, Args, 309*f4a2713aSLionel Sambuc Begin, End); 310*f4a2713aSLionel Sambuc } 311*f4a2713aSLionel Sambuc 312*f4a2713aSLionel Sambuc UnresolvedLookupExpr * 313*f4a2713aSLionel Sambuc UnresolvedLookupExpr::CreateEmpty(const ASTContext &C, 314*f4a2713aSLionel Sambuc bool HasTemplateKWAndArgsInfo, 315*f4a2713aSLionel Sambuc unsigned NumTemplateArgs) { 316*f4a2713aSLionel Sambuc std::size_t size = sizeof(UnresolvedLookupExpr); 317*f4a2713aSLionel Sambuc if (HasTemplateKWAndArgsInfo) 318*f4a2713aSLionel Sambuc size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); 319*f4a2713aSLionel Sambuc 320*f4a2713aSLionel Sambuc void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>()); 321*f4a2713aSLionel Sambuc UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell()); 322*f4a2713aSLionel Sambuc E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; 323*f4a2713aSLionel Sambuc return E; 324*f4a2713aSLionel Sambuc } 325*f4a2713aSLionel Sambuc 326*f4a2713aSLionel Sambuc OverloadExpr::OverloadExpr(StmtClass K, const ASTContext &C, 327*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, 328*f4a2713aSLionel Sambuc SourceLocation TemplateKWLoc, 329*f4a2713aSLionel Sambuc const DeclarationNameInfo &NameInfo, 330*f4a2713aSLionel Sambuc const TemplateArgumentListInfo *TemplateArgs, 331*f4a2713aSLionel Sambuc UnresolvedSetIterator Begin, 332*f4a2713aSLionel Sambuc UnresolvedSetIterator End, 333*f4a2713aSLionel Sambuc bool KnownDependent, 334*f4a2713aSLionel Sambuc bool KnownInstantiationDependent, 335*f4a2713aSLionel Sambuc bool KnownContainsUnexpandedParameterPack) 336*f4a2713aSLionel Sambuc : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent, 337*f4a2713aSLionel Sambuc KnownDependent, 338*f4a2713aSLionel Sambuc (KnownInstantiationDependent || 339*f4a2713aSLionel Sambuc NameInfo.isInstantiationDependent() || 340*f4a2713aSLionel Sambuc (QualifierLoc && 341*f4a2713aSLionel Sambuc QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), 342*f4a2713aSLionel Sambuc (KnownContainsUnexpandedParameterPack || 343*f4a2713aSLionel Sambuc NameInfo.containsUnexpandedParameterPack() || 344*f4a2713aSLionel Sambuc (QualifierLoc && 345*f4a2713aSLionel Sambuc QualifierLoc.getNestedNameSpecifier() 346*f4a2713aSLionel Sambuc ->containsUnexpandedParameterPack()))), 347*f4a2713aSLionel Sambuc NameInfo(NameInfo), QualifierLoc(QualifierLoc), 348*f4a2713aSLionel Sambuc Results(0), NumResults(End - Begin), 349*f4a2713aSLionel Sambuc HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()) 350*f4a2713aSLionel Sambuc { 351*f4a2713aSLionel Sambuc NumResults = End - Begin; 352*f4a2713aSLionel Sambuc if (NumResults) { 353*f4a2713aSLionel Sambuc // Determine whether this expression is type-dependent. 354*f4a2713aSLionel Sambuc for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) { 355*f4a2713aSLionel Sambuc if ((*I)->getDeclContext()->isDependentContext() || 356*f4a2713aSLionel Sambuc isa<UnresolvedUsingValueDecl>(*I)) { 357*f4a2713aSLionel Sambuc ExprBits.TypeDependent = true; 358*f4a2713aSLionel Sambuc ExprBits.ValueDependent = true; 359*f4a2713aSLionel Sambuc ExprBits.InstantiationDependent = true; 360*f4a2713aSLionel Sambuc } 361*f4a2713aSLionel Sambuc } 362*f4a2713aSLionel Sambuc 363*f4a2713aSLionel Sambuc Results = static_cast<DeclAccessPair *>( 364*f4a2713aSLionel Sambuc C.Allocate(sizeof(DeclAccessPair) * NumResults, 365*f4a2713aSLionel Sambuc llvm::alignOf<DeclAccessPair>())); 366*f4a2713aSLionel Sambuc memcpy(Results, &*Begin.getIterator(), 367*f4a2713aSLionel Sambuc NumResults * sizeof(DeclAccessPair)); 368*f4a2713aSLionel Sambuc } 369*f4a2713aSLionel Sambuc 370*f4a2713aSLionel Sambuc // If we have explicit template arguments, check for dependent 371*f4a2713aSLionel Sambuc // template arguments and whether they contain any unexpanded pack 372*f4a2713aSLionel Sambuc // expansions. 373*f4a2713aSLionel Sambuc if (TemplateArgs) { 374*f4a2713aSLionel Sambuc bool Dependent = false; 375*f4a2713aSLionel Sambuc bool InstantiationDependent = false; 376*f4a2713aSLionel Sambuc bool ContainsUnexpandedParameterPack = false; 377*f4a2713aSLionel Sambuc getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, 378*f4a2713aSLionel Sambuc Dependent, 379*f4a2713aSLionel Sambuc InstantiationDependent, 380*f4a2713aSLionel Sambuc ContainsUnexpandedParameterPack); 381*f4a2713aSLionel Sambuc 382*f4a2713aSLionel Sambuc if (Dependent) { 383*f4a2713aSLionel Sambuc ExprBits.TypeDependent = true; 384*f4a2713aSLionel Sambuc ExprBits.ValueDependent = true; 385*f4a2713aSLionel Sambuc } 386*f4a2713aSLionel Sambuc if (InstantiationDependent) 387*f4a2713aSLionel Sambuc ExprBits.InstantiationDependent = true; 388*f4a2713aSLionel Sambuc if (ContainsUnexpandedParameterPack) 389*f4a2713aSLionel Sambuc ExprBits.ContainsUnexpandedParameterPack = true; 390*f4a2713aSLionel Sambuc } else if (TemplateKWLoc.isValid()) { 391*f4a2713aSLionel Sambuc getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 392*f4a2713aSLionel Sambuc } 393*f4a2713aSLionel Sambuc 394*f4a2713aSLionel Sambuc if (isTypeDependent()) 395*f4a2713aSLionel Sambuc setType(C.DependentTy); 396*f4a2713aSLionel Sambuc } 397*f4a2713aSLionel Sambuc 398*f4a2713aSLionel Sambuc void OverloadExpr::initializeResults(const ASTContext &C, 399*f4a2713aSLionel Sambuc UnresolvedSetIterator Begin, 400*f4a2713aSLionel Sambuc UnresolvedSetIterator End) { 401*f4a2713aSLionel Sambuc assert(Results == 0 && "Results already initialized!"); 402*f4a2713aSLionel Sambuc NumResults = End - Begin; 403*f4a2713aSLionel Sambuc if (NumResults) { 404*f4a2713aSLionel Sambuc Results = static_cast<DeclAccessPair *>( 405*f4a2713aSLionel Sambuc C.Allocate(sizeof(DeclAccessPair) * NumResults, 406*f4a2713aSLionel Sambuc 407*f4a2713aSLionel Sambuc llvm::alignOf<DeclAccessPair>())); 408*f4a2713aSLionel Sambuc memcpy(Results, &*Begin.getIterator(), 409*f4a2713aSLionel Sambuc NumResults * sizeof(DeclAccessPair)); 410*f4a2713aSLionel Sambuc } 411*f4a2713aSLionel Sambuc } 412*f4a2713aSLionel Sambuc 413*f4a2713aSLionel Sambuc CXXRecordDecl *OverloadExpr::getNamingClass() const { 414*f4a2713aSLionel Sambuc if (isa<UnresolvedLookupExpr>(this)) 415*f4a2713aSLionel Sambuc return cast<UnresolvedLookupExpr>(this)->getNamingClass(); 416*f4a2713aSLionel Sambuc else 417*f4a2713aSLionel Sambuc return cast<UnresolvedMemberExpr>(this)->getNamingClass(); 418*f4a2713aSLionel Sambuc } 419*f4a2713aSLionel Sambuc 420*f4a2713aSLionel Sambuc // DependentScopeDeclRefExpr 421*f4a2713aSLionel Sambuc DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T, 422*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, 423*f4a2713aSLionel Sambuc SourceLocation TemplateKWLoc, 424*f4a2713aSLionel Sambuc const DeclarationNameInfo &NameInfo, 425*f4a2713aSLionel Sambuc const TemplateArgumentListInfo *Args) 426*f4a2713aSLionel Sambuc : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary, 427*f4a2713aSLionel Sambuc true, true, 428*f4a2713aSLionel Sambuc (NameInfo.isInstantiationDependent() || 429*f4a2713aSLionel Sambuc (QualifierLoc && 430*f4a2713aSLionel Sambuc QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())), 431*f4a2713aSLionel Sambuc (NameInfo.containsUnexpandedParameterPack() || 432*f4a2713aSLionel Sambuc (QualifierLoc && 433*f4a2713aSLionel Sambuc QualifierLoc.getNestedNameSpecifier() 434*f4a2713aSLionel Sambuc ->containsUnexpandedParameterPack()))), 435*f4a2713aSLionel Sambuc QualifierLoc(QualifierLoc), NameInfo(NameInfo), 436*f4a2713aSLionel Sambuc HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid()) 437*f4a2713aSLionel Sambuc { 438*f4a2713aSLionel Sambuc if (Args) { 439*f4a2713aSLionel Sambuc bool Dependent = true; 440*f4a2713aSLionel Sambuc bool InstantiationDependent = true; 441*f4a2713aSLionel Sambuc bool ContainsUnexpandedParameterPack 442*f4a2713aSLionel Sambuc = ExprBits.ContainsUnexpandedParameterPack; 443*f4a2713aSLionel Sambuc getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args, 444*f4a2713aSLionel Sambuc Dependent, 445*f4a2713aSLionel Sambuc InstantiationDependent, 446*f4a2713aSLionel Sambuc ContainsUnexpandedParameterPack); 447*f4a2713aSLionel Sambuc ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 448*f4a2713aSLionel Sambuc } else if (TemplateKWLoc.isValid()) { 449*f4a2713aSLionel Sambuc getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 450*f4a2713aSLionel Sambuc } 451*f4a2713aSLionel Sambuc } 452*f4a2713aSLionel Sambuc 453*f4a2713aSLionel Sambuc DependentScopeDeclRefExpr * 454*f4a2713aSLionel Sambuc DependentScopeDeclRefExpr::Create(const ASTContext &C, 455*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, 456*f4a2713aSLionel Sambuc SourceLocation TemplateKWLoc, 457*f4a2713aSLionel Sambuc const DeclarationNameInfo &NameInfo, 458*f4a2713aSLionel Sambuc const TemplateArgumentListInfo *Args) { 459*f4a2713aSLionel Sambuc assert(QualifierLoc && "should be created for dependent qualifiers"); 460*f4a2713aSLionel Sambuc std::size_t size = sizeof(DependentScopeDeclRefExpr); 461*f4a2713aSLionel Sambuc if (Args) 462*f4a2713aSLionel Sambuc size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size()); 463*f4a2713aSLionel Sambuc else if (TemplateKWLoc.isValid()) 464*f4a2713aSLionel Sambuc size += ASTTemplateKWAndArgsInfo::sizeFor(0); 465*f4a2713aSLionel Sambuc void *Mem = C.Allocate(size); 466*f4a2713aSLionel Sambuc return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc, 467*f4a2713aSLionel Sambuc TemplateKWLoc, NameInfo, Args); 468*f4a2713aSLionel Sambuc } 469*f4a2713aSLionel Sambuc 470*f4a2713aSLionel Sambuc DependentScopeDeclRefExpr * 471*f4a2713aSLionel Sambuc DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &C, 472*f4a2713aSLionel Sambuc bool HasTemplateKWAndArgsInfo, 473*f4a2713aSLionel Sambuc unsigned NumTemplateArgs) { 474*f4a2713aSLionel Sambuc std::size_t size = sizeof(DependentScopeDeclRefExpr); 475*f4a2713aSLionel Sambuc if (HasTemplateKWAndArgsInfo) 476*f4a2713aSLionel Sambuc size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); 477*f4a2713aSLionel Sambuc void *Mem = C.Allocate(size); 478*f4a2713aSLionel Sambuc DependentScopeDeclRefExpr *E 479*f4a2713aSLionel Sambuc = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(), 480*f4a2713aSLionel Sambuc SourceLocation(), 481*f4a2713aSLionel Sambuc DeclarationNameInfo(), 0); 482*f4a2713aSLionel Sambuc E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; 483*f4a2713aSLionel Sambuc return E; 484*f4a2713aSLionel Sambuc } 485*f4a2713aSLionel Sambuc 486*f4a2713aSLionel Sambuc SourceLocation CXXConstructExpr::getLocStart() const { 487*f4a2713aSLionel Sambuc if (isa<CXXTemporaryObjectExpr>(this)) 488*f4a2713aSLionel Sambuc return cast<CXXTemporaryObjectExpr>(this)->getLocStart(); 489*f4a2713aSLionel Sambuc return Loc; 490*f4a2713aSLionel Sambuc } 491*f4a2713aSLionel Sambuc 492*f4a2713aSLionel Sambuc SourceLocation CXXConstructExpr::getLocEnd() const { 493*f4a2713aSLionel Sambuc if (isa<CXXTemporaryObjectExpr>(this)) 494*f4a2713aSLionel Sambuc return cast<CXXTemporaryObjectExpr>(this)->getLocEnd(); 495*f4a2713aSLionel Sambuc 496*f4a2713aSLionel Sambuc if (ParenOrBraceRange.isValid()) 497*f4a2713aSLionel Sambuc return ParenOrBraceRange.getEnd(); 498*f4a2713aSLionel Sambuc 499*f4a2713aSLionel Sambuc SourceLocation End = Loc; 500*f4a2713aSLionel Sambuc for (unsigned I = getNumArgs(); I > 0; --I) { 501*f4a2713aSLionel Sambuc const Expr *Arg = getArg(I-1); 502*f4a2713aSLionel Sambuc if (!Arg->isDefaultArgument()) { 503*f4a2713aSLionel Sambuc SourceLocation NewEnd = Arg->getLocEnd(); 504*f4a2713aSLionel Sambuc if (NewEnd.isValid()) { 505*f4a2713aSLionel Sambuc End = NewEnd; 506*f4a2713aSLionel Sambuc break; 507*f4a2713aSLionel Sambuc } 508*f4a2713aSLionel Sambuc } 509*f4a2713aSLionel Sambuc } 510*f4a2713aSLionel Sambuc 511*f4a2713aSLionel Sambuc return End; 512*f4a2713aSLionel Sambuc } 513*f4a2713aSLionel Sambuc 514*f4a2713aSLionel Sambuc SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const { 515*f4a2713aSLionel Sambuc OverloadedOperatorKind Kind = getOperator(); 516*f4a2713aSLionel Sambuc if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { 517*f4a2713aSLionel Sambuc if (getNumArgs() == 1) 518*f4a2713aSLionel Sambuc // Prefix operator 519*f4a2713aSLionel Sambuc return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd()); 520*f4a2713aSLionel Sambuc else 521*f4a2713aSLionel Sambuc // Postfix operator 522*f4a2713aSLionel Sambuc return SourceRange(getArg(0)->getLocStart(), getOperatorLoc()); 523*f4a2713aSLionel Sambuc } else if (Kind == OO_Arrow) { 524*f4a2713aSLionel Sambuc return getArg(0)->getSourceRange(); 525*f4a2713aSLionel Sambuc } else if (Kind == OO_Call) { 526*f4a2713aSLionel Sambuc return SourceRange(getArg(0)->getLocStart(), getRParenLoc()); 527*f4a2713aSLionel Sambuc } else if (Kind == OO_Subscript) { 528*f4a2713aSLionel Sambuc return SourceRange(getArg(0)->getLocStart(), getRParenLoc()); 529*f4a2713aSLionel Sambuc } else if (getNumArgs() == 1) { 530*f4a2713aSLionel Sambuc return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd()); 531*f4a2713aSLionel Sambuc } else if (getNumArgs() == 2) { 532*f4a2713aSLionel Sambuc return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd()); 533*f4a2713aSLionel Sambuc } else { 534*f4a2713aSLionel Sambuc return getOperatorLoc(); 535*f4a2713aSLionel Sambuc } 536*f4a2713aSLionel Sambuc } 537*f4a2713aSLionel Sambuc 538*f4a2713aSLionel Sambuc Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { 539*f4a2713aSLionel Sambuc const Expr *Callee = getCallee()->IgnoreParens(); 540*f4a2713aSLionel Sambuc if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee)) 541*f4a2713aSLionel Sambuc return MemExpr->getBase(); 542*f4a2713aSLionel Sambuc if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee)) 543*f4a2713aSLionel Sambuc if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI) 544*f4a2713aSLionel Sambuc return BO->getLHS(); 545*f4a2713aSLionel Sambuc 546*f4a2713aSLionel Sambuc // FIXME: Will eventually need to cope with member pointers. 547*f4a2713aSLionel Sambuc return 0; 548*f4a2713aSLionel Sambuc } 549*f4a2713aSLionel Sambuc 550*f4a2713aSLionel Sambuc CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { 551*f4a2713aSLionel Sambuc if (const MemberExpr *MemExpr = 552*f4a2713aSLionel Sambuc dyn_cast<MemberExpr>(getCallee()->IgnoreParens())) 553*f4a2713aSLionel Sambuc return cast<CXXMethodDecl>(MemExpr->getMemberDecl()); 554*f4a2713aSLionel Sambuc 555*f4a2713aSLionel Sambuc // FIXME: Will eventually need to cope with member pointers. 556*f4a2713aSLionel Sambuc return 0; 557*f4a2713aSLionel Sambuc } 558*f4a2713aSLionel Sambuc 559*f4a2713aSLionel Sambuc 560*f4a2713aSLionel Sambuc CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const { 561*f4a2713aSLionel Sambuc Expr* ThisArg = getImplicitObjectArgument(); 562*f4a2713aSLionel Sambuc if (!ThisArg) 563*f4a2713aSLionel Sambuc return 0; 564*f4a2713aSLionel Sambuc 565*f4a2713aSLionel Sambuc if (ThisArg->getType()->isAnyPointerType()) 566*f4a2713aSLionel Sambuc return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl(); 567*f4a2713aSLionel Sambuc 568*f4a2713aSLionel Sambuc return ThisArg->getType()->getAsCXXRecordDecl(); 569*f4a2713aSLionel Sambuc } 570*f4a2713aSLionel Sambuc 571*f4a2713aSLionel Sambuc 572*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 573*f4a2713aSLionel Sambuc // Named casts 574*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 575*f4a2713aSLionel Sambuc 576*f4a2713aSLionel Sambuc /// getCastName - Get the name of the C++ cast being used, e.g., 577*f4a2713aSLionel Sambuc /// "static_cast", "dynamic_cast", "reinterpret_cast", or 578*f4a2713aSLionel Sambuc /// "const_cast". The returned pointer must not be freed. 579*f4a2713aSLionel Sambuc const char *CXXNamedCastExpr::getCastName() const { 580*f4a2713aSLionel Sambuc switch (getStmtClass()) { 581*f4a2713aSLionel Sambuc case CXXStaticCastExprClass: return "static_cast"; 582*f4a2713aSLionel Sambuc case CXXDynamicCastExprClass: return "dynamic_cast"; 583*f4a2713aSLionel Sambuc case CXXReinterpretCastExprClass: return "reinterpret_cast"; 584*f4a2713aSLionel Sambuc case CXXConstCastExprClass: return "const_cast"; 585*f4a2713aSLionel Sambuc default: return "<invalid cast>"; 586*f4a2713aSLionel Sambuc } 587*f4a2713aSLionel Sambuc } 588*f4a2713aSLionel Sambuc 589*f4a2713aSLionel Sambuc CXXStaticCastExpr *CXXStaticCastExpr::Create(const ASTContext &C, QualType T, 590*f4a2713aSLionel Sambuc ExprValueKind VK, 591*f4a2713aSLionel Sambuc CastKind K, Expr *Op, 592*f4a2713aSLionel Sambuc const CXXCastPath *BasePath, 593*f4a2713aSLionel Sambuc TypeSourceInfo *WrittenTy, 594*f4a2713aSLionel Sambuc SourceLocation L, 595*f4a2713aSLionel Sambuc SourceLocation RParenLoc, 596*f4a2713aSLionel Sambuc SourceRange AngleBrackets) { 597*f4a2713aSLionel Sambuc unsigned PathSize = (BasePath ? BasePath->size() : 0); 598*f4a2713aSLionel Sambuc void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr) 599*f4a2713aSLionel Sambuc + PathSize * sizeof(CXXBaseSpecifier*)); 600*f4a2713aSLionel Sambuc CXXStaticCastExpr *E = 601*f4a2713aSLionel Sambuc new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, 602*f4a2713aSLionel Sambuc RParenLoc, AngleBrackets); 603*f4a2713aSLionel Sambuc if (PathSize) E->setCastPath(*BasePath); 604*f4a2713aSLionel Sambuc return E; 605*f4a2713aSLionel Sambuc } 606*f4a2713aSLionel Sambuc 607*f4a2713aSLionel Sambuc CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C, 608*f4a2713aSLionel Sambuc unsigned PathSize) { 609*f4a2713aSLionel Sambuc void *Buffer = 610*f4a2713aSLionel Sambuc C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 611*f4a2713aSLionel Sambuc return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize); 612*f4a2713aSLionel Sambuc } 613*f4a2713aSLionel Sambuc 614*f4a2713aSLionel Sambuc CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T, 615*f4a2713aSLionel Sambuc ExprValueKind VK, 616*f4a2713aSLionel Sambuc CastKind K, Expr *Op, 617*f4a2713aSLionel Sambuc const CXXCastPath *BasePath, 618*f4a2713aSLionel Sambuc TypeSourceInfo *WrittenTy, 619*f4a2713aSLionel Sambuc SourceLocation L, 620*f4a2713aSLionel Sambuc SourceLocation RParenLoc, 621*f4a2713aSLionel Sambuc SourceRange AngleBrackets) { 622*f4a2713aSLionel Sambuc unsigned PathSize = (BasePath ? BasePath->size() : 0); 623*f4a2713aSLionel Sambuc void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr) 624*f4a2713aSLionel Sambuc + PathSize * sizeof(CXXBaseSpecifier*)); 625*f4a2713aSLionel Sambuc CXXDynamicCastExpr *E = 626*f4a2713aSLionel Sambuc new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, 627*f4a2713aSLionel Sambuc RParenLoc, AngleBrackets); 628*f4a2713aSLionel Sambuc if (PathSize) E->setCastPath(*BasePath); 629*f4a2713aSLionel Sambuc return E; 630*f4a2713aSLionel Sambuc } 631*f4a2713aSLionel Sambuc 632*f4a2713aSLionel Sambuc CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C, 633*f4a2713aSLionel Sambuc unsigned PathSize) { 634*f4a2713aSLionel Sambuc void *Buffer = 635*f4a2713aSLionel Sambuc C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 636*f4a2713aSLionel Sambuc return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize); 637*f4a2713aSLionel Sambuc } 638*f4a2713aSLionel Sambuc 639*f4a2713aSLionel Sambuc /// isAlwaysNull - Return whether the result of the dynamic_cast is proven 640*f4a2713aSLionel Sambuc /// to always be null. For example: 641*f4a2713aSLionel Sambuc /// 642*f4a2713aSLionel Sambuc /// struct A { }; 643*f4a2713aSLionel Sambuc /// struct B final : A { }; 644*f4a2713aSLionel Sambuc /// struct C { }; 645*f4a2713aSLionel Sambuc /// 646*f4a2713aSLionel Sambuc /// C *f(B* b) { return dynamic_cast<C*>(b); } 647*f4a2713aSLionel Sambuc bool CXXDynamicCastExpr::isAlwaysNull() const 648*f4a2713aSLionel Sambuc { 649*f4a2713aSLionel Sambuc QualType SrcType = getSubExpr()->getType(); 650*f4a2713aSLionel Sambuc QualType DestType = getType(); 651*f4a2713aSLionel Sambuc 652*f4a2713aSLionel Sambuc if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) { 653*f4a2713aSLionel Sambuc SrcType = SrcPTy->getPointeeType(); 654*f4a2713aSLionel Sambuc DestType = DestType->castAs<PointerType>()->getPointeeType(); 655*f4a2713aSLionel Sambuc } 656*f4a2713aSLionel Sambuc 657*f4a2713aSLionel Sambuc if (DestType->isVoidType()) 658*f4a2713aSLionel Sambuc return false; 659*f4a2713aSLionel Sambuc 660*f4a2713aSLionel Sambuc const CXXRecordDecl *SrcRD = 661*f4a2713aSLionel Sambuc cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl()); 662*f4a2713aSLionel Sambuc 663*f4a2713aSLionel Sambuc if (!SrcRD->hasAttr<FinalAttr>()) 664*f4a2713aSLionel Sambuc return false; 665*f4a2713aSLionel Sambuc 666*f4a2713aSLionel Sambuc const CXXRecordDecl *DestRD = 667*f4a2713aSLionel Sambuc cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl()); 668*f4a2713aSLionel Sambuc 669*f4a2713aSLionel Sambuc return !DestRD->isDerivedFrom(SrcRD); 670*f4a2713aSLionel Sambuc } 671*f4a2713aSLionel Sambuc 672*f4a2713aSLionel Sambuc CXXReinterpretCastExpr * 673*f4a2713aSLionel Sambuc CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T, 674*f4a2713aSLionel Sambuc ExprValueKind VK, CastKind K, Expr *Op, 675*f4a2713aSLionel Sambuc const CXXCastPath *BasePath, 676*f4a2713aSLionel Sambuc TypeSourceInfo *WrittenTy, SourceLocation L, 677*f4a2713aSLionel Sambuc SourceLocation RParenLoc, 678*f4a2713aSLionel Sambuc SourceRange AngleBrackets) { 679*f4a2713aSLionel Sambuc unsigned PathSize = (BasePath ? BasePath->size() : 0); 680*f4a2713aSLionel Sambuc void *Buffer = 681*f4a2713aSLionel Sambuc C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 682*f4a2713aSLionel Sambuc CXXReinterpretCastExpr *E = 683*f4a2713aSLionel Sambuc new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, 684*f4a2713aSLionel Sambuc RParenLoc, AngleBrackets); 685*f4a2713aSLionel Sambuc if (PathSize) E->setCastPath(*BasePath); 686*f4a2713aSLionel Sambuc return E; 687*f4a2713aSLionel Sambuc } 688*f4a2713aSLionel Sambuc 689*f4a2713aSLionel Sambuc CXXReinterpretCastExpr * 690*f4a2713aSLionel Sambuc CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { 691*f4a2713aSLionel Sambuc void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr) 692*f4a2713aSLionel Sambuc + PathSize * sizeof(CXXBaseSpecifier*)); 693*f4a2713aSLionel Sambuc return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize); 694*f4a2713aSLionel Sambuc } 695*f4a2713aSLionel Sambuc 696*f4a2713aSLionel Sambuc CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T, 697*f4a2713aSLionel Sambuc ExprValueKind VK, Expr *Op, 698*f4a2713aSLionel Sambuc TypeSourceInfo *WrittenTy, 699*f4a2713aSLionel Sambuc SourceLocation L, 700*f4a2713aSLionel Sambuc SourceLocation RParenLoc, 701*f4a2713aSLionel Sambuc SourceRange AngleBrackets) { 702*f4a2713aSLionel Sambuc return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets); 703*f4a2713aSLionel Sambuc } 704*f4a2713aSLionel Sambuc 705*f4a2713aSLionel Sambuc CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) { 706*f4a2713aSLionel Sambuc return new (C) CXXConstCastExpr(EmptyShell()); 707*f4a2713aSLionel Sambuc } 708*f4a2713aSLionel Sambuc 709*f4a2713aSLionel Sambuc CXXFunctionalCastExpr * 710*f4a2713aSLionel Sambuc CXXFunctionalCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK, 711*f4a2713aSLionel Sambuc TypeSourceInfo *Written, CastKind K, Expr *Op, 712*f4a2713aSLionel Sambuc const CXXCastPath *BasePath, 713*f4a2713aSLionel Sambuc SourceLocation L, SourceLocation R) { 714*f4a2713aSLionel Sambuc unsigned PathSize = (BasePath ? BasePath->size() : 0); 715*f4a2713aSLionel Sambuc void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) 716*f4a2713aSLionel Sambuc + PathSize * sizeof(CXXBaseSpecifier*)); 717*f4a2713aSLionel Sambuc CXXFunctionalCastExpr *E = 718*f4a2713aSLionel Sambuc new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R); 719*f4a2713aSLionel Sambuc if (PathSize) E->setCastPath(*BasePath); 720*f4a2713aSLionel Sambuc return E; 721*f4a2713aSLionel Sambuc } 722*f4a2713aSLionel Sambuc 723*f4a2713aSLionel Sambuc CXXFunctionalCastExpr * 724*f4a2713aSLionel Sambuc CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) { 725*f4a2713aSLionel Sambuc void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr) 726*f4a2713aSLionel Sambuc + PathSize * sizeof(CXXBaseSpecifier*)); 727*f4a2713aSLionel Sambuc return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize); 728*f4a2713aSLionel Sambuc } 729*f4a2713aSLionel Sambuc 730*f4a2713aSLionel Sambuc SourceLocation CXXFunctionalCastExpr::getLocStart() const { 731*f4a2713aSLionel Sambuc return getTypeInfoAsWritten()->getTypeLoc().getLocStart(); 732*f4a2713aSLionel Sambuc } 733*f4a2713aSLionel Sambuc 734*f4a2713aSLionel Sambuc SourceLocation CXXFunctionalCastExpr::getLocEnd() const { 735*f4a2713aSLionel Sambuc return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getLocEnd(); 736*f4a2713aSLionel Sambuc } 737*f4a2713aSLionel Sambuc 738*f4a2713aSLionel Sambuc UserDefinedLiteral::LiteralOperatorKind 739*f4a2713aSLionel Sambuc UserDefinedLiteral::getLiteralOperatorKind() const { 740*f4a2713aSLionel Sambuc if (getNumArgs() == 0) 741*f4a2713aSLionel Sambuc return LOK_Template; 742*f4a2713aSLionel Sambuc if (getNumArgs() == 2) 743*f4a2713aSLionel Sambuc return LOK_String; 744*f4a2713aSLionel Sambuc 745*f4a2713aSLionel Sambuc assert(getNumArgs() == 1 && "unexpected #args in literal operator call"); 746*f4a2713aSLionel Sambuc QualType ParamTy = 747*f4a2713aSLionel Sambuc cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType(); 748*f4a2713aSLionel Sambuc if (ParamTy->isPointerType()) 749*f4a2713aSLionel Sambuc return LOK_Raw; 750*f4a2713aSLionel Sambuc if (ParamTy->isAnyCharacterType()) 751*f4a2713aSLionel Sambuc return LOK_Character; 752*f4a2713aSLionel Sambuc if (ParamTy->isIntegerType()) 753*f4a2713aSLionel Sambuc return LOK_Integer; 754*f4a2713aSLionel Sambuc if (ParamTy->isFloatingType()) 755*f4a2713aSLionel Sambuc return LOK_Floating; 756*f4a2713aSLionel Sambuc 757*f4a2713aSLionel Sambuc llvm_unreachable("unknown kind of literal operator"); 758*f4a2713aSLionel Sambuc } 759*f4a2713aSLionel Sambuc 760*f4a2713aSLionel Sambuc Expr *UserDefinedLiteral::getCookedLiteral() { 761*f4a2713aSLionel Sambuc #ifndef NDEBUG 762*f4a2713aSLionel Sambuc LiteralOperatorKind LOK = getLiteralOperatorKind(); 763*f4a2713aSLionel Sambuc assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal"); 764*f4a2713aSLionel Sambuc #endif 765*f4a2713aSLionel Sambuc return getArg(0); 766*f4a2713aSLionel Sambuc } 767*f4a2713aSLionel Sambuc 768*f4a2713aSLionel Sambuc const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const { 769*f4a2713aSLionel Sambuc return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier(); 770*f4a2713aSLionel Sambuc } 771*f4a2713aSLionel Sambuc 772*f4a2713aSLionel Sambuc CXXDefaultArgExpr * 773*f4a2713aSLionel Sambuc CXXDefaultArgExpr::Create(const ASTContext &C, SourceLocation Loc, 774*f4a2713aSLionel Sambuc ParmVarDecl *Param, Expr *SubExpr) { 775*f4a2713aSLionel Sambuc void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *)); 776*f4a2713aSLionel Sambuc return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, 777*f4a2713aSLionel Sambuc SubExpr); 778*f4a2713aSLionel Sambuc } 779*f4a2713aSLionel Sambuc 780*f4a2713aSLionel Sambuc CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, 781*f4a2713aSLionel Sambuc FieldDecl *Field, QualType T) 782*f4a2713aSLionel Sambuc : Expr(CXXDefaultInitExprClass, T.getNonLValueExprType(C), 783*f4a2713aSLionel Sambuc T->isLValueReferenceType() ? VK_LValue : T->isRValueReferenceType() 784*f4a2713aSLionel Sambuc ? VK_XValue 785*f4a2713aSLionel Sambuc : VK_RValue, 786*f4a2713aSLionel Sambuc /*FIXME*/ OK_Ordinary, false, false, false, false), 787*f4a2713aSLionel Sambuc Field(Field), Loc(Loc) { 788*f4a2713aSLionel Sambuc assert(Field->hasInClassInitializer()); 789*f4a2713aSLionel Sambuc } 790*f4a2713aSLionel Sambuc 791*f4a2713aSLionel Sambuc CXXTemporary *CXXTemporary::Create(const ASTContext &C, 792*f4a2713aSLionel Sambuc const CXXDestructorDecl *Destructor) { 793*f4a2713aSLionel Sambuc return new (C) CXXTemporary(Destructor); 794*f4a2713aSLionel Sambuc } 795*f4a2713aSLionel Sambuc 796*f4a2713aSLionel Sambuc CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C, 797*f4a2713aSLionel Sambuc CXXTemporary *Temp, 798*f4a2713aSLionel Sambuc Expr* SubExpr) { 799*f4a2713aSLionel Sambuc assert((SubExpr->getType()->isRecordType() || 800*f4a2713aSLionel Sambuc SubExpr->getType()->isArrayType()) && 801*f4a2713aSLionel Sambuc "Expression bound to a temporary must have record or array type!"); 802*f4a2713aSLionel Sambuc 803*f4a2713aSLionel Sambuc return new (C) CXXBindTemporaryExpr(Temp, SubExpr); 804*f4a2713aSLionel Sambuc } 805*f4a2713aSLionel Sambuc 806*f4a2713aSLionel Sambuc CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(const ASTContext &C, 807*f4a2713aSLionel Sambuc CXXConstructorDecl *Cons, 808*f4a2713aSLionel Sambuc TypeSourceInfo *Type, 809*f4a2713aSLionel Sambuc ArrayRef<Expr*> Args, 810*f4a2713aSLionel Sambuc SourceRange ParenOrBraceRange, 811*f4a2713aSLionel Sambuc bool HadMultipleCandidates, 812*f4a2713aSLionel Sambuc bool ListInitialization, 813*f4a2713aSLionel Sambuc bool ZeroInitialization) 814*f4a2713aSLionel Sambuc : CXXConstructExpr(C, CXXTemporaryObjectExprClass, 815*f4a2713aSLionel Sambuc Type->getType().getNonReferenceType(), 816*f4a2713aSLionel Sambuc Type->getTypeLoc().getBeginLoc(), 817*f4a2713aSLionel Sambuc Cons, false, Args, 818*f4a2713aSLionel Sambuc HadMultipleCandidates, 819*f4a2713aSLionel Sambuc ListInitialization, ZeroInitialization, 820*f4a2713aSLionel Sambuc CXXConstructExpr::CK_Complete, ParenOrBraceRange), 821*f4a2713aSLionel Sambuc Type(Type) { 822*f4a2713aSLionel Sambuc } 823*f4a2713aSLionel Sambuc 824*f4a2713aSLionel Sambuc SourceLocation CXXTemporaryObjectExpr::getLocStart() const { 825*f4a2713aSLionel Sambuc return Type->getTypeLoc().getBeginLoc(); 826*f4a2713aSLionel Sambuc } 827*f4a2713aSLionel Sambuc 828*f4a2713aSLionel Sambuc SourceLocation CXXTemporaryObjectExpr::getLocEnd() const { 829*f4a2713aSLionel Sambuc SourceLocation Loc = getParenOrBraceRange().getEnd(); 830*f4a2713aSLionel Sambuc if (Loc.isInvalid() && getNumArgs()) 831*f4a2713aSLionel Sambuc Loc = getArg(getNumArgs()-1)->getLocEnd(); 832*f4a2713aSLionel Sambuc return Loc; 833*f4a2713aSLionel Sambuc } 834*f4a2713aSLionel Sambuc 835*f4a2713aSLionel Sambuc CXXConstructExpr *CXXConstructExpr::Create(const ASTContext &C, QualType T, 836*f4a2713aSLionel Sambuc SourceLocation Loc, 837*f4a2713aSLionel Sambuc CXXConstructorDecl *D, bool Elidable, 838*f4a2713aSLionel Sambuc ArrayRef<Expr*> Args, 839*f4a2713aSLionel Sambuc bool HadMultipleCandidates, 840*f4a2713aSLionel Sambuc bool ListInitialization, 841*f4a2713aSLionel Sambuc bool ZeroInitialization, 842*f4a2713aSLionel Sambuc ConstructionKind ConstructKind, 843*f4a2713aSLionel Sambuc SourceRange ParenOrBraceRange) { 844*f4a2713aSLionel Sambuc return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D, 845*f4a2713aSLionel Sambuc Elidable, Args, 846*f4a2713aSLionel Sambuc HadMultipleCandidates, ListInitialization, 847*f4a2713aSLionel Sambuc ZeroInitialization, ConstructKind, 848*f4a2713aSLionel Sambuc ParenOrBraceRange); 849*f4a2713aSLionel Sambuc } 850*f4a2713aSLionel Sambuc 851*f4a2713aSLionel Sambuc CXXConstructExpr::CXXConstructExpr(const ASTContext &C, StmtClass SC, 852*f4a2713aSLionel Sambuc QualType T, SourceLocation Loc, 853*f4a2713aSLionel Sambuc CXXConstructorDecl *D, bool elidable, 854*f4a2713aSLionel Sambuc ArrayRef<Expr*> args, 855*f4a2713aSLionel Sambuc bool HadMultipleCandidates, 856*f4a2713aSLionel Sambuc bool ListInitialization, 857*f4a2713aSLionel Sambuc bool ZeroInitialization, 858*f4a2713aSLionel Sambuc ConstructionKind ConstructKind, 859*f4a2713aSLionel Sambuc SourceRange ParenOrBraceRange) 860*f4a2713aSLionel Sambuc : Expr(SC, T, VK_RValue, OK_Ordinary, 861*f4a2713aSLionel Sambuc T->isDependentType(), T->isDependentType(), 862*f4a2713aSLionel Sambuc T->isInstantiationDependentType(), 863*f4a2713aSLionel Sambuc T->containsUnexpandedParameterPack()), 864*f4a2713aSLionel Sambuc Constructor(D), Loc(Loc), ParenOrBraceRange(ParenOrBraceRange), 865*f4a2713aSLionel Sambuc NumArgs(args.size()), 866*f4a2713aSLionel Sambuc Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates), 867*f4a2713aSLionel Sambuc ListInitialization(ListInitialization), 868*f4a2713aSLionel Sambuc ZeroInitialization(ZeroInitialization), 869*f4a2713aSLionel Sambuc ConstructKind(ConstructKind), Args(0) 870*f4a2713aSLionel Sambuc { 871*f4a2713aSLionel Sambuc if (NumArgs) { 872*f4a2713aSLionel Sambuc Args = new (C) Stmt*[args.size()]; 873*f4a2713aSLionel Sambuc 874*f4a2713aSLionel Sambuc for (unsigned i = 0; i != args.size(); ++i) { 875*f4a2713aSLionel Sambuc assert(args[i] && "NULL argument in CXXConstructExpr"); 876*f4a2713aSLionel Sambuc 877*f4a2713aSLionel Sambuc if (args[i]->isValueDependent()) 878*f4a2713aSLionel Sambuc ExprBits.ValueDependent = true; 879*f4a2713aSLionel Sambuc if (args[i]->isInstantiationDependent()) 880*f4a2713aSLionel Sambuc ExprBits.InstantiationDependent = true; 881*f4a2713aSLionel Sambuc if (args[i]->containsUnexpandedParameterPack()) 882*f4a2713aSLionel Sambuc ExprBits.ContainsUnexpandedParameterPack = true; 883*f4a2713aSLionel Sambuc 884*f4a2713aSLionel Sambuc Args[i] = args[i]; 885*f4a2713aSLionel Sambuc } 886*f4a2713aSLionel Sambuc } 887*f4a2713aSLionel Sambuc } 888*f4a2713aSLionel Sambuc 889*f4a2713aSLionel Sambuc LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit, 890*f4a2713aSLionel Sambuc LambdaCaptureKind Kind, VarDecl *Var, 891*f4a2713aSLionel Sambuc SourceLocation EllipsisLoc) 892*f4a2713aSLionel Sambuc : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) 893*f4a2713aSLionel Sambuc { 894*f4a2713aSLionel Sambuc unsigned Bits = 0; 895*f4a2713aSLionel Sambuc if (Implicit) 896*f4a2713aSLionel Sambuc Bits |= Capture_Implicit; 897*f4a2713aSLionel Sambuc 898*f4a2713aSLionel Sambuc switch (Kind) { 899*f4a2713aSLionel Sambuc case LCK_This: 900*f4a2713aSLionel Sambuc assert(Var == 0 && "'this' capture cannot have a variable!"); 901*f4a2713aSLionel Sambuc break; 902*f4a2713aSLionel Sambuc 903*f4a2713aSLionel Sambuc case LCK_ByCopy: 904*f4a2713aSLionel Sambuc Bits |= Capture_ByCopy; 905*f4a2713aSLionel Sambuc // Fall through 906*f4a2713aSLionel Sambuc case LCK_ByRef: 907*f4a2713aSLionel Sambuc assert(Var && "capture must have a variable!"); 908*f4a2713aSLionel Sambuc break; 909*f4a2713aSLionel Sambuc } 910*f4a2713aSLionel Sambuc DeclAndBits.setInt(Bits); 911*f4a2713aSLionel Sambuc } 912*f4a2713aSLionel Sambuc 913*f4a2713aSLionel Sambuc LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const { 914*f4a2713aSLionel Sambuc Decl *D = DeclAndBits.getPointer(); 915*f4a2713aSLionel Sambuc if (!D) 916*f4a2713aSLionel Sambuc return LCK_This; 917*f4a2713aSLionel Sambuc 918*f4a2713aSLionel Sambuc return (DeclAndBits.getInt() & Capture_ByCopy) ? LCK_ByCopy : LCK_ByRef; 919*f4a2713aSLionel Sambuc } 920*f4a2713aSLionel Sambuc 921*f4a2713aSLionel Sambuc LambdaExpr::LambdaExpr(QualType T, 922*f4a2713aSLionel Sambuc SourceRange IntroducerRange, 923*f4a2713aSLionel Sambuc LambdaCaptureDefault CaptureDefault, 924*f4a2713aSLionel Sambuc SourceLocation CaptureDefaultLoc, 925*f4a2713aSLionel Sambuc ArrayRef<Capture> Captures, 926*f4a2713aSLionel Sambuc bool ExplicitParams, 927*f4a2713aSLionel Sambuc bool ExplicitResultType, 928*f4a2713aSLionel Sambuc ArrayRef<Expr *> CaptureInits, 929*f4a2713aSLionel Sambuc ArrayRef<VarDecl *> ArrayIndexVars, 930*f4a2713aSLionel Sambuc ArrayRef<unsigned> ArrayIndexStarts, 931*f4a2713aSLionel Sambuc SourceLocation ClosingBrace, 932*f4a2713aSLionel Sambuc bool ContainsUnexpandedParameterPack) 933*f4a2713aSLionel Sambuc : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, 934*f4a2713aSLionel Sambuc T->isDependentType(), T->isDependentType(), T->isDependentType(), 935*f4a2713aSLionel Sambuc ContainsUnexpandedParameterPack), 936*f4a2713aSLionel Sambuc IntroducerRange(IntroducerRange), 937*f4a2713aSLionel Sambuc CaptureDefaultLoc(CaptureDefaultLoc), 938*f4a2713aSLionel Sambuc NumCaptures(Captures.size()), 939*f4a2713aSLionel Sambuc CaptureDefault(CaptureDefault), 940*f4a2713aSLionel Sambuc ExplicitParams(ExplicitParams), 941*f4a2713aSLionel Sambuc ExplicitResultType(ExplicitResultType), 942*f4a2713aSLionel Sambuc ClosingBrace(ClosingBrace) 943*f4a2713aSLionel Sambuc { 944*f4a2713aSLionel Sambuc assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments"); 945*f4a2713aSLionel Sambuc CXXRecordDecl *Class = getLambdaClass(); 946*f4a2713aSLionel Sambuc CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData(); 947*f4a2713aSLionel Sambuc 948*f4a2713aSLionel Sambuc // FIXME: Propagate "has unexpanded parameter pack" bit. 949*f4a2713aSLionel Sambuc 950*f4a2713aSLionel Sambuc // Copy captures. 951*f4a2713aSLionel Sambuc const ASTContext &Context = Class->getASTContext(); 952*f4a2713aSLionel Sambuc Data.NumCaptures = NumCaptures; 953*f4a2713aSLionel Sambuc Data.NumExplicitCaptures = 0; 954*f4a2713aSLionel Sambuc Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures); 955*f4a2713aSLionel Sambuc Capture *ToCapture = Data.Captures; 956*f4a2713aSLionel Sambuc for (unsigned I = 0, N = Captures.size(); I != N; ++I) { 957*f4a2713aSLionel Sambuc if (Captures[I].isExplicit()) 958*f4a2713aSLionel Sambuc ++Data.NumExplicitCaptures; 959*f4a2713aSLionel Sambuc 960*f4a2713aSLionel Sambuc *ToCapture++ = Captures[I]; 961*f4a2713aSLionel Sambuc } 962*f4a2713aSLionel Sambuc 963*f4a2713aSLionel Sambuc // Copy initialization expressions for the non-static data members. 964*f4a2713aSLionel Sambuc Stmt **Stored = getStoredStmts(); 965*f4a2713aSLionel Sambuc for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I) 966*f4a2713aSLionel Sambuc *Stored++ = CaptureInits[I]; 967*f4a2713aSLionel Sambuc 968*f4a2713aSLionel Sambuc // Copy the body of the lambda. 969*f4a2713aSLionel Sambuc *Stored++ = getCallOperator()->getBody(); 970*f4a2713aSLionel Sambuc 971*f4a2713aSLionel Sambuc // Copy the array index variables, if any. 972*f4a2713aSLionel Sambuc HasArrayIndexVars = !ArrayIndexVars.empty(); 973*f4a2713aSLionel Sambuc if (HasArrayIndexVars) { 974*f4a2713aSLionel Sambuc assert(ArrayIndexStarts.size() == NumCaptures); 975*f4a2713aSLionel Sambuc memcpy(getArrayIndexVars(), ArrayIndexVars.data(), 976*f4a2713aSLionel Sambuc sizeof(VarDecl *) * ArrayIndexVars.size()); 977*f4a2713aSLionel Sambuc memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(), 978*f4a2713aSLionel Sambuc sizeof(unsigned) * Captures.size()); 979*f4a2713aSLionel Sambuc getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size(); 980*f4a2713aSLionel Sambuc } 981*f4a2713aSLionel Sambuc } 982*f4a2713aSLionel Sambuc 983*f4a2713aSLionel Sambuc LambdaExpr *LambdaExpr::Create(const ASTContext &Context, 984*f4a2713aSLionel Sambuc CXXRecordDecl *Class, 985*f4a2713aSLionel Sambuc SourceRange IntroducerRange, 986*f4a2713aSLionel Sambuc LambdaCaptureDefault CaptureDefault, 987*f4a2713aSLionel Sambuc SourceLocation CaptureDefaultLoc, 988*f4a2713aSLionel Sambuc ArrayRef<Capture> Captures, 989*f4a2713aSLionel Sambuc bool ExplicitParams, 990*f4a2713aSLionel Sambuc bool ExplicitResultType, 991*f4a2713aSLionel Sambuc ArrayRef<Expr *> CaptureInits, 992*f4a2713aSLionel Sambuc ArrayRef<VarDecl *> ArrayIndexVars, 993*f4a2713aSLionel Sambuc ArrayRef<unsigned> ArrayIndexStarts, 994*f4a2713aSLionel Sambuc SourceLocation ClosingBrace, 995*f4a2713aSLionel Sambuc bool ContainsUnexpandedParameterPack) { 996*f4a2713aSLionel Sambuc // Determine the type of the expression (i.e., the type of the 997*f4a2713aSLionel Sambuc // function object we're creating). 998*f4a2713aSLionel Sambuc QualType T = Context.getTypeDeclType(Class); 999*f4a2713aSLionel Sambuc 1000*f4a2713aSLionel Sambuc unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1); 1001*f4a2713aSLionel Sambuc if (!ArrayIndexVars.empty()) { 1002*f4a2713aSLionel Sambuc Size += sizeof(unsigned) * (Captures.size() + 1); 1003*f4a2713aSLionel Sambuc // Realign for following VarDecl array. 1004*f4a2713aSLionel Sambuc Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>()); 1005*f4a2713aSLionel Sambuc Size += sizeof(VarDecl *) * ArrayIndexVars.size(); 1006*f4a2713aSLionel Sambuc } 1007*f4a2713aSLionel Sambuc void *Mem = Context.Allocate(Size); 1008*f4a2713aSLionel Sambuc return new (Mem) LambdaExpr(T, IntroducerRange, 1009*f4a2713aSLionel Sambuc CaptureDefault, CaptureDefaultLoc, Captures, 1010*f4a2713aSLionel Sambuc ExplicitParams, ExplicitResultType, 1011*f4a2713aSLionel Sambuc CaptureInits, ArrayIndexVars, ArrayIndexStarts, 1012*f4a2713aSLionel Sambuc ClosingBrace, ContainsUnexpandedParameterPack); 1013*f4a2713aSLionel Sambuc } 1014*f4a2713aSLionel Sambuc 1015*f4a2713aSLionel Sambuc LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C, 1016*f4a2713aSLionel Sambuc unsigned NumCaptures, 1017*f4a2713aSLionel Sambuc unsigned NumArrayIndexVars) { 1018*f4a2713aSLionel Sambuc unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1); 1019*f4a2713aSLionel Sambuc if (NumArrayIndexVars) 1020*f4a2713aSLionel Sambuc Size += sizeof(VarDecl) * NumArrayIndexVars 1021*f4a2713aSLionel Sambuc + sizeof(unsigned) * (NumCaptures + 1); 1022*f4a2713aSLionel Sambuc void *Mem = C.Allocate(Size); 1023*f4a2713aSLionel Sambuc return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0); 1024*f4a2713aSLionel Sambuc } 1025*f4a2713aSLionel Sambuc 1026*f4a2713aSLionel Sambuc LambdaExpr::capture_iterator LambdaExpr::capture_begin() const { 1027*f4a2713aSLionel Sambuc return getLambdaClass()->getLambdaData().Captures; 1028*f4a2713aSLionel Sambuc } 1029*f4a2713aSLionel Sambuc 1030*f4a2713aSLionel Sambuc LambdaExpr::capture_iterator LambdaExpr::capture_end() const { 1031*f4a2713aSLionel Sambuc return capture_begin() + NumCaptures; 1032*f4a2713aSLionel Sambuc } 1033*f4a2713aSLionel Sambuc 1034*f4a2713aSLionel Sambuc LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const { 1035*f4a2713aSLionel Sambuc return capture_begin(); 1036*f4a2713aSLionel Sambuc } 1037*f4a2713aSLionel Sambuc 1038*f4a2713aSLionel Sambuc LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const { 1039*f4a2713aSLionel Sambuc struct CXXRecordDecl::LambdaDefinitionData &Data 1040*f4a2713aSLionel Sambuc = getLambdaClass()->getLambdaData(); 1041*f4a2713aSLionel Sambuc return Data.Captures + Data.NumExplicitCaptures; 1042*f4a2713aSLionel Sambuc } 1043*f4a2713aSLionel Sambuc 1044*f4a2713aSLionel Sambuc LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const { 1045*f4a2713aSLionel Sambuc return explicit_capture_end(); 1046*f4a2713aSLionel Sambuc } 1047*f4a2713aSLionel Sambuc 1048*f4a2713aSLionel Sambuc LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const { 1049*f4a2713aSLionel Sambuc return capture_end(); 1050*f4a2713aSLionel Sambuc } 1051*f4a2713aSLionel Sambuc 1052*f4a2713aSLionel Sambuc ArrayRef<VarDecl *> 1053*f4a2713aSLionel Sambuc LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const { 1054*f4a2713aSLionel Sambuc assert(HasArrayIndexVars && "No array index-var data?"); 1055*f4a2713aSLionel Sambuc 1056*f4a2713aSLionel Sambuc unsigned Index = Iter - capture_init_begin(); 1057*f4a2713aSLionel Sambuc assert(Index < getLambdaClass()->getLambdaData().NumCaptures && 1058*f4a2713aSLionel Sambuc "Capture index out-of-range"); 1059*f4a2713aSLionel Sambuc VarDecl **IndexVars = getArrayIndexVars(); 1060*f4a2713aSLionel Sambuc unsigned *IndexStarts = getArrayIndexStarts(); 1061*f4a2713aSLionel Sambuc return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index], 1062*f4a2713aSLionel Sambuc IndexVars + IndexStarts[Index + 1]); 1063*f4a2713aSLionel Sambuc } 1064*f4a2713aSLionel Sambuc 1065*f4a2713aSLionel Sambuc CXXRecordDecl *LambdaExpr::getLambdaClass() const { 1066*f4a2713aSLionel Sambuc return getType()->getAsCXXRecordDecl(); 1067*f4a2713aSLionel Sambuc } 1068*f4a2713aSLionel Sambuc 1069*f4a2713aSLionel Sambuc CXXMethodDecl *LambdaExpr::getCallOperator() const { 1070*f4a2713aSLionel Sambuc CXXRecordDecl *Record = getLambdaClass(); 1071*f4a2713aSLionel Sambuc return Record->getLambdaCallOperator(); 1072*f4a2713aSLionel Sambuc } 1073*f4a2713aSLionel Sambuc 1074*f4a2713aSLionel Sambuc TemplateParameterList *LambdaExpr::getTemplateParameterList() const { 1075*f4a2713aSLionel Sambuc CXXRecordDecl *Record = getLambdaClass(); 1076*f4a2713aSLionel Sambuc return Record->getGenericLambdaTemplateParameterList(); 1077*f4a2713aSLionel Sambuc 1078*f4a2713aSLionel Sambuc } 1079*f4a2713aSLionel Sambuc 1080*f4a2713aSLionel Sambuc CompoundStmt *LambdaExpr::getBody() const { 1081*f4a2713aSLionel Sambuc if (!getStoredStmts()[NumCaptures]) 1082*f4a2713aSLionel Sambuc getStoredStmts()[NumCaptures] = getCallOperator()->getBody(); 1083*f4a2713aSLionel Sambuc 1084*f4a2713aSLionel Sambuc return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]); 1085*f4a2713aSLionel Sambuc } 1086*f4a2713aSLionel Sambuc 1087*f4a2713aSLionel Sambuc bool LambdaExpr::isMutable() const { 1088*f4a2713aSLionel Sambuc return !getCallOperator()->isConst(); 1089*f4a2713aSLionel Sambuc } 1090*f4a2713aSLionel Sambuc 1091*f4a2713aSLionel Sambuc ExprWithCleanups::ExprWithCleanups(Expr *subexpr, 1092*f4a2713aSLionel Sambuc ArrayRef<CleanupObject> objects) 1093*f4a2713aSLionel Sambuc : Expr(ExprWithCleanupsClass, subexpr->getType(), 1094*f4a2713aSLionel Sambuc subexpr->getValueKind(), subexpr->getObjectKind(), 1095*f4a2713aSLionel Sambuc subexpr->isTypeDependent(), subexpr->isValueDependent(), 1096*f4a2713aSLionel Sambuc subexpr->isInstantiationDependent(), 1097*f4a2713aSLionel Sambuc subexpr->containsUnexpandedParameterPack()), 1098*f4a2713aSLionel Sambuc SubExpr(subexpr) { 1099*f4a2713aSLionel Sambuc ExprWithCleanupsBits.NumObjects = objects.size(); 1100*f4a2713aSLionel Sambuc for (unsigned i = 0, e = objects.size(); i != e; ++i) 1101*f4a2713aSLionel Sambuc getObjectsBuffer()[i] = objects[i]; 1102*f4a2713aSLionel Sambuc } 1103*f4a2713aSLionel Sambuc 1104*f4a2713aSLionel Sambuc ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr, 1105*f4a2713aSLionel Sambuc ArrayRef<CleanupObject> objects) { 1106*f4a2713aSLionel Sambuc size_t size = sizeof(ExprWithCleanups) 1107*f4a2713aSLionel Sambuc + objects.size() * sizeof(CleanupObject); 1108*f4a2713aSLionel Sambuc void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>()); 1109*f4a2713aSLionel Sambuc return new (buffer) ExprWithCleanups(subexpr, objects); 1110*f4a2713aSLionel Sambuc } 1111*f4a2713aSLionel Sambuc 1112*f4a2713aSLionel Sambuc ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects) 1113*f4a2713aSLionel Sambuc : Expr(ExprWithCleanupsClass, empty) { 1114*f4a2713aSLionel Sambuc ExprWithCleanupsBits.NumObjects = numObjects; 1115*f4a2713aSLionel Sambuc } 1116*f4a2713aSLionel Sambuc 1117*f4a2713aSLionel Sambuc ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, 1118*f4a2713aSLionel Sambuc EmptyShell empty, 1119*f4a2713aSLionel Sambuc unsigned numObjects) { 1120*f4a2713aSLionel Sambuc size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject); 1121*f4a2713aSLionel Sambuc void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>()); 1122*f4a2713aSLionel Sambuc return new (buffer) ExprWithCleanups(empty, numObjects); 1123*f4a2713aSLionel Sambuc } 1124*f4a2713aSLionel Sambuc 1125*f4a2713aSLionel Sambuc CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 1126*f4a2713aSLionel Sambuc SourceLocation LParenLoc, 1127*f4a2713aSLionel Sambuc ArrayRef<Expr*> Args, 1128*f4a2713aSLionel Sambuc SourceLocation RParenLoc) 1129*f4a2713aSLionel Sambuc : Expr(CXXUnresolvedConstructExprClass, 1130*f4a2713aSLionel Sambuc Type->getType().getNonReferenceType(), 1131*f4a2713aSLionel Sambuc (Type->getType()->isLValueReferenceType() ? VK_LValue 1132*f4a2713aSLionel Sambuc :Type->getType()->isRValueReferenceType()? VK_XValue 1133*f4a2713aSLionel Sambuc :VK_RValue), 1134*f4a2713aSLionel Sambuc OK_Ordinary, 1135*f4a2713aSLionel Sambuc Type->getType()->isDependentType(), true, true, 1136*f4a2713aSLionel Sambuc Type->getType()->containsUnexpandedParameterPack()), 1137*f4a2713aSLionel Sambuc Type(Type), 1138*f4a2713aSLionel Sambuc LParenLoc(LParenLoc), 1139*f4a2713aSLionel Sambuc RParenLoc(RParenLoc), 1140*f4a2713aSLionel Sambuc NumArgs(Args.size()) { 1141*f4a2713aSLionel Sambuc Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1); 1142*f4a2713aSLionel Sambuc for (unsigned I = 0; I != Args.size(); ++I) { 1143*f4a2713aSLionel Sambuc if (Args[I]->containsUnexpandedParameterPack()) 1144*f4a2713aSLionel Sambuc ExprBits.ContainsUnexpandedParameterPack = true; 1145*f4a2713aSLionel Sambuc 1146*f4a2713aSLionel Sambuc StoredArgs[I] = Args[I]; 1147*f4a2713aSLionel Sambuc } 1148*f4a2713aSLionel Sambuc } 1149*f4a2713aSLionel Sambuc 1150*f4a2713aSLionel Sambuc CXXUnresolvedConstructExpr * 1151*f4a2713aSLionel Sambuc CXXUnresolvedConstructExpr::Create(const ASTContext &C, 1152*f4a2713aSLionel Sambuc TypeSourceInfo *Type, 1153*f4a2713aSLionel Sambuc SourceLocation LParenLoc, 1154*f4a2713aSLionel Sambuc ArrayRef<Expr*> Args, 1155*f4a2713aSLionel Sambuc SourceLocation RParenLoc) { 1156*f4a2713aSLionel Sambuc void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + 1157*f4a2713aSLionel Sambuc sizeof(Expr *) * Args.size()); 1158*f4a2713aSLionel Sambuc return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc); 1159*f4a2713aSLionel Sambuc } 1160*f4a2713aSLionel Sambuc 1161*f4a2713aSLionel Sambuc CXXUnresolvedConstructExpr * 1162*f4a2713aSLionel Sambuc CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &C, unsigned NumArgs) { 1163*f4a2713aSLionel Sambuc Stmt::EmptyShell Empty; 1164*f4a2713aSLionel Sambuc void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) + 1165*f4a2713aSLionel Sambuc sizeof(Expr *) * NumArgs); 1166*f4a2713aSLionel Sambuc return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs); 1167*f4a2713aSLionel Sambuc } 1168*f4a2713aSLionel Sambuc 1169*f4a2713aSLionel Sambuc SourceLocation CXXUnresolvedConstructExpr::getLocStart() const { 1170*f4a2713aSLionel Sambuc return Type->getTypeLoc().getBeginLoc(); 1171*f4a2713aSLionel Sambuc } 1172*f4a2713aSLionel Sambuc 1173*f4a2713aSLionel Sambuc CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(const ASTContext &C, 1174*f4a2713aSLionel Sambuc Expr *Base, QualType BaseType, 1175*f4a2713aSLionel Sambuc bool IsArrow, 1176*f4a2713aSLionel Sambuc SourceLocation OperatorLoc, 1177*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, 1178*f4a2713aSLionel Sambuc SourceLocation TemplateKWLoc, 1179*f4a2713aSLionel Sambuc NamedDecl *FirstQualifierFoundInScope, 1180*f4a2713aSLionel Sambuc DeclarationNameInfo MemberNameInfo, 1181*f4a2713aSLionel Sambuc const TemplateArgumentListInfo *TemplateArgs) 1182*f4a2713aSLionel Sambuc : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, 1183*f4a2713aSLionel Sambuc VK_LValue, OK_Ordinary, true, true, true, 1184*f4a2713aSLionel Sambuc ((Base && Base->containsUnexpandedParameterPack()) || 1185*f4a2713aSLionel Sambuc (QualifierLoc && 1186*f4a2713aSLionel Sambuc QualifierLoc.getNestedNameSpecifier() 1187*f4a2713aSLionel Sambuc ->containsUnexpandedParameterPack()) || 1188*f4a2713aSLionel Sambuc MemberNameInfo.containsUnexpandedParameterPack())), 1189*f4a2713aSLionel Sambuc Base(Base), BaseType(BaseType), IsArrow(IsArrow), 1190*f4a2713aSLionel Sambuc HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()), 1191*f4a2713aSLionel Sambuc OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), 1192*f4a2713aSLionel Sambuc FirstQualifierFoundInScope(FirstQualifierFoundInScope), 1193*f4a2713aSLionel Sambuc MemberNameInfo(MemberNameInfo) { 1194*f4a2713aSLionel Sambuc if (TemplateArgs) { 1195*f4a2713aSLionel Sambuc bool Dependent = true; 1196*f4a2713aSLionel Sambuc bool InstantiationDependent = true; 1197*f4a2713aSLionel Sambuc bool ContainsUnexpandedParameterPack = false; 1198*f4a2713aSLionel Sambuc getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs, 1199*f4a2713aSLionel Sambuc Dependent, 1200*f4a2713aSLionel Sambuc InstantiationDependent, 1201*f4a2713aSLionel Sambuc ContainsUnexpandedParameterPack); 1202*f4a2713aSLionel Sambuc if (ContainsUnexpandedParameterPack) 1203*f4a2713aSLionel Sambuc ExprBits.ContainsUnexpandedParameterPack = true; 1204*f4a2713aSLionel Sambuc } else if (TemplateKWLoc.isValid()) { 1205*f4a2713aSLionel Sambuc getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc); 1206*f4a2713aSLionel Sambuc } 1207*f4a2713aSLionel Sambuc } 1208*f4a2713aSLionel Sambuc 1209*f4a2713aSLionel Sambuc CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(const ASTContext &C, 1210*f4a2713aSLionel Sambuc Expr *Base, QualType BaseType, 1211*f4a2713aSLionel Sambuc bool IsArrow, 1212*f4a2713aSLionel Sambuc SourceLocation OperatorLoc, 1213*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, 1214*f4a2713aSLionel Sambuc NamedDecl *FirstQualifierFoundInScope, 1215*f4a2713aSLionel Sambuc DeclarationNameInfo MemberNameInfo) 1216*f4a2713aSLionel Sambuc : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, 1217*f4a2713aSLionel Sambuc VK_LValue, OK_Ordinary, true, true, true, 1218*f4a2713aSLionel Sambuc ((Base && Base->containsUnexpandedParameterPack()) || 1219*f4a2713aSLionel Sambuc (QualifierLoc && 1220*f4a2713aSLionel Sambuc QualifierLoc.getNestedNameSpecifier()-> 1221*f4a2713aSLionel Sambuc containsUnexpandedParameterPack()) || 1222*f4a2713aSLionel Sambuc MemberNameInfo.containsUnexpandedParameterPack())), 1223*f4a2713aSLionel Sambuc Base(Base), BaseType(BaseType), IsArrow(IsArrow), 1224*f4a2713aSLionel Sambuc HasTemplateKWAndArgsInfo(false), 1225*f4a2713aSLionel Sambuc OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc), 1226*f4a2713aSLionel Sambuc FirstQualifierFoundInScope(FirstQualifierFoundInScope), 1227*f4a2713aSLionel Sambuc MemberNameInfo(MemberNameInfo) { } 1228*f4a2713aSLionel Sambuc 1229*f4a2713aSLionel Sambuc CXXDependentScopeMemberExpr * 1230*f4a2713aSLionel Sambuc CXXDependentScopeMemberExpr::Create(const ASTContext &C, 1231*f4a2713aSLionel Sambuc Expr *Base, QualType BaseType, bool IsArrow, 1232*f4a2713aSLionel Sambuc SourceLocation OperatorLoc, 1233*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, 1234*f4a2713aSLionel Sambuc SourceLocation TemplateKWLoc, 1235*f4a2713aSLionel Sambuc NamedDecl *FirstQualifierFoundInScope, 1236*f4a2713aSLionel Sambuc DeclarationNameInfo MemberNameInfo, 1237*f4a2713aSLionel Sambuc const TemplateArgumentListInfo *TemplateArgs) { 1238*f4a2713aSLionel Sambuc if (!TemplateArgs && !TemplateKWLoc.isValid()) 1239*f4a2713aSLionel Sambuc return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType, 1240*f4a2713aSLionel Sambuc IsArrow, OperatorLoc, 1241*f4a2713aSLionel Sambuc QualifierLoc, 1242*f4a2713aSLionel Sambuc FirstQualifierFoundInScope, 1243*f4a2713aSLionel Sambuc MemberNameInfo); 1244*f4a2713aSLionel Sambuc 1245*f4a2713aSLionel Sambuc unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0; 1246*f4a2713aSLionel Sambuc std::size_t size = sizeof(CXXDependentScopeMemberExpr) 1247*f4a2713aSLionel Sambuc + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); 1248*f4a2713aSLionel Sambuc 1249*f4a2713aSLionel Sambuc void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); 1250*f4a2713aSLionel Sambuc return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType, 1251*f4a2713aSLionel Sambuc IsArrow, OperatorLoc, 1252*f4a2713aSLionel Sambuc QualifierLoc, 1253*f4a2713aSLionel Sambuc TemplateKWLoc, 1254*f4a2713aSLionel Sambuc FirstQualifierFoundInScope, 1255*f4a2713aSLionel Sambuc MemberNameInfo, TemplateArgs); 1256*f4a2713aSLionel Sambuc } 1257*f4a2713aSLionel Sambuc 1258*f4a2713aSLionel Sambuc CXXDependentScopeMemberExpr * 1259*f4a2713aSLionel Sambuc CXXDependentScopeMemberExpr::CreateEmpty(const ASTContext &C, 1260*f4a2713aSLionel Sambuc bool HasTemplateKWAndArgsInfo, 1261*f4a2713aSLionel Sambuc unsigned NumTemplateArgs) { 1262*f4a2713aSLionel Sambuc if (!HasTemplateKWAndArgsInfo) 1263*f4a2713aSLionel Sambuc return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(), 1264*f4a2713aSLionel Sambuc 0, SourceLocation(), 1265*f4a2713aSLionel Sambuc NestedNameSpecifierLoc(), 0, 1266*f4a2713aSLionel Sambuc DeclarationNameInfo()); 1267*f4a2713aSLionel Sambuc 1268*f4a2713aSLionel Sambuc std::size_t size = sizeof(CXXDependentScopeMemberExpr) + 1269*f4a2713aSLionel Sambuc ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); 1270*f4a2713aSLionel Sambuc void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>()); 1271*f4a2713aSLionel Sambuc CXXDependentScopeMemberExpr *E 1272*f4a2713aSLionel Sambuc = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(), 1273*f4a2713aSLionel Sambuc 0, SourceLocation(), 1274*f4a2713aSLionel Sambuc NestedNameSpecifierLoc(), 1275*f4a2713aSLionel Sambuc SourceLocation(), 0, 1276*f4a2713aSLionel Sambuc DeclarationNameInfo(), 0); 1277*f4a2713aSLionel Sambuc E->HasTemplateKWAndArgsInfo = true; 1278*f4a2713aSLionel Sambuc return E; 1279*f4a2713aSLionel Sambuc } 1280*f4a2713aSLionel Sambuc 1281*f4a2713aSLionel Sambuc bool CXXDependentScopeMemberExpr::isImplicitAccess() const { 1282*f4a2713aSLionel Sambuc if (Base == 0) 1283*f4a2713aSLionel Sambuc return true; 1284*f4a2713aSLionel Sambuc 1285*f4a2713aSLionel Sambuc return cast<Expr>(Base)->isImplicitCXXThis(); 1286*f4a2713aSLionel Sambuc } 1287*f4a2713aSLionel Sambuc 1288*f4a2713aSLionel Sambuc static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, 1289*f4a2713aSLionel Sambuc UnresolvedSetIterator end) { 1290*f4a2713aSLionel Sambuc do { 1291*f4a2713aSLionel Sambuc NamedDecl *decl = *begin; 1292*f4a2713aSLionel Sambuc if (isa<UnresolvedUsingValueDecl>(decl)) 1293*f4a2713aSLionel Sambuc return false; 1294*f4a2713aSLionel Sambuc if (isa<UsingShadowDecl>(decl)) 1295*f4a2713aSLionel Sambuc decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl(); 1296*f4a2713aSLionel Sambuc 1297*f4a2713aSLionel Sambuc // Unresolved member expressions should only contain methods and 1298*f4a2713aSLionel Sambuc // method templates. 1299*f4a2713aSLionel Sambuc assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl)); 1300*f4a2713aSLionel Sambuc 1301*f4a2713aSLionel Sambuc if (isa<FunctionTemplateDecl>(decl)) 1302*f4a2713aSLionel Sambuc decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl(); 1303*f4a2713aSLionel Sambuc if (cast<CXXMethodDecl>(decl)->isStatic()) 1304*f4a2713aSLionel Sambuc return false; 1305*f4a2713aSLionel Sambuc } while (++begin != end); 1306*f4a2713aSLionel Sambuc 1307*f4a2713aSLionel Sambuc return true; 1308*f4a2713aSLionel Sambuc } 1309*f4a2713aSLionel Sambuc 1310*f4a2713aSLionel Sambuc UnresolvedMemberExpr::UnresolvedMemberExpr(const ASTContext &C, 1311*f4a2713aSLionel Sambuc bool HasUnresolvedUsing, 1312*f4a2713aSLionel Sambuc Expr *Base, QualType BaseType, 1313*f4a2713aSLionel Sambuc bool IsArrow, 1314*f4a2713aSLionel Sambuc SourceLocation OperatorLoc, 1315*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, 1316*f4a2713aSLionel Sambuc SourceLocation TemplateKWLoc, 1317*f4a2713aSLionel Sambuc const DeclarationNameInfo &MemberNameInfo, 1318*f4a2713aSLionel Sambuc const TemplateArgumentListInfo *TemplateArgs, 1319*f4a2713aSLionel Sambuc UnresolvedSetIterator Begin, 1320*f4a2713aSLionel Sambuc UnresolvedSetIterator End) 1321*f4a2713aSLionel Sambuc : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc, 1322*f4a2713aSLionel Sambuc MemberNameInfo, TemplateArgs, Begin, End, 1323*f4a2713aSLionel Sambuc // Dependent 1324*f4a2713aSLionel Sambuc ((Base && Base->isTypeDependent()) || 1325*f4a2713aSLionel Sambuc BaseType->isDependentType()), 1326*f4a2713aSLionel Sambuc ((Base && Base->isInstantiationDependent()) || 1327*f4a2713aSLionel Sambuc BaseType->isInstantiationDependentType()), 1328*f4a2713aSLionel Sambuc // Contains unexpanded parameter pack 1329*f4a2713aSLionel Sambuc ((Base && Base->containsUnexpandedParameterPack()) || 1330*f4a2713aSLionel Sambuc BaseType->containsUnexpandedParameterPack())), 1331*f4a2713aSLionel Sambuc IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), 1332*f4a2713aSLionel Sambuc Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) { 1333*f4a2713aSLionel Sambuc 1334*f4a2713aSLionel Sambuc // Check whether all of the members are non-static member functions, 1335*f4a2713aSLionel Sambuc // and if so, mark give this bound-member type instead of overload type. 1336*f4a2713aSLionel Sambuc if (hasOnlyNonStaticMemberFunctions(Begin, End)) 1337*f4a2713aSLionel Sambuc setType(C.BoundMemberTy); 1338*f4a2713aSLionel Sambuc } 1339*f4a2713aSLionel Sambuc 1340*f4a2713aSLionel Sambuc bool UnresolvedMemberExpr::isImplicitAccess() const { 1341*f4a2713aSLionel Sambuc if (Base == 0) 1342*f4a2713aSLionel Sambuc return true; 1343*f4a2713aSLionel Sambuc 1344*f4a2713aSLionel Sambuc return cast<Expr>(Base)->isImplicitCXXThis(); 1345*f4a2713aSLionel Sambuc } 1346*f4a2713aSLionel Sambuc 1347*f4a2713aSLionel Sambuc UnresolvedMemberExpr * 1348*f4a2713aSLionel Sambuc UnresolvedMemberExpr::Create(const ASTContext &C, bool HasUnresolvedUsing, 1349*f4a2713aSLionel Sambuc Expr *Base, QualType BaseType, bool IsArrow, 1350*f4a2713aSLionel Sambuc SourceLocation OperatorLoc, 1351*f4a2713aSLionel Sambuc NestedNameSpecifierLoc QualifierLoc, 1352*f4a2713aSLionel Sambuc SourceLocation TemplateKWLoc, 1353*f4a2713aSLionel Sambuc const DeclarationNameInfo &MemberNameInfo, 1354*f4a2713aSLionel Sambuc const TemplateArgumentListInfo *TemplateArgs, 1355*f4a2713aSLionel Sambuc UnresolvedSetIterator Begin, 1356*f4a2713aSLionel Sambuc UnresolvedSetIterator End) { 1357*f4a2713aSLionel Sambuc std::size_t size = sizeof(UnresolvedMemberExpr); 1358*f4a2713aSLionel Sambuc if (TemplateArgs) 1359*f4a2713aSLionel Sambuc size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size()); 1360*f4a2713aSLionel Sambuc else if (TemplateKWLoc.isValid()) 1361*f4a2713aSLionel Sambuc size += ASTTemplateKWAndArgsInfo::sizeFor(0); 1362*f4a2713aSLionel Sambuc 1363*f4a2713aSLionel Sambuc void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); 1364*f4a2713aSLionel Sambuc return new (Mem) UnresolvedMemberExpr(C, 1365*f4a2713aSLionel Sambuc HasUnresolvedUsing, Base, BaseType, 1366*f4a2713aSLionel Sambuc IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc, 1367*f4a2713aSLionel Sambuc MemberNameInfo, TemplateArgs, Begin, End); 1368*f4a2713aSLionel Sambuc } 1369*f4a2713aSLionel Sambuc 1370*f4a2713aSLionel Sambuc UnresolvedMemberExpr * 1371*f4a2713aSLionel Sambuc UnresolvedMemberExpr::CreateEmpty(const ASTContext &C, 1372*f4a2713aSLionel Sambuc bool HasTemplateKWAndArgsInfo, 1373*f4a2713aSLionel Sambuc unsigned NumTemplateArgs) { 1374*f4a2713aSLionel Sambuc std::size_t size = sizeof(UnresolvedMemberExpr); 1375*f4a2713aSLionel Sambuc if (HasTemplateKWAndArgsInfo) 1376*f4a2713aSLionel Sambuc size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs); 1377*f4a2713aSLionel Sambuc 1378*f4a2713aSLionel Sambuc void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>()); 1379*f4a2713aSLionel Sambuc UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); 1380*f4a2713aSLionel Sambuc E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; 1381*f4a2713aSLionel Sambuc return E; 1382*f4a2713aSLionel Sambuc } 1383*f4a2713aSLionel Sambuc 1384*f4a2713aSLionel Sambuc CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { 1385*f4a2713aSLionel Sambuc // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this. 1386*f4a2713aSLionel Sambuc 1387*f4a2713aSLionel Sambuc // If there was a nested name specifier, it names the naming class. 1388*f4a2713aSLionel Sambuc // It can't be dependent: after all, we were actually able to do the 1389*f4a2713aSLionel Sambuc // lookup. 1390*f4a2713aSLionel Sambuc CXXRecordDecl *Record = 0; 1391*f4a2713aSLionel Sambuc if (getQualifier()) { 1392*f4a2713aSLionel Sambuc const Type *T = getQualifier()->getAsType(); 1393*f4a2713aSLionel Sambuc assert(T && "qualifier in member expression does not name type"); 1394*f4a2713aSLionel Sambuc Record = T->getAsCXXRecordDecl(); 1395*f4a2713aSLionel Sambuc assert(Record && "qualifier in member expression does not name record"); 1396*f4a2713aSLionel Sambuc } 1397*f4a2713aSLionel Sambuc // Otherwise the naming class must have been the base class. 1398*f4a2713aSLionel Sambuc else { 1399*f4a2713aSLionel Sambuc QualType BaseType = getBaseType().getNonReferenceType(); 1400*f4a2713aSLionel Sambuc if (isArrow()) { 1401*f4a2713aSLionel Sambuc const PointerType *PT = BaseType->getAs<PointerType>(); 1402*f4a2713aSLionel Sambuc assert(PT && "base of arrow member access is not pointer"); 1403*f4a2713aSLionel Sambuc BaseType = PT->getPointeeType(); 1404*f4a2713aSLionel Sambuc } 1405*f4a2713aSLionel Sambuc 1406*f4a2713aSLionel Sambuc Record = BaseType->getAsCXXRecordDecl(); 1407*f4a2713aSLionel Sambuc assert(Record && "base of member expression does not name record"); 1408*f4a2713aSLionel Sambuc } 1409*f4a2713aSLionel Sambuc 1410*f4a2713aSLionel Sambuc return Record; 1411*f4a2713aSLionel Sambuc } 1412*f4a2713aSLionel Sambuc 1413*f4a2713aSLionel Sambuc SubstNonTypeTemplateParmPackExpr:: 1414*f4a2713aSLionel Sambuc SubstNonTypeTemplateParmPackExpr(QualType T, 1415*f4a2713aSLionel Sambuc NonTypeTemplateParmDecl *Param, 1416*f4a2713aSLionel Sambuc SourceLocation NameLoc, 1417*f4a2713aSLionel Sambuc const TemplateArgument &ArgPack) 1418*f4a2713aSLionel Sambuc : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary, 1419*f4a2713aSLionel Sambuc true, true, true, true), 1420*f4a2713aSLionel Sambuc Param(Param), Arguments(ArgPack.pack_begin()), 1421*f4a2713aSLionel Sambuc NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { } 1422*f4a2713aSLionel Sambuc 1423*f4a2713aSLionel Sambuc TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const { 1424*f4a2713aSLionel Sambuc return TemplateArgument(Arguments, NumArguments); 1425*f4a2713aSLionel Sambuc } 1426*f4a2713aSLionel Sambuc 1427*f4a2713aSLionel Sambuc FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, 1428*f4a2713aSLionel Sambuc SourceLocation NameLoc, 1429*f4a2713aSLionel Sambuc unsigned NumParams, 1430*f4a2713aSLionel Sambuc Decl * const *Params) 1431*f4a2713aSLionel Sambuc : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, 1432*f4a2713aSLionel Sambuc true, true, true, true), 1433*f4a2713aSLionel Sambuc ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) { 1434*f4a2713aSLionel Sambuc if (Params) 1435*f4a2713aSLionel Sambuc std::uninitialized_copy(Params, Params + NumParams, 1436*f4a2713aSLionel Sambuc reinterpret_cast<Decl**>(this+1)); 1437*f4a2713aSLionel Sambuc } 1438*f4a2713aSLionel Sambuc 1439*f4a2713aSLionel Sambuc FunctionParmPackExpr * 1440*f4a2713aSLionel Sambuc FunctionParmPackExpr::Create(const ASTContext &Context, QualType T, 1441*f4a2713aSLionel Sambuc ParmVarDecl *ParamPack, SourceLocation NameLoc, 1442*f4a2713aSLionel Sambuc ArrayRef<Decl *> Params) { 1443*f4a2713aSLionel Sambuc return new (Context.Allocate(sizeof(FunctionParmPackExpr) + 1444*f4a2713aSLionel Sambuc sizeof(ParmVarDecl*) * Params.size())) 1445*f4a2713aSLionel Sambuc FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data()); 1446*f4a2713aSLionel Sambuc } 1447*f4a2713aSLionel Sambuc 1448*f4a2713aSLionel Sambuc FunctionParmPackExpr * 1449*f4a2713aSLionel Sambuc FunctionParmPackExpr::CreateEmpty(const ASTContext &Context, 1450*f4a2713aSLionel Sambuc unsigned NumParams) { 1451*f4a2713aSLionel Sambuc return new (Context.Allocate(sizeof(FunctionParmPackExpr) + 1452*f4a2713aSLionel Sambuc sizeof(ParmVarDecl*) * NumParams)) 1453*f4a2713aSLionel Sambuc FunctionParmPackExpr(QualType(), 0, SourceLocation(), 0, 0); 1454*f4a2713aSLionel Sambuc } 1455*f4a2713aSLionel Sambuc 1456*f4a2713aSLionel Sambuc TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, 1457*f4a2713aSLionel Sambuc ArrayRef<TypeSourceInfo *> Args, 1458*f4a2713aSLionel Sambuc SourceLocation RParenLoc, 1459*f4a2713aSLionel Sambuc bool Value) 1460*f4a2713aSLionel Sambuc : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary, 1461*f4a2713aSLionel Sambuc /*TypeDependent=*/false, 1462*f4a2713aSLionel Sambuc /*ValueDependent=*/false, 1463*f4a2713aSLionel Sambuc /*InstantiationDependent=*/false, 1464*f4a2713aSLionel Sambuc /*ContainsUnexpandedParameterPack=*/false), 1465*f4a2713aSLionel Sambuc Loc(Loc), RParenLoc(RParenLoc) 1466*f4a2713aSLionel Sambuc { 1467*f4a2713aSLionel Sambuc TypeTraitExprBits.Kind = Kind; 1468*f4a2713aSLionel Sambuc TypeTraitExprBits.Value = Value; 1469*f4a2713aSLionel Sambuc TypeTraitExprBits.NumArgs = Args.size(); 1470*f4a2713aSLionel Sambuc 1471*f4a2713aSLionel Sambuc TypeSourceInfo **ToArgs = getTypeSourceInfos(); 1472*f4a2713aSLionel Sambuc 1473*f4a2713aSLionel Sambuc for (unsigned I = 0, N = Args.size(); I != N; ++I) { 1474*f4a2713aSLionel Sambuc if (Args[I]->getType()->isDependentType()) 1475*f4a2713aSLionel Sambuc setValueDependent(true); 1476*f4a2713aSLionel Sambuc if (Args[I]->getType()->isInstantiationDependentType()) 1477*f4a2713aSLionel Sambuc setInstantiationDependent(true); 1478*f4a2713aSLionel Sambuc if (Args[I]->getType()->containsUnexpandedParameterPack()) 1479*f4a2713aSLionel Sambuc setContainsUnexpandedParameterPack(true); 1480*f4a2713aSLionel Sambuc 1481*f4a2713aSLionel Sambuc ToArgs[I] = Args[I]; 1482*f4a2713aSLionel Sambuc } 1483*f4a2713aSLionel Sambuc } 1484*f4a2713aSLionel Sambuc 1485*f4a2713aSLionel Sambuc TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T, 1486*f4a2713aSLionel Sambuc SourceLocation Loc, 1487*f4a2713aSLionel Sambuc TypeTrait Kind, 1488*f4a2713aSLionel Sambuc ArrayRef<TypeSourceInfo *> Args, 1489*f4a2713aSLionel Sambuc SourceLocation RParenLoc, 1490*f4a2713aSLionel Sambuc bool Value) { 1491*f4a2713aSLionel Sambuc unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * Args.size(); 1492*f4a2713aSLionel Sambuc void *Mem = C.Allocate(Size); 1493*f4a2713aSLionel Sambuc return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value); 1494*f4a2713aSLionel Sambuc } 1495*f4a2713aSLionel Sambuc 1496*f4a2713aSLionel Sambuc TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C, 1497*f4a2713aSLionel Sambuc unsigned NumArgs) { 1498*f4a2713aSLionel Sambuc unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * NumArgs; 1499*f4a2713aSLionel Sambuc void *Mem = C.Allocate(Size); 1500*f4a2713aSLionel Sambuc return new (Mem) TypeTraitExpr(EmptyShell()); 1501*f4a2713aSLionel Sambuc } 1502*f4a2713aSLionel Sambuc 1503*f4a2713aSLionel Sambuc void ArrayTypeTraitExpr::anchor() { } 1504