/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/ExprCXX.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- ExprCXX.h - Classes for representing expressions ---------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | /// \file |
10 | | /// Defines the clang::Expr interface and subclasses for C++ expressions. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #ifndef LLVM_CLANG_AST_EXPRCXX_H |
15 | | #define LLVM_CLANG_AST_EXPRCXX_H |
16 | | |
17 | | #include "clang/AST/ASTConcept.h" |
18 | | #include "clang/AST/ComputeDependence.h" |
19 | | #include "clang/AST/Decl.h" |
20 | | #include "clang/AST/DeclBase.h" |
21 | | #include "clang/AST/DeclCXX.h" |
22 | | #include "clang/AST/DeclTemplate.h" |
23 | | #include "clang/AST/DeclarationName.h" |
24 | | #include "clang/AST/DependenceFlags.h" |
25 | | #include "clang/AST/Expr.h" |
26 | | #include "clang/AST/NestedNameSpecifier.h" |
27 | | #include "clang/AST/OperationKinds.h" |
28 | | #include "clang/AST/Stmt.h" |
29 | | #include "clang/AST/StmtCXX.h" |
30 | | #include "clang/AST/TemplateBase.h" |
31 | | #include "clang/AST/Type.h" |
32 | | #include "clang/AST/UnresolvedSet.h" |
33 | | #include "clang/Basic/ExceptionSpecificationType.h" |
34 | | #include "clang/Basic/ExpressionTraits.h" |
35 | | #include "clang/Basic/LLVM.h" |
36 | | #include "clang/Basic/Lambda.h" |
37 | | #include "clang/Basic/LangOptions.h" |
38 | | #include "clang/Basic/OperatorKinds.h" |
39 | | #include "clang/Basic/SourceLocation.h" |
40 | | #include "clang/Basic/Specifiers.h" |
41 | | #include "clang/Basic/TypeTraits.h" |
42 | | #include "llvm/ADT/ArrayRef.h" |
43 | | #include "llvm/ADT/None.h" |
44 | | #include "llvm/ADT/Optional.h" |
45 | | #include "llvm/ADT/PointerUnion.h" |
46 | | #include "llvm/ADT/StringRef.h" |
47 | | #include "llvm/ADT/iterator_range.h" |
48 | | #include "llvm/Support/Casting.h" |
49 | | #include "llvm/Support/Compiler.h" |
50 | | #include "llvm/Support/TrailingObjects.h" |
51 | | #include <cassert> |
52 | | #include <cstddef> |
53 | | #include <cstdint> |
54 | | #include <memory> |
55 | | |
56 | | namespace clang { |
57 | | |
58 | | class ASTContext; |
59 | | class DeclAccessPair; |
60 | | class IdentifierInfo; |
61 | | class LambdaCapture; |
62 | | class NonTypeTemplateParmDecl; |
63 | | class TemplateParameterList; |
64 | | |
65 | | //===--------------------------------------------------------------------===// |
66 | | // C++ Expressions. |
67 | | //===--------------------------------------------------------------------===// |
68 | | |
69 | | /// A call to an overloaded operator written using operator |
70 | | /// syntax. |
71 | | /// |
72 | | /// Represents a call to an overloaded operator written using operator |
73 | | /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a |
74 | | /// normal call, this AST node provides better information about the |
75 | | /// syntactic representation of the call. |
76 | | /// |
77 | | /// In a C++ template, this expression node kind will be used whenever |
78 | | /// any of the arguments are type-dependent. In this case, the |
79 | | /// function itself will be a (possibly empty) set of functions and |
80 | | /// function templates that were found by name lookup at template |
81 | | /// definition time. |
82 | | class CXXOperatorCallExpr final : public CallExpr { |
83 | | friend class ASTStmtReader; |
84 | | friend class ASTStmtWriter; |
85 | | |
86 | | SourceRange Range; |
87 | | |
88 | | // CXXOperatorCallExpr has some trailing objects belonging |
89 | | // to CallExpr. See CallExpr for the details. |
90 | | |
91 | | SourceRange getSourceRangeImpl() const LLVM_READONLY; |
92 | | |
93 | | CXXOperatorCallExpr(OverloadedOperatorKind OpKind, Expr *Fn, |
94 | | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
95 | | SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, |
96 | | ADLCallKind UsesADL); |
97 | | |
98 | | CXXOperatorCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); |
99 | | |
100 | | public: |
101 | | static CXXOperatorCallExpr * |
102 | | Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, |
103 | | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
104 | | SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, |
105 | | ADLCallKind UsesADL = NotADL); |
106 | | |
107 | | static CXXOperatorCallExpr *CreateEmpty(const ASTContext &Ctx, |
108 | | unsigned NumArgs, bool HasFPFeatures, |
109 | | EmptyShell Empty); |
110 | | |
111 | | /// Returns the kind of overloaded operator that this expression refers to. |
112 | 4.00M | OverloadedOperatorKind getOperator() const { |
113 | 4.00M | return static_cast<OverloadedOperatorKind>( |
114 | 4.00M | CXXOperatorCallExprBits.OperatorKind); |
115 | 4.00M | } |
116 | | |
117 | 53.3k | static bool isAssignmentOp(OverloadedOperatorKind Opc) { |
118 | 53.3k | return Opc == OO_Equal || Opc == OO_StarEqual49.5k || Opc == OO_SlashEqual49.5k || |
119 | 53.3k | Opc == OO_PercentEqual49.5k || Opc == OO_PlusEqual49.5k || |
120 | 53.3k | Opc == OO_MinusEqual49.1k || Opc == OO_LessLessEqual49.1k || |
121 | 53.3k | Opc == OO_GreaterGreaterEqual49.1k || Opc == OO_AmpEqual49.1k || |
122 | 53.3k | Opc == OO_CaretEqual49.0k || Opc == OO_PipeEqual49.0k ; |
123 | 53.3k | } |
124 | 53.3k | bool isAssignmentOp() const { return isAssignmentOp(getOperator()); } |
125 | | |
126 | 20 | static bool isComparisonOp(OverloadedOperatorKind Opc) { |
127 | 20 | switch (Opc) { |
128 | 20 | case OO_EqualEqual: |
129 | 20 | case OO_ExclaimEqual: |
130 | 20 | case OO_Greater: |
131 | 20 | case OO_GreaterEqual: |
132 | 20 | case OO_Less: |
133 | 20 | case OO_LessEqual: |
134 | 20 | case OO_Spaceship: |
135 | 20 | return true; |
136 | 0 | default: |
137 | 0 | return false; |
138 | 20 | } |
139 | 20 | } |
140 | 20 | bool isComparisonOp() const { return isComparisonOp(getOperator()); } |
141 | | |
142 | | /// Is this written as an infix binary operator? |
143 | | bool isInfixBinaryOp() const; |
144 | | |
145 | | /// Returns the location of the operator symbol in the expression. |
146 | | /// |
147 | | /// When \c getOperator()==OO_Call, this is the location of the right |
148 | | /// parentheses; when \c getOperator()==OO_Subscript, this is the location |
149 | | /// of the right bracket. |
150 | 814k | SourceLocation getOperatorLoc() const { return getRParenLoc(); } |
151 | | |
152 | 802k | SourceLocation getExprLoc() const LLVM_READONLY { |
153 | 802k | OverloadedOperatorKind Operator = getOperator(); |
154 | 802k | return (Operator < OO_Plus || Operator >= OO_Arrow || |
155 | 802k | Operator == OO_PlusPlus691k || Operator == OO_MinusMinus638k ) |
156 | 802k | ? getBeginLoc()171k |
157 | 802k | : getOperatorLoc()631k ; |
158 | 802k | } |
159 | | |
160 | 899k | SourceLocation getBeginLoc() const { return Range.getBegin(); } |
161 | 49.8k | SourceLocation getEndLoc() const { return Range.getEnd(); } |
162 | 129k | SourceRange getSourceRange() const { return Range; } |
163 | | |
164 | 44.5M | static bool classof(const Stmt *T) { |
165 | 44.5M | return T->getStmtClass() == CXXOperatorCallExprClass; |
166 | 44.5M | } |
167 | | }; |
168 | | |
169 | | /// Represents a call to a member function that |
170 | | /// may be written either with member call syntax (e.g., "obj.func()" |
171 | | /// or "objptr->func()") or with normal function-call syntax |
172 | | /// ("func()") within a member function that ends up calling a member |
173 | | /// function. The callee in either case is a MemberExpr that contains |
174 | | /// both the object argument and the member function, while the |
175 | | /// arguments are the arguments within the parentheses (not including |
176 | | /// the object argument). |
177 | | class CXXMemberCallExpr final : public CallExpr { |
178 | | // CXXMemberCallExpr has some trailing objects belonging |
179 | | // to CallExpr. See CallExpr for the details. |
180 | | |
181 | | CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty, |
182 | | ExprValueKind VK, SourceLocation RP, |
183 | | FPOptionsOverride FPOptions, unsigned MinNumArgs); |
184 | | |
185 | | CXXMemberCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); |
186 | | |
187 | | public: |
188 | | static CXXMemberCallExpr *Create(const ASTContext &Ctx, Expr *Fn, |
189 | | ArrayRef<Expr *> Args, QualType Ty, |
190 | | ExprValueKind VK, SourceLocation RP, |
191 | | FPOptionsOverride FPFeatures, |
192 | | unsigned MinNumArgs = 0); |
193 | | |
194 | | static CXXMemberCallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, |
195 | | bool HasFPFeatures, EmptyShell Empty); |
196 | | |
197 | | /// Retrieve the implicit object argument for the member call. |
198 | | /// |
199 | | /// For example, in "x.f(5)", this returns the sub-expression "x". |
200 | | Expr *getImplicitObjectArgument() const; |
201 | | |
202 | | /// Retrieve the type of the object argument. |
203 | | /// |
204 | | /// Note that this always returns a non-pointer type. |
205 | | QualType getObjectType() const; |
206 | | |
207 | | /// Retrieve the declaration of the called method. |
208 | | CXXMethodDecl *getMethodDecl() const; |
209 | | |
210 | | /// Retrieve the CXXRecordDecl for the underlying type of |
211 | | /// the implicit object argument. |
212 | | /// |
213 | | /// Note that this is may not be the same declaration as that of the class |
214 | | /// context of the CXXMethodDecl which this function is calling. |
215 | | /// FIXME: Returns 0 for member pointer call exprs. |
216 | | CXXRecordDecl *getRecordDecl() const; |
217 | | |
218 | 1.31M | SourceLocation getExprLoc() const LLVM_READONLY { |
219 | 1.31M | SourceLocation CLoc = getCallee()->getExprLoc(); |
220 | 1.31M | if (CLoc.isValid()) |
221 | 1.29M | return CLoc; |
222 | | |
223 | 19.7k | return getBeginLoc(); |
224 | 1.31M | } |
225 | | |
226 | 10.1M | static bool classof(const Stmt *T) { |
227 | 10.1M | return T->getStmtClass() == CXXMemberCallExprClass; |
228 | 10.1M | } |
229 | | }; |
230 | | |
231 | | /// Represents a call to a CUDA kernel function. |
232 | | class CUDAKernelCallExpr final : public CallExpr { |
233 | | friend class ASTStmtReader; |
234 | | |
235 | | enum { CONFIG, END_PREARG }; |
236 | | |
237 | | // CUDAKernelCallExpr has some trailing objects belonging |
238 | | // to CallExpr. See CallExpr for the details. |
239 | | |
240 | | CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, ArrayRef<Expr *> Args, |
241 | | QualType Ty, ExprValueKind VK, SourceLocation RP, |
242 | | FPOptionsOverride FPFeatures, unsigned MinNumArgs); |
243 | | |
244 | | CUDAKernelCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); |
245 | | |
246 | | public: |
247 | | static CUDAKernelCallExpr *Create(const ASTContext &Ctx, Expr *Fn, |
248 | | CallExpr *Config, ArrayRef<Expr *> Args, |
249 | | QualType Ty, ExprValueKind VK, |
250 | | SourceLocation RP, |
251 | | FPOptionsOverride FPFeatures, |
252 | | unsigned MinNumArgs = 0); |
253 | | |
254 | | static CUDAKernelCallExpr *CreateEmpty(const ASTContext &Ctx, |
255 | | unsigned NumArgs, bool HasFPFeatures, |
256 | | EmptyShell Empty); |
257 | | |
258 | 63 | const CallExpr *getConfig() const { |
259 | 63 | return cast_or_null<CallExpr>(getPreArg(CONFIG)); |
260 | 63 | } |
261 | 20 | CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } |
262 | | |
263 | 270k | static bool classof(const Stmt *T) { |
264 | 270k | return T->getStmtClass() == CUDAKernelCallExprClass; |
265 | 270k | } |
266 | | }; |
267 | | |
268 | | /// A rewritten comparison expression that was originally written using |
269 | | /// operator syntax. |
270 | | /// |
271 | | /// In C++20, the following rewrites are performed: |
272 | | /// - <tt>a == b</tt> -> <tt>b == a</tt> |
273 | | /// - <tt>a != b</tt> -> <tt>!(a == b)</tt> |
274 | | /// - <tt>a != b</tt> -> <tt>!(b == a)</tt> |
275 | | /// - For \c \@ in \c <, \c <=, \c >, \c >=, \c <=>: |
276 | | /// - <tt>a @ b</tt> -> <tt>(a <=> b) @ 0</tt> |
277 | | /// - <tt>a @ b</tt> -> <tt>0 @ (b <=> a)</tt> |
278 | | /// |
279 | | /// This expression provides access to both the original syntax and the |
280 | | /// rewritten expression. |
281 | | /// |
282 | | /// Note that the rewritten calls to \c ==, \c <=>, and \c \@ are typically |
283 | | /// \c CXXOperatorCallExprs, but could theoretically be \c BinaryOperators. |
284 | | class CXXRewrittenBinaryOperator : public Expr { |
285 | | friend class ASTStmtReader; |
286 | | |
287 | | /// The rewritten semantic form. |
288 | | Stmt *SemanticForm; |
289 | | |
290 | | public: |
291 | | CXXRewrittenBinaryOperator(Expr *SemanticForm, bool IsReversed) |
292 | | : Expr(CXXRewrittenBinaryOperatorClass, SemanticForm->getType(), |
293 | | SemanticForm->getValueKind(), SemanticForm->getObjectKind()), |
294 | 347 | SemanticForm(SemanticForm) { |
295 | 347 | CXXRewrittenBinaryOperatorBits.IsReversed = IsReversed; |
296 | 347 | setDependence(computeDependence(this)); |
297 | 347 | } |
298 | | CXXRewrittenBinaryOperator(EmptyShell Empty) |
299 | 4 | : Expr(CXXRewrittenBinaryOperatorClass, Empty), SemanticForm() {} |
300 | | |
301 | | /// Get an equivalent semantic form for this expression. |
302 | 371 | Expr *getSemanticForm() { return cast<Expr>(SemanticForm); } |
303 | 2.44k | const Expr *getSemanticForm() const { return cast<Expr>(SemanticForm); } |
304 | | |
305 | | struct DecomposedForm { |
306 | | /// The original opcode, prior to rewriting. |
307 | | BinaryOperatorKind Opcode; |
308 | | /// The original left-hand side. |
309 | | const Expr *LHS; |
310 | | /// The original right-hand side. |
311 | | const Expr *RHS; |
312 | | /// The inner \c == or \c <=> operator expression. |
313 | | const Expr *InnerBinOp; |
314 | | }; |
315 | | |
316 | | /// Decompose this operator into its syntactic form. |
317 | | DecomposedForm getDecomposedForm() const LLVM_READONLY; |
318 | | |
319 | | /// Determine whether this expression was rewritten in reverse form. |
320 | 3.76k | bool isReversed() const { return CXXRewrittenBinaryOperatorBits.IsReversed; } |
321 | | |
322 | 188 | BinaryOperatorKind getOperator() const { return getDecomposedForm().Opcode; } |
323 | 188 | BinaryOperatorKind getOpcode() const { return getOperator(); } |
324 | 0 | static StringRef getOpcodeStr(BinaryOperatorKind Op) { |
325 | 0 | return BinaryOperator::getOpcodeStr(Op); |
326 | 0 | } |
327 | 188 | StringRef getOpcodeStr() const { |
328 | 188 | return BinaryOperator::getOpcodeStr(getOpcode()); |
329 | 188 | } |
330 | 28 | bool isComparisonOp() const { return true; } |
331 | 0 | bool isAssignmentOp() const { return false; } |
332 | | |
333 | 313 | const Expr *getLHS() const { return getDecomposedForm().LHS; } |
334 | 281 | const Expr *getRHS() const { return getDecomposedForm().RHS; } |
335 | | |
336 | 516 | SourceLocation getOperatorLoc() const LLVM_READONLY { |
337 | 516 | return getDecomposedForm().InnerBinOp->getExprLoc(); |
338 | 516 | } |
339 | 484 | SourceLocation getExprLoc() const LLVM_READONLY { return getOperatorLoc(); } |
340 | | |
341 | | /// Compute the begin and end locations from the decomposed form. |
342 | | /// The locations of the semantic form are not reliable if this is |
343 | | /// a reversed expression. |
344 | | //@{ |
345 | 894 | SourceLocation getBeginLoc() const LLVM_READONLY { |
346 | 894 | return getDecomposedForm().LHS->getBeginLoc(); |
347 | 894 | } |
348 | 2 | SourceLocation getEndLoc() const LLVM_READONLY { |
349 | 2 | return getDecomposedForm().RHS->getEndLoc(); |
350 | 2 | } |
351 | 25 | SourceRange getSourceRange() const LLVM_READONLY { |
352 | 25 | DecomposedForm DF = getDecomposedForm(); |
353 | 25 | return SourceRange(DF.LHS->getBeginLoc(), DF.RHS->getEndLoc()); |
354 | 25 | } |
355 | | //@} |
356 | | |
357 | 972 | child_range children() { |
358 | 972 | return child_range(&SemanticForm, &SemanticForm + 1); |
359 | 972 | } |
360 | | |
361 | 438k | static bool classof(const Stmt *T) { |
362 | 438k | return T->getStmtClass() == CXXRewrittenBinaryOperatorClass; |
363 | 438k | } |
364 | | }; |
365 | | |
366 | | /// Abstract class common to all of the C++ "named"/"keyword" casts. |
367 | | /// |
368 | | /// This abstract class is inherited by all of the classes |
369 | | /// representing "named" casts: CXXStaticCastExpr for \c static_cast, |
370 | | /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for |
371 | | /// reinterpret_cast, CXXConstCastExpr for \c const_cast and |
372 | | /// CXXAddrspaceCastExpr for addrspace_cast (in OpenCL). |
373 | | class CXXNamedCastExpr : public ExplicitCastExpr { |
374 | | private: |
375 | | // the location of the casting op |
376 | | SourceLocation Loc; |
377 | | |
378 | | // the location of the right parenthesis |
379 | | SourceLocation RParenLoc; |
380 | | |
381 | | // range for '<' '>' |
382 | | SourceRange AngleBrackets; |
383 | | |
384 | | protected: |
385 | | friend class ASTStmtReader; |
386 | | |
387 | | CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, CastKind kind, |
388 | | Expr *op, unsigned PathSize, bool HasFPFeatures, |
389 | | TypeSourceInfo *writtenTy, SourceLocation l, |
390 | | SourceLocation RParenLoc, SourceRange AngleBrackets) |
391 | | : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, HasFPFeatures, |
392 | | writtenTy), |
393 | 345k | Loc(l), RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {} |
394 | | |
395 | | explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize, |
396 | | bool HasFPFeatures) |
397 | 62.6k | : ExplicitCastExpr(SC, Shell, PathSize, HasFPFeatures) {} |
398 | | |
399 | | public: |
400 | | const char *getCastName() const; |
401 | | |
402 | | /// Retrieve the location of the cast operator keyword, e.g., |
403 | | /// \c static_cast. |
404 | 116k | SourceLocation getOperatorLoc() const { return Loc; } |
405 | | |
406 | | /// Retrieve the location of the closing parenthesis. |
407 | 116k | SourceLocation getRParenLoc() const { return RParenLoc; } |
408 | | |
409 | 692k | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
410 | 35.7k | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
411 | 197k | SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; } |
412 | | |
413 | 75 | static bool classof(const Stmt *T) { |
414 | 75 | switch (T->getStmtClass()) { |
415 | 16 | case CXXStaticCastExprClass: |
416 | 16 | case CXXDynamicCastExprClass: |
417 | 22 | case CXXReinterpretCastExprClass: |
418 | 22 | case CXXConstCastExprClass: |
419 | 22 | case CXXAddrspaceCastExprClass: |
420 | 22 | return true; |
421 | 53 | default: |
422 | 53 | return false; |
423 | 75 | } |
424 | 75 | } |
425 | | }; |
426 | | |
427 | | /// A C++ \c static_cast expression (C++ [expr.static.cast]). |
428 | | /// |
429 | | /// This expression node represents a C++ static cast, e.g., |
430 | | /// \c static_cast<int>(1.0). |
431 | | class CXXStaticCastExpr final |
432 | | : public CXXNamedCastExpr, |
433 | | private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *, |
434 | | FPOptionsOverride> { |
435 | | CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, |
436 | | unsigned pathSize, TypeSourceInfo *writtenTy, |
437 | | FPOptionsOverride FPO, SourceLocation l, |
438 | | SourceLocation RParenLoc, SourceRange AngleBrackets) |
439 | | : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, |
440 | | FPO.requiresTrailingStorage(), writtenTy, l, RParenLoc, |
441 | 323k | AngleBrackets) { |
442 | 323k | if (hasStoredFPFeatures()) |
443 | 10 | *getTrailingFPFeatures() = FPO; |
444 | 323k | } |
445 | | |
446 | | explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize, |
447 | | bool HasFPFeatures) |
448 | | : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize, |
449 | 58.8k | HasFPFeatures) {} |
450 | | |
451 | 14 | unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const { |
452 | 14 | return path_size(); |
453 | 14 | } |
454 | | |
455 | | public: |
456 | | friend class CastExpr; |
457 | | friend TrailingObjects; |
458 | | |
459 | | static CXXStaticCastExpr * |
460 | | Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, |
461 | | Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, |
462 | | FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, |
463 | | SourceRange AngleBrackets); |
464 | | static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context, |
465 | | unsigned PathSize, bool hasFPFeatures); |
466 | | |
467 | 98.6k | static bool classof(const Stmt *T) { |
468 | 98.6k | return T->getStmtClass() == CXXStaticCastExprClass; |
469 | 98.6k | } |
470 | | }; |
471 | | |
472 | | /// A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]). |
473 | | /// |
474 | | /// This expression node represents a dynamic cast, e.g., |
475 | | /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time |
476 | | /// check to determine how to perform the type conversion. |
477 | | class CXXDynamicCastExpr final |
478 | | : public CXXNamedCastExpr, |
479 | | private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> { |
480 | | CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, Expr *op, |
481 | | unsigned pathSize, TypeSourceInfo *writtenTy, |
482 | | SourceLocation l, SourceLocation RParenLoc, |
483 | | SourceRange AngleBrackets) |
484 | | : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, |
485 | | /*HasFPFeatures*/ false, writtenTy, l, RParenLoc, |
486 | 1.29k | AngleBrackets) {} |
487 | | |
488 | | explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) |
489 | | : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize, |
490 | 3 | /*HasFPFeatures*/ false) {} |
491 | | |
492 | | public: |
493 | | friend class CastExpr; |
494 | | friend TrailingObjects; |
495 | | |
496 | | static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T, |
497 | | ExprValueKind VK, CastKind Kind, Expr *Op, |
498 | | const CXXCastPath *Path, |
499 | | TypeSourceInfo *Written, SourceLocation L, |
500 | | SourceLocation RParenLoc, |
501 | | SourceRange AngleBrackets); |
502 | | |
503 | | static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context, |
504 | | unsigned pathSize); |
505 | | |
506 | | bool isAlwaysNull() const; |
507 | | |
508 | 436k | static bool classof(const Stmt *T) { |
509 | 436k | return T->getStmtClass() == CXXDynamicCastExprClass; |
510 | 436k | } |
511 | | }; |
512 | | |
513 | | /// A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]). |
514 | | /// |
515 | | /// This expression node represents a reinterpret cast, e.g., |
516 | | /// @c reinterpret_cast<int>(VoidPtr). |
517 | | /// |
518 | | /// A reinterpret_cast provides a differently-typed view of a value but |
519 | | /// (in Clang, as in most C++ implementations) performs no actual work at |
520 | | /// run time. |
521 | | class CXXReinterpretCastExpr final |
522 | | : public CXXNamedCastExpr, |
523 | | private llvm::TrailingObjects<CXXReinterpretCastExpr, |
524 | | CXXBaseSpecifier *> { |
525 | | CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, |
526 | | unsigned pathSize, TypeSourceInfo *writtenTy, |
527 | | SourceLocation l, SourceLocation RParenLoc, |
528 | | SourceRange AngleBrackets) |
529 | | : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, |
530 | | pathSize, /*HasFPFeatures*/ false, writtenTy, l, |
531 | 9.63k | RParenLoc, AngleBrackets) {} |
532 | | |
533 | | CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) |
534 | | : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize, |
535 | 589 | /*HasFPFeatures*/ false) {} |
536 | | |
537 | | public: |
538 | | friend class CastExpr; |
539 | | friend TrailingObjects; |
540 | | |
541 | | static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T, |
542 | | ExprValueKind VK, CastKind Kind, |
543 | | Expr *Op, const CXXCastPath *Path, |
544 | | TypeSourceInfo *WrittenTy, SourceLocation L, |
545 | | SourceLocation RParenLoc, |
546 | | SourceRange AngleBrackets); |
547 | | static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context, |
548 | | unsigned pathSize); |
549 | | |
550 | 146k | static bool classof(const Stmt *T) { |
551 | 146k | return T->getStmtClass() == CXXReinterpretCastExprClass; |
552 | 146k | } |
553 | | }; |
554 | | |
555 | | /// A C++ \c const_cast expression (C++ [expr.const.cast]). |
556 | | /// |
557 | | /// This expression node represents a const cast, e.g., |
558 | | /// \c const_cast<char*>(PtrToConstChar). |
559 | | /// |
560 | | /// A const_cast can remove type qualifiers but does not change the underlying |
561 | | /// value. |
562 | | class CXXConstCastExpr final |
563 | | : public CXXNamedCastExpr, |
564 | | private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> { |
565 | | CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, |
566 | | TypeSourceInfo *writtenTy, SourceLocation l, |
567 | | SourceLocation RParenLoc, SourceRange AngleBrackets) |
568 | | : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 0, |
569 | | /*HasFPFeatures*/ false, writtenTy, l, RParenLoc, |
570 | 10.6k | AngleBrackets) {} |
571 | | |
572 | | explicit CXXConstCastExpr(EmptyShell Empty) |
573 | | : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0, |
574 | 3.20k | /*HasFPFeatures*/ false) {} |
575 | | |
576 | | public: |
577 | | friend class CastExpr; |
578 | | friend TrailingObjects; |
579 | | |
580 | | static CXXConstCastExpr *Create(const ASTContext &Context, QualType T, |
581 | | ExprValueKind VK, Expr *Op, |
582 | | TypeSourceInfo *WrittenTy, SourceLocation L, |
583 | | SourceLocation RParenLoc, |
584 | | SourceRange AngleBrackets); |
585 | | static CXXConstCastExpr *CreateEmpty(const ASTContext &Context); |
586 | | |
587 | 4.38k | static bool classof(const Stmt *T) { |
588 | 4.38k | return T->getStmtClass() == CXXConstCastExprClass; |
589 | 4.38k | } |
590 | | }; |
591 | | |
592 | | /// A C++ addrspace_cast expression (currently only enabled for OpenCL). |
593 | | /// |
594 | | /// This expression node represents a cast between pointers to objects in |
595 | | /// different address spaces e.g., |
596 | | /// \c addrspace_cast<global int*>(PtrToGenericInt). |
597 | | /// |
598 | | /// A addrspace_cast can cast address space type qualifiers but does not change |
599 | | /// the underlying value. |
600 | | class CXXAddrspaceCastExpr final |
601 | | : public CXXNamedCastExpr, |
602 | | private llvm::TrailingObjects<CXXAddrspaceCastExpr, CXXBaseSpecifier *> { |
603 | | CXXAddrspaceCastExpr(QualType ty, ExprValueKind VK, CastKind Kind, Expr *op, |
604 | | TypeSourceInfo *writtenTy, SourceLocation l, |
605 | | SourceLocation RParenLoc, SourceRange AngleBrackets) |
606 | | : CXXNamedCastExpr(CXXAddrspaceCastExprClass, ty, VK, Kind, op, 0, |
607 | | /*HasFPFeatures*/ false, writtenTy, l, RParenLoc, |
608 | 10 | AngleBrackets) {} |
609 | | |
610 | | explicit CXXAddrspaceCastExpr(EmptyShell Empty) |
611 | | : CXXNamedCastExpr(CXXAddrspaceCastExprClass, Empty, 0, |
612 | 0 | /*HasFPFeatures*/ false) {} |
613 | | |
614 | | public: |
615 | | friend class CastExpr; |
616 | | friend TrailingObjects; |
617 | | |
618 | | static CXXAddrspaceCastExpr * |
619 | | Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, |
620 | | Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, |
621 | | SourceLocation RParenLoc, SourceRange AngleBrackets); |
622 | | static CXXAddrspaceCastExpr *CreateEmpty(const ASTContext &Context); |
623 | | |
624 | 3 | static bool classof(const Stmt *T) { |
625 | 3 | return T->getStmtClass() == CXXAddrspaceCastExprClass; |
626 | 3 | } |
627 | | }; |
628 | | |
629 | | /// A call to a literal operator (C++11 [over.literal]) |
630 | | /// written as a user-defined literal (C++11 [lit.ext]). |
631 | | /// |
632 | | /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this |
633 | | /// is semantically equivalent to a normal call, this AST node provides better |
634 | | /// information about the syntactic representation of the literal. |
635 | | /// |
636 | | /// Since literal operators are never found by ADL and can only be declared at |
637 | | /// namespace scope, a user-defined literal is never dependent. |
638 | | class UserDefinedLiteral final : public CallExpr { |
639 | | friend class ASTStmtReader; |
640 | | friend class ASTStmtWriter; |
641 | | |
642 | | /// The location of a ud-suffix within the literal. |
643 | | SourceLocation UDSuffixLoc; |
644 | | |
645 | | // UserDefinedLiteral has some trailing objects belonging |
646 | | // to CallExpr. See CallExpr for the details. |
647 | | |
648 | | UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty, |
649 | | ExprValueKind VK, SourceLocation LitEndLoc, |
650 | | SourceLocation SuffixLoc, FPOptionsOverride FPFeatures); |
651 | | |
652 | | UserDefinedLiteral(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); |
653 | | |
654 | | public: |
655 | | static UserDefinedLiteral *Create(const ASTContext &Ctx, Expr *Fn, |
656 | | ArrayRef<Expr *> Args, QualType Ty, |
657 | | ExprValueKind VK, SourceLocation LitEndLoc, |
658 | | SourceLocation SuffixLoc, |
659 | | FPOptionsOverride FPFeatures); |
660 | | |
661 | | static UserDefinedLiteral *CreateEmpty(const ASTContext &Ctx, |
662 | | unsigned NumArgs, bool HasFPOptions, |
663 | | EmptyShell Empty); |
664 | | |
665 | | /// The kind of literal operator which is invoked. |
666 | | enum LiteralOperatorKind { |
667 | | /// Raw form: operator "" X (const char *) |
668 | | LOK_Raw, |
669 | | |
670 | | /// Raw form: operator "" X<cs...> () |
671 | | LOK_Template, |
672 | | |
673 | | /// operator "" X (unsigned long long) |
674 | | LOK_Integer, |
675 | | |
676 | | /// operator "" X (long double) |
677 | | LOK_Floating, |
678 | | |
679 | | /// operator "" X (const CharT *, size_t) |
680 | | LOK_String, |
681 | | |
682 | | /// operator "" X (CharT) |
683 | | LOK_Character |
684 | | }; |
685 | | |
686 | | /// Returns the kind of literal operator invocation |
687 | | /// which this expression represents. |
688 | | LiteralOperatorKind getLiteralOperatorKind() const; |
689 | | |
690 | | /// If this is not a raw user-defined literal, get the |
691 | | /// underlying cooked literal (representing the literal with the suffix |
692 | | /// removed). |
693 | | Expr *getCookedLiteral(); |
694 | 0 | const Expr *getCookedLiteral() const { |
695 | 0 | return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral(); |
696 | 0 | } |
697 | | |
698 | 8.91k | SourceLocation getBeginLoc() const { |
699 | 8.91k | if (getLiteralOperatorKind() == LOK_Template) |
700 | 695 | return getRParenLoc(); |
701 | 8.21k | return getArg(0)->getBeginLoc(); |
702 | 8.91k | } |
703 | | |
704 | 139 | SourceLocation getEndLoc() const { return getRParenLoc(); } |
705 | | |
706 | | /// Returns the location of a ud-suffix in the expression. |
707 | | /// |
708 | | /// For a string literal, there may be multiple identical suffixes. This |
709 | | /// returns the first. |
710 | 0 | SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; } |
711 | | |
712 | | /// Returns the ud-suffix specified for this literal. |
713 | | const IdentifierInfo *getUDSuffix() const; |
714 | | |
715 | 13 | static bool classof(const Stmt *S) { |
716 | 13 | return S->getStmtClass() == UserDefinedLiteralClass; |
717 | 13 | } |
718 | | }; |
719 | | |
720 | | /// A boolean literal, per ([C++ lex.bool] Boolean literals). |
721 | | class CXXBoolLiteralExpr : public Expr { |
722 | | public: |
723 | | CXXBoolLiteralExpr(bool Val, QualType Ty, SourceLocation Loc) |
724 | 763k | : Expr(CXXBoolLiteralExprClass, Ty, VK_PRValue, OK_Ordinary) { |
725 | 763k | CXXBoolLiteralExprBits.Value = Val; |
726 | 763k | CXXBoolLiteralExprBits.Loc = Loc; |
727 | 763k | setDependence(ExprDependence::None); |
728 | 763k | } |
729 | | |
730 | | explicit CXXBoolLiteralExpr(EmptyShell Empty) |
731 | 145k | : Expr(CXXBoolLiteralExprClass, Empty) {} |
732 | | |
733 | 964k | bool getValue() const { return CXXBoolLiteralExprBits.Value; } |
734 | 145k | void setValue(bool V) { CXXBoolLiteralExprBits.Value = V; } |
735 | | |
736 | 3.05M | SourceLocation getBeginLoc() const { return getLocation(); } |
737 | 33.5k | SourceLocation getEndLoc() const { return getLocation(); } |
738 | | |
739 | 3.17M | SourceLocation getLocation() const { return CXXBoolLiteralExprBits.Loc; } |
740 | 145k | void setLocation(SourceLocation L) { CXXBoolLiteralExprBits.Loc = L; } |
741 | | |
742 | 569k | static bool classof(const Stmt *T) { |
743 | 569k | return T->getStmtClass() == CXXBoolLiteralExprClass; |
744 | 569k | } |
745 | | |
746 | | // Iterators |
747 | 1.91M | child_range children() { |
748 | 1.91M | return child_range(child_iterator(), child_iterator()); |
749 | 1.91M | } |
750 | | |
751 | 0 | const_child_range children() const { |
752 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
753 | 0 | } |
754 | | }; |
755 | | |
756 | | /// The null pointer literal (C++11 [lex.nullptr]) |
757 | | /// |
758 | | /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr. |
759 | | class CXXNullPtrLiteralExpr : public Expr { |
760 | | public: |
761 | | CXXNullPtrLiteralExpr(QualType Ty, SourceLocation Loc) |
762 | 204k | : Expr(CXXNullPtrLiteralExprClass, Ty, VK_PRValue, OK_Ordinary) { |
763 | 204k | CXXNullPtrLiteralExprBits.Loc = Loc; |
764 | 204k | setDependence(ExprDependence::None); |
765 | 204k | } |
766 | | |
767 | | explicit CXXNullPtrLiteralExpr(EmptyShell Empty) |
768 | 52.4k | : Expr(CXXNullPtrLiteralExprClass, Empty) {} |
769 | | |
770 | 424k | SourceLocation getBeginLoc() const { return getLocation(); } |
771 | 94.3k | SourceLocation getEndLoc() const { return getLocation(); } |
772 | | |
773 | 578k | SourceLocation getLocation() const { return CXXNullPtrLiteralExprBits.Loc; } |
774 | 52.4k | void setLocation(SourceLocation L) { CXXNullPtrLiteralExprBits.Loc = L; } |
775 | | |
776 | 84.5k | static bool classof(const Stmt *T) { |
777 | 84.5k | return T->getStmtClass() == CXXNullPtrLiteralExprClass; |
778 | 84.5k | } |
779 | | |
780 | 139k | child_range children() { |
781 | 139k | return child_range(child_iterator(), child_iterator()); |
782 | 139k | } |
783 | | |
784 | 0 | const_child_range children() const { |
785 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
786 | 0 | } |
787 | | }; |
788 | | |
789 | | /// Implicit construction of a std::initializer_list<T> object from an |
790 | | /// array temporary within list-initialization (C++11 [dcl.init.list]p5). |
791 | | class CXXStdInitializerListExpr : public Expr { |
792 | | Stmt *SubExpr = nullptr; |
793 | | |
794 | | CXXStdInitializerListExpr(EmptyShell Empty) |
795 | 3 | : Expr(CXXStdInitializerListExprClass, Empty) {} |
796 | | |
797 | | public: |
798 | | friend class ASTReader; |
799 | | friend class ASTStmtReader; |
800 | | |
801 | | CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr) |
802 | | : Expr(CXXStdInitializerListExprClass, Ty, VK_PRValue, OK_Ordinary), |
803 | 684 | SubExpr(SubExpr) { |
804 | 684 | setDependence(computeDependence(this)); |
805 | 684 | } |
806 | | |
807 | 1.28k | Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); } |
808 | 328 | const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); } |
809 | | |
810 | 2.98k | SourceLocation getBeginLoc() const LLVM_READONLY { |
811 | 2.98k | return SubExpr->getBeginLoc(); |
812 | 2.98k | } |
813 | | |
814 | 33 | SourceLocation getEndLoc() const LLVM_READONLY { |
815 | 33 | return SubExpr->getEndLoc(); |
816 | 33 | } |
817 | | |
818 | | /// Retrieve the source range of the expression. |
819 | 57 | SourceRange getSourceRange() const LLVM_READONLY { |
820 | 57 | return SubExpr->getSourceRange(); |
821 | 57 | } |
822 | | |
823 | 4.55M | static bool classof(const Stmt *S) { |
824 | 4.55M | return S->getStmtClass() == CXXStdInitializerListExprClass; |
825 | 4.55M | } |
826 | | |
827 | 2.19k | child_range children() { return child_range(&SubExpr, &SubExpr + 1); } |
828 | | |
829 | 0 | const_child_range children() const { |
830 | 0 | return const_child_range(&SubExpr, &SubExpr + 1); |
831 | 0 | } |
832 | | }; |
833 | | |
834 | | /// A C++ \c typeid expression (C++ [expr.typeid]), which gets |
835 | | /// the \c type_info that corresponds to the supplied type, or the (possibly |
836 | | /// dynamic) type of the supplied expression. |
837 | | /// |
838 | | /// This represents code like \c typeid(int) or \c typeid(*objPtr) |
839 | | class CXXTypeidExpr : public Expr { |
840 | | friend class ASTStmtReader; |
841 | | |
842 | | private: |
843 | | llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; |
844 | | SourceRange Range; |
845 | | |
846 | | public: |
847 | | CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) |
848 | | : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), |
849 | 5.13k | Range(R) { |
850 | 5.13k | setDependence(computeDependence(this)); |
851 | 5.13k | } |
852 | | |
853 | | CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) |
854 | | : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), |
855 | 337 | Range(R) { |
856 | 337 | setDependence(computeDependence(this)); |
857 | 337 | } |
858 | | |
859 | | CXXTypeidExpr(EmptyShell Empty, bool isExpr) |
860 | 138 | : Expr(CXXTypeidExprClass, Empty) { |
861 | 138 | if (isExpr) |
862 | 2 | Operand = (Expr*)nullptr; |
863 | 136 | else |
864 | 136 | Operand = (TypeSourceInfo*)nullptr; |
865 | 138 | } |
866 | | |
867 | | /// Determine whether this typeid has a type operand which is potentially |
868 | | /// evaluated, per C++11 [expr.typeid]p3. |
869 | | bool isPotentiallyEvaluated() const; |
870 | | |
871 | | /// Best-effort check if the expression operand refers to a most derived |
872 | | /// object. This is not a strong guarantee. |
873 | | bool isMostDerived(ASTContext &Context) const; |
874 | | |
875 | 23.7k | bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } |
876 | | |
877 | | /// Retrieves the type operand of this typeid() expression after |
878 | | /// various required adjustments (removing reference types, cv-qualifiers). |
879 | | QualType getTypeOperand(ASTContext &Context) const; |
880 | | |
881 | | /// Retrieve source information for the type operand. |
882 | 5.97k | TypeSourceInfo *getTypeOperandSourceInfo() const { |
883 | 5.97k | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); |
884 | 0 | return Operand.get<TypeSourceInfo *>(); |
885 | 5.97k | } |
886 | 1.67k | Expr *getExprOperand() const { |
887 | 1.67k | assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); |
888 | 0 | return static_cast<Expr*>(Operand.get<Stmt *>()); |
889 | 1.67k | } |
890 | | |
891 | 15.5k | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
892 | 1.60k | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
893 | 1.61k | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
894 | 138 | void setSourceRange(SourceRange R) { Range = R; } |
895 | | |
896 | 4.98k | static bool classof(const Stmt *T) { |
897 | 4.98k | return T->getStmtClass() == CXXTypeidExprClass; |
898 | 4.98k | } |
899 | | |
900 | | // Iterators |
901 | 2.08k | child_range children() { |
902 | 2.08k | if (isTypeOperand()) |
903 | 1.65k | return child_range(child_iterator(), child_iterator()); |
904 | 431 | auto **begin = reinterpret_cast<Stmt **>(&Operand); |
905 | 431 | return child_range(begin, begin + 1); |
906 | 2.08k | } |
907 | | |
908 | 0 | const_child_range children() const { |
909 | 0 | if (isTypeOperand()) |
910 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
911 | 0 |
|
912 | 0 | auto **begin = |
913 | 0 | reinterpret_cast<Stmt **>(&const_cast<CXXTypeidExpr *>(this)->Operand); |
914 | 0 | return const_child_range(begin, begin + 1); |
915 | 0 | } |
916 | | }; |
917 | | |
918 | | /// A member reference to an MSPropertyDecl. |
919 | | /// |
920 | | /// This expression always has pseudo-object type, and therefore it is |
921 | | /// typically not encountered in a fully-typechecked expression except |
922 | | /// within the syntactic form of a PseudoObjectExpr. |
923 | | class MSPropertyRefExpr : public Expr { |
924 | | Expr *BaseExpr; |
925 | | MSPropertyDecl *TheDecl; |
926 | | SourceLocation MemberLoc; |
927 | | bool IsArrow; |
928 | | NestedNameSpecifierLoc QualifierLoc; |
929 | | |
930 | | public: |
931 | | friend class ASTStmtReader; |
932 | | |
933 | | MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow, |
934 | | QualType ty, ExprValueKind VK, |
935 | | NestedNameSpecifierLoc qualifierLoc, SourceLocation nameLoc) |
936 | | : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary), BaseExpr(baseExpr), |
937 | | TheDecl(decl), MemberLoc(nameLoc), IsArrow(isArrow), |
938 | 532 | QualifierLoc(qualifierLoc) { |
939 | 532 | setDependence(computeDependence(this)); |
940 | 532 | } |
941 | | |
942 | 22 | MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {} |
943 | | |
944 | 601 | SourceRange getSourceRange() const LLVM_READONLY { |
945 | 601 | return SourceRange(getBeginLoc(), getEndLoc()); |
946 | 601 | } |
947 | | |
948 | 1.93k | bool isImplicitAccess() const { |
949 | 1.93k | return getBaseExpr() && getBaseExpr()->isImplicitCXXThis(); |
950 | 1.93k | } |
951 | | |
952 | 1.93k | SourceLocation getBeginLoc() const { |
953 | 1.93k | if (!isImplicitAccess()) |
954 | 1.69k | return BaseExpr->getBeginLoc(); |
955 | 237 | else if (QualifierLoc) |
956 | 18 | return QualifierLoc.getBeginLoc(); |
957 | 219 | else |
958 | 219 | return MemberLoc; |
959 | 1.93k | } |
960 | | |
961 | 650 | SourceLocation getEndLoc() const { return getMemberLoc(); } |
962 | | |
963 | 368 | child_range children() { |
964 | 368 | return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1); |
965 | 368 | } |
966 | | |
967 | 0 | const_child_range children() const { |
968 | 0 | auto Children = const_cast<MSPropertyRefExpr *>(this)->children(); |
969 | 0 | return const_child_range(Children.begin(), Children.end()); |
970 | 0 | } |
971 | | |
972 | 1.02k | static bool classof(const Stmt *T) { |
973 | 1.02k | return T->getStmtClass() == MSPropertyRefExprClass; |
974 | 1.02k | } |
975 | | |
976 | 5.28k | Expr *getBaseExpr() const { return BaseExpr; } |
977 | 1.01k | MSPropertyDecl *getPropertyDecl() const { return TheDecl; } |
978 | 611 | bool isArrow() const { return IsArrow; } |
979 | 1.29k | SourceLocation getMemberLoc() const { return MemberLoc; } |
980 | 613 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
981 | | }; |
982 | | |
983 | | /// MS property subscript expression. |
984 | | /// MSVC supports 'property' attribute and allows to apply it to the |
985 | | /// declaration of an empty array in a class or structure definition. |
986 | | /// For example: |
987 | | /// \code |
988 | | /// __declspec(property(get=GetX, put=PutX)) int x[]; |
989 | | /// \endcode |
990 | | /// The above statement indicates that x[] can be used with one or more array |
991 | | /// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and |
992 | | /// p->x[a][b] = i will be turned into p->PutX(a, b, i). |
993 | | /// This is a syntactic pseudo-object expression. |
994 | | class MSPropertySubscriptExpr : public Expr { |
995 | | friend class ASTStmtReader; |
996 | | |
997 | | enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 }; |
998 | | |
999 | | Stmt *SubExprs[NUM_SUBEXPRS]; |
1000 | | SourceLocation RBracketLoc; |
1001 | | |
1002 | 36 | void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; } |
1003 | 36 | void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; } |
1004 | | |
1005 | | public: |
1006 | | MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK, |
1007 | | ExprObjectKind OK, SourceLocation RBracketLoc) |
1008 | | : Expr(MSPropertySubscriptExprClass, Ty, VK, OK), |
1009 | 312 | RBracketLoc(RBracketLoc) { |
1010 | 312 | SubExprs[BASE_EXPR] = Base; |
1011 | 312 | SubExprs[IDX_EXPR] = Idx; |
1012 | 312 | setDependence(computeDependence(this)); |
1013 | 312 | } |
1014 | | |
1015 | | /// Create an empty array subscript expression. |
1016 | | explicit MSPropertySubscriptExpr(EmptyShell Shell) |
1017 | 36 | : Expr(MSPropertySubscriptExprClass, Shell) {} |
1018 | | |
1019 | 596 | Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); } |
1020 | 972 | const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); } |
1021 | | |
1022 | 886 | Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); } |
1023 | 0 | const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); } |
1024 | | |
1025 | 566 | SourceLocation getBeginLoc() const LLVM_READONLY { |
1026 | 566 | return getBase()->getBeginLoc(); |
1027 | 566 | } |
1028 | | |
1029 | 97 | SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; } |
1030 | | |
1031 | 224 | SourceLocation getRBracketLoc() const { return RBracketLoc; } |
1032 | 36 | void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } |
1033 | | |
1034 | 406 | SourceLocation getExprLoc() const LLVM_READONLY { |
1035 | 406 | return getBase()->getExprLoc(); |
1036 | 406 | } |
1037 | | |
1038 | 554 | static bool classof(const Stmt *T) { |
1039 | 554 | return T->getStmtClass() == MSPropertySubscriptExprClass; |
1040 | 554 | } |
1041 | | |
1042 | | // Iterators |
1043 | 220 | child_range children() { |
1044 | 220 | return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); |
1045 | 220 | } |
1046 | | |
1047 | 0 | const_child_range children() const { |
1048 | 0 | return const_child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); |
1049 | 0 | } |
1050 | | }; |
1051 | | |
1052 | | /// A Microsoft C++ @c __uuidof expression, which gets |
1053 | | /// the _GUID that corresponds to the supplied type or expression. |
1054 | | /// |
1055 | | /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) |
1056 | | class CXXUuidofExpr : public Expr { |
1057 | | friend class ASTStmtReader; |
1058 | | |
1059 | | private: |
1060 | | llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; |
1061 | | MSGuidDecl *Guid; |
1062 | | SourceRange Range; |
1063 | | |
1064 | | public: |
1065 | | CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, MSGuidDecl *Guid, |
1066 | | SourceRange R) |
1067 | | : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), |
1068 | 152 | Guid(Guid), Range(R) { |
1069 | 152 | setDependence(computeDependence(this)); |
1070 | 152 | } |
1071 | | |
1072 | | CXXUuidofExpr(QualType Ty, Expr *Operand, MSGuidDecl *Guid, SourceRange R) |
1073 | | : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), |
1074 | 30 | Guid(Guid), Range(R) { |
1075 | 30 | setDependence(computeDependence(this)); |
1076 | 30 | } |
1077 | | |
1078 | | CXXUuidofExpr(EmptyShell Empty, bool isExpr) |
1079 | 1 | : Expr(CXXUuidofExprClass, Empty) { |
1080 | 1 | if (isExpr) |
1081 | 1 | Operand = (Expr*)nullptr; |
1082 | 0 | else |
1083 | 0 | Operand = (TypeSourceInfo*)nullptr; |
1084 | 1 | } |
1085 | | |
1086 | 599 | bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } |
1087 | | |
1088 | | /// Retrieves the type operand of this __uuidof() expression after |
1089 | | /// various required adjustments (removing reference types, cv-qualifiers). |
1090 | | QualType getTypeOperand(ASTContext &Context) const; |
1091 | | |
1092 | | /// Retrieve source information for the type operand. |
1093 | 187 | TypeSourceInfo *getTypeOperandSourceInfo() const { |
1094 | 187 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); |
1095 | 0 | return Operand.get<TypeSourceInfo *>(); |
1096 | 187 | } |
1097 | 51 | Expr *getExprOperand() const { |
1098 | 51 | assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); |
1099 | 0 | return static_cast<Expr*>(Operand.get<Stmt *>()); |
1100 | 51 | } |
1101 | | |
1102 | 263 | MSGuidDecl *getGuidDecl() const { return Guid; } |
1103 | | |
1104 | 697 | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
1105 | 54 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
1106 | 46 | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
1107 | 1 | void setSourceRange(SourceRange R) { Range = R; } |
1108 | | |
1109 | 26.2k | static bool classof(const Stmt *T) { |
1110 | 26.2k | return T->getStmtClass() == CXXUuidofExprClass; |
1111 | 26.2k | } |
1112 | | |
1113 | | // Iterators |
1114 | 137 | child_range children() { |
1115 | 137 | if (isTypeOperand()) |
1116 | 110 | return child_range(child_iterator(), child_iterator()); |
1117 | 27 | auto **begin = reinterpret_cast<Stmt **>(&Operand); |
1118 | 27 | return child_range(begin, begin + 1); |
1119 | 137 | } |
1120 | | |
1121 | 0 | const_child_range children() const { |
1122 | 0 | if (isTypeOperand()) |
1123 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1124 | 0 | auto **begin = |
1125 | 0 | reinterpret_cast<Stmt **>(&const_cast<CXXUuidofExpr *>(this)->Operand); |
1126 | 0 | return const_child_range(begin, begin + 1); |
1127 | 0 | } |
1128 | | }; |
1129 | | |
1130 | | /// Represents the \c this expression in C++. |
1131 | | /// |
1132 | | /// This is a pointer to the object on which the current member function is |
1133 | | /// executing (C++ [expr.prim]p3). Example: |
1134 | | /// |
1135 | | /// \code |
1136 | | /// class Foo { |
1137 | | /// public: |
1138 | | /// void bar(); |
1139 | | /// void test() { this->bar(); } |
1140 | | /// }; |
1141 | | /// \endcode |
1142 | | class CXXThisExpr : public Expr { |
1143 | | public: |
1144 | | CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit) |
1145 | 2.10M | : Expr(CXXThisExprClass, Ty, VK_PRValue, OK_Ordinary) { |
1146 | 2.10M | CXXThisExprBits.IsImplicit = IsImplicit; |
1147 | 2.10M | CXXThisExprBits.Loc = L; |
1148 | 2.10M | setDependence(computeDependence(this)); |
1149 | 2.10M | } |
1150 | | |
1151 | 465k | CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} |
1152 | | |
1153 | 3.40M | SourceLocation getLocation() const { return CXXThisExprBits.Loc; } |
1154 | 465k | void setLocation(SourceLocation L) { CXXThisExprBits.Loc = L; } |
1155 | | |
1156 | 2.64M | SourceLocation getBeginLoc() const { return getLocation(); } |
1157 | 205k | SourceLocation getEndLoc() const { return getLocation(); } |
1158 | | |
1159 | 5.99M | bool isImplicit() const { return CXXThisExprBits.IsImplicit; } |
1160 | 465k | void setImplicit(bool I) { CXXThisExprBits.IsImplicit = I; } |
1161 | | |
1162 | 18.4M | static bool classof(const Stmt *T) { |
1163 | 18.4M | return T->getStmtClass() == CXXThisExprClass; |
1164 | 18.4M | } |
1165 | | |
1166 | | // Iterators |
1167 | 729k | child_range children() { |
1168 | 729k | return child_range(child_iterator(), child_iterator()); |
1169 | 729k | } |
1170 | | |
1171 | 0 | const_child_range children() const { |
1172 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1173 | 0 | } |
1174 | | }; |
1175 | | |
1176 | | /// A C++ throw-expression (C++ [except.throw]). |
1177 | | /// |
1178 | | /// This handles 'throw' (for re-throwing the current exception) and |
1179 | | /// 'throw' assignment-expression. When assignment-expression isn't |
1180 | | /// present, Op will be null. |
1181 | | class CXXThrowExpr : public Expr { |
1182 | | friend class ASTStmtReader; |
1183 | | |
1184 | | /// The optional expression in the throw statement. |
1185 | | Stmt *Operand; |
1186 | | |
1187 | | public: |
1188 | | // \p Ty is the void type which is used as the result type of the |
1189 | | // expression. The \p Loc is the location of the throw keyword. |
1190 | | // \p Operand is the expression in the throw statement, and can be |
1191 | | // null if not present. |
1192 | | CXXThrowExpr(Expr *Operand, QualType Ty, SourceLocation Loc, |
1193 | | bool IsThrownVariableInScope) |
1194 | 17.9k | : Expr(CXXThrowExprClass, Ty, VK_PRValue, OK_Ordinary), Operand(Operand) { |
1195 | 17.9k | CXXThrowExprBits.ThrowLoc = Loc; |
1196 | 17.9k | CXXThrowExprBits.IsThrownVariableInScope = IsThrownVariableInScope; |
1197 | 17.9k | setDependence(computeDependence(this)); |
1198 | 17.9k | } |
1199 | 86 | CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} |
1200 | | |
1201 | 2.32k | const Expr *getSubExpr() const { return cast_or_null<Expr>(Operand); } |
1202 | 19.0k | Expr *getSubExpr() { return cast_or_null<Expr>(Operand); } |
1203 | | |
1204 | 56.7k | SourceLocation getThrowLoc() const { return CXXThrowExprBits.ThrowLoc; } |
1205 | | |
1206 | | /// Determines whether the variable thrown by this expression (if any!) |
1207 | | /// is within the innermost try block. |
1208 | | /// |
1209 | | /// This information is required to determine whether the NRVO can apply to |
1210 | | /// this variable. |
1211 | 832 | bool isThrownVariableInScope() const { |
1212 | 832 | return CXXThrowExprBits.IsThrownVariableInScope; |
1213 | 832 | } |
1214 | | |
1215 | 55.8k | SourceLocation getBeginLoc() const { return getThrowLoc(); } |
1216 | 53 | SourceLocation getEndLoc() const LLVM_READONLY { |
1217 | 53 | if (!getSubExpr()) |
1218 | 16 | return getThrowLoc(); |
1219 | 37 | return getSubExpr()->getEndLoc(); |
1220 | 53 | } |
1221 | | |
1222 | 370k | static bool classof(const Stmt *T) { |
1223 | 370k | return T->getStmtClass() == CXXThrowExprClass; |
1224 | 370k | } |
1225 | | |
1226 | | // Iterators |
1227 | 36.9k | child_range children() { |
1228 | 36.9k | return child_range(&Operand, Operand ? &Operand + 116.7k : &Operand20.2k ); |
1229 | 36.9k | } |
1230 | | |
1231 | 0 | const_child_range children() const { |
1232 | 0 | return const_child_range(&Operand, Operand ? &Operand + 1 : &Operand); |
1233 | 0 | } |
1234 | | }; |
1235 | | |
1236 | | /// A default argument (C++ [dcl.fct.default]). |
1237 | | /// |
1238 | | /// This wraps up a function call argument that was created from the |
1239 | | /// corresponding parameter's default argument, when the call did not |
1240 | | /// explicitly supply arguments for all of the parameters. |
1241 | | class CXXDefaultArgExpr final : public Expr { |
1242 | | friend class ASTStmtReader; |
1243 | | |
1244 | | /// The parameter whose default is being used. |
1245 | | ParmVarDecl *Param; |
1246 | | |
1247 | | /// The context where the default argument expression was used. |
1248 | | DeclContext *UsedContext; |
1249 | | |
1250 | | CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param, |
1251 | | DeclContext *UsedContext) |
1252 | | : Expr(SC, |
1253 | | Param->hasUnparsedDefaultArg() |
1254 | | ? Param->getType().getNonReferenceType() |
1255 | | : Param->getDefaultArg()->getType(), |
1256 | | Param->getDefaultArg()->getValueKind(), |
1257 | | Param->getDefaultArg()->getObjectKind()), |
1258 | 32.2k | Param(Param), UsedContext(UsedContext) { |
1259 | 32.2k | CXXDefaultArgExprBits.Loc = Loc; |
1260 | 32.2k | setDependence(computeDependence(this)); |
1261 | 32.2k | } |
1262 | | |
1263 | | public: |
1264 | 1.64k | CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} |
1265 | | |
1266 | | // \p Param is the parameter whose default argument is used by this |
1267 | | // expression. |
1268 | | static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc, |
1269 | | ParmVarDecl *Param, |
1270 | 32.2k | DeclContext *UsedContext) { |
1271 | 32.2k | return new (C) |
1272 | 32.2k | CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, UsedContext); |
1273 | 32.2k | } |
1274 | | |
1275 | | // Retrieve the parameter that the argument was created from. |
1276 | 12.9k | const ParmVarDecl *getParam() const { return Param; } |
1277 | 44.4k | ParmVarDecl *getParam() { return Param; } |
1278 | | |
1279 | | // Retrieve the actual argument to the function call. |
1280 | 11.3k | const Expr *getExpr() const { return getParam()->getDefaultArg(); } |
1281 | 40.9k | Expr *getExpr() { return getParam()->getDefaultArg(); } |
1282 | | |
1283 | 132 | const DeclContext *getUsedContext() const { return UsedContext; } |
1284 | 3.53k | DeclContext *getUsedContext() { return UsedContext; } |
1285 | | |
1286 | | /// Retrieve the location where this default argument was actually used. |
1287 | 69.5k | SourceLocation getUsedLocation() const { return CXXDefaultArgExprBits.Loc; } |
1288 | | |
1289 | | /// Default argument expressions have no representation in the |
1290 | | /// source, so they have an empty source range. |
1291 | 13.6k | SourceLocation getBeginLoc() const { return SourceLocation(); } |
1292 | 6.04k | SourceLocation getEndLoc() const { return SourceLocation(); } |
1293 | | |
1294 | 65.9k | SourceLocation getExprLoc() const { return getUsedLocation(); } |
1295 | | |
1296 | 3.93M | static bool classof(const Stmt *T) { |
1297 | 3.93M | return T->getStmtClass() == CXXDefaultArgExprClass; |
1298 | 3.93M | } |
1299 | | |
1300 | | // Iterators |
1301 | 71.8k | child_range children() { |
1302 | 71.8k | return child_range(child_iterator(), child_iterator()); |
1303 | 71.8k | } |
1304 | | |
1305 | 0 | const_child_range children() const { |
1306 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1307 | 0 | } |
1308 | | }; |
1309 | | |
1310 | | /// A use of a default initializer in a constructor or in aggregate |
1311 | | /// initialization. |
1312 | | /// |
1313 | | /// This wraps a use of a C++ default initializer (technically, |
1314 | | /// a brace-or-equal-initializer for a non-static data member) when it |
1315 | | /// is implicitly used in a mem-initializer-list in a constructor |
1316 | | /// (C++11 [class.base.init]p8) or in aggregate initialization |
1317 | | /// (C++1y [dcl.init.aggr]p7). |
1318 | | class CXXDefaultInitExpr : public Expr { |
1319 | | friend class ASTReader; |
1320 | | friend class ASTStmtReader; |
1321 | | |
1322 | | /// The field whose default is being used. |
1323 | | FieldDecl *Field; |
1324 | | |
1325 | | /// The context where the default initializer expression was used. |
1326 | | DeclContext *UsedContext; |
1327 | | |
1328 | | CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc, |
1329 | | FieldDecl *Field, QualType Ty, DeclContext *UsedContext); |
1330 | | |
1331 | 185 | CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {} |
1332 | | |
1333 | | public: |
1334 | | /// \p Field is the non-static data member whose default initializer is used |
1335 | | /// by this expression. |
1336 | | static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc, |
1337 | 3.37k | FieldDecl *Field, DeclContext *UsedContext) { |
1338 | 3.37k | return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType(), UsedContext); |
1339 | 3.37k | } |
1340 | | |
1341 | | /// Get the field whose initializer will be used. |
1342 | 3.19k | FieldDecl *getField() { return Field; } |
1343 | 2.73k | const FieldDecl *getField() const { return Field; } |
1344 | | |
1345 | | /// Get the initialization expression that will be used. |
1346 | 5.62k | const Expr *getExpr() const { |
1347 | 5.62k | assert(Field->getInClassInitializer() && "initializer hasn't been parsed"); |
1348 | 0 | return Field->getInClassInitializer(); |
1349 | 5.62k | } |
1350 | 9.03k | Expr *getExpr() { |
1351 | 9.03k | assert(Field->getInClassInitializer() && "initializer hasn't been parsed"); |
1352 | 0 | return Field->getInClassInitializer(); |
1353 | 9.03k | } |
1354 | | |
1355 | 107 | const DeclContext *getUsedContext() const { return UsedContext; } |
1356 | 326 | DeclContext *getUsedContext() { return UsedContext; } |
1357 | | |
1358 | | /// Retrieve the location where this default initializer expression was |
1359 | | /// actually used. |
1360 | 107 | SourceLocation getUsedLocation() const { return getBeginLoc(); } |
1361 | | |
1362 | 7.04k | SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; } |
1363 | 3.14k | SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; } |
1364 | | |
1365 | 10.8M | static bool classof(const Stmt *T) { |
1366 | 10.8M | return T->getStmtClass() == CXXDefaultInitExprClass; |
1367 | 10.8M | } |
1368 | | |
1369 | | // Iterators |
1370 | 1.74k | child_range children() { |
1371 | 1.74k | return child_range(child_iterator(), child_iterator()); |
1372 | 1.74k | } |
1373 | | |
1374 | 0 | const_child_range children() const { |
1375 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1376 | 0 | } |
1377 | | }; |
1378 | | |
1379 | | /// Represents a C++ temporary. |
1380 | | class CXXTemporary { |
1381 | | /// The destructor that needs to be called. |
1382 | | const CXXDestructorDecl *Destructor; |
1383 | | |
1384 | | explicit CXXTemporary(const CXXDestructorDecl *destructor) |
1385 | 51.5k | : Destructor(destructor) {} |
1386 | | |
1387 | | public: |
1388 | | static CXXTemporary *Create(const ASTContext &C, |
1389 | | const CXXDestructorDecl *Destructor); |
1390 | | |
1391 | 21.7k | const CXXDestructorDecl *getDestructor() const { return Destructor; } |
1392 | | |
1393 | 1.20k | void setDestructor(const CXXDestructorDecl *Dtor) { |
1394 | 1.20k | Destructor = Dtor; |
1395 | 1.20k | } |
1396 | | }; |
1397 | | |
1398 | | /// Represents binding an expression to a temporary. |
1399 | | /// |
1400 | | /// This ensures the destructor is called for the temporary. It should only be |
1401 | | /// needed for non-POD, non-trivially destructable class types. For example: |
1402 | | /// |
1403 | | /// \code |
1404 | | /// struct S { |
1405 | | /// S() { } // User defined constructor makes S non-POD. |
1406 | | /// ~S() { } // User defined destructor makes it non-trivial. |
1407 | | /// }; |
1408 | | /// void test() { |
1409 | | /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. |
1410 | | /// } |
1411 | | /// \endcode |
1412 | | class CXXBindTemporaryExpr : public Expr { |
1413 | | CXXTemporary *Temp = nullptr; |
1414 | | Stmt *SubExpr = nullptr; |
1415 | | |
1416 | | CXXBindTemporaryExpr(CXXTemporary *temp, Expr *SubExpr) |
1417 | | : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), VK_PRValue, |
1418 | | OK_Ordinary), |
1419 | 48.4k | Temp(temp), SubExpr(SubExpr) { |
1420 | 48.4k | setDependence(computeDependence(this)); |
1421 | 48.4k | } |
1422 | | |
1423 | | public: |
1424 | | CXXBindTemporaryExpr(EmptyShell Empty) |
1425 | 3.11k | : Expr(CXXBindTemporaryExprClass, Empty) {} |
1426 | | |
1427 | | static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp, |
1428 | | Expr* SubExpr); |
1429 | | |
1430 | 19.7k | CXXTemporary *getTemporary() { return Temp; } |
1431 | 4.02k | const CXXTemporary *getTemporary() const { return Temp; } |
1432 | 3.11k | void setTemporary(CXXTemporary *T) { Temp = T; } |
1433 | | |
1434 | 68.0k | const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } |
1435 | 145k | Expr *getSubExpr() { return cast<Expr>(SubExpr); } |
1436 | 3.11k | void setSubExpr(Expr *E) { SubExpr = E; } |
1437 | | |
1438 | 301k | SourceLocation getBeginLoc() const LLVM_READONLY { |
1439 | 301k | return SubExpr->getBeginLoc(); |
1440 | 301k | } |
1441 | | |
1442 | 31.8k | SourceLocation getEndLoc() const LLVM_READONLY { |
1443 | 31.8k | return SubExpr->getEndLoc(); |
1444 | 31.8k | } |
1445 | | |
1446 | | // Implement isa/cast/dyncast/etc. |
1447 | 19.0M | static bool classof(const Stmt *T) { |
1448 | 19.0M | return T->getStmtClass() == CXXBindTemporaryExprClass; |
1449 | 19.0M | } |
1450 | | |
1451 | | // Iterators |
1452 | 68.6k | child_range children() { return child_range(&SubExpr, &SubExpr + 1); } |
1453 | | |
1454 | 0 | const_child_range children() const { |
1455 | 0 | return const_child_range(&SubExpr, &SubExpr + 1); |
1456 | 0 | } |
1457 | | }; |
1458 | | |
1459 | | /// Represents a call to a C++ constructor. |
1460 | | class CXXConstructExpr : public Expr { |
1461 | | friend class ASTStmtReader; |
1462 | | |
1463 | | public: |
1464 | | enum ConstructionKind { |
1465 | | CK_Complete, |
1466 | | CK_NonVirtualBase, |
1467 | | CK_VirtualBase, |
1468 | | CK_Delegating |
1469 | | }; |
1470 | | |
1471 | | private: |
1472 | | /// A pointer to the constructor which will be ultimately called. |
1473 | | CXXConstructorDecl *Constructor; |
1474 | | |
1475 | | SourceRange ParenOrBraceRange; |
1476 | | |
1477 | | /// The number of arguments. |
1478 | | unsigned NumArgs; |
1479 | | |
1480 | | // We would like to stash the arguments of the constructor call after |
1481 | | // CXXConstructExpr. However CXXConstructExpr is used as a base class of |
1482 | | // CXXTemporaryObjectExpr which makes the use of llvm::TrailingObjects |
1483 | | // impossible. |
1484 | | // |
1485 | | // Instead we manually stash the trailing object after the full object |
1486 | | // containing CXXConstructExpr (that is either CXXConstructExpr or |
1487 | | // CXXTemporaryObjectExpr). |
1488 | | // |
1489 | | // The trailing objects are: |
1490 | | // |
1491 | | // * An array of getNumArgs() "Stmt *" for the arguments of the |
1492 | | // constructor call. |
1493 | | |
1494 | | /// Return a pointer to the start of the trailing arguments. |
1495 | | /// Defined just after CXXTemporaryObjectExpr. |
1496 | | inline Stmt **getTrailingArgs(); |
1497 | 536k | const Stmt *const *getTrailingArgs() const { |
1498 | 536k | return const_cast<CXXConstructExpr *>(this)->getTrailingArgs(); |
1499 | 536k | } |
1500 | | |
1501 | | protected: |
1502 | | /// Build a C++ construction expression. |
1503 | | CXXConstructExpr(StmtClass SC, QualType Ty, SourceLocation Loc, |
1504 | | CXXConstructorDecl *Ctor, bool Elidable, |
1505 | | ArrayRef<Expr *> Args, bool HadMultipleCandidates, |
1506 | | bool ListInitialization, bool StdInitListInitialization, |
1507 | | bool ZeroInitialization, ConstructionKind ConstructKind, |
1508 | | SourceRange ParenOrBraceRange); |
1509 | | |
1510 | | /// Build an empty C++ construction expression. |
1511 | | CXXConstructExpr(StmtClass SC, EmptyShell Empty, unsigned NumArgs); |
1512 | | |
1513 | | /// Return the size in bytes of the trailing objects. Used by |
1514 | | /// CXXTemporaryObjectExpr to allocate the right amount of storage. |
1515 | 457k | static unsigned sizeOfTrailingObjects(unsigned NumArgs) { |
1516 | 457k | return NumArgs * sizeof(Stmt *); |
1517 | 457k | } |
1518 | | |
1519 | | public: |
1520 | | /// Create a C++ construction expression. |
1521 | | static CXXConstructExpr * |
1522 | | Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, |
1523 | | CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args, |
1524 | | bool HadMultipleCandidates, bool ListInitialization, |
1525 | | bool StdInitListInitialization, bool ZeroInitialization, |
1526 | | ConstructionKind ConstructKind, SourceRange ParenOrBraceRange); |
1527 | | |
1528 | | /// Create an empty C++ construction expression. |
1529 | | static CXXConstructExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs); |
1530 | | |
1531 | | /// Get the constructor that this expression will (ultimately) call. |
1532 | 2.26M | CXXConstructorDecl *getConstructor() const { return Constructor; } |
1533 | | |
1534 | 1.51M | SourceLocation getLocation() const { return CXXConstructExprBits.Loc; } |
1535 | 0 | void setLocation(SourceLocation Loc) { CXXConstructExprBits.Loc = Loc; } |
1536 | | |
1537 | | /// Whether this construction is elidable. |
1538 | 203k | bool isElidable() const { return CXXConstructExprBits.Elidable; } |
1539 | 0 | void setElidable(bool E) { CXXConstructExprBits.Elidable = E; } |
1540 | | |
1541 | | /// Whether the referred constructor was resolved from |
1542 | | /// an overloaded set having size greater than 1. |
1543 | 49.8k | bool hadMultipleCandidates() const { |
1544 | 49.8k | return CXXConstructExprBits.HadMultipleCandidates; |
1545 | 49.8k | } |
1546 | 0 | void setHadMultipleCandidates(bool V) { |
1547 | 0 | CXXConstructExprBits.HadMultipleCandidates = V; |
1548 | 0 | } |
1549 | | |
1550 | | /// Whether this constructor call was written as list-initialization. |
1551 | 350k | bool isListInitialization() const { |
1552 | 350k | return CXXConstructExprBits.ListInitialization; |
1553 | 350k | } |
1554 | 0 | void setListInitialization(bool V) { |
1555 | 0 | CXXConstructExprBits.ListInitialization = V; |
1556 | 0 | } |
1557 | | |
1558 | | /// Whether this constructor call was written as list-initialization, |
1559 | | /// but was interpreted as forming a std::initializer_list<T> from the list |
1560 | | /// and passing that as a single constructor argument. |
1561 | | /// See C++11 [over.match.list]p1 bullet 1. |
1562 | 53.6k | bool isStdInitListInitialization() const { |
1563 | 53.6k | return CXXConstructExprBits.StdInitListInitialization; |
1564 | 53.6k | } |
1565 | 0 | void setStdInitListInitialization(bool V) { |
1566 | 0 | CXXConstructExprBits.StdInitListInitialization = V; |
1567 | 0 | } |
1568 | | |
1569 | | /// Whether this construction first requires |
1570 | | /// zero-initialization before the initializer is called. |
1571 | 222k | bool requiresZeroInitialization() const { |
1572 | 222k | return CXXConstructExprBits.ZeroInitialization; |
1573 | 222k | } |
1574 | 0 | void setRequiresZeroInitialization(bool ZeroInit) { |
1575 | 0 | CXXConstructExprBits.ZeroInitialization = ZeroInit; |
1576 | 0 | } |
1577 | | |
1578 | | /// Determine whether this constructor is actually constructing |
1579 | | /// a base class (rather than a complete object). |
1580 | 163k | ConstructionKind getConstructionKind() const { |
1581 | 163k | return static_cast<ConstructionKind>(CXXConstructExprBits.ConstructionKind); |
1582 | 163k | } |
1583 | 0 | void setConstructionKind(ConstructionKind CK) { |
1584 | 0 | CXXConstructExprBits.ConstructionKind = CK; |
1585 | 0 | } |
1586 | | |
1587 | | using arg_iterator = ExprIterator; |
1588 | | using const_arg_iterator = ConstExprIterator; |
1589 | | using arg_range = llvm::iterator_range<arg_iterator>; |
1590 | | using const_arg_range = llvm::iterator_range<const_arg_iterator>; |
1591 | | |
1592 | 449k | arg_range arguments() { return arg_range(arg_begin(), arg_end()); } |
1593 | 38.9k | const_arg_range arguments() const { |
1594 | 38.9k | return const_arg_range(arg_begin(), arg_end()); |
1595 | 38.9k | } |
1596 | | |
1597 | 901k | arg_iterator arg_begin() { return getTrailingArgs(); } |
1598 | 450k | arg_iterator arg_end() { return arg_begin() + getNumArgs(); } |
1599 | 84.7k | const_arg_iterator arg_begin() const { return getTrailingArgs(); } |
1600 | 42.3k | const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } |
1601 | | |
1602 | 483k | Expr **getArgs() { return reinterpret_cast<Expr **>(getTrailingArgs()); } |
1603 | 451k | const Expr *const *getArgs() const { |
1604 | 451k | return reinterpret_cast<const Expr *const *>(getTrailingArgs()); |
1605 | 451k | } |
1606 | | |
1607 | | /// Return the number of arguments to the constructor call. |
1608 | 3.30M | unsigned getNumArgs() const { return NumArgs; } |
1609 | | |
1610 | | /// Return the specified argument. |
1611 | 193k | Expr *getArg(unsigned Arg) { |
1612 | 193k | assert(Arg < getNumArgs() && "Arg access out of range!"); |
1613 | 0 | return getArgs()[Arg]; |
1614 | 193k | } |
1615 | 427k | const Expr *getArg(unsigned Arg) const { |
1616 | 427k | assert(Arg < getNumArgs() && "Arg access out of range!"); |
1617 | 0 | return getArgs()[Arg]; |
1618 | 427k | } |
1619 | | |
1620 | | /// Set the specified argument. |
1621 | 22.4k | void setArg(unsigned Arg, Expr *ArgExpr) { |
1622 | 22.4k | assert(Arg < getNumArgs() && "Arg access out of range!"); |
1623 | 0 | getArgs()[Arg] = ArgExpr; |
1624 | 22.4k | } |
1625 | | |
1626 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
1627 | | SourceLocation getEndLoc() const LLVM_READONLY; |
1628 | 104k | SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; } |
1629 | 25.8k | void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; } |
1630 | | |
1631 | 12.2M | static bool classof(const Stmt *T) { |
1632 | 12.2M | return T->getStmtClass() == CXXConstructExprClass || |
1633 | 12.2M | T->getStmtClass() == CXXTemporaryObjectExprClass9.07M ; |
1634 | 12.2M | } |
1635 | | |
1636 | | // Iterators |
1637 | 774k | child_range children() { |
1638 | 774k | return child_range(getTrailingArgs(), getTrailingArgs() + getNumArgs()); |
1639 | 774k | } |
1640 | | |
1641 | 0 | const_child_range children() const { |
1642 | 0 | auto Children = const_cast<CXXConstructExpr *>(this)->children(); |
1643 | 0 | return const_child_range(Children.begin(), Children.end()); |
1644 | 0 | } |
1645 | | }; |
1646 | | |
1647 | | /// Represents a call to an inherited base class constructor from an |
1648 | | /// inheriting constructor. This call implicitly forwards the arguments from |
1649 | | /// the enclosing context (an inheriting constructor) to the specified inherited |
1650 | | /// base class constructor. |
1651 | | class CXXInheritedCtorInitExpr : public Expr { |
1652 | | private: |
1653 | | CXXConstructorDecl *Constructor = nullptr; |
1654 | | |
1655 | | /// The location of the using declaration. |
1656 | | SourceLocation Loc; |
1657 | | |
1658 | | /// Whether this is the construction of a virtual base. |
1659 | | unsigned ConstructsVirtualBase : 1; |
1660 | | |
1661 | | /// Whether the constructor is inherited from a virtual base class of the |
1662 | | /// class that we construct. |
1663 | | unsigned InheritedFromVirtualBase : 1; |
1664 | | |
1665 | | public: |
1666 | | friend class ASTStmtReader; |
1667 | | |
1668 | | /// Construct a C++ inheriting construction expression. |
1669 | | CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T, |
1670 | | CXXConstructorDecl *Ctor, bool ConstructsVirtualBase, |
1671 | | bool InheritedFromVirtualBase) |
1672 | | : Expr(CXXInheritedCtorInitExprClass, T, VK_PRValue, OK_Ordinary), |
1673 | | Constructor(Ctor), Loc(Loc), |
1674 | | ConstructsVirtualBase(ConstructsVirtualBase), |
1675 | 346 | InheritedFromVirtualBase(InheritedFromVirtualBase) { |
1676 | 346 | assert(!T->isDependentType()); |
1677 | 0 | setDependence(ExprDependence::None); |
1678 | 346 | } |
1679 | | |
1680 | | /// Construct an empty C++ inheriting construction expression. |
1681 | | explicit CXXInheritedCtorInitExpr(EmptyShell Empty) |
1682 | | : Expr(CXXInheritedCtorInitExprClass, Empty), |
1683 | 0 | ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {} |
1684 | | |
1685 | | /// Get the constructor that this expression will call. |
1686 | 323 | CXXConstructorDecl *getConstructor() const { return Constructor; } |
1687 | | |
1688 | | /// Determine whether this constructor is actually constructing |
1689 | | /// a base class (rather than a complete object). |
1690 | 213 | bool constructsVBase() const { return ConstructsVirtualBase; } |
1691 | 5 | CXXConstructExpr::ConstructionKind getConstructionKind() const { |
1692 | 5 | return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase0 |
1693 | 5 | : CXXConstructExpr::CK_NonVirtualBase; |
1694 | 5 | } |
1695 | | |
1696 | | /// Determine whether the inherited constructor is inherited from a |
1697 | | /// virtual base of the object we construct. If so, we are not responsible |
1698 | | /// for calling the inherited constructor (the complete object constructor |
1699 | | /// does that), and so we don't need to pass any arguments. |
1700 | 213 | bool inheritedFromVBase() const { return InheritedFromVirtualBase; } |
1701 | | |
1702 | 504 | SourceLocation getLocation() const LLVM_READONLY { return Loc; } |
1703 | 349 | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
1704 | 69 | SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } |
1705 | | |
1706 | 675k | static bool classof(const Stmt *T) { |
1707 | 675k | return T->getStmtClass() == CXXInheritedCtorInitExprClass; |
1708 | 675k | } |
1709 | | |
1710 | 472 | child_range children() { |
1711 | 472 | return child_range(child_iterator(), child_iterator()); |
1712 | 472 | } |
1713 | | |
1714 | 0 | const_child_range children() const { |
1715 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1716 | 0 | } |
1717 | | }; |
1718 | | |
1719 | | /// Represents an explicit C++ type conversion that uses "functional" |
1720 | | /// notation (C++ [expr.type.conv]). |
1721 | | /// |
1722 | | /// Example: |
1723 | | /// \code |
1724 | | /// x = int(0.5); |
1725 | | /// \endcode |
1726 | | class CXXFunctionalCastExpr final |
1727 | | : public ExplicitCastExpr, |
1728 | | private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *, |
1729 | | FPOptionsOverride> { |
1730 | | SourceLocation LParenLoc; |
1731 | | SourceLocation RParenLoc; |
1732 | | |
1733 | | CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, |
1734 | | TypeSourceInfo *writtenTy, CastKind kind, |
1735 | | Expr *castExpr, unsigned pathSize, |
1736 | | FPOptionsOverride FPO, SourceLocation lParenLoc, |
1737 | | SourceLocation rParenLoc) |
1738 | | : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, castExpr, |
1739 | | pathSize, FPO.requiresTrailingStorage(), writtenTy), |
1740 | 83.1k | LParenLoc(lParenLoc), RParenLoc(rParenLoc) { |
1741 | 83.1k | if (hasStoredFPFeatures()) |
1742 | 2 | *getTrailingFPFeatures() = FPO; |
1743 | 83.1k | } |
1744 | | |
1745 | | explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize, |
1746 | | bool HasFPFeatures) |
1747 | | : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize, |
1748 | 10.1k | HasFPFeatures) {} |
1749 | | |
1750 | 6 | unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const { |
1751 | 6 | return path_size(); |
1752 | 6 | } |
1753 | | |
1754 | | public: |
1755 | | friend class CastExpr; |
1756 | | friend TrailingObjects; |
1757 | | |
1758 | | static CXXFunctionalCastExpr * |
1759 | | Create(const ASTContext &Context, QualType T, ExprValueKind VK, |
1760 | | TypeSourceInfo *Written, CastKind Kind, Expr *Op, |
1761 | | const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, |
1762 | | SourceLocation RPLoc); |
1763 | | static CXXFunctionalCastExpr * |
1764 | | CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures); |
1765 | | |
1766 | 21.4k | SourceLocation getLParenLoc() const { return LParenLoc; } |
1767 | 10.1k | void setLParenLoc(SourceLocation L) { LParenLoc = L; } |
1768 | 21.4k | SourceLocation getRParenLoc() const { return RParenLoc; } |
1769 | 10.1k | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
1770 | | |
1771 | | /// Determine whether this expression models list-initialization. |
1772 | 9.96k | bool isListInitialization() const { return LParenLoc.isInvalid(); } |
1773 | | |
1774 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
1775 | | SourceLocation getEndLoc() const LLVM_READONLY; |
1776 | | |
1777 | 89.6k | static bool classof(const Stmt *T) { |
1778 | 89.6k | return T->getStmtClass() == CXXFunctionalCastExprClass; |
1779 | 89.6k | } |
1780 | | }; |
1781 | | |
1782 | | /// Represents a C++ functional cast expression that builds a |
1783 | | /// temporary object. |
1784 | | /// |
1785 | | /// This expression type represents a C++ "functional" cast |
1786 | | /// (C++[expr.type.conv]) with N != 1 arguments that invokes a |
1787 | | /// constructor to build a temporary object. With N == 1 arguments the |
1788 | | /// functional cast expression will be represented by CXXFunctionalCastExpr. |
1789 | | /// Example: |
1790 | | /// \code |
1791 | | /// struct X { X(int, float); } |
1792 | | /// |
1793 | | /// X create_X() { |
1794 | | /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr |
1795 | | /// }; |
1796 | | /// \endcode |
1797 | | class CXXTemporaryObjectExpr final : public CXXConstructExpr { |
1798 | | friend class ASTStmtReader; |
1799 | | |
1800 | | // CXXTemporaryObjectExpr has some trailing objects belonging |
1801 | | // to CXXConstructExpr. See the comment inside CXXConstructExpr |
1802 | | // for more details. |
1803 | | |
1804 | | TypeSourceInfo *TSI; |
1805 | | |
1806 | | CXXTemporaryObjectExpr(CXXConstructorDecl *Cons, QualType Ty, |
1807 | | TypeSourceInfo *TSI, ArrayRef<Expr *> Args, |
1808 | | SourceRange ParenOrBraceRange, |
1809 | | bool HadMultipleCandidates, bool ListInitialization, |
1810 | | bool StdInitListInitialization, |
1811 | | bool ZeroInitialization); |
1812 | | |
1813 | | CXXTemporaryObjectExpr(EmptyShell Empty, unsigned NumArgs); |
1814 | | |
1815 | | public: |
1816 | | static CXXTemporaryObjectExpr * |
1817 | | Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, |
1818 | | TypeSourceInfo *TSI, ArrayRef<Expr *> Args, |
1819 | | SourceRange ParenOrBraceRange, bool HadMultipleCandidates, |
1820 | | bool ListInitialization, bool StdInitListInitialization, |
1821 | | bool ZeroInitialization); |
1822 | | |
1823 | | static CXXTemporaryObjectExpr *CreateEmpty(const ASTContext &Ctx, |
1824 | | unsigned NumArgs); |
1825 | | |
1826 | 957k | TypeSourceInfo *getTypeSourceInfo() const { return TSI; } |
1827 | | |
1828 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
1829 | | SourceLocation getEndLoc() const LLVM_READONLY; |
1830 | | |
1831 | 5.54M | static bool classof(const Stmt *T) { |
1832 | 5.54M | return T->getStmtClass() == CXXTemporaryObjectExprClass; |
1833 | 5.54M | } |
1834 | | }; |
1835 | | |
1836 | 3.89M | Stmt **CXXConstructExpr::getTrailingArgs() { |
1837 | 3.89M | if (auto *E = dyn_cast<CXXTemporaryObjectExpr>(this)) |
1838 | 563k | return reinterpret_cast<Stmt **>(E + 1); |
1839 | 3.32M | assert((getStmtClass() == CXXConstructExprClass) && |
1840 | 3.32M | "Unexpected class deriving from CXXConstructExpr!"); |
1841 | 0 | return reinterpret_cast<Stmt **>(this + 1); |
1842 | 3.89M | } |
1843 | | |
1844 | | /// A C++ lambda expression, which produces a function object |
1845 | | /// (of unspecified type) that can be invoked later. |
1846 | | /// |
1847 | | /// Example: |
1848 | | /// \code |
1849 | | /// void low_pass_filter(std::vector<double> &values, double cutoff) { |
1850 | | /// values.erase(std::remove_if(values.begin(), values.end(), |
1851 | | /// [=](double value) { return value > cutoff; }); |
1852 | | /// } |
1853 | | /// \endcode |
1854 | | /// |
1855 | | /// C++11 lambda expressions can capture local variables, either by copying |
1856 | | /// the values of those local variables at the time the function |
1857 | | /// object is constructed (not when it is called!) or by holding a |
1858 | | /// reference to the local variable. These captures can occur either |
1859 | | /// implicitly or can be written explicitly between the square |
1860 | | /// brackets ([...]) that start the lambda expression. |
1861 | | /// |
1862 | | /// C++1y introduces a new form of "capture" called an init-capture that |
1863 | | /// includes an initializing expression (rather than capturing a variable), |
1864 | | /// and which can never occur implicitly. |
1865 | | class LambdaExpr final : public Expr, |
1866 | | private llvm::TrailingObjects<LambdaExpr, Stmt *> { |
1867 | | // LambdaExpr has some data stored in LambdaExprBits. |
1868 | | |
1869 | | /// The source range that covers the lambda introducer ([...]). |
1870 | | SourceRange IntroducerRange; |
1871 | | |
1872 | | /// The source location of this lambda's capture-default ('=' or '&'). |
1873 | | SourceLocation CaptureDefaultLoc; |
1874 | | |
1875 | | /// The location of the closing brace ('}') that completes |
1876 | | /// the lambda. |
1877 | | /// |
1878 | | /// The location of the brace is also available by looking up the |
1879 | | /// function call operator in the lambda class. However, it is |
1880 | | /// stored here to improve the performance of getSourceRange(), and |
1881 | | /// to avoid having to deserialize the function call operator from a |
1882 | | /// module file just to determine the source range. |
1883 | | SourceLocation ClosingBrace; |
1884 | | |
1885 | | /// Construct a lambda expression. |
1886 | | LambdaExpr(QualType T, SourceRange IntroducerRange, |
1887 | | LambdaCaptureDefault CaptureDefault, |
1888 | | SourceLocation CaptureDefaultLoc, bool ExplicitParams, |
1889 | | bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, |
1890 | | SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack); |
1891 | | |
1892 | | /// Construct an empty lambda expression. |
1893 | | LambdaExpr(EmptyShell Empty, unsigned NumCaptures); |
1894 | | |
1895 | 60.7k | Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); } |
1896 | 41.3k | Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); } |
1897 | | |
1898 | | void initBodyIfNeeded() const; |
1899 | | |
1900 | | public: |
1901 | | friend class ASTStmtReader; |
1902 | | friend class ASTStmtWriter; |
1903 | | friend TrailingObjects; |
1904 | | |
1905 | | /// Construct a new lambda expression. |
1906 | | static LambdaExpr * |
1907 | | Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, |
1908 | | LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, |
1909 | | bool ExplicitParams, bool ExplicitResultType, |
1910 | | ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace, |
1911 | | bool ContainsUnexpandedParameterPack); |
1912 | | |
1913 | | /// Construct a new lambda expression that will be deserialized from |
1914 | | /// an external source. |
1915 | | static LambdaExpr *CreateDeserialized(const ASTContext &C, |
1916 | | unsigned NumCaptures); |
1917 | | |
1918 | | /// Determine the default capture kind for this lambda. |
1919 | 16.4k | LambdaCaptureDefault getCaptureDefault() const { |
1920 | 16.4k | return static_cast<LambdaCaptureDefault>(LambdaExprBits.CaptureDefault); |
1921 | 16.4k | } |
1922 | | |
1923 | | /// Retrieve the location of this lambda's capture-default, if any. |
1924 | 2.65k | SourceLocation getCaptureDefaultLoc() const { return CaptureDefaultLoc; } |
1925 | | |
1926 | | /// Determine whether one of this lambda's captures is an init-capture. |
1927 | | bool isInitCapture(const LambdaCapture *Capture) const; |
1928 | | |
1929 | | /// An iterator that walks over the captures of the lambda, |
1930 | | /// both implicit and explicit. |
1931 | | using capture_iterator = const LambdaCapture *; |
1932 | | |
1933 | | /// An iterator over a range of lambda captures. |
1934 | | using capture_range = llvm::iterator_range<capture_iterator>; |
1935 | | |
1936 | | /// Retrieve this lambda's captures. |
1937 | | capture_range captures() const; |
1938 | | |
1939 | | /// Retrieve an iterator pointing to the first lambda capture. |
1940 | | capture_iterator capture_begin() const; |
1941 | | |
1942 | | /// Retrieve an iterator pointing past the end of the |
1943 | | /// sequence of lambda captures. |
1944 | | capture_iterator capture_end() const; |
1945 | | |
1946 | | /// Determine the number of captures in this lambda. |
1947 | 74.4k | unsigned capture_size() const { return LambdaExprBits.NumCaptures; } |
1948 | | |
1949 | | /// Retrieve this lambda's explicit captures. |
1950 | | capture_range explicit_captures() const; |
1951 | | |
1952 | | /// Retrieve an iterator pointing to the first explicit |
1953 | | /// lambda capture. |
1954 | | capture_iterator explicit_capture_begin() const; |
1955 | | |
1956 | | /// Retrieve an iterator pointing past the end of the sequence of |
1957 | | /// explicit lambda captures. |
1958 | | capture_iterator explicit_capture_end() const; |
1959 | | |
1960 | | /// Retrieve this lambda's implicit captures. |
1961 | | capture_range implicit_captures() const; |
1962 | | |
1963 | | /// Retrieve an iterator pointing to the first implicit |
1964 | | /// lambda capture. |
1965 | | capture_iterator implicit_capture_begin() const; |
1966 | | |
1967 | | /// Retrieve an iterator pointing past the end of the sequence of |
1968 | | /// implicit lambda captures. |
1969 | | capture_iterator implicit_capture_end() const; |
1970 | | |
1971 | | /// Iterator that walks over the capture initialization |
1972 | | /// arguments. |
1973 | | using capture_init_iterator = Expr **; |
1974 | | |
1975 | | /// Const iterator that walks over the capture initialization |
1976 | | /// arguments. |
1977 | | /// FIXME: This interface is prone to being used incorrectly. |
1978 | | using const_capture_init_iterator = Expr *const *; |
1979 | | |
1980 | | /// Retrieve the initialization expressions for this lambda's captures. |
1981 | 5.93k | llvm::iterator_range<capture_init_iterator> capture_inits() { |
1982 | 5.93k | return llvm::make_range(capture_init_begin(), capture_init_end()); |
1983 | 5.93k | } |
1984 | | |
1985 | | /// Retrieve the initialization expressions for this lambda's captures. |
1986 | 1.78k | llvm::iterator_range<const_capture_init_iterator> capture_inits() const { |
1987 | 1.78k | return llvm::make_range(capture_init_begin(), capture_init_end()); |
1988 | 1.78k | } |
1989 | | |
1990 | | /// Retrieve the first initialization argument for this |
1991 | | /// lambda expression (which initializes the first capture field). |
1992 | 30.4k | capture_init_iterator capture_init_begin() { |
1993 | 30.4k | return reinterpret_cast<Expr **>(getStoredStmts()); |
1994 | 30.4k | } |
1995 | | |
1996 | | /// Retrieve the first initialization argument for this |
1997 | | /// lambda expression (which initializes the first capture field). |
1998 | 23.6k | const_capture_init_iterator capture_init_begin() const { |
1999 | 23.6k | return reinterpret_cast<Expr *const *>(getStoredStmts()); |
2000 | 23.6k | } |
2001 | | |
2002 | | /// Retrieve the iterator pointing one past the last |
2003 | | /// initialization argument for this lambda expression. |
2004 | 15.0k | capture_init_iterator capture_init_end() { |
2005 | 15.0k | return capture_init_begin() + capture_size(); |
2006 | 15.0k | } |
2007 | | |
2008 | | /// Retrieve the iterator pointing one past the last |
2009 | | /// initialization argument for this lambda expression. |
2010 | 11.4k | const_capture_init_iterator capture_init_end() const { |
2011 | 11.4k | return capture_init_begin() + capture_size(); |
2012 | 11.4k | } |
2013 | | |
2014 | | /// Retrieve the source range covering the lambda introducer, |
2015 | | /// which contains the explicit capture list surrounded by square |
2016 | | /// brackets ([...]). |
2017 | 7.85k | SourceRange getIntroducerRange() const { return IntroducerRange; } |
2018 | | |
2019 | | /// Retrieve the class that corresponds to the lambda. |
2020 | | /// |
2021 | | /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the |
2022 | | /// captures in its fields and provides the various operations permitted |
2023 | | /// on a lambda (copying, calling). |
2024 | | CXXRecordDecl *getLambdaClass() const; |
2025 | | |
2026 | | /// Retrieve the function call operator associated with this |
2027 | | /// lambda expression. |
2028 | | CXXMethodDecl *getCallOperator() const; |
2029 | | |
2030 | | /// Retrieve the function template call operator associated with this |
2031 | | /// lambda expression. |
2032 | | FunctionTemplateDecl *getDependentCallOperator() const; |
2033 | | |
2034 | | /// If this is a generic lambda expression, retrieve the template |
2035 | | /// parameter list associated with it, or else return null. |
2036 | | TemplateParameterList *getTemplateParameterList() const; |
2037 | | |
2038 | | /// Get the template parameters were explicitly specified (as opposed to being |
2039 | | /// invented by use of an auto parameter). |
2040 | | ArrayRef<NamedDecl *> getExplicitTemplateParameters() const; |
2041 | | |
2042 | | /// Get the trailing requires clause, if any. |
2043 | | Expr *getTrailingRequiresClause() const; |
2044 | | |
2045 | | /// Whether this is a generic lambda. |
2046 | 5 | bool isGenericLambda() const { return getTemplateParameterList(); } |
2047 | | |
2048 | | /// Retrieve the body of the lambda. This will be most of the time |
2049 | | /// a \p CompoundStmt, but can also be \p CoroutineBodyStmt wrapping |
2050 | | /// a \p CompoundStmt. Note that unlike functions, lambda-expressions |
2051 | | /// cannot have a function-try-block. |
2052 | | Stmt *getBody() const; |
2053 | | |
2054 | | /// Retrieve the \p CompoundStmt representing the body of the lambda. |
2055 | | /// This is a convenience function for callers who do not need |
2056 | | /// to handle node(s) which may wrap a \p CompoundStmt. |
2057 | | const CompoundStmt *getCompoundStmtBody() const; |
2058 | 153 | CompoundStmt *getCompoundStmtBody() { |
2059 | 153 | const auto *ConstThis = this; |
2060 | 153 | return const_cast<CompoundStmt *>(ConstThis->getCompoundStmtBody()); |
2061 | 153 | } |
2062 | | |
2063 | | /// Determine whether the lambda is mutable, meaning that any |
2064 | | /// captures values can be modified. |
2065 | | bool isMutable() const; |
2066 | | |
2067 | | /// Determine whether this lambda has an explicit parameter |
2068 | | /// list vs. an implicit (empty) parameter list. |
2069 | 4.22k | bool hasExplicitParameters() const { return LambdaExprBits.ExplicitParams; } |
2070 | | |
2071 | | /// Whether this lambda had its result type explicitly specified. |
2072 | 4.16k | bool hasExplicitResultType() const { |
2073 | 4.16k | return LambdaExprBits.ExplicitResultType; |
2074 | 4.16k | } |
2075 | | |
2076 | 4.04M | static bool classof(const Stmt *T) { |
2077 | 4.04M | return T->getStmtClass() == LambdaExprClass; |
2078 | 4.04M | } |
2079 | | |
2080 | 104k | SourceLocation getBeginLoc() const LLVM_READONLY { |
2081 | 104k | return IntroducerRange.getBegin(); |
2082 | 104k | } |
2083 | | |
2084 | 4.72k | SourceLocation getEndLoc() const LLVM_READONLY { return ClosingBrace; } |
2085 | | |
2086 | | /// Includes the captures and the body of the lambda. |
2087 | | child_range children(); |
2088 | | const_child_range children() const; |
2089 | | }; |
2090 | | |
2091 | | /// An expression "T()" which creates a value-initialized rvalue of type |
2092 | | /// T, which is a non-class type. See (C++98 [5.2.3p2]). |
2093 | | class CXXScalarValueInitExpr : public Expr { |
2094 | | friend class ASTStmtReader; |
2095 | | |
2096 | | TypeSourceInfo *TypeInfo; |
2097 | | |
2098 | | public: |
2099 | | /// Create an explicitly-written scalar-value initialization |
2100 | | /// expression. |
2101 | | CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo, |
2102 | | SourceLocation RParenLoc) |
2103 | | : Expr(CXXScalarValueInitExprClass, Type, VK_PRValue, OK_Ordinary), |
2104 | 23.9k | TypeInfo(TypeInfo) { |
2105 | 23.9k | CXXScalarValueInitExprBits.RParenLoc = RParenLoc; |
2106 | 23.9k | setDependence(computeDependence(this)); |
2107 | 23.9k | } |
2108 | | |
2109 | | explicit CXXScalarValueInitExpr(EmptyShell Shell) |
2110 | 1.20k | : Expr(CXXScalarValueInitExprClass, Shell) {} |
2111 | | |
2112 | 26.9k | TypeSourceInfo *getTypeSourceInfo() const { |
2113 | 26.9k | return TypeInfo; |
2114 | 26.9k | } |
2115 | | |
2116 | 2.23k | SourceLocation getRParenLoc() const { |
2117 | 2.23k | return CXXScalarValueInitExprBits.RParenLoc; |
2118 | 2.23k | } |
2119 | | |
2120 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
2121 | 360 | SourceLocation getEndLoc() const { return getRParenLoc(); } |
2122 | | |
2123 | 82.3k | static bool classof(const Stmt *T) { |
2124 | 82.3k | return T->getStmtClass() == CXXScalarValueInitExprClass; |
2125 | 82.3k | } |
2126 | | |
2127 | | // Iterators |
2128 | 27.8k | child_range children() { |
2129 | 27.8k | return child_range(child_iterator(), child_iterator()); |
2130 | 27.8k | } |
2131 | | |
2132 | 0 | const_child_range children() const { |
2133 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
2134 | 0 | } |
2135 | | }; |
2136 | | |
2137 | | /// Represents a new-expression for memory allocation and constructor |
2138 | | /// calls, e.g: "new CXXNewExpr(foo)". |
2139 | | class CXXNewExpr final |
2140 | | : public Expr, |
2141 | | private llvm::TrailingObjects<CXXNewExpr, Stmt *, SourceRange> { |
2142 | | friend class ASTStmtReader; |
2143 | | friend class ASTStmtWriter; |
2144 | | friend TrailingObjects; |
2145 | | |
2146 | | /// Points to the allocation function used. |
2147 | | FunctionDecl *OperatorNew; |
2148 | | |
2149 | | /// Points to the deallocation function used in case of error. May be null. |
2150 | | FunctionDecl *OperatorDelete; |
2151 | | |
2152 | | /// The allocated type-source information, as written in the source. |
2153 | | TypeSourceInfo *AllocatedTypeInfo; |
2154 | | |
2155 | | /// Range of the entire new expression. |
2156 | | SourceRange Range; |
2157 | | |
2158 | | /// Source-range of a paren-delimited initializer. |
2159 | | SourceRange DirectInitRange; |
2160 | | |
2161 | | // CXXNewExpr is followed by several optional trailing objects. |
2162 | | // They are in order: |
2163 | | // |
2164 | | // * An optional "Stmt *" for the array size expression. |
2165 | | // Present if and ony if isArray(). |
2166 | | // |
2167 | | // * An optional "Stmt *" for the init expression. |
2168 | | // Present if and only if hasInitializer(). |
2169 | | // |
2170 | | // * An array of getNumPlacementArgs() "Stmt *" for the placement new |
2171 | | // arguments, if any. |
2172 | | // |
2173 | | // * An optional SourceRange for the range covering the parenthesized type-id |
2174 | | // if the allocated type was expressed as a parenthesized type-id. |
2175 | | // Present if and only if isParenTypeId(). |
2176 | 199k | unsigned arraySizeOffset() const { return 0; } |
2177 | 193k | unsigned initExprOffset() const { return arraySizeOffset() + isArray(); } |
2178 | 115k | unsigned placementNewArgsOffset() const { |
2179 | 115k | return initExprOffset() + hasInitializer(); |
2180 | 115k | } |
2181 | | |
2182 | 29.6k | unsigned numTrailingObjects(OverloadToken<Stmt *>) const { |
2183 | 29.6k | return isArray() + hasInitializer() + getNumPlacementArgs(); |
2184 | 29.6k | } |
2185 | | |
2186 | 0 | unsigned numTrailingObjects(OverloadToken<SourceRange>) const { |
2187 | 0 | return isParenTypeId(); |
2188 | 0 | } |
2189 | | |
2190 | | public: |
2191 | | enum InitializationStyle { |
2192 | | /// New-expression has no initializer as written. |
2193 | | NoInit, |
2194 | | |
2195 | | /// New-expression has a C++98 paren-delimited initializer. |
2196 | | CallInit, |
2197 | | |
2198 | | /// New-expression has a C++11 list-initializer. |
2199 | | ListInit |
2200 | | }; |
2201 | | |
2202 | | private: |
2203 | | /// Build a c++ new expression. |
2204 | | CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, |
2205 | | FunctionDecl *OperatorDelete, bool ShouldPassAlignment, |
2206 | | bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, |
2207 | | SourceRange TypeIdParens, Optional<Expr *> ArraySize, |
2208 | | InitializationStyle InitializationStyle, Expr *Initializer, |
2209 | | QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, |
2210 | | SourceRange DirectInitRange); |
2211 | | |
2212 | | /// Build an empty c++ new expression. |
2213 | | CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs, |
2214 | | bool IsParenTypeId); |
2215 | | |
2216 | | public: |
2217 | | /// Create a c++ new expression. |
2218 | | static CXXNewExpr * |
2219 | | Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, |
2220 | | FunctionDecl *OperatorDelete, bool ShouldPassAlignment, |
2221 | | bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, |
2222 | | SourceRange TypeIdParens, Optional<Expr *> ArraySize, |
2223 | | InitializationStyle InitializationStyle, Expr *Initializer, |
2224 | | QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, |
2225 | | SourceRange DirectInitRange); |
2226 | | |
2227 | | /// Create an empty c++ new expression. |
2228 | | static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray, |
2229 | | bool HasInit, unsigned NumPlacementArgs, |
2230 | | bool IsParenTypeId); |
2231 | | |
2232 | 45.5k | QualType getAllocatedType() const { |
2233 | 45.5k | return getType()->castAs<PointerType>()->getPointeeType(); |
2234 | 45.5k | } |
2235 | | |
2236 | 48.5k | TypeSourceInfo *getAllocatedTypeSourceInfo() const { |
2237 | 48.5k | return AllocatedTypeInfo; |
2238 | 48.5k | } |
2239 | | |
2240 | | /// True if the allocation result needs to be null-checked. |
2241 | | /// |
2242 | | /// C++11 [expr.new]p13: |
2243 | | /// If the allocation function returns null, initialization shall |
2244 | | /// not be done, the deallocation function shall not be called, |
2245 | | /// and the value of the new-expression shall be null. |
2246 | | /// |
2247 | | /// C++ DR1748: |
2248 | | /// If the allocation function is a reserved placement allocation |
2249 | | /// function that returns null, the behavior is undefined. |
2250 | | /// |
2251 | | /// An allocation function is not allowed to return null unless it |
2252 | | /// has a non-throwing exception-specification. The '03 rule is |
2253 | | /// identical except that the definition of a non-throwing |
2254 | | /// exception specification is just "is it throw()?". |
2255 | | bool shouldNullCheckAllocation() const; |
2256 | | |
2257 | 83.6k | FunctionDecl *getOperatorNew() const { return OperatorNew; } |
2258 | 4.41k | void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } |
2259 | 15.8k | FunctionDecl *getOperatorDelete() const { return OperatorDelete; } |
2260 | 4.41k | void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } |
2261 | | |
2262 | 294k | bool isArray() const { return CXXNewExprBits.IsArray; } |
2263 | | |
2264 | | /// This might return None even if isArray() returns true, |
2265 | | /// since there might not be an array size expression. |
2266 | | /// If the result is not-None, it will never wrap a nullptr. |
2267 | 39.8k | Optional<Expr *> getArraySize() { |
2268 | 39.8k | if (!isArray()) |
2269 | 36.9k | return None; |
2270 | | |
2271 | 2.85k | if (auto *Result = |
2272 | 2.85k | cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()])) |
2273 | 2.82k | return Result; |
2274 | | |
2275 | 35 | return None; |
2276 | 2.85k | } |
2277 | | |
2278 | | /// This might return None even if isArray() returns true, |
2279 | | /// since there might not be an array size expression. |
2280 | | /// If the result is not-None, it will never wrap a nullptr. |
2281 | 3.04k | Optional<const Expr *> getArraySize() const { |
2282 | 3.04k | if (!isArray()) |
2283 | 1.28k | return None; |
2284 | | |
2285 | 1.76k | if (auto *Result = |
2286 | 1.76k | cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()])) |
2287 | 1.76k | return Result; |
2288 | | |
2289 | 1 | return None; |
2290 | 1.76k | } |
2291 | | |
2292 | 120k | unsigned getNumPlacementArgs() const { |
2293 | 120k | return CXXNewExprBits.NumPlacementArgs; |
2294 | 120k | } |
2295 | | |
2296 | 5.03k | Expr **getPlacementArgs() { |
2297 | 5.03k | return reinterpret_cast<Expr **>(getTrailingObjects<Stmt *>() + |
2298 | 5.03k | placementNewArgsOffset()); |
2299 | 5.03k | } |
2300 | | |
2301 | 3.24k | Expr *getPlacementArg(unsigned I) { |
2302 | 3.24k | assert((I < getNumPlacementArgs()) && "Index out of range!"); |
2303 | 0 | return getPlacementArgs()[I]; |
2304 | 3.24k | } |
2305 | 3.21k | const Expr *getPlacementArg(unsigned I) const { |
2306 | 3.21k | return const_cast<CXXNewExpr *>(this)->getPlacementArg(I); |
2307 | 3.21k | } |
2308 | | |
2309 | 16.4k | bool isParenTypeId() const { return CXXNewExprBits.IsParenTypeId; } |
2310 | 6.03k | SourceRange getTypeIdParens() const { |
2311 | 6.03k | return isParenTypeId() ? getTrailingObjects<SourceRange>()[0]10 |
2312 | 6.03k | : SourceRange()6.02k ; |
2313 | 6.03k | } |
2314 | | |
2315 | 10.3k | bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; } |
2316 | | |
2317 | | /// Whether this new-expression has any initializer at all. |
2318 | 203k | bool hasInitializer() const { |
2319 | 203k | return CXXNewExprBits.StoredInitializationStyle > 0; |
2320 | 203k | } |
2321 | | |
2322 | | /// The kind of initializer this new-expression has. |
2323 | 41.3k | InitializationStyle getInitializationStyle() const { |
2324 | 41.3k | if (CXXNewExprBits.StoredInitializationStyle == 0) |
2325 | 2.78k | return NoInit; |
2326 | 38.5k | return static_cast<InitializationStyle>( |
2327 | 38.5k | CXXNewExprBits.StoredInitializationStyle - 1); |
2328 | 41.3k | } |
2329 | | |
2330 | | /// The initializer of this new-expression. |
2331 | 44.7k | Expr *getInitializer() { |
2332 | 44.7k | return hasInitializer() |
2333 | 44.7k | ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])41.0k |
2334 | 44.7k | : nullptr3.68k ; |
2335 | 44.7k | } |
2336 | 6.94k | const Expr *getInitializer() const { |
2337 | 6.94k | return hasInitializer() |
2338 | 6.94k | ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])5.01k |
2339 | 6.94k | : nullptr1.92k ; |
2340 | 6.94k | } |
2341 | | |
2342 | | /// Returns the CXXConstructExpr from this new-expression, or null. |
2343 | 2.54k | const CXXConstructExpr *getConstructExpr() const { |
2344 | 2.54k | return dyn_cast_or_null<CXXConstructExpr>(getInitializer()); |
2345 | 2.54k | } |
2346 | | |
2347 | | /// Indicates whether the required alignment should be implicitly passed to |
2348 | | /// the allocation function. |
2349 | 48.3k | bool passAlignment() const { return CXXNewExprBits.ShouldPassAlignment; } |
2350 | | |
2351 | | /// Answers whether the usual array deallocation function for the |
2352 | | /// allocated type expects the size of the allocation as a |
2353 | | /// parameter. |
2354 | 6.53k | bool doesUsualArrayDeleteWantSize() const { |
2355 | 6.53k | return CXXNewExprBits.UsualArrayDeleteWantsSize; |
2356 | 6.53k | } |
2357 | | |
2358 | | using arg_iterator = ExprIterator; |
2359 | | using const_arg_iterator = ConstExprIterator; |
2360 | | |
2361 | 38.5k | llvm::iterator_range<arg_iterator> placement_arguments() { |
2362 | 38.5k | return llvm::make_range(placement_arg_begin(), placement_arg_end()); |
2363 | 38.5k | } |
2364 | | |
2365 | 1.95k | llvm::iterator_range<const_arg_iterator> placement_arguments() const { |
2366 | 1.95k | return llvm::make_range(placement_arg_begin(), placement_arg_end()); |
2367 | 1.95k | } |
2368 | | |
2369 | 82.1k | arg_iterator placement_arg_begin() { |
2370 | 82.1k | return getTrailingObjects<Stmt *>() + placementNewArgsOffset(); |
2371 | 82.1k | } |
2372 | 41.0k | arg_iterator placement_arg_end() { |
2373 | 41.0k | return placement_arg_begin() + getNumPlacementArgs(); |
2374 | 41.0k | } |
2375 | 3.92k | const_arg_iterator placement_arg_begin() const { |
2376 | 3.92k | return getTrailingObjects<Stmt *>() + placementNewArgsOffset(); |
2377 | 3.92k | } |
2378 | 1.96k | const_arg_iterator placement_arg_end() const { |
2379 | 1.96k | return placement_arg_begin() + getNumPlacementArgs(); |
2380 | 1.96k | } |
2381 | | |
2382 | | using raw_arg_iterator = Stmt **; |
2383 | | |
2384 | 59.1k | raw_arg_iterator raw_arg_begin() { return getTrailingObjects<Stmt *>(); } |
2385 | 29.5k | raw_arg_iterator raw_arg_end() { |
2386 | 29.5k | return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>()); |
2387 | 29.5k | } |
2388 | 0 | const_arg_iterator raw_arg_begin() const { |
2389 | 0 | return getTrailingObjects<Stmt *>(); |
2390 | 0 | } |
2391 | 0 | const_arg_iterator raw_arg_end() const { |
2392 | 0 | return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>()); |
2393 | 0 | } |
2394 | | |
2395 | 92.3k | SourceLocation getBeginLoc() const { return Range.getBegin(); } |
2396 | 1.10k | SourceLocation getEndLoc() const { return Range.getEnd(); } |
2397 | | |
2398 | 7.60k | SourceRange getDirectInitRange() const { return DirectInitRange; } |
2399 | 14.9k | SourceRange getSourceRange() const { return Range; } |
2400 | | |
2401 | 1.96M | static bool classof(const Stmt *T) { |
2402 | 1.96M | return T->getStmtClass() == CXXNewExprClass; |
2403 | 1.96M | } |
2404 | | |
2405 | | // Iterators |
2406 | 23.5k | child_range children() { return child_range(raw_arg_begin(), raw_arg_end()); } |
2407 | | |
2408 | 0 | const_child_range children() const { |
2409 | 0 | return const_child_range(const_cast<CXXNewExpr *>(this)->children()); |
2410 | 0 | } |
2411 | | }; |
2412 | | |
2413 | | /// Represents a \c delete expression for memory deallocation and |
2414 | | /// destructor calls, e.g. "delete[] pArray". |
2415 | | class CXXDeleteExpr : public Expr { |
2416 | | friend class ASTStmtReader; |
2417 | | |
2418 | | /// Points to the operator delete overload that is used. Could be a member. |
2419 | | FunctionDecl *OperatorDelete = nullptr; |
2420 | | |
2421 | | /// The pointer expression to be deleted. |
2422 | | Stmt *Argument = nullptr; |
2423 | | |
2424 | | public: |
2425 | | CXXDeleteExpr(QualType Ty, bool GlobalDelete, bool ArrayForm, |
2426 | | bool ArrayFormAsWritten, bool UsualArrayDeleteWantsSize, |
2427 | | FunctionDecl *OperatorDelete, Expr *Arg, SourceLocation Loc) |
2428 | | : Expr(CXXDeleteExprClass, Ty, VK_PRValue, OK_Ordinary), |
2429 | 7.50k | OperatorDelete(OperatorDelete), Argument(Arg) { |
2430 | 7.50k | CXXDeleteExprBits.GlobalDelete = GlobalDelete; |
2431 | 7.50k | CXXDeleteExprBits.ArrayForm = ArrayForm; |
2432 | 7.50k | CXXDeleteExprBits.ArrayFormAsWritten = ArrayFormAsWritten; |
2433 | 7.50k | CXXDeleteExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize; |
2434 | 7.50k | CXXDeleteExprBits.Loc = Loc; |
2435 | 7.50k | setDependence(computeDependence(this)); |
2436 | 7.50k | } |
2437 | | |
2438 | 810 | explicit CXXDeleteExpr(EmptyShell Shell) : Expr(CXXDeleteExprClass, Shell) {} |
2439 | | |
2440 | 6.70k | bool isGlobalDelete() const { return CXXDeleteExprBits.GlobalDelete; } |
2441 | 16.5k | bool isArrayForm() const { return CXXDeleteExprBits.ArrayForm; } |
2442 | 1.07k | bool isArrayFormAsWritten() const { |
2443 | 1.07k | return CXXDeleteExprBits.ArrayFormAsWritten; |
2444 | 1.07k | } |
2445 | | |
2446 | | /// Answers whether the usual array deallocation function for the |
2447 | | /// allocated type expects the size of the allocation as a |
2448 | | /// parameter. This can be true even if the actual deallocation |
2449 | | /// function that we're using doesn't want a size. |
2450 | 1.28k | bool doesUsualArrayDeleteWantSize() const { |
2451 | 1.28k | return CXXDeleteExprBits.UsualArrayDeleteWantsSize; |
2452 | 1.28k | } |
2453 | | |
2454 | 48.0k | FunctionDecl *getOperatorDelete() const { return OperatorDelete; } |
2455 | | |
2456 | 11.8k | Expr *getArgument() { return cast<Expr>(Argument); } |
2457 | 14.0k | const Expr *getArgument() const { return cast<Expr>(Argument); } |
2458 | | |
2459 | | /// Retrieve the type being destroyed. |
2460 | | /// |
2461 | | /// If the type being destroyed is a dependent type which may or may not |
2462 | | /// be a pointer, return an invalid type. |
2463 | | QualType getDestroyedType() const; |
2464 | | |
2465 | 21.9k | SourceLocation getBeginLoc() const { return CXXDeleteExprBits.Loc; } |
2466 | 2.04k | SourceLocation getEndLoc() const LLVM_READONLY { |
2467 | 2.04k | return Argument->getEndLoc(); |
2468 | 2.04k | } |
2469 | | |
2470 | 80.7k | static bool classof(const Stmt *T) { |
2471 | 80.7k | return T->getStmtClass() == CXXDeleteExprClass; |
2472 | 80.7k | } |
2473 | | |
2474 | | // Iterators |
2475 | 11.4k | child_range children() { return child_range(&Argument, &Argument + 1); } |
2476 | | |
2477 | 0 | const_child_range children() const { |
2478 | 0 | return const_child_range(&Argument, &Argument + 1); |
2479 | 0 | } |
2480 | | }; |
2481 | | |
2482 | | /// Stores the type being destroyed by a pseudo-destructor expression. |
2483 | | class PseudoDestructorTypeStorage { |
2484 | | /// Either the type source information or the name of the type, if |
2485 | | /// it couldn't be resolved due to type-dependence. |
2486 | | llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; |
2487 | | |
2488 | | /// The starting source location of the pseudo-destructor type. |
2489 | | SourceLocation Location; |
2490 | | |
2491 | | public: |
2492 | 9.95k | PseudoDestructorTypeStorage() = default; |
2493 | | |
2494 | | PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) |
2495 | 7 | : Type(II), Location(Loc) {} |
2496 | | |
2497 | | PseudoDestructorTypeStorage(TypeSourceInfo *Info); |
2498 | | |
2499 | 40.2k | TypeSourceInfo *getTypeSourceInfo() const { |
2500 | 40.2k | return Type.dyn_cast<TypeSourceInfo *>(); |
2501 | 40.2k | } |
2502 | | |
2503 | 2.59k | IdentifierInfo *getIdentifier() const { |
2504 | 2.59k | return Type.dyn_cast<IdentifierInfo *>(); |
2505 | 2.59k | } |
2506 | | |
2507 | 1.35k | SourceLocation getLocation() const { return Location; } |
2508 | | }; |
2509 | | |
2510 | | /// Represents a C++ pseudo-destructor (C++ [expr.pseudo]). |
2511 | | /// |
2512 | | /// A pseudo-destructor is an expression that looks like a member access to a |
2513 | | /// destructor of a scalar type, except that scalar types don't have |
2514 | | /// destructors. For example: |
2515 | | /// |
2516 | | /// \code |
2517 | | /// typedef int T; |
2518 | | /// void f(int *p) { |
2519 | | /// p->T::~T(); |
2520 | | /// } |
2521 | | /// \endcode |
2522 | | /// |
2523 | | /// Pseudo-destructors typically occur when instantiating templates such as: |
2524 | | /// |
2525 | | /// \code |
2526 | | /// template<typename T> |
2527 | | /// void destroy(T* ptr) { |
2528 | | /// ptr->T::~T(); |
2529 | | /// } |
2530 | | /// \endcode |
2531 | | /// |
2532 | | /// for scalar types. A pseudo-destructor expression has no run-time semantics |
2533 | | /// beyond evaluating the base expression. |
2534 | | class CXXPseudoDestructorExpr : public Expr { |
2535 | | friend class ASTStmtReader; |
2536 | | |
2537 | | /// The base expression (that is being destroyed). |
2538 | | Stmt *Base = nullptr; |
2539 | | |
2540 | | /// Whether the operator was an arrow ('->'); otherwise, it was a |
2541 | | /// period ('.'). |
2542 | | bool IsArrow : 1; |
2543 | | |
2544 | | /// The location of the '.' or '->' operator. |
2545 | | SourceLocation OperatorLoc; |
2546 | | |
2547 | | /// The nested-name-specifier that follows the operator, if present. |
2548 | | NestedNameSpecifierLoc QualifierLoc; |
2549 | | |
2550 | | /// The type that precedes the '::' in a qualified pseudo-destructor |
2551 | | /// expression. |
2552 | | TypeSourceInfo *ScopeType = nullptr; |
2553 | | |
2554 | | /// The location of the '::' in a qualified pseudo-destructor |
2555 | | /// expression. |
2556 | | SourceLocation ColonColonLoc; |
2557 | | |
2558 | | /// The location of the '~'. |
2559 | | SourceLocation TildeLoc; |
2560 | | |
2561 | | /// The type being destroyed, or its name if we were unable to |
2562 | | /// resolve the name. |
2563 | | PseudoDestructorTypeStorage DestroyedType; |
2564 | | |
2565 | | public: |
2566 | | CXXPseudoDestructorExpr(const ASTContext &Context, |
2567 | | Expr *Base, bool isArrow, SourceLocation OperatorLoc, |
2568 | | NestedNameSpecifierLoc QualifierLoc, |
2569 | | TypeSourceInfo *ScopeType, |
2570 | | SourceLocation ColonColonLoc, |
2571 | | SourceLocation TildeLoc, |
2572 | | PseudoDestructorTypeStorage DestroyedType); |
2573 | | |
2574 | | explicit CXXPseudoDestructorExpr(EmptyShell Shell) |
2575 | 777 | : Expr(CXXPseudoDestructorExprClass, Shell), IsArrow(false) {} |
2576 | | |
2577 | 10.9k | Expr *getBase() const { return cast<Expr>(Base); } |
2578 | | |
2579 | | /// Determines whether this member expression actually had |
2580 | | /// a C++ nested-name-specifier prior to the name of the member, e.g., |
2581 | | /// x->Base::foo. |
2582 | 0 | bool hasQualifier() const { return QualifierLoc.hasQualifier(); } |
2583 | | |
2584 | | /// Retrieves the nested-name-specifier that qualifies the type name, |
2585 | | /// with source-location information. |
2586 | 2.72k | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
2587 | | |
2588 | | /// If the member name was qualified, retrieves the |
2589 | | /// nested-name-specifier that precedes the member name. Otherwise, returns |
2590 | | /// null. |
2591 | 14.5k | NestedNameSpecifier *getQualifier() const { |
2592 | 14.5k | return QualifierLoc.getNestedNameSpecifier(); |
2593 | 14.5k | } |
2594 | | |
2595 | | /// Determine whether this pseudo-destructor expression was written |
2596 | | /// using an '->' (otherwise, it used a '.'). |
2597 | 9.77k | bool isArrow() const { return IsArrow; } |
2598 | | |
2599 | | /// Retrieve the location of the '.' or '->' operator. |
2600 | 3.60k | SourceLocation getOperatorLoc() const { return OperatorLoc; } |
2601 | | |
2602 | | /// Retrieve the scope type in a qualified pseudo-destructor |
2603 | | /// expression. |
2604 | | /// |
2605 | | /// Pseudo-destructor expressions can have extra qualification within them |
2606 | | /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). |
2607 | | /// Here, if the object type of the expression is (or may be) a scalar type, |
2608 | | /// \p T may also be a scalar type and, therefore, cannot be part of a |
2609 | | /// nested-name-specifier. It is stored as the "scope type" of the pseudo- |
2610 | | /// destructor expression. |
2611 | 23.5k | TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } |
2612 | | |
2613 | | /// Retrieve the location of the '::' in a qualified pseudo-destructor |
2614 | | /// expression. |
2615 | 2.30k | SourceLocation getColonColonLoc() const { return ColonColonLoc; } |
2616 | | |
2617 | | /// Retrieve the location of the '~'. |
2618 | 2.30k | SourceLocation getTildeLoc() const { return TildeLoc; } |
2619 | | |
2620 | | /// Retrieve the source location information for the type |
2621 | | /// being destroyed. |
2622 | | /// |
2623 | | /// This type-source information is available for non-dependent |
2624 | | /// pseudo-destructor expressions and some dependent pseudo-destructor |
2625 | | /// expressions. Returns null if we only have the identifier for a |
2626 | | /// dependent pseudo-destructor expression. |
2627 | 24.7k | TypeSourceInfo *getDestroyedTypeInfo() const { |
2628 | 24.7k | return DestroyedType.getTypeSourceInfo(); |
2629 | 24.7k | } |
2630 | | |
2631 | | /// In a dependent pseudo-destructor expression for which we do not |
2632 | | /// have full type information on the destroyed type, provides the name |
2633 | | /// of the destroyed type. |
2634 | 1.37k | IdentifierInfo *getDestroyedTypeIdentifier() const { |
2635 | 1.37k | return DestroyedType.getIdentifier(); |
2636 | 1.37k | } |
2637 | | |
2638 | | /// Retrieve the type being destroyed. |
2639 | | QualType getDestroyedType() const; |
2640 | | |
2641 | | /// Retrieve the starting location of the type being destroyed. |
2642 | 12 | SourceLocation getDestroyedTypeLoc() const { |
2643 | 12 | return DestroyedType.getLocation(); |
2644 | 12 | } |
2645 | | |
2646 | | /// Set the name of destroyed type for a dependent pseudo-destructor |
2647 | | /// expression. |
2648 | 0 | void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { |
2649 | 0 | DestroyedType = PseudoDestructorTypeStorage(II, Loc); |
2650 | 0 | } |
2651 | | |
2652 | | /// Set the destroyed type. |
2653 | 777 | void setDestroyedType(TypeSourceInfo *Info) { |
2654 | 777 | DestroyedType = PseudoDestructorTypeStorage(Info); |
2655 | 777 | } |
2656 | | |
2657 | 15.6k | SourceLocation getBeginLoc() const LLVM_READONLY { |
2658 | 15.6k | return Base->getBeginLoc(); |
2659 | 15.6k | } |
2660 | | SourceLocation getEndLoc() const LLVM_READONLY; |
2661 | | |
2662 | 4.73M | static bool classof(const Stmt *T) { |
2663 | 4.73M | return T->getStmtClass() == CXXPseudoDestructorExprClass; |
2664 | 4.73M | } |
2665 | | |
2666 | | // Iterators |
2667 | 7.67k | child_range children() { return child_range(&Base, &Base + 1); } |
2668 | | |
2669 | 0 | const_child_range children() const { |
2670 | 0 | return const_child_range(&Base, &Base + 1); |
2671 | 0 | } |
2672 | | }; |
2673 | | |
2674 | | /// A type trait used in the implementation of various C++11 and |
2675 | | /// Library TR1 trait templates. |
2676 | | /// |
2677 | | /// \code |
2678 | | /// __is_pod(int) == true |
2679 | | /// __is_enum(std::string) == false |
2680 | | /// __is_trivially_constructible(vector<int>, int*, int*) |
2681 | | /// \endcode |
2682 | | class TypeTraitExpr final |
2683 | | : public Expr, |
2684 | | private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> { |
2685 | | /// The location of the type trait keyword. |
2686 | | SourceLocation Loc; |
2687 | | |
2688 | | /// The location of the closing parenthesis. |
2689 | | SourceLocation RParenLoc; |
2690 | | |
2691 | | // Note: The TypeSourceInfos for the arguments are allocated after the |
2692 | | // TypeTraitExpr. |
2693 | | |
2694 | | TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, |
2695 | | ArrayRef<TypeSourceInfo *> Args, |
2696 | | SourceLocation RParenLoc, |
2697 | | bool Value); |
2698 | | |
2699 | 52.2k | TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {} |
2700 | | |
2701 | 0 | size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const { |
2702 | 0 | return getNumArgs(); |
2703 | 0 | } |
2704 | | |
2705 | | public: |
2706 | | friend class ASTStmtReader; |
2707 | | friend class ASTStmtWriter; |
2708 | | friend TrailingObjects; |
2709 | | |
2710 | | /// Create a new type trait expression. |
2711 | | static TypeTraitExpr *Create(const ASTContext &C, QualType T, |
2712 | | SourceLocation Loc, TypeTrait Kind, |
2713 | | ArrayRef<TypeSourceInfo *> Args, |
2714 | | SourceLocation RParenLoc, |
2715 | | bool Value); |
2716 | | |
2717 | | static TypeTraitExpr *CreateDeserialized(const ASTContext &C, |
2718 | | unsigned NumArgs); |
2719 | | |
2720 | | /// Determine which type trait this expression uses. |
2721 | 741k | TypeTrait getTrait() const { |
2722 | 741k | return static_cast<TypeTrait>(TypeTraitExprBits.Kind); |
2723 | 741k | } |
2724 | | |
2725 | 230k | bool getValue() const { |
2726 | 230k | assert(!isValueDependent()); |
2727 | 0 | return TypeTraitExprBits.Value; |
2728 | 230k | } |
2729 | | |
2730 | | /// Determine the number of arguments to this type trait. |
2731 | 3.56M | unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } |
2732 | | |
2733 | | /// Retrieve the Ith argument. |
2734 | 1.03M | TypeSourceInfo *getArg(unsigned I) const { |
2735 | 1.03M | assert(I < getNumArgs() && "Argument out-of-range"); |
2736 | 0 | return getArgs()[I]; |
2737 | 1.03M | } |
2738 | | |
2739 | | /// Retrieve the argument types. |
2740 | 1.43M | ArrayRef<TypeSourceInfo *> getArgs() const { |
2741 | 1.43M | return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(), |
2742 | 1.43M | getNumArgs()); |
2743 | 1.43M | } |
2744 | | |
2745 | 1.42M | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
2746 | 277k | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
2747 | | |
2748 | 245k | static bool classof(const Stmt *T) { |
2749 | 245k | return T->getStmtClass() == TypeTraitExprClass; |
2750 | 245k | } |
2751 | | |
2752 | | // Iterators |
2753 | 913k | child_range children() { |
2754 | 913k | return child_range(child_iterator(), child_iterator()); |
2755 | 913k | } |
2756 | | |
2757 | 0 | const_child_range children() const { |
2758 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
2759 | 0 | } |
2760 | | }; |
2761 | | |
2762 | | /// An Embarcadero array type trait, as used in the implementation of |
2763 | | /// __array_rank and __array_extent. |
2764 | | /// |
2765 | | /// Example: |
2766 | | /// \code |
2767 | | /// __array_rank(int[10][20]) == 2 |
2768 | | /// __array_extent(int, 1) == 20 |
2769 | | /// \endcode |
2770 | | class ArrayTypeTraitExpr : public Expr { |
2771 | | /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned. |
2772 | | unsigned ATT : 2; |
2773 | | |
2774 | | /// The value of the type trait. Unspecified if dependent. |
2775 | | uint64_t Value = 0; |
2776 | | |
2777 | | /// The array dimension being queried, or -1 if not used. |
2778 | | Expr *Dimension; |
2779 | | |
2780 | | /// The location of the type trait keyword. |
2781 | | SourceLocation Loc; |
2782 | | |
2783 | | /// The location of the closing paren. |
2784 | | SourceLocation RParen; |
2785 | | |
2786 | | /// The type being queried. |
2787 | | TypeSourceInfo *QueriedType = nullptr; |
2788 | | |
2789 | | public: |
2790 | | friend class ASTStmtReader; |
2791 | | |
2792 | | ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, |
2793 | | TypeSourceInfo *queried, uint64_t value, Expr *dimension, |
2794 | | SourceLocation rparen, QualType ty) |
2795 | | : Expr(ArrayTypeTraitExprClass, ty, VK_PRValue, OK_Ordinary), ATT(att), |
2796 | | Value(value), Dimension(dimension), Loc(loc), RParen(rparen), |
2797 | 544 | QueriedType(queried) { |
2798 | 544 | assert(att <= ATT_Last && "invalid enum value!"); |
2799 | 0 | assert(static_cast<unsigned>(att) == ATT && "ATT overflow!"); |
2800 | 0 | setDependence(computeDependence(this)); |
2801 | 544 | } |
2802 | | |
2803 | | explicit ArrayTypeTraitExpr(EmptyShell Empty) |
2804 | 5 | : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {} |
2805 | | |
2806 | 1.63k | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
2807 | 48 | SourceLocation getEndLoc() const LLVM_READONLY { return RParen; } |
2808 | | |
2809 | 4.79k | ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } |
2810 | | |
2811 | 5.29k | QualType getQueriedType() const { return QueriedType->getType(); } |
2812 | | |
2813 | 66 | TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } |
2814 | | |
2815 | 66 | uint64_t getValue() const { assert(!isTypeDependent()); return Value; } |
2816 | | |
2817 | 586 | Expr *getDimensionExpression() const { return Dimension; } |
2818 | | |
2819 | 0 | static bool classof(const Stmt *T) { |
2820 | 0 | return T->getStmtClass() == ArrayTypeTraitExprClass; |
2821 | 0 | } |
2822 | | |
2823 | | // Iterators |
2824 | 4.80k | child_range children() { |
2825 | 4.80k | return child_range(child_iterator(), child_iterator()); |
2826 | 4.80k | } |
2827 | | |
2828 | 0 | const_child_range children() const { |
2829 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
2830 | 0 | } |
2831 | | }; |
2832 | | |
2833 | | /// An expression trait intrinsic. |
2834 | | /// |
2835 | | /// Example: |
2836 | | /// \code |
2837 | | /// __is_lvalue_expr(std::cout) == true |
2838 | | /// __is_lvalue_expr(1) == false |
2839 | | /// \endcode |
2840 | | class ExpressionTraitExpr : public Expr { |
2841 | | /// The trait. A ExpressionTrait enum in MSVC compatible unsigned. |
2842 | | unsigned ET : 31; |
2843 | | |
2844 | | /// The value of the type trait. Unspecified if dependent. |
2845 | | unsigned Value : 1; |
2846 | | |
2847 | | /// The location of the type trait keyword. |
2848 | | SourceLocation Loc; |
2849 | | |
2850 | | /// The location of the closing paren. |
2851 | | SourceLocation RParen; |
2852 | | |
2853 | | /// The expression being queried. |
2854 | | Expr* QueriedExpression = nullptr; |
2855 | | |
2856 | | public: |
2857 | | friend class ASTStmtReader; |
2858 | | |
2859 | | ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, Expr *queried, |
2860 | | bool value, SourceLocation rparen, QualType resultType) |
2861 | | : Expr(ExpressionTraitExprClass, resultType, VK_PRValue, OK_Ordinary), |
2862 | | ET(et), Value(value), Loc(loc), RParen(rparen), |
2863 | 445 | QueriedExpression(queried) { |
2864 | 445 | assert(et <= ET_Last && "invalid enum value!"); |
2865 | 0 | assert(static_cast<unsigned>(et) == ET && "ET overflow!"); |
2866 | 0 | setDependence(computeDependence(this)); |
2867 | 445 | } |
2868 | | |
2869 | | explicit ExpressionTraitExpr(EmptyShell Empty) |
2870 | 2 | : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false) {} |
2871 | | |
2872 | 1.13k | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
2873 | 21 | SourceLocation getEndLoc() const LLVM_READONLY { return RParen; } |
2874 | | |
2875 | 30 | ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } |
2876 | | |
2877 | 922 | Expr *getQueriedExpression() const { return QueriedExpression; } |
2878 | | |
2879 | 440 | bool getValue() const { return Value; } |
2880 | | |
2881 | 8 | static bool classof(const Stmt *T) { |
2882 | 8 | return T->getStmtClass() == ExpressionTraitExprClass; |
2883 | 8 | } |
2884 | | |
2885 | | // Iterators |
2886 | 35 | child_range children() { |
2887 | 35 | return child_range(child_iterator(), child_iterator()); |
2888 | 35 | } |
2889 | | |
2890 | 0 | const_child_range children() const { |
2891 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
2892 | 0 | } |
2893 | | }; |
2894 | | |
2895 | | /// A reference to an overloaded function set, either an |
2896 | | /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr. |
2897 | | class OverloadExpr : public Expr { |
2898 | | friend class ASTStmtReader; |
2899 | | friend class ASTStmtWriter; |
2900 | | |
2901 | | /// The common name of these declarations. |
2902 | | DeclarationNameInfo NameInfo; |
2903 | | |
2904 | | /// The nested-name-specifier that qualifies the name, if any. |
2905 | | NestedNameSpecifierLoc QualifierLoc; |
2906 | | |
2907 | | protected: |
2908 | | OverloadExpr(StmtClass SC, const ASTContext &Context, |
2909 | | NestedNameSpecifierLoc QualifierLoc, |
2910 | | SourceLocation TemplateKWLoc, |
2911 | | const DeclarationNameInfo &NameInfo, |
2912 | | const TemplateArgumentListInfo *TemplateArgs, |
2913 | | UnresolvedSetIterator Begin, UnresolvedSetIterator End, |
2914 | | bool KnownDependent, bool KnownInstantiationDependent, |
2915 | | bool KnownContainsUnexpandedParameterPack); |
2916 | | |
2917 | | OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults, |
2918 | | bool HasTemplateKWAndArgsInfo); |
2919 | | |
2920 | | /// Return the results. Defined after UnresolvedMemberExpr. |
2921 | | inline DeclAccessPair *getTrailingResults(); |
2922 | 19.8M | const DeclAccessPair *getTrailingResults() const { |
2923 | 19.8M | return const_cast<OverloadExpr *>(this)->getTrailingResults(); |
2924 | 19.8M | } |
2925 | | |
2926 | | /// Return the optional template keyword and arguments info. |
2927 | | /// Defined after UnresolvedMemberExpr. |
2928 | | inline ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo(); |
2929 | 9.15M | const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const { |
2930 | 9.15M | return const_cast<OverloadExpr *>(this) |
2931 | 9.15M | ->getTrailingASTTemplateKWAndArgsInfo(); |
2932 | 9.15M | } |
2933 | | |
2934 | | /// Return the optional template arguments. Defined after |
2935 | | /// UnresolvedMemberExpr. |
2936 | | inline TemplateArgumentLoc *getTrailingTemplateArgumentLoc(); |
2937 | 0 | const TemplateArgumentLoc *getTrailingTemplateArgumentLoc() const { |
2938 | 0 | return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc(); |
2939 | 0 | } |
2940 | | |
2941 | 32.7M | bool hasTemplateKWAndArgsInfo() const { |
2942 | 32.7M | return OverloadExprBits.HasTemplateKWAndArgsInfo; |
2943 | 32.7M | } |
2944 | | |
2945 | | public: |
2946 | | struct FindResult { |
2947 | | OverloadExpr *Expression; |
2948 | | bool IsAddressOfOperand; |
2949 | | bool HasFormOfMemberPointer; |
2950 | | }; |
2951 | | |
2952 | | /// Finds the overloaded expression in the given expression \p E of |
2953 | | /// OverloadTy. |
2954 | | /// |
2955 | | /// \return the expression (which must be there) and true if it has |
2956 | | /// the particular form of a member pointer expression |
2957 | 822k | static FindResult find(Expr *E) { |
2958 | 822k | assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); |
2959 | | |
2960 | 0 | FindResult Result; |
2961 | | |
2962 | 822k | E = E->IgnoreParens(); |
2963 | 822k | if (isa<UnaryOperator>(E)) { |
2964 | 2.61k | assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); |
2965 | 0 | E = cast<UnaryOperator>(E)->getSubExpr(); |
2966 | 2.61k | auto *Ovl = cast<OverloadExpr>(E->IgnoreParens()); |
2967 | | |
2968 | 2.61k | Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()2.59k ); |
2969 | 2.61k | Result.IsAddressOfOperand = true; |
2970 | 2.61k | Result.Expression = Ovl; |
2971 | 819k | } else { |
2972 | 819k | Result.HasFormOfMemberPointer = false; |
2973 | 819k | Result.IsAddressOfOperand = false; |
2974 | 819k | Result.Expression = cast<OverloadExpr>(E); |
2975 | 819k | } |
2976 | | |
2977 | 0 | return Result; |
2978 | 822k | } |
2979 | | |
2980 | | /// Gets the naming class of this lookup, if any. |
2981 | | /// Defined after UnresolvedMemberExpr. |
2982 | | inline CXXRecordDecl *getNamingClass(); |
2983 | 0 | const CXXRecordDecl *getNamingClass() const { |
2984 | 0 | return const_cast<OverloadExpr *>(this)->getNamingClass(); |
2985 | 0 | } |
2986 | | |
2987 | | using decls_iterator = UnresolvedSetImpl::iterator; |
2988 | | |
2989 | 10.6M | decls_iterator decls_begin() const { |
2990 | 10.6M | return UnresolvedSetIterator(getTrailingResults()); |
2991 | 10.6M | } |
2992 | 9.23M | decls_iterator decls_end() const { |
2993 | 9.23M | return UnresolvedSetIterator(getTrailingResults() + getNumDecls()); |
2994 | 9.23M | } |
2995 | 5.45M | llvm::iterator_range<decls_iterator> decls() const { |
2996 | 5.45M | return llvm::make_range(decls_begin(), decls_end()); |
2997 | 5.45M | } |
2998 | | |
2999 | | /// Gets the number of declarations in the unresolved set. |
3000 | 23.0M | unsigned getNumDecls() const { return OverloadExprBits.NumResults; } |
3001 | | |
3002 | | /// Gets the full name info. |
3003 | 9.02M | const DeclarationNameInfo &getNameInfo() const { return NameInfo; } |
3004 | | |
3005 | | /// Gets the name looked up. |
3006 | 2.65M | DeclarationName getName() const { return NameInfo.getName(); } |
3007 | | |
3008 | | /// Gets the location of the name. |
3009 | 3.87M | SourceLocation getNameLoc() const { return NameInfo.getLoc(); } |
3010 | | |
3011 | | /// Fetches the nested-name qualifier, if one was given. |
3012 | 5.52M | NestedNameSpecifier *getQualifier() const { |
3013 | 5.52M | return QualifierLoc.getNestedNameSpecifier(); |
3014 | 5.52M | } |
3015 | | |
3016 | | /// Fetches the nested-name qualifier with source-location |
3017 | | /// information, if one was given. |
3018 | 7.52M | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3019 | | |
3020 | | /// Retrieve the location of the template keyword preceding |
3021 | | /// this name, if any. |
3022 | 1.44M | SourceLocation getTemplateKeywordLoc() const { |
3023 | 1.44M | if (!hasTemplateKWAndArgsInfo()) |
3024 | 946k | return SourceLocation(); |
3025 | 499k | return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc; |
3026 | 1.44M | } |
3027 | | |
3028 | | /// Retrieve the location of the left angle bracket starting the |
3029 | | /// explicit template argument list following the name, if any. |
3030 | 17.5M | SourceLocation getLAngleLoc() const { |
3031 | 17.5M | if (!hasTemplateKWAndArgsInfo()) |
3032 | 11.2M | return SourceLocation(); |
3033 | 6.32M | return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc; |
3034 | 17.5M | } |
3035 | | |
3036 | | /// Retrieve the location of the right angle bracket ending the |
3037 | | /// explicit template argument list following the name, if any. |
3038 | 559k | SourceLocation getRAngleLoc() const { |
3039 | 559k | if (!hasTemplateKWAndArgsInfo()) |
3040 | 0 | return SourceLocation(); |
3041 | 559k | return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc; |
3042 | 559k | } |
3043 | | |
3044 | | /// Determines whether the name was preceded by the template keyword. |
3045 | 115 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
3046 | | |
3047 | | /// Determines whether this expression had explicit template arguments. |
3048 | 17.3M | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } |
3049 | | |
3050 | 5.47M | TemplateArgumentLoc const *getTemplateArgs() const { |
3051 | 5.47M | if (!hasExplicitTemplateArgs()) |
3052 | 3.76M | return nullptr; |
3053 | 1.71M | return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc(); |
3054 | 5.47M | } |
3055 | | |
3056 | 5.10M | unsigned getNumTemplateArgs() const { |
3057 | 5.10M | if (!hasExplicitTemplateArgs()) |
3058 | 3.76M | return 0; |
3059 | | |
3060 | 1.33M | return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs; |
3061 | 5.10M | } |
3062 | | |
3063 | 4.38M | ArrayRef<TemplateArgumentLoc> template_arguments() const { |
3064 | 4.38M | return {getTemplateArgs(), getNumTemplateArgs()}; |
3065 | 4.38M | } |
3066 | | |
3067 | | /// Copies the template arguments into the given structure. |
3068 | 432k | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { |
3069 | 432k | if (hasExplicitTemplateArgs()) |
3070 | 432k | getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List); |
3071 | 432k | } |
3072 | | |
3073 | 828k | static bool classof(const Stmt *T) { |
3074 | 828k | return T->getStmtClass() == UnresolvedLookupExprClass || |
3075 | 828k | T->getStmtClass() == UnresolvedMemberExprClass10.0k ; |
3076 | 828k | } |
3077 | | }; |
3078 | | |
3079 | | /// A reference to a name which we were able to look up during |
3080 | | /// parsing but could not resolve to a specific declaration. |
3081 | | /// |
3082 | | /// This arises in several ways: |
3083 | | /// * we might be waiting for argument-dependent lookup; |
3084 | | /// * the name might resolve to an overloaded function; |
3085 | | /// and eventually: |
3086 | | /// * the lookup might have included a function template. |
3087 | | /// |
3088 | | /// These never include UnresolvedUsingValueDecls, which are always class |
3089 | | /// members and therefore appear only in UnresolvedMemberLookupExprs. |
3090 | | class UnresolvedLookupExpr final |
3091 | | : public OverloadExpr, |
3092 | | private llvm::TrailingObjects<UnresolvedLookupExpr, DeclAccessPair, |
3093 | | ASTTemplateKWAndArgsInfo, |
3094 | | TemplateArgumentLoc> { |
3095 | | friend class ASTStmtReader; |
3096 | | friend class OverloadExpr; |
3097 | | friend TrailingObjects; |
3098 | | |
3099 | | /// The naming class (C++ [class.access.base]p5) of the lookup, if |
3100 | | /// any. This can generally be recalculated from the context chain, |
3101 | | /// but that can be fairly expensive for unqualified lookups. |
3102 | | CXXRecordDecl *NamingClass; |
3103 | | |
3104 | | // UnresolvedLookupExpr is followed by several trailing objects. |
3105 | | // They are in order: |
3106 | | // |
3107 | | // * An array of getNumResults() DeclAccessPair for the results. These are |
3108 | | // undesugared, which is to say, they may include UsingShadowDecls. |
3109 | | // Access is relative to the naming class. |
3110 | | // |
3111 | | // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified |
3112 | | // template keyword and arguments. Present if and only if |
3113 | | // hasTemplateKWAndArgsInfo(). |
3114 | | // |
3115 | | // * An array of getNumTemplateArgs() TemplateArgumentLoc containing |
3116 | | // location information for the explicitly specified template arguments. |
3117 | | |
3118 | | UnresolvedLookupExpr(const ASTContext &Context, CXXRecordDecl *NamingClass, |
3119 | | NestedNameSpecifierLoc QualifierLoc, |
3120 | | SourceLocation TemplateKWLoc, |
3121 | | const DeclarationNameInfo &NameInfo, bool RequiresADL, |
3122 | | bool Overloaded, |
3123 | | const TemplateArgumentListInfo *TemplateArgs, |
3124 | | UnresolvedSetIterator Begin, UnresolvedSetIterator End); |
3125 | | |
3126 | | UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults, |
3127 | | bool HasTemplateKWAndArgsInfo); |
3128 | | |
3129 | 12.0M | unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const { |
3130 | 12.0M | return getNumDecls(); |
3131 | 12.0M | } |
3132 | | |
3133 | 2.34M | unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
3134 | 2.34M | return hasTemplateKWAndArgsInfo(); |
3135 | 2.34M | } |
3136 | | |
3137 | | public: |
3138 | | static UnresolvedLookupExpr * |
3139 | | Create(const ASTContext &Context, CXXRecordDecl *NamingClass, |
3140 | | NestedNameSpecifierLoc QualifierLoc, |
3141 | | const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, |
3142 | | UnresolvedSetIterator Begin, UnresolvedSetIterator End); |
3143 | | |
3144 | | static UnresolvedLookupExpr * |
3145 | | Create(const ASTContext &Context, CXXRecordDecl *NamingClass, |
3146 | | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
3147 | | const DeclarationNameInfo &NameInfo, bool RequiresADL, |
3148 | | const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin, |
3149 | | UnresolvedSetIterator End); |
3150 | | |
3151 | | static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context, |
3152 | | unsigned NumResults, |
3153 | | bool HasTemplateKWAndArgsInfo, |
3154 | | unsigned NumTemplateArgs); |
3155 | | |
3156 | | /// True if this declaration should be extended by |
3157 | | /// argument-dependent lookup. |
3158 | 3.86M | bool requiresADL() const { return UnresolvedLookupExprBits.RequiresADL; } |
3159 | | |
3160 | | /// True if this lookup is overloaded. |
3161 | 633k | bool isOverloaded() const { return UnresolvedLookupExprBits.Overloaded; } |
3162 | | |
3163 | | /// Gets the 'naming class' (in the sense of C++0x |
3164 | | /// [class.access.base]p5) of the lookup. This is the scope |
3165 | | /// that was looked in to find these results. |
3166 | 2.35M | CXXRecordDecl *getNamingClass() { return NamingClass; } |
3167 | 0 | const CXXRecordDecl *getNamingClass() const { return NamingClass; } |
3168 | | |
3169 | 4.04M | SourceLocation getBeginLoc() const LLVM_READONLY { |
3170 | 4.04M | if (NestedNameSpecifierLoc l = getQualifierLoc()) |
3171 | 1.72M | return l.getBeginLoc(); |
3172 | 2.32M | return getNameInfo().getBeginLoc(); |
3173 | 4.04M | } |
3174 | | |
3175 | 354k | SourceLocation getEndLoc() const LLVM_READONLY { |
3176 | 354k | if (hasExplicitTemplateArgs()) |
3177 | 275k | return getRAngleLoc(); |
3178 | 78.7k | return getNameInfo().getEndLoc(); |
3179 | 354k | } |
3180 | | |
3181 | 689k | child_range children() { |
3182 | 689k | return child_range(child_iterator(), child_iterator()); |
3183 | 689k | } |
3184 | | |
3185 | 0 | const_child_range children() const { |
3186 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
3187 | 0 | } |
3188 | | |
3189 | 48.1M | static bool classof(const Stmt *T) { |
3190 | 48.1M | return T->getStmtClass() == UnresolvedLookupExprClass; |
3191 | 48.1M | } |
3192 | | }; |
3193 | | |
3194 | | /// A qualified reference to a name whose declaration cannot |
3195 | | /// yet be resolved. |
3196 | | /// |
3197 | | /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that |
3198 | | /// it expresses a reference to a declaration such as |
3199 | | /// X<T>::value. The difference, however, is that an |
3200 | | /// DependentScopeDeclRefExpr node is used only within C++ templates when |
3201 | | /// the qualification (e.g., X<T>::) refers to a dependent type. In |
3202 | | /// this case, X<T>::value cannot resolve to a declaration because the |
3203 | | /// declaration will differ from one instantiation of X<T> to the |
3204 | | /// next. Therefore, DependentScopeDeclRefExpr keeps track of the |
3205 | | /// qualifier (X<T>::) and the name of the entity being referenced |
3206 | | /// ("value"). Such expressions will instantiate to a DeclRefExpr once the |
3207 | | /// declaration can be found. |
3208 | | class DependentScopeDeclRefExpr final |
3209 | | : public Expr, |
3210 | | private llvm::TrailingObjects<DependentScopeDeclRefExpr, |
3211 | | ASTTemplateKWAndArgsInfo, |
3212 | | TemplateArgumentLoc> { |
3213 | | friend class ASTStmtReader; |
3214 | | friend class ASTStmtWriter; |
3215 | | friend TrailingObjects; |
3216 | | |
3217 | | /// The nested-name-specifier that qualifies this unresolved |
3218 | | /// declaration name. |
3219 | | NestedNameSpecifierLoc QualifierLoc; |
3220 | | |
3221 | | /// The name of the entity we will be referencing. |
3222 | | DeclarationNameInfo NameInfo; |
3223 | | |
3224 | | DependentScopeDeclRefExpr(QualType Ty, NestedNameSpecifierLoc QualifierLoc, |
3225 | | SourceLocation TemplateKWLoc, |
3226 | | const DeclarationNameInfo &NameInfo, |
3227 | | const TemplateArgumentListInfo *Args); |
3228 | | |
3229 | 200k | size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
3230 | 200k | return hasTemplateKWAndArgsInfo(); |
3231 | 200k | } |
3232 | | |
3233 | 19.4M | bool hasTemplateKWAndArgsInfo() const { |
3234 | 19.4M | return DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo; |
3235 | 19.4M | } |
3236 | | |
3237 | | public: |
3238 | | static DependentScopeDeclRefExpr * |
3239 | | Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, |
3240 | | SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, |
3241 | | const TemplateArgumentListInfo *TemplateArgs); |
3242 | | |
3243 | | static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &Context, |
3244 | | bool HasTemplateKWAndArgsInfo, |
3245 | | unsigned NumTemplateArgs); |
3246 | | |
3247 | | /// Retrieve the name that this expression refers to. |
3248 | 4.18M | const DeclarationNameInfo &getNameInfo() const { return NameInfo; } |
3249 | | |
3250 | | /// Retrieve the name that this expression refers to. |
3251 | 5.80M | DeclarationName getDeclName() const { return NameInfo.getName(); } |
3252 | | |
3253 | | /// Retrieve the location of the name within the expression. |
3254 | | /// |
3255 | | /// For example, in "X<T>::value" this is the location of "value". |
3256 | 84.3k | SourceLocation getLocation() const { return NameInfo.getLoc(); } |
3257 | | |
3258 | | /// Retrieve the nested-name-specifier that qualifies the |
3259 | | /// name, with source location information. |
3260 | 4.69M | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3261 | | |
3262 | | /// Retrieve the nested-name-specifier that qualifies this |
3263 | | /// declaration. |
3264 | 7.65M | NestedNameSpecifier *getQualifier() const { |
3265 | 7.65M | return QualifierLoc.getNestedNameSpecifier(); |
3266 | 7.65M | } |
3267 | | |
3268 | | /// Retrieve the location of the template keyword preceding |
3269 | | /// this name, if any. |
3270 | 1.68M | SourceLocation getTemplateKeywordLoc() const { |
3271 | 1.68M | if (!hasTemplateKWAndArgsInfo()) |
3272 | 1.63M | return SourceLocation(); |
3273 | 52.4k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc; |
3274 | 1.68M | } |
3275 | | |
3276 | | /// Retrieve the location of the left angle bracket starting the |
3277 | | /// explicit template argument list following the name, if any. |
3278 | 17.2M | SourceLocation getLAngleLoc() const { |
3279 | 17.2M | if (!hasTemplateKWAndArgsInfo()) |
3280 | 16.6M | return SourceLocation(); |
3281 | 592k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc; |
3282 | 17.2M | } |
3283 | | |
3284 | | /// Retrieve the location of the right angle bracket ending the |
3285 | | /// explicit template argument list following the name, if any. |
3286 | 319k | SourceLocation getRAngleLoc() const { |
3287 | 319k | if (!hasTemplateKWAndArgsInfo()) |
3288 | 248k | return SourceLocation(); |
3289 | 70.3k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc; |
3290 | 319k | } |
3291 | | |
3292 | | /// Determines whether the name was preceded by the template keyword. |
3293 | 183 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
3294 | | |
3295 | | /// Determines whether this lookup had explicit template arguments. |
3296 | 16.9M | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } |
3297 | | |
3298 | | /// Copies the template arguments (if present) into the given |
3299 | | /// structure. |
3300 | 0 | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { |
3301 | 0 | if (hasExplicitTemplateArgs()) |
3302 | 0 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto( |
3303 | 0 | getTrailingObjects<TemplateArgumentLoc>(), List); |
3304 | 0 | } |
3305 | | |
3306 | 2.28M | TemplateArgumentLoc const *getTemplateArgs() const { |
3307 | 2.28M | if (!hasExplicitTemplateArgs()) |
3308 | 2.12M | return nullptr; |
3309 | | |
3310 | 159k | return getTrailingObjects<TemplateArgumentLoc>(); |
3311 | 2.28M | } |
3312 | | |
3313 | 2.28M | unsigned getNumTemplateArgs() const { |
3314 | 2.28M | if (!hasExplicitTemplateArgs()) |
3315 | 2.12M | return 0; |
3316 | | |
3317 | 159k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; |
3318 | 2.28M | } |
3319 | | |
3320 | 2.11M | ArrayRef<TemplateArgumentLoc> template_arguments() const { |
3321 | 2.11M | return {getTemplateArgs(), getNumTemplateArgs()}; |
3322 | 2.11M | } |
3323 | | |
3324 | | /// Note: getBeginLoc() is the start of the whole DependentScopeDeclRefExpr, |
3325 | | /// and differs from getLocation().getStart(). |
3326 | 2.07M | SourceLocation getBeginLoc() const LLVM_READONLY { |
3327 | 2.07M | return QualifierLoc.getBeginLoc(); |
3328 | 2.07M | } |
3329 | | |
3330 | 102k | SourceLocation getEndLoc() const LLVM_READONLY { |
3331 | 102k | if (hasExplicitTemplateArgs()) |
3332 | 17.8k | return getRAngleLoc(); |
3333 | 84.3k | return getLocation(); |
3334 | 102k | } |
3335 | | |
3336 | 1.50M | static bool classof(const Stmt *T) { |
3337 | 1.50M | return T->getStmtClass() == DependentScopeDeclRefExprClass; |
3338 | 1.50M | } |
3339 | | |
3340 | 5.70M | child_range children() { |
3341 | 5.70M | return child_range(child_iterator(), child_iterator()); |
3342 | 5.70M | } |
3343 | | |
3344 | 0 | const_child_range children() const { |
3345 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
3346 | 0 | } |
3347 | | }; |
3348 | | |
3349 | | /// Represents an expression -- generally a full-expression -- that |
3350 | | /// introduces cleanups to be run at the end of the sub-expression's |
3351 | | /// evaluation. The most common source of expression-introduced |
3352 | | /// cleanups is temporary objects in C++, but several other kinds of |
3353 | | /// expressions can create cleanups, including basically every |
3354 | | /// call in ARC that returns an Objective-C pointer. |
3355 | | /// |
3356 | | /// This expression also tracks whether the sub-expression contains a |
3357 | | /// potentially-evaluated block literal. The lifetime of a block |
3358 | | /// literal is the extent of the enclosing scope. |
3359 | | class ExprWithCleanups final |
3360 | | : public FullExpr, |
3361 | | private llvm::TrailingObjects< |
3362 | | ExprWithCleanups, |
3363 | | llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>> { |
3364 | | public: |
3365 | | /// The type of objects that are kept in the cleanup. |
3366 | | /// It's useful to remember the set of blocks and block-scoped compound |
3367 | | /// literals; we could also remember the set of temporaries, but there's |
3368 | | /// currently no need. |
3369 | | using CleanupObject = llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>; |
3370 | | |
3371 | | private: |
3372 | | friend class ASTStmtReader; |
3373 | | friend TrailingObjects; |
3374 | | |
3375 | | ExprWithCleanups(EmptyShell, unsigned NumObjects); |
3376 | | ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects, |
3377 | | ArrayRef<CleanupObject> Objects); |
3378 | | |
3379 | | public: |
3380 | | static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty, |
3381 | | unsigned numObjects); |
3382 | | |
3383 | | static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr, |
3384 | | bool CleanupsHaveSideEffects, |
3385 | | ArrayRef<CleanupObject> objects); |
3386 | | |
3387 | 17.2k | ArrayRef<CleanupObject> getObjects() const { |
3388 | 17.2k | return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(), |
3389 | 17.2k | getNumObjects()); |
3390 | 17.2k | } |
3391 | | |
3392 | 51.3k | unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } |
3393 | | |
3394 | 129 | CleanupObject getObject(unsigned i) const { |
3395 | 129 | assert(i < getNumObjects() && "Index out of range"); |
3396 | 0 | return getObjects()[i]; |
3397 | 129 | } |
3398 | | |
3399 | 35.5k | bool cleanupsHaveSideEffects() const { |
3400 | 35.5k | return ExprWithCleanupsBits.CleanupsHaveSideEffects; |
3401 | 35.5k | } |
3402 | | |
3403 | 46.1k | SourceLocation getBeginLoc() const LLVM_READONLY { |
3404 | 46.1k | return SubExpr->getBeginLoc(); |
3405 | 46.1k | } |
3406 | | |
3407 | 51.1k | SourceLocation getEndLoc() const LLVM_READONLY { |
3408 | 51.1k | return SubExpr->getEndLoc(); |
3409 | 51.1k | } |
3410 | | |
3411 | | // Implement isa/cast/dyncast/etc. |
3412 | 2.78M | static bool classof(const Stmt *T) { |
3413 | 2.78M | return T->getStmtClass() == ExprWithCleanupsClass; |
3414 | 2.78M | } |
3415 | | |
3416 | | // Iterators |
3417 | 69.0k | child_range children() { return child_range(&SubExpr, &SubExpr + 1); } |
3418 | | |
3419 | 0 | const_child_range children() const { |
3420 | 0 | return const_child_range(&SubExpr, &SubExpr + 1); |
3421 | 0 | } |
3422 | | }; |
3423 | | |
3424 | | /// Describes an explicit type conversion that uses functional |
3425 | | /// notion but could not be resolved because one or more arguments are |
3426 | | /// type-dependent. |
3427 | | /// |
3428 | | /// The explicit type conversions expressed by |
3429 | | /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>, |
3430 | | /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and |
3431 | | /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is |
3432 | | /// type-dependent. For example, this would occur in a template such |
3433 | | /// as: |
3434 | | /// |
3435 | | /// \code |
3436 | | /// template<typename T, typename A1> |
3437 | | /// inline T make_a(const A1& a1) { |
3438 | | /// return T(a1); |
3439 | | /// } |
3440 | | /// \endcode |
3441 | | /// |
3442 | | /// When the returned expression is instantiated, it may resolve to a |
3443 | | /// constructor call, conversion function call, or some kind of type |
3444 | | /// conversion. |
3445 | | class CXXUnresolvedConstructExpr final |
3446 | | : public Expr, |
3447 | | private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> { |
3448 | | friend class ASTStmtReader; |
3449 | | friend TrailingObjects; |
3450 | | |
3451 | | /// The type being constructed. |
3452 | | TypeSourceInfo *TSI; |
3453 | | |
3454 | | /// The location of the left parentheses ('('). |
3455 | | SourceLocation LParenLoc; |
3456 | | |
3457 | | /// The location of the right parentheses (')'). |
3458 | | SourceLocation RParenLoc; |
3459 | | |
3460 | | CXXUnresolvedConstructExpr(QualType T, TypeSourceInfo *TSI, |
3461 | | SourceLocation LParenLoc, ArrayRef<Expr *> Args, |
3462 | | SourceLocation RParenLoc); |
3463 | | |
3464 | | CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) |
3465 | 91.6k | : Expr(CXXUnresolvedConstructExprClass, Empty), TSI(nullptr) { |
3466 | 91.6k | CXXUnresolvedConstructExprBits.NumArgs = NumArgs; |
3467 | 91.6k | } |
3468 | | |
3469 | | public: |
3470 | | static CXXUnresolvedConstructExpr *Create(const ASTContext &Context, |
3471 | | QualType T, TypeSourceInfo *TSI, |
3472 | | SourceLocation LParenLoc, |
3473 | | ArrayRef<Expr *> Args, |
3474 | | SourceLocation RParenLoc); |
3475 | | |
3476 | | static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &Context, |
3477 | | unsigned NumArgs); |
3478 | | |
3479 | | /// Retrieve the type that is being constructed, as specified |
3480 | | /// in the source code. |
3481 | 498k | QualType getTypeAsWritten() const { return TSI->getType(); } |
3482 | | |
3483 | | /// Retrieve the type source information for the type being |
3484 | | /// constructed. |
3485 | 268k | TypeSourceInfo *getTypeSourceInfo() const { return TSI; } |
3486 | | |
3487 | | /// Retrieve the location of the left parentheses ('(') that |
3488 | | /// precedes the argument list. |
3489 | 173k | SourceLocation getLParenLoc() const { return LParenLoc; } |
3490 | 91.6k | void setLParenLoc(SourceLocation L) { LParenLoc = L; } |
3491 | | |
3492 | | /// Retrieve the location of the right parentheses (')') that |
3493 | | /// follows the argument list. |
3494 | 173k | SourceLocation getRParenLoc() const { return RParenLoc; } |
3495 | 91.6k | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
3496 | | |
3497 | | /// Determine whether this expression models list-initialization. |
3498 | | /// If so, there will be exactly one subexpression, which will be |
3499 | | /// an InitListExpr. |
3500 | 184k | bool isListInitialization() const { return LParenLoc.isInvalid(); } |
3501 | | |
3502 | | /// Retrieve the number of arguments. |
3503 | 1.17M | unsigned getNumArgs() const { return CXXUnresolvedConstructExprBits.NumArgs; } |
3504 | | |
3505 | | using arg_iterator = Expr **; |
3506 | | using arg_range = llvm::iterator_range<arg_iterator>; |
3507 | | |
3508 | 1.36M | arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); } |
3509 | 547k | arg_iterator arg_end() { return arg_begin() + getNumArgs(); } |
3510 | 434k | arg_range arguments() { return arg_range(arg_begin(), arg_end()); } |
3511 | | |
3512 | | using const_arg_iterator = const Expr* const *; |
3513 | | using const_arg_range = llvm::iterator_range<const_arg_iterator>; |
3514 | | |
3515 | 254 | const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); } |
3516 | 8 | const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } |
3517 | 8 | const_arg_range arguments() const { |
3518 | 8 | return const_arg_range(arg_begin(), arg_end()); |
3519 | 8 | } |
3520 | | |
3521 | 0 | Expr *getArg(unsigned I) { |
3522 | 0 | assert(I < getNumArgs() && "Argument index out-of-range"); |
3523 | 0 | return arg_begin()[I]; |
3524 | 0 | } |
3525 | | |
3526 | 238 | const Expr *getArg(unsigned I) const { |
3527 | 238 | assert(I < getNumArgs() && "Argument index out-of-range"); |
3528 | 0 | return arg_begin()[I]; |
3529 | 238 | } |
3530 | | |
3531 | 87.2k | void setArg(unsigned I, Expr *E) { |
3532 | 87.2k | assert(I < getNumArgs() && "Argument index out-of-range"); |
3533 | 0 | arg_begin()[I] = E; |
3534 | 87.2k | } |
3535 | | |
3536 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
3537 | 22.8k | SourceLocation getEndLoc() const LLVM_READONLY { |
3538 | 22.8k | if (!RParenLoc.isValid() && getNumArgs() > 0200 ) |
3539 | 200 | return getArg(getNumArgs() - 1)->getEndLoc(); |
3540 | 22.6k | return RParenLoc; |
3541 | 22.8k | } |
3542 | | |
3543 | 71.4k | static bool classof(const Stmt *T) { |
3544 | 71.4k | return T->getStmtClass() == CXXUnresolvedConstructExprClass; |
3545 | 71.4k | } |
3546 | | |
3547 | | // Iterators |
3548 | 121k | child_range children() { |
3549 | 121k | auto **begin = reinterpret_cast<Stmt **>(arg_begin()); |
3550 | 121k | return child_range(begin, begin + getNumArgs()); |
3551 | 121k | } |
3552 | | |
3553 | 0 | const_child_range children() const { |
3554 | 0 | auto **begin = reinterpret_cast<Stmt **>( |
3555 | 0 | const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin()); |
3556 | 0 | return const_child_range(begin, begin + getNumArgs()); |
3557 | 0 | } |
3558 | | }; |
3559 | | |
3560 | | /// Represents a C++ member access expression where the actual |
3561 | | /// member referenced could not be resolved because the base |
3562 | | /// expression or the member name was dependent. |
3563 | | /// |
3564 | | /// Like UnresolvedMemberExprs, these can be either implicit or |
3565 | | /// explicit accesses. It is only possible to get one of these with |
3566 | | /// an implicit access if a qualifier is provided. |
3567 | | class CXXDependentScopeMemberExpr final |
3568 | | : public Expr, |
3569 | | private llvm::TrailingObjects<CXXDependentScopeMemberExpr, |
3570 | | ASTTemplateKWAndArgsInfo, |
3571 | | TemplateArgumentLoc, NamedDecl *> { |
3572 | | friend class ASTStmtReader; |
3573 | | friend class ASTStmtWriter; |
3574 | | friend TrailingObjects; |
3575 | | |
3576 | | /// The expression for the base pointer or class reference, |
3577 | | /// e.g., the \c x in x.f. Can be null in implicit accesses. |
3578 | | Stmt *Base; |
3579 | | |
3580 | | /// The type of the base expression. Never null, even for |
3581 | | /// implicit accesses. |
3582 | | QualType BaseType; |
3583 | | |
3584 | | /// The nested-name-specifier that precedes the member name, if any. |
3585 | | /// FIXME: This could be in principle store as a trailing object. |
3586 | | /// However the performance impact of doing so should be investigated first. |
3587 | | NestedNameSpecifierLoc QualifierLoc; |
3588 | | |
3589 | | /// The member to which this member expression refers, which |
3590 | | /// can be name, overloaded operator, or destructor. |
3591 | | /// |
3592 | | /// FIXME: could also be a template-id |
3593 | | DeclarationNameInfo MemberNameInfo; |
3594 | | |
3595 | | // CXXDependentScopeMemberExpr is followed by several trailing objects, |
3596 | | // some of which optional. They are in order: |
3597 | | // |
3598 | | // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified |
3599 | | // template keyword and arguments. Present if and only if |
3600 | | // hasTemplateKWAndArgsInfo(). |
3601 | | // |
3602 | | // * An array of getNumTemplateArgs() TemplateArgumentLoc containing location |
3603 | | // information for the explicitly specified template arguments. |
3604 | | // |
3605 | | // * An optional NamedDecl *. In a qualified member access expression such |
3606 | | // as t->Base::f, this member stores the resolves of name lookup in the |
3607 | | // context of the member access expression, to be used at instantiation |
3608 | | // time. Present if and only if hasFirstQualifierFoundInScope(). |
3609 | | |
3610 | 8.04M | bool hasTemplateKWAndArgsInfo() const { |
3611 | 8.04M | return CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo; |
3612 | 8.04M | } |
3613 | | |
3614 | 3.71M | bool hasFirstQualifierFoundInScope() const { |
3615 | 3.71M | return CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope; |
3616 | 3.71M | } |
3617 | | |
3618 | 6.46k | unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
3619 | 6.46k | return hasTemplateKWAndArgsInfo(); |
3620 | 6.46k | } |
3621 | | |
3622 | 117 | unsigned numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const { |
3623 | 117 | return getNumTemplateArgs(); |
3624 | 117 | } |
3625 | | |
3626 | 0 | unsigned numTrailingObjects(OverloadToken<NamedDecl *>) const { |
3627 | 0 | return hasFirstQualifierFoundInScope(); |
3628 | 0 | } |
3629 | | |
3630 | | CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base, |
3631 | | QualType BaseType, bool IsArrow, |
3632 | | SourceLocation OperatorLoc, |
3633 | | NestedNameSpecifierLoc QualifierLoc, |
3634 | | SourceLocation TemplateKWLoc, |
3635 | | NamedDecl *FirstQualifierFoundInScope, |
3636 | | DeclarationNameInfo MemberNameInfo, |
3637 | | const TemplateArgumentListInfo *TemplateArgs); |
3638 | | |
3639 | | CXXDependentScopeMemberExpr(EmptyShell Empty, bool HasTemplateKWAndArgsInfo, |
3640 | | bool HasFirstQualifierFoundInScope); |
3641 | | |
3642 | | public: |
3643 | | static CXXDependentScopeMemberExpr * |
3644 | | Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, |
3645 | | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, |
3646 | | SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, |
3647 | | DeclarationNameInfo MemberNameInfo, |
3648 | | const TemplateArgumentListInfo *TemplateArgs); |
3649 | | |
3650 | | static CXXDependentScopeMemberExpr * |
3651 | | CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo, |
3652 | | unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope); |
3653 | | |
3654 | | /// True if this is an implicit access, i.e. one in which the |
3655 | | /// member being accessed was not written in the source. The source |
3656 | | /// location of the operator is invalid in this case. |
3657 | 8.12M | bool isImplicitAccess() const { |
3658 | 8.12M | if (!Base) |
3659 | 735k | return true; |
3660 | 7.39M | return cast<Expr>(Base)->isImplicitCXXThis(); |
3661 | 8.12M | } |
3662 | | |
3663 | | /// Retrieve the base object of this member expressions, |
3664 | | /// e.g., the \c x in \c x.m. |
3665 | 2.58M | Expr *getBase() const { |
3666 | 2.58M | assert(!isImplicitAccess()); |
3667 | 0 | return cast<Expr>(Base); |
3668 | 2.58M | } |
3669 | | |
3670 | 153k | QualType getBaseType() const { return BaseType; } |
3671 | | |
3672 | | /// Determine whether this member expression used the '->' |
3673 | | /// operator; otherwise, it used the '.' operator. |
3674 | 1.19M | bool isArrow() const { return CXXDependentScopeMemberExprBits.IsArrow; } |
3675 | | |
3676 | | /// Retrieve the location of the '->' or '.' operator. |
3677 | 999k | SourceLocation getOperatorLoc() const { |
3678 | 999k | return CXXDependentScopeMemberExprBits.OperatorLoc; |
3679 | 999k | } |
3680 | | |
3681 | | /// Retrieve the nested-name-specifier that qualifies the member name. |
3682 | 2.71M | NestedNameSpecifier *getQualifier() const { |
3683 | 2.71M | return QualifierLoc.getNestedNameSpecifier(); |
3684 | 2.71M | } |
3685 | | |
3686 | | /// Retrieve the nested-name-specifier that qualifies the member |
3687 | | /// name, with source location information. |
3688 | 1.28M | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3689 | | |
3690 | | /// Retrieve the first part of the nested-name-specifier that was |
3691 | | /// found in the scope of the member access expression when the member access |
3692 | | /// was initially parsed. |
3693 | | /// |
3694 | | /// This function only returns a useful result when member access expression |
3695 | | /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration |
3696 | | /// returned by this function describes what was found by unqualified name |
3697 | | /// lookup for the identifier "Base" within the scope of the member access |
3698 | | /// expression itself. At template instantiation time, this information is |
3699 | | /// combined with the results of name lookup into the type of the object |
3700 | | /// expression itself (the class type of x). |
3701 | 759k | NamedDecl *getFirstQualifierFoundInScope() const { |
3702 | 759k | if (!hasFirstQualifierFoundInScope()) |
3703 | 759k | return nullptr; |
3704 | 59 | return *getTrailingObjects<NamedDecl *>(); |
3705 | 759k | } |
3706 | | |
3707 | | /// Retrieve the name of the member that this expression refers to. |
3708 | 2.97M | const DeclarationNameInfo &getMemberNameInfo() const { |
3709 | 2.97M | return MemberNameInfo; |
3710 | 2.97M | } |
3711 | | |
3712 | | /// Retrieve the name of the member that this expression refers to. |
3713 | 852k | DeclarationName getMember() const { return MemberNameInfo.getName(); } |
3714 | | |
3715 | | // Retrieve the location of the name of the member that this |
3716 | | // expression refers to. |
3717 | 617k | SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } |
3718 | | |
3719 | | /// Retrieve the location of the template keyword preceding the |
3720 | | /// member name, if any. |
3721 | 761k | SourceLocation getTemplateKeywordLoc() const { |
3722 | 761k | if (!hasTemplateKWAndArgsInfo()) |
3723 | 761k | return SourceLocation(); |
3724 | 416 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc; |
3725 | 761k | } |
3726 | | |
3727 | | /// Retrieve the location of the left angle bracket starting the |
3728 | | /// explicit template argument list following the member name, if any. |
3729 | 6.39M | SourceLocation getLAngleLoc() const { |
3730 | 6.39M | if (!hasTemplateKWAndArgsInfo()) |
3731 | 6.38M | return SourceLocation(); |
3732 | 8.97k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc; |
3733 | 6.39M | } |
3734 | | |
3735 | | /// Retrieve the location of the right angle bracket ending the |
3736 | | /// explicit template argument list following the member name, if any. |
3737 | 387 | SourceLocation getRAngleLoc() const { |
3738 | 387 | if (!hasTemplateKWAndArgsInfo()) |
3739 | 0 | return SourceLocation(); |
3740 | 387 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc; |
3741 | 387 | } |
3742 | | |
3743 | | /// Determines whether the member name was preceded by the template keyword. |
3744 | 2.29k | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
3745 | | |
3746 | | /// Determines whether this member expression actually had a C++ |
3747 | | /// template argument list explicitly specified, e.g., x.f<int>. |
3748 | 6.39M | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } |
3749 | | |
3750 | | /// Copies the template arguments (if present) into the given |
3751 | | /// structure. |
3752 | 0 | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { |
3753 | 0 | if (hasExplicitTemplateArgs()) |
3754 | 0 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto( |
3755 | 0 | getTrailingObjects<TemplateArgumentLoc>(), List); |
3756 | 0 | } |
3757 | | |
3758 | | /// Retrieve the template arguments provided as part of this |
3759 | | /// template-id. |
3760 | 2.07M | const TemplateArgumentLoc *getTemplateArgs() const { |
3761 | 2.07M | if (!hasExplicitTemplateArgs()) |
3762 | 2.07M | return nullptr; |
3763 | | |
3764 | 3.50k | return getTrailingObjects<TemplateArgumentLoc>(); |
3765 | 2.07M | } |
3766 | | |
3767 | | /// Retrieve the number of template arguments provided as part of this |
3768 | | /// template-id. |
3769 | 2.83M | unsigned getNumTemplateArgs() const { |
3770 | 2.83M | if (!hasExplicitTemplateArgs()) |
3771 | 2.83M | return 0; |
3772 | | |
3773 | 3.82k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; |
3774 | 2.83M | } |
3775 | | |
3776 | 2.07M | ArrayRef<TemplateArgumentLoc> template_arguments() const { |
3777 | 2.07M | return {getTemplateArgs(), getNumTemplateArgs()}; |
3778 | 2.07M | } |
3779 | | |
3780 | 1.73M | SourceLocation getBeginLoc() const LLVM_READONLY { |
3781 | 1.73M | if (!isImplicitAccess()) |
3782 | 1.48M | return Base->getBeginLoc(); |
3783 | 256k | if (getQualifier()) |
3784 | 256k | return getQualifierLoc().getBeginLoc(); |
3785 | 8 | return MemberNameInfo.getBeginLoc(); |
3786 | 256k | } |
3787 | | |
3788 | 105k | SourceLocation getEndLoc() const LLVM_READONLY { |
3789 | 105k | if (hasExplicitTemplateArgs()) |
3790 | 5 | return getRAngleLoc(); |
3791 | 105k | return MemberNameInfo.getEndLoc(); |
3792 | 105k | } |
3793 | | |
3794 | 151k | static bool classof(const Stmt *T) { |
3795 | 151k | return T->getStmtClass() == CXXDependentScopeMemberExprClass; |
3796 | 151k | } |
3797 | | |
3798 | | // Iterators |
3799 | 379k | child_range children() { |
3800 | 379k | if (isImplicitAccess()) |
3801 | 19.8k | return child_range(child_iterator(), child_iterator()); |
3802 | 359k | return child_range(&Base, &Base + 1); |
3803 | 379k | } |
3804 | | |
3805 | 0 | const_child_range children() const { |
3806 | 0 | if (isImplicitAccess()) |
3807 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
3808 | 0 | return const_child_range(&Base, &Base + 1); |
3809 | 0 | } |
3810 | | }; |
3811 | | |
3812 | | /// Represents a C++ member access expression for which lookup |
3813 | | /// produced a set of overloaded functions. |
3814 | | /// |
3815 | | /// The member access may be explicit or implicit: |
3816 | | /// \code |
3817 | | /// struct A { |
3818 | | /// int a, b; |
3819 | | /// int explicitAccess() { return this->a + this->A::b; } |
3820 | | /// int implicitAccess() { return a + A::b; } |
3821 | | /// }; |
3822 | | /// \endcode |
3823 | | /// |
3824 | | /// In the final AST, an explicit access always becomes a MemberExpr. |
3825 | | /// An implicit access may become either a MemberExpr or a |
3826 | | /// DeclRefExpr, depending on whether the member is static. |
3827 | | class UnresolvedMemberExpr final |
3828 | | : public OverloadExpr, |
3829 | | private llvm::TrailingObjects<UnresolvedMemberExpr, DeclAccessPair, |
3830 | | ASTTemplateKWAndArgsInfo, |
3831 | | TemplateArgumentLoc> { |
3832 | | friend class ASTStmtReader; |
3833 | | friend class OverloadExpr; |
3834 | | friend TrailingObjects; |
3835 | | |
3836 | | /// The expression for the base pointer or class reference, |
3837 | | /// e.g., the \c x in x.f. |
3838 | | /// |
3839 | | /// This can be null if this is an 'unbased' member expression. |
3840 | | Stmt *Base; |
3841 | | |
3842 | | /// The type of the base expression; never null. |
3843 | | QualType BaseType; |
3844 | | |
3845 | | /// The location of the '->' or '.' operator. |
3846 | | SourceLocation OperatorLoc; |
3847 | | |
3848 | | // UnresolvedMemberExpr is followed by several trailing objects. |
3849 | | // They are in order: |
3850 | | // |
3851 | | // * An array of getNumResults() DeclAccessPair for the results. These are |
3852 | | // undesugared, which is to say, they may include UsingShadowDecls. |
3853 | | // Access is relative to the naming class. |
3854 | | // |
3855 | | // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified |
3856 | | // template keyword and arguments. Present if and only if |
3857 | | // hasTemplateKWAndArgsInfo(). |
3858 | | // |
3859 | | // * An array of getNumTemplateArgs() TemplateArgumentLoc containing |
3860 | | // location information for the explicitly specified template arguments. |
3861 | | |
3862 | | UnresolvedMemberExpr(const ASTContext &Context, bool HasUnresolvedUsing, |
3863 | | Expr *Base, QualType BaseType, bool IsArrow, |
3864 | | SourceLocation OperatorLoc, |
3865 | | NestedNameSpecifierLoc QualifierLoc, |
3866 | | SourceLocation TemplateKWLoc, |
3867 | | const DeclarationNameInfo &MemberNameInfo, |
3868 | | const TemplateArgumentListInfo *TemplateArgs, |
3869 | | UnresolvedSetIterator Begin, UnresolvedSetIterator End); |
3870 | | |
3871 | | UnresolvedMemberExpr(EmptyShell Empty, unsigned NumResults, |
3872 | | bool HasTemplateKWAndArgsInfo); |
3873 | | |
3874 | 108k | unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const { |
3875 | 108k | return getNumDecls(); |
3876 | 108k | } |
3877 | | |
3878 | 30.5k | unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
3879 | 30.5k | return hasTemplateKWAndArgsInfo(); |
3880 | 30.5k | } |
3881 | | |
3882 | | public: |
3883 | | static UnresolvedMemberExpr * |
3884 | | Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, |
3885 | | QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, |
3886 | | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
3887 | | const DeclarationNameInfo &MemberNameInfo, |
3888 | | const TemplateArgumentListInfo *TemplateArgs, |
3889 | | UnresolvedSetIterator Begin, UnresolvedSetIterator End); |
3890 | | |
3891 | | static UnresolvedMemberExpr *CreateEmpty(const ASTContext &Context, |
3892 | | unsigned NumResults, |
3893 | | bool HasTemplateKWAndArgsInfo, |
3894 | | unsigned NumTemplateArgs); |
3895 | | |
3896 | | /// True if this is an implicit access, i.e., one in which the |
3897 | | /// member being accessed was not written in the source. |
3898 | | /// |
3899 | | /// The source location of the operator is invalid in this case. |
3900 | | bool isImplicitAccess() const; |
3901 | | |
3902 | | /// Retrieve the base object of this member expressions, |
3903 | | /// e.g., the \c x in \c x.m. |
3904 | 112k | Expr *getBase() { |
3905 | 112k | assert(!isImplicitAccess()); |
3906 | 0 | return cast<Expr>(Base); |
3907 | 112k | } |
3908 | 18 | const Expr *getBase() const { |
3909 | 18 | assert(!isImplicitAccess()); |
3910 | 0 | return cast<Expr>(Base); |
3911 | 18 | } |
3912 | | |
3913 | 193k | QualType getBaseType() const { return BaseType; } |
3914 | | |
3915 | | /// Determine whether the lookup results contain an unresolved using |
3916 | | /// declaration. |
3917 | 113k | bool hasUnresolvedUsing() const { |
3918 | 113k | return UnresolvedMemberExprBits.HasUnresolvedUsing; |
3919 | 113k | } |
3920 | | |
3921 | | /// Determine whether this member expression used the '->' |
3922 | | /// operator; otherwise, it used the '.' operator. |
3923 | 352k | bool isArrow() const { return UnresolvedMemberExprBits.IsArrow; } |
3924 | | |
3925 | | /// Retrieve the location of the '->' or '.' operator. |
3926 | 209k | SourceLocation getOperatorLoc() const { return OperatorLoc; } |
3927 | | |
3928 | | /// Retrieve the naming class of this lookup. |
3929 | | CXXRecordDecl *getNamingClass(); |
3930 | 132 | const CXXRecordDecl *getNamingClass() const { |
3931 | 132 | return const_cast<UnresolvedMemberExpr *>(this)->getNamingClass(); |
3932 | 132 | } |
3933 | | |
3934 | | /// Retrieve the full name info for the member that this expression |
3935 | | /// refers to. |
3936 | 726k | const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } |
3937 | | |
3938 | | /// Retrieve the name of the member that this expression refers to. |
3939 | 102k | DeclarationName getMemberName() const { return getName(); } |
3940 | | |
3941 | | /// Retrieve the location of the name of the member that this |
3942 | | /// expression refers to. |
3943 | 133k | SourceLocation getMemberLoc() const { return getNameLoc(); } |
3944 | | |
3945 | | /// Return the preferred location (the member name) for the arrow when |
3946 | | /// diagnosing a problem with this expression. |
3947 | 305 | SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); } |
3948 | | |
3949 | 696k | SourceLocation getBeginLoc() const LLVM_READONLY { |
3950 | 696k | if (!isImplicitAccess()) |
3951 | 120k | return Base->getBeginLoc(); |
3952 | 576k | if (NestedNameSpecifierLoc l = getQualifierLoc()) |
3953 | 14.3k | return l.getBeginLoc(); |
3954 | 561k | return getMemberNameInfo().getBeginLoc(); |
3955 | 576k | } |
3956 | | |
3957 | 69.6k | SourceLocation getEndLoc() const LLVM_READONLY { |
3958 | 69.6k | if (hasExplicitTemplateArgs()) |
3959 | 560 | return getRAngleLoc(); |
3960 | 69.0k | return getMemberNameInfo().getEndLoc(); |
3961 | 69.6k | } |
3962 | | |
3963 | 5.16M | static bool classof(const Stmt *T) { |
3964 | 5.16M | return T->getStmtClass() == UnresolvedMemberExprClass; |
3965 | 5.16M | } |
3966 | | |
3967 | | // Iterators |
3968 | 32.2k | child_range children() { |
3969 | 32.2k | if (isImplicitAccess()) |
3970 | 27.9k | return child_range(child_iterator(), child_iterator()); |
3971 | 4.32k | return child_range(&Base, &Base + 1); |
3972 | 32.2k | } |
3973 | | |
3974 | 0 | const_child_range children() const { |
3975 | 0 | if (isImplicitAccess()) |
3976 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
3977 | 0 | return const_child_range(&Base, &Base + 1); |
3978 | 0 | } |
3979 | | }; |
3980 | | |
3981 | 24.8M | DeclAccessPair *OverloadExpr::getTrailingResults() { |
3982 | 24.8M | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) |
3983 | 22.8M | return ULE->getTrailingObjects<DeclAccessPair>(); |
3984 | 1.97M | return cast<UnresolvedMemberExpr>(this)->getTrailingObjects<DeclAccessPair>(); |
3985 | 24.8M | } |
3986 | | |
3987 | 9.81M | ASTTemplateKWAndArgsInfo *OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() { |
3988 | 9.81M | if (!hasTemplateKWAndArgsInfo()) |
3989 | 0 | return nullptr; |
3990 | | |
3991 | 9.81M | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) |
3992 | 9.73M | return ULE->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); |
3993 | 78.0k | return cast<UnresolvedMemberExpr>(this) |
3994 | 78.0k | ->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); |
3995 | 9.81M | } |
3996 | | |
3997 | 2.37M | TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() { |
3998 | 2.37M | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) |
3999 | 2.34M | return ULE->getTrailingObjects<TemplateArgumentLoc>(); |
4000 | 30.5k | return cast<UnresolvedMemberExpr>(this) |
4001 | 30.5k | ->getTrailingObjects<TemplateArgumentLoc>(); |
4002 | 2.37M | } |
4003 | | |
4004 | 101 | CXXRecordDecl *OverloadExpr::getNamingClass() { |
4005 | 101 | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) |
4006 | 101 | return ULE->getNamingClass(); |
4007 | 0 | return cast<UnresolvedMemberExpr>(this)->getNamingClass(); |
4008 | 101 | } |
4009 | | |
4010 | | /// Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]). |
4011 | | /// |
4012 | | /// The noexcept expression tests whether a given expression might throw. Its |
4013 | | /// result is a boolean constant. |
4014 | | class CXXNoexceptExpr : public Expr { |
4015 | | friend class ASTStmtReader; |
4016 | | |
4017 | | Stmt *Operand; |
4018 | | SourceRange Range; |
4019 | | |
4020 | | public: |
4021 | | CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, |
4022 | | SourceLocation Keyword, SourceLocation RParen) |
4023 | | : Expr(CXXNoexceptExprClass, Ty, VK_PRValue, OK_Ordinary), |
4024 | 15.8k | Operand(Operand), Range(Keyword, RParen) { |
4025 | 15.8k | CXXNoexceptExprBits.Value = Val == CT_Cannot; |
4026 | 15.8k | setDependence(computeDependence(this, Val)); |
4027 | 15.8k | } |
4028 | | |
4029 | 9.39k | CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {} |
4030 | | |
4031 | 21.6k | Expr *getOperand() const { return static_cast<Expr *>(Operand); } |
4032 | | |
4033 | 32.4k | SourceLocation getBeginLoc() const { return Range.getBegin(); } |
4034 | 2.60k | SourceLocation getEndLoc() const { return Range.getEnd(); } |
4035 | 2.23k | SourceRange getSourceRange() const { return Range; } |
4036 | | |
4037 | 3.33k | bool getValue() const { return CXXNoexceptExprBits.Value; } |
4038 | | |
4039 | 5.21k | static bool classof(const Stmt *T) { |
4040 | 5.21k | return T->getStmtClass() == CXXNoexceptExprClass; |
4041 | 5.21k | } |
4042 | | |
4043 | | // Iterators |
4044 | 117k | child_range children() { return child_range(&Operand, &Operand + 1); } |
4045 | | |
4046 | 0 | const_child_range children() const { |
4047 | 0 | return const_child_range(&Operand, &Operand + 1); |
4048 | 0 | } |
4049 | | }; |
4050 | | |
4051 | | /// Represents a C++11 pack expansion that produces a sequence of |
4052 | | /// expressions. |
4053 | | /// |
4054 | | /// A pack expansion expression contains a pattern (which itself is an |
4055 | | /// expression) followed by an ellipsis. For example: |
4056 | | /// |
4057 | | /// \code |
4058 | | /// template<typename F, typename ...Types> |
4059 | | /// void forward(F f, Types &&...args) { |
4060 | | /// f(static_cast<Types&&>(args)...); |
4061 | | /// } |
4062 | | /// \endcode |
4063 | | /// |
4064 | | /// Here, the argument to the function object \c f is a pack expansion whose |
4065 | | /// pattern is \c static_cast<Types&&>(args). When the \c forward function |
4066 | | /// template is instantiated, the pack expansion will instantiate to zero or |
4067 | | /// or more function arguments to the function object \c f. |
4068 | | class PackExpansionExpr : public Expr { |
4069 | | friend class ASTStmtReader; |
4070 | | friend class ASTStmtWriter; |
4071 | | |
4072 | | SourceLocation EllipsisLoc; |
4073 | | |
4074 | | /// The number of expansions that will be produced by this pack |
4075 | | /// expansion expression, if known. |
4076 | | /// |
4077 | | /// When zero, the number of expansions is not known. Otherwise, this value |
4078 | | /// is the number of expansions + 1. |
4079 | | unsigned NumExpansions; |
4080 | | |
4081 | | Stmt *Pattern; |
4082 | | |
4083 | | public: |
4084 | | PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, |
4085 | | Optional<unsigned> NumExpansions) |
4086 | | : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), |
4087 | | Pattern->getObjectKind()), |
4088 | | EllipsisLoc(EllipsisLoc), |
4089 | | NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), |
4090 | 134k | Pattern(Pattern) { |
4091 | 134k | setDependence(computeDependence(this)); |
4092 | 134k | } |
4093 | | |
4094 | 37.2k | PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) {} |
4095 | | |
4096 | | /// Retrieve the pattern of the pack expansion. |
4097 | 219k | Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } |
4098 | | |
4099 | | /// Retrieve the pattern of the pack expansion. |
4100 | 7.29k | const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } |
4101 | | |
4102 | | /// Retrieve the location of the ellipsis that describes this pack |
4103 | | /// expansion. |
4104 | 81.1k | SourceLocation getEllipsisLoc() const { return EllipsisLoc; } |
4105 | | |
4106 | | /// Determine the number of expansions that will be produced when |
4107 | | /// this pack expansion is instantiated, if already known. |
4108 | 74.0k | Optional<unsigned> getNumExpansions() const { |
4109 | 74.0k | if (NumExpansions) |
4110 | 17 | return NumExpansions - 1; |
4111 | | |
4112 | 74.0k | return None; |
4113 | 74.0k | } |
4114 | | |
4115 | 33.3k | SourceLocation getBeginLoc() const LLVM_READONLY { |
4116 | 33.3k | return Pattern->getBeginLoc(); |
4117 | 33.3k | } |
4118 | | |
4119 | 34 | SourceLocation getEndLoc() const LLVM_READONLY { return EllipsisLoc; } |
4120 | | |
4121 | 19.3M | static bool classof(const Stmt *T) { |
4122 | 19.3M | return T->getStmtClass() == PackExpansionExprClass; |
4123 | 19.3M | } |
4124 | | |
4125 | | // Iterators |
4126 | 187k | child_range children() { |
4127 | 187k | return child_range(&Pattern, &Pattern + 1); |
4128 | 187k | } |
4129 | | |
4130 | 0 | const_child_range children() const { |
4131 | 0 | return const_child_range(&Pattern, &Pattern + 1); |
4132 | 0 | } |
4133 | | }; |
4134 | | |
4135 | | /// Represents an expression that computes the length of a parameter |
4136 | | /// pack. |
4137 | | /// |
4138 | | /// \code |
4139 | | /// template<typename ...Types> |
4140 | | /// struct count { |
4141 | | /// static const unsigned value = sizeof...(Types); |
4142 | | /// }; |
4143 | | /// \endcode |
4144 | | class SizeOfPackExpr final |
4145 | | : public Expr, |
4146 | | private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> { |
4147 | | friend class ASTStmtReader; |
4148 | | friend class ASTStmtWriter; |
4149 | | friend TrailingObjects; |
4150 | | |
4151 | | /// The location of the \c sizeof keyword. |
4152 | | SourceLocation OperatorLoc; |
4153 | | |
4154 | | /// The location of the name of the parameter pack. |
4155 | | SourceLocation PackLoc; |
4156 | | |
4157 | | /// The location of the closing parenthesis. |
4158 | | SourceLocation RParenLoc; |
4159 | | |
4160 | | /// The length of the parameter pack, if known. |
4161 | | /// |
4162 | | /// When this expression is not value-dependent, this is the length of |
4163 | | /// the pack. When the expression was parsed rather than instantiated |
4164 | | /// (and thus is value-dependent), this is zero. |
4165 | | /// |
4166 | | /// After partial substitution into a sizeof...(X) expression (for instance, |
4167 | | /// within an alias template or during function template argument deduction), |
4168 | | /// we store a trailing array of partially-substituted TemplateArguments, |
4169 | | /// and this is the length of that array. |
4170 | | unsigned Length; |
4171 | | |
4172 | | /// The parameter pack. |
4173 | | NamedDecl *Pack = nullptr; |
4174 | | |
4175 | | /// Create an expression that computes the length of |
4176 | | /// the given parameter pack. |
4177 | | SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, |
4178 | | SourceLocation PackLoc, SourceLocation RParenLoc, |
4179 | | Optional<unsigned> Length, |
4180 | | ArrayRef<TemplateArgument> PartialArgs) |
4181 | | : Expr(SizeOfPackExprClass, SizeType, VK_PRValue, OK_Ordinary), |
4182 | | OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), |
4183 | 69.8k | Length(Length ? *Length : PartialArgs.size()), Pack(Pack) { |
4184 | 69.8k | assert((!Length || PartialArgs.empty()) && |
4185 | 69.8k | "have partial args for non-dependent sizeof... expression"); |
4186 | 0 | auto *Args = getTrailingObjects<TemplateArgument>(); |
4187 | 69.8k | std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args); |
4188 | 69.8k | setDependence(Length ? ExprDependence::None14.5k |
4189 | 69.8k | : ExprDependence::ValueInstantiation55.2k ); |
4190 | 69.8k | } |
4191 | | |
4192 | | /// Create an empty expression. |
4193 | | SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs) |
4194 | 26.6k | : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {} |
4195 | | |
4196 | | public: |
4197 | | static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc, |
4198 | | NamedDecl *Pack, SourceLocation PackLoc, |
4199 | | SourceLocation RParenLoc, |
4200 | | Optional<unsigned> Length = None, |
4201 | | ArrayRef<TemplateArgument> PartialArgs = None); |
4202 | | static SizeOfPackExpr *CreateDeserialized(ASTContext &Context, |
4203 | | unsigned NumPartialArgs); |
4204 | | |
4205 | | /// Determine the location of the 'sizeof' keyword. |
4206 | 56.2k | SourceLocation getOperatorLoc() const { return OperatorLoc; } |
4207 | | |
4208 | | /// Determine the location of the parameter pack. |
4209 | 91.7k | SourceLocation getPackLoc() const { return PackLoc; } |
4210 | | |
4211 | | /// Determine the location of the right parenthesis. |
4212 | 31.6k | SourceLocation getRParenLoc() const { return RParenLoc; } |
4213 | | |
4214 | | /// Retrieve the parameter pack. |
4215 | 236k | NamedDecl *getPack() const { return Pack; } |
4216 | | |
4217 | | /// Retrieve the length of the parameter pack. |
4218 | | /// |
4219 | | /// This routine may only be invoked when the expression is not |
4220 | | /// value-dependent. |
4221 | 22.6k | unsigned getPackLength() const { |
4222 | 22.6k | assert(!isValueDependent() && |
4223 | 22.6k | "Cannot get the length of a value-dependent pack size expression"); |
4224 | 0 | return Length; |
4225 | 22.6k | } |
4226 | | |
4227 | | /// Determine whether this represents a partially-substituted sizeof... |
4228 | | /// expression, such as is produced for: |
4229 | | /// |
4230 | | /// template<typename ...Ts> using X = int[sizeof...(Ts)]; |
4231 | | /// template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>); |
4232 | 234k | bool isPartiallySubstituted() const { |
4233 | 234k | return isValueDependent() && Length223k ; |
4234 | 234k | } |
4235 | | |
4236 | | /// Get |
4237 | 912 | ArrayRef<TemplateArgument> getPartialArguments() const { |
4238 | 912 | assert(isPartiallySubstituted()); |
4239 | 0 | const auto *Args = getTrailingObjects<TemplateArgument>(); |
4240 | 912 | return llvm::makeArrayRef(Args, Args + Length); |
4241 | 912 | } |
4242 | | |
4243 | 170k | SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; } |
4244 | 24.7k | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
4245 | | |
4246 | 41.8k | static bool classof(const Stmt *T) { |
4247 | 41.8k | return T->getStmtClass() == SizeOfPackExprClass; |
4248 | 41.8k | } |
4249 | | |
4250 | | // Iterators |
4251 | 195k | child_range children() { |
4252 | 195k | return child_range(child_iterator(), child_iterator()); |
4253 | 195k | } |
4254 | | |
4255 | 0 | const_child_range children() const { |
4256 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
4257 | 0 | } |
4258 | | }; |
4259 | | |
4260 | | /// Represents a reference to a non-type template parameter |
4261 | | /// that has been substituted with a template argument. |
4262 | | class SubstNonTypeTemplateParmExpr : public Expr { |
4263 | | friend class ASTReader; |
4264 | | friend class ASTStmtReader; |
4265 | | |
4266 | | /// The replaced parameter and a flag indicating if it was a reference |
4267 | | /// parameter. For class NTTPs, we can't determine that based on the value |
4268 | | /// category alone. |
4269 | | llvm::PointerIntPair<NonTypeTemplateParmDecl*, 1, bool> ParamAndRef; |
4270 | | |
4271 | | /// The replacement expression. |
4272 | | Stmt *Replacement; |
4273 | | |
4274 | | explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) |
4275 | 155k | : Expr(SubstNonTypeTemplateParmExprClass, Empty) {} |
4276 | | |
4277 | | public: |
4278 | | SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind, |
4279 | | SourceLocation Loc, |
4280 | | NonTypeTemplateParmDecl *Param, bool RefParam, |
4281 | | Expr *Replacement) |
4282 | | : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary), |
4283 | 989k | ParamAndRef(Param, RefParam), Replacement(Replacement) { |
4284 | 989k | SubstNonTypeTemplateParmExprBits.NameLoc = Loc; |
4285 | 989k | setDependence(computeDependence(this)); |
4286 | 989k | } |
4287 | | |
4288 | 3.46M | SourceLocation getNameLoc() const { |
4289 | 3.46M | return SubstNonTypeTemplateParmExprBits.NameLoc; |
4290 | 3.46M | } |
4291 | 3.34M | SourceLocation getBeginLoc() const { return getNameLoc(); } |
4292 | 87.5k | SourceLocation getEndLoc() const { return getNameLoc(); } |
4293 | | |
4294 | 5.30M | Expr *getReplacement() const { return cast<Expr>(Replacement); } |
4295 | | |
4296 | 115k | NonTypeTemplateParmDecl *getParameter() const { |
4297 | 115k | return ParamAndRef.getPointer(); |
4298 | 115k | } |
4299 | | |
4300 | 69.5k | bool isReferenceParameter() const { return ParamAndRef.getInt(); } |
4301 | | |
4302 | | /// Determine the substituted type of the template parameter. |
4303 | | QualType getParameterType(const ASTContext &Ctx) const; |
4304 | | |
4305 | 231M | static bool classof(const Stmt *s) { |
4306 | 231M | return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; |
4307 | 231M | } |
4308 | | |
4309 | | // Iterators |
4310 | 867k | child_range children() { return child_range(&Replacement, &Replacement + 1); } |
4311 | | |
4312 | 0 | const_child_range children() const { |
4313 | 0 | return const_child_range(&Replacement, &Replacement + 1); |
4314 | 0 | } |
4315 | | }; |
4316 | | |
4317 | | /// Represents a reference to a non-type template parameter pack that |
4318 | | /// has been substituted with a non-template argument pack. |
4319 | | /// |
4320 | | /// When a pack expansion in the source code contains multiple parameter packs |
4321 | | /// and those parameter packs correspond to different levels of template |
4322 | | /// parameter lists, this node is used to represent a non-type template |
4323 | | /// parameter pack from an outer level, which has already had its argument pack |
4324 | | /// substituted but that still lives within a pack expansion that itself |
4325 | | /// could not be instantiated. When actually performing a substitution into |
4326 | | /// that pack expansion (e.g., when all template parameters have corresponding |
4327 | | /// arguments), this type will be replaced with the appropriate underlying |
4328 | | /// expression at the current pack substitution index. |
4329 | | class SubstNonTypeTemplateParmPackExpr : public Expr { |
4330 | | friend class ASTReader; |
4331 | | friend class ASTStmtReader; |
4332 | | |
4333 | | /// The non-type template parameter pack itself. |
4334 | | NonTypeTemplateParmDecl *Param; |
4335 | | |
4336 | | /// A pointer to the set of template arguments that this |
4337 | | /// parameter pack is instantiated with. |
4338 | | const TemplateArgument *Arguments; |
4339 | | |
4340 | | /// The number of template arguments in \c Arguments. |
4341 | | unsigned NumArguments; |
4342 | | |
4343 | | /// The location of the non-type template parameter pack reference. |
4344 | | SourceLocation NameLoc; |
4345 | | |
4346 | | explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) |
4347 | 0 | : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) {} |
4348 | | |
4349 | | public: |
4350 | | SubstNonTypeTemplateParmPackExpr(QualType T, |
4351 | | ExprValueKind ValueKind, |
4352 | | NonTypeTemplateParmDecl *Param, |
4353 | | SourceLocation NameLoc, |
4354 | | const TemplateArgument &ArgPack); |
4355 | | |
4356 | | /// Retrieve the non-type template parameter pack being substituted. |
4357 | 171 | NonTypeTemplateParmDecl *getParameterPack() const { return Param; } |
4358 | | |
4359 | | /// Retrieve the location of the parameter pack name. |
4360 | 145 | SourceLocation getParameterPackLocation() const { return NameLoc; } |
4361 | | |
4362 | | /// Retrieve the template argument pack containing the substituted |
4363 | | /// template arguments. |
4364 | | TemplateArgument getArgumentPack() const; |
4365 | | |
4366 | 40 | SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; } |
4367 | 1 | SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; } |
4368 | | |
4369 | 5.98k | static bool classof(const Stmt *T) { |
4370 | 5.98k | return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; |
4371 | 5.98k | } |
4372 | | |
4373 | | // Iterators |
4374 | 88 | child_range children() { |
4375 | 88 | return child_range(child_iterator(), child_iterator()); |
4376 | 88 | } |
4377 | | |
4378 | 0 | const_child_range children() const { |
4379 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
4380 | 0 | } |
4381 | | }; |
4382 | | |
4383 | | /// Represents a reference to a function parameter pack or init-capture pack |
4384 | | /// that has been substituted but not yet expanded. |
4385 | | /// |
4386 | | /// When a pack expansion contains multiple parameter packs at different levels, |
4387 | | /// this node is used to represent a function parameter pack at an outer level |
4388 | | /// which we have already substituted to refer to expanded parameters, but where |
4389 | | /// the containing pack expansion cannot yet be expanded. |
4390 | | /// |
4391 | | /// \code |
4392 | | /// template<typename...Ts> struct S { |
4393 | | /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...)); |
4394 | | /// }; |
4395 | | /// template struct S<int, int>; |
4396 | | /// \endcode |
4397 | | class FunctionParmPackExpr final |
4398 | | : public Expr, |
4399 | | private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> { |
4400 | | friend class ASTReader; |
4401 | | friend class ASTStmtReader; |
4402 | | friend TrailingObjects; |
4403 | | |
4404 | | /// The function parameter pack which was referenced. |
4405 | | VarDecl *ParamPack; |
4406 | | |
4407 | | /// The location of the function parameter pack reference. |
4408 | | SourceLocation NameLoc; |
4409 | | |
4410 | | /// The number of expansions of this pack. |
4411 | | unsigned NumParameters; |
4412 | | |
4413 | | FunctionParmPackExpr(QualType T, VarDecl *ParamPack, |
4414 | | SourceLocation NameLoc, unsigned NumParams, |
4415 | | VarDecl *const *Params); |
4416 | | |
4417 | | public: |
4418 | | static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, |
4419 | | VarDecl *ParamPack, |
4420 | | SourceLocation NameLoc, |
4421 | | ArrayRef<VarDecl *> Params); |
4422 | | static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context, |
4423 | | unsigned NumParams); |
4424 | | |
4425 | | /// Get the parameter pack which this expression refers to. |
4426 | 109 | VarDecl *getParameterPack() const { return ParamPack; } |
4427 | | |
4428 | | /// Get the location of the parameter pack. |
4429 | 1.33k | SourceLocation getParameterPackLocation() const { return NameLoc; } |
4430 | | |
4431 | | /// Iterators over the parameters which the parameter pack expanded |
4432 | | /// into. |
4433 | | using iterator = VarDecl * const *; |
4434 | 1.33k | iterator begin() const { return getTrailingObjects<VarDecl *>(); } |
4435 | 641 | iterator end() const { return begin() + NumParameters; } |
4436 | | |
4437 | | /// Get the number of parameters in this parameter pack. |
4438 | 250 | unsigned getNumExpansions() const { return NumParameters; } |
4439 | | |
4440 | | /// Get an expansion of the parameter pack by index. |
4441 | 54 | VarDecl *getExpansion(unsigned I) const { return begin()[I]; } |
4442 | | |
4443 | 201 | SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; } |
4444 | 0 | SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; } |
4445 | | |
4446 | 3.07k | static bool classof(const Stmt *T) { |
4447 | 3.07k | return T->getStmtClass() == FunctionParmPackExprClass; |
4448 | 3.07k | } |
4449 | | |
4450 | 119 | child_range children() { |
4451 | 119 | return child_range(child_iterator(), child_iterator()); |
4452 | 119 | } |
4453 | | |
4454 | 0 | const_child_range children() const { |
4455 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
4456 | 0 | } |
4457 | | }; |
4458 | | |
4459 | | /// Represents a prvalue temporary that is written into memory so that |
4460 | | /// a reference can bind to it. |
4461 | | /// |
4462 | | /// Prvalue expressions are materialized when they need to have an address |
4463 | | /// in memory for a reference to bind to. This happens when binding a |
4464 | | /// reference to the result of a conversion, e.g., |
4465 | | /// |
4466 | | /// \code |
4467 | | /// const int &r = 1.0; |
4468 | | /// \endcode |
4469 | | /// |
4470 | | /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is |
4471 | | /// then materialized via a \c MaterializeTemporaryExpr, and the reference |
4472 | | /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues |
4473 | | /// (either an lvalue or an xvalue, depending on the kind of reference binding |
4474 | | /// to it), maintaining the invariant that references always bind to glvalues. |
4475 | | /// |
4476 | | /// Reference binding and copy-elision can both extend the lifetime of a |
4477 | | /// temporary. When either happens, the expression will also track the |
4478 | | /// declaration which is responsible for the lifetime extension. |
4479 | | class MaterializeTemporaryExpr : public Expr { |
4480 | | private: |
4481 | | friend class ASTStmtReader; |
4482 | | friend class ASTStmtWriter; |
4483 | | |
4484 | | llvm::PointerUnion<Stmt *, LifetimeExtendedTemporaryDecl *> State; |
4485 | | |
4486 | | public: |
4487 | | MaterializeTemporaryExpr(QualType T, Expr *Temporary, |
4488 | | bool BoundToLvalueReference, |
4489 | | LifetimeExtendedTemporaryDecl *MTD = nullptr); |
4490 | | |
4491 | | MaterializeTemporaryExpr(EmptyShell Empty) |
4492 | 14.3k | : Expr(MaterializeTemporaryExprClass, Empty) {} |
4493 | | |
4494 | | /// Retrieve the temporary-generating subexpression whose value will |
4495 | | /// be materialized into a glvalue. |
4496 | 6.39M | Expr *getSubExpr() const { |
4497 | 6.39M | return cast<Expr>( |
4498 | 6.39M | State.is<Stmt *>() |
4499 | 6.39M | ? State.get<Stmt *>()6.36M |
4500 | 6.39M | : State.get<LifetimeExtendedTemporaryDecl *>()->getTemporaryExpr()28.8k ); |
4501 | 6.39M | } |
4502 | | |
4503 | | /// Retrieve the storage duration for the materialized temporary. |
4504 | 279k | StorageDuration getStorageDuration() const { |
4505 | 279k | return State.is<Stmt *>() ? SD_FullExpression269k |
4506 | 279k | : State.get<LifetimeExtendedTemporaryDecl *>() |
4507 | 10.1k | ->getStorageDuration(); |
4508 | 279k | } |
4509 | | |
4510 | | /// Get the storage for the constant value of a materialized temporary |
4511 | | /// of static storage duration. |
4512 | 1.84k | APValue *getOrCreateValue(bool MayCreate) const { |
4513 | 1.84k | assert(State.is<LifetimeExtendedTemporaryDecl *>() && |
4514 | 1.84k | "the temporary has not been lifetime extended"); |
4515 | 0 | return State.get<LifetimeExtendedTemporaryDecl *>()->getOrCreateValue( |
4516 | 1.84k | MayCreate); |
4517 | 1.84k | } |
4518 | | |
4519 | 57.1k | LifetimeExtendedTemporaryDecl *getLifetimeExtendedTemporaryDecl() { |
4520 | 57.1k | return State.dyn_cast<LifetimeExtendedTemporaryDecl *>(); |
4521 | 57.1k | } |
4522 | | const LifetimeExtendedTemporaryDecl * |
4523 | 0 | getLifetimeExtendedTemporaryDecl() const { |
4524 | 0 | return State.dyn_cast<LifetimeExtendedTemporaryDecl *>(); |
4525 | 0 | } |
4526 | | |
4527 | | /// Get the declaration which triggered the lifetime-extension of this |
4528 | | /// temporary, if any. |
4529 | 23.9k | ValueDecl *getExtendingDecl() { |
4530 | 23.9k | return State.is<Stmt *>() ? nullptr21.5k |
4531 | 23.9k | : State.get<LifetimeExtendedTemporaryDecl *>() |
4532 | 2.33k | ->getExtendingDecl(); |
4533 | 23.9k | } |
4534 | 19.8k | const ValueDecl *getExtendingDecl() const { |
4535 | 19.8k | return const_cast<MaterializeTemporaryExpr *>(this)->getExtendingDecl(); |
4536 | 19.8k | } |
4537 | | |
4538 | | void setExtendingDecl(ValueDecl *ExtendedBy, unsigned ManglingNumber); |
4539 | | |
4540 | 239 | unsigned getManglingNumber() const { |
4541 | 239 | return State.is<Stmt *>() ? 00 |
4542 | 239 | : State.get<LifetimeExtendedTemporaryDecl *>() |
4543 | 239 | ->getManglingNumber(); |
4544 | 239 | } |
4545 | | |
4546 | | /// Determine whether this materialized temporary is bound to an |
4547 | | /// lvalue reference; otherwise, it's bound to an rvalue reference. |
4548 | 24.4k | bool isBoundToLvalueReference() const { return isLValue(); } |
4549 | | |
4550 | | /// Determine whether this temporary object is usable in constant |
4551 | | /// expressions, as specified in C++20 [expr.const]p4. |
4552 | | bool isUsableInConstantExpressions(const ASTContext &Context) const; |
4553 | | |
4554 | 471k | SourceLocation getBeginLoc() const LLVM_READONLY { |
4555 | 471k | return getSubExpr()->getBeginLoc(); |
4556 | 471k | } |
4557 | | |
4558 | 187k | SourceLocation getEndLoc() const LLVM_READONLY { |
4559 | 187k | return getSubExpr()->getEndLoc(); |
4560 | 187k | } |
4561 | | |
4562 | 246M | static bool classof(const Stmt *T) { |
4563 | 246M | return T->getStmtClass() == MaterializeTemporaryExprClass; |
4564 | 246M | } |
4565 | | |
4566 | | // Iterators |
4567 | 276k | child_range children() { |
4568 | 276k | return State.is<Stmt *>() |
4569 | 276k | ? child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1)270k |
4570 | 276k | : State.get<LifetimeExtendedTemporaryDecl *>()->childrenExpr()6.64k ; |
4571 | 276k | } |
4572 | | |
4573 | 0 | const_child_range children() const { |
4574 | 0 | return State.is<Stmt *>() |
4575 | 0 | ? const_child_range(State.getAddrOfPtr1(), |
4576 | 0 | State.getAddrOfPtr1() + 1) |
4577 | 0 | : const_cast<const LifetimeExtendedTemporaryDecl *>( |
4578 | 0 | State.get<LifetimeExtendedTemporaryDecl *>()) |
4579 | 0 | ->childrenExpr(); |
4580 | 0 | } |
4581 | | }; |
4582 | | |
4583 | | /// Represents a folding of a pack over an operator. |
4584 | | /// |
4585 | | /// This expression is always dependent and represents a pack expansion of the |
4586 | | /// forms: |
4587 | | /// |
4588 | | /// ( expr op ... ) |
4589 | | /// ( ... op expr ) |
4590 | | /// ( expr op ... op expr ) |
4591 | | class CXXFoldExpr : public Expr { |
4592 | | friend class ASTStmtReader; |
4593 | | friend class ASTStmtWriter; |
4594 | | |
4595 | | enum SubExpr { Callee, LHS, RHS, Count }; |
4596 | | |
4597 | | SourceLocation LParenLoc; |
4598 | | SourceLocation EllipsisLoc; |
4599 | | SourceLocation RParenLoc; |
4600 | | // When 0, the number of expansions is not known. Otherwise, this is one more |
4601 | | // than the number of expansions. |
4602 | | unsigned NumExpansions; |
4603 | | Stmt *SubExprs[SubExpr::Count]; |
4604 | | BinaryOperatorKind Opcode; |
4605 | | |
4606 | | public: |
4607 | | CXXFoldExpr(QualType T, UnresolvedLookupExpr *Callee, |
4608 | | SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Opcode, |
4609 | | SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, |
4610 | | Optional<unsigned> NumExpansions) |
4611 | | : Expr(CXXFoldExprClass, T, VK_PRValue, OK_Ordinary), |
4612 | | LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc), |
4613 | 319 | NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) { |
4614 | 319 | SubExprs[SubExpr::Callee] = Callee; |
4615 | 319 | SubExprs[SubExpr::LHS] = LHS; |
4616 | 319 | SubExprs[SubExpr::RHS] = RHS; |
4617 | 319 | setDependence(computeDependence(this)); |
4618 | 319 | } |
4619 | | |
4620 | 7 | CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {} |
4621 | | |
4622 | 388 | UnresolvedLookupExpr *getCallee() const { |
4623 | 388 | return static_cast<UnresolvedLookupExpr *>(SubExprs[SubExpr::Callee]); |
4624 | 388 | } |
4625 | 3.46k | Expr *getLHS() const { return static_cast<Expr*>(SubExprs[SubExpr::LHS]); } |
4626 | 780 | Expr *getRHS() const { return static_cast<Expr*>(SubExprs[SubExpr::RHS]); } |
4627 | | |
4628 | | /// Does this produce a right-associated sequence of operators? |
4629 | 1.31k | bool isRightFold() const { |
4630 | 1.31k | return getLHS() && getLHS()->containsUnexpandedParameterPack()1.24k ; |
4631 | 1.31k | } |
4632 | | |
4633 | | /// Does this produce a left-associated sequence of operators? |
4634 | 1.24k | bool isLeftFold() const { return !isRightFold(); } |
4635 | | |
4636 | | /// Get the pattern, that is, the operand that contains an unexpanded pack. |
4637 | 372 | Expr *getPattern() const { return isLeftFold() ? getRHS()55 : getLHS()317 ; } |
4638 | | |
4639 | | /// Get the operand that doesn't contain a pack, for a binary fold. |
4640 | 401 | Expr *getInit() const { return isLeftFold() ? getLHS()76 : getRHS()325 ; } |
4641 | | |
4642 | 16 | SourceLocation getLParenLoc() const { return LParenLoc; } |
4643 | 16 | SourceLocation getRParenLoc() const { return RParenLoc; } |
4644 | 1.09k | SourceLocation getEllipsisLoc() const { return EllipsisLoc; } |
4645 | 874 | BinaryOperatorKind getOperator() const { return Opcode; } |
4646 | | |
4647 | 388 | Optional<unsigned> getNumExpansions() const { |
4648 | 388 | if (NumExpansions) |
4649 | 7 | return NumExpansions - 1; |
4650 | 381 | return None; |
4651 | 388 | } |
4652 | | |
4653 | 572 | SourceLocation getBeginLoc() const LLVM_READONLY { |
4654 | 572 | if (LParenLoc.isValid()) |
4655 | 482 | return LParenLoc; |
4656 | 90 | if (isLeftFold()) |
4657 | 0 | return getEllipsisLoc(); |
4658 | 90 | return getLHS()->getBeginLoc(); |
4659 | 90 | } |
4660 | | |
4661 | 190 | SourceLocation getEndLoc() const LLVM_READONLY { |
4662 | 190 | if (RParenLoc.isValid()) |
4663 | 143 | return RParenLoc; |
4664 | 47 | if (isRightFold()) |
4665 | 47 | return getEllipsisLoc(); |
4666 | 0 | return getRHS()->getEndLoc(); |
4667 | 47 | } |
4668 | | |
4669 | 537 | static bool classof(const Stmt *T) { |
4670 | 537 | return T->getStmtClass() == CXXFoldExprClass; |
4671 | 537 | } |
4672 | | |
4673 | | // Iterators |
4674 | 199 | child_range children() { |
4675 | 199 | return child_range(SubExprs, SubExprs + SubExpr::Count); |
4676 | 199 | } |
4677 | | |
4678 | 0 | const_child_range children() const { |
4679 | 0 | return const_child_range(SubExprs, SubExprs + SubExpr::Count); |
4680 | 0 | } |
4681 | | }; |
4682 | | |
4683 | | /// Represents an expression that might suspend coroutine execution; |
4684 | | /// either a co_await or co_yield expression. |
4685 | | /// |
4686 | | /// Evaluation of this expression first evaluates its 'ready' expression. If |
4687 | | /// that returns 'false': |
4688 | | /// -- execution of the coroutine is suspended |
4689 | | /// -- the 'suspend' expression is evaluated |
4690 | | /// -- if the 'suspend' expression returns 'false', the coroutine is |
4691 | | /// resumed |
4692 | | /// -- otherwise, control passes back to the resumer. |
4693 | | /// If the coroutine is not suspended, or when it is resumed, the 'resume' |
4694 | | /// expression is evaluated, and its result is the result of the overall |
4695 | | /// expression. |
4696 | | class CoroutineSuspendExpr : public Expr { |
4697 | | friend class ASTStmtReader; |
4698 | | |
4699 | | SourceLocation KeywordLoc; |
4700 | | |
4701 | | enum SubExpr { Operand, Common, Ready, Suspend, Resume, Count }; |
4702 | | |
4703 | | Stmt *SubExprs[SubExpr::Count]; |
4704 | | OpaqueValueExpr *OpaqueValue = nullptr; |
4705 | | |
4706 | | public: |
4707 | | CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand, |
4708 | | Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume, |
4709 | | OpaqueValueExpr *OpaqueValue) |
4710 | | : Expr(SC, Resume->getType(), Resume->getValueKind(), |
4711 | | Resume->getObjectKind()), |
4712 | 2.25k | KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) { |
4713 | 2.25k | SubExprs[SubExpr::Operand] = Operand; |
4714 | 2.25k | SubExprs[SubExpr::Common] = Common; |
4715 | 2.25k | SubExprs[SubExpr::Ready] = Ready; |
4716 | 2.25k | SubExprs[SubExpr::Suspend] = Suspend; |
4717 | 2.25k | SubExprs[SubExpr::Resume] = Resume; |
4718 | 2.25k | setDependence(computeDependence(this)); |
4719 | 2.25k | } |
4720 | | |
4721 | | CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty, |
4722 | | Expr *Operand, Expr *Common) |
4723 | 576 | : Expr(SC, Ty, VK_PRValue, OK_Ordinary), KeywordLoc(KeywordLoc) { |
4724 | 576 | assert(Common->isTypeDependent() && Ty->isDependentType() && |
4725 | 576 | "wrong constructor for non-dependent co_await/co_yield expression"); |
4726 | 0 | SubExprs[SubExpr::Operand] = Operand; |
4727 | 576 | SubExprs[SubExpr::Common] = Common; |
4728 | 576 | SubExprs[SubExpr::Ready] = nullptr; |
4729 | 576 | SubExprs[SubExpr::Suspend] = nullptr; |
4730 | 576 | SubExprs[SubExpr::Resume] = nullptr; |
4731 | 576 | setDependence(computeDependence(this)); |
4732 | 576 | } |
4733 | | |
4734 | 11 | CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) { |
4735 | 11 | SubExprs[SubExpr::Operand] = nullptr; |
4736 | 11 | SubExprs[SubExpr::Common] = nullptr; |
4737 | 11 | SubExprs[SubExpr::Ready] = nullptr; |
4738 | 11 | SubExprs[SubExpr::Suspend] = nullptr; |
4739 | 11 | SubExprs[SubExpr::Resume] = nullptr; |
4740 | 11 | } |
4741 | | |
4742 | 3.14k | Expr *getCommonExpr() const { |
4743 | 3.14k | return static_cast<Expr*>(SubExprs[SubExpr::Common]); |
4744 | 3.14k | } |
4745 | | |
4746 | | /// getOpaqueValue - Return the opaque value placeholder. |
4747 | 303 | OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } |
4748 | | |
4749 | 319 | Expr *getReadyExpr() const { |
4750 | 319 | return static_cast<Expr*>(SubExprs[SubExpr::Ready]); |
4751 | 319 | } |
4752 | | |
4753 | 319 | Expr *getSuspendExpr() const { |
4754 | 319 | return static_cast<Expr*>(SubExprs[SubExpr::Suspend]); |
4755 | 319 | } |
4756 | | |
4757 | 4.15k | Expr *getResumeExpr() const { |
4758 | 4.15k | return static_cast<Expr*>(SubExprs[SubExpr::Resume]); |
4759 | 4.15k | } |
4760 | | |
4761 | | // The syntactic operand written in the code |
4762 | 11.8k | Expr *getOperand() const { |
4763 | 11.8k | return static_cast<Expr *>(SubExprs[SubExpr::Operand]); |
4764 | 11.8k | } |
4765 | | |
4766 | 1.12k | SourceLocation getKeywordLoc() const { return KeywordLoc; } |
4767 | | |
4768 | 7.37k | SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; } |
4769 | | |
4770 | 102 | SourceLocation getEndLoc() const LLVM_READONLY { |
4771 | 102 | return getOperand()->getEndLoc(); |
4772 | 102 | } |
4773 | | |
4774 | 6.08k | child_range children() { |
4775 | 6.08k | return child_range(SubExprs, SubExprs + SubExpr::Count); |
4776 | 6.08k | } |
4777 | | |
4778 | 0 | const_child_range children() const { |
4779 | 0 | return const_child_range(SubExprs, SubExprs + SubExpr::Count); |
4780 | 0 | } |
4781 | | |
4782 | 21.3M | static bool classof(const Stmt *T) { |
4783 | 21.3M | return T->getStmtClass() == CoawaitExprClass || |
4784 | 21.3M | T->getStmtClass() == CoyieldExprClass21.3M ; |
4785 | 21.3M | } |
4786 | | }; |
4787 | | |
4788 | | /// Represents a 'co_await' expression. |
4789 | | class CoawaitExpr : public CoroutineSuspendExpr { |
4790 | | friend class ASTStmtReader; |
4791 | | |
4792 | | public: |
4793 | | CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Common, |
4794 | | Expr *Ready, Expr *Suspend, Expr *Resume, |
4795 | | OpaqueValueExpr *OpaqueValue, bool IsImplicit = false) |
4796 | | : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Common, |
4797 | 1.99k | Ready, Suspend, Resume, OpaqueValue) { |
4798 | 1.99k | CoawaitBits.IsImplicit = IsImplicit; |
4799 | 1.99k | } |
4800 | | |
4801 | | CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand, |
4802 | | Expr *Common, bool IsImplicit = false) |
4803 | | : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand, |
4804 | 478 | Common) { |
4805 | 478 | CoawaitBits.IsImplicit = IsImplicit; |
4806 | 478 | } |
4807 | | |
4808 | | CoawaitExpr(EmptyShell Empty) |
4809 | 10 | : CoroutineSuspendExpr(CoawaitExprClass, Empty) {} |
4810 | | |
4811 | 518 | bool isImplicit() const { return CoawaitBits.IsImplicit; } |
4812 | 10 | void setIsImplicit(bool value = true) { CoawaitBits.IsImplicit = value; } |
4813 | | |
4814 | 516 | static bool classof(const Stmt *T) { |
4815 | 516 | return T->getStmtClass() == CoawaitExprClass; |
4816 | 516 | } |
4817 | | }; |
4818 | | |
4819 | | /// Represents a 'co_await' expression while the type of the promise |
4820 | | /// is dependent. |
4821 | | class DependentCoawaitExpr : public Expr { |
4822 | | friend class ASTStmtReader; |
4823 | | |
4824 | | SourceLocation KeywordLoc; |
4825 | | Stmt *SubExprs[2]; |
4826 | | |
4827 | | public: |
4828 | | DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op, |
4829 | | UnresolvedLookupExpr *OpCoawait) |
4830 | | : Expr(DependentCoawaitExprClass, Ty, VK_PRValue, OK_Ordinary), |
4831 | 111 | KeywordLoc(KeywordLoc) { |
4832 | | // NOTE: A co_await expression is dependent on the coroutines promise |
4833 | | // type and may be dependent even when the `Op` expression is not. |
4834 | 111 | assert(Ty->isDependentType() && |
4835 | 111 | "wrong constructor for non-dependent co_await/co_yield expression"); |
4836 | 0 | SubExprs[0] = Op; |
4837 | 111 | SubExprs[1] = OpCoawait; |
4838 | 111 | setDependence(computeDependence(this)); |
4839 | 111 | } |
4840 | | |
4841 | | DependentCoawaitExpr(EmptyShell Empty) |
4842 | 1 | : Expr(DependentCoawaitExprClass, Empty) {} |
4843 | | |
4844 | 225 | Expr *getOperand() const { return cast<Expr>(SubExprs[0]); } |
4845 | | |
4846 | 114 | UnresolvedLookupExpr *getOperatorCoawaitLookup() const { |
4847 | 114 | return cast<UnresolvedLookupExpr>(SubExprs[1]); |
4848 | 114 | } |
4849 | | |
4850 | 116 | SourceLocation getKeywordLoc() const { return KeywordLoc; } |
4851 | | |
4852 | 215 | SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; } |
4853 | | |
4854 | 0 | SourceLocation getEndLoc() const LLVM_READONLY { |
4855 | 0 | return getOperand()->getEndLoc(); |
4856 | 0 | } |
4857 | | |
4858 | 4 | child_range children() { return child_range(SubExprs, SubExprs + 2); } |
4859 | | |
4860 | 0 | const_child_range children() const { |
4861 | 0 | return const_child_range(SubExprs, SubExprs + 2); |
4862 | 0 | } |
4863 | | |
4864 | 114 | static bool classof(const Stmt *T) { |
4865 | 114 | return T->getStmtClass() == DependentCoawaitExprClass; |
4866 | 114 | } |
4867 | | }; |
4868 | | |
4869 | | /// Represents a 'co_yield' expression. |
4870 | | class CoyieldExpr : public CoroutineSuspendExpr { |
4871 | | friend class ASTStmtReader; |
4872 | | |
4873 | | public: |
4874 | | CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Common, |
4875 | | Expr *Ready, Expr *Suspend, Expr *Resume, |
4876 | | OpaqueValueExpr *OpaqueValue) |
4877 | | : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Common, |
4878 | 258 | Ready, Suspend, Resume, OpaqueValue) {} |
4879 | | CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand, |
4880 | | Expr *Common) |
4881 | | : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand, |
4882 | 98 | Common) {} |
4883 | | CoyieldExpr(EmptyShell Empty) |
4884 | 1 | : CoroutineSuspendExpr(CoyieldExprClass, Empty) {} |
4885 | | |
4886 | 112 | static bool classof(const Stmt *T) { |
4887 | 112 | return T->getStmtClass() == CoyieldExprClass; |
4888 | 112 | } |
4889 | | }; |
4890 | | |
4891 | | /// Represents a C++2a __builtin_bit_cast(T, v) expression. Used to implement |
4892 | | /// std::bit_cast. These can sometimes be evaluated as part of a constant |
4893 | | /// expression, but otherwise CodeGen to a simple memcpy in general. |
4894 | | class BuiltinBitCastExpr final |
4895 | | : public ExplicitCastExpr, |
4896 | | private llvm::TrailingObjects<BuiltinBitCastExpr, CXXBaseSpecifier *> { |
4897 | | friend class ASTStmtReader; |
4898 | | friend class CastExpr; |
4899 | | friend TrailingObjects; |
4900 | | |
4901 | | SourceLocation KWLoc; |
4902 | | SourceLocation RParenLoc; |
4903 | | |
4904 | | public: |
4905 | | BuiltinBitCastExpr(QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr, |
4906 | | TypeSourceInfo *DstType, SourceLocation KWLoc, |
4907 | | SourceLocation RParenLoc) |
4908 | | : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0, false, |
4909 | | DstType), |
4910 | 797 | KWLoc(KWLoc), RParenLoc(RParenLoc) {} |
4911 | | BuiltinBitCastExpr(EmptyShell Empty) |
4912 | 1 | : ExplicitCastExpr(BuiltinBitCastExprClass, Empty, 0, false) {} |
4913 | | |
4914 | 3.78k | SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; } |
4915 | 305 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
4916 | | |
4917 | 85 | static bool classof(const Stmt *T) { |
4918 | 85 | return T->getStmtClass() == BuiltinBitCastExprClass; |
4919 | 85 | } |
4920 | | }; |
4921 | | |
4922 | | } // namespace clang |
4923 | | |
4924 | | #endif // LLVM_CLANG_AST_EXPRCXX_H |