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