1//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief Defines the clang::Expr interface and subclasses for C++ expressions.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_EXPRCXX_H
16#define LLVM_CLANG_AST_EXPRCXX_H
17
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclCXX.h"
20#include "clang/AST/Expr.h"
21#include "clang/AST/LambdaCapture.h"
22#include "clang/AST/TemplateBase.h"
23#include "clang/AST/UnresolvedSet.h"
24#include "clang/Basic/ExpressionTraits.h"
25#include "clang/Basic/TypeTraits.h"
26#include "llvm/Support/Compiler.h"
27
28namespace clang {
29
30class CXXTemporary;
31class MSPropertyDecl;
32class TemplateArgumentListInfo;
33class UuidAttr;
34
35//===--------------------------------------------------------------------===//
36// C++ Expressions.
37//===--------------------------------------------------------------------===//
38
39/// \brief A call to an overloaded operator written using operator
40/// syntax.
41///
42/// Represents a call to an overloaded operator written using operator
43/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
44/// normal call, this AST node provides better information about the
45/// syntactic representation of the call.
46///
47/// In a C++ template, this expression node kind will be used whenever
48/// any of the arguments are type-dependent. In this case, the
49/// function itself will be a (possibly empty) set of functions and
50/// function templates that were found by name lookup at template
51/// definition time.
52class CXXOperatorCallExpr : public CallExpr {
53 /// \brief The overloaded operator.
54 OverloadedOperatorKind Operator;
55 SourceRange Range;
56
57 // Only meaningful for floating point types.
58 FPOptions FPFeatures;
59
60 SourceRange getSourceRangeImpl() const LLVM_READONLY;
61public:
62 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
63 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
64 SourceLocation operatorloc, FPOptions FPFeatures)
65 : CallExpr(C, CXXOperatorCallExprClass, fn, args, t, VK, operatorloc),
66 Operator(Op), FPFeatures(FPFeatures) {
67 Range = getSourceRangeImpl();
68 }
69 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
70 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
71
72
73 /// \brief Returns the kind of overloaded operator that this
74 /// expression refers to.
75 OverloadedOperatorKind getOperator() const { return Operator; }
76
77 static bool isAssignmentOp(OverloadedOperatorKind Opc) {
78 return Opc == OO_Equal || Opc == OO_StarEqual ||
79 Opc == OO_SlashEqual || Opc == OO_PercentEqual ||
80 Opc == OO_PlusEqual || Opc == OO_MinusEqual ||
81 Opc == OO_LessLessEqual || Opc == OO_GreaterGreaterEqual ||
82 Opc == OO_AmpEqual || Opc == OO_CaretEqual ||
83 Opc == OO_PipeEqual;
84 }
85 bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
86
87 /// \brief Is this written as an infix binary operator?
88 bool isInfixBinaryOp() const;
89
90 /// \brief Returns the location of the operator symbol in the expression.
91 ///
92 /// When \c getOperator()==OO_Call, this is the location of the right
93 /// parentheses; when \c getOperator()==OO_Subscript, this is the location
94 /// of the right bracket.
95 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
96
97 SourceLocation getExprLoc() const LLVM_READONLY {
98 return (Operator < OO_Plus || Operator >= OO_Arrow ||
99 Operator == OO_PlusPlus || Operator == OO_MinusMinus)
100 ? getLocStart()
101 : getOperatorLoc();
102 }
103
104 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
105 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
106 SourceRange getSourceRange() const { return Range; }
107
108 static bool classof(const Stmt *T) {
109 return T->getStmtClass() == CXXOperatorCallExprClass;
110 }
111
112 // Set the FP contractability status of this operator. Only meaningful for
113 // operations on floating point types.
114 void setFPFeatures(FPOptions F) { FPFeatures = F; }
115
116 FPOptions getFPFeatures() const { return FPFeatures; }
117
118 // Get the FP contractability status of this operator. Only meaningful for
119 // operations on floating point types.
120 bool isFPContractableWithinStatement() const {
121 return FPFeatures.allowFPContractWithinStatement();
122 }
123
124 friend class ASTStmtReader;
125 friend class ASTStmtWriter;
126};
127
128/// Represents a call to a member function that
129/// may be written either with member call syntax (e.g., "obj.func()"
130/// or "objptr->func()") or with normal function-call syntax
131/// ("func()") within a member function that ends up calling a member
132/// function. The callee in either case is a MemberExpr that contains
133/// both the object argument and the member function, while the
134/// arguments are the arguments within the parentheses (not including
135/// the object argument).
136class CXXMemberCallExpr : public CallExpr {
137public:
138 CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
139 QualType t, ExprValueKind VK, SourceLocation RP)
140 : CallExpr(C, CXXMemberCallExprClass, fn, args, t, VK, RP) {}
141
142 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
143 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
144
145 /// \brief Retrieves the implicit object argument for the member call.
146 ///
147 /// For example, in "x.f(5)", this returns the sub-expression "x".
148 Expr *getImplicitObjectArgument() const;
149
150 /// \brief Retrieves the declaration of the called method.
151 CXXMethodDecl *getMethodDecl() const;
152
153 /// \brief Retrieves the CXXRecordDecl for the underlying type of
154 /// the implicit object argument.
155 ///
156 /// Note that this is may not be the same declaration as that of the class
157 /// context of the CXXMethodDecl which this function is calling.
158 /// FIXME: Returns 0 for member pointer call exprs.
159 CXXRecordDecl *getRecordDecl() const;
160
161 SourceLocation getExprLoc() const LLVM_READONLY {
162 SourceLocation CLoc = getCallee()->getExprLoc();
163 if (CLoc.isValid())
164 return CLoc;
165
166 return getLocStart();
167 }
168
169 static bool classof(const Stmt *T) {
170 return T->getStmtClass() == CXXMemberCallExprClass;
171 }
172};
173
174/// \brief Represents a call to a CUDA kernel function.
175class CUDAKernelCallExpr : public CallExpr {
176private:
177 enum { CONFIG, END_PREARG };
178
179public:
180 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
181 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
182 SourceLocation RP)
183 : CallExpr(C, CUDAKernelCallExprClass, fn, Config, args, t, VK, RP) {}
184
185 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
186 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
187
188 const CallExpr *getConfig() const {
189 return cast_or_null<CallExpr>(getPreArg(CONFIG));
190 }
191 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
192
193 /// \brief Sets the kernel configuration expression.
194 ///
195 /// Note that this method cannot be called if config has already been set to a
196 /// non-null value.
197 void setConfig(CallExpr *E) {
198 assert(!getConfig() &&
199 "Cannot call setConfig if config is not null");
200 setPreArg(CONFIG, E);
201 setInstantiationDependent(isInstantiationDependent() ||
202 E->isInstantiationDependent());
203 setContainsUnexpandedParameterPack(containsUnexpandedParameterPack() ||
204 E->containsUnexpandedParameterPack());
205 }
206
207 static bool classof(const Stmt *T) {
208 return T->getStmtClass() == CUDAKernelCallExprClass;
209 }
210};
211
212/// \brief Abstract class common to all of the C++ "named"/"keyword" casts.
213///
214/// This abstract class is inherited by all of the classes
215/// representing "named" casts: CXXStaticCastExpr for \c static_cast,
216/// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
217/// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
218class CXXNamedCastExpr : public ExplicitCastExpr {
219private:
220 SourceLocation Loc; // the location of the casting op
221 SourceLocation RParenLoc; // the location of the right parenthesis
222 SourceRange AngleBrackets; // range for '<' '>'
223
224protected:
225 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
226 CastKind kind, Expr *op, unsigned PathSize,
227 TypeSourceInfo *writtenTy, SourceLocation l,
228 SourceLocation RParenLoc,
229 SourceRange AngleBrackets)
230 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
231 RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
232
233 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
234 : ExplicitCastExpr(SC, Shell, PathSize) { }
235
236 friend class ASTStmtReader;
237
238public:
239 const char *getCastName() const;
240
241 /// \brief Retrieve the location of the cast operator keyword, e.g.,
242 /// \c static_cast.
243 SourceLocation getOperatorLoc() const { return Loc; }
244
245 /// \brief Retrieve the location of the closing parenthesis.
246 SourceLocation getRParenLoc() const { return RParenLoc; }
247
248 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
249 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
250 SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
251
252 static bool classof(const Stmt *T) {
253 switch (T->getStmtClass()) {
254 case CXXStaticCastExprClass:
255 case CXXDynamicCastExprClass:
256 case CXXReinterpretCastExprClass:
257 case CXXConstCastExprClass:
258 return true;
259 default:
260 return false;
261 }
262 }
263};
264
265/// \brief A C++ \c static_cast expression (C++ [expr.static.cast]).
266///
267/// This expression node represents a C++ static cast, e.g.,
268/// \c static_cast<int>(1.0).
269class CXXStaticCastExpr final
270 : public CXXNamedCastExpr,
271 private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *> {
272 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
273 unsigned pathSize, TypeSourceInfo *writtenTy,
274 SourceLocation l, SourceLocation RParenLoc,
275 SourceRange AngleBrackets)
276 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
277 writtenTy, l, RParenLoc, AngleBrackets) {}
278
279 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
280 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
281
282public:
283 static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
284 ExprValueKind VK, CastKind K, Expr *Op,
285 const CXXCastPath *Path,
286 TypeSourceInfo *Written, SourceLocation L,
287 SourceLocation RParenLoc,
288 SourceRange AngleBrackets);
289 static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
290 unsigned PathSize);
291
292 static bool classof(const Stmt *T) {
293 return T->getStmtClass() == CXXStaticCastExprClass;
294 }
295
296 friend TrailingObjects;
297 friend class CastExpr;
298};
299
300/// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
301///
302/// This expression node represents a dynamic cast, e.g.,
303/// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
304/// check to determine how to perform the type conversion.
305class CXXDynamicCastExpr final
306 : public CXXNamedCastExpr,
307 private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> {
308 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
309 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
310 SourceLocation l, SourceLocation RParenLoc,
311 SourceRange AngleBrackets)
312 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
313 writtenTy, l, RParenLoc, AngleBrackets) {}
314
315 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
316 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
317
318public:
319 static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
320 ExprValueKind VK, CastKind Kind, Expr *Op,
321 const CXXCastPath *Path,
322 TypeSourceInfo *Written, SourceLocation L,
323 SourceLocation RParenLoc,
324 SourceRange AngleBrackets);
325
326 static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
327 unsigned pathSize);
328
329 bool isAlwaysNull() const;
330
331 static bool classof(const Stmt *T) {
332 return T->getStmtClass() == CXXDynamicCastExprClass;
333 }
334
335 friend TrailingObjects;
336 friend class CastExpr;
337};
338
339/// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
340///
341/// This expression node represents a reinterpret cast, e.g.,
342/// @c reinterpret_cast<int>(VoidPtr).
343///
344/// A reinterpret_cast provides a differently-typed view of a value but
345/// (in Clang, as in most C++ implementations) performs no actual work at
346/// run time.
347class CXXReinterpretCastExpr final
348 : public CXXNamedCastExpr,
349 private llvm::TrailingObjects<CXXReinterpretCastExpr,
350 CXXBaseSpecifier *> {
351 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
352 Expr *op, unsigned pathSize,
353 TypeSourceInfo *writtenTy, SourceLocation l,
354 SourceLocation RParenLoc,
355 SourceRange AngleBrackets)
356 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
357 pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
358
359 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
360 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
361
362public:
363 static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
364 ExprValueKind VK, CastKind Kind,
365 Expr *Op, const CXXCastPath *Path,
366 TypeSourceInfo *WrittenTy, SourceLocation L,
367 SourceLocation RParenLoc,
368 SourceRange AngleBrackets);
369 static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
370 unsigned pathSize);
371
372 static bool classof(const Stmt *T) {
373 return T->getStmtClass() == CXXReinterpretCastExprClass;
374 }
375
376 friend TrailingObjects;
377 friend class CastExpr;
378};
379
380/// \brief A C++ \c const_cast expression (C++ [expr.const.cast]).
381///
382/// This expression node represents a const cast, e.g.,
383/// \c const_cast<char*>(PtrToConstChar).
384///
385/// A const_cast can remove type qualifiers but does not change the underlying
386/// value.
387class CXXConstCastExpr final
388 : public CXXNamedCastExpr,
389 private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> {
390 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
391 TypeSourceInfo *writtenTy, SourceLocation l,
392 SourceLocation RParenLoc, SourceRange AngleBrackets)
393 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
394 0, writtenTy, l, RParenLoc, AngleBrackets) {}
395
396 explicit CXXConstCastExpr(EmptyShell Empty)
397 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
398
399public:
400 static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
401 ExprValueKind VK, Expr *Op,
402 TypeSourceInfo *WrittenTy, SourceLocation L,
403 SourceLocation RParenLoc,
404 SourceRange AngleBrackets);
405 static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
406
407 static bool classof(const Stmt *T) {
408 return T->getStmtClass() == CXXConstCastExprClass;
409 }
410
411 friend TrailingObjects;
412 friend class CastExpr;
413};
414
415/// \brief A call to a literal operator (C++11 [over.literal])
416/// written as a user-defined literal (C++11 [lit.ext]).
417///
418/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
419/// is semantically equivalent to a normal call, this AST node provides better
420/// information about the syntactic representation of the literal.
421///
422/// Since literal operators are never found by ADL and can only be declared at
423/// namespace scope, a user-defined literal is never dependent.
424class UserDefinedLiteral : public CallExpr {
425 /// \brief The location of a ud-suffix within the literal.
426 SourceLocation UDSuffixLoc;
427
428public:
429 UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
430 QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
431 SourceLocation SuffixLoc)
432 : CallExpr(C, UserDefinedLiteralClass, Fn, Args, T, VK, LitEndLoc),
433 UDSuffixLoc(SuffixLoc) {}
434 explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty)
435 : CallExpr(C, UserDefinedLiteralClass, Empty) {}
436
437 /// The kind of literal operator which is invoked.
438 enum LiteralOperatorKind {
439 LOK_Raw, ///< Raw form: operator "" X (const char *)
440 LOK_Template, ///< Raw form: operator "" X<cs...> ()
441 LOK_Integer, ///< operator "" X (unsigned long long)
442 LOK_Floating, ///< operator "" X (long double)
443 LOK_String, ///< operator "" X (const CharT *, size_t)
444 LOK_Character ///< operator "" X (CharT)
445 };
446
447 /// \brief Returns the kind of literal operator invocation
448 /// which this expression represents.
449 LiteralOperatorKind getLiteralOperatorKind() const;
450
451 /// \brief If this is not a raw user-defined literal, get the
452 /// underlying cooked literal (representing the literal with the suffix
453 /// removed).
454 Expr *getCookedLiteral();
455 const Expr *getCookedLiteral() const {
456 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
457 }
458
459 SourceLocation getLocStart() const {
460 if (getLiteralOperatorKind() == LOK_Template)
461 return getRParenLoc();
462 return getArg(0)->getLocStart();
463 }
464 SourceLocation getLocEnd() const { return getRParenLoc(); }
465
466
467 /// \brief Returns the location of a ud-suffix in the expression.
468 ///
469 /// For a string literal, there may be multiple identical suffixes. This
470 /// returns the first.
471 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
472
473 /// \brief Returns the ud-suffix specified for this literal.
474 const IdentifierInfo *getUDSuffix() const;
475
476 static bool classof(const Stmt *S) {
477 return S->getStmtClass() == UserDefinedLiteralClass;
478 }
479
480 friend class ASTStmtReader;
481 friend class ASTStmtWriter;
482};
483
484/// \brief A boolean literal, per ([C++ lex.bool] Boolean literals).
485///
486class CXXBoolLiteralExpr : public Expr {
487 bool Value;
488 SourceLocation Loc;
489public:
490 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
491 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
492 false, false),
493 Value(val), Loc(l) {}
494
495 explicit CXXBoolLiteralExpr(EmptyShell Empty)
496 : Expr(CXXBoolLiteralExprClass, Empty) { }
497
498 bool getValue() const { return Value; }
499 void setValue(bool V) { Value = V; }
500
501 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
502 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
503
504 SourceLocation getLocation() const { return Loc; }
505 void setLocation(SourceLocation L) { Loc = L; }
506
507 static bool classof(const Stmt *T) {
508 return T->getStmtClass() == CXXBoolLiteralExprClass;
509 }
510
511 // Iterators
512 child_range children() {
513 return child_range(child_iterator(), child_iterator());
514 }
515};
516
517/// \brief The null pointer literal (C++11 [lex.nullptr])
518///
519/// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
520class CXXNullPtrLiteralExpr : public Expr {
521 SourceLocation Loc;
522public:
523 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
524 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
525 false, false),
526 Loc(l) {}
527
528 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
529 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
530
531 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
532 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
533
534 SourceLocation getLocation() const { return Loc; }
535 void setLocation(SourceLocation L) { Loc = L; }
536
537 static bool classof(const Stmt *T) {
538 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
539 }
540
541 child_range children() {
542 return child_range(child_iterator(), child_iterator());
543 }
544};
545
546/// \brief Implicit construction of a std::initializer_list<T> object from an
547/// array temporary within list-initialization (C++11 [dcl.init.list]p5).
548class CXXStdInitializerListExpr : public Expr {
549 Stmt *SubExpr;
550
551 CXXStdInitializerListExpr(EmptyShell Empty)
552 : Expr(CXXStdInitializerListExprClass, Empty), SubExpr(nullptr) {}
553
554public:
555 CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
556 : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
557 Ty->isDependentType(), SubExpr->isValueDependent(),
558 SubExpr->isInstantiationDependent(),
559 SubExpr->containsUnexpandedParameterPack()),
560 SubExpr(SubExpr) {}
561
562 Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
563 const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
564
565 SourceLocation getLocStart() const LLVM_READONLY {
566 return SubExpr->getLocStart();
567 }
568 SourceLocation getLocEnd() const LLVM_READONLY {
569 return SubExpr->getLocEnd();
570 }
571 SourceRange getSourceRange() const LLVM_READONLY {
572 return SubExpr->getSourceRange();
573 }
574
575 static bool classof(const Stmt *S) {
576 return S->getStmtClass() == CXXStdInitializerListExprClass;
577 }
578
579 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
580
581 friend class ASTReader;
582 friend class ASTStmtReader;
583};
584
585/// A C++ \c typeid expression (C++ [expr.typeid]), which gets
586/// the \c type_info that corresponds to the supplied type, or the (possibly
587/// dynamic) type of the supplied expression.
588///
589/// This represents code like \c typeid(int) or \c typeid(*objPtr)
590class CXXTypeidExpr : public Expr {
591private:
592 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
593 SourceRange Range;
594
595public:
596 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
597 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
598 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
599 false,
600 // typeid is value-dependent if the type or expression are dependent
601 Operand->getType()->isDependentType(),
602 Operand->getType()->isInstantiationDependentType(),
603 Operand->getType()->containsUnexpandedParameterPack()),
604 Operand(Operand), Range(R) { }
605
606 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
607 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
608 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
609 false,
610 // typeid is value-dependent if the type or expression are dependent
611 Operand->isTypeDependent() || Operand->isValueDependent(),
612 Operand->isInstantiationDependent(),
613 Operand->containsUnexpandedParameterPack()),
614 Operand(Operand), Range(R) { }
615
616 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
617 : Expr(CXXTypeidExprClass, Empty) {
618 if (isExpr)
619 Operand = (Expr*)nullptr;
620 else
621 Operand = (TypeSourceInfo*)nullptr;
622 }
623
624 /// Determine whether this typeid has a type operand which is potentially
625 /// evaluated, per C++11 [expr.typeid]p3.
626 bool isPotentiallyEvaluated() const;
627
628 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
629
630 /// \brief Retrieves the type operand of this typeid() expression after
631 /// various required adjustments (removing reference types, cv-qualifiers).
632 QualType getTypeOperand(ASTContext &Context) const;
633
634 /// \brief Retrieve source information for the type operand.
635 TypeSourceInfo *getTypeOperandSourceInfo() const {
636 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
637 return Operand.get<TypeSourceInfo *>();
638 }
639
640 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
641 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
642 Operand = TSI;
643 }
644
645 Expr *getExprOperand() const {
646 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
647 return static_cast<Expr*>(Operand.get<Stmt *>());
648 }
649
650 void setExprOperand(Expr *E) {
651 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
652 Operand = E;
653 }
654
655 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
656 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
657 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
658 void setSourceRange(SourceRange R) { Range = R; }
659
660 static bool classof(const Stmt *T) {
661 return T->getStmtClass() == CXXTypeidExprClass;
662 }
663
664 // Iterators
665 child_range children() {
666 if (isTypeOperand())
667 return child_range(child_iterator(), child_iterator());
668 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
669 return child_range(begin, begin + 1);
670 }
671};
672
673/// \brief A member reference to an MSPropertyDecl.
674///
675/// This expression always has pseudo-object type, and therefore it is
676/// typically not encountered in a fully-typechecked expression except
677/// within the syntactic form of a PseudoObjectExpr.
678class MSPropertyRefExpr : public Expr {
679 Expr *BaseExpr;
680 MSPropertyDecl *TheDecl;
681 SourceLocation MemberLoc;
682 bool IsArrow;
683 NestedNameSpecifierLoc QualifierLoc;
684
685public:
686 MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
687 QualType ty, ExprValueKind VK,
688 NestedNameSpecifierLoc qualifierLoc,
689 SourceLocation nameLoc)
690 : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
691 /*type-dependent*/ false, baseExpr->isValueDependent(),
692 baseExpr->isInstantiationDependent(),
693 baseExpr->containsUnexpandedParameterPack()),
694 BaseExpr(baseExpr), TheDecl(decl),
695 MemberLoc(nameLoc), IsArrow(isArrow),
696 QualifierLoc(qualifierLoc) {}
697
698 MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
699
700 SourceRange getSourceRange() const LLVM_READONLY {
701 return SourceRange(getLocStart(), getLocEnd());
702 }
703 bool isImplicitAccess() const {
704 return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
705 }
706 SourceLocation getLocStart() const {
707 if (!isImplicitAccess())
708 return BaseExpr->getLocStart();
709 else if (QualifierLoc)
710 return QualifierLoc.getBeginLoc();
711 else
712 return MemberLoc;
713 }
714 SourceLocation getLocEnd() const { return getMemberLoc(); }
715
716 child_range children() {
717 return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
718 }
719 static bool classof(const Stmt *T) {
720 return T->getStmtClass() == MSPropertyRefExprClass;
721 }
722
723 Expr *getBaseExpr() const { return BaseExpr; }
724 MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
725 bool isArrow() const { return IsArrow; }
726 SourceLocation getMemberLoc() const { return MemberLoc; }
727 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
728
729 friend class ASTStmtReader;
730};
731
732/// MS property subscript expression.
733/// MSVC supports 'property' attribute and allows to apply it to the
734/// declaration of an empty array in a class or structure definition.
735/// For example:
736/// \code
737/// __declspec(property(get=GetX, put=PutX)) int x[];
738/// \endcode
739/// The above statement indicates that x[] can be used with one or more array
740/// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and
741/// p->x[a][b] = i will be turned into p->PutX(a, b, i).
742/// This is a syntactic pseudo-object expression.
743class MSPropertySubscriptExpr : public Expr {
744 friend class ASTStmtReader;
745 enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 };
746 Stmt *SubExprs[NUM_SUBEXPRS];
747 SourceLocation RBracketLoc;
748
749 void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; }
750 void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; }
751
752public:
753 MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK,
754 ExprObjectKind OK, SourceLocation RBracketLoc)
755 : Expr(MSPropertySubscriptExprClass, Ty, VK, OK, Idx->isTypeDependent(),
756 Idx->isValueDependent(), Idx->isInstantiationDependent(),
757 Idx->containsUnexpandedParameterPack()),
758 RBracketLoc(RBracketLoc) {
759 SubExprs[BASE_EXPR] = Base;
760 SubExprs[IDX_EXPR] = Idx;
761 }
762
763 /// \brief Create an empty array subscript expression.
764 explicit MSPropertySubscriptExpr(EmptyShell Shell)
765 : Expr(MSPropertySubscriptExprClass, Shell) {}
766
767 Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); }
768 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); }
769
770 Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); }
771 const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); }
772
773 SourceLocation getLocStart() const LLVM_READONLY {
774 return getBase()->getLocStart();
775 }
776 SourceLocation getLocEnd() const LLVM_READONLY { return RBracketLoc; }
777
778 SourceLocation getRBracketLoc() const { return RBracketLoc; }
779 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
780
781 SourceLocation getExprLoc() const LLVM_READONLY {
782 return getBase()->getExprLoc();
783 }
784
785 static bool classof(const Stmt *T) {
786 return T->getStmtClass() == MSPropertySubscriptExprClass;
787 }
788
789 // Iterators
790 child_range children() {
791 return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
792 }
793};
794
795/// A Microsoft C++ @c __uuidof expression, which gets
796/// the _GUID that corresponds to the supplied type or expression.
797///
798/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
799class CXXUuidofExpr : public Expr {
800private:
801 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
802 StringRef UuidStr;
803 SourceRange Range;
804
805public:
806 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, StringRef UuidStr,
807 SourceRange R)
808 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
809 Operand->getType()->isDependentType(),
810 Operand->getType()->isInstantiationDependentType(),
811 Operand->getType()->containsUnexpandedParameterPack()),
812 Operand(Operand), UuidStr(UuidStr), Range(R) {}
813
814 CXXUuidofExpr(QualType Ty, Expr *Operand, StringRef UuidStr, SourceRange R)
815 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
816 Operand->isTypeDependent(), Operand->isInstantiationDependent(),
817 Operand->containsUnexpandedParameterPack()),
818 Operand(Operand), UuidStr(UuidStr), Range(R) {}
819
820 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
821 : Expr(CXXUuidofExprClass, Empty) {
822 if (isExpr)
823 Operand = (Expr*)nullptr;
824 else
825 Operand = (TypeSourceInfo*)nullptr;
826 }
827
828 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
829
830 /// \brief Retrieves the type operand of this __uuidof() expression after
831 /// various required adjustments (removing reference types, cv-qualifiers).
832 QualType getTypeOperand(ASTContext &Context) const;
833
834 /// \brief Retrieve source information for the type operand.
835 TypeSourceInfo *getTypeOperandSourceInfo() const {
836 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
837 return Operand.get<TypeSourceInfo *>();
838 }
839
840 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
841 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
842 Operand = TSI;
843 }
844
845 Expr *getExprOperand() const {
846 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
847 return static_cast<Expr*>(Operand.get<Stmt *>());
848 }
849
850 void setExprOperand(Expr *E) {
851 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
852 Operand = E;
853 }
854
855 void setUuidStr(StringRef US) { UuidStr = US; }
856 StringRef getUuidStr() const { return UuidStr; }
857
858 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
859 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
860 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
861 void setSourceRange(SourceRange R) { Range = R; }
862
863 static bool classof(const Stmt *T) {
864 return T->getStmtClass() == CXXUuidofExprClass;
865 }
866
867 // Iterators
868 child_range children() {
869 if (isTypeOperand())
870 return child_range(child_iterator(), child_iterator());
871 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
872 return child_range(begin, begin + 1);
873 }
874};
875
876/// \brief Represents the \c this expression in C++.
877///
878/// This is a pointer to the object on which the current member function is
879/// executing (C++ [expr.prim]p3). Example:
880///
881/// \code
882/// class Foo {
883/// public:
884/// void bar();
885/// void test() { this->bar(); }
886/// };
887/// \endcode
888class CXXThisExpr : public Expr {
889 SourceLocation Loc;
890 bool Implicit : 1;
891
892public:
893 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
894 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
895 // 'this' is type-dependent if the class type of the enclosing
896 // member function is dependent (C++ [temp.dep.expr]p2)
897 Type->isDependentType(), Type->isDependentType(),
898 Type->isInstantiationDependentType(),
899 /*ContainsUnexpandedParameterPack=*/false),
900 Loc(L), Implicit(isImplicit) { }
901
902 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
903
904 SourceLocation getLocation() const { return Loc; }
905 void setLocation(SourceLocation L) { Loc = L; }
906
907 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
908 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
909
910 bool isImplicit() const { return Implicit; }
911 void setImplicit(bool I) { Implicit = I; }
912
913 static bool classof(const Stmt *T) {
914 return T->getStmtClass() == CXXThisExprClass;
915 }
916
917 // Iterators
918 child_range children() {
919 return child_range(child_iterator(), child_iterator());
920 }
921};
922
923/// \brief A C++ throw-expression (C++ [except.throw]).
924///
925/// This handles 'throw' (for re-throwing the current exception) and
926/// 'throw' assignment-expression. When assignment-expression isn't
927/// present, Op will be null.
928class CXXThrowExpr : public Expr {
929 Stmt *Op;
930 SourceLocation ThrowLoc;
931 /// \brief Whether the thrown variable (if any) is in scope.
932 unsigned IsThrownVariableInScope : 1;
933
934 friend class ASTStmtReader;
935
936public:
937 // \p Ty is the void type which is used as the result type of the
938 // expression. The \p l is the location of the throw keyword. \p expr
939 // can by null, if the optional expression to throw isn't present.
940 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
941 bool IsThrownVariableInScope) :
942 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
943 expr && expr->isInstantiationDependent(),
944 expr && expr->containsUnexpandedParameterPack()),
945 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
946 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
947
948 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
949 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
950
951 SourceLocation getThrowLoc() const { return ThrowLoc; }
952
953 /// \brief Determines whether the variable thrown by this expression (if any!)
954 /// is within the innermost try block.
955 ///
956 /// This information is required to determine whether the NRVO can apply to
957 /// this variable.
958 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
959
960 SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
961 SourceLocation getLocEnd() const LLVM_READONLY {
962 if (!getSubExpr())
963 return ThrowLoc;
964 return getSubExpr()->getLocEnd();
965 }
966
967 static bool classof(const Stmt *T) {
968 return T->getStmtClass() == CXXThrowExprClass;
969 }
970
971 // Iterators
972 child_range children() {
973 return child_range(&Op, Op ? &Op+1 : &Op);
974 }
975};
976
977/// \brief A default argument (C++ [dcl.fct.default]).
978///
979/// This wraps up a function call argument that was created from the
980/// corresponding parameter's default argument, when the call did not
981/// explicitly supply arguments for all of the parameters.
982class CXXDefaultArgExpr final : public Expr {
983 /// \brief The parameter whose default is being used.
984 ParmVarDecl *Param;
985
986 /// \brief The location where the default argument expression was used.
987 SourceLocation Loc;
988
989 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
990 : Expr(SC,
991 param->hasUnparsedDefaultArg()
992 ? param->getType().getNonReferenceType()
993 : param->getDefaultArg()->getType(),
994 param->getDefaultArg()->getValueKind(),
995 param->getDefaultArg()->getObjectKind(), false, false, false, false),
996 Param(param), Loc(Loc) { }
997
998public:
999 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
1000
1001 // \p Param is the parameter whose default argument is used by this
1002 // expression.
1003 static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
1004 ParmVarDecl *Param) {
1005 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
1006 }
1007
1008 // Retrieve the parameter that the argument was created from.
1009 const ParmVarDecl *getParam() const { return Param; }
1010 ParmVarDecl *getParam() { return Param; }
1011
1012 // Retrieve the actual argument to the function call.
1013 const Expr *getExpr() const {
1014 return getParam()->getDefaultArg();
1015 }
1016 Expr *getExpr() {
1017 return getParam()->getDefaultArg();
1018 }
1019
1020 /// \brief Retrieve the location where this default argument was actually
1021 /// used.
1022 SourceLocation getUsedLocation() const { return Loc; }
1023
1024 /// Default argument expressions have no representation in the
1025 /// source, so they have an empty source range.
1026 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1027 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1028
1029 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
1030
1031 static bool classof(const Stmt *T) {
1032 return T->getStmtClass() == CXXDefaultArgExprClass;
1033 }
1034
1035 // Iterators
1036 child_range children() {
1037 return child_range(child_iterator(), child_iterator());
1038 }
1039
1040 friend class ASTStmtReader;
1041 friend class ASTStmtWriter;
1042};
1043
1044/// \brief A use of a default initializer in a constructor or in aggregate
1045/// initialization.
1046///
1047/// This wraps a use of a C++ default initializer (technically,
1048/// a brace-or-equal-initializer for a non-static data member) when it
1049/// is implicitly used in a mem-initializer-list in a constructor
1050/// (C++11 [class.base.init]p8) or in aggregate initialization
1051/// (C++1y [dcl.init.aggr]p7).
1052class CXXDefaultInitExpr : public Expr {
1053 /// \brief The field whose default is being used.
1054 FieldDecl *Field;
1055
1056 /// \brief The location where the default initializer expression was used.
1057 SourceLocation Loc;
1058
1059 CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field,
1060 QualType T);
1061
1062 CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
1063
1064public:
1065 /// \p Field is the non-static data member whose default initializer is used
1066 /// by this expression.
1067 static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc,
1068 FieldDecl *Field) {
1069 return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType());
1070 }
1071
1072 /// \brief Get the field whose initializer will be used.
1073 FieldDecl *getField() { return Field; }
1074 const FieldDecl *getField() const { return Field; }
1075
1076 /// \brief Get the initialization expression that will be used.
1077 const Expr *getExpr() const {
1078 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1079 return Field->getInClassInitializer();
1080 }
1081 Expr *getExpr() {
1082 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1083 return Field->getInClassInitializer();
1084 }
1085
1086 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1087 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1088
1089 static bool classof(const Stmt *T) {
1090 return T->getStmtClass() == CXXDefaultInitExprClass;
1091 }
1092
1093 // Iterators
1094 child_range children() {
1095 return child_range(child_iterator(), child_iterator());
1096 }
1097
1098 friend class ASTReader;
1099 friend class ASTStmtReader;
1100};
1101
1102/// \brief Represents a C++ temporary.
1103class CXXTemporary {
1104 /// \brief The destructor that needs to be called.
1105 const CXXDestructorDecl *Destructor;
1106
1107 explicit CXXTemporary(const CXXDestructorDecl *destructor)
1108 : Destructor(destructor) { }
1109
1110public:
1111 static CXXTemporary *Create(const ASTContext &C,
1112 const CXXDestructorDecl *Destructor);
1113
1114 const CXXDestructorDecl *getDestructor() const { return Destructor; }
1115 void setDestructor(const CXXDestructorDecl *Dtor) {
1116 Destructor = Dtor;
1117 }
1118};
1119
1120/// \brief Represents binding an expression to a temporary.
1121///
1122/// This ensures the destructor is called for the temporary. It should only be
1123/// needed for non-POD, non-trivially destructable class types. For example:
1124///
1125/// \code
1126/// struct S {
1127/// S() { } // User defined constructor makes S non-POD.
1128/// ~S() { } // User defined destructor makes it non-trivial.
1129/// };
1130/// void test() {
1131/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
1132/// }
1133/// \endcode
1134class CXXBindTemporaryExpr : public Expr {
1135 CXXTemporary *Temp;
1136
1137 Stmt *SubExpr;
1138
1139 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
1140 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
1141 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
1142 SubExpr->isValueDependent(),
1143 SubExpr->isInstantiationDependent(),
1144 SubExpr->containsUnexpandedParameterPack()),
1145 Temp(temp), SubExpr(SubExpr) { }
1146
1147public:
1148 CXXBindTemporaryExpr(EmptyShell Empty)
1149 : Expr(CXXBindTemporaryExprClass, Empty), Temp(nullptr), SubExpr(nullptr) {}
1150
1151 static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
1152 Expr* SubExpr);
1153
1154 CXXTemporary *getTemporary() { return Temp; }
1155 const CXXTemporary *getTemporary() const { return Temp; }
1156 void setTemporary(CXXTemporary *T) { Temp = T; }
1157
1158 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1159 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1160 void setSubExpr(Expr *E) { SubExpr = E; }
1161
1162 SourceLocation getLocStart() const LLVM_READONLY {
1163 return SubExpr->getLocStart();
1164 }
1165 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
1166
1167 // Implement isa/cast/dyncast/etc.
1168 static bool classof(const Stmt *T) {
1169 return T->getStmtClass() == CXXBindTemporaryExprClass;
1170 }
1171
1172 // Iterators
1173 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1174};
1175
1176/// \brief Represents a call to a C++ constructor.
1177class CXXConstructExpr : public Expr {
1178public:
1179 enum ConstructionKind {
1180 CK_Complete,
1181 CK_NonVirtualBase,
1182 CK_VirtualBase,
1183 CK_Delegating
1184 };
1185
1186private:
1187 CXXConstructorDecl *Constructor;
1188
1189 SourceLocation Loc;
1190 SourceRange ParenOrBraceRange;
1191 unsigned NumArgs : 16;
1192 unsigned Elidable : 1;
1193 unsigned HadMultipleCandidates : 1;
1194 unsigned ListInitialization : 1;
1195 unsigned StdInitListInitialization : 1;
1196 unsigned ZeroInitialization : 1;
1197 unsigned ConstructKind : 2;
1198 Stmt **Args;
1199
1200 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
1201
1202protected:
1203 CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T,
1204 SourceLocation Loc,
1205 CXXConstructorDecl *Ctor,
1206 bool Elidable,
1207 ArrayRef<Expr *> Args,
1208 bool HadMultipleCandidates,
1209 bool ListInitialization,
1210 bool StdInitListInitialization,
1211 bool ZeroInitialization,
1212 ConstructionKind ConstructKind,
1213 SourceRange ParenOrBraceRange);
1214
1215 /// \brief Construct an empty C++ construction expression.
1216 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
1217 : Expr(SC, Empty), Constructor(nullptr), NumArgs(0), Elidable(false),
1218 HadMultipleCandidates(false), ListInitialization(false),
1219 ZeroInitialization(false), ConstructKind(0), Args(nullptr)
1220 { }
1221
1222public:
1223 /// \brief Construct an empty C++ construction expression.
1224 explicit CXXConstructExpr(EmptyShell Empty)
1225 : CXXConstructExpr(CXXConstructExprClass, Empty) {}
1226
1227 static CXXConstructExpr *Create(const ASTContext &C, QualType T,
1228 SourceLocation Loc,
1229 CXXConstructorDecl *Ctor,
1230 bool Elidable,
1231 ArrayRef<Expr *> Args,
1232 bool HadMultipleCandidates,
1233 bool ListInitialization,
1234 bool StdInitListInitialization,
1235 bool ZeroInitialization,
1236 ConstructionKind ConstructKind,
1237 SourceRange ParenOrBraceRange);
1238
1239 /// \brief Get the constructor that this expression will (ultimately) call.
1240 CXXConstructorDecl *getConstructor() const { return Constructor; }
1241
1242 SourceLocation getLocation() const { return Loc; }
1243 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
1244
1245 /// \brief Whether this construction is elidable.
1246 bool isElidable() const { return Elidable; }
1247 void setElidable(bool E) { Elidable = E; }
1248
1249 /// \brief Whether the referred constructor was resolved from
1250 /// an overloaded set having size greater than 1.
1251 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
1252 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
1253
1254 /// \brief Whether this constructor call was written as list-initialization.
1255 bool isListInitialization() const { return ListInitialization; }
1256 void setListInitialization(bool V) { ListInitialization = V; }
1257
1258 /// \brief Whether this constructor call was written as list-initialization,
1259 /// but was interpreted as forming a std::initializer_list<T> from the list
1260 /// and passing that as a single constructor argument.
1261 /// See C++11 [over.match.list]p1 bullet 1.
1262 bool isStdInitListInitialization() const { return StdInitListInitialization; }
1263 void setStdInitListInitialization(bool V) { StdInitListInitialization = V; }
1264
1265 /// \brief Whether this construction first requires
1266 /// zero-initialization before the initializer is called.
1267 bool requiresZeroInitialization() const { return ZeroInitialization; }
1268 void setRequiresZeroInitialization(bool ZeroInit) {
1269 ZeroInitialization = ZeroInit;
1270 }
1271
1272 /// \brief Determine whether this constructor is actually constructing
1273 /// a base class (rather than a complete object).
1274 ConstructionKind getConstructionKind() const {
1275 return (ConstructionKind)ConstructKind;
1276 }
1277 void setConstructionKind(ConstructionKind CK) {
1278 ConstructKind = CK;
1279 }
1280
1281 typedef ExprIterator arg_iterator;
1282 typedef ConstExprIterator const_arg_iterator;
1283 typedef llvm::iterator_range<arg_iterator> arg_range;
1284 typedef llvm::iterator_range<const_arg_iterator> arg_const_range;
1285
1286 arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
1287 arg_const_range arguments() const {
1288 return arg_const_range(arg_begin(), arg_end());
1289 }
1290
1291 arg_iterator arg_begin() { return Args; }
1292 arg_iterator arg_end() { return Args + NumArgs; }
1293 const_arg_iterator arg_begin() const { return Args; }
1294 const_arg_iterator arg_end() const { return Args + NumArgs; }
1295
1296 Expr **getArgs() { return reinterpret_cast<Expr **>(Args); }
1297 const Expr *const *getArgs() const {
1298 return const_cast<CXXConstructExpr *>(this)->getArgs();
1299 }
1300 unsigned getNumArgs() const { return NumArgs; }
1301
1302 /// \brief Return the specified argument.
1303 Expr *getArg(unsigned Arg) {
1304 assert(Arg < NumArgs && "Arg access out of range!");
1305 return cast<Expr>(Args[Arg]);
1306 }
1307 const Expr *getArg(unsigned Arg) const {
1308 assert(Arg < NumArgs && "Arg access out of range!");
1309 return cast<Expr>(Args[Arg]);
1310 }
1311
1312 /// \brief Set the specified argument.
1313 void setArg(unsigned Arg, Expr *ArgExpr) {
1314 assert(Arg < NumArgs && "Arg access out of range!");
1315 Args[Arg] = ArgExpr;
1316 }
1317
1318 SourceLocation getLocStart() const LLVM_READONLY;
1319 SourceLocation getLocEnd() const LLVM_READONLY;
1320 SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
1321 void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
1322
1323 static bool classof(const Stmt *T) {
1324 return T->getStmtClass() == CXXConstructExprClass ||
1325 T->getStmtClass() == CXXTemporaryObjectExprClass;
1326 }
1327
1328 // Iterators
1329 child_range children() {
1330 return child_range(&Args[0], &Args[0]+NumArgs);
1331 }
1332
1333 friend class ASTStmtReader;
1334};
1335
1336/// \brief Represents a call to an inherited base class constructor from an
1337/// inheriting constructor. This call implicitly forwards the arguments from
1338/// the enclosing context (an inheriting constructor) to the specified inherited
1339/// base class constructor.
1340class CXXInheritedCtorInitExpr : public Expr {
1341private:
1342 CXXConstructorDecl *Constructor;
1343
1344 /// The location of the using declaration.
1345 SourceLocation Loc;
1346
1347 /// Whether this is the construction of a virtual base.
1348 unsigned ConstructsVirtualBase : 1;
1349
1350 /// Whether the constructor is inherited from a virtual base class of the
1351 /// class that we construct.
1352 unsigned InheritedFromVirtualBase : 1;
1353
1354public:
1355 /// \brief Construct a C++ inheriting construction expression.
1356 CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T,
1357 CXXConstructorDecl *Ctor, bool ConstructsVirtualBase,
1358 bool InheritedFromVirtualBase)
1359 : Expr(CXXInheritedCtorInitExprClass, T, VK_RValue, OK_Ordinary, false,
1360 false, false, false),
1361 Constructor(Ctor), Loc(Loc),
1362 ConstructsVirtualBase(ConstructsVirtualBase),
1363 InheritedFromVirtualBase(InheritedFromVirtualBase) {
1364 assert(!T->isDependentType());
1365 }
1366
1367 /// \brief Construct an empty C++ inheriting construction expression.
1368 explicit CXXInheritedCtorInitExpr(EmptyShell Empty)
1369 : Expr(CXXInheritedCtorInitExprClass, Empty), Constructor(nullptr),
1370 ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {}
1371
1372 /// \brief Get the constructor that this expression will call.
1373 CXXConstructorDecl *getConstructor() const { return Constructor; }
1374
1375 /// \brief Determine whether this constructor is actually constructing
1376 /// a base class (rather than a complete object).
1377 bool constructsVBase() const { return ConstructsVirtualBase; }
1378 CXXConstructExpr::ConstructionKind getConstructionKind() const {
1379 return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase
1380 : CXXConstructExpr::CK_NonVirtualBase;
1381 }
1382
1383 /// \brief Determine whether the inherited constructor is inherited from a
1384 /// virtual base of the object we construct. If so, we are not responsible
1385 /// for calling the inherited constructor (the complete object constructor
1386 /// does that), and so we don't need to pass any arguments.
1387 bool inheritedFromVBase() const { return InheritedFromVirtualBase; }
1388
1389 SourceLocation getLocation() const LLVM_READONLY { return Loc; }
1390 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1391 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1392
1393 static bool classof(const Stmt *T) {
1394 return T->getStmtClass() == CXXInheritedCtorInitExprClass;
1395 }
1396 child_range children() {
1397 return child_range(child_iterator(), child_iterator());
1398 }
1399
1400 friend class ASTStmtReader;
1401};
1402
1403/// \brief Represents an explicit C++ type conversion that uses "functional"
1404/// notation (C++ [expr.type.conv]).
1405///
1406/// Example:
1407/// \code
1408/// x = int(0.5);
1409/// \endcode
1410class CXXFunctionalCastExpr final
1411 : public ExplicitCastExpr,
1412 private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *> {
1413 SourceLocation LParenLoc;
1414 SourceLocation RParenLoc;
1415
1416 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1417 TypeSourceInfo *writtenTy,
1418 CastKind kind, Expr *castExpr, unsigned pathSize,
1419 SourceLocation lParenLoc, SourceLocation rParenLoc)
1420 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1421 castExpr, pathSize, writtenTy),
1422 LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
1423
1424 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1425 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1426
1427public:
1428 static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
1429 ExprValueKind VK,
1430 TypeSourceInfo *Written,
1431 CastKind Kind, Expr *Op,
1432 const CXXCastPath *Path,
1433 SourceLocation LPLoc,
1434 SourceLocation RPLoc);
1435 static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
1436 unsigned PathSize);
1437
1438 SourceLocation getLParenLoc() const { return LParenLoc; }
1439 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1440 SourceLocation getRParenLoc() const { return RParenLoc; }
1441 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1442
1443 SourceLocation getLocStart() const LLVM_READONLY;
1444 SourceLocation getLocEnd() const LLVM_READONLY;
1445
1446 static bool classof(const Stmt *T) {
1447 return T->getStmtClass() == CXXFunctionalCastExprClass;
1448 }
1449
1450 friend TrailingObjects;
1451 friend class CastExpr;
1452};
1453
1454/// @brief Represents a C++ functional cast expression that builds a
1455/// temporary object.
1456///
1457/// This expression type represents a C++ "functional" cast
1458/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1459/// constructor to build a temporary object. With N == 1 arguments the
1460/// functional cast expression will be represented by CXXFunctionalCastExpr.
1461/// Example:
1462/// \code
1463/// struct X { X(int, float); }
1464///
1465/// X create_X() {
1466/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1467/// };
1468/// \endcode
1469class CXXTemporaryObjectExpr : public CXXConstructExpr {
1470 TypeSourceInfo *Type;
1471
1472public:
1473 CXXTemporaryObjectExpr(const ASTContext &C,
1474 CXXConstructorDecl *Cons,
1475 QualType Type,
1476 TypeSourceInfo *TSI,
1477 ArrayRef<Expr *> Args,
1478 SourceRange ParenOrBraceRange,
1479 bool HadMultipleCandidates,
1480 bool ListInitialization,
1481 bool StdInitListInitialization,
1482 bool ZeroInitialization);
1483 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1484 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1485
1486 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1487
1488 SourceLocation getLocStart() const LLVM_READONLY;
1489 SourceLocation getLocEnd() const LLVM_READONLY;
1490
1491 static bool classof(const Stmt *T) {
1492 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1493 }
1494
1495 friend class ASTStmtReader;
1496};
1497
1498/// \brief A C++ lambda expression, which produces a function object
1499/// (of unspecified type) that can be invoked later.
1500///
1501/// Example:
1502/// \code
1503/// void low_pass_filter(std::vector<double> &values, double cutoff) {
1504/// values.erase(std::remove_if(values.begin(), values.end(),
1505/// [=](double value) { return value > cutoff; });
1506/// }
1507/// \endcode
1508///
1509/// C++11 lambda expressions can capture local variables, either by copying
1510/// the values of those local variables at the time the function
1511/// object is constructed (not when it is called!) or by holding a
1512/// reference to the local variable. These captures can occur either
1513/// implicitly or can be written explicitly between the square
1514/// brackets ([...]) that start the lambda expression.
1515///
1516/// C++1y introduces a new form of "capture" called an init-capture that
1517/// includes an initializing expression (rather than capturing a variable),
1518/// and which can never occur implicitly.
1519class LambdaExpr final : public Expr,
1520 private llvm::TrailingObjects<LambdaExpr, Stmt *> {
1521 /// \brief The source range that covers the lambda introducer ([...]).
1522 SourceRange IntroducerRange;
1523
1524 /// \brief The source location of this lambda's capture-default ('=' or '&').
1525 SourceLocation CaptureDefaultLoc;
1526
1527 /// \brief The number of captures.
1528 unsigned NumCaptures : 16;
1529
1530 /// \brief The default capture kind, which is a value of type
1531 /// LambdaCaptureDefault.
1532 unsigned CaptureDefault : 2;
1533
1534 /// \brief Whether this lambda had an explicit parameter list vs. an
1535 /// implicit (and empty) parameter list.
1536 unsigned ExplicitParams : 1;
1537
1538 /// \brief Whether this lambda had the result type explicitly specified.
1539 unsigned ExplicitResultType : 1;
1540
1541 /// \brief The location of the closing brace ('}') that completes
1542 /// the lambda.
1543 ///
1544 /// The location of the brace is also available by looking up the
1545 /// function call operator in the lambda class. However, it is
1546 /// stored here to improve the performance of getSourceRange(), and
1547 /// to avoid having to deserialize the function call operator from a
1548 /// module file just to determine the source range.
1549 SourceLocation ClosingBrace;
1550
1551 /// \brief Construct a lambda expression.
1552 LambdaExpr(QualType T, SourceRange IntroducerRange,
1553 LambdaCaptureDefault CaptureDefault,
1554 SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
1555 bool ExplicitParams, bool ExplicitResultType,
1556 ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace,
1557 bool ContainsUnexpandedParameterPack);
1558
1559 /// \brief Construct an empty lambda expression.
1560 LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
1561 : Expr(LambdaExprClass, Empty),
1562 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
1563 ExplicitResultType(false) {
1564 getStoredStmts()[NumCaptures] = nullptr;
1565 }
1566
1567 Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
1568
1569 Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); }
1570
1571public:
1572 /// \brief Construct a new lambda expression.
1573 static LambdaExpr *
1574 Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange,
1575 LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc,
1576 ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
1577 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1578 SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack);
1579
1580 /// \brief Construct a new lambda expression that will be deserialized from
1581 /// an external source.
1582 static LambdaExpr *CreateDeserialized(const ASTContext &C,
1583 unsigned NumCaptures);
1584
1585 /// \brief Determine the default capture kind for this lambda.
1586 LambdaCaptureDefault getCaptureDefault() const {
1587 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1588 }
1589
1590 /// \brief Retrieve the location of this lambda's capture-default, if any.
1591 SourceLocation getCaptureDefaultLoc() const {
1592 return CaptureDefaultLoc;
1593 }
1594
1595 /// \brief Determine whether one of this lambda's captures is an init-capture.
1596 bool isInitCapture(const LambdaCapture *Capture) const;
1597
1598 /// \brief An iterator that walks over the captures of the lambda,
1599 /// both implicit and explicit.
1600 typedef const LambdaCapture *capture_iterator;
1601
1602 /// \brief An iterator over a range of lambda captures.
1603 typedef llvm::iterator_range<capture_iterator> capture_range;
1604
1605 /// \brief Retrieve this lambda's captures.
1606 capture_range captures() const;
1607
1608 /// \brief Retrieve an iterator pointing to the first lambda capture.
1609 capture_iterator capture_begin() const;
1610
1611 /// \brief Retrieve an iterator pointing past the end of the
1612 /// sequence of lambda captures.
1613 capture_iterator capture_end() const;
1614
1615 /// \brief Determine the number of captures in this lambda.
1616 unsigned capture_size() const { return NumCaptures; }
1617
1618 /// \brief Retrieve this lambda's explicit captures.
1619 capture_range explicit_captures() const;
1620
1621 /// \brief Retrieve an iterator pointing to the first explicit
1622 /// lambda capture.
1623 capture_iterator explicit_capture_begin() const;
1624
1625 /// \brief Retrieve an iterator pointing past the end of the sequence of
1626 /// explicit lambda captures.
1627 capture_iterator explicit_capture_end() const;
1628
1629 /// \brief Retrieve this lambda's implicit captures.
1630 capture_range implicit_captures() const;
1631
1632 /// \brief Retrieve an iterator pointing to the first implicit
1633 /// lambda capture.
1634 capture_iterator implicit_capture_begin() const;
1635
1636 /// \brief Retrieve an iterator pointing past the end of the sequence of
1637 /// implicit lambda captures.
1638 capture_iterator implicit_capture_end() const;
1639
1640 /// \brief Iterator that walks over the capture initialization
1641 /// arguments.
1642 typedef Expr **capture_init_iterator;
1643
1644 /// \brief Const iterator that walks over the capture initialization
1645 /// arguments.
1646 typedef Expr *const *const_capture_init_iterator;
1647
1648 /// \brief Retrieve the initialization expressions for this lambda's captures.
1649 llvm::iterator_range<capture_init_iterator> capture_inits() {
1650 return llvm::make_range(capture_init_begin(), capture_init_end());
1651 }
1652
1653 /// \brief Retrieve the initialization expressions for this lambda's captures.
1654 llvm::iterator_range<const_capture_init_iterator> capture_inits() const {
1655 return llvm::make_range(capture_init_begin(), capture_init_end());
1656 }
1657
1658 /// \brief Retrieve the first initialization argument for this
1659 /// lambda expression (which initializes the first capture field).
1660 capture_init_iterator capture_init_begin() {
1661 return reinterpret_cast<Expr **>(getStoredStmts());
1662 }
1663
1664 /// \brief Retrieve the first initialization argument for this
1665 /// lambda expression (which initializes the first capture field).
1666 const_capture_init_iterator capture_init_begin() const {
1667 return reinterpret_cast<Expr *const *>(getStoredStmts());
1668 }
1669
1670 /// \brief Retrieve the iterator pointing one past the last
1671 /// initialization argument for this lambda expression.
1672 capture_init_iterator capture_init_end() {
1673 return capture_init_begin() + NumCaptures;
1674 }
1675
1676 /// \brief Retrieve the iterator pointing one past the last
1677 /// initialization argument for this lambda expression.
1678 const_capture_init_iterator capture_init_end() const {
1679 return capture_init_begin() + NumCaptures;
1680 }
1681
1682 /// \brief Retrieve the source range covering the lambda introducer,
1683 /// which contains the explicit capture list surrounded by square
1684 /// brackets ([...]).
1685 SourceRange getIntroducerRange() const { return IntroducerRange; }
1686
1687 /// \brief Retrieve the class that corresponds to the lambda.
1688 ///
1689 /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
1690 /// captures in its fields and provides the various operations permitted
1691 /// on a lambda (copying, calling).
1692 CXXRecordDecl *getLambdaClass() const;
1693
1694 /// \brief Retrieve the function call operator associated with this
1695 /// lambda expression.
1696 CXXMethodDecl *getCallOperator() const;
1697
1698 /// \brief If this is a generic lambda expression, retrieve the template
1699 /// parameter list associated with it, or else return null.
1700 TemplateParameterList *getTemplateParameterList() const;
1701
1702 /// \brief Whether this is a generic lambda.
1703 bool isGenericLambda() const { return getTemplateParameterList(); }
1704
1705 /// \brief Retrieve the body of the lambda.
1706 CompoundStmt *getBody() const;
1707
1708 /// \brief Determine whether the lambda is mutable, meaning that any
1709 /// captures values can be modified.
1710 bool isMutable() const;
1711
1712 /// \brief Determine whether this lambda has an explicit parameter
1713 /// list vs. an implicit (empty) parameter list.
1714 bool hasExplicitParameters() const { return ExplicitParams; }
1715
1716 /// \brief Whether this lambda had its result type explicitly specified.
1717 bool hasExplicitResultType() const { return ExplicitResultType; }
1718
1719 static bool classof(const Stmt *T) {
1720 return T->getStmtClass() == LambdaExprClass;
1721 }
1722
1723 SourceLocation getLocStart() const LLVM_READONLY {
1724 return IntroducerRange.getBegin();
1725 }
1726 SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
1727
1728 child_range children() {
1729 // Includes initialization exprs plus body stmt
1730 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1731 }
1732
1733 friend TrailingObjects;
1734 friend class ASTStmtReader;
1735 friend class ASTStmtWriter;
1736};
1737
1738/// An expression "T()" which creates a value-initialized rvalue of type
1739/// T, which is a non-class type. See (C++98 [5.2.3p2]).
1740class CXXScalarValueInitExpr : public Expr {
1741 SourceLocation RParenLoc;
1742 TypeSourceInfo *TypeInfo;
1743
1744 friend class ASTStmtReader;
1745
1746public:
1747 /// \brief Create an explicitly-written scalar-value initialization
1748 /// expression.
1749 CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
1750 SourceLocation rParenLoc)
1751 : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1752 false, false, Type->isInstantiationDependentType(),
1753 Type->containsUnexpandedParameterPack()),
1754 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1755
1756 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1757 : Expr(CXXScalarValueInitExprClass, Shell) { }
1758
1759 TypeSourceInfo *getTypeSourceInfo() const {
1760 return TypeInfo;
1761 }
1762
1763 SourceLocation getRParenLoc() const { return RParenLoc; }
1764
1765 SourceLocation getLocStart() const LLVM_READONLY;
1766 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1767
1768 static bool classof(const Stmt *T) {
1769 return T->getStmtClass() == CXXScalarValueInitExprClass;
1770 }
1771
1772 // Iterators
1773 child_range children() {
1774 return child_range(child_iterator(), child_iterator());
1775 }
1776};
1777
1778/// \brief Represents a new-expression for memory allocation and constructor
1779/// calls, e.g: "new CXXNewExpr(foo)".
1780class CXXNewExpr : public Expr {
1781 /// Contains an optional array size expression, an optional initialization
1782 /// expression, and any number of optional placement arguments, in that order.
1783 Stmt **SubExprs;
1784 /// \brief Points to the allocation function used.
1785 FunctionDecl *OperatorNew;
1786 /// \brief Points to the deallocation function used in case of error. May be
1787 /// null.
1788 FunctionDecl *OperatorDelete;
1789
1790 /// \brief The allocated type-source information, as written in the source.
1791 TypeSourceInfo *AllocatedTypeInfo;
1792
1793 /// \brief If the allocated type was expressed as a parenthesized type-id,
1794 /// the source range covering the parenthesized type-id.
1795 SourceRange TypeIdParens;
1796
1797 /// \brief Range of the entire new expression.
1798 SourceRange Range;
1799
1800 /// \brief Source-range of a paren-delimited initializer.
1801 SourceRange DirectInitRange;
1802
1803 /// Was the usage ::new, i.e. is the global new to be used?
1804 unsigned GlobalNew : 1;
1805 /// Do we allocate an array? If so, the first SubExpr is the size expression.
1806 unsigned Array : 1;
1807 /// Should the alignment be passed to the allocation function?
1808 unsigned PassAlignment : 1;
1809 /// If this is an array allocation, does the usual deallocation
1810 /// function for the allocated type want to know the allocated size?
1811 unsigned UsualArrayDeleteWantsSize : 1;
1812 /// The number of placement new arguments.
1813 unsigned NumPlacementArgs : 26;
1814 /// What kind of initializer do we have? Could be none, parens, or braces.
1815 /// In storage, we distinguish between "none, and no initializer expr", and
1816 /// "none, but an implicit initializer expr".
1817 unsigned StoredInitializationStyle : 2;
1818
1819 friend class ASTStmtReader;
1820 friend class ASTStmtWriter;
1821public:
1822 enum InitializationStyle {
1823 NoInit, ///< New-expression has no initializer as written.
1824 CallInit, ///< New-expression has a C++98 paren-delimited initializer.
1825 ListInit ///< New-expression has a C++11 list-initializer.
1826 };
1827
1828 CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1829 FunctionDecl *operatorDelete, bool PassAlignment,
1830 bool usualArrayDeleteWantsSize, ArrayRef<Expr*> placementArgs,
1831 SourceRange typeIdParens, Expr *arraySize,
1832 InitializationStyle initializationStyle, Expr *initializer,
1833 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1834 SourceRange Range, SourceRange directInitRange);
1835 explicit CXXNewExpr(EmptyShell Shell)
1836 : Expr(CXXNewExprClass, Shell), SubExprs(nullptr) { }
1837
1838 void AllocateArgsArray(const ASTContext &C, bool isArray,
1839 unsigned numPlaceArgs, bool hasInitializer);
1840
1841 QualType getAllocatedType() const {
1842 assert(getType()->isPointerType());
1843 return getType()->getAs<PointerType>()->getPointeeType();
1844 }
1845
1846 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1847 return AllocatedTypeInfo;
1848 }
1849
1850 /// \brief True if the allocation result needs to be null-checked.
1851 ///
1852 /// C++11 [expr.new]p13:
1853 /// If the allocation function returns null, initialization shall
1854 /// not be done, the deallocation function shall not be called,
1855 /// and the value of the new-expression shall be null.
1856 ///
1857 /// C++ DR1748:
1858 /// If the allocation function is a reserved placement allocation
1859 /// function that returns null, the behavior is undefined.
1860 ///
1861 /// An allocation function is not allowed to return null unless it
1862 /// has a non-throwing exception-specification. The '03 rule is
1863 /// identical except that the definition of a non-throwing
1864 /// exception specification is just "is it throw()?".
1865 bool shouldNullCheckAllocation(const ASTContext &Ctx) const;
1866
1867 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1868 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1869 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1870 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1871
1872 bool isArray() const { return Array; }
1873 Expr *getArraySize() {
1874 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1875 }
1876 const Expr *getArraySize() const {
1877 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1878 }
1879
1880 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1881 Expr **getPlacementArgs() {
1882 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1883 }
1884
1885 Expr *getPlacementArg(unsigned i) {
1886 assert(i < NumPlacementArgs && "Index out of range");
1887 return getPlacementArgs()[i];
1888 }
1889 const Expr *getPlacementArg(unsigned i) const {
1890 assert(i < NumPlacementArgs && "Index out of range");
1891 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1892 }
1893
1894 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1895 SourceRange getTypeIdParens() const { return TypeIdParens; }
1896
1897 bool isGlobalNew() const { return GlobalNew; }
1898
1899 /// \brief Whether this new-expression has any initializer at all.
1900 bool hasInitializer() const { return StoredInitializationStyle > 0; }
1901
1902 /// \brief The kind of initializer this new-expression has.
1903 InitializationStyle getInitializationStyle() const {
1904 if (StoredInitializationStyle == 0)
1905 return NoInit;
1906 return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1907 }
1908
1909 /// \brief The initializer of this new-expression.
1910 Expr *getInitializer() {
1911 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1912 }
1913 const Expr *getInitializer() const {
1914 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1915 }
1916
1917 /// \brief Returns the CXXConstructExpr from this new-expression, or null.
1918 const CXXConstructExpr *getConstructExpr() const {
1919 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1920 }
1921
1922 /// Indicates whether the required alignment should be implicitly passed to
1923 /// the allocation function.
1924 bool passAlignment() const {
1925 return PassAlignment;
1926 }
1927
1928 /// Answers whether the usual array deallocation function for the
1929 /// allocated type expects the size of the allocation as a
1930 /// parameter.
1931 bool doesUsualArrayDeleteWantSize() const {
1932 return UsualArrayDeleteWantsSize;
1933 }
1934
1935 typedef ExprIterator arg_iterator;
1936 typedef ConstExprIterator const_arg_iterator;
1937
1938 llvm::iterator_range<arg_iterator> placement_arguments() {
1939 return llvm::make_range(placement_arg_begin(), placement_arg_end());
1940 }
1941
1942 llvm::iterator_range<const_arg_iterator> placement_arguments() const {
1943 return llvm::make_range(placement_arg_begin(), placement_arg_end());
1944 }
1945
1946 arg_iterator placement_arg_begin() {
1947 return SubExprs + Array + hasInitializer();
1948 }
1949 arg_iterator placement_arg_end() {
1950 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1951 }
1952 const_arg_iterator placement_arg_begin() const {
1953 return SubExprs + Array + hasInitializer();
1954 }
1955 const_arg_iterator placement_arg_end() const {
1956 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1957 }
1958
1959 typedef Stmt **raw_arg_iterator;
1960 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1961 raw_arg_iterator raw_arg_end() {
1962 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1963 }
1964 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1965 const_arg_iterator raw_arg_end() const {
1966 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1967 }
1968
1969 SourceLocation getStartLoc() const { return Range.getBegin(); }
1970 SourceLocation getEndLoc() const { return Range.getEnd(); }
1971
1972 SourceRange getDirectInitRange() const { return DirectInitRange; }
1973
1974 SourceRange getSourceRange() const LLVM_READONLY {
1975 return Range;
1976 }
1977 SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
1978 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1979
1980 static bool classof(const Stmt *T) {
1981 return T->getStmtClass() == CXXNewExprClass;
1982 }
1983
1984 // Iterators
1985 child_range children() {
1986 return child_range(raw_arg_begin(), raw_arg_end());
1987 }
1988};
1989
1990/// \brief Represents a \c delete expression for memory deallocation and
1991/// destructor calls, e.g. "delete[] pArray".
1992class CXXDeleteExpr : public Expr {
1993 /// Points to the operator delete overload that is used. Could be a member.
1994 FunctionDecl *OperatorDelete;
1995 /// The pointer expression to be deleted.
1996 Stmt *Argument;
1997 /// Location of the expression.
1998 SourceLocation Loc;
1999 /// Is this a forced global delete, i.e. "::delete"?
2000 bool GlobalDelete : 1;
2001 /// Is this the array form of delete, i.e. "delete[]"?
2002 bool ArrayForm : 1;
2003 /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
2004 /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
2005 /// will be true).
2006 bool ArrayFormAsWritten : 1;
2007 /// Does the usual deallocation function for the element type require
2008 /// a size_t argument?
2009 bool UsualArrayDeleteWantsSize : 1;
2010public:
2011 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
2012 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
2013 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
2014 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
2015 arg->isInstantiationDependent(),
2016 arg->containsUnexpandedParameterPack()),
2017 OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
2018 GlobalDelete(globalDelete),
2019 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
2020 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
2021 explicit CXXDeleteExpr(EmptyShell Shell)
2022 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(nullptr),
2023 Argument(nullptr) {}
2024
2025 bool isGlobalDelete() const { return GlobalDelete; }
2026 bool isArrayForm() const { return ArrayForm; }
2027 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
2028
2029 /// Answers whether the usual array deallocation function for the
2030 /// allocated type expects the size of the allocation as a
2031 /// parameter. This can be true even if the actual deallocation
2032 /// function that we're using doesn't want a size.
2033 bool doesUsualArrayDeleteWantSize() const {
2034 return UsualArrayDeleteWantsSize;
2035 }
2036
2037 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2038
2039 Expr *getArgument() { return cast<Expr>(Argument); }
2040 const Expr *getArgument() const { return cast<Expr>(Argument); }
2041
2042 /// \brief Retrieve the type being destroyed.
2043 ///
2044 /// If the type being destroyed is a dependent type which may or may not
2045 /// be a pointer, return an invalid type.
2046 QualType getDestroyedType() const;
2047
2048 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2049 SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
2050
2051 static bool classof(const Stmt *T) {
2052 return T->getStmtClass() == CXXDeleteExprClass;
2053 }
2054
2055 // Iterators
2056 child_range children() { return child_range(&Argument, &Argument+1); }
2057
2058 friend class ASTStmtReader;
2059};
2060
2061/// \brief Stores the type being destroyed by a pseudo-destructor expression.
2062class PseudoDestructorTypeStorage {
2063 /// \brief Either the type source information or the name of the type, if
2064 /// it couldn't be resolved due to type-dependence.
2065 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
2066
2067 /// \brief The starting source location of the pseudo-destructor type.
2068 SourceLocation Location;
2069
2070public:
2071 PseudoDestructorTypeStorage() { }
2072
2073 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
2074 : Type(II), Location(Loc) { }
2075
2076 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
2077
2078 TypeSourceInfo *getTypeSourceInfo() const {
2079 return Type.dyn_cast<TypeSourceInfo *>();
2080 }
2081
2082 IdentifierInfo *getIdentifier() const {
2083 return Type.dyn_cast<IdentifierInfo *>();
2084 }
2085
2086 SourceLocation getLocation() const { return Location; }
2087};
2088
2089/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
2090///
2091/// A pseudo-destructor is an expression that looks like a member access to a
2092/// destructor of a scalar type, except that scalar types don't have
2093/// destructors. For example:
2094///
2095/// \code
2096/// typedef int T;
2097/// void f(int *p) {
2098/// p->T::~T();
2099/// }
2100/// \endcode
2101///
2102/// Pseudo-destructors typically occur when instantiating templates such as:
2103///
2104/// \code
2105/// template<typename T>
2106/// void destroy(T* ptr) {
2107/// ptr->T::~T();
2108/// }
2109/// \endcode
2110///
2111/// for scalar types. A pseudo-destructor expression has no run-time semantics
2112/// beyond evaluating the base expression.
2113class CXXPseudoDestructorExpr : public Expr {
2114 /// \brief The base expression (that is being destroyed).
2115 Stmt *Base;
2116
2117 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
2118 /// period ('.').
2119 bool IsArrow : 1;
2120
2121 /// \brief The location of the '.' or '->' operator.
2122 SourceLocation OperatorLoc;
2123
2124 /// \brief The nested-name-specifier that follows the operator, if present.
2125 NestedNameSpecifierLoc QualifierLoc;
2126
2127 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
2128 /// expression.
2129 TypeSourceInfo *ScopeType;
2130
2131 /// \brief The location of the '::' in a qualified pseudo-destructor
2132 /// expression.
2133 SourceLocation ColonColonLoc;
2134
2135 /// \brief The location of the '~'.
2136 SourceLocation TildeLoc;
2137
2138 /// \brief The type being destroyed, or its name if we were unable to
2139 /// resolve the name.
2140 PseudoDestructorTypeStorage DestroyedType;
2141
2142 friend class ASTStmtReader;
2143
2144public:
2145 CXXPseudoDestructorExpr(const ASTContext &Context,
2146 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
2147 NestedNameSpecifierLoc QualifierLoc,
2148 TypeSourceInfo *ScopeType,
2149 SourceLocation ColonColonLoc,
2150 SourceLocation TildeLoc,
2151 PseudoDestructorTypeStorage DestroyedType);
2152
2153 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
2154 : Expr(CXXPseudoDestructorExprClass, Shell),
2155 Base(nullptr), IsArrow(false), QualifierLoc(), ScopeType(nullptr) { }
2156
2157 Expr *getBase() const { return cast<Expr>(Base); }
2158
2159 /// \brief Determines whether this member expression actually had
2160 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2161 /// x->Base::foo.
2162 bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
2163
2164 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
2165 /// with source-location information.
2166 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2167
2168 /// \brief If the member name was qualified, retrieves the
2169 /// nested-name-specifier that precedes the member name. Otherwise, returns
2170 /// null.
2171 NestedNameSpecifier *getQualifier() const {
2172 return QualifierLoc.getNestedNameSpecifier();
2173 }
2174
2175 /// \brief Determine whether this pseudo-destructor expression was written
2176 /// using an '->' (otherwise, it used a '.').
2177 bool isArrow() const { return IsArrow; }
2178
2179 /// \brief Retrieve the location of the '.' or '->' operator.
2180 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2181
2182 /// \brief Retrieve the scope type in a qualified pseudo-destructor
2183 /// expression.
2184 ///
2185 /// Pseudo-destructor expressions can have extra qualification within them
2186 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2187 /// Here, if the object type of the expression is (or may be) a scalar type,
2188 /// \p T may also be a scalar type and, therefore, cannot be part of a
2189 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2190 /// destructor expression.
2191 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2192
2193 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
2194 /// expression.
2195 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2196
2197 /// \brief Retrieve the location of the '~'.
2198 SourceLocation getTildeLoc() const { return TildeLoc; }
2199
2200 /// \brief Retrieve the source location information for the type
2201 /// being destroyed.
2202 ///
2203 /// This type-source information is available for non-dependent
2204 /// pseudo-destructor expressions and some dependent pseudo-destructor
2205 /// expressions. Returns null if we only have the identifier for a
2206 /// dependent pseudo-destructor expression.
2207 TypeSourceInfo *getDestroyedTypeInfo() const {
2208 return DestroyedType.getTypeSourceInfo();
2209 }
2210
2211 /// \brief In a dependent pseudo-destructor expression for which we do not
2212 /// have full type information on the destroyed type, provides the name
2213 /// of the destroyed type.
2214 IdentifierInfo *getDestroyedTypeIdentifier() const {
2215 return DestroyedType.getIdentifier();
2216 }
2217
2218 /// \brief Retrieve the type being destroyed.
2219 QualType getDestroyedType() const;
2220
2221 /// \brief Retrieve the starting location of the type being destroyed.
2222 SourceLocation getDestroyedTypeLoc() const {
2223 return DestroyedType.getLocation();
2224 }
2225
2226 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
2227 /// expression.
2228 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2229 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2230 }
2231
2232 /// \brief Set the destroyed type.
2233 void setDestroyedType(TypeSourceInfo *Info) {
2234 DestroyedType = PseudoDestructorTypeStorage(Info);
2235 }
2236
2237 SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
2238 SourceLocation getLocEnd() const LLVM_READONLY;
2239
2240 static bool classof(const Stmt *T) {
2241 return T->getStmtClass() == CXXPseudoDestructorExprClass;
2242 }
2243
2244 // Iterators
2245 child_range children() { return child_range(&Base, &Base + 1); }
2246};
2247
2248/// \brief A type trait used in the implementation of various C++11 and
2249/// Library TR1 trait templates.
2250///
2251/// \code
2252/// __is_pod(int) == true
2253/// __is_enum(std::string) == false
2254/// __is_trivially_constructible(vector<int>, int*, int*)
2255/// \endcode
2256class TypeTraitExpr final
2257 : public Expr,
2258 private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
2259 /// \brief The location of the type trait keyword.
2260 SourceLocation Loc;
2261
2262 /// \brief The location of the closing parenthesis.
2263 SourceLocation RParenLoc;
2264
2265 // Note: The TypeSourceInfos for the arguments are allocated after the
2266 // TypeTraitExpr.
2267
2268 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2269 ArrayRef<TypeSourceInfo *> Args,
2270 SourceLocation RParenLoc,
2271 bool Value);
2272
2273 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
2274
2275 size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
2276 return getNumArgs();
2277 }
2278
2279public:
2280 /// \brief Create a new type trait expression.
2281 static TypeTraitExpr *Create(const ASTContext &C, QualType T,
2282 SourceLocation Loc, TypeTrait Kind,
2283 ArrayRef<TypeSourceInfo *> Args,
2284 SourceLocation RParenLoc,
2285 bool Value);
2286
2287 static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
2288 unsigned NumArgs);
2289
2290 /// \brief Determine which type trait this expression uses.
2291 TypeTrait getTrait() const {
2292 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2293 }
2294
2295 bool getValue() const {
2296 assert(!isValueDependent());
2297 return TypeTraitExprBits.Value;
2298 }
2299
2300 /// \brief Determine the number of arguments to this type trait.
2301 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2302
2303 /// \brief Retrieve the Ith argument.
2304 TypeSourceInfo *getArg(unsigned I) const {
2305 assert(I < getNumArgs() && "Argument out-of-range");
2306 return getArgs()[I];
2307 }
2308
2309 /// \brief Retrieve the argument types.
2310 ArrayRef<TypeSourceInfo *> getArgs() const {
2311 return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(),
2312 getNumArgs());
2313 }
2314
2315 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2316 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2317
2318 static bool classof(const Stmt *T) {
2319 return T->getStmtClass() == TypeTraitExprClass;
2320 }
2321
2322 // Iterators
2323 child_range children() {
2324 return child_range(child_iterator(), child_iterator());
2325 }
2326
2327 friend TrailingObjects;
2328 friend class ASTStmtReader;
2329 friend class ASTStmtWriter;
2330};
2331
2332/// \brief An Embarcadero array type trait, as used in the implementation of
2333/// __array_rank and __array_extent.
2334///
2335/// Example:
2336/// \code
2337/// __array_rank(int[10][20]) == 2
2338/// __array_extent(int, 1) == 20
2339/// \endcode
2340class ArrayTypeTraitExpr : public Expr {
2341 virtual void anchor();
2342
2343 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2344 unsigned ATT : 2;
2345
2346 /// \brief The value of the type trait. Unspecified if dependent.
2347 uint64_t Value;
2348
2349 /// \brief The array dimension being queried, or -1 if not used.
2350 Expr *Dimension;
2351
2352 /// \brief The location of the type trait keyword.
2353 SourceLocation Loc;
2354
2355 /// \brief The location of the closing paren.
2356 SourceLocation RParen;
2357
2358 /// \brief The type being queried.
2359 TypeSourceInfo *QueriedType;
2360
2361public:
2362 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2363 TypeSourceInfo *queried, uint64_t value,
2364 Expr *dimension, SourceLocation rparen, QualType ty)
2365 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2366 false, queried->getType()->isDependentType(),
2367 (queried->getType()->isInstantiationDependentType() ||
2368 (dimension && dimension->isInstantiationDependent())),
2369 queried->getType()->containsUnexpandedParameterPack()),
2370 ATT(att), Value(value), Dimension(dimension),
2371 Loc(loc), RParen(rparen), QueriedType(queried) { }
2372
2373
2374 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2375 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
2376 QueriedType() { }
2377
2378 virtual ~ArrayTypeTraitExpr() { }
2379
2380 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2381 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2382
2383 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2384
2385 QualType getQueriedType() const { return QueriedType->getType(); }
2386
2387 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2388
2389 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2390
2391 Expr *getDimensionExpression() const { return Dimension; }
2392
2393 static bool classof(const Stmt *T) {
2394 return T->getStmtClass() == ArrayTypeTraitExprClass;
2395 }
2396
2397 // Iterators
2398 child_range children() {
2399 return child_range(child_iterator(), child_iterator());
2400 }
2401
2402 friend class ASTStmtReader;
2403};
2404
2405/// \brief An expression trait intrinsic.
2406///
2407/// Example:
2408/// \code
2409/// __is_lvalue_expr(std::cout) == true
2410/// __is_lvalue_expr(1) == false
2411/// \endcode
2412class ExpressionTraitExpr : public Expr {
2413 /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2414 unsigned ET : 31;
2415 /// \brief The value of the type trait. Unspecified if dependent.
2416 unsigned Value : 1;
2417
2418 /// \brief The location of the type trait keyword.
2419 SourceLocation Loc;
2420
2421 /// \brief The location of the closing paren.
2422 SourceLocation RParen;
2423
2424 /// \brief The expression being queried.
2425 Expr* QueriedExpression;
2426public:
2427 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2428 Expr *queried, bool value,
2429 SourceLocation rparen, QualType resultType)
2430 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2431 false, // Not type-dependent
2432 // Value-dependent if the argument is type-dependent.
2433 queried->isTypeDependent(),
2434 queried->isInstantiationDependent(),
2435 queried->containsUnexpandedParameterPack()),
2436 ET(et), Value(value), Loc(loc), RParen(rparen),
2437 QueriedExpression(queried) { }
2438
2439 explicit ExpressionTraitExpr(EmptyShell Empty)
2440 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2441 QueriedExpression() { }
2442
2443 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2444 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2445
2446 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2447
2448 Expr *getQueriedExpression() const { return QueriedExpression; }
2449
2450 bool getValue() const { return Value; }
2451
2452 static bool classof(const Stmt *T) {
2453 return T->getStmtClass() == ExpressionTraitExprClass;
2454 }
2455
2456 // Iterators
2457 child_range children() {
2458 return child_range(child_iterator(), child_iterator());
2459 }
2460
2461 friend class ASTStmtReader;
2462};
2463
2464
2465/// \brief A reference to an overloaded function set, either an
2466/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2467class OverloadExpr : public Expr {
2468 /// \brief The common name of these declarations.
2469 DeclarationNameInfo NameInfo;
2470
2471 /// \brief The nested-name-specifier that qualifies the name, if any.
2472 NestedNameSpecifierLoc QualifierLoc;
2473
2474 /// The results. These are undesugared, which is to say, they may
2475 /// include UsingShadowDecls. Access is relative to the naming
2476 /// class.
2477 // FIXME: Allocate this data after the OverloadExpr subclass.
2478 DeclAccessPair *Results;
2479 unsigned NumResults;
2480
2481protected:
2482 /// \brief Whether the name includes info for explicit template
2483 /// keyword and arguments.
2484 bool HasTemplateKWAndArgsInfo;
2485
2486 /// \brief Return the optional template keyword and arguments info.
2487 ASTTemplateKWAndArgsInfo *
2488 getTrailingASTTemplateKWAndArgsInfo(); // defined far below.
2489
2490 /// \brief Return the optional template keyword and arguments info.
2491 const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const {
2492 return const_cast<OverloadExpr *>(this)
2493 ->getTrailingASTTemplateKWAndArgsInfo();
2494 }
2495
2496 /// Return the optional template arguments.
2497 TemplateArgumentLoc *getTrailingTemplateArgumentLoc(); // defined far below
2498
2499 OverloadExpr(StmtClass K, const ASTContext &C,
2500 NestedNameSpecifierLoc QualifierLoc,
2501 SourceLocation TemplateKWLoc,
2502 const DeclarationNameInfo &NameInfo,
2503 const TemplateArgumentListInfo *TemplateArgs,
2504 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2505 bool KnownDependent,
2506 bool KnownInstantiationDependent,
2507 bool KnownContainsUnexpandedParameterPack);
2508
2509 OverloadExpr(StmtClass K, EmptyShell Empty)
2510 : Expr(K, Empty), QualifierLoc(), Results(nullptr), NumResults(0),
2511 HasTemplateKWAndArgsInfo(false) { }
2512
2513 void initializeResults(const ASTContext &C,
2514 UnresolvedSetIterator Begin,
2515 UnresolvedSetIterator End);
2516
2517public:
2518 struct FindResult {
2519 OverloadExpr *Expression;
2520 bool IsAddressOfOperand;
2521 bool HasFormOfMemberPointer;
2522 };
2523
2524 /// \brief Finds the overloaded expression in the given expression \p E of
2525 /// OverloadTy.
2526 ///
2527 /// \return the expression (which must be there) and true if it has
2528 /// the particular form of a member pointer expression
2529 static FindResult find(Expr *E) {
2530 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2531
2532 FindResult Result;
2533
2534 E = E->IgnoreParens();
2535 if (isa<UnaryOperator>(E)) {
2536 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2537 E = cast<UnaryOperator>(E)->getSubExpr();
2538 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2539
2540 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2541 Result.IsAddressOfOperand = true;
2542 Result.Expression = Ovl;
2543 } else {
2544 Result.HasFormOfMemberPointer = false;
2545 Result.IsAddressOfOperand = false;
2546 Result.Expression = cast<OverloadExpr>(E);
2547 }
2548
2549 return Result;
2550 }
2551
2552 /// \brief Gets the naming class of this lookup, if any.
2553 CXXRecordDecl *getNamingClass() const;
2554
2555 typedef UnresolvedSetImpl::iterator decls_iterator;
2556 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2557 decls_iterator decls_end() const {
2558 return UnresolvedSetIterator(Results + NumResults);
2559 }
2560 llvm::iterator_range<decls_iterator> decls() const {
2561 return llvm::make_range(decls_begin(), decls_end());
2562 }
2563
2564 /// \brief Gets the number of declarations in the unresolved set.
2565 unsigned getNumDecls() const { return NumResults; }
2566
2567 /// \brief Gets the full name info.
2568 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2569
2570 /// \brief Gets the name looked up.
2571 DeclarationName getName() const { return NameInfo.getName(); }
2572
2573 /// \brief Gets the location of the name.
2574 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2575
2576 /// \brief Fetches the nested-name qualifier, if one was given.
2577 NestedNameSpecifier *getQualifier() const {
2578 return QualifierLoc.getNestedNameSpecifier();
2579 }
2580
2581 /// \brief Fetches the nested-name qualifier with source-location
2582 /// information, if one was given.
2583 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2584
2585 /// \brief Retrieve the location of the template keyword preceding
2586 /// this name, if any.
2587 SourceLocation getTemplateKeywordLoc() const {
2588 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2589 return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc;
2590 }
2591
2592 /// \brief Retrieve the location of the left angle bracket starting the
2593 /// explicit template argument list following the name, if any.
2594 SourceLocation getLAngleLoc() const {
2595 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2596 return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc;
2597 }
2598
2599 /// \brief Retrieve the location of the right angle bracket ending the
2600 /// explicit template argument list following the name, if any.
2601 SourceLocation getRAngleLoc() const {
2602 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2603 return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc;
2604 }
2605
2606 /// \brief Determines whether the name was preceded by the template keyword.
2607 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2608
2609 /// \brief Determines whether this expression had explicit template arguments.
2610 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2611
2612 TemplateArgumentLoc const *getTemplateArgs() const {
2613 if (!hasExplicitTemplateArgs())
2614 return nullptr;
2615 return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
2616 }
2617
2618 unsigned getNumTemplateArgs() const {
2619 if (!hasExplicitTemplateArgs())
2620 return 0;
2621
2622 return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs;
2623 }
2624
2625 ArrayRef<TemplateArgumentLoc> template_arguments() const {
2626 return {getTemplateArgs(), getNumTemplateArgs()};
2627 }
2628
2629 /// \brief Copies the template arguments into the given structure.
2630 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2631 if (hasExplicitTemplateArgs())
2632 getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List);
2633 }
2634
2635 static bool classof(const Stmt *T) {
2636 return T->getStmtClass() == UnresolvedLookupExprClass ||
2637 T->getStmtClass() == UnresolvedMemberExprClass;
2638 }
2639
2640 friend class ASTStmtReader;
2641 friend class ASTStmtWriter;
2642};
2643
2644/// \brief A reference to a name which we were able to look up during
2645/// parsing but could not resolve to a specific declaration.
2646///
2647/// This arises in several ways:
2648/// * we might be waiting for argument-dependent lookup;
2649/// * the name might resolve to an overloaded function;
2650/// and eventually:
2651/// * the lookup might have included a function template.
2652///
2653/// These never include UnresolvedUsingValueDecls, which are always class
2654/// members and therefore appear only in UnresolvedMemberLookupExprs.
2655class UnresolvedLookupExpr final
2656 : public OverloadExpr,
2657 private llvm::TrailingObjects<
2658 UnresolvedLookupExpr, ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> {
2659 /// True if these lookup results should be extended by
2660 /// argument-dependent lookup if this is the operand of a function
2661 /// call.
2662 bool RequiresADL;
2663
2664 /// True if these lookup results are overloaded. This is pretty
2665 /// trivially rederivable if we urgently need to kill this field.
2666 bool Overloaded;
2667
2668 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2669 /// any. This can generally be recalculated from the context chain,
2670 /// but that can be fairly expensive for unqualified lookups. If we
2671 /// want to improve memory use here, this could go in a union
2672 /// against the qualified-lookup bits.
2673 CXXRecordDecl *NamingClass;
2674
2675 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2676 return HasTemplateKWAndArgsInfo ? 1 : 0;
2677 }
2678
2679 UnresolvedLookupExpr(const ASTContext &C,
2680 CXXRecordDecl *NamingClass,
2681 NestedNameSpecifierLoc QualifierLoc,
2682 SourceLocation TemplateKWLoc,
2683 const DeclarationNameInfo &NameInfo,
2684 bool RequiresADL, bool Overloaded,
2685 const TemplateArgumentListInfo *TemplateArgs,
2686 UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2687 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2688 NameInfo, TemplateArgs, Begin, End, false, false, false),
2689 RequiresADL(RequiresADL),
2690 Overloaded(Overloaded), NamingClass(NamingClass)
2691 {}
2692
2693 UnresolvedLookupExpr(EmptyShell Empty)
2694 : OverloadExpr(UnresolvedLookupExprClass, Empty),
2695 RequiresADL(false), Overloaded(false), NamingClass(nullptr)
2696 {}
2697
2698 friend TrailingObjects;
2699 friend class OverloadExpr;
2700 friend class ASTStmtReader;
2701
2702public:
2703 static UnresolvedLookupExpr *Create(const ASTContext &C,
2704 CXXRecordDecl *NamingClass,
2705 NestedNameSpecifierLoc QualifierLoc,
2706 const DeclarationNameInfo &NameInfo,
2707 bool ADL, bool Overloaded,
2708 UnresolvedSetIterator Begin,
2709 UnresolvedSetIterator End) {
2710 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2711 SourceLocation(), NameInfo,
2712 ADL, Overloaded, nullptr, Begin, End);
2713 }
2714
2715 static UnresolvedLookupExpr *Create(const ASTContext &C,
2716 CXXRecordDecl *NamingClass,
2717 NestedNameSpecifierLoc QualifierLoc,
2718 SourceLocation TemplateKWLoc,
2719 const DeclarationNameInfo &NameInfo,
2720 bool ADL,
2721 const TemplateArgumentListInfo *Args,
2722 UnresolvedSetIterator Begin,
2723 UnresolvedSetIterator End);
2724
2725 static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C,
2726 bool HasTemplateKWAndArgsInfo,
2727 unsigned NumTemplateArgs);
2728
2729 /// True if this declaration should be extended by
2730 /// argument-dependent lookup.
2731 bool requiresADL() const { return RequiresADL; }
2732
2733 /// True if this lookup is overloaded.
2734 bool isOverloaded() const { return Overloaded; }
2735
2736 /// Gets the 'naming class' (in the sense of C++0x
2737 /// [class.access.base]p5) of the lookup. This is the scope
2738 /// that was looked in to find these results.
2739 CXXRecordDecl *getNamingClass() const { return NamingClass; }
2740
2741 SourceLocation getLocStart() const LLVM_READONLY {
2742 if (NestedNameSpecifierLoc l = getQualifierLoc())
2743 return l.getBeginLoc();
2744 return getNameInfo().getLocStart();
2745 }
2746 SourceLocation getLocEnd() const LLVM_READONLY {
2747 if (hasExplicitTemplateArgs())
2748 return getRAngleLoc();
2749 return getNameInfo().getLocEnd();
2750 }
2751
2752 child_range children() {
2753 return child_range(child_iterator(), child_iterator());
2754 }
2755
2756 static bool classof(const Stmt *T) {
2757 return T->getStmtClass() == UnresolvedLookupExprClass;
2758 }
2759};
2760
2761/// \brief A qualified reference to a name whose declaration cannot
2762/// yet be resolved.
2763///
2764/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2765/// it expresses a reference to a declaration such as
2766/// X<T>::value. The difference, however, is that an
2767/// DependentScopeDeclRefExpr node is used only within C++ templates when
2768/// the qualification (e.g., X<T>::) refers to a dependent type. In
2769/// this case, X<T>::value cannot resolve to a declaration because the
2770/// declaration will differ from one instantiation of X<T> to the
2771/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2772/// qualifier (X<T>::) and the name of the entity being referenced
2773/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2774/// declaration can be found.
2775class DependentScopeDeclRefExpr final
2776 : public Expr,
2777 private llvm::TrailingObjects<DependentScopeDeclRefExpr,
2778 ASTTemplateKWAndArgsInfo,
2779 TemplateArgumentLoc> {
2780 /// \brief The nested-name-specifier that qualifies this unresolved
2781 /// declaration name.
2782 NestedNameSpecifierLoc QualifierLoc;
2783
2784 /// \brief The name of the entity we will be referencing.
2785 DeclarationNameInfo NameInfo;
2786
2787 /// \brief Whether the name includes info for explicit template
2788 /// keyword and arguments.
2789 bool HasTemplateKWAndArgsInfo;
2790
2791 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2792 return HasTemplateKWAndArgsInfo ? 1 : 0;
2793 }
2794
2795 DependentScopeDeclRefExpr(QualType T,
2796 NestedNameSpecifierLoc QualifierLoc,
2797 SourceLocation TemplateKWLoc,
2798 const DeclarationNameInfo &NameInfo,
2799 const TemplateArgumentListInfo *Args);
2800
2801public:
2802 static DependentScopeDeclRefExpr *Create(const ASTContext &C,
2803 NestedNameSpecifierLoc QualifierLoc,
2804 SourceLocation TemplateKWLoc,
2805 const DeclarationNameInfo &NameInfo,
2806 const TemplateArgumentListInfo *TemplateArgs);
2807
2808 static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C,
2809 bool HasTemplateKWAndArgsInfo,
2810 unsigned NumTemplateArgs);
2811
2812 /// \brief Retrieve the name that this expression refers to.
2813 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2814
2815 /// \brief Retrieve the name that this expression refers to.
2816 DeclarationName getDeclName() const { return NameInfo.getName(); }
2817
2818 /// \brief Retrieve the location of the name within the expression.
2819 ///
2820 /// For example, in "X<T>::value" this is the location of "value".
2821 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2822
2823 /// \brief Retrieve the nested-name-specifier that qualifies the
2824 /// name, with source location information.
2825 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2826
2827 /// \brief Retrieve the nested-name-specifier that qualifies this
2828 /// declaration.
2829 NestedNameSpecifier *getQualifier() const {
2830 return QualifierLoc.getNestedNameSpecifier();
2831 }
2832
2833 /// \brief Retrieve the location of the template keyword preceding
2834 /// this name, if any.
2835 SourceLocation getTemplateKeywordLoc() const {
2836 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2837 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
2838 }
2839
2840 /// \brief Retrieve the location of the left angle bracket starting the
2841 /// explicit template argument list following the name, if any.
2842 SourceLocation getLAngleLoc() const {
2843 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2844 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
2845 }
2846
2847 /// \brief Retrieve the location of the right angle bracket ending the
2848 /// explicit template argument list following the name, if any.
2849 SourceLocation getRAngleLoc() const {
2850 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2851 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
2852 }
2853
2854 /// Determines whether the name was preceded by the template keyword.
2855 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2856
2857 /// Determines whether this lookup had explicit template arguments.
2858 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2859
2860 /// \brief Copies the template arguments (if present) into the given
2861 /// structure.
2862 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2863 if (hasExplicitTemplateArgs())
2864 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
2865 getTrailingObjects<TemplateArgumentLoc>(), List);
2866 }
2867
2868 TemplateArgumentLoc const *getTemplateArgs() const {
2869 if (!hasExplicitTemplateArgs())
2870 return nullptr;
2871
2872 return getTrailingObjects<TemplateArgumentLoc>();
2873 }
2874
2875 unsigned getNumTemplateArgs() const {
2876 if (!hasExplicitTemplateArgs())
2877 return 0;
2878
2879 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
2880 }
2881
2882 ArrayRef<TemplateArgumentLoc> template_arguments() const {
2883 return {getTemplateArgs(), getNumTemplateArgs()};
2884 }
2885
2886 /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr,
2887 /// and differs from getLocation().getStart().
2888 SourceLocation getLocStart() const LLVM_READONLY {
2889 return QualifierLoc.getBeginLoc();
2890 }
2891 SourceLocation getLocEnd() const LLVM_READONLY {
2892 if (hasExplicitTemplateArgs())
2893 return getRAngleLoc();
2894 return getLocation();
2895 }
2896
2897 static bool classof(const Stmt *T) {
2898 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2899 }
2900
2901 child_range children() {
2902 return child_range(child_iterator(), child_iterator());
2903 }
2904
2905 friend TrailingObjects;
2906 friend class ASTStmtReader;
2907 friend class ASTStmtWriter;
2908};
2909
2910/// Represents an expression -- generally a full-expression -- that
2911/// introduces cleanups to be run at the end of the sub-expression's
2912/// evaluation. The most common source of expression-introduced
2913/// cleanups is temporary objects in C++, but several other kinds of
2914/// expressions can create cleanups, including basically every
2915/// call in ARC that returns an Objective-C pointer.
2916///
2917/// This expression also tracks whether the sub-expression contains a
2918/// potentially-evaluated block literal. The lifetime of a block
2919/// literal is the extent of the enclosing scope.
2920class ExprWithCleanups final
2921 : public Expr,
2922 private llvm::TrailingObjects<ExprWithCleanups, BlockDecl *> {
2923public:
2924 /// The type of objects that are kept in the cleanup.
2925 /// It's useful to remember the set of blocks; we could also
2926 /// remember the set of temporaries, but there's currently
2927 /// no need.
2928 typedef BlockDecl *CleanupObject;
2929
2930private:
2931 Stmt *SubExpr;
2932
2933 ExprWithCleanups(EmptyShell, unsigned NumObjects);
2934 ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects,
2935 ArrayRef<CleanupObject> Objects);
2936
2937 friend TrailingObjects;
2938 friend class ASTStmtReader;
2939
2940public:
2941 static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
2942 unsigned numObjects);
2943
2944 static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
2945 bool CleanupsHaveSideEffects,
2946 ArrayRef<CleanupObject> objects);
2947
2948 ArrayRef<CleanupObject> getObjects() const {
2949 return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(),
2950 getNumObjects());
2951 }
2952
2953 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2954
2955 CleanupObject getObject(unsigned i) const {
2956 assert(i < getNumObjects() && "Index out of range");
2957 return getObjects()[i];
2958 }
2959
2960 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2961 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2962 bool cleanupsHaveSideEffects() const {
2963 return ExprWithCleanupsBits.CleanupsHaveSideEffects;
2964 }
2965
2966 /// As with any mutator of the AST, be very careful
2967 /// when modifying an existing AST to preserve its invariants.
2968 void setSubExpr(Expr *E) { SubExpr = E; }
2969
2970 SourceLocation getLocStart() const LLVM_READONLY {
2971 return SubExpr->getLocStart();
2972 }
2973 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
2974
2975 // Implement isa/cast/dyncast/etc.
2976 static bool classof(const Stmt *T) {
2977 return T->getStmtClass() == ExprWithCleanupsClass;
2978 }
2979
2980 // Iterators
2981 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2982};
2983
2984/// \brief Describes an explicit type conversion that uses functional
2985/// notion but could not be resolved because one or more arguments are
2986/// type-dependent.
2987///
2988/// The explicit type conversions expressed by
2989/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
2990/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
2991/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
2992/// type-dependent. For example, this would occur in a template such
2993/// as:
2994///
2995/// \code
2996/// template<typename T, typename A1>
2997/// inline T make_a(const A1& a1) {
2998/// return T(a1);
2999/// }
3000/// \endcode
3001///
3002/// When the returned expression is instantiated, it may resolve to a
3003/// constructor call, conversion function call, or some kind of type
3004/// conversion.
3005class CXXUnresolvedConstructExpr final
3006 : public Expr,
3007 private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> {
3008 /// \brief The type being constructed.
3009 TypeSourceInfo *Type;
3010
3011 /// \brief The location of the left parentheses ('(').
3012 SourceLocation LParenLoc;
3013
3014 /// \brief The location of the right parentheses (')').
3015 SourceLocation RParenLoc;
3016
3017 /// \brief The number of arguments used to construct the type.
3018 unsigned NumArgs;
3019
3020 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
3021 SourceLocation LParenLoc,
3022 ArrayRef<Expr*> Args,
3023 SourceLocation RParenLoc);
3024
3025 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
3026 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
3027
3028 friend TrailingObjects;
3029 friend class ASTStmtReader;
3030
3031public:
3032 static CXXUnresolvedConstructExpr *Create(const ASTContext &C,
3033 TypeSourceInfo *Type,
3034 SourceLocation LParenLoc,
3035 ArrayRef<Expr*> Args,
3036 SourceLocation RParenLoc);
3037
3038 static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C,
3039 unsigned NumArgs);
3040
3041 /// \brief Retrieve the type that is being constructed, as specified
3042 /// in the source code.
3043 QualType getTypeAsWritten() const { return Type->getType(); }
3044
3045 /// \brief Retrieve the type source information for the type being
3046 /// constructed.
3047 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
3048
3049 /// \brief Retrieve the location of the left parentheses ('(') that
3050 /// precedes the argument list.
3051 SourceLocation getLParenLoc() const { return LParenLoc; }
3052 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3053
3054 /// \brief Retrieve the location of the right parentheses (')') that
3055 /// follows the argument list.
3056 SourceLocation getRParenLoc() const { return RParenLoc; }
3057 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3058
3059 /// \brief Retrieve the number of arguments.
3060 unsigned arg_size() const { return NumArgs; }
3061
3062 typedef Expr** arg_iterator;
3063 arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
3064 arg_iterator arg_end() { return arg_begin() + NumArgs; }
3065
3066 typedef const Expr* const * const_arg_iterator;
3067 const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
3068 const_arg_iterator arg_end() const {
3069 return arg_begin() + NumArgs;
3070 }
3071
3072 Expr *getArg(unsigned I) {
3073 assert(I < NumArgs && "Argument index out-of-range");
3074 return *(arg_begin() + I);
3075 }
3076
3077 const Expr *getArg(unsigned I) const {
3078 assert(I < NumArgs && "Argument index out-of-range");
3079 return *(arg_begin() + I);
3080 }
3081
3082 void setArg(unsigned I, Expr *E) {
3083 assert(I < NumArgs && "Argument index out-of-range");
3084 *(arg_begin() + I) = E;
3085 }
3086
3087 SourceLocation getLocStart() const LLVM_READONLY;
3088 SourceLocation getLocEnd() const LLVM_READONLY {
3089 if (!RParenLoc.isValid() && NumArgs > 0)
3090 return getArg(NumArgs - 1)->getLocEnd();
3091 return RParenLoc;
3092 }
3093
3094 static bool classof(const Stmt *T) {
3095 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
3096 }
3097
3098 // Iterators
3099 child_range children() {
3100 Stmt **begin = reinterpret_cast<Stmt **>(arg_begin());
3101 return child_range(begin, begin + NumArgs);
3102 }
3103};
3104
3105/// \brief Represents a C++ member access expression where the actual
3106/// member referenced could not be resolved because the base
3107/// expression or the member name was dependent.
3108///
3109/// Like UnresolvedMemberExprs, these can be either implicit or
3110/// explicit accesses. It is only possible to get one of these with
3111/// an implicit access if a qualifier is provided.
3112class CXXDependentScopeMemberExpr final
3113 : public Expr,
3114 private llvm::TrailingObjects<CXXDependentScopeMemberExpr,
3115 ASTTemplateKWAndArgsInfo,
3116 TemplateArgumentLoc> {
3117 /// \brief The expression for the base pointer or class reference,
3118 /// e.g., the \c x in x.f. Can be null in implicit accesses.
3119 Stmt *Base;
3120
3121 /// \brief The type of the base expression. Never null, even for
3122 /// implicit accesses.
3123 QualType BaseType;
3124
3125 /// \brief Whether this member expression used the '->' operator or
3126 /// the '.' operator.
3127 bool IsArrow : 1;
3128
3129 /// \brief Whether this member expression has info for explicit template
3130 /// keyword and arguments.
3131 bool HasTemplateKWAndArgsInfo : 1;
3132
3133 /// \brief The location of the '->' or '.' operator.
3134 SourceLocation OperatorLoc;
3135
3136 /// \brief The nested-name-specifier that precedes the member name, if any.
3137 NestedNameSpecifierLoc QualifierLoc;
3138
3139 /// \brief In a qualified member access expression such as t->Base::f, this
3140 /// member stores the resolves of name lookup in the context of the member
3141 /// access expression, to be used at instantiation time.
3142 ///
3143 /// FIXME: This member, along with the QualifierLoc, could
3144 /// be stuck into a structure that is optionally allocated at the end of
3145 /// the CXXDependentScopeMemberExpr, to save space in the common case.
3146 NamedDecl *FirstQualifierFoundInScope;
3147
3148 /// \brief The member to which this member expression refers, which
3149 /// can be name, overloaded operator, or destructor.
3150 ///
3151 /// FIXME: could also be a template-id
3152 DeclarationNameInfo MemberNameInfo;
3153
3154 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3155 return HasTemplateKWAndArgsInfo ? 1 : 0;
3156 }
3157
3158 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3159 QualType BaseType, bool IsArrow,
3160 SourceLocation OperatorLoc,
3161 NestedNameSpecifierLoc QualifierLoc,
3162 SourceLocation TemplateKWLoc,
3163 NamedDecl *FirstQualifierFoundInScope,
3164 DeclarationNameInfo MemberNameInfo,
3165 const TemplateArgumentListInfo *TemplateArgs);
3166
3167public:
3168 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3169 QualType BaseType, bool IsArrow,
3170 SourceLocation OperatorLoc,
3171 NestedNameSpecifierLoc QualifierLoc,
3172 NamedDecl *FirstQualifierFoundInScope,
3173 DeclarationNameInfo MemberNameInfo);
3174
3175 static CXXDependentScopeMemberExpr *
3176 Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
3177 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3178 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
3179 DeclarationNameInfo MemberNameInfo,
3180 const TemplateArgumentListInfo *TemplateArgs);
3181
3182 static CXXDependentScopeMemberExpr *
3183 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3184 unsigned NumTemplateArgs);
3185
3186 /// \brief True if this is an implicit access, i.e. one in which the
3187 /// member being accessed was not written in the source. The source
3188 /// location of the operator is invalid in this case.
3189 bool isImplicitAccess() const;
3190
3191 /// \brief Retrieve the base object of this member expressions,
3192 /// e.g., the \c x in \c x.m.
3193 Expr *getBase() const {
3194 assert(!isImplicitAccess());
3195 return cast<Expr>(Base);
3196 }
3197
3198 QualType getBaseType() const { return BaseType; }
3199
3200 /// \brief Determine whether this member expression used the '->'
3201 /// operator; otherwise, it used the '.' operator.
3202 bool isArrow() const { return IsArrow; }
3203
3204 /// \brief Retrieve the location of the '->' or '.' operator.
3205 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3206
3207 /// \brief Retrieve the nested-name-specifier that qualifies the member
3208 /// name.
3209 NestedNameSpecifier *getQualifier() const {
3210 return QualifierLoc.getNestedNameSpecifier();
3211 }
3212
3213 /// \brief Retrieve the nested-name-specifier that qualifies the member
3214 /// name, with source location information.
3215 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3216
3217
3218 /// \brief Retrieve the first part of the nested-name-specifier that was
3219 /// found in the scope of the member access expression when the member access
3220 /// was initially parsed.
3221 ///
3222 /// This function only returns a useful result when member access expression
3223 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3224 /// returned by this function describes what was found by unqualified name
3225 /// lookup for the identifier "Base" within the scope of the member access
3226 /// expression itself. At template instantiation time, this information is
3227 /// combined with the results of name lookup into the type of the object
3228 /// expression itself (the class type of x).
3229 NamedDecl *getFirstQualifierFoundInScope() const {
3230 return FirstQualifierFoundInScope;
3231 }
3232
3233 /// \brief Retrieve the name of the member that this expression
3234 /// refers to.
3235 const DeclarationNameInfo &getMemberNameInfo() const {
3236 return MemberNameInfo;
3237 }
3238
3239 /// \brief Retrieve the name of the member that this expression
3240 /// refers to.
3241 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3242
3243 // \brief Retrieve the location of the name of the member that this
3244 // expression refers to.
3245 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3246
3247 /// \brief Retrieve the location of the template keyword preceding the
3248 /// member name, if any.
3249 SourceLocation getTemplateKeywordLoc() const {
3250 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3251 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3252 }
3253
3254 /// \brief Retrieve the location of the left angle bracket starting the
3255 /// explicit template argument list following the member name, if any.
3256 SourceLocation getLAngleLoc() const {
3257 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3258 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3259 }
3260
3261 /// \brief Retrieve the location of the right angle bracket ending the
3262 /// explicit template argument list following the member name, if any.
3263 SourceLocation getRAngleLoc() const {
3264 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3265 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3266 }
3267
3268 /// Determines whether the member name was preceded by the template keyword.
3269 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3270
3271 /// \brief Determines whether this member expression actually had a C++
3272 /// template argument list explicitly specified, e.g., x.f<int>.
3273 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3274
3275 /// \brief Copies the template arguments (if present) into the given
3276 /// structure.
3277 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3278 if (hasExplicitTemplateArgs())
3279 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3280 getTrailingObjects<TemplateArgumentLoc>(), List);
3281 }
3282
3283 /// \brief Retrieve the template arguments provided as part of this
3284 /// template-id.
3285 const TemplateArgumentLoc *getTemplateArgs() const {
3286 if (!hasExplicitTemplateArgs())
3287 return nullptr;
3288
3289 return getTrailingObjects<TemplateArgumentLoc>();
3290 }
3291
3292 /// \brief Retrieve the number of template arguments provided as part of this
3293 /// template-id.
3294 unsigned getNumTemplateArgs() const {
3295 if (!hasExplicitTemplateArgs())
3296 return 0;
3297
3298 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3299 }
3300
3301 ArrayRef<TemplateArgumentLoc> template_arguments() const {
3302 return {getTemplateArgs(), getNumTemplateArgs()};
3303 }
3304
3305 SourceLocation getLocStart() const LLVM_READONLY {
3306 if (!isImplicitAccess())
3307 return Base->getLocStart();
3308 if (getQualifier())
3309 return getQualifierLoc().getBeginLoc();
3310 return MemberNameInfo.getBeginLoc();
3311 }
3312
3313 SourceLocation getLocEnd() const LLVM_READONLY {
3314 if (hasExplicitTemplateArgs())
3315 return getRAngleLoc();
3316 return MemberNameInfo.getEndLoc();
3317 }
3318
3319 static bool classof(const Stmt *T) {
3320 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3321 }
3322
3323 // Iterators
3324 child_range children() {
3325 if (isImplicitAccess())
3326 return child_range(child_iterator(), child_iterator());
3327 return child_range(&Base, &Base + 1);
3328 }
3329
3330 friend TrailingObjects;
3331 friend class ASTStmtReader;
3332 friend class ASTStmtWriter;
3333};
3334
3335/// \brief Represents a C++ member access expression for which lookup
3336/// produced a set of overloaded functions.
3337///
3338/// The member access may be explicit or implicit:
3339/// \code
3340/// struct A {
3341/// int a, b;
3342/// int explicitAccess() { return this->a + this->A::b; }
3343/// int implicitAccess() { return a + A::b; }
3344/// };
3345/// \endcode
3346///
3347/// In the final AST, an explicit access always becomes a MemberExpr.
3348/// An implicit access may become either a MemberExpr or a
3349/// DeclRefExpr, depending on whether the member is static.
3350class UnresolvedMemberExpr final
3351 : public OverloadExpr,
3352 private llvm::TrailingObjects<
3353 UnresolvedMemberExpr, ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> {
3354 /// \brief Whether this member expression used the '->' operator or
3355 /// the '.' operator.
3356 bool IsArrow : 1;
3357
3358 /// \brief Whether the lookup results contain an unresolved using
3359 /// declaration.
3360 bool HasUnresolvedUsing : 1;
3361
3362 /// \brief The expression for the base pointer or class reference,
3363 /// e.g., the \c x in x.f.
3364 ///
3365 /// This can be null if this is an 'unbased' member expression.
3366 Stmt *Base;
3367
3368 /// \brief The type of the base expression; never null.
3369 QualType BaseType;
3370
3371 /// \brief The location of the '->' or '.' operator.
3372 SourceLocation OperatorLoc;
3373
3374 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3375 return HasTemplateKWAndArgsInfo ? 1 : 0;
3376 }
3377
3378 UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing,
3379 Expr *Base, QualType BaseType, bool IsArrow,
3380 SourceLocation OperatorLoc,
3381 NestedNameSpecifierLoc QualifierLoc,
3382 SourceLocation TemplateKWLoc,
3383 const DeclarationNameInfo &MemberNameInfo,
3384 const TemplateArgumentListInfo *TemplateArgs,
3385 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3386
3387 UnresolvedMemberExpr(EmptyShell Empty)
3388 : OverloadExpr