/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/Expr.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- Expr.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 | | // This file defines the Expr interface and subclasses. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef LLVM_CLANG_AST_EXPR_H |
14 | | #define LLVM_CLANG_AST_EXPR_H |
15 | | |
16 | | #include "clang/AST/APValue.h" |
17 | | #include "clang/AST/ASTVector.h" |
18 | | #include "clang/AST/ComputeDependence.h" |
19 | | #include "clang/AST/Decl.h" |
20 | | #include "clang/AST/DeclAccessPair.h" |
21 | | #include "clang/AST/DependenceFlags.h" |
22 | | #include "clang/AST/OperationKinds.h" |
23 | | #include "clang/AST/Stmt.h" |
24 | | #include "clang/AST/TemplateBase.h" |
25 | | #include "clang/AST/Type.h" |
26 | | #include "clang/Basic/CharInfo.h" |
27 | | #include "clang/Basic/LangOptions.h" |
28 | | #include "clang/Basic/SyncScope.h" |
29 | | #include "clang/Basic/TypeTraits.h" |
30 | | #include "llvm/ADT/APFloat.h" |
31 | | #include "llvm/ADT/APSInt.h" |
32 | | #include "llvm/ADT/SmallVector.h" |
33 | | #include "llvm/ADT/StringRef.h" |
34 | | #include "llvm/ADT/iterator.h" |
35 | | #include "llvm/ADT/iterator_range.h" |
36 | | #include "llvm/Support/AtomicOrdering.h" |
37 | | #include "llvm/Support/Compiler.h" |
38 | | #include "llvm/Support/TrailingObjects.h" |
39 | | |
40 | | namespace clang { |
41 | | class APValue; |
42 | | class ASTContext; |
43 | | class BlockDecl; |
44 | | class CXXBaseSpecifier; |
45 | | class CXXMemberCallExpr; |
46 | | class CXXOperatorCallExpr; |
47 | | class CastExpr; |
48 | | class Decl; |
49 | | class IdentifierInfo; |
50 | | class MaterializeTemporaryExpr; |
51 | | class NamedDecl; |
52 | | class ObjCPropertyRefExpr; |
53 | | class OpaqueValueExpr; |
54 | | class ParmVarDecl; |
55 | | class StringLiteral; |
56 | | class TargetInfo; |
57 | | class ValueDecl; |
58 | | |
59 | | /// A simple array of base specifiers. |
60 | | typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; |
61 | | |
62 | | /// An adjustment to be made to the temporary created when emitting a |
63 | | /// reference binding, which accesses a particular subobject of that temporary. |
64 | | struct SubobjectAdjustment { |
65 | | enum { |
66 | | DerivedToBaseAdjustment, |
67 | | FieldAdjustment, |
68 | | MemberPointerAdjustment |
69 | | } Kind; |
70 | | |
71 | | struct DTB { |
72 | | const CastExpr *BasePath; |
73 | | const CXXRecordDecl *DerivedClass; |
74 | | }; |
75 | | |
76 | | struct P { |
77 | | const MemberPointerType *MPT; |
78 | | Expr *RHS; |
79 | | }; |
80 | | |
81 | | union { |
82 | | struct DTB DerivedToBase; |
83 | | FieldDecl *Field; |
84 | | struct P Ptr; |
85 | | }; |
86 | | |
87 | | SubobjectAdjustment(const CastExpr *BasePath, |
88 | | const CXXRecordDecl *DerivedClass) |
89 | 4.24k | : Kind(DerivedToBaseAdjustment) { |
90 | 4.24k | DerivedToBase.BasePath = BasePath; |
91 | 4.24k | DerivedToBase.DerivedClass = DerivedClass; |
92 | 4.24k | } |
93 | | |
94 | | SubobjectAdjustment(FieldDecl *Field) |
95 | 59.7k | : Kind(FieldAdjustment) { |
96 | 59.7k | this->Field = Field; |
97 | 59.7k | } |
98 | | |
99 | | SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS) |
100 | 118 | : Kind(MemberPointerAdjustment) { |
101 | 118 | this->Ptr.MPT = MPT; |
102 | 118 | this->Ptr.RHS = RHS; |
103 | 118 | } |
104 | | }; |
105 | | |
106 | | /// This represents one expression. Note that Expr's are subclasses of Stmt. |
107 | | /// This allows an expression to be transparently used any place a Stmt is |
108 | | /// required. |
109 | | class Expr : public ValueStmt { |
110 | | QualType TR; |
111 | | |
112 | | public: |
113 | | Expr() = delete; |
114 | | Expr(const Expr&) = delete; |
115 | | Expr(Expr &&) = delete; |
116 | | Expr &operator=(const Expr&) = delete; |
117 | | Expr &operator=(Expr&&) = delete; |
118 | | |
119 | | protected: |
120 | | Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK) |
121 | 120M | : ValueStmt(SC) { |
122 | 120M | ExprBits.Dependent = 0; |
123 | 120M | ExprBits.ValueKind = VK; |
124 | 120M | ExprBits.ObjectKind = OK; |
125 | 120M | assert(ExprBits.ObjectKind == OK && "truncated kind"); |
126 | 0 | setType(T); |
127 | 120M | } |
128 | | |
129 | | /// Construct an empty expression. |
130 | 10.4M | explicit Expr(StmtClass SC, EmptyShell) : ValueStmt(SC) { } |
131 | | |
132 | | /// Each concrete expr subclass is expected to compute its dependence and call |
133 | | /// this in the constructor. |
134 | 146M | void setDependence(ExprDependence Deps) { |
135 | 146M | ExprBits.Dependent = static_cast<unsigned>(Deps); |
136 | 146M | } |
137 | | friend class ASTImporter; // Sets dependence dircetly. |
138 | | friend class ASTStmtReader; // Sets dependence dircetly. |
139 | | |
140 | | public: |
141 | 1.25G | QualType getType() const { return TR; } |
142 | 137M | void setType(QualType t) { |
143 | | // In C++, the type of an expression is always adjusted so that it |
144 | | // will not have reference type (C++ [expr]p6). Use |
145 | | // QualType::getNonReferenceType() to retrieve the non-reference |
146 | | // type. Additionally, inspect Expr::isLvalue to determine whether |
147 | | // an expression that is adjusted in this manner should be |
148 | | // considered an lvalue. |
149 | 137M | assert((t.isNull() || !t->isReferenceType()) && |
150 | 137M | "Expressions can't have reference type"); |
151 | | |
152 | 0 | TR = t; |
153 | 137M | } |
154 | | |
155 | 613M | ExprDependence getDependence() const { |
156 | 613M | return static_cast<ExprDependence>(ExprBits.Dependent); |
157 | 613M | } |
158 | | |
159 | | /// Determines whether the value of this expression depends on |
160 | | /// - a template parameter (C++ [temp.dep.constexpr]) |
161 | | /// - or an error, whose resolution is unknown |
162 | | /// |
163 | | /// For example, the array bound of "Chars" in the following example is |
164 | | /// value-dependent. |
165 | | /// @code |
166 | | /// template<int Size, char (&Chars)[Size]> struct meta_string; |
167 | | /// @endcode |
168 | 258M | bool isValueDependent() const { |
169 | 258M | return static_cast<bool>(getDependence() & ExprDependence::Value); |
170 | 258M | } |
171 | | |
172 | | /// Determines whether the type of this expression depends on |
173 | | /// - a template paramter (C++ [temp.dep.expr], which means that its type |
174 | | /// could change from one template instantiation to the next) |
175 | | /// - or an error |
176 | | /// |
177 | | /// For example, the expressions "x" and "x + y" are type-dependent in |
178 | | /// the following code, but "y" is not type-dependent: |
179 | | /// @code |
180 | | /// template<typename T> |
181 | | /// void add(T x, int y) { |
182 | | /// x + y; |
183 | | /// } |
184 | | /// @endcode |
185 | 167M | bool isTypeDependent() const { |
186 | 167M | return static_cast<bool>(getDependence() & ExprDependence::Type); |
187 | 167M | } |
188 | | |
189 | | /// Whether this expression is instantiation-dependent, meaning that |
190 | | /// it depends in some way on |
191 | | /// - a template parameter (even if neither its type nor (constant) value |
192 | | /// can change due to the template instantiation) |
193 | | /// - or an error |
194 | | /// |
195 | | /// In the following example, the expression \c sizeof(sizeof(T() + T())) is |
196 | | /// instantiation-dependent (since it involves a template parameter \c T), but |
197 | | /// is neither type- nor value-dependent, since the type of the inner |
198 | | /// \c sizeof is known (\c std::size_t) and therefore the size of the outer |
199 | | /// \c sizeof is known. |
200 | | /// |
201 | | /// \code |
202 | | /// template<typename T> |
203 | | /// void f(T x, T y) { |
204 | | /// sizeof(sizeof(T() + T()); |
205 | | /// } |
206 | | /// \endcode |
207 | | /// |
208 | | /// \code |
209 | | /// void func(int) { |
210 | | /// func(); // the expression is instantiation-dependent, because it depends |
211 | | /// // on an error. |
212 | | /// } |
213 | | /// \endcode |
214 | 16.8M | bool isInstantiationDependent() const { |
215 | 16.8M | return static_cast<bool>(getDependence() & ExprDependence::Instantiation); |
216 | 16.8M | } |
217 | | |
218 | | /// Whether this expression contains an unexpanded parameter |
219 | | /// pack (for C++11 variadic templates). |
220 | | /// |
221 | | /// Given the following function template: |
222 | | /// |
223 | | /// \code |
224 | | /// template<typename F, typename ...Types> |
225 | | /// void forward(const F &f, Types &&...args) { |
226 | | /// f(static_cast<Types&&>(args)...); |
227 | | /// } |
228 | | /// \endcode |
229 | | /// |
230 | | /// The expressions \c args and \c static_cast<Types&&>(args) both |
231 | | /// contain parameter packs. |
232 | 27.9M | bool containsUnexpandedParameterPack() const { |
233 | 27.9M | return static_cast<bool>(getDependence() & ExprDependence::UnexpandedPack); |
234 | 27.9M | } |
235 | | |
236 | | /// Whether this expression contains subexpressions which had errors, e.g. a |
237 | | /// TypoExpr. |
238 | 19.6M | bool containsErrors() const { |
239 | 19.6M | return static_cast<bool>(getDependence() & ExprDependence::Error); |
240 | 19.6M | } |
241 | | |
242 | | /// getExprLoc - Return the preferred location for the arrow when diagnosing |
243 | | /// a problem with a generic expression. |
244 | | SourceLocation getExprLoc() const LLVM_READONLY; |
245 | | |
246 | | /// Determine whether an lvalue-to-rvalue conversion should implicitly be |
247 | | /// applied to this expression if it appears as a discarded-value expression |
248 | | /// in C++11 onwards. This applies to certain forms of volatile glvalues. |
249 | | bool isReadIfDiscardedInCPlusPlus11() const; |
250 | | |
251 | | /// isUnusedResultAWarning - Return true if this immediate expression should |
252 | | /// be warned about if the result is unused. If so, fill in expr, location, |
253 | | /// and ranges with expr to warn on and source locations/ranges appropriate |
254 | | /// for a warning. |
255 | | bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc, |
256 | | SourceRange &R1, SourceRange &R2, |
257 | | ASTContext &Ctx) const; |
258 | | |
259 | | /// isLValue - True if this expression is an "l-value" according to |
260 | | /// the rules of the current language. C and C++ give somewhat |
261 | | /// different rules for this concept, but in general, the result of |
262 | | /// an l-value expression identifies a specific object whereas the |
263 | | /// result of an r-value expression is a value detached from any |
264 | | /// specific storage. |
265 | | /// |
266 | | /// C++11 divides the concept of "r-value" into pure r-values |
267 | | /// ("pr-values") and so-called expiring values ("x-values"), which |
268 | | /// identify specific objects that can be safely cannibalized for |
269 | | /// their resources. |
270 | 11.0M | bool isLValue() const { return getValueKind() == VK_LValue; } |
271 | 62.1M | bool isPRValue() const { return getValueKind() == VK_PRValue; } |
272 | 764k | bool isXValue() const { return getValueKind() == VK_XValue; } |
273 | 124M | bool isGLValue() const { return getValueKind() != VK_PRValue; } |
274 | | |
275 | | enum LValueClassification { |
276 | | LV_Valid, |
277 | | LV_NotObjectType, |
278 | | LV_IncompleteVoidType, |
279 | | LV_DuplicateVectorComponents, |
280 | | LV_InvalidExpression, |
281 | | LV_InvalidMessageExpression, |
282 | | LV_MemberFunction, |
283 | | LV_SubObjCPropertySetting, |
284 | | LV_ClassTemporary, |
285 | | LV_ArrayTemporary |
286 | | }; |
287 | | /// Reasons why an expression might not be an l-value. |
288 | | LValueClassification ClassifyLValue(ASTContext &Ctx) const; |
289 | | |
290 | | enum isModifiableLvalueResult { |
291 | | MLV_Valid, |
292 | | MLV_NotObjectType, |
293 | | MLV_IncompleteVoidType, |
294 | | MLV_DuplicateVectorComponents, |
295 | | MLV_InvalidExpression, |
296 | | MLV_LValueCast, // Specialized form of MLV_InvalidExpression. |
297 | | MLV_IncompleteType, |
298 | | MLV_ConstQualified, |
299 | | MLV_ConstQualifiedField, |
300 | | MLV_ConstAddrSpace, |
301 | | MLV_ArrayType, |
302 | | MLV_NoSetterProperty, |
303 | | MLV_MemberFunction, |
304 | | MLV_SubObjCPropertySetting, |
305 | | MLV_InvalidMessageExpression, |
306 | | MLV_ClassTemporary, |
307 | | MLV_ArrayTemporary |
308 | | }; |
309 | | /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, |
310 | | /// does not have an incomplete type, does not have a const-qualified type, |
311 | | /// and if it is a structure or union, does not have any member (including, |
312 | | /// recursively, any member or element of all contained aggregates or unions) |
313 | | /// with a const-qualified type. |
314 | | /// |
315 | | /// \param Loc [in,out] - A source location which *may* be filled |
316 | | /// in with the location of the expression making this a |
317 | | /// non-modifiable lvalue, if specified. |
318 | | isModifiableLvalueResult |
319 | | isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc = nullptr) const; |
320 | | |
321 | | /// The return type of classify(). Represents the C++11 expression |
322 | | /// taxonomy. |
323 | | class Classification { |
324 | | public: |
325 | | /// The various classification results. Most of these mean prvalue. |
326 | | enum Kinds { |
327 | | CL_LValue, |
328 | | CL_XValue, |
329 | | CL_Function, // Functions cannot be lvalues in C. |
330 | | CL_Void, // Void cannot be an lvalue in C. |
331 | | CL_AddressableVoid, // Void expression whose address can be taken in C. |
332 | | CL_DuplicateVectorComponents, // A vector shuffle with dupes. |
333 | | CL_MemberFunction, // An expression referring to a member function |
334 | | CL_SubObjCPropertySetting, |
335 | | CL_ClassTemporary, // A temporary of class type, or subobject thereof. |
336 | | CL_ArrayTemporary, // A temporary of array type. |
337 | | CL_ObjCMessageRValue, // ObjC message is an rvalue |
338 | | CL_PRValue // A prvalue for any other reason, of any other type |
339 | | }; |
340 | | /// The results of modification testing. |
341 | | enum ModifiableType { |
342 | | CM_Untested, // testModifiable was false. |
343 | | CM_Modifiable, |
344 | | CM_RValue, // Not modifiable because it's an rvalue |
345 | | CM_Function, // Not modifiable because it's a function; C++ only |
346 | | CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext |
347 | | CM_NoSetterProperty,// Implicit assignment to ObjC property without setter |
348 | | CM_ConstQualified, |
349 | | CM_ConstQualifiedField, |
350 | | CM_ConstAddrSpace, |
351 | | CM_ArrayType, |
352 | | CM_IncompleteType |
353 | | }; |
354 | | |
355 | | private: |
356 | | friend class Expr; |
357 | | |
358 | | unsigned short Kind; |
359 | | unsigned short Modifiable; |
360 | | |
361 | | explicit Classification(Kinds k, ModifiableType m) |
362 | | : Kind(k), Modifiable(m) |
363 | 10.7M | {} |
364 | | |
365 | | public: |
366 | 916k | Classification() {} |
367 | | |
368 | 4.53M | Kinds getKind() const { return static_cast<Kinds>(Kind); } |
369 | 2.21M | ModifiableType getModifiable() const { |
370 | 2.21M | assert(Modifiable != CM_Untested && "Did not test for modifiability."); |
371 | 0 | return static_cast<ModifiableType>(Modifiable); |
372 | 2.21M | } |
373 | 6.46M | bool isLValue() const { return Kind == CL_LValue; } |
374 | 782k | bool isXValue() const { return Kind == CL_XValue; } |
375 | 0 | bool isGLValue() const { return Kind <= CL_XValue; } |
376 | 837k | bool isPRValue() const { return Kind >= CL_Function; } |
377 | 6.87M | bool isRValue() const { return Kind >= CL_XValue; } |
378 | 0 | bool isModifiable() const { return getModifiable() == CM_Modifiable; } |
379 | | |
380 | | /// Create a simple, modifiably lvalue |
381 | 288k | static Classification makeSimpleLValue() { |
382 | 288k | return Classification(CL_LValue, CM_Modifiable); |
383 | 288k | } |
384 | | |
385 | | }; |
386 | | /// Classify - Classify this expression according to the C++11 |
387 | | /// expression taxonomy. |
388 | | /// |
389 | | /// C++11 defines ([basic.lval]) a new taxonomy of expressions to replace the |
390 | | /// old lvalue vs rvalue. This function determines the type of expression this |
391 | | /// is. There are three expression types: |
392 | | /// - lvalues are classical lvalues as in C++03. |
393 | | /// - prvalues are equivalent to rvalues in C++03. |
394 | | /// - xvalues are expressions yielding unnamed rvalue references, e.g. a |
395 | | /// function returning an rvalue reference. |
396 | | /// lvalues and xvalues are collectively referred to as glvalues, while |
397 | | /// prvalues and xvalues together form rvalues. |
398 | 8.29M | Classification Classify(ASTContext &Ctx) const { |
399 | 8.29M | return ClassifyImpl(Ctx, nullptr); |
400 | 8.29M | } |
401 | | |
402 | | /// ClassifyModifiable - Classify this expression according to the |
403 | | /// C++11 expression taxonomy, and see if it is valid on the left side |
404 | | /// of an assignment. |
405 | | /// |
406 | | /// This function extends classify in that it also tests whether the |
407 | | /// expression is modifiable (C99 6.3.2.1p1). |
408 | | /// \param Loc A source location that might be filled with a relevant location |
409 | | /// if the expression is not modifiable. |
410 | 2.21M | Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ |
411 | 2.21M | return ClassifyImpl(Ctx, &Loc); |
412 | 2.21M | } |
413 | | |
414 | | /// Returns the set of floating point options that apply to this expression. |
415 | | /// Only meaningful for operations on floating point values. |
416 | | FPOptions getFPFeaturesInEffect(const LangOptions &LO) const; |
417 | | |
418 | | /// getValueKindForType - Given a formal return or parameter type, |
419 | | /// give its value kind. |
420 | 9.83M | static ExprValueKind getValueKindForType(QualType T) { |
421 | 9.83M | if (const ReferenceType *RT = T->getAs<ReferenceType>()) |
422 | 515k | return (isa<LValueReferenceType>(RT) |
423 | 515k | ? VK_LValue262k |
424 | 515k | : (252k RT->getPointeeType()->isFunctionType()252k |
425 | 252k | ? VK_LValue11 : VK_XValue252k )); |
426 | 9.31M | return VK_PRValue; |
427 | 9.83M | } |
428 | | |
429 | | /// getValueKind - The value kind that this expression produces. |
430 | 233M | ExprValueKind getValueKind() const { |
431 | 233M | return static_cast<ExprValueKind>(ExprBits.ValueKind); |
432 | 233M | } |
433 | | |
434 | | /// getObjectKind - The object kind that this expression produces. |
435 | | /// Object kinds are meaningful only for expressions that yield an |
436 | | /// l-value or x-value. |
437 | 29.8M | ExprObjectKind getObjectKind() const { |
438 | 29.8M | return static_cast<ExprObjectKind>(ExprBits.ObjectKind); |
439 | 29.8M | } |
440 | | |
441 | 36.2k | bool isOrdinaryOrBitFieldObject() const { |
442 | 36.2k | ExprObjectKind OK = getObjectKind(); |
443 | 36.2k | return (OK == OK_Ordinary || OK == OK_BitField60 ); |
444 | 36.2k | } |
445 | | |
446 | | /// setValueKind - Set the value kind produced by this expression. |
447 | 22.4M | void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } |
448 | | |
449 | | /// setObjectKind - Set the object kind produced by this expression. |
450 | 18.9M | void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } |
451 | | |
452 | | private: |
453 | | Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; |
454 | | |
455 | | public: |
456 | | |
457 | | /// Returns true if this expression is a gl-value that |
458 | | /// potentially refers to a bit-field. |
459 | | /// |
460 | | /// In C++, whether a gl-value refers to a bitfield is essentially |
461 | | /// an aspect of the value-kind type system. |
462 | 376k | bool refersToBitField() const { return getObjectKind() == OK_BitField; } |
463 | | |
464 | | /// If this expression refers to a bit-field, retrieve the |
465 | | /// declaration of that bit-field. |
466 | | /// |
467 | | /// Note that this returns a non-null pointer in subtly different |
468 | | /// places than refersToBitField returns true. In particular, this can |
469 | | /// return a non-null pointer even for r-values loaded from |
470 | | /// bit-fields, but it will return null for a conditional bit-field. |
471 | | FieldDecl *getSourceBitField(); |
472 | | |
473 | 831k | const FieldDecl *getSourceBitField() const { |
474 | 831k | return const_cast<Expr*>(this)->getSourceBitField(); |
475 | 831k | } |
476 | | |
477 | | Decl *getReferencedDeclOfCallee(); |
478 | 11.9M | const Decl *getReferencedDeclOfCallee() const { |
479 | 11.9M | return const_cast<Expr*>(this)->getReferencedDeclOfCallee(); |
480 | 11.9M | } |
481 | | |
482 | | /// If this expression is an l-value for an Objective C |
483 | | /// property, find the underlying property reference expression. |
484 | | const ObjCPropertyRefExpr *getObjCProperty() const; |
485 | | |
486 | | /// Check if this expression is the ObjC 'self' implicit parameter. |
487 | | bool isObjCSelfExpr() const; |
488 | | |
489 | | /// Returns whether this expression refers to a vector element. |
490 | | bool refersToVectorElement() const; |
491 | | |
492 | | /// Returns whether this expression refers to a matrix element. |
493 | 362k | bool refersToMatrixElement() const { |
494 | 362k | return getObjectKind() == OK_MatrixComponent; |
495 | 362k | } |
496 | | |
497 | | /// Returns whether this expression refers to a global register |
498 | | /// variable. |
499 | | bool refersToGlobalRegisterVar() const; |
500 | | |
501 | | /// Returns whether this expression has a placeholder type. |
502 | 71.6M | bool hasPlaceholderType() const { |
503 | 71.6M | return getType()->isPlaceholderType(); |
504 | 71.6M | } |
505 | | |
506 | | /// Returns whether this expression has a specific placeholder type. |
507 | 5.27M | bool hasPlaceholderType(BuiltinType::Kind K) const { |
508 | 5.27M | assert(BuiltinType::isPlaceholderTypeKind(K)); |
509 | 5.27M | if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType())) |
510 | 3.08M | return BT->getKind() == K; |
511 | 2.19M | return false; |
512 | 5.27M | } |
513 | | |
514 | | /// isKnownToHaveBooleanValue - Return true if this is an integer expression |
515 | | /// that is known to return 0 or 1. This happens for _Bool/bool expressions |
516 | | /// but also int expressions which are produced by things like comparisons in |
517 | | /// C. |
518 | | /// |
519 | | /// \param Semantic If true, only return true for expressions that are known |
520 | | /// to be semantically boolean, which might not be true even for expressions |
521 | | /// that are known to evaluate to 0/1. For instance, reading an unsigned |
522 | | /// bit-field with width '1' will evaluate to 0/1, but doesn't necessarily |
523 | | /// semantically correspond to a bool. |
524 | | bool isKnownToHaveBooleanValue(bool Semantic = true) const; |
525 | | |
526 | | /// isIntegerConstantExpr - Return the value if this expression is a valid |
527 | | /// integer constant expression. If not a valid i-c-e, return None and fill |
528 | | /// in Loc (if specified) with the location of the invalid expression. |
529 | | /// |
530 | | /// Note: This does not perform the implicit conversions required by C++11 |
531 | | /// [expr.const]p5. |
532 | | Optional<llvm::APSInt> getIntegerConstantExpr(const ASTContext &Ctx, |
533 | | SourceLocation *Loc = nullptr, |
534 | | bool isEvaluated = true) const; |
535 | | bool isIntegerConstantExpr(const ASTContext &Ctx, |
536 | | SourceLocation *Loc = nullptr) const; |
537 | | |
538 | | /// isCXX98IntegralConstantExpr - Return true if this expression is an |
539 | | /// integral constant expression in C++98. Can only be used in C++. |
540 | | bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const; |
541 | | |
542 | | /// isCXX11ConstantExpr - Return true if this expression is a constant |
543 | | /// expression in C++11. Can only be used in C++. |
544 | | /// |
545 | | /// Note: This does not perform the implicit conversions required by C++11 |
546 | | /// [expr.const]p5. |
547 | | bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr, |
548 | | SourceLocation *Loc = nullptr) const; |
549 | | |
550 | | /// isPotentialConstantExpr - Return true if this function's definition |
551 | | /// might be usable in a constant expression in C++11, if it were marked |
552 | | /// constexpr. Return false if the function can never produce a constant |
553 | | /// expression, along with diagnostics describing why not. |
554 | | static bool isPotentialConstantExpr(const FunctionDecl *FD, |
555 | | SmallVectorImpl< |
556 | | PartialDiagnosticAt> &Diags); |
557 | | |
558 | | /// isPotentialConstantExprUnevaluted - Return true if this expression might |
559 | | /// be usable in a constant expression in C++11 in an unevaluated context, if |
560 | | /// it were in function FD marked constexpr. Return false if the function can |
561 | | /// never produce a constant expression, along with diagnostics describing |
562 | | /// why not. |
563 | | static bool isPotentialConstantExprUnevaluated(Expr *E, |
564 | | const FunctionDecl *FD, |
565 | | SmallVectorImpl< |
566 | | PartialDiagnosticAt> &Diags); |
567 | | |
568 | | /// isConstantInitializer - Returns true if this expression can be emitted to |
569 | | /// IR as a constant, and thus can be used as a constant initializer in C. |
570 | | /// If this expression is not constant and Culprit is non-null, |
571 | | /// it is used to store the address of first non constant expr. |
572 | | bool isConstantInitializer(ASTContext &Ctx, bool ForRef, |
573 | | const Expr **Culprit = nullptr) const; |
574 | | |
575 | | /// If this expression is an unambiguous reference to a single declaration, |
576 | | /// in the style of __builtin_function_start, return that declaration. Note |
577 | | /// that this may return a non-static member function or field in C++ if this |
578 | | /// expression is a member pointer constant. |
579 | | const ValueDecl *getAsBuiltinConstantDeclRef(const ASTContext &Context) const; |
580 | | |
581 | | /// EvalStatus is a struct with detailed info about an evaluation in progress. |
582 | | struct EvalStatus { |
583 | | /// Whether the evaluated expression has side effects. |
584 | | /// For example, (f() && 0) can be folded, but it still has side effects. |
585 | | bool HasSideEffects; |
586 | | |
587 | | /// Whether the evaluation hit undefined behavior. |
588 | | /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior. |
589 | | /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB. |
590 | | bool HasUndefinedBehavior; |
591 | | |
592 | | /// Diag - If this is non-null, it will be filled in with a stack of notes |
593 | | /// indicating why evaluation failed (or why it failed to produce a constant |
594 | | /// expression). |
595 | | /// If the expression is unfoldable, the notes will indicate why it's not |
596 | | /// foldable. If the expression is foldable, but not a constant expression, |
597 | | /// the notes will describes why it isn't a constant expression. If the |
598 | | /// expression *is* a constant expression, no notes will be produced. |
599 | | SmallVectorImpl<PartialDiagnosticAt> *Diag; |
600 | | |
601 | | EvalStatus() |
602 | 40.4M | : HasSideEffects(false), HasUndefinedBehavior(false), Diag(nullptr) {} |
603 | | |
604 | | // hasSideEffects - Return true if the evaluated expression has |
605 | | // side effects. |
606 | 1.09k | bool hasSideEffects() const { |
607 | 1.09k | return HasSideEffects; |
608 | 1.09k | } |
609 | | }; |
610 | | |
611 | | /// EvalResult is a struct with detailed info about an evaluated expression. |
612 | | struct EvalResult : EvalStatus { |
613 | | /// Val - This is the value the expression can be folded to. |
614 | | APValue Val; |
615 | | |
616 | | // isGlobalLValue - Return true if the evaluated lvalue expression |
617 | | // is global. |
618 | | bool isGlobalLValue() const; |
619 | | }; |
620 | | |
621 | | /// EvaluateAsRValue - Return true if this is a constant which we can fold to |
622 | | /// an rvalue using any crazy technique (that has nothing to do with language |
623 | | /// standards) that we want to, even if the expression has side-effects. If |
624 | | /// this function returns true, it returns the folded constant in Result. If |
625 | | /// the expression is a glvalue, an lvalue-to-rvalue conversion will be |
626 | | /// applied. |
627 | | bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, |
628 | | bool InConstantContext = false) const; |
629 | | |
630 | | /// EvaluateAsBooleanCondition - Return true if this is a constant |
631 | | /// which we can fold and convert to a boolean condition using |
632 | | /// any crazy technique that we want to, even if the expression has |
633 | | /// side-effects. |
634 | | bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx, |
635 | | bool InConstantContext = false) const; |
636 | | |
637 | | enum SideEffectsKind { |
638 | | SE_NoSideEffects, ///< Strictly evaluate the expression. |
639 | | SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not |
640 | | ///< arbitrary unmodeled side effects. |
641 | | SE_AllowSideEffects ///< Allow any unmodeled side effect. |
642 | | }; |
643 | | |
644 | | /// EvaluateAsInt - Return true if this is a constant which we can fold and |
645 | | /// convert to an integer, using any crazy technique that we want to. |
646 | | bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, |
647 | | SideEffectsKind AllowSideEffects = SE_NoSideEffects, |
648 | | bool InConstantContext = false) const; |
649 | | |
650 | | /// EvaluateAsFloat - Return true if this is a constant which we can fold and |
651 | | /// convert to a floating point value, using any crazy technique that we |
652 | | /// want to. |
653 | | bool EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx, |
654 | | SideEffectsKind AllowSideEffects = SE_NoSideEffects, |
655 | | bool InConstantContext = false) const; |
656 | | |
657 | | /// EvaluateAsFloat - Return true if this is a constant which we can fold and |
658 | | /// convert to a fixed point value. |
659 | | bool EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx, |
660 | | SideEffectsKind AllowSideEffects = SE_NoSideEffects, |
661 | | bool InConstantContext = false) const; |
662 | | |
663 | | /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be |
664 | | /// constant folded without side-effects, but discard the result. |
665 | | bool isEvaluatable(const ASTContext &Ctx, |
666 | | SideEffectsKind AllowSideEffects = SE_NoSideEffects) const; |
667 | | |
668 | | /// HasSideEffects - This routine returns true for all those expressions |
669 | | /// which have any effect other than producing a value. Example is a function |
670 | | /// call, volatile variable read, or throwing an exception. If |
671 | | /// IncludePossibleEffects is false, this call treats certain expressions with |
672 | | /// potential side effects (such as function call-like expressions, |
673 | | /// instantiation-dependent expressions, or invocations from a macro) as not |
674 | | /// having side effects. |
675 | | bool HasSideEffects(const ASTContext &Ctx, |
676 | | bool IncludePossibleEffects = true) const; |
677 | | |
678 | | /// Determine whether this expression involves a call to any function |
679 | | /// that is not trivial. |
680 | | bool hasNonTrivialCall(const ASTContext &Ctx) const; |
681 | | |
682 | | /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded |
683 | | /// integer. This must be called on an expression that constant folds to an |
684 | | /// integer. |
685 | | llvm::APSInt EvaluateKnownConstInt( |
686 | | const ASTContext &Ctx, |
687 | | SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const; |
688 | | |
689 | | llvm::APSInt EvaluateKnownConstIntCheckOverflow( |
690 | | const ASTContext &Ctx, |
691 | | SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const; |
692 | | |
693 | | void EvaluateForOverflow(const ASTContext &Ctx) const; |
694 | | |
695 | | /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an |
696 | | /// lvalue with link time known address, with no side-effects. |
697 | | bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, |
698 | | bool InConstantContext = false) const; |
699 | | |
700 | | /// EvaluateAsInitializer - Evaluate an expression as if it were the |
701 | | /// initializer of the given declaration. Returns true if the initializer |
702 | | /// can be folded to a constant, and produces any relevant notes. In C++11, |
703 | | /// notes will be produced if the expression is not a constant expression. |
704 | | bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx, |
705 | | const VarDecl *VD, |
706 | | SmallVectorImpl<PartialDiagnosticAt> &Notes, |
707 | | bool IsConstantInitializer) const; |
708 | | |
709 | | /// EvaluateWithSubstitution - Evaluate an expression as if from the context |
710 | | /// of a call to the given function with the given arguments, inside an |
711 | | /// unevaluated context. Returns true if the expression could be folded to a |
712 | | /// constant. |
713 | | bool EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx, |
714 | | const FunctionDecl *Callee, |
715 | | ArrayRef<const Expr*> Args, |
716 | | const Expr *This = nullptr) const; |
717 | | |
718 | | enum class ConstantExprKind { |
719 | | /// An integer constant expression (an array bound, enumerator, case value, |
720 | | /// bit-field width, or similar) or similar. |
721 | | Normal, |
722 | | /// A non-class template argument. Such a value is only used for mangling, |
723 | | /// not for code generation, so can refer to dllimported functions. |
724 | | NonClassTemplateArgument, |
725 | | /// A class template argument. Such a value is used for code generation. |
726 | | ClassTemplateArgument, |
727 | | /// An immediate invocation. The destruction of the end result of this |
728 | | /// evaluation is not part of the evaluation, but all other temporaries |
729 | | /// are destroyed. |
730 | | ImmediateInvocation, |
731 | | }; |
732 | | |
733 | | /// Evaluate an expression that is required to be a constant expression. Does |
734 | | /// not check the syntactic constraints for C and C++98 constant expressions. |
735 | | bool EvaluateAsConstantExpr( |
736 | | EvalResult &Result, const ASTContext &Ctx, |
737 | | ConstantExprKind Kind = ConstantExprKind::Normal) const; |
738 | | |
739 | | /// If the current Expr is a pointer, this will try to statically |
740 | | /// determine the number of bytes available where the pointer is pointing. |
741 | | /// Returns true if all of the above holds and we were able to figure out the |
742 | | /// size, false otherwise. |
743 | | /// |
744 | | /// \param Type - How to evaluate the size of the Expr, as defined by the |
745 | | /// "type" parameter of __builtin_object_size |
746 | | bool tryEvaluateObjectSize(uint64_t &Result, ASTContext &Ctx, |
747 | | unsigned Type) const; |
748 | | |
749 | | /// If the current Expr is a pointer, this will try to statically |
750 | | /// determine the strlen of the string pointed to. |
751 | | /// Returns true if all of the above holds and we were able to figure out the |
752 | | /// strlen, false otherwise. |
753 | | bool tryEvaluateStrLen(uint64_t &Result, ASTContext &Ctx) const; |
754 | | |
755 | | /// Enumeration used to describe the kind of Null pointer constant |
756 | | /// returned from \c isNullPointerConstant(). |
757 | | enum NullPointerConstantKind { |
758 | | /// Expression is not a Null pointer constant. |
759 | | NPCK_NotNull = 0, |
760 | | |
761 | | /// Expression is a Null pointer constant built from a zero integer |
762 | | /// expression that is not a simple, possibly parenthesized, zero literal. |
763 | | /// C++ Core Issue 903 will classify these expressions as "not pointers" |
764 | | /// once it is adopted. |
765 | | /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903 |
766 | | NPCK_ZeroExpression, |
767 | | |
768 | | /// Expression is a Null pointer constant built from a literal zero. |
769 | | NPCK_ZeroLiteral, |
770 | | |
771 | | /// Expression is a C++11 nullptr. |
772 | | NPCK_CXX11_nullptr, |
773 | | |
774 | | /// Expression is a GNU-style __null constant. |
775 | | NPCK_GNUNull |
776 | | }; |
777 | | |
778 | | /// Enumeration used to describe how \c isNullPointerConstant() |
779 | | /// should cope with value-dependent expressions. |
780 | | enum NullPointerConstantValueDependence { |
781 | | /// Specifies that the expression should never be value-dependent. |
782 | | NPC_NeverValueDependent = 0, |
783 | | |
784 | | /// Specifies that a value-dependent expression of integral or |
785 | | /// dependent type should be considered a null pointer constant. |
786 | | NPC_ValueDependentIsNull, |
787 | | |
788 | | /// Specifies that a value-dependent expression should be considered |
789 | | /// to never be a null pointer constant. |
790 | | NPC_ValueDependentIsNotNull |
791 | | }; |
792 | | |
793 | | /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to |
794 | | /// a Null pointer constant. The return value can further distinguish the |
795 | | /// kind of NULL pointer constant that was detected. |
796 | | NullPointerConstantKind isNullPointerConstant( |
797 | | ASTContext &Ctx, |
798 | | NullPointerConstantValueDependence NPC) const; |
799 | | |
800 | | /// isOBJCGCCandidate - Return true if this expression may be used in a read/ |
801 | | /// write barrier. |
802 | | bool isOBJCGCCandidate(ASTContext &Ctx) const; |
803 | | |
804 | | /// Returns true if this expression is a bound member function. |
805 | | bool isBoundMemberFunction(ASTContext &Ctx) const; |
806 | | |
807 | | /// Given an expression of bound-member type, find the type |
808 | | /// of the member. Returns null if this is an *overloaded* bound |
809 | | /// member expression. |
810 | | static QualType findBoundMemberType(const Expr *expr); |
811 | | |
812 | | /// Skip past any invisble AST nodes which might surround this |
813 | | /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes, |
814 | | /// but also injected CXXMemberExpr and CXXConstructExpr which represent |
815 | | /// implicit conversions. |
816 | | Expr *IgnoreUnlessSpelledInSource(); |
817 | 92 | const Expr *IgnoreUnlessSpelledInSource() const { |
818 | 92 | return const_cast<Expr *>(this)->IgnoreUnlessSpelledInSource(); |
819 | 92 | } |
820 | | |
821 | | /// Skip past any implicit casts which might surround this expression until |
822 | | /// reaching a fixed point. Skips: |
823 | | /// * ImplicitCastExpr |
824 | | /// * FullExpr |
825 | | Expr *IgnoreImpCasts() LLVM_READONLY; |
826 | 528k | const Expr *IgnoreImpCasts() const { |
827 | 528k | return const_cast<Expr *>(this)->IgnoreImpCasts(); |
828 | 528k | } |
829 | | |
830 | | /// Skip past any casts which might surround this expression until reaching |
831 | | /// a fixed point. Skips: |
832 | | /// * CastExpr |
833 | | /// * FullExpr |
834 | | /// * MaterializeTemporaryExpr |
835 | | /// * SubstNonTypeTemplateParmExpr |
836 | | Expr *IgnoreCasts() LLVM_READONLY; |
837 | 1.15k | const Expr *IgnoreCasts() const { |
838 | 1.15k | return const_cast<Expr *>(this)->IgnoreCasts(); |
839 | 1.15k | } |
840 | | |
841 | | /// Skip past any implicit AST nodes which might surround this expression |
842 | | /// until reaching a fixed point. Skips: |
843 | | /// * What IgnoreImpCasts() skips |
844 | | /// * MaterializeTemporaryExpr |
845 | | /// * CXXBindTemporaryExpr |
846 | | Expr *IgnoreImplicit() LLVM_READONLY; |
847 | 54.4k | const Expr *IgnoreImplicit() const { |
848 | 54.4k | return const_cast<Expr *>(this)->IgnoreImplicit(); |
849 | 54.4k | } |
850 | | |
851 | | /// Skip past any implicit AST nodes which might surround this expression |
852 | | /// until reaching a fixed point. Same as IgnoreImplicit, except that it |
853 | | /// also skips over implicit calls to constructors and conversion functions. |
854 | | /// |
855 | | /// FIXME: Should IgnoreImplicit do this? |
856 | | Expr *IgnoreImplicitAsWritten() LLVM_READONLY; |
857 | 2.47k | const Expr *IgnoreImplicitAsWritten() const { |
858 | 2.47k | return const_cast<Expr *>(this)->IgnoreImplicitAsWritten(); |
859 | 2.47k | } |
860 | | |
861 | | /// Skip past any parentheses which might surround this expression until |
862 | | /// reaching a fixed point. Skips: |
863 | | /// * ParenExpr |
864 | | /// * UnaryOperator if `UO_Extension` |
865 | | /// * GenericSelectionExpr if `!isResultDependent()` |
866 | | /// * ChooseExpr if `!isConditionDependent()` |
867 | | /// * ConstantExpr |
868 | | Expr *IgnoreParens() LLVM_READONLY; |
869 | 47.7M | const Expr *IgnoreParens() const { |
870 | 47.7M | return const_cast<Expr *>(this)->IgnoreParens(); |
871 | 47.7M | } |
872 | | |
873 | | /// Skip past any parentheses and implicit casts which might surround this |
874 | | /// expression until reaching a fixed point. |
875 | | /// FIXME: IgnoreParenImpCasts really ought to be equivalent to |
876 | | /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However |
877 | | /// this is currently not the case. Instead IgnoreParenImpCasts() skips: |
878 | | /// * What IgnoreParens() skips |
879 | | /// * What IgnoreImpCasts() skips |
880 | | /// * MaterializeTemporaryExpr |
881 | | /// * SubstNonTypeTemplateParmExpr |
882 | | Expr *IgnoreParenImpCasts() LLVM_READONLY; |
883 | 37.6M | const Expr *IgnoreParenImpCasts() const { |
884 | 37.6M | return const_cast<Expr *>(this)->IgnoreParenImpCasts(); |
885 | 37.6M | } |
886 | | |
887 | | /// Skip past any parentheses and casts which might surround this expression |
888 | | /// until reaching a fixed point. Skips: |
889 | | /// * What IgnoreParens() skips |
890 | | /// * What IgnoreCasts() skips |
891 | | Expr *IgnoreParenCasts() LLVM_READONLY; |
892 | 17.0M | const Expr *IgnoreParenCasts() const { |
893 | 17.0M | return const_cast<Expr *>(this)->IgnoreParenCasts(); |
894 | 17.0M | } |
895 | | |
896 | | /// Skip conversion operators. If this Expr is a call to a conversion |
897 | | /// operator, return the argument. |
898 | | Expr *IgnoreConversionOperatorSingleStep() LLVM_READONLY; |
899 | 0 | const Expr *IgnoreConversionOperatorSingleStep() const { |
900 | 0 | return const_cast<Expr *>(this)->IgnoreConversionOperatorSingleStep(); |
901 | 0 | } |
902 | | |
903 | | /// Skip past any parentheses and lvalue casts which might surround this |
904 | | /// expression until reaching a fixed point. Skips: |
905 | | /// * What IgnoreParens() skips |
906 | | /// * What IgnoreCasts() skips, except that only lvalue-to-rvalue |
907 | | /// casts are skipped |
908 | | /// FIXME: This is intended purely as a temporary workaround for code |
909 | | /// that hasn't yet been rewritten to do the right thing about those |
910 | | /// casts, and may disappear along with the last internal use. |
911 | | Expr *IgnoreParenLValueCasts() LLVM_READONLY; |
912 | 1.86k | const Expr *IgnoreParenLValueCasts() const { |
913 | 1.86k | return const_cast<Expr *>(this)->IgnoreParenLValueCasts(); |
914 | 1.86k | } |
915 | | |
916 | | /// Skip past any parenthese and casts which do not change the value |
917 | | /// (including ptr->int casts of the same size) until reaching a fixed point. |
918 | | /// Skips: |
919 | | /// * What IgnoreParens() skips |
920 | | /// * CastExpr which do not change the value |
921 | | /// * SubstNonTypeTemplateParmExpr |
922 | | Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY; |
923 | 202k | const Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) const { |
924 | 202k | return const_cast<Expr *>(this)->IgnoreParenNoopCasts(Ctx); |
925 | 202k | } |
926 | | |
927 | | /// Skip past any parentheses and derived-to-base casts until reaching a |
928 | | /// fixed point. Skips: |
929 | | /// * What IgnoreParens() skips |
930 | | /// * CastExpr which represent a derived-to-base cast (CK_DerivedToBase, |
931 | | /// CK_UncheckedDerivedToBase and CK_NoOp) |
932 | | Expr *IgnoreParenBaseCasts() LLVM_READONLY; |
933 | 37.7k | const Expr *IgnoreParenBaseCasts() const { |
934 | 37.7k | return const_cast<Expr *>(this)->IgnoreParenBaseCasts(); |
935 | 37.7k | } |
936 | | |
937 | | /// Determine whether this expression is a default function argument. |
938 | | /// |
939 | | /// Default arguments are implicitly generated in the abstract syntax tree |
940 | | /// by semantic analysis for function calls, object constructions, etc. in |
941 | | /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; |
942 | | /// this routine also looks through any implicit casts to determine whether |
943 | | /// the expression is a default argument. |
944 | | bool isDefaultArgument() const; |
945 | | |
946 | | /// Determine whether the result of this expression is a |
947 | | /// temporary object of the given class type. |
948 | | bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; |
949 | | |
950 | | /// Whether this expression is an implicit reference to 'this' in C++. |
951 | | bool isImplicitCXXThis() const; |
952 | | |
953 | | static bool hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs); |
954 | | |
955 | | /// For an expression of class type or pointer to class type, |
956 | | /// return the most derived class decl the expression is known to refer to. |
957 | | /// |
958 | | /// If this expression is a cast, this method looks through it to find the |
959 | | /// most derived decl that can be inferred from the expression. |
960 | | /// This is valid because derived-to-base conversions have undefined |
961 | | /// behavior if the object isn't dynamically of the derived type. |
962 | | const CXXRecordDecl *getBestDynamicClassType() const; |
963 | | |
964 | | /// Get the inner expression that determines the best dynamic class. |
965 | | /// If this is a prvalue, we guarantee that it is of the most-derived type |
966 | | /// for the object itself. |
967 | | const Expr *getBestDynamicClassTypeExpr() const; |
968 | | |
969 | | /// Walk outwards from an expression we want to bind a reference to and |
970 | | /// find the expression whose lifetime needs to be extended. Record |
971 | | /// the LHSs of comma expressions and adjustments needed along the path. |
972 | | const Expr *skipRValueSubobjectAdjustments( |
973 | | SmallVectorImpl<const Expr *> &CommaLHS, |
974 | | SmallVectorImpl<SubobjectAdjustment> &Adjustments) const; |
975 | 8.17M | const Expr *skipRValueSubobjectAdjustments() const { |
976 | 8.17M | SmallVector<const Expr *, 8> CommaLHSs; |
977 | 8.17M | SmallVector<SubobjectAdjustment, 8> Adjustments; |
978 | 8.17M | return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments); |
979 | 8.17M | } |
980 | | |
981 | | /// Checks that the two Expr's will refer to the same value as a comparison |
982 | | /// operand. The caller must ensure that the values referenced by the Expr's |
983 | | /// are not modified between E1 and E2 or the result my be invalid. |
984 | | static bool isSameComparisonOperand(const Expr* E1, const Expr* E2); |
985 | | |
986 | 731M | static bool classof(const Stmt *T) { |
987 | 731M | return T->getStmtClass() >= firstExprConstant && |
988 | 731M | T->getStmtClass() <= lastExprConstant728M ; |
989 | 731M | } |
990 | | }; |
991 | | // PointerLikeTypeTraits is specialized so it can be used with a forward-decl of |
992 | | // Expr. Verify that we got it right. |
993 | | static_assert(llvm::PointerLikeTypeTraits<Expr *>::NumLowBitsAvailable <= |
994 | | llvm::detail::ConstantLog2<alignof(Expr)>::value, |
995 | | "PointerLikeTypeTraits<Expr*> assumes too much alignment."); |
996 | | |
997 | | using ConstantExprKind = Expr::ConstantExprKind; |
998 | | |
999 | | //===----------------------------------------------------------------------===// |
1000 | | // Wrapper Expressions. |
1001 | | //===----------------------------------------------------------------------===// |
1002 | | |
1003 | | /// FullExpr - Represents a "full-expression" node. |
1004 | | class FullExpr : public Expr { |
1005 | | protected: |
1006 | | Stmt *SubExpr; |
1007 | | |
1008 | | FullExpr(StmtClass SC, Expr *subexpr) |
1009 | | : Expr(SC, subexpr->getType(), subexpr->getValueKind(), |
1010 | | subexpr->getObjectKind()), |
1011 | 6.32M | SubExpr(subexpr) { |
1012 | 6.32M | setDependence(computeDependence(this)); |
1013 | 6.32M | } |
1014 | | FullExpr(StmtClass SC, EmptyShell Empty) |
1015 | 250k | : Expr(SC, Empty) {} |
1016 | | public: |
1017 | 93.1k | const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } |
1018 | 7.50M | Expr *getSubExpr() { return cast<Expr>(SubExpr); } |
1019 | | |
1020 | | /// As with any mutator of the AST, be very careful when modifying an |
1021 | | /// existing AST to preserve its invariants. |
1022 | 238k | void setSubExpr(Expr *E) { SubExpr = E; } |
1023 | | |
1024 | 245M | static bool classof(const Stmt *T) { |
1025 | 245M | return T->getStmtClass() >= firstFullExprConstant && |
1026 | 245M | T->getStmtClass() <= lastFullExprConstant52.4M ; |
1027 | 245M | } |
1028 | | }; |
1029 | | |
1030 | | /// ConstantExpr - An expression that occurs in a constant context and |
1031 | | /// optionally the result of evaluating the expression. |
1032 | | class ConstantExpr final |
1033 | | : public FullExpr, |
1034 | | private llvm::TrailingObjects<ConstantExpr, APValue, uint64_t> { |
1035 | | static_assert(std::is_same<uint64_t, llvm::APInt::WordType>::value, |
1036 | | "ConstantExpr assumes that llvm::APInt::WordType is uint64_t " |
1037 | | "for tail-allocated storage"); |
1038 | | friend TrailingObjects; |
1039 | | friend class ASTStmtReader; |
1040 | | friend class ASTStmtWriter; |
1041 | | |
1042 | | public: |
1043 | | /// Describes the kind of result that can be tail-allocated. |
1044 | | enum ResultStorageKind { RSK_None, RSK_Int64, RSK_APValue }; |
1045 | | |
1046 | | private: |
1047 | 6.88M | size_t numTrailingObjects(OverloadToken<APValue>) const { |
1048 | 6.88M | return ConstantExprBits.ResultKind == ConstantExpr::RSK_APValue; |
1049 | 6.88M | } |
1050 | 0 | size_t numTrailingObjects(OverloadToken<uint64_t>) const { |
1051 | 0 | return ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64; |
1052 | 0 | } |
1053 | | |
1054 | 6.88M | uint64_t &Int64Result() { |
1055 | 6.88M | assert(ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64 && |
1056 | 6.88M | "invalid accessor"); |
1057 | 0 | return *getTrailingObjects<uint64_t>(); |
1058 | 6.88M | } |
1059 | 247k | const uint64_t &Int64Result() const { |
1060 | 247k | return const_cast<ConstantExpr *>(this)->Int64Result(); |
1061 | 247k | } |
1062 | 2.16k | APValue &APValueResult() { |
1063 | 2.16k | assert(ConstantExprBits.ResultKind == ConstantExpr::RSK_APValue && |
1064 | 2.16k | "invalid accessor"); |
1065 | 0 | return *getTrailingObjects<APValue>(); |
1066 | 2.16k | } |
1067 | 68 | APValue &APValueResult() const { |
1068 | 68 | return const_cast<ConstantExpr *>(this)->APValueResult(); |
1069 | 68 | } |
1070 | | |
1071 | | ConstantExpr(Expr *SubExpr, ResultStorageKind StorageKind, |
1072 | | bool IsImmediateInvocation); |
1073 | | ConstantExpr(EmptyShell Empty, ResultStorageKind StorageKind); |
1074 | | |
1075 | | public: |
1076 | | static ConstantExpr *Create(const ASTContext &Context, Expr *E, |
1077 | | const APValue &Result); |
1078 | | static ConstantExpr *Create(const ASTContext &Context, Expr *E, |
1079 | | ResultStorageKind Storage = RSK_None, |
1080 | | bool IsImmediateInvocation = false); |
1081 | | static ConstantExpr *CreateEmpty(const ASTContext &Context, |
1082 | | ResultStorageKind StorageKind); |
1083 | | |
1084 | | static ResultStorageKind getStorageKind(const APValue &Value); |
1085 | | static ResultStorageKind getStorageKind(const Type *T, |
1086 | | const ASTContext &Context); |
1087 | | |
1088 | 2.08M | SourceLocation getBeginLoc() const LLVM_READONLY { |
1089 | 2.08M | return SubExpr->getBeginLoc(); |
1090 | 2.08M | } |
1091 | 198k | SourceLocation getEndLoc() const LLVM_READONLY { |
1092 | 198k | return SubExpr->getEndLoc(); |
1093 | 198k | } |
1094 | | |
1095 | 21.1M | static bool classof(const Stmt *T) { |
1096 | 21.1M | return T->getStmtClass() == ConstantExprClass; |
1097 | 21.1M | } |
1098 | | |
1099 | 6.17M | void SetResult(APValue Value, const ASTContext &Context) { |
1100 | 6.17M | MoveIntoResult(Value, Context); |
1101 | 6.17M | } |
1102 | | void MoveIntoResult(APValue &Value, const ASTContext &Context); |
1103 | | |
1104 | 16 | APValue::ValueKind getResultAPValueKind() const { |
1105 | 16 | return static_cast<APValue::ValueKind>(ConstantExprBits.APValueKind); |
1106 | 16 | } |
1107 | 0 | ResultStorageKind getResultStorageKind() const { |
1108 | 0 | return static_cast<ResultStorageKind>(ConstantExprBits.ResultKind); |
1109 | 0 | } |
1110 | 18 | bool isImmediateInvocation() const { |
1111 | 18 | return ConstantExprBits.IsImmediateInvocation; |
1112 | 18 | } |
1113 | 188k | bool hasAPValueResult() const { |
1114 | 188k | return ConstantExprBits.APValueKind != APValue::None; |
1115 | 188k | } |
1116 | | APValue getAPValueResult() const; |
1117 | 0 | APValue &getResultAsAPValue() const { return APValueResult(); } |
1118 | | llvm::APSInt getResultAsAPSInt() const; |
1119 | | // Iterators |
1120 | 433k | child_range children() { return child_range(&SubExpr, &SubExpr+1); } |
1121 | 0 | const_child_range children() const { |
1122 | 0 | return const_child_range(&SubExpr, &SubExpr + 1); |
1123 | 0 | } |
1124 | | }; |
1125 | | |
1126 | | //===----------------------------------------------------------------------===// |
1127 | | // Primary Expressions. |
1128 | | //===----------------------------------------------------------------------===// |
1129 | | |
1130 | | /// OpaqueValueExpr - An expression referring to an opaque object of a |
1131 | | /// fixed type and value class. These don't correspond to concrete |
1132 | | /// syntax; instead they're used to express operations (usually copy |
1133 | | /// operations) on values whose source is generally obvious from |
1134 | | /// context. |
1135 | | class OpaqueValueExpr : public Expr { |
1136 | | friend class ASTStmtReader; |
1137 | | Expr *SourceExpr; |
1138 | | |
1139 | | public: |
1140 | | OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, |
1141 | | ExprObjectKind OK = OK_Ordinary, Expr *SourceExpr = nullptr) |
1142 | 796k | : Expr(OpaqueValueExprClass, T, VK, OK), SourceExpr(SourceExpr) { |
1143 | 796k | setIsUnique(false); |
1144 | 796k | OpaqueValueExprBits.Loc = Loc; |
1145 | 796k | setDependence(computeDependence(this)); |
1146 | 796k | } |
1147 | | |
1148 | | /// Given an expression which invokes a copy constructor --- i.e. a |
1149 | | /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- |
1150 | | /// find the OpaqueValueExpr that's the source of the construction. |
1151 | | static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); |
1152 | | |
1153 | | explicit OpaqueValueExpr(EmptyShell Empty) |
1154 | 1.36k | : Expr(OpaqueValueExprClass, Empty) {} |
1155 | | |
1156 | | /// Retrieve the location of this expression. |
1157 | 499k | SourceLocation getLocation() const { return OpaqueValueExprBits.Loc; } |
1158 | | |
1159 | 503k | SourceLocation getBeginLoc() const LLVM_READONLY { |
1160 | 503k | return SourceExpr ? SourceExpr->getBeginLoc()83.2k : getLocation()420k ; |
1161 | 503k | } |
1162 | 19.4k | SourceLocation getEndLoc() const LLVM_READONLY { |
1163 | 19.4k | return SourceExpr ? SourceExpr->getEndLoc()13.5k : getLocation()5.83k ; |
1164 | 19.4k | } |
1165 | 97.5k | SourceLocation getExprLoc() const LLVM_READONLY { |
1166 | 97.5k | return SourceExpr ? SourceExpr->getExprLoc()25.7k : getLocation()71.7k ; |
1167 | 97.5k | } |
1168 | | |
1169 | 51.8k | child_range children() { |
1170 | 51.8k | return child_range(child_iterator(), child_iterator()); |
1171 | 51.8k | } |
1172 | | |
1173 | 0 | const_child_range children() const { |
1174 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1175 | 0 | } |
1176 | | |
1177 | | /// The source expression of an opaque value expression is the |
1178 | | /// expression which originally generated the value. This is |
1179 | | /// provided as a convenience for analyses that don't wish to |
1180 | | /// precisely model the execution behavior of the program. |
1181 | | /// |
1182 | | /// The source expression is typically set when building the |
1183 | | /// expression which binds the opaque value expression in the first |
1184 | | /// place. |
1185 | 850k | Expr *getSourceExpr() const { return SourceExpr; } |
1186 | | |
1187 | 803k | void setIsUnique(bool V) { |
1188 | 803k | assert((!V || SourceExpr) && |
1189 | 803k | "unique OVEs are expected to have source expressions"); |
1190 | 0 | OpaqueValueExprBits.IsUnique = V; |
1191 | 803k | } |
1192 | | |
1193 | 4.37k | bool isUnique() const { return OpaqueValueExprBits.IsUnique; } |
1194 | | |
1195 | 44.8M | static bool classof(const Stmt *T) { |
1196 | 44.8M | return T->getStmtClass() == OpaqueValueExprClass; |
1197 | 44.8M | } |
1198 | | }; |
1199 | | |
1200 | | /// A reference to a declared variable, function, enum, etc. |
1201 | | /// [C99 6.5.1p2] |
1202 | | /// |
1203 | | /// This encodes all the information about how a declaration is referenced |
1204 | | /// within an expression. |
1205 | | /// |
1206 | | /// There are several optional constructs attached to DeclRefExprs only when |
1207 | | /// they apply in order to conserve memory. These are laid out past the end of |
1208 | | /// the object, and flags in the DeclRefExprBitfield track whether they exist: |
1209 | | /// |
1210 | | /// DeclRefExprBits.HasQualifier: |
1211 | | /// Specifies when this declaration reference expression has a C++ |
1212 | | /// nested-name-specifier. |
1213 | | /// DeclRefExprBits.HasFoundDecl: |
1214 | | /// Specifies when this declaration reference expression has a record of |
1215 | | /// a NamedDecl (different from the referenced ValueDecl) which was found |
1216 | | /// during name lookup and/or overload resolution. |
1217 | | /// DeclRefExprBits.HasTemplateKWAndArgsInfo: |
1218 | | /// Specifies when this declaration reference expression has an explicit |
1219 | | /// C++ template keyword and/or template argument list. |
1220 | | /// DeclRefExprBits.RefersToEnclosingVariableOrCapture |
1221 | | /// Specifies when this declaration reference expression (validly) |
1222 | | /// refers to an enclosed local or a captured variable. |
1223 | | class DeclRefExpr final |
1224 | | : public Expr, |
1225 | | private llvm::TrailingObjects<DeclRefExpr, NestedNameSpecifierLoc, |
1226 | | NamedDecl *, ASTTemplateKWAndArgsInfo, |
1227 | | TemplateArgumentLoc> { |
1228 | | friend class ASTStmtReader; |
1229 | | friend class ASTStmtWriter; |
1230 | | friend TrailingObjects; |
1231 | | |
1232 | | /// The declaration that we are referencing. |
1233 | | ValueDecl *D; |
1234 | | |
1235 | | /// Provides source/type location info for the declaration name |
1236 | | /// embedded in D. |
1237 | | DeclarationNameLoc DNLoc; |
1238 | | |
1239 | 2.70M | size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const { |
1240 | 2.70M | return hasQualifier(); |
1241 | 2.70M | } |
1242 | | |
1243 | 2.16M | size_t numTrailingObjects(OverloadToken<NamedDecl *>) const { |
1244 | 2.16M | return hasFoundDecl(); |
1245 | 2.16M | } |
1246 | | |
1247 | 547k | size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
1248 | 547k | return hasTemplateKWAndArgsInfo(); |
1249 | 547k | } |
1250 | | |
1251 | | /// Test whether there is a distinct FoundDecl attached to the end of |
1252 | | /// this DRE. |
1253 | 12.3M | bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } |
1254 | | |
1255 | | DeclRefExpr(const ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc, |
1256 | | SourceLocation TemplateKWLoc, ValueDecl *D, |
1257 | | bool RefersToEnlosingVariableOrCapture, |
1258 | | const DeclarationNameInfo &NameInfo, NamedDecl *FoundD, |
1259 | | const TemplateArgumentListInfo *TemplateArgs, QualType T, |
1260 | | ExprValueKind VK, NonOdrUseReason NOUR); |
1261 | | |
1262 | | /// Construct an empty declaration reference expression. |
1263 | 2.62M | explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {} |
1264 | | |
1265 | | public: |
1266 | | DeclRefExpr(const ASTContext &Ctx, ValueDecl *D, |
1267 | | bool RefersToEnclosingVariableOrCapture, QualType T, |
1268 | | ExprValueKind VK, SourceLocation L, |
1269 | | const DeclarationNameLoc &LocInfo = DeclarationNameLoc(), |
1270 | | NonOdrUseReason NOUR = NOUR_None); |
1271 | | |
1272 | | static DeclRefExpr * |
1273 | | Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, |
1274 | | SourceLocation TemplateKWLoc, ValueDecl *D, |
1275 | | bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, |
1276 | | QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr, |
1277 | | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
1278 | | NonOdrUseReason NOUR = NOUR_None); |
1279 | | |
1280 | | static DeclRefExpr * |
1281 | | Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, |
1282 | | SourceLocation TemplateKWLoc, ValueDecl *D, |
1283 | | bool RefersToEnclosingVariableOrCapture, |
1284 | | const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK, |
1285 | | NamedDecl *FoundD = nullptr, |
1286 | | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
1287 | | NonOdrUseReason NOUR = NOUR_None); |
1288 | | |
1289 | | /// Construct an empty declaration reference expression. |
1290 | | static DeclRefExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier, |
1291 | | bool HasFoundDecl, |
1292 | | bool HasTemplateKWAndArgsInfo, |
1293 | | unsigned NumTemplateArgs); |
1294 | | |
1295 | 156M | ValueDecl *getDecl() { return D; } |
1296 | 180M | const ValueDecl *getDecl() const { return D; } |
1297 | | void setDecl(ValueDecl *NewD); |
1298 | | |
1299 | 135M | DeclarationNameInfo getNameInfo() const { |
1300 | 135M | return DeclarationNameInfo(getDecl()->getDeclName(), getLocation(), DNLoc); |
1301 | 135M | } |
1302 | | |
1303 | 162M | SourceLocation getLocation() const { return DeclRefExprBits.Loc; } |
1304 | 2.62M | void setLocation(SourceLocation L) { DeclRefExprBits.Loc = L; } |
1305 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
1306 | | SourceLocation getEndLoc() const LLVM_READONLY; |
1307 | | |
1308 | | /// Determine whether this declaration reference was preceded by a |
1309 | | /// C++ nested-name-specifier, e.g., \c N::foo. |
1310 | 184M | bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } |
1311 | | |
1312 | | /// If the name was qualified, retrieves the nested-name-specifier |
1313 | | /// that precedes the name, with source-location information. |
1314 | 45.7M | NestedNameSpecifierLoc getQualifierLoc() const { |
1315 | 45.7M | if (!hasQualifier()) |
1316 | 30.0M | return NestedNameSpecifierLoc(); |
1317 | 15.7M | return *getTrailingObjects<NestedNameSpecifierLoc>(); |
1318 | 45.7M | } |
1319 | | |
1320 | | /// If the name was qualified, retrieves the nested-name-specifier |
1321 | | /// that precedes the name. Otherwise, returns NULL. |
1322 | 28.7M | NestedNameSpecifier *getQualifier() const { |
1323 | 28.7M | return getQualifierLoc().getNestedNameSpecifier(); |
1324 | 28.7M | } |
1325 | | |
1326 | | /// Get the NamedDecl through which this reference occurred. |
1327 | | /// |
1328 | | /// This Decl may be different from the ValueDecl actually referred to in the |
1329 | | /// presence of using declarations, etc. It always returns non-NULL, and may |
1330 | | /// simple return the ValueDecl when appropriate. |
1331 | | |
1332 | 7.52M | NamedDecl *getFoundDecl() { |
1333 | 7.52M | return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>()121k : D7.40M ; |
1334 | 7.52M | } |
1335 | | |
1336 | | /// Get the NamedDecl through which this reference occurred. |
1337 | | /// See non-const variant. |
1338 | 8.76k | const NamedDecl *getFoundDecl() const { |
1339 | 8.76k | return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>()284 : D8.47k ; |
1340 | 8.76k | } |
1341 | | |
1342 | 60.9M | bool hasTemplateKWAndArgsInfo() const { |
1343 | 60.9M | return DeclRefExprBits.HasTemplateKWAndArgsInfo; |
1344 | 60.9M | } |
1345 | | |
1346 | | /// Retrieve the location of the template keyword preceding |
1347 | | /// this name, if any. |
1348 | 3.09M | SourceLocation getTemplateKeywordLoc() const { |
1349 | 3.09M | if (!hasTemplateKWAndArgsInfo()) |
1350 | 3.07M | return SourceLocation(); |
1351 | 18.3k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc; |
1352 | 3.09M | } |
1353 | | |
1354 | | /// Retrieve the location of the left angle bracket starting the |
1355 | | /// explicit template argument list following the name, if any. |
1356 | 47.5M | SourceLocation getLAngleLoc() const { |
1357 | 47.5M | if (!hasTemplateKWAndArgsInfo()) |
1358 | 46.7M | return SourceLocation(); |
1359 | 811k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc; |
1360 | 47.5M | } |
1361 | | |
1362 | | /// Retrieve the location of the right angle bracket ending the |
1363 | | /// explicit template argument list following the name, if any. |
1364 | 297k | SourceLocation getRAngleLoc() const { |
1365 | 297k | if (!hasTemplateKWAndArgsInfo()) |
1366 | 63.6k | return SourceLocation(); |
1367 | 233k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc; |
1368 | 297k | } |
1369 | | |
1370 | | /// Determines whether the name in this declaration reference |
1371 | | /// was preceded by the template keyword. |
1372 | 76.3k | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
1373 | | |
1374 | | /// Determines whether this declaration reference was followed by an |
1375 | | /// explicit template argument list. |
1376 | 47.4M | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } |
1377 | | |
1378 | | /// Copies the template arguments (if present) into the given |
1379 | | /// structure. |
1380 | 4.57k | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { |
1381 | 4.57k | if (hasExplicitTemplateArgs()) |
1382 | 4.55k | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto( |
1383 | 4.55k | getTrailingObjects<TemplateArgumentLoc>(), List); |
1384 | 4.57k | } |
1385 | | |
1386 | | /// Retrieve the template arguments provided as part of this |
1387 | | /// template-id. |
1388 | 27.7M | const TemplateArgumentLoc *getTemplateArgs() const { |
1389 | 27.7M | if (!hasExplicitTemplateArgs()) |
1390 | 27.4M | return nullptr; |
1391 | 268k | return getTrailingObjects<TemplateArgumentLoc>(); |
1392 | 27.7M | } |
1393 | | |
1394 | | /// Retrieve the number of template arguments provided as part of this |
1395 | | /// template-id. |
1396 | 1.12M | unsigned getNumTemplateArgs() const { |
1397 | 1.12M | if (!hasExplicitTemplateArgs()) |
1398 | 848k | return 0; |
1399 | 275k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; |
1400 | 1.12M | } |
1401 | | |
1402 | 13.7k | ArrayRef<TemplateArgumentLoc> template_arguments() const { |
1403 | 13.7k | return {getTemplateArgs(), getNumTemplateArgs()}; |
1404 | 13.7k | } |
1405 | | |
1406 | | /// Returns true if this expression refers to a function that |
1407 | | /// was resolved from an overloaded set having size greater than 1. |
1408 | 2.93M | bool hadMultipleCandidates() const { |
1409 | 2.93M | return DeclRefExprBits.HadMultipleCandidates; |
1410 | 2.93M | } |
1411 | | /// Sets the flag telling whether this expression refers to |
1412 | | /// a function that was resolved from an overloaded set having size |
1413 | | /// greater than 1. |
1414 | 893k | void setHadMultipleCandidates(bool V = true) { |
1415 | 893k | DeclRefExprBits.HadMultipleCandidates = V; |
1416 | 893k | } |
1417 | | |
1418 | | /// Is this expression a non-odr-use reference, and if so, why? |
1419 | 34.2M | NonOdrUseReason isNonOdrUse() const { |
1420 | 34.2M | return static_cast<NonOdrUseReason>(DeclRefExprBits.NonOdrUseReason); |
1421 | 34.2M | } |
1422 | | |
1423 | | /// Does this DeclRefExpr refer to an enclosing local or a captured |
1424 | | /// variable? |
1425 | 8.08M | bool refersToEnclosingVariableOrCapture() const { |
1426 | 8.08M | return DeclRefExprBits.RefersToEnclosingVariableOrCapture; |
1427 | 8.08M | } |
1428 | | |
1429 | 129M | static bool classof(const Stmt *T) { |
1430 | 129M | return T->getStmtClass() == DeclRefExprClass; |
1431 | 129M | } |
1432 | | |
1433 | | // Iterators |
1434 | 22.2M | child_range children() { |
1435 | 22.2M | return child_range(child_iterator(), child_iterator()); |
1436 | 22.2M | } |
1437 | | |
1438 | 0 | const_child_range children() const { |
1439 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1440 | 0 | } |
1441 | | }; |
1442 | | |
1443 | | /// Used by IntegerLiteral/FloatingLiteral to store the numeric without |
1444 | | /// leaking memory. |
1445 | | /// |
1446 | | /// For large floats/integers, APFloat/APInt will allocate memory from the heap |
1447 | | /// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator |
1448 | | /// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with |
1449 | | /// the APFloat/APInt values will never get freed. APNumericStorage uses |
1450 | | /// ASTContext's allocator for memory allocation. |
1451 | | class APNumericStorage { |
1452 | | union { |
1453 | | uint64_t VAL; ///< Used to store the <= 64 bits integer value. |
1454 | | uint64_t *pVal; ///< Used to store the >64 bits integer value. |
1455 | | }; |
1456 | | unsigned BitWidth; |
1457 | | |
1458 | 10.6M | bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } |
1459 | | |
1460 | | APNumericStorage(const APNumericStorage &) = delete; |
1461 | | void operator=(const APNumericStorage &) = delete; |
1462 | | |
1463 | | protected: |
1464 | 10.6M | APNumericStorage() : VAL(0), BitWidth(0) { } |
1465 | | |
1466 | 21.0M | llvm::APInt getIntValue() const { |
1467 | 21.0M | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
1468 | 21.0M | if (NumWords > 1) |
1469 | 6.45k | return llvm::APInt(BitWidth, NumWords, pVal); |
1470 | 21.0M | else |
1471 | 21.0M | return llvm::APInt(BitWidth, VAL); |
1472 | 21.0M | } |
1473 | | void setIntValue(const ASTContext &C, const llvm::APInt &Val); |
1474 | | }; |
1475 | | |
1476 | | class APIntStorage : private APNumericStorage { |
1477 | | public: |
1478 | 20.9M | llvm::APInt getValue() const { return getIntValue(); } |
1479 | 10.6M | void setValue(const ASTContext &C, const llvm::APInt &Val) { |
1480 | 10.6M | setIntValue(C, Val); |
1481 | 10.6M | } |
1482 | | }; |
1483 | | |
1484 | | class APFloatStorage : private APNumericStorage { |
1485 | | public: |
1486 | 70.7k | llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const { |
1487 | 70.7k | return llvm::APFloat(Semantics, getIntValue()); |
1488 | 70.7k | } |
1489 | 55.2k | void setValue(const ASTContext &C, const llvm::APFloat &Val) { |
1490 | 55.2k | setIntValue(C, Val.bitcastToAPInt()); |
1491 | 55.2k | } |
1492 | | }; |
1493 | | |
1494 | | class IntegerLiteral : public Expr, public APIntStorage { |
1495 | | SourceLocation Loc; |
1496 | | |
1497 | | /// Construct an empty integer literal. |
1498 | | explicit IntegerLiteral(EmptyShell Empty) |
1499 | 497k | : Expr(IntegerLiteralClass, Empty) { } |
1500 | | |
1501 | | public: |
1502 | | // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, |
1503 | | // or UnsignedLongLongTy |
1504 | | IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type, |
1505 | | SourceLocation l); |
1506 | | |
1507 | | /// Returns a new integer literal with value 'V' and type 'type'. |
1508 | | /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, |
1509 | | /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V |
1510 | | /// \param V - the value that the returned integer literal contains. |
1511 | | static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V, |
1512 | | QualType type, SourceLocation l); |
1513 | | /// Returns a new empty integer literal. |
1514 | | static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty); |
1515 | | |
1516 | 25.1M | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
1517 | 1.07M | SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } |
1518 | | |
1519 | | /// Retrieve the location of the literal. |
1520 | 703k | SourceLocation getLocation() const { return Loc; } |
1521 | | |
1522 | 497k | void setLocation(SourceLocation Location) { Loc = Location; } |
1523 | | |
1524 | 13.8M | static bool classof(const Stmt *T) { |
1525 | 13.8M | return T->getStmtClass() == IntegerLiteralClass; |
1526 | 13.8M | } |
1527 | | |
1528 | | // Iterators |
1529 | 15.8M | child_range children() { |
1530 | 15.8M | return child_range(child_iterator(), child_iterator()); |
1531 | 15.8M | } |
1532 | 0 | const_child_range children() const { |
1533 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1534 | 0 | } |
1535 | | }; |
1536 | | |
1537 | | class FixedPointLiteral : public Expr, public APIntStorage { |
1538 | | SourceLocation Loc; |
1539 | | unsigned Scale; |
1540 | | |
1541 | | /// \brief Construct an empty fixed-point literal. |
1542 | | explicit FixedPointLiteral(EmptyShell Empty) |
1543 | 56 | : Expr(FixedPointLiteralClass, Empty) {} |
1544 | | |
1545 | | public: |
1546 | | FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type, |
1547 | | SourceLocation l, unsigned Scale); |
1548 | | |
1549 | | // Store the int as is without any bit shifting. |
1550 | | static FixedPointLiteral *CreateFromRawInt(const ASTContext &C, |
1551 | | const llvm::APInt &V, |
1552 | | QualType type, SourceLocation l, |
1553 | | unsigned Scale); |
1554 | | |
1555 | | /// Returns an empty fixed-point literal. |
1556 | | static FixedPointLiteral *Create(const ASTContext &C, EmptyShell Empty); |
1557 | | |
1558 | 2.81k | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
1559 | 328 | SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } |
1560 | | |
1561 | | /// \brief Retrieve the location of the literal. |
1562 | 64 | SourceLocation getLocation() const { return Loc; } |
1563 | | |
1564 | 56 | void setLocation(SourceLocation Location) { Loc = Location; } |
1565 | | |
1566 | 56 | unsigned getScale() const { return Scale; } |
1567 | 56 | void setScale(unsigned S) { Scale = S; } |
1568 | | |
1569 | 0 | static bool classof(const Stmt *T) { |
1570 | 0 | return T->getStmtClass() == FixedPointLiteralClass; |
1571 | 0 | } |
1572 | | |
1573 | | std::string getValueAsString(unsigned Radix) const; |
1574 | | |
1575 | | // Iterators |
1576 | 1.76k | child_range children() { |
1577 | 1.76k | return child_range(child_iterator(), child_iterator()); |
1578 | 1.76k | } |
1579 | 0 | const_child_range children() const { |
1580 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1581 | 0 | } |
1582 | | }; |
1583 | | |
1584 | | class CharacterLiteral : public Expr { |
1585 | | public: |
1586 | | enum CharacterKind { |
1587 | | Ascii, |
1588 | | Wide, |
1589 | | UTF8, |
1590 | | UTF16, |
1591 | | UTF32 |
1592 | | }; |
1593 | | |
1594 | | private: |
1595 | | unsigned Value; |
1596 | | SourceLocation Loc; |
1597 | | public: |
1598 | | // type should be IntTy |
1599 | | CharacterLiteral(unsigned value, CharacterKind kind, QualType type, |
1600 | | SourceLocation l) |
1601 | | : Expr(CharacterLiteralClass, type, VK_PRValue, OK_Ordinary), |
1602 | 593k | Value(value), Loc(l) { |
1603 | 593k | CharacterLiteralBits.Kind = kind; |
1604 | 593k | setDependence(ExprDependence::None); |
1605 | 593k | } |
1606 | | |
1607 | | /// Construct an empty character literal. |
1608 | 26.1k | CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } |
1609 | | |
1610 | 61.5k | SourceLocation getLocation() const { return Loc; } |
1611 | 85.2k | CharacterKind getKind() const { |
1612 | 85.2k | return static_cast<CharacterKind>(CharacterLiteralBits.Kind); |
1613 | 85.2k | } |
1614 | | |
1615 | 1.93M | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
1616 | 24.2k | SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } |
1617 | | |
1618 | 804k | unsigned getValue() const { return Value; } |
1619 | | |
1620 | 26.1k | void setLocation(SourceLocation Location) { Loc = Location; } |
1621 | 26.1k | void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; } |
1622 | 26.1k | void setValue(unsigned Val) { Value = Val; } |
1623 | | |
1624 | 2.80M | static bool classof(const Stmt *T) { |
1625 | 2.80M | return T->getStmtClass() == CharacterLiteralClass; |
1626 | 2.80M | } |
1627 | | |
1628 | | static void print(unsigned val, CharacterKind Kind, raw_ostream &OS); |
1629 | | |
1630 | | // Iterators |
1631 | 234k | child_range children() { |
1632 | 234k | return child_range(child_iterator(), child_iterator()); |
1633 | 234k | } |
1634 | 0 | const_child_range children() const { |
1635 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1636 | 0 | } |
1637 | | }; |
1638 | | |
1639 | | class FloatingLiteral : public Expr, private APFloatStorage { |
1640 | | SourceLocation Loc; |
1641 | | |
1642 | | FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact, |
1643 | | QualType Type, SourceLocation L); |
1644 | | |
1645 | | /// Construct an empty floating-point literal. |
1646 | | explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty); |
1647 | | |
1648 | | public: |
1649 | | static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V, |
1650 | | bool isexact, QualType Type, SourceLocation L); |
1651 | | static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty); |
1652 | | |
1653 | 70.7k | llvm::APFloat getValue() const { |
1654 | 70.7k | return APFloatStorage::getValue(getSemantics()); |
1655 | 70.7k | } |
1656 | 55.2k | void setValue(const ASTContext &C, const llvm::APFloat &Val) { |
1657 | 55.2k | assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics"); |
1658 | 0 | APFloatStorage::setValue(C, Val); |
1659 | 55.2k | } |
1660 | | |
1661 | | /// Get a raw enumeration value representing the floating-point semantics of |
1662 | | /// this literal (32-bit IEEE, x87, ...), suitable for serialisation. |
1663 | 3.49k | llvm::APFloatBase::Semantics getRawSemantics() const { |
1664 | 3.49k | return static_cast<llvm::APFloatBase::Semantics>( |
1665 | 3.49k | FloatingLiteralBits.Semantics); |
1666 | 3.49k | } |
1667 | | |
1668 | | /// Set the raw enumeration value representing the floating-point semantics of |
1669 | | /// this literal (32-bit IEEE, x87, ...), suitable for serialisation. |
1670 | 13.0k | void setRawSemantics(llvm::APFloatBase::Semantics Sem) { |
1671 | 13.0k | FloatingLiteralBits.Semantics = Sem; |
1672 | 13.0k | } |
1673 | | |
1674 | | /// Return the APFloat semantics this literal uses. |
1675 | 132k | const llvm::fltSemantics &getSemantics() const { |
1676 | 132k | return llvm::APFloatBase::EnumToSemantics( |
1677 | 132k | static_cast<llvm::APFloatBase::Semantics>( |
1678 | 132k | FloatingLiteralBits.Semantics)); |
1679 | 132k | } |
1680 | | |
1681 | | /// Set the APFloat semantics this literal uses. |
1682 | 48.6k | void setSemantics(const llvm::fltSemantics &Sem) { |
1683 | 48.6k | FloatingLiteralBits.Semantics = llvm::APFloatBase::SemanticsToEnum(Sem); |
1684 | 48.6k | } |
1685 | | |
1686 | 12.1k | bool isExact() const { return FloatingLiteralBits.IsExact; } |
1687 | 6.54k | void setExact(bool E) { FloatingLiteralBits.IsExact = E; } |
1688 | | |
1689 | | /// getValueAsApproximateDouble - This returns the value as an inaccurate |
1690 | | /// double. Note that this may cause loss of precision, but is useful for |
1691 | | /// debugging dumps, etc. |
1692 | | double getValueAsApproximateDouble() const; |
1693 | | |
1694 | 8.64k | SourceLocation getLocation() const { return Loc; } |
1695 | 6.54k | void setLocation(SourceLocation L) { Loc = L; } |
1696 | | |
1697 | 224k | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
1698 | 12.5k | SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } |
1699 | | |
1700 | 201k | static bool classof(const Stmt *T) { |
1701 | 201k | return T->getStmtClass() == FloatingLiteralClass; |
1702 | 201k | } |
1703 | | |
1704 | | // Iterators |
1705 | 117k | child_range children() { |
1706 | 117k | return child_range(child_iterator(), child_iterator()); |
1707 | 117k | } |
1708 | 0 | const_child_range children() const { |
1709 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1710 | 0 | } |
1711 | | }; |
1712 | | |
1713 | | /// ImaginaryLiteral - We support imaginary integer and floating point literals, |
1714 | | /// like "1.0i". We represent these as a wrapper around FloatingLiteral and |
1715 | | /// IntegerLiteral classes. Instances of this class always have a Complex type |
1716 | | /// whose element type matches the subexpression. |
1717 | | /// |
1718 | | class ImaginaryLiteral : public Expr { |
1719 | | Stmt *Val; |
1720 | | public: |
1721 | | ImaginaryLiteral(Expr *val, QualType Ty) |
1722 | 368 | : Expr(ImaginaryLiteralClass, Ty, VK_PRValue, OK_Ordinary), Val(val) { |
1723 | 368 | setDependence(ExprDependence::None); |
1724 | 368 | } |
1725 | | |
1726 | | /// Build an empty imaginary literal. |
1727 | | explicit ImaginaryLiteral(EmptyShell Empty) |
1728 | 5 | : Expr(ImaginaryLiteralClass, Empty) { } |
1729 | | |
1730 | 554 | const Expr *getSubExpr() const { return cast<Expr>(Val); } |
1731 | 31 | Expr *getSubExpr() { return cast<Expr>(Val); } |
1732 | 5 | void setSubExpr(Expr *E) { Val = E; } |
1733 | | |
1734 | 990 | SourceLocation getBeginLoc() const LLVM_READONLY { |
1735 | 990 | return Val->getBeginLoc(); |
1736 | 990 | } |
1737 | 137 | SourceLocation getEndLoc() const LLVM_READONLY { return Val->getEndLoc(); } |
1738 | | |
1739 | 2 | static bool classof(const Stmt *T) { |
1740 | 2 | return T->getStmtClass() == ImaginaryLiteralClass; |
1741 | 2 | } |
1742 | | |
1743 | | // Iterators |
1744 | 880 | child_range children() { return child_range(&Val, &Val+1); } |
1745 | 0 | const_child_range children() const { |
1746 | 0 | return const_child_range(&Val, &Val + 1); |
1747 | 0 | } |
1748 | | }; |
1749 | | |
1750 | | /// StringLiteral - This represents a string literal expression, e.g. "foo" |
1751 | | /// or L"bar" (wide strings). The actual string data can be obtained with |
1752 | | /// getBytes() and is NOT null-terminated. The length of the string data is |
1753 | | /// determined by calling getByteLength(). |
1754 | | /// |
1755 | | /// The C type for a string is always a ConstantArrayType. In C++, the char |
1756 | | /// type is const qualified, in C it is not. |
1757 | | /// |
1758 | | /// Note that strings in C can be formed by concatenation of multiple string |
1759 | | /// literal pptokens in translation phase #6. This keeps track of the locations |
1760 | | /// of each of these pieces. |
1761 | | /// |
1762 | | /// Strings in C can also be truncated and extended by assigning into arrays, |
1763 | | /// e.g. with constructs like: |
1764 | | /// char X[2] = "foobar"; |
1765 | | /// In this case, getByteLength() will return 6, but the string literal will |
1766 | | /// have type "char[2]". |
1767 | | class StringLiteral final |
1768 | | : public Expr, |
1769 | | private llvm::TrailingObjects<StringLiteral, unsigned, SourceLocation, |
1770 | | char> { |
1771 | | friend class ASTStmtReader; |
1772 | | friend TrailingObjects; |
1773 | | |
1774 | | /// StringLiteral is followed by several trailing objects. They are in order: |
1775 | | /// |
1776 | | /// * A single unsigned storing the length in characters of this string. The |
1777 | | /// length in bytes is this length times the width of a single character. |
1778 | | /// Always present and stored as a trailing objects because storing it in |
1779 | | /// StringLiteral would increase the size of StringLiteral by sizeof(void *) |
1780 | | /// due to alignment requirements. If you add some data to StringLiteral, |
1781 | | /// consider moving it inside StringLiteral. |
1782 | | /// |
1783 | | /// * An array of getNumConcatenated() SourceLocation, one for each of the |
1784 | | /// token this string is made of. |
1785 | | /// |
1786 | | /// * An array of getByteLength() char used to store the string data. |
1787 | | |
1788 | | public: |
1789 | | enum StringKind { Ordinary, Wide, UTF8, UTF16, UTF32 }; |
1790 | | |
1791 | | private: |
1792 | 21.9M | unsigned numTrailingObjects(OverloadToken<unsigned>) const { return 1; } |
1793 | 11.1M | unsigned numTrailingObjects(OverloadToken<SourceLocation>) const { |
1794 | 11.1M | return getNumConcatenated(); |
1795 | 11.1M | } |
1796 | | |
1797 | 0 | unsigned numTrailingObjects(OverloadToken<char>) const { |
1798 | 0 | return getByteLength(); |
1799 | 0 | } |
1800 | | |
1801 | 27.8k | char *getStrDataAsChar() { return getTrailingObjects<char>(); } |
1802 | 5.63M | const char *getStrDataAsChar() const { return getTrailingObjects<char>(); } |
1803 | | |
1804 | 3.29k | const uint16_t *getStrDataAsUInt16() const { |
1805 | 3.29k | return reinterpret_cast<const uint16_t *>(getTrailingObjects<char>()); |
1806 | 3.29k | } |
1807 | | |
1808 | 7.16k | const uint32_t *getStrDataAsUInt32() const { |
1809 | 7.16k | return reinterpret_cast<const uint32_t *>(getTrailingObjects<char>()); |
1810 | 7.16k | } |
1811 | | |
1812 | | /// Build a string literal. |
1813 | | StringLiteral(const ASTContext &Ctx, StringRef Str, StringKind Kind, |
1814 | | bool Pascal, QualType Ty, const SourceLocation *Loc, |
1815 | | unsigned NumConcatenated); |
1816 | | |
1817 | | /// Build an empty string literal. |
1818 | | StringLiteral(EmptyShell Empty, unsigned NumConcatenated, unsigned Length, |
1819 | | unsigned CharByteWidth); |
1820 | | |
1821 | | /// Map a target and string kind to the appropriate character width. |
1822 | | static unsigned mapCharByteWidth(TargetInfo const &Target, StringKind SK); |
1823 | | |
1824 | | /// Set one of the string literal token. |
1825 | 29.8k | void setStrTokenLoc(unsigned TokNum, SourceLocation L) { |
1826 | 29.8k | assert(TokNum < getNumConcatenated() && "Invalid tok number"); |
1827 | 0 | getTrailingObjects<SourceLocation>()[TokNum] = L; |
1828 | 29.8k | } |
1829 | | |
1830 | | public: |
1831 | | /// This is the "fully general" constructor that allows representation of |
1832 | | /// strings formed from multiple concatenated tokens. |
1833 | | static StringLiteral *Create(const ASTContext &Ctx, StringRef Str, |
1834 | | StringKind Kind, bool Pascal, QualType Ty, |
1835 | | const SourceLocation *Loc, |
1836 | | unsigned NumConcatenated); |
1837 | | |
1838 | | /// Simple constructor for string literals made from one token. |
1839 | | static StringLiteral *Create(const ASTContext &Ctx, StringRef Str, |
1840 | | StringKind Kind, bool Pascal, QualType Ty, |
1841 | 1.42k | SourceLocation Loc) { |
1842 | 1.42k | return Create(Ctx, Str, Kind, Pascal, Ty, &Loc, 1); |
1843 | 1.42k | } |
1844 | | |
1845 | | /// Construct an empty string literal. |
1846 | | static StringLiteral *CreateEmpty(const ASTContext &Ctx, |
1847 | | unsigned NumConcatenated, unsigned Length, |
1848 | | unsigned CharByteWidth); |
1849 | | |
1850 | 5.45M | StringRef getString() const { |
1851 | 5.45M | assert(getCharByteWidth() == 1 && |
1852 | 5.45M | "This function is used in places that assume strings use char"); |
1853 | 0 | return StringRef(getStrDataAsChar(), getByteLength()); |
1854 | 5.45M | } |
1855 | | |
1856 | | /// Allow access to clients that need the byte representation, such as |
1857 | | /// ASTWriterStmt::VisitStringLiteral(). |
1858 | 43.9k | StringRef getBytes() const { |
1859 | | // FIXME: StringRef may not be the right type to use as a result for this. |
1860 | 43.9k | return StringRef(getStrDataAsChar(), getByteLength()); |
1861 | 43.9k | } |
1862 | | |
1863 | | void outputString(raw_ostream &OS) const; |
1864 | | |
1865 | 140k | uint32_t getCodeUnit(size_t i) const { |
1866 | 140k | assert(i < getLength() && "out of bounds access"); |
1867 | 0 | switch (getCharByteWidth()) { |
1868 | 129k | case 1: |
1869 | 129k | return static_cast<unsigned char>(getStrDataAsChar()[i]); |
1870 | 3.29k | case 2: |
1871 | 3.29k | return getStrDataAsUInt16()[i]; |
1872 | 7.16k | case 4: |
1873 | 7.16k | return getStrDataAsUInt32()[i]; |
1874 | 140k | } |
1875 | 0 | llvm_unreachable("Unsupported character width!"); |
1876 | 0 | } |
1877 | | |
1878 | 5.51M | unsigned getByteLength() const { return getCharByteWidth() * getLength(); } |
1879 | 5.75M | unsigned getLength() const { return *getTrailingObjects<unsigned>(); } |
1880 | 11.2M | unsigned getCharByteWidth() const { return StringLiteralBits.CharByteWidth; } |
1881 | | |
1882 | 5.33M | StringKind getKind() const { |
1883 | 5.33M | return static_cast<StringKind>(StringLiteralBits.Kind); |
1884 | 5.33M | } |
1885 | | |
1886 | 5.18M | bool isOrdinary() const { return getKind() == Ordinary; } |
1887 | 5.11k | bool isWide() const { return getKind() == Wide; } |
1888 | 17 | bool isUTF8() const { return getKind() == UTF8; } |
1889 | 0 | bool isUTF16() const { return getKind() == UTF16; } |
1890 | 0 | bool isUTF32() const { return getKind() == UTF32; } |
1891 | 35.0k | bool isPascal() const { return StringLiteralBits.IsPascal; } |
1892 | | |
1893 | 3 | bool containsNonAscii() const { |
1894 | 3 | for (auto c : getString()) |
1895 | 25 | if (!isASCII(c)) |
1896 | 0 | return true; |
1897 | 3 | return false; |
1898 | 3 | } |
1899 | | |
1900 | 11.7k | bool containsNonAsciiOrNull() const { |
1901 | 11.7k | for (auto c : getString()) |
1902 | 372k | if (!isASCII(c) || !c372k ) |
1903 | 397 | return true; |
1904 | 11.4k | return false; |
1905 | 11.7k | } |
1906 | | |
1907 | | /// getNumConcatenated - Get the number of string literal tokens that were |
1908 | | /// concatenated in translation phase #6 to form this string literal. |
1909 | 11.5M | unsigned getNumConcatenated() const { |
1910 | 11.5M | return StringLiteralBits.NumConcatenated; |
1911 | 11.5M | } |
1912 | | |
1913 | | /// Get one of the string literal token. |
1914 | 214k | SourceLocation getStrTokenLoc(unsigned TokNum) const { |
1915 | 214k | assert(TokNum < getNumConcatenated() && "Invalid tok number"); |
1916 | 0 | return getTrailingObjects<SourceLocation>()[TokNum]; |
1917 | 214k | } |
1918 | | |
1919 | | /// getLocationOfByte - Return a source location that points to the specified |
1920 | | /// byte of this string literal. |
1921 | | /// |
1922 | | /// Strings are amazingly complex. They can be formed from multiple tokens |
1923 | | /// and can have escape sequences in them in addition to the usual trigraph |
1924 | | /// and escaped newline business. This routine handles this complexity. |
1925 | | /// |
1926 | | SourceLocation |
1927 | | getLocationOfByte(unsigned ByteNo, const SourceManager &SM, |
1928 | | const LangOptions &Features, const TargetInfo &Target, |
1929 | | unsigned *StartToken = nullptr, |
1930 | | unsigned *StartTokenByteOffset = nullptr) const; |
1931 | | |
1932 | | typedef const SourceLocation *tokloc_iterator; |
1933 | | |
1934 | 5.06M | tokloc_iterator tokloc_begin() const { |
1935 | 5.06M | return getTrailingObjects<SourceLocation>(); |
1936 | 5.06M | } |
1937 | | |
1938 | 78.6k | tokloc_iterator tokloc_end() const { |
1939 | 78.6k | return getTrailingObjects<SourceLocation>() + getNumConcatenated(); |
1940 | 78.6k | } |
1941 | | |
1942 | 5.03M | SourceLocation getBeginLoc() const LLVM_READONLY { return *tokloc_begin(); } |
1943 | 51.7k | SourceLocation getEndLoc() const LLVM_READONLY { return *(tokloc_end() - 1); } |
1944 | | |
1945 | 12.0M | static bool classof(const Stmt *T) { |
1946 | 12.0M | return T->getStmtClass() == StringLiteralClass; |
1947 | 12.0M | } |
1948 | | |
1949 | | // Iterators |
1950 | 383k | child_range children() { |
1951 | 383k | return child_range(child_iterator(), child_iterator()); |
1952 | 383k | } |
1953 | 0 | const_child_range children() const { |
1954 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
1955 | 0 | } |
1956 | | }; |
1957 | | |
1958 | | /// [C99 6.4.2.2] - A predefined identifier such as __func__. |
1959 | | class PredefinedExpr final |
1960 | | : public Expr, |
1961 | | private llvm::TrailingObjects<PredefinedExpr, Stmt *> { |
1962 | | friend class ASTStmtReader; |
1963 | | friend TrailingObjects; |
1964 | | |
1965 | | // PredefinedExpr is optionally followed by a single trailing |
1966 | | // "Stmt *" for the predefined identifier. It is present if and only if |
1967 | | // hasFunctionName() is true and is always a "StringLiteral *". |
1968 | | |
1969 | | public: |
1970 | | enum IdentKind { |
1971 | | Func, |
1972 | | Function, |
1973 | | LFunction, // Same as Function, but as wide string. |
1974 | | FuncDName, |
1975 | | FuncSig, |
1976 | | LFuncSig, // Same as FuncSig, but as as wide string |
1977 | | PrettyFunction, |
1978 | | /// The same as PrettyFunction, except that the |
1979 | | /// 'virtual' keyword is omitted for virtual member functions. |
1980 | | PrettyFunctionNoVirtual |
1981 | | }; |
1982 | | |
1983 | | private: |
1984 | | PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK, |
1985 | | StringLiteral *SL); |
1986 | | |
1987 | | explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName); |
1988 | | |
1989 | | /// True if this PredefinedExpr has storage for a function name. |
1990 | 7.76k | bool hasFunctionName() const { return PredefinedExprBits.HasFunctionName; } |
1991 | | |
1992 | 833 | void setFunctionName(StringLiteral *SL) { |
1993 | 833 | assert(hasFunctionName() && |
1994 | 833 | "This PredefinedExpr has no storage for a function name!"); |
1995 | 0 | *getTrailingObjects<Stmt *>() = SL; |
1996 | 833 | } |
1997 | | |
1998 | | public: |
1999 | | /// Create a PredefinedExpr. |
2000 | | static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L, |
2001 | | QualType FNTy, IdentKind IK, StringLiteral *SL); |
2002 | | |
2003 | | /// Create an empty PredefinedExpr. |
2004 | | static PredefinedExpr *CreateEmpty(const ASTContext &Ctx, |
2005 | | bool HasFunctionName); |
2006 | | |
2007 | 1.66k | IdentKind getIdentKind() const { |
2008 | 1.66k | return static_cast<IdentKind>(PredefinedExprBits.Kind); |
2009 | 1.66k | } |
2010 | | |
2011 | 11.3k | SourceLocation getLocation() const { return PredefinedExprBits.Loc; } |
2012 | 17 | void setLocation(SourceLocation L) { PredefinedExprBits.Loc = L; } |
2013 | | |
2014 | 43 | StringLiteral *getFunctionName() { |
2015 | 43 | return hasFunctionName() |
2016 | 43 | ? static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>())36 |
2017 | 43 | : nullptr7 ; |
2018 | 43 | } |
2019 | | |
2020 | 3.30k | const StringLiteral *getFunctionName() const { |
2021 | 3.30k | return hasFunctionName() |
2022 | 3.30k | ? static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>()) |
2023 | 3.30k | : nullptr0 ; |
2024 | 3.30k | } |
2025 | | |
2026 | | static StringRef getIdentKindName(IdentKind IK); |
2027 | 8 | StringRef getIdentKindName() const { |
2028 | 8 | return getIdentKindName(getIdentKind()); |
2029 | 8 | } |
2030 | | |
2031 | | static std::string ComputeName(IdentKind IK, const Decl *CurrentDecl); |
2032 | | |
2033 | 10.2k | SourceLocation getBeginLoc() const { return getLocation(); } |
2034 | 1.03k | SourceLocation getEndLoc() const { return getLocation(); } |
2035 | | |
2036 | 144k | static bool classof(const Stmt *T) { |
2037 | 144k | return T->getStmtClass() == PredefinedExprClass; |
2038 | 144k | } |
2039 | | |
2040 | | // Iterators |
2041 | 3.58k | child_range children() { |
2042 | 3.58k | return child_range(getTrailingObjects<Stmt *>(), |
2043 | 3.58k | getTrailingObjects<Stmt *>() + hasFunctionName()); |
2044 | 3.58k | } |
2045 | | |
2046 | 0 | const_child_range children() const { |
2047 | 0 | return const_child_range(getTrailingObjects<Stmt *>(), |
2048 | 0 | getTrailingObjects<Stmt *>() + hasFunctionName()); |
2049 | 0 | } |
2050 | | }; |
2051 | | |
2052 | | // This represents a use of the __builtin_sycl_unique_stable_name, which takes a |
2053 | | // type-id, and at CodeGen time emits a unique string representation of the |
2054 | | // type in a way that permits us to properly encode information about the SYCL |
2055 | | // kernels. |
2056 | | class SYCLUniqueStableNameExpr final : public Expr { |
2057 | | friend class ASTStmtReader; |
2058 | | SourceLocation OpLoc, LParen, RParen; |
2059 | | TypeSourceInfo *TypeInfo; |
2060 | | |
2061 | | SYCLUniqueStableNameExpr(EmptyShell Empty, QualType ResultTy); |
2062 | | SYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, |
2063 | | SourceLocation RParen, QualType ResultTy, |
2064 | | TypeSourceInfo *TSI); |
2065 | | |
2066 | 84 | void setTypeSourceInfo(TypeSourceInfo *Ty) { TypeInfo = Ty; } |
2067 | | |
2068 | 0 | void setLocation(SourceLocation L) { OpLoc = L; } |
2069 | 0 | void setLParenLocation(SourceLocation L) { LParen = L; } |
2070 | 0 | void setRParenLocation(SourceLocation L) { RParen = L; } |
2071 | | |
2072 | | public: |
2073 | 138 | TypeSourceInfo *getTypeSourceInfo() { return TypeInfo; } |
2074 | | |
2075 | 48 | const TypeSourceInfo *getTypeSourceInfo() const { return TypeInfo; } |
2076 | | |
2077 | | static SYCLUniqueStableNameExpr * |
2078 | | Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen, |
2079 | | SourceLocation RParen, TypeSourceInfo *TSI); |
2080 | | |
2081 | | static SYCLUniqueStableNameExpr *CreateEmpty(const ASTContext &Ctx); |
2082 | | |
2083 | 297 | SourceLocation getBeginLoc() const { return getLocation(); } |
2084 | 22 | SourceLocation getEndLoc() const { return RParen; } |
2085 | 341 | SourceLocation getLocation() const { return OpLoc; } |
2086 | 22 | SourceLocation getLParenLocation() const { return LParen; } |
2087 | 22 | SourceLocation getRParenLocation() const { return RParen; } |
2088 | | |
2089 | 27 | static bool classof(const Stmt *T) { |
2090 | 27 | return T->getStmtClass() == SYCLUniqueStableNameExprClass; |
2091 | 27 | } |
2092 | | |
2093 | | // Iterators |
2094 | 138 | child_range children() { |
2095 | 138 | return child_range(child_iterator(), child_iterator()); |
2096 | 138 | } |
2097 | | |
2098 | 0 | const_child_range children() const { |
2099 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
2100 | 0 | } |
2101 | | |
2102 | | // Convenience function to generate the name of the currently stored type. |
2103 | | std::string ComputeName(ASTContext &Context) const; |
2104 | | |
2105 | | // Get the generated name of the type. Note that this only works after all |
2106 | | // kernels have been instantiated. |
2107 | | static std::string ComputeName(ASTContext &Context, QualType Ty); |
2108 | | }; |
2109 | | |
2110 | | /// ParenExpr - This represents a parethesized expression, e.g. "(1)". This |
2111 | | /// AST node is only formed if full location information is requested. |
2112 | | class ParenExpr : public Expr { |
2113 | | SourceLocation L, R; |
2114 | | Stmt *Val; |
2115 | | public: |
2116 | | ParenExpr(SourceLocation l, SourceLocation r, Expr *val) |
2117 | | : Expr(ParenExprClass, val->getType(), val->getValueKind(), |
2118 | | val->getObjectKind()), |
2119 | 2.67M | L(l), R(r), Val(val) { |
2120 | 2.67M | setDependence(computeDependence(this)); |
2121 | 2.67M | } |
2122 | | |
2123 | | /// Construct an empty parenthesized expression. |
2124 | | explicit ParenExpr(EmptyShell Empty) |
2125 | 169k | : Expr(ParenExprClass, Empty) { } |
2126 | | |
2127 | 1.12M | const Expr *getSubExpr() const { return cast<Expr>(Val); } |
2128 | 16.1M | Expr *getSubExpr() { return cast<Expr>(Val); } |
2129 | 169k | void setSubExpr(Expr *E) { Val = E; } |
2130 | | |
2131 | 3.55M | SourceLocation getBeginLoc() const LLVM_READONLY { return L; } |
2132 | 640k | SourceLocation getEndLoc() const LLVM_READONLY { return R; } |
2133 | | |
2134 | | /// Get the location of the left parentheses '('. |
2135 | 360k | SourceLocation getLParen() const { return L; } |
2136 | 169k | void setLParen(SourceLocation Loc) { L = Loc; } |
2137 | | |
2138 | | /// Get the location of the right parentheses ')'. |
2139 | 360k | SourceLocation getRParen() const { return R; } |
2140 | 169k | void setRParen(SourceLocation Loc) { R = Loc; } |
2141 | | |
2142 | 419M | static bool classof(const Stmt *T) { |
2143 | 419M | return T->getStmtClass() == ParenExprClass; |
2144 | 419M | } |
2145 | | |
2146 | | // Iterators |
2147 | 2.74M | child_range children() { return child_range(&Val, &Val+1); } |
2148 | 0 | const_child_range children() const { |
2149 | 0 | return const_child_range(&Val, &Val + 1); |
2150 | 0 | } |
2151 | | }; |
2152 | | |
2153 | | /// UnaryOperator - This represents the unary-expression's (except sizeof and |
2154 | | /// alignof), the postinc/postdec operators from postfix-expression, and various |
2155 | | /// extensions. |
2156 | | /// |
2157 | | /// Notes on various nodes: |
2158 | | /// |
2159 | | /// Real/Imag - These return the real/imag part of a complex operand. If |
2160 | | /// applied to a non-complex value, the former returns its operand and the |
2161 | | /// later returns zero in the type of the operand. |
2162 | | /// |
2163 | | class UnaryOperator final |
2164 | | : public Expr, |
2165 | | private llvm::TrailingObjects<UnaryOperator, FPOptionsOverride> { |
2166 | | Stmt *Val; |
2167 | | |
2168 | 0 | size_t numTrailingObjects(OverloadToken<FPOptionsOverride>) const { |
2169 | 0 | return UnaryOperatorBits.HasFPFeatures ? 1 : 0; |
2170 | 0 | } |
2171 | | |
2172 | 6.05k | FPOptionsOverride &getTrailingFPFeatures() { |
2173 | 6.05k | assert(UnaryOperatorBits.HasFPFeatures); |
2174 | 0 | return *getTrailingObjects<FPOptionsOverride>(); |
2175 | 6.05k | } |
2176 | | |
2177 | 75 | const FPOptionsOverride &getTrailingFPFeatures() const { |
2178 | 75 | assert(UnaryOperatorBits.HasFPFeatures); |
2179 | 0 | return *getTrailingObjects<FPOptionsOverride>(); |
2180 | 75 | } |
2181 | | |
2182 | | public: |
2183 | | typedef UnaryOperatorKind Opcode; |
2184 | | |
2185 | | protected: |
2186 | | UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type, |
2187 | | ExprValueKind VK, ExprObjectKind OK, SourceLocation l, |
2188 | | bool CanOverflow, FPOptionsOverride FPFeatures); |
2189 | | |
2190 | | /// Build an empty unary operator. |
2191 | | explicit UnaryOperator(bool HasFPFeatures, EmptyShell Empty) |
2192 | 349k | : Expr(UnaryOperatorClass, Empty) { |
2193 | 349k | UnaryOperatorBits.Opc = UO_AddrOf; |
2194 | 349k | UnaryOperatorBits.HasFPFeatures = HasFPFeatures; |
2195 | 349k | } |
2196 | | |
2197 | | public: |
2198 | | static UnaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures); |
2199 | | |
2200 | | static UnaryOperator *Create(const ASTContext &C, Expr *input, Opcode opc, |
2201 | | QualType type, ExprValueKind VK, |
2202 | | ExprObjectKind OK, SourceLocation l, |
2203 | | bool CanOverflow, FPOptionsOverride FPFeatures); |
2204 | | |
2205 | 28.5M | Opcode getOpcode() const { |
2206 | 28.5M | return static_cast<Opcode>(UnaryOperatorBits.Opc); |
2207 | 28.5M | } |
2208 | 349k | void setOpcode(Opcode Opc) { UnaryOperatorBits.Opc = Opc; } |
2209 | | |
2210 | 10.8M | Expr *getSubExpr() const { return cast<Expr>(Val); } |
2211 | 349k | void setSubExpr(Expr *E) { Val = E; } |
2212 | | |
2213 | | /// getOperatorLoc - Return the location of the operator. |
2214 | 8.37M | SourceLocation getOperatorLoc() const { return UnaryOperatorBits.Loc; } |
2215 | 349k | void setOperatorLoc(SourceLocation L) { UnaryOperatorBits.Loc = L; } |
2216 | | |
2217 | | /// Returns true if the unary operator can cause an overflow. For instance, |
2218 | | /// signed int i = INT_MAX; i++; |
2219 | | /// signed char c = CHAR_MAX; c++; |
2220 | | /// Due to integer promotions, c++ is promoted to an int before the postfix |
2221 | | /// increment, and the result is an int that cannot overflow. However, i++ |
2222 | | /// can overflow. |
2223 | 406k | bool canOverflow() const { return UnaryOperatorBits.CanOverflow; } |
2224 | 349k | void setCanOverflow(bool C) { UnaryOperatorBits.CanOverflow = C; } |
2225 | | |
2226 | | // Get the FP contractability status of this operator. Only meaningful for |
2227 | | // operations on floating point types. |
2228 | 0 | bool isFPContractableWithinStatement(const LangOptions &LO) const { |
2229 | 0 | return getFPFeaturesInEffect(LO).allowFPContractWithinStatement(); |
2230 | 0 | } |
2231 | | |
2232 | | // Get the FENV_ACCESS status of this operator. Only meaningful for |
2233 | | // operations on floating point types. |
2234 | 0 | bool isFEnvAccessOn(const LangOptions &LO) const { |
2235 | 0 | return getFPFeaturesInEffect(LO).getAllowFEnvAccess(); |
2236 | 0 | } |
2237 | | |
2238 | | /// isPostfix - Return true if this is a postfix operation, like x++. |
2239 | 4.57M | static bool isPostfix(Opcode Op) { |
2240 | 4.57M | return Op == UO_PostInc || Op == UO_PostDec4.35M ; |
2241 | 4.57M | } |
2242 | | |
2243 | | /// isPrefix - Return true if this is a prefix operation, like --x. |
2244 | 105k | static bool isPrefix(Opcode Op) { |
2245 | 105k | return Op == UO_PreInc || Op == UO_PreDec103k ; |
2246 | 105k | } |
2247 | | |
2248 | 105k | bool isPrefix() const { return isPrefix(getOpcode()); } |
2249 | 4.57M | bool isPostfix() const { return isPostfix(getOpcode()); } |
2250 | | |
2251 | 59.0k | static bool isIncrementOp(Opcode Op) { |
2252 | 59.0k | return Op == UO_PreInc || Op == UO_PostInc13.0k ; |
2253 | 59.0k | } |
2254 | 58.9k | bool isIncrementOp() const { |
2255 | 58.9k | return isIncrementOp(getOpcode()); |
2256 | 58.9k | } |
2257 | | |
2258 | 153k | static bool isDecrementOp(Opcode Op) { |
2259 | 153k | return Op == UO_PreDec || Op == UO_PostDec153k ; |
2260 | 153k | } |
2261 | 153k | bool isDecrementOp() const { |
2262 | 153k | return isDecrementOp(getOpcode()); |
2263 | 153k | } |
2264 | | |
2265 | 662k | static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; } |
2266 | 662k | bool isIncrementDecrementOp() const { |
2267 | 662k | return isIncrementDecrementOp(getOpcode()); |
2268 | 662k | } |
2269 | | |
2270 | 0 | static bool isArithmeticOp(Opcode Op) { |
2271 | 0 | return Op >= UO_Plus && Op <= UO_LNot; |
2272 | 0 | } |
2273 | 0 | bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } |
2274 | | |
2275 | | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
2276 | | /// corresponds to, e.g. "sizeof" or "[pre]++" |
2277 | | static StringRef getOpcodeStr(Opcode Op); |
2278 | | |
2279 | | /// Retrieve the unary opcode that corresponds to the given |
2280 | | /// overloaded operator. |
2281 | | static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); |
2282 | | |
2283 | | /// Retrieve the overloaded operator kind that corresponds to |
2284 | | /// the given unary opcode. |
2285 | | static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); |
2286 | | |
2287 | 3.93M | SourceLocation getBeginLoc() const LLVM_READONLY { |
2288 | 3.93M | return isPostfix() ? Val->getBeginLoc()157k : getOperatorLoc()3.77M ; |
2289 | 3.93M | } |
2290 | 530k | SourceLocation getEndLoc() const LLVM_READONLY { |
2291 | 530k | return isPostfix() ? getOperatorLoc()51.6k : Val->getEndLoc()479k ; |
2292 | 530k | } |
2293 | 3.71M | SourceLocation getExprLoc() const { return getOperatorLoc(); } |
2294 | | |
2295 | 699M | static bool classof(const Stmt *T) { |
2296 | 699M | return T->getStmtClass() == UnaryOperatorClass; |
2297 | 699M | } |
2298 | | |
2299 | | // Iterators |
2300 | 3.15M | child_range children() { return child_range(&Val, &Val+1); } |
2301 | 0 | const_child_range children() const { |
2302 | 0 | return const_child_range(&Val, &Val + 1); |
2303 | 0 | } |
2304 | | |
2305 | | /// Is FPFeatures in Trailing Storage? |
2306 | 3.64M | bool hasStoredFPFeatures() const { return UnaryOperatorBits.HasFPFeatures; } |
2307 | | |
2308 | | /// Get FPFeatures from trailing storage. |
2309 | 75 | FPOptionsOverride getStoredFPFeatures() const { |
2310 | 75 | return getTrailingFPFeatures(); |
2311 | 75 | } |
2312 | | |
2313 | | protected: |
2314 | | /// Set FPFeatures in trailing storage, used only by Serialization |
2315 | 6.05k | void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; } |
2316 | | |
2317 | | public: |
2318 | | // Get the FP features status of this operator. Only meaningful for |
2319 | | // operations on floating point types. |
2320 | 11.5k | FPOptions getFPFeaturesInEffect(const LangOptions &LO) const { |
2321 | 11.5k | if (UnaryOperatorBits.HasFPFeatures) |
2322 | 71 | return getStoredFPFeatures().applyOverrides(LO); |
2323 | 11.4k | return FPOptions::defaultWithoutTrailingStorage(LO); |
2324 | 11.5k | } |
2325 | 245k | FPOptionsOverride getFPOptionsOverride() const { |
2326 | 245k | if (UnaryOperatorBits.HasFPFeatures) |
2327 | 0 | return getStoredFPFeatures(); |
2328 | 245k | return FPOptionsOverride(); |
2329 | 245k | } |
2330 | | |
2331 | | friend TrailingObjects; |
2332 | | friend class ASTReader; |
2333 | | friend class ASTStmtReader; |
2334 | | friend class ASTStmtWriter; |
2335 | | }; |
2336 | | |
2337 | | /// Helper class for OffsetOfExpr. |
2338 | | |
2339 | | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
2340 | | class OffsetOfNode { |
2341 | | public: |
2342 | | /// The kind of offsetof node we have. |
2343 | | enum Kind { |
2344 | | /// An index into an array. |
2345 | | Array = 0x00, |
2346 | | /// A field. |
2347 | | Field = 0x01, |
2348 | | /// A field in a dependent type, known only by its name. |
2349 | | Identifier = 0x02, |
2350 | | /// An implicit indirection through a C++ base class, when the |
2351 | | /// field found is in a base class. |
2352 | | Base = 0x03 |
2353 | | }; |
2354 | | |
2355 | | private: |
2356 | | enum { MaskBits = 2, Mask = 0x03 }; |
2357 | | |
2358 | | /// The source range that covers this part of the designator. |
2359 | | SourceRange Range; |
2360 | | |
2361 | | /// The data describing the designator, which comes in three |
2362 | | /// different forms, depending on the lower two bits. |
2363 | | /// - An unsigned index into the array of Expr*'s stored after this node |
2364 | | /// in memory, for [constant-expression] designators. |
2365 | | /// - A FieldDecl*, for references to a known field. |
2366 | | /// - An IdentifierInfo*, for references to a field with a given name |
2367 | | /// when the class type is dependent. |
2368 | | /// - A CXXBaseSpecifier*, for references that look at a field in a |
2369 | | /// base class. |
2370 | | uintptr_t Data; |
2371 | | |
2372 | | public: |
2373 | | /// Create an offsetof node that refers to an array element. |
2374 | | OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, |
2375 | | SourceLocation RBracketLoc) |
2376 | 45 | : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) {} |
2377 | | |
2378 | | /// Create an offsetof node that refers to a field. |
2379 | | OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, SourceLocation NameLoc) |
2380 | | : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc), |
2381 | 370 | Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) {} |
2382 | | |
2383 | | /// Create an offsetof node that refers to an identifier. |
2384 | | OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, |
2385 | | SourceLocation NameLoc) |
2386 | | : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc), |
2387 | 18 | Data(reinterpret_cast<uintptr_t>(Name) | Identifier) {} |
2388 | | |
2389 | | /// Create an offsetof node that refers into a C++ base class. |
2390 | | explicit OffsetOfNode(const CXXBaseSpecifier *Base) |
2391 | 31 | : Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} |
2392 | | |
2393 | | /// Determine what kind of offsetof node this is. |
2394 | 2.61k | Kind getKind() const { return static_cast<Kind>(Data & Mask); } |
2395 | | |
2396 | | /// For an array element node, returns the index into the array |
2397 | | /// of expressions. |
2398 | 49 | unsigned getArrayExprIndex() const { |
2399 | 49 | assert(getKind() == Array); |
2400 | 0 | return Data >> 2; |
2401 | 49 | } |
2402 | | |
2403 | | /// For a field offsetof node, returns the field. |
2404 | 1.13k | FieldDecl *getField() const { |
2405 | 1.13k | assert(getKind() == Field); |
2406 | 0 | return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); |
2407 | 1.13k | } |
2408 | | |
2409 | | /// For a field or identifier offsetof node, returns the name of |
2410 | | /// the field. |
2411 | | IdentifierInfo *getFieldName() const; |
2412 | | |
2413 | | /// For a base class node, returns the base specifier. |
2414 | 62 | CXXBaseSpecifier *getBase() const { |
2415 | 62 | assert(getKind() == Base); |
2416 | 0 | return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); |
2417 | 62 | } |
2418 | | |
2419 | | /// Retrieve the source range that covers this offsetof node. |
2420 | | /// |
2421 | | /// For an array element node, the source range contains the locations of |
2422 | | /// the square brackets. For a field or identifier node, the source range |
2423 | | /// contains the location of the period (if there is one) and the |
2424 | | /// identifier. |
2425 | 42 | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
2426 | 3 | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
2427 | 37 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
2428 | | }; |
2429 | | |
2430 | | /// OffsetOfExpr - [C99 7.17] - This represents an expression of the form |
2431 | | /// offsetof(record-type, member-designator). For example, given: |
2432 | | /// @code |
2433 | | /// struct S { |
2434 | | /// float f; |
2435 | | /// double d; |
2436 | | /// }; |
2437 | | /// struct T { |
2438 | | /// int i; |
2439 | | /// struct S s[10]; |
2440 | | /// }; |
2441 | | /// @endcode |
2442 | | /// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). |
2443 | | |
2444 | | class OffsetOfExpr final |
2445 | | : public Expr, |
2446 | | private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> { |
2447 | | SourceLocation OperatorLoc, RParenLoc; |
2448 | | // Base type; |
2449 | | TypeSourceInfo *TSInfo; |
2450 | | // Number of sub-components (i.e. instances of OffsetOfNode). |
2451 | | unsigned NumComps; |
2452 | | // Number of sub-expressions (i.e. array subscript expressions). |
2453 | | unsigned NumExprs; |
2454 | | |
2455 | 686 | size_t numTrailingObjects(OverloadToken<OffsetOfNode>) const { |
2456 | 686 | return NumComps; |
2457 | 686 | } |
2458 | | |
2459 | | OffsetOfExpr(const ASTContext &C, QualType type, |
2460 | | SourceLocation OperatorLoc, TypeSourceInfo *tsi, |
2461 | | ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs, |
2462 | | SourceLocation RParenLoc); |
2463 | | |
2464 | | explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) |
2465 | | : Expr(OffsetOfExprClass, EmptyShell()), |
2466 | 3 | TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {} |
2467 | | |
2468 | | public: |
2469 | | |
2470 | | static OffsetOfExpr *Create(const ASTContext &C, QualType type, |
2471 | | SourceLocation OperatorLoc, TypeSourceInfo *tsi, |
2472 | | ArrayRef<OffsetOfNode> comps, |
2473 | | ArrayRef<Expr*> exprs, SourceLocation RParenLoc); |
2474 | | |
2475 | | static OffsetOfExpr *CreateEmpty(const ASTContext &C, |
2476 | | unsigned NumComps, unsigned NumExprs); |
2477 | | |
2478 | | /// getOperatorLoc - Return the location of the operator. |
2479 | 9 | SourceLocation getOperatorLoc() const { return OperatorLoc; } |
2480 | 3 | void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } |
2481 | | |
2482 | | /// Return the location of the right parentheses. |
2483 | 9 | SourceLocation getRParenLoc() const { return RParenLoc; } |
2484 | 3 | void setRParenLoc(SourceLocation R) { RParenLoc = R; } |
2485 | | |
2486 | 1.54k | TypeSourceInfo *getTypeSourceInfo() const { |
2487 | 1.54k | return TSInfo; |
2488 | 1.54k | } |
2489 | 3 | void setTypeSourceInfo(TypeSourceInfo *tsi) { |
2490 | 3 | TSInfo = tsi; |
2491 | 3 | } |
2492 | | |
2493 | 1.28k | const OffsetOfNode &getComponent(unsigned Idx) const { |
2494 | 1.28k | assert(Idx < NumComps && "Subscript out of range"); |
2495 | 0 | return getTrailingObjects<OffsetOfNode>()[Idx]; |
2496 | 1.28k | } |
2497 | | |
2498 | 460 | void setComponent(unsigned Idx, OffsetOfNode ON) { |
2499 | 460 | assert(Idx < NumComps && "Subscript out of range"); |
2500 | 0 | getTrailingObjects<OffsetOfNode>()[Idx] = ON; |
2501 | 460 | } |
2502 | | |
2503 | 1.11k | unsigned getNumComponents() const { |
2504 | 1.11k | return NumComps; |
2505 | 1.11k | } |
2506 | | |
2507 | 47 | Expr* getIndexExpr(unsigned Idx) { |
2508 | 47 | assert(Idx < NumExprs && "Subscript out of range"); |
2509 | 0 | return getTrailingObjects<Expr *>()[Idx]; |
2510 | 47 | } |
2511 | | |
2512 | 43 | const Expr *getIndexExpr(unsigned Idx) const { |
2513 | 43 | assert(Idx < NumExprs && "Subscript out of range"); |
2514 | 0 | return getTrailingObjects<Expr *>()[Idx]; |
2515 | 43 | } |
2516 | | |
2517 | 43 | void setIndexExpr(unsigned Idx, Expr* E) { |
2518 | 43 | assert(Idx < NumComps && "Subscript out of range"); |
2519 | 0 | getTrailingObjects<Expr *>()[Idx] = E; |
2520 | 43 | } |
2521 | | |
2522 | 371 | unsigned getNumExpressions() const { |
2523 | 371 | return NumExprs; |
2524 | 371 | } |
2525 | | |
2526 | 2.14k | SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; } |
2527 | 90 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
2528 | | |
2529 | 187 | static bool classof(const Stmt *T) { |
2530 | 187 | return T->getStmtClass() == OffsetOfExprClass; |
2531 | 187 | } |
2532 | | |
2533 | | // Iterators |
2534 | 553 | child_range children() { |
2535 | 553 | Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>()); |
2536 | 553 | return child_range(begin, begin + NumExprs); |
2537 | 553 | } |
2538 | 0 | const_child_range children() const { |
2539 | 0 | Stmt *const *begin = |
2540 | 0 | reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>()); |
2541 | 0 | return const_child_range(begin, begin + NumExprs); |
2542 | 0 | } |
2543 | | friend TrailingObjects; |
2544 | | }; |
2545 | | |
2546 | | /// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) |
2547 | | /// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and |
2548 | | /// vec_step (OpenCL 1.1 6.11.12). |
2549 | | class UnaryExprOrTypeTraitExpr : public Expr { |
2550 | | union { |
2551 | | TypeSourceInfo *Ty; |
2552 | | Stmt *Ex; |
2553 | | } Argument; |
2554 | | SourceLocation OpLoc, RParenLoc; |
2555 | | |
2556 | | public: |
2557 | | UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, |
2558 | | QualType resultType, SourceLocation op, |
2559 | | SourceLocation rp) |
2560 | | : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_PRValue, |
2561 | | OK_Ordinary), |
2562 | 138k | OpLoc(op), RParenLoc(rp) { |
2563 | 138k | assert(ExprKind <= UETT_Last && "invalid enum value!"); |
2564 | 0 | UnaryExprOrTypeTraitExprBits.Kind = ExprKind; |
2565 | 138k | assert(static_cast<unsigned>(ExprKind) == |
2566 | 138k | UnaryExprOrTypeTraitExprBits.Kind && |
2567 | 138k | "UnaryExprOrTypeTraitExprBits.Kind overflow!"); |
2568 | 0 | UnaryExprOrTypeTraitExprBits.IsType = true; |
2569 | 138k | Argument.Ty = TInfo; |
2570 | 138k | setDependence(computeDependence(this)); |
2571 | 138k | } |
2572 | | |
2573 | | UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, |
2574 | | QualType resultType, SourceLocation op, |
2575 | | SourceLocation rp); |
2576 | | |
2577 | | /// Construct an empty sizeof/alignof expression. |
2578 | | explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) |
2579 | 22.0k | : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } |
2580 | | |
2581 | 441k | UnaryExprOrTypeTrait getKind() const { |
2582 | 441k | return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind); |
2583 | 441k | } |
2584 | 22.0k | void setKind(UnaryExprOrTypeTrait K) { |
2585 | 22.0k | assert(K <= UETT_Last && "invalid enum value!"); |
2586 | 0 | UnaryExprOrTypeTraitExprBits.Kind = K; |
2587 | 22.0k | assert(static_cast<unsigned>(K) == UnaryExprOrTypeTraitExprBits.Kind && |
2588 | 22.0k | "UnaryExprOrTypeTraitExprBits.Kind overflow!"); |
2589 | 22.0k | } |
2590 | | |
2591 | 1.44M | bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; } |
2592 | 571k | QualType getArgumentType() const { |
2593 | 571k | return getArgumentTypeInfo()->getType(); |
2594 | 571k | } |
2595 | 660k | TypeSourceInfo *getArgumentTypeInfo() const { |
2596 | 660k | assert(isArgumentType() && "calling getArgumentType() when arg is expr"); |
2597 | 0 | return Argument.Ty; |
2598 | 660k | } |
2599 | 54.2k | Expr *getArgumentExpr() { |
2600 | 54.2k | assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); |
2601 | 0 | return static_cast<Expr*>(Argument.Ex); |
2602 | 54.2k | } |
2603 | 20.5k | const Expr *getArgumentExpr() const { |
2604 | 20.5k | return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); |
2605 | 20.5k | } |
2606 | | |
2607 | 2.77k | void setArgument(Expr *E) { |
2608 | 2.77k | Argument.Ex = E; |
2609 | 2.77k | UnaryExprOrTypeTraitExprBits.IsType = false; |
2610 | 2.77k | } |
2611 | 19.2k | void setArgument(TypeSourceInfo *TInfo) { |
2612 | 19.2k | Argument.Ty = TInfo; |
2613 | 19.2k | UnaryExprOrTypeTraitExprBits.IsType = true; |
2614 | 19.2k | } |
2615 | | |
2616 | | /// Gets the argument type, or the type of the argument expression, whichever |
2617 | | /// is appropriate. |
2618 | 183k | QualType getTypeOfArgument() const { |
2619 | 183k | return isArgumentType() ? getArgumentType()166k : getArgumentExpr()->getType()16.9k ; |
2620 | 183k | } |
2621 | | |
2622 | 71.9k | SourceLocation getOperatorLoc() const { return OpLoc; } |
2623 | 22.0k | void setOperatorLoc(SourceLocation L) { OpLoc = L; } |
2624 | | |
2625 | 30.4k | SourceLocation getRParenLoc() const { return RParenLoc; } |
2626 | 22.0k | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
2627 | | |
2628 | 466k | SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; } |
2629 | 48.7k | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
2630 | | |
2631 | 34.2M | static bool classof(const Stmt *T) { |
2632 | 34.2M | return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; |
2633 | 34.2M | } |
2634 | | |
2635 | | // Iterators |
2636 | | child_range children(); |
2637 | | const_child_range children() const; |
2638 | | }; |
2639 | | |
2640 | | //===----------------------------------------------------------------------===// |
2641 | | // Postfix Operators. |
2642 | | //===----------------------------------------------------------------------===// |
2643 | | |
2644 | | /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. |
2645 | | class ArraySubscriptExpr : public Expr { |
2646 | | enum { LHS, RHS, END_EXPR }; |
2647 | | Stmt *SubExprs[END_EXPR]; |
2648 | | |
2649 | 4.83M | bool lhsIsBase() const { return getRHS()->getType()->isIntegerType(); } |
2650 | | |
2651 | | public: |
2652 | | ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, |
2653 | | ExprObjectKind OK, SourceLocation rbracketloc) |
2654 | 401k | : Expr(ArraySubscriptExprClass, t, VK, OK) { |
2655 | 401k | SubExprs[LHS] = lhs; |
2656 | 401k | SubExprs[RHS] = rhs; |
2657 | 401k | ArrayOrMatrixSubscriptExprBits.RBracketLoc = rbracketloc; |
2658 | 401k | setDependence(computeDependence(this)); |
2659 | 401k | } |
2660 | | |
2661 | | /// Create an empty array subscript expression. |
2662 | | explicit ArraySubscriptExpr(EmptyShell Shell) |
2663 | 41.1k | : Expr(ArraySubscriptExprClass, Shell) { } |
2664 | | |
2665 | | /// An array access can be written A[4] or 4[A] (both are equivalent). |
2666 | | /// - getBase() and getIdx() always present the normalized view: A[4]. |
2667 | | /// In this case getBase() returns "A" and getIdx() returns "4". |
2668 | | /// - getLHS() and getRHS() present the syntactic view. e.g. for |
2669 | | /// 4[A] getLHS() returns "4". |
2670 | | /// Note: Because vector element access is also written A[4] we must |
2671 | | /// predicate the format conversion in getBase and getIdx only on the |
2672 | | /// the type of the RHS, as it is possible for the LHS to be a vector of |
2673 | | /// integer type |
2674 | 920k | Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } |
2675 | 6.12M | const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } |
2676 | 41.1k | void setLHS(Expr *E) { SubExprs[LHS] = E; } |
2677 | | |
2678 | 531k | Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } |
2679 | 6.25M | const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } |
2680 | 41.1k | void setRHS(Expr *E) { SubExprs[RHS] = E; } |
2681 | | |
2682 | 240k | Expr *getBase() { return lhsIsBase() ? getLHS()240k : getRHS()95 ; } |
2683 | 3.99M | const Expr *getBase() const { return lhsIsBase() ? getLHS()3.98M : getRHS()7.78k ; } |
2684 | | |
2685 | 810 | Expr *getIdx() { return lhsIsBase() ? getRHS() : getLHS()0 ; } |
2686 | 598k | const Expr *getIdx() const { return lhsIsBase() ? getRHS()598k : getLHS()139 ; } |
2687 | | |
2688 | 1.25M | SourceLocation getBeginLoc() const LLVM_READONLY { |
2689 | 1.25M | return getLHS()->getBeginLoc(); |
2690 | 1.25M | } |
2691 | 155k | SourceLocation getEndLoc() const { return getRBracketLoc(); } |
2692 | | |
2693 | 282k | SourceLocation getRBracketLoc() const { |
2694 | 282k | return ArrayOrMatrixSubscriptExprBits.RBracketLoc; |
2695 | 282k | } |
2696 | 41.1k | void setRBracketLoc(SourceLocation L) { |
2697 | 41.1k | ArrayOrMatrixSubscriptExprBits.RBracketLoc = L; |
2698 | 41.1k | } |
2699 | | |
2700 | 639k | SourceLocation getExprLoc() const LLVM_READONLY { |
2701 | 639k | return getBase()->getExprLoc(); |
2702 | 639k | } |
2703 | | |
2704 | 4.82M | static bool classof(const Stmt *T) { |
2705 | 4.82M | return T->getStmtClass() == ArraySubscriptExprClass; |
2706 | 4.82M | } |
2707 | | |
2708 | | // Iterators |
2709 | 491k | child_range children() { |
2710 | 491k | return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); |
2711 | 491k | } |
2712 | 0 | const_child_range children() const { |
2713 | 0 | return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); |
2714 | 0 | } |
2715 | | }; |
2716 | | |
2717 | | /// MatrixSubscriptExpr - Matrix subscript expression for the MatrixType |
2718 | | /// extension. |
2719 | | /// MatrixSubscriptExpr can be either incomplete (only Base and RowIdx are set |
2720 | | /// so far, the type is IncompleteMatrixIdx) or complete (Base, RowIdx and |
2721 | | /// ColumnIdx refer to valid expressions). Incomplete matrix expressions only |
2722 | | /// exist during the initial construction of the AST. |
2723 | | class MatrixSubscriptExpr : public Expr { |
2724 | | enum { BASE, ROW_IDX, COLUMN_IDX, END_EXPR }; |
2725 | | Stmt *SubExprs[END_EXPR]; |
2726 | | |
2727 | | public: |
2728 | | MatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, QualType T, |
2729 | | SourceLocation RBracketLoc) |
2730 | | : Expr(MatrixSubscriptExprClass, T, Base->getValueKind(), |
2731 | 202 | OK_MatrixComponent) { |
2732 | 202 | SubExprs[BASE] = Base; |
2733 | 202 | SubExprs[ROW_IDX] = RowIdx; |
2734 | 202 | SubExprs[COLUMN_IDX] = ColumnIdx; |
2735 | 202 | ArrayOrMatrixSubscriptExprBits.RBracketLoc = RBracketLoc; |
2736 | 202 | setDependence(computeDependence(this)); |
2737 | 202 | } |
2738 | | |
2739 | | /// Create an empty matrix subscript expression. |
2740 | | explicit MatrixSubscriptExpr(EmptyShell Shell) |
2741 | 0 | : Expr(MatrixSubscriptExprClass, Shell) {} |
2742 | | |
2743 | 185 | bool isIncomplete() const { |
2744 | 185 | bool IsIncomplete = hasPlaceholderType(BuiltinType::IncompleteMatrixIdx); |
2745 | 185 | assert((SubExprs[COLUMN_IDX] || IsIncomplete) && |
2746 | 185 | "expressions without column index must be marked as incomplete"); |
2747 | 0 | return IsIncomplete; |
2748 | 185 | } |
2749 | 377 | Expr *getBase() { return cast<Expr>(SubExprs[BASE]); } |
2750 | 473 | const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); } |
2751 | 0 | void setBase(Expr *E) { SubExprs[BASE] = E; } |
2752 | | |
2753 | 355 | Expr *getRowIdx() { return cast<Expr>(SubExprs[ROW_IDX]); } |
2754 | 36 | const Expr *getRowIdx() const { return cast<Expr>(SubExprs[ROW_IDX]); } |
2755 | 0 | void setRowIdx(Expr *E) { SubExprs[ROW_IDX] = E; } |
2756 | | |
2757 | 308 | Expr *getColumnIdx() { return cast_or_null<Expr>(SubExprs[COLUMN_IDX]); } |
2758 | 36 | const Expr *getColumnIdx() const { |
2759 | 36 | assert(!isIncomplete() && |
2760 | 36 | "cannot get the column index of an incomplete expression"); |
2761 | 0 | return cast<Expr>(SubExprs[COLUMN_IDX]); |
2762 | 36 | } |
2763 | 0 | void setColumnIdx(Expr *E) { SubExprs[COLUMN_IDX] = E; } |
2764 | | |
2765 | 158 | SourceLocation getBeginLoc() const LLVM_READONLY { |
2766 | 158 | return getBase()->getBeginLoc(); |
2767 | 158 | } |
2768 | | |
2769 | 23 | SourceLocation getEndLoc() const { return getRBracketLoc(); } |
2770 | | |
2771 | 167 | SourceLocation getExprLoc() const LLVM_READONLY { |
2772 | 167 | return getBase()->getExprLoc(); |
2773 | 167 | } |
2774 | | |
2775 | 29 | SourceLocation getRBracketLoc() const { |
2776 | 29 | return ArrayOrMatrixSubscriptExprBits.RBracketLoc; |
2777 | 29 | } |
2778 | 0 | void setRBracketLoc(SourceLocation L) { |
2779 | 0 | ArrayOrMatrixSubscriptExprBits.RBracketLoc = L; |
2780 | 0 | } |
2781 | | |
2782 | 370k | static bool classof(const Stmt *T) { |
2783 | 370k | return T->getStmtClass() == MatrixSubscriptExprClass; |
2784 | 370k | } |
2785 | | |
2786 | | // Iterators |
2787 | 176 | child_range children() { |
2788 | 176 | return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); |
2789 | 176 | } |
2790 | 0 | const_child_range children() const { |
2791 | 0 | return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); |
2792 | 0 | } |
2793 | | }; |
2794 | | |
2795 | | /// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). |
2796 | | /// CallExpr itself represents a normal function call, e.g., "f(x, 2)", |
2797 | | /// while its subclasses may represent alternative syntax that (semantically) |
2798 | | /// results in a function call. For example, CXXOperatorCallExpr is |
2799 | | /// a subclass for overloaded operator calls that use operator syntax, e.g., |
2800 | | /// "str1 + str2" to resolve to a function call. |
2801 | | class CallExpr : public Expr { |
2802 | | enum { FN = 0, PREARGS_START = 1 }; |
2803 | | |
2804 | | /// The number of arguments in the call expression. |
2805 | | unsigned NumArgs; |
2806 | | |
2807 | | /// The location of the right parenthese. This has a different meaning for |
2808 | | /// the derived classes of CallExpr. |
2809 | | SourceLocation RParenLoc; |
2810 | | |
2811 | | // CallExpr store some data in trailing objects. However since CallExpr |
2812 | | // is used a base of other expression classes we cannot use |
2813 | | // llvm::TrailingObjects. Instead we manually perform the pointer arithmetic |
2814 | | // and casts. |
2815 | | // |
2816 | | // The trailing objects are in order: |
2817 | | // |
2818 | | // * A single "Stmt *" for the callee expression. |
2819 | | // |
2820 | | // * An array of getNumPreArgs() "Stmt *" for the pre-argument expressions. |
2821 | | // |
2822 | | // * An array of getNumArgs() "Stmt *" for the argument expressions. |
2823 | | // |
2824 | | // * An optional of type FPOptionsOverride. |
2825 | | // |
2826 | | // Note that we store the offset in bytes from the this pointer to the start |
2827 | | // of the trailing objects. It would be perfectly possible to compute it |
2828 | | // based on the dynamic kind of the CallExpr. However 1.) we have plenty of |
2829 | | // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to |
2830 | | // compute this once and then load the offset from the bit-fields of Stmt, |
2831 | | // instead of re-computing the offset each time the trailing objects are |
2832 | | // accessed. |
2833 | | |
2834 | | /// Return a pointer to the start of the trailing array of "Stmt *". |
2835 | 190M | Stmt **getTrailingStmts() { |
2836 | 190M | return reinterpret_cast<Stmt **>(reinterpret_cast<char *>(this) + |
2837 | 190M | CallExprBits.OffsetToTrailingObjects); |
2838 | 190M | } |
2839 | 61.2M | Stmt *const *getTrailingStmts() const { |
2840 | 61.2M | return const_cast<CallExpr *>(this)->getTrailingStmts(); |
2841 | 61.2M | } |
2842 | | |
2843 | | /// Map a statement class to the appropriate offset in bytes from the |
2844 | | /// this pointer to the trailing objects. |
2845 | | static unsigned offsetToTrailingObjects(StmtClass SC); |
2846 | | |
2847 | 71.0k | unsigned getSizeOfTrailingStmts() const { |
2848 | 71.0k | return (1 + getNumPreArgs() + getNumArgs()) * sizeof(Stmt *); |
2849 | 71.0k | } |
2850 | | |
2851 | 0 | size_t getOffsetOfTrailingFPFeatures() const { |
2852 | 0 | assert(hasStoredFPFeatures()); |
2853 | 0 | return CallExprBits.OffsetToTrailingObjects + getSizeOfTrailingStmts(); |
2854 | 0 | } |
2855 | | |
2856 | | public: |
2857 | | enum class ADLCallKind : bool { NotADL, UsesADL }; |
2858 | | static constexpr ADLCallKind NotADL = ADLCallKind::NotADL; |
2859 | | static constexpr ADLCallKind UsesADL = ADLCallKind::UsesADL; |
2860 | | |
2861 | | protected: |
2862 | | /// Build a call expression, assuming that appropriate storage has been |
2863 | | /// allocated for the trailing objects. |
2864 | | CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs, |
2865 | | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
2866 | | SourceLocation RParenLoc, FPOptionsOverride FPFeatures, |
2867 | | unsigned MinNumArgs, ADLCallKind UsesADL); |
2868 | | |
2869 | | /// Build an empty call expression, for deserialization. |
2870 | | CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs, |
2871 | | bool hasFPFeatures, EmptyShell Empty); |
2872 | | |
2873 | | /// Return the size in bytes needed for the trailing objects. |
2874 | | /// Used by the derived classes to allocate the right amount of storage. |
2875 | | static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs, |
2876 | 10.0M | bool HasFPFeatures) { |
2877 | 10.0M | return (1 + NumPreArgs + NumArgs) * sizeof(Stmt *) + |
2878 | 10.0M | HasFPFeatures * sizeof(FPOptionsOverride); |
2879 | 10.0M | } |
2880 | | |
2881 | 20 | Stmt *getPreArg(unsigned I) { |
2882 | 20 | assert(I < getNumPreArgs() && "Prearg access out of range!"); |
2883 | 0 | return getTrailingStmts()[PREARGS_START + I]; |
2884 | 20 | } |
2885 | 63 | const Stmt *getPreArg(unsigned I) const { |
2886 | 63 | assert(I < getNumPreArgs() && "Prearg access out of range!"); |
2887 | 0 | return getTrailingStmts()[PREARGS_START + I]; |
2888 | 63 | } |
2889 | 194 | void setPreArg(unsigned I, Stmt *PreArg) { |
2890 | 194 | assert(I < getNumPreArgs() && "Prearg access out of range!"); |
2891 | 0 | getTrailingStmts()[PREARGS_START + I] = PreArg; |
2892 | 194 | } |
2893 | | |
2894 | 105M | unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } |
2895 | | |
2896 | | /// Return a pointer to the trailing FPOptions |
2897 | 70.5k | FPOptionsOverride *getTrailingFPFeatures() { |
2898 | 70.5k | assert(hasStoredFPFeatures()); |
2899 | 0 | return reinterpret_cast<FPOptionsOverride *>( |
2900 | 70.5k | reinterpret_cast<char *>(this) + CallExprBits.OffsetToTrailingObjects + |
2901 | 70.5k | getSizeOfTrailingStmts()); |
2902 | 70.5k | } |
2903 | 495 | const FPOptionsOverride *getTrailingFPFeatures() const { |
2904 | 495 | assert(hasStoredFPFeatures()); |
2905 | 0 | return reinterpret_cast<const FPOptionsOverride *>( |
2906 | 495 | reinterpret_cast<const char *>(this) + |
2907 | 495 | CallExprBits.OffsetToTrailingObjects + getSizeOfTrailingStmts()); |
2908 | 495 | } |
2909 | | |
2910 | | public: |
2911 | | /// Create a call expression. |
2912 | | /// \param Fn The callee expression, |
2913 | | /// \param Args The argument array, |
2914 | | /// \param Ty The type of the call expression (which is *not* the return |
2915 | | /// type in general), |
2916 | | /// \param VK The value kind of the call expression (lvalue, rvalue, ...), |
2917 | | /// \param RParenLoc The location of the right parenthesis in the call |
2918 | | /// expression. |
2919 | | /// \param FPFeatures Floating-point features associated with the call, |
2920 | | /// \param MinNumArgs Specifies the minimum number of arguments. The actual |
2921 | | /// number of arguments will be the greater of Args.size() |
2922 | | /// and MinNumArgs. This is used in a few places to allocate |
2923 | | /// enough storage for the default arguments. |
2924 | | /// \param UsesADL Specifies whether the callee was found through |
2925 | | /// argument-dependent lookup. |
2926 | | /// |
2927 | | /// Note that you can use CreateTemporary if you need a temporary call |
2928 | | /// expression on the stack. |
2929 | | static CallExpr *Create(const ASTContext &Ctx, Expr *Fn, |
2930 | | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
2931 | | SourceLocation RParenLoc, |
2932 | | FPOptionsOverride FPFeatures, unsigned MinNumArgs = 0, |
2933 | | ADLCallKind UsesADL = NotADL); |
2934 | | |
2935 | | /// Create a temporary call expression with no arguments in the memory |
2936 | | /// pointed to by Mem. Mem must points to at least sizeof(CallExpr) |
2937 | | /// + sizeof(Stmt *) bytes of storage, aligned to alignof(CallExpr): |
2938 | | /// |
2939 | | /// \code{.cpp} |
2940 | | /// alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)]; |
2941 | | /// CallExpr *TheCall = CallExpr::CreateTemporary(Buffer, etc); |
2942 | | /// \endcode |
2943 | | static CallExpr *CreateTemporary(void *Mem, Expr *Fn, QualType Ty, |
2944 | | ExprValueKind VK, SourceLocation RParenLoc, |
2945 | | ADLCallKind UsesADL = NotADL); |
2946 | | |
2947 | | /// Create an empty call expression, for deserialization. |
2948 | | static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, |
2949 | | bool HasFPFeatures, EmptyShell Empty); |
2950 | | |
2951 | 30.2M | Expr *getCallee() { return cast<Expr>(getTrailingStmts()[FN]); } |
2952 | 48.6M | const Expr *getCallee() const { return cast<Expr>(getTrailingStmts()[FN]); } |
2953 | 10.6M | void setCallee(Expr *F) { getTrailingStmts()[FN] = F; } |
2954 | | |
2955 | 1.54M | ADLCallKind getADLCallKind() const { |
2956 | 1.54M | return static_cast<ADLCallKind>(CallExprBits.UsesADL); |
2957 | 1.54M | } |
2958 | 1.30M | void setADLCallKind(ADLCallKind V = UsesADL) { |
2959 | 1.30M | CallExprBits.UsesADL = static_cast<bool>(V); |
2960 | 1.30M | } |
2961 | 1.51k | bool usesADL() const { return getADLCallKind() == UsesADL; } |
2962 | | |
2963 | 12.1M | bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; } |
2964 | | |
2965 | 4.20M | Decl *getCalleeDecl() { return getCallee()->getReferencedDeclOfCallee(); } |
2966 | 11.9M | const Decl *getCalleeDecl() const { |
2967 | 11.9M | return getCallee()->getReferencedDeclOfCallee(); |
2968 | 11.9M | } |
2969 | | |
2970 | | /// If the callee is a FunctionDecl, return it. Otherwise return null. |
2971 | 4.20M | FunctionDecl *getDirectCallee() { |
2972 | 4.20M | return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); |
2973 | 4.20M | } |
2974 | 10.6M | const FunctionDecl *getDirectCallee() const { |
2975 | 10.6M | return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); |
2976 | 10.6M | } |
2977 | | |
2978 | | /// getNumArgs - Return the number of actual arguments to this call. |
2979 | 99.3M | unsigned getNumArgs() const { return NumArgs; } |
2980 | | |
2981 | | /// Retrieve the call arguments. |
2982 | 54.7M | Expr **getArgs() { |
2983 | 54.7M | return reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START + |
2984 | 54.7M | getNumPreArgs()); |
2985 | 54.7M | } |
2986 | 4.59M | const Expr *const *getArgs() const { |
2987 | 4.59M | return reinterpret_cast<const Expr *const *>( |
2988 | 4.59M | getTrailingStmts() + PREARGS_START + getNumPreArgs()); |
2989 | 4.59M | } |
2990 | | |
2991 | | /// getArg - Return the specified argument. |
2992 | 12.8M | Expr *getArg(unsigned Arg) { |
2993 | 12.8M | assert(Arg < getNumArgs() && "Arg access out of range!"); |
2994 | 0 | return getArgs()[Arg]; |
2995 | 12.8M | } |
2996 | 3.85M | const Expr *getArg(unsigned Arg) const { |
2997 | 3.85M | assert(Arg < getNumArgs() && "Arg access out of range!"); |
2998 | 0 | return getArgs()[Arg]; |
2999 | 3.85M | } |
3000 | | |
3001 | | /// setArg - Set the specified argument. |
3002 | | /// ! the dependence bits might be stale after calling this setter, it is |
3003 | | /// *caller*'s responsibility to recompute them by calling |
3004 | | /// computeDependence(). |
3005 | 22.9M | void setArg(unsigned Arg, Expr *ArgExpr) { |
3006 | 22.9M | assert(Arg < getNumArgs() && "Arg access out of range!"); |
3007 | 0 | getArgs()[Arg] = ArgExpr; |
3008 | 22.9M | } |
3009 | | |
3010 | | /// Compute and set dependence bits. |
3011 | 12.9M | void computeDependence() { |
3012 | 12.9M | setDependence(clang::computeDependence( |
3013 | 12.9M | this, llvm::makeArrayRef( |
3014 | 12.9M | reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START), |
3015 | 12.9M | getNumPreArgs()))); |
3016 | 12.9M | } |
3017 | | |
3018 | | /// Reduce the number of arguments in this call expression. This is used for |
3019 | | /// example during error recovery to drop extra arguments. There is no way |
3020 | | /// to perform the opposite because: 1.) We don't track how much storage |
3021 | | /// we have for the argument array 2.) This would potentially require growing |
3022 | | /// the argument array, something we cannot support since the arguments are |
3023 | | /// stored in a trailing array. |
3024 | 83 | void shrinkNumArgs(unsigned NewNumArgs) { |
3025 | 83 | assert((NewNumArgs <= getNumArgs()) && |
3026 | 83 | "shrinkNumArgs cannot increase the number of arguments!"); |
3027 | 0 | NumArgs = NewNumArgs; |
3028 | 83 | } |
3029 | | |
3030 | | /// Bluntly set a new number of arguments without doing any checks whatsoever. |
3031 | | /// Only used during construction of a CallExpr in a few places in Sema. |
3032 | | /// FIXME: Find a way to remove it. |
3033 | 0 | void setNumArgsUnsafe(unsigned NewNumArgs) { NumArgs = NewNumArgs; } |
3034 | | |
3035 | | typedef ExprIterator arg_iterator; |
3036 | | typedef ConstExprIterator const_arg_iterator; |
3037 | | typedef llvm::iterator_range<arg_iterator> arg_range; |
3038 | | typedef llvm::iterator_range<const_arg_iterator> const_arg_range; |
3039 | | |
3040 | 1.30M | arg_range arguments() { return arg_range(arg_begin(), arg_end()); } |
3041 | 3.96M | const_arg_range arguments() const { |
3042 | 3.96M | return const_arg_range(arg_begin(), arg_end()); |
3043 | 3.96M | } |
3044 | | |
3045 | 9.28M | arg_iterator arg_begin() { |
3046 | 9.28M | return getTrailingStmts() + PREARGS_START + getNumPreArgs(); |
3047 | 9.28M | } |
3048 | 4.64M | arg_iterator arg_end() { return arg_begin() + getNumArgs(); } |
3049 | | |
3050 | 7.94M | const_arg_iterator arg_begin() const { |
3051 | 7.94M | return getTrailingStmts() + PREARGS_START + getNumPreArgs(); |
3052 | 7.94M | } |
3053 | 3.97M | const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } |
3054 | | |
3055 | | /// This method provides fast access to all the subexpressions of |
3056 | | /// a CallExpr without going through the slower virtual child_iterator |
3057 | | /// interface. This provides efficient reverse iteration of the |
3058 | | /// subexpressions. This is currently used for CFG construction. |
3059 | 304k | ArrayRef<Stmt *> getRawSubExprs() { |
3060 | 304k | return llvm::makeArrayRef(getTrailingStmts(), |
3061 | 304k | PREARGS_START + getNumPreArgs() + getNumArgs()); |
3062 | 304k | } |
3063 | | |
3064 | | /// getNumCommas - Return the number of commas that must have been present in |
3065 | | /// this function call. |
3066 | 0 | unsigned getNumCommas() const { return getNumArgs() ? getNumArgs() - 1 : 0; } |
3067 | | |
3068 | | /// Get FPOptionsOverride from trailing storage. |
3069 | 495 | FPOptionsOverride getStoredFPFeatures() const { |
3070 | 495 | assert(hasStoredFPFeatures()); |
3071 | 0 | return *getTrailingFPFeatures(); |
3072 | 495 | } |
3073 | | /// Set FPOptionsOverride in trailing storage. Used only by Serialization. |
3074 | 70.5k | void setStoredFPFeatures(FPOptionsOverride F) { |
3075 | 70.5k | assert(hasStoredFPFeatures()); |
3076 | 0 | *getTrailingFPFeatures() = F; |
3077 | 70.5k | } |
3078 | | |
3079 | | // Get the FP features status of this operator. Only meaningful for |
3080 | | // operations on floating point types. |
3081 | 5.46k | FPOptions getFPFeaturesInEffect(const LangOptions &LO) const { |
3082 | 5.46k | if (hasStoredFPFeatures()) |
3083 | 455 | return getStoredFPFeatures().applyOverrides(LO); |
3084 | 5.01k | return FPOptions::defaultWithoutTrailingStorage(LO); |
3085 | 5.46k | } |
3086 | | |
3087 | 1.29M | FPOptionsOverride getFPFeatures() const { |
3088 | 1.29M | if (hasStoredFPFeatures()) |
3089 | 40 | return getStoredFPFeatures(); |
3090 | 1.29M | return FPOptionsOverride(); |
3091 | 1.29M | } |
3092 | | |
3093 | | /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID |
3094 | | /// of the callee. If not, return 0. |
3095 | | unsigned getBuiltinCallee() const; |
3096 | | |
3097 | | /// Returns \c true if this is a call to a builtin which does not |
3098 | | /// evaluate side-effects within its arguments. |
3099 | | bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const; |
3100 | | |
3101 | | /// getCallReturnType - Get the return type of the call expr. This is not |
3102 | | /// always the type of the expr itself, if the return type is a reference |
3103 | | /// type. |
3104 | | QualType getCallReturnType(const ASTContext &Ctx) const; |
3105 | | |
3106 | | /// Returns the WarnUnusedResultAttr that is either declared on the called |
3107 | | /// function, or its return type declaration. |
3108 | | const Attr *getUnusedResultAttr(const ASTContext &Ctx) const; |
3109 | | |
3110 | | /// Returns true if this call expression should warn on unused results. |
3111 | 550k | bool hasUnusedResultAttr(const ASTContext &Ctx) const { |
3112 | 550k | return getUnusedResultAttr(Ctx) != nullptr; |
3113 | 550k | } |
3114 | | |
3115 | 10.8M | SourceLocation getRParenLoc() const { return RParenLoc; } |
3116 | 1.30M | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
3117 | | |
3118 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
3119 | | SourceLocation getEndLoc() const LLVM_READONLY; |
3120 | | |
3121 | | /// Return true if this is a call to __assume() or __builtin_assume() with |
3122 | | /// a non-value-dependent constant parameter evaluating as false. |
3123 | | bool isBuiltinAssumeFalse(const ASTContext &Ctx) const; |
3124 | | |
3125 | | /// Used by Sema to implement MSVC-compatible delayed name lookup. |
3126 | | /// (Usually Exprs themselves should set dependence). |
3127 | 15 | void markDependentForPostponedNameLookup() { |
3128 | 15 | setDependence(getDependence() | ExprDependence::TypeValueInstantiation); |
3129 | 15 | } |
3130 | | |
3131 | | bool isCallToStdMove() const; |
3132 | | |
3133 | 84.5M | static bool classof(const Stmt *T) { |
3134 | 84.5M | return T->getStmtClass() >= firstCallExprConstant && |
3135 | 84.5M | T->getStmtClass() <= lastCallExprConstant73.2M ; |
3136 | 84.5M | } |
3137 | | |
3138 | | // Iterators |
3139 | 5.40M | child_range children() { |
3140 | 5.40M | return child_range(getTrailingStmts(), getTrailingStmts() + PREARGS_START + |
3141 | 5.40M | getNumPreArgs() + getNumArgs()); |
3142 | 5.40M | } |
3143 | | |
3144 | 1.33k | const_child_range children() const { |
3145 | 1.33k | return const_child_range(getTrailingStmts(), |
3146 | 1.33k | getTrailingStmts() + PREARGS_START + |
3147 | 1.33k | getNumPreArgs() + getNumArgs()); |
3148 | 1.33k | } |
3149 | | }; |
3150 | | |
3151 | | /// Extra data stored in some MemberExpr objects. |
3152 | | struct MemberExprNameQualifier { |
3153 | | /// The nested-name-specifier that qualifies the name, including |
3154 | | /// source-location information. |
3155 | | NestedNameSpecifierLoc QualifierLoc; |
3156 | | |
3157 | | /// The DeclAccessPair through which the MemberDecl was found due to |
3158 | | /// name qualifiers. |
3159 | | DeclAccessPair FoundDecl; |
3160 | | }; |
3161 | | |
3162 | | /// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. |
3163 | | /// |
3164 | | class MemberExpr final |
3165 | | : public Expr, |
3166 | | private llvm::TrailingObjects<MemberExpr, MemberExprNameQualifier, |
3167 | | ASTTemplateKWAndArgsInfo, |
3168 | | TemplateArgumentLoc> { |
3169 | | friend class ASTReader; |
3170 | | friend class ASTStmtReader; |
3171 | | friend class ASTStmtWriter; |
3172 | | friend TrailingObjects; |
3173 | | |
3174 | | /// Base - the expression for the base pointer or structure references. In |
3175 | | /// X.F, this is "X". |
3176 | | Stmt *Base; |
3177 | | |
3178 | | /// MemberDecl - This is the decl being referenced by the field/member name. |
3179 | | /// In X.F, this is the decl referenced by F. |
3180 | | ValueDecl *MemberDecl; |
3181 | | |
3182 | | /// MemberDNLoc - Provides source/type location info for the |
3183 | | /// declaration name embedded in MemberDecl. |
3184 | | DeclarationNameLoc MemberDNLoc; |
3185 | | |
3186 | | /// MemberLoc - This is the location of the member name. |
3187 | | SourceLocation MemberLoc; |
3188 | | |
3189 | 10.5k | size_t numTrailingObjects(OverloadToken<MemberExprNameQualifier>) const { |
3190 | 10.5k | return hasQualifierOrFoundDecl(); |
3191 | 10.5k | } |
3192 | | |
3193 | 2.43k | size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
3194 | 2.43k | return hasTemplateKWAndArgsInfo(); |
3195 | 2.43k | } |
3196 | | |
3197 | 6.14M | bool hasQualifierOrFoundDecl() const { |
3198 | 6.14M | return MemberExprBits.HasQualifierOrFoundDecl; |
3199 | 6.14M | } |
3200 | | |
3201 | 2.24M | bool hasTemplateKWAndArgsInfo() const { |
3202 | 2.24M | return MemberExprBits.HasTemplateKWAndArgsInfo; |
3203 | 2.24M | } |
3204 | | |
3205 | | MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc, |
3206 | | ValueDecl *MemberDecl, const DeclarationNameInfo &NameInfo, |
3207 | | QualType T, ExprValueKind VK, ExprObjectKind OK, |
3208 | | NonOdrUseReason NOUR); |
3209 | | MemberExpr(EmptyShell Empty) |
3210 | 382k | : Expr(MemberExprClass, Empty), Base(), MemberDecl() {} |
3211 | | |
3212 | | public: |
3213 | | static MemberExpr *Create(const ASTContext &C, Expr *Base, bool IsArrow, |
3214 | | SourceLocation OperatorLoc, |
3215 | | NestedNameSpecifierLoc QualifierLoc, |
3216 | | SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, |
3217 | | DeclAccessPair FoundDecl, |
3218 | | DeclarationNameInfo MemberNameInfo, |
3219 | | const TemplateArgumentListInfo *TemplateArgs, |
3220 | | QualType T, ExprValueKind VK, ExprObjectKind OK, |
3221 | | NonOdrUseReason NOUR); |
3222 | | |
3223 | | /// Create an implicit MemberExpr, with no location, qualifier, template |
3224 | | /// arguments, and so on. Suitable only for non-static member access. |
3225 | | static MemberExpr *CreateImplicit(const ASTContext &C, Expr *Base, |
3226 | | bool IsArrow, ValueDecl *MemberDecl, |
3227 | | QualType T, ExprValueKind VK, |
3228 | 372 | ExprObjectKind OK) { |
3229 | 372 | return Create(C, Base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(), |
3230 | 372 | SourceLocation(), MemberDecl, |
3231 | 372 | DeclAccessPair::make(MemberDecl, MemberDecl->getAccess()), |
3232 | 372 | DeclarationNameInfo(), nullptr, T, VK, OK, NOUR_None); |
3233 | 372 | } |
3234 | | |
3235 | | static MemberExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier, |
3236 | | bool HasFoundDecl, |
3237 | | bool HasTemplateKWAndArgsInfo, |
3238 | | unsigned NumTemplateArgs); |
3239 | | |
3240 | 213k | void setBase(Expr *E) { Base = E; } |
3241 | 22.9M | Expr *getBase() const { return cast<Expr>(Base); } |
3242 | | |
3243 | | /// Retrieve the member declaration to which this expression refers. |
3244 | | /// |
3245 | | /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for |
3246 | | /// static data members), a CXXMethodDecl, or an EnumConstantDecl. |
3247 | 16.0M | ValueDecl *getMemberDecl() const { return MemberDecl; } |
3248 | | void setMemberDecl(ValueDecl *D); |
3249 | | |
3250 | | /// Retrieves the declaration found by lookup. |
3251 | 953k | DeclAccessPair getFoundDecl() const { |
3252 | 953k | if (!hasQualifierOrFoundDecl()) |
3253 | 925k | return DeclAccessPair::make(getMemberDecl(), |
3254 | 925k | getMemberDecl()->getAccess()); |
3255 | 27.7k | return getTrailingObjects<MemberExprNameQualifier>()->FoundDecl; |
3256 | 953k | } |
3257 | | |
3258 | | /// Determines whether this member expression actually had |
3259 | | /// a C++ nested-name-specifier prior to the name of the member, e.g., |
3260 | | /// x->Base::foo. |
3261 | 4.27M | bool hasQualifier() const { return getQualifier() != nullptr; } |
3262 | | |
3263 | | /// If the member name was qualified, retrieves the |
3264 | | /// nested-name-specifier that precedes the member name, with source-location |
3265 | | /// information. |
3266 | 5.07M | NestedNameSpecifierLoc getQualifierLoc() const { |
3267 | 5.07M | if (!hasQualifierOrFoundDecl()) |
3268 | 4.90M | return NestedNameSpecifierLoc(); |
3269 | 165k | return getTrailingObjects<MemberExprNameQualifier>()->QualifierLoc; |
3270 | 5.07M | } |
3271 | | |
3272 | | /// If the member name was qualified, retrieves the |
3273 | | /// nested-name-specifier that precedes the member name. Otherwise, returns |
3274 | | /// NULL. |
3275 | 4.51M | NestedNameSpecifier *getQualifier() const { |
3276 | 4.51M | return getQualifierLoc().getNestedNameSpecifier(); |
3277 | 4.51M | } |
3278 | | |
3279 | | /// Retrieve the location of the template keyword preceding |
3280 | | /// the member name, if any. |
3281 | 454k | SourceLocation getTemplateKeywordLoc() const { |
3282 | 454k | if (!hasTemplateKWAndArgsInfo()) |
3283 | 454k | return SourceLocation(); |
3284 | 162 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc; |
3285 | 454k | } |
3286 | | |
3287 | | /// Retrieve the location of the left angle bracket starting the |
3288 | | /// explicit template argument list following the member name, if any. |
3289 | 1.67M | SourceLocation getLAngleLoc() const { |
3290 | 1.67M | if (!hasTemplateKWAndArgsInfo()) |
3291 | 1.67M | return SourceLocation(); |
3292 | 3.02k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc; |
3293 | 1.67M | } |
3294 | | |
3295 | | /// Retrieve the location of the right angle bracket ending the |
3296 | | /// explicit template argument list following the member name, if any. |
3297 | 2.18k | SourceLocation getRAngleLoc() const { |
3298 | 2.18k | if (!hasTemplateKWAndArgsInfo()) |
3299 | 0 | return SourceLocation(); |
3300 | 2.18k | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc; |
3301 | 2.18k | } |
3302 | | |
3303 | | /// Determines whether the member name was preceded by the template keyword. |
3304 | 7.32k | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
3305 | | |
3306 | | /// Determines whether the member name was followed by an |
3307 | | /// explicit template argument list. |
3308 | 1.67M | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } |
3309 | | |
3310 | | /// Copies the template arguments (if present) into the given |
3311 | | /// structure. |
3312 | 0 | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { |
3313 | 0 | if (hasExplicitTemplateArgs()) |
3314 | 0 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto( |
3315 | 0 | getTrailingObjects<TemplateArgumentLoc>(), List); |
3316 | 0 | } |
3317 | | |
3318 | | /// Retrieve the template arguments provided as part of this |
3319 | | /// template-id. |
3320 | 152k | const TemplateArgumentLoc *getTemplateArgs() const { |
3321 | 152k | if (!hasExplicitTemplateArgs()) |
3322 | 151k | return nullptr; |
3323 | | |
3324 | 277 | return getTrailingObjects<TemplateArgumentLoc>(); |
3325 | 152k | } |
3326 | | |
3327 | | /// Retrieve the number of template arguments provided as part of this |
3328 | | /// template-id. |
3329 | 260k | unsigned getNumTemplateArgs() const { |
3330 | 260k | if (!hasExplicitTemplateArgs()) |
3331 | 259k | return 0; |
3332 | | |
3333 | 368 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; |
3334 | 260k | } |
3335 | | |
3336 | 26 | ArrayRef<TemplateArgumentLoc> template_arguments() const { |
3337 | 26 | return {getTemplateArgs(), getNumTemplateArgs()}; |
3338 | 26 | } |
3339 | | |
3340 | | /// Retrieve the member declaration name info. |
3341 | 1.69M | DeclarationNameInfo getMemberNameInfo() const { |
3342 | 1.69M | return DeclarationNameInfo(MemberDecl->getDeclName(), |
3343 | 1.69M | MemberLoc, MemberDNLoc); |
3344 | 1.69M | } |
3345 | | |
3346 | 473k | SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; } |
3347 | | |
3348 | 2.73M | bool isArrow() const { return MemberExprBits.IsArrow; } |
3349 | 0 | void setArrow(bool A) { MemberExprBits.IsArrow = A; } |
3350 | | |
3351 | | /// getMemberLoc - Return the location of the "member", in X->F, it is the |
3352 | | /// location of 'F'. |
3353 | 3.59M | SourceLocation getMemberLoc() const { return MemberLoc; } |
3354 | 0 | void setMemberLoc(SourceLocation L) { MemberLoc = L; } |
3355 | | |
3356 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
3357 | | SourceLocation getEndLoc() const LLVM_READONLY; |
3358 | | |
3359 | 3.08M | SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; } |
3360 | | |
3361 | | /// Determine whether the base of this explicit is implicit. |
3362 | 5.71M | bool isImplicitAccess() const { |
3363 | 5.71M | return getBase() && getBase()->isImplicitCXXThis(); |
3364 | 5.71M | } |
3365 | | |
3366 | | /// Returns true if this member expression refers to a method that |
3367 | | /// was resolved from an overloaded set having size greater than 1. |
3368 | 108k | bool hadMultipleCandidates() const { |
3369 | 108k | return MemberExprBits.HadMultipleCandidates; |
3370 | 108k | } |
3371 | | /// Sets the flag telling whether this expression refers to |
3372 | | /// a method that was resolved from an overloaded set having size |
3373 | | /// greater than 1. |
3374 | 1.59M | void setHadMultipleCandidates(bool V = true) { |
3375 | 1.59M | MemberExprBits.HadMultipleCandidates = V; |
3376 | 1.59M | } |
3377 | | |
3378 | | /// Returns true if virtual dispatch is performed. |
3379 | | /// If the member access is fully qualified, (i.e. X::f()), virtual |
3380 | | /// dispatching is not performed. In -fapple-kext mode qualified |
3381 | | /// calls to virtual method will still go through the vtable. |
3382 | 1.61M | bool performsVirtualDispatch(const LangOptions &LO) const { |
3383 | 1.61M | return LO.AppleKext || !hasQualifier()1.61M ; |
3384 | 1.61M | } |
3385 | | |
3386 | | /// Is this expression a non-odr-use reference, and if so, why? |
3387 | | /// This is only meaningful if the named member is a static member. |
3388 | 474k | NonOdrUseReason isNonOdrUse() const { |
3389 | 474k | return static_cast<NonOdrUseReason>(MemberExprBits.NonOdrUseReason); |
3390 | 474k | } |
3391 | | |
3392 | 67.9M | static bool classof(const Stmt *T) { |
3393 | 67.9M | return T->getStmtClass() == MemberExprClass; |
3394 | 67.9M | } |
3395 | | |
3396 | | // Iterators |
3397 | 1.06M | child_range children() { return child_range(&Base, &Base+1); } |
3398 | 0 | const_child_range children() const { |
3399 | 0 | return const_child_range(&Base, &Base + 1); |
3400 | 0 | } |
3401 | | }; |
3402 | | |
3403 | | /// CompoundLiteralExpr - [C99 6.5.2.5] |
3404 | | /// |
3405 | | class CompoundLiteralExpr : public Expr { |
3406 | | /// LParenLoc - If non-null, this is the location of the left paren in a |
3407 | | /// compound literal like "(int){4}". This can be null if this is a |
3408 | | /// synthesized compound expression. |
3409 | | SourceLocation LParenLoc; |
3410 | | |
3411 | | /// The type as written. This can be an incomplete array type, in |
3412 | | /// which case the actual expression type will be different. |
3413 | | /// The int part of the pair stores whether this expr is file scope. |
3414 | | llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope; |
3415 | | Stmt *Init; |
3416 | | public: |
3417 | | CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, |
3418 | | QualType T, ExprValueKind VK, Expr *init, bool fileScope) |
3419 | | : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary), |
3420 | 55.7k | LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) { |
3421 | 55.7k | setDependence(computeDependence(this)); |
3422 | 55.7k | } |
3423 | | |
3424 | | /// Construct an empty compound literal. |
3425 | | explicit CompoundLiteralExpr(EmptyShell Empty) |
3426 | 9 | : Expr(CompoundLiteralExprClass, Empty) { } |
3427 | | |
3428 | 24.3k | const Expr *getInitializer() const { return cast<Expr>(Init); } |
3429 | 57.6k | Expr *getInitializer() { return cast<Expr>(Init); } |
3430 | 9 | void setInitializer(Expr *E) { Init = E; } |
3431 | | |
3432 | 3.73k | bool isFileScope() const { return TInfoAndScope.getInt(); } |
3433 | 9 | void setFileScope(bool FS) { TInfoAndScope.setInt(FS); } |
3434 | | |
3435 | 1.20k | SourceLocation getLParenLoc() const { return LParenLoc; } |
3436 | 9 | void setLParenLoc(SourceLocation L) { LParenLoc = L; } |
3437 | | |
3438 | 57.4k | TypeSourceInfo *getTypeSourceInfo() const { |
3439 | 57.4k | return TInfoAndScope.getPointer(); |
3440 | 57.4k | } |
3441 | 9 | void setTypeSourceInfo(TypeSourceInfo *tinfo) { |
3442 | 9 | TInfoAndScope.setPointer(tinfo); |
3443 | 9 | } |
3444 | | |
3445 | 139k | SourceLocation getBeginLoc() const LLVM_READONLY { |
3446 | | // FIXME: Init should never be null. |
3447 | 139k | if (!Init) |
3448 | 0 | return SourceLocation(); |
3449 | 139k | if (LParenLoc.isInvalid()) |
3450 | 137 | return Init->getBeginLoc(); |
3451 | 139k | return LParenLoc; |
3452 | 139k | } |
3453 | 13.4k | SourceLocation getEndLoc() const LLVM_READONLY { |
3454 | | // FIXME: Init should never be null. |
3455 | 13.4k | if (!Init) |
3456 | 0 | return SourceLocation(); |
3457 | 13.4k | return Init->getEndLoc(); |
3458 | 13.4k | } |
3459 | | |
3460 | 56.8k | static bool classof(const Stmt *T) { |
3461 | 56.8k | return T->getStmtClass() == CompoundLiteralExprClass; |
3462 | 56.8k | } |
3463 | | |
3464 | | // Iterators |
3465 | 114k | child_range children() { return child_range(&Init, &Init+1); } |
3466 | 0 | const_child_range children() const { |
3467 | 0 | return const_child_range(&Init, &Init + 1); |
3468 | 0 | } |
3469 | | }; |
3470 | | |
3471 | | /// CastExpr - Base class for type casts, including both implicit |
3472 | | /// casts (ImplicitCastExpr) and explicit casts that have some |
3473 | | /// representation in the source code (ExplicitCastExpr's derived |
3474 | | /// classes). |
3475 | | class CastExpr : public Expr { |
3476 | | Stmt *Op; |
3477 | | |
3478 | | bool CastConsistency() const; |
3479 | | |
3480 | 50.3k | const CXXBaseSpecifier * const *path_buffer() const { |
3481 | 50.3k | return const_cast<CastExpr*>(this)->path_buffer(); |
3482 | 50.3k | } |
3483 | | CXXBaseSpecifier **path_buffer(); |
3484 | | |
3485 | | friend class ASTStmtReader; |
3486 | | |
3487 | | protected: |
3488 | | CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, const CastKind kind, |
3489 | | Expr *op, unsigned BasePathSize, bool HasFPFeatures) |
3490 | 26.8M | : Expr(SC, ty, VK, OK_Ordinary), Op(op) { |
3491 | 26.8M | CastExprBits.Kind = kind; |
3492 | 26.8M | CastExprBits.PartOfExplicitCast = false; |
3493 | 26.8M | CastExprBits.BasePathSize = BasePathSize; |
3494 | 26.8M | assert((CastExprBits.BasePathSize == BasePathSize) && |
3495 | 26.8M | "BasePathSize overflow!"); |
3496 | 0 | assert(CastConsistency()); |
3497 | 0 | CastExprBits.HasFPFeatures = HasFPFeatures; |
3498 | 26.8M | } |
3499 | | |
3500 | | /// Construct an empty cast. |
3501 | | CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize, |
3502 | | bool HasFPFeatures) |
3503 | 1.39M | : Expr(SC, Empty) { |
3504 | 1.39M | CastExprBits.PartOfExplicitCast = false; |
3505 | 1.39M | CastExprBits.BasePathSize = BasePathSize; |
3506 | 1.39M | CastExprBits.HasFPFeatures = HasFPFeatures; |
3507 | 1.39M | assert((CastExprBits.BasePathSize == BasePathSize) && |
3508 | 1.39M | "BasePathSize overflow!"); |
3509 | 1.39M | } |
3510 | | |
3511 | | /// Return a pointer to the trailing FPOptions. |
3512 | | /// \pre hasStoredFPFeatures() == true |
3513 | | FPOptionsOverride *getTrailingFPFeatures(); |
3514 | 2.41k | const FPOptionsOverride *getTrailingFPFeatures() const { |
3515 | 2.41k | return const_cast<CastExpr *>(this)->getTrailingFPFeatures(); |
3516 | 2.41k | } |
3517 | | |
3518 | | public: |
3519 | 105M | CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } |
3520 | 1.39M | void setCastKind(CastKind K) { CastExprBits.Kind = K; } |
3521 | | |
3522 | | static const char *getCastKindName(CastKind CK); |
3523 | 7.79k | const char *getCastKindName() const { return getCastKindName(getCastKind()); } |
3524 | | |
3525 | 121M | Expr *getSubExpr() { return cast<Expr>(Op); } |
3526 | 123M | const Expr *getSubExpr() const { return cast<Expr>(Op); } |
3527 | 1.39M | void setSubExpr(Expr *E) { Op = E; } |
3528 | | |
3529 | | /// Retrieve the cast subexpression as it was written in the source |
3530 | | /// code, looking through any implicit casts or other intermediate nodes |
3531 | | /// introduced by semantic analysis. |
3532 | | Expr *getSubExprAsWritten(); |
3533 | 443k | const Expr *getSubExprAsWritten() const { |
3534 | 443k | return const_cast<CastExpr *>(this)->getSubExprAsWritten(); |
3535 | 443k | } |
3536 | | |
3537 | | /// If this cast applies a user-defined conversion, retrieve the conversion |
3538 | | /// function that it invokes. |
3539 | | NamedDecl *getConversionFunction() const; |
3540 | | |
3541 | | typedef CXXBaseSpecifier **path_iterator; |
3542 | | typedef const CXXBaseSpecifier *const *path_const_iterator; |
3543 | 26.8M | bool path_empty() const { return path_size() == 0; } |
3544 | 32.3M | unsigned path_size() const { return CastExprBits.BasePathSize; } |
3545 | 3.21M | path_iterator path_begin() { return path_buffer(); } |
3546 | 1.81M | path_iterator path_end() { return path_buffer() + path_size(); } |
3547 | 25.1k | path_const_iterator path_begin() const { return path_buffer(); } |
3548 | 25.1k | path_const_iterator path_end() const { return path_buffer() + path_size(); } |
3549 | | |
3550 | 55 | llvm::iterator_range<path_iterator> path() { |
3551 | 55 | return llvm::make_range(path_begin(), path_end()); |
3552 | 55 | } |
3553 | 87 | llvm::iterator_range<path_const_iterator> path() const { |
3554 | 87 | return llvm::make_range(path_begin(), path_end()); |
3555 | 87 | } |
3556 | | |
3557 | 4 | const FieldDecl *getTargetUnionField() const { |
3558 | 4 | assert(getCastKind() == CK_ToUnion); |
3559 | 0 | return getTargetFieldForToUnionCast(getType(), getSubExpr()->getType()); |
3560 | 4 | } |
3561 | | |
3562 | 32.4M | bool hasStoredFPFeatures() const { return CastExprBits.HasFPFeatures; } |
3563 | | |
3564 | | /// Get FPOptionsOverride from trailing storage. |
3565 | 2.41k | FPOptionsOverride getStoredFPFeatures() const { |
3566 | 2.41k | assert(hasStoredFPFeatures()); |
3567 | 0 | return *getTrailingFPFeatures(); |
3568 | 2.41k | } |
3569 | | |
3570 | | // Get the FP features status of this operation. Only meaningful for |
3571 | | // operations on floating point types. |
3572 | 146k | FPOptions getFPFeaturesInEffect(const LangOptions &LO) const { |
3573 | 146k | if (hasStoredFPFeatures()) |
3574 | 2.27k | return getStoredFPFeatures().applyOverrides(LO); |
3575 | 144k | return FPOptions::defaultWithoutTrailingStorage(LO); |
3576 | 146k | } |
3577 | | |
3578 | 768k | FPOptionsOverride getFPFeatures() const { |
3579 | 768k | if (hasStoredFPFeatures()) |
3580 | 142 | return getStoredFPFeatures(); |
3581 | 767k | return FPOptionsOverride(); |
3582 | 768k | } |
3583 | | |
3584 | | static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType, |
3585 | | QualType opType); |
3586 | | static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD, |
3587 | | QualType opType); |
3588 | | |
3589 | 135M | static bool classof(const Stmt *T) { |
3590 | 135M | return T->getStmtClass() >= firstCastExprConstant && |
3591 | 135M | T->getStmtClass() <= lastCastExprConstant116M ; |
3592 | 135M | } |
3593 | | |
3594 | | // Iterators |
3595 | 27.5M | child_range children() { return child_range(&Op, &Op+1); } |
3596 | 0 | const_child_range children() const { return const_child_range(&Op, &Op + 1); } |
3597 | | }; |
3598 | | |
3599 | | /// ImplicitCastExpr - Allows us to explicitly represent implicit type |
3600 | | /// conversions, which have no direct representation in the original |
3601 | | /// source code. For example: converting T[]->T*, void f()->void |
3602 | | /// (*f)(), float->double, short->int, etc. |
3603 | | /// |
3604 | | /// In C, implicit casts always produce rvalues. However, in C++, an |
3605 | | /// implicit cast whose result is being bound to a reference will be |
3606 | | /// an lvalue or xvalue. For example: |
3607 | | /// |
3608 | | /// @code |
3609 | | /// class Base { }; |
3610 | | /// class Derived : public Base { }; |
3611 | | /// Derived &&ref(); |
3612 | | /// void f(Derived d) { |
3613 | | /// Base& b = d; // initializer is an ImplicitCastExpr |
3614 | | /// // to an lvalue of type Base |
3615 | | /// Base&& r = ref(); // initializer is an ImplicitCastExpr |
3616 | | /// // to an xvalue of type Base |
3617 | | /// } |
3618 | | /// @endcode |
3619 | | class ImplicitCastExpr final |
3620 | | : public CastExpr, |
3621 | | private llvm::TrailingObjects<ImplicitCastExpr, CXXBaseSpecifier *, |
3622 | | FPOptionsOverride> { |
3623 | | |
3624 | | ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, |
3625 | | unsigned BasePathLength, FPOptionsOverride FPO, |
3626 | | ExprValueKind VK) |
3627 | | : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength, |
3628 | 21.0M | FPO.requiresTrailingStorage()) { |
3629 | 21.0M | setDependence(computeDependence(this)); |
3630 | 21.0M | if (hasStoredFPFeatures()) |
3631 | 215k | *getTrailingFPFeatures() = FPO; |
3632 | 21.0M | } |
3633 | | |
3634 | | /// Construct an empty implicit cast. |
3635 | | explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize, |
3636 | | bool HasFPFeatures) |
3637 | 1.29M | : CastExpr(ImplicitCastExprClass, Shell, PathSize, HasFPFeatures) {} |
3638 | | |
3639 | 217k | unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const { |
3640 | 217k | return path_size(); |
3641 | 217k | } |
3642 | | |
3643 | | public: |
3644 | | enum OnStack_t { OnStack }; |
3645 | | ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, |
3646 | | ExprValueKind VK, FPOptionsOverride FPO) |
3647 | | : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0, |
3648 | 596k | FPO.requiresTrailingStorage()) { |
3649 | 596k | if (hasStoredFPFeatures()) |
3650 | 0 | *getTrailingFPFeatures() = FPO; |
3651 | 596k | } |
3652 | | |
3653 | 1.02M | bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; } |
3654 | 4.21M | void setIsPartOfExplicitCast(bool PartOfExplicitCast) { |
3655 | 4.21M | CastExprBits.PartOfExplicitCast = PartOfExplicitCast; |
3656 | 4.21M | } |
3657 | | |
3658 | | static ImplicitCastExpr *Create(const ASTContext &Context, QualType T, |
3659 | | CastKind Kind, Expr *Operand, |
3660 | | const CXXCastPath *BasePath, |
3661 | | ExprValueKind Cat, FPOptionsOverride FPO); |
3662 | | |
3663 | | static ImplicitCastExpr *CreateEmpty(const ASTContext &Context, |
3664 | | unsigned PathSize, bool HasFPFeatures); |
3665 | | |
3666 | 60.1M | SourceLocation getBeginLoc() const LLVM_READONLY { |
3667 | 60.1M | return getSubExpr()->getBeginLoc(); |
3668 | 60.1M | } |
3669 | 6.56M | SourceLocation getEndLoc() const LLVM_READONLY { |
3670 | 6.56M | return getSubExpr()->getEndLoc(); |
3671 | 6.56M | } |
3672 | | |
3673 | 275M | static bool classof(const Stmt *T) { |
3674 | 275M | return T->getStmtClass() == ImplicitCastExprClass; |
3675 | 275M | } |
3676 | | |
3677 | | friend TrailingObjects; |
3678 | | friend class CastExpr; |
3679 | | }; |
3680 | | |
3681 | | /// ExplicitCastExpr - An explicit cast written in the source |
3682 | | /// code. |
3683 | | /// |
3684 | | /// This class is effectively an abstract class, because it provides |
3685 | | /// the basic representation of an explicitly-written cast without |
3686 | | /// specifying which kind of cast (C cast, functional cast, static |
3687 | | /// cast, etc.) was written; specific derived classes represent the |
3688 | | /// particular style of cast and its location information. |
3689 | | /// |
3690 | | /// Unlike implicit casts, explicit cast nodes have two different |
3691 | | /// types: the type that was written into the source code, and the |
3692 | | /// actual type of the expression as determined by semantic |
3693 | | /// analysis. These types may differ slightly. For example, in C++ one |
3694 | | /// can cast to a reference type, which indicates that the resulting |
3695 | | /// expression will be an lvalue or xvalue. The reference type, however, |
3696 | | /// will not be used as the type of the expression. |
3697 | | class ExplicitCastExpr : public CastExpr { |
3698 | | /// TInfo - Source type info for the (written) type |
3699 | | /// this expression is casting to. |
3700 | | TypeSourceInfo *TInfo; |
3701 | | |
3702 | | protected: |
3703 | | ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, |
3704 | | CastKind kind, Expr *op, unsigned PathSize, |
3705 | | bool HasFPFeatures, TypeSourceInfo *writtenTy) |
3706 | | : CastExpr(SC, exprTy, VK, kind, op, PathSize, HasFPFeatures), |
3707 | 5.22M | TInfo(writtenTy) { |
3708 | 5.22M | setDependence(computeDependence(this)); |
3709 | 5.22M | } |
3710 | | |
3711 | | /// Construct an empty explicit cast. |
3712 | | ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize, |
3713 | | bool HasFPFeatures) |
3714 | 100k | : CastExpr(SC, Shell, PathSize, HasFPFeatures) {} |
3715 | | |
3716 | | public: |
3717 | | /// getTypeInfoAsWritten - Returns the type source info for the type |
3718 | | /// that this expression is casting to. |
3719 | 1.07M | TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } |
3720 | 100k | void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } |
3721 | | |
3722 | | /// getTypeAsWritten - Returns the type that this expression is |
3723 | | /// casting to, as written in the source code. |
3724 | 5.66M | QualType getTypeAsWritten() const { return TInfo->getType(); } |
3725 | | |
3726 | 48.3M | static bool classof(const Stmt *T) { |
3727 | 48.3M | return T->getStmtClass() >= firstExplicitCastExprConstant && |
3728 | 48.3M | T->getStmtClass() <= lastExplicitCastExprConstant36.8M ; |
3729 | 48.3M | } |
3730 | | }; |
3731 | | |
3732 | | /// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style |
3733 | | /// cast in C++ (C++ [expr.cast]), which uses the syntax |
3734 | | /// (Type)expr. For example: @c (int)f. |
3735 | | class CStyleCastExpr final |
3736 | | : public ExplicitCastExpr, |
3737 | | private llvm::TrailingObjects<CStyleCastExpr, CXXBaseSpecifier *, |
3738 | | FPOptionsOverride> { |
3739 | | SourceLocation LPLoc; // the location of the left paren |
3740 | | SourceLocation RPLoc; // the location of the right paren |
3741 | | |
3742 | | CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, |
3743 | | unsigned PathSize, FPOptionsOverride FPO, |
3744 | | TypeSourceInfo *writtenTy, SourceLocation l, SourceLocation r) |
3745 | | : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, |
3746 | | FPO.requiresTrailingStorage(), writtenTy), |
3747 | 4.79M | LPLoc(l), RPLoc(r) { |
3748 | 4.79M | if (hasStoredFPFeatures()) |
3749 | 139k | *getTrailingFPFeatures() = FPO; |
3750 | 4.79M | } |
3751 | | |
3752 | | /// Construct an empty C-style explicit cast. |
3753 | | explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize, |
3754 | | bool HasFPFeatures) |
3755 | 27.8k | : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize, HasFPFeatures) {} |
3756 | | |
3757 | 139k | unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const { |
3758 | 139k | return path_size(); |
3759 | 139k | } |
3760 | | |
3761 | | public: |
3762 | | static CStyleCastExpr * |
3763 | | Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, |
3764 | | Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, |
3765 | | TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R); |
3766 | | |
3767 | | static CStyleCastExpr *CreateEmpty(const ASTContext &Context, |
3768 | | unsigned PathSize, bool HasFPFeatures); |
3769 | | |
3770 | 220k | SourceLocation getLParenLoc() const { return LPLoc; } |
3771 | 27.8k | void setLParenLoc(SourceLocation L) { LPLoc = L; } |
3772 | | |
3773 | 220k | SourceLocation getRParenLoc() const { return RPLoc; } |
3774 | 27.8k | void setRParenLoc(SourceLocation L) { RPLoc = L; } |
3775 | | |
3776 | 23.5M | SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; } |
3777 | 832k | SourceLocation getEndLoc() const LLVM_READONLY { |
3778 | 832k | return getSubExpr()->getEndLoc(); |
3779 | 832k | } |
3780 | | |
3781 | 68.8k | static bool classof(const Stmt *T) { |
3782 | 68.8k | return T->getStmtClass() == CStyleCastExprClass; |
3783 | 68.8k | } |
3784 | | |
3785 | | friend TrailingObjects; |
3786 | | friend class CastExpr; |
3787 | | }; |
3788 | | |
3789 | | /// A builtin binary operation expression such as "x + y" or "x <= y". |
3790 | | /// |
3791 | | /// This expression node kind describes a builtin binary operation, |
3792 | | /// such as "x + y" for integer values "x" and "y". The operands will |
3793 | | /// already have been converted to appropriate types (e.g., by |
3794 | | /// performing promotions or conversions). |
3795 | | /// |
3796 | | /// In C++, where operators may be overloaded, a different kind of |
3797 | | /// expression node (CXXOperatorCallExpr) is used to express the |
3798 | | /// invocation of an overloaded operator with operator syntax. Within |
3799 | | /// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is |
3800 | | /// used to store an expression "x + y" depends on the subexpressions |
3801 | | /// for x and y. If neither x or y is type-dependent, and the "+" |
3802 | | /// operator resolves to a built-in operation, BinaryOperator will be |
3803 | | /// used to express the computation (x and y may still be |
3804 | | /// value-dependent). If either x or y is type-dependent, or if the |
3805 | | /// "+" resolves to an overloaded operator, CXXOperatorCallExpr will |
3806 | | /// be used to express the computation. |
3807 | | class BinaryOperator : public Expr { |
3808 | | enum { LHS, RHS, END_EXPR }; |
3809 | | Stmt *SubExprs[END_EXPR]; |
3810 | | |
3811 | | public: |
3812 | | typedef BinaryOperatorKind Opcode; |
3813 | | |
3814 | | protected: |
3815 | | size_t offsetOfTrailingStorage() const; |
3816 | | |
3817 | | /// Return a pointer to the trailing FPOptions |
3818 | 14.5k | FPOptionsOverride *getTrailingFPFeatures() { |
3819 | 14.5k | assert(BinaryOperatorBits.HasFPFeatures); |
3820 | 0 | return reinterpret_cast<FPOptionsOverride *>( |
3821 | 14.5k | reinterpret_cast<char *>(this) + offsetOfTrailingStorage()); |
3822 | 14.5k | } |
3823 | 1.43k | const FPOptionsOverride *getTrailingFPFeatures() const { |
3824 | 1.43k | assert(BinaryOperatorBits.HasFPFeatures); |
3825 | 0 | return reinterpret_cast<const FPOptionsOverride *>( |
3826 | 1.43k | reinterpret_cast<const char *>(this) + offsetOfTrailingStorage()); |
3827 | 1.43k | } |
3828 | | |
3829 | | /// Build a binary operator, assuming that appropriate storage has been |
3830 | | /// allocated for the trailing objects when needed. |
3831 | | BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc, |
3832 | | QualType ResTy, ExprValueKind VK, ExprObjectKind OK, |
3833 | | SourceLocation opLoc, FPOptionsOverride FPFeatures); |
3834 | | |
3835 | | /// Construct an empty binary operator. |
3836 | 774k | explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) { |
3837 | 774k | BinaryOperatorBits.Opc = BO_Comma; |
3838 | 774k | } |
3839 | | |
3840 | | public: |
3841 | | static BinaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures); |
3842 | | |
3843 | | static BinaryOperator *Create(const ASTContext &C, Expr *lhs, Expr *rhs, |
3844 | | Opcode opc, QualType ResTy, ExprValueKind VK, |
3845 | | ExprObjectKind OK, SourceLocation opLoc, |
3846 | | FPOptionsOverride FPFeatures); |
3847 | 12.2M | SourceLocation getExprLoc() const { return getOperatorLoc(); } |
3848 | 18.5M | SourceLocation getOperatorLoc() const { return BinaryOperatorBits.OpLoc; } |
3849 | 817k | void setOperatorLoc(SourceLocation L) { BinaryOperatorBits.OpLoc = L; } |
3850 | | |
3851 | 158M | Opcode getOpcode() const { |
3852 | 158M | return static_cast<Opcode>(BinaryOperatorBits.Opc); |
3853 | 158M | } |
3854 | 817k | void setOpcode(Opcode Opc) { BinaryOperatorBits.Opc = Opc; } |
3855 | | |
3856 | 71.3M | Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } |
3857 | 817k | void setLHS(Expr *E) { SubExprs[LHS] = E; } |
3858 | 54.7M | Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } |
3859 | 817k | void setRHS(Expr *E) { SubExprs[RHS] = E; } |
3860 | | |
3861 | 8.16M | SourceLocation getBeginLoc() const LLVM_READONLY { |
3862 | 8.16M | return getLHS()->getBeginLoc(); |
3863 | 8.16M | } |
3864 | 619k | SourceLocation getEndLoc() const LLVM_READONLY { |
3865 | 619k | return getRHS()->getEndLoc(); |
3866 | 619k | } |
3867 | | |
3868 | | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
3869 | | /// corresponds to, e.g. "<<=". |
3870 | | static StringRef getOpcodeStr(Opcode Op); |
3871 | | |
3872 | 3.44k | StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); } |
3873 | | |
3874 | | /// Retrieve the binary opcode that corresponds to the given |
3875 | | /// overloaded operator. |
3876 | | static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); |
3877 | | |
3878 | | /// Retrieve the overloaded operator kind that corresponds to |
3879 | | /// the given binary opcode. |
3880 | | static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); |
3881 | | |
3882 | | /// predicates to categorize the respective opcodes. |
3883 | 70.2k | static bool isPtrMemOp(Opcode Opc) { |
3884 | 70.2k | return Opc == BO_PtrMemD || Opc == BO_PtrMemI69.0k ; |
3885 | 70.2k | } |
3886 | 70.2k | bool isPtrMemOp() const { return isPtrMemOp(getOpcode()); } |
3887 | | |
3888 | 214k | static bool isMultiplicativeOp(Opcode Opc) { |
3889 | 214k | return Opc >= BO_Mul && Opc <= BO_Rem; |
3890 | 214k | } |
3891 | 3.67k | bool isMultiplicativeOp() const { return isMultiplicativeOp(getOpcode()); } |
3892 | 4.92M | static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub3.80M ; } |
3893 | 4.59M | bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } |
3894 | 251k | static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr250k ; } |
3895 | 541 | bool isShiftOp() const { return isShiftOp(getOpcode()); } |
3896 | | |
3897 | 4.13M | static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or1.80M ; } |
3898 | 13.0k | bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } |
3899 | | |
3900 | 1.69M | static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE1.56M ; } |
3901 | 411k | bool isRelationalOp() const { return isRelationalOp(getOpcode()); } |
3902 | | |
3903 | 774k | static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE602k ; } |
3904 | 621k | bool isEqualityOp() const { return isEqualityOp(getOpcode()); } |
3905 | | |
3906 | 11.0M | static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && Opc<=BO_NE6.22M ; } |
3907 | 6.03M | bool isComparisonOp() const { return isComparisonOp(getOpcode()); } |
3908 | | |
3909 | 3.22k | static bool isCommaOp(Opcode Opc) { return Opc == BO_Comma; } |
3910 | 3.22k | bool isCommaOp() const { return isCommaOp(getOpcode()); } |
3911 | | |
3912 | 121k | static Opcode negateComparisonOp(Opcode Opc) { |
3913 | 121k | switch (Opc) { |
3914 | 0 | default: |
3915 | 0 | llvm_unreachable("Not a comparison operator."); |
3916 | 2.23k | case BO_LT: return BO_GE; |
3917 | 3.45k | case BO_GT: return BO_LE; |
3918 | 11.1k | case BO_LE: return BO_GT; |
3919 | 19.6k | case BO_GE: return BO_LT; |
3920 | 5.11k | case BO_EQ: return BO_NE; |
3921 | 79.5k | case BO_NE: return BO_EQ; |
3922 | 121k | } |
3923 | 121k | } |
3924 | | |
3925 | 137k | static Opcode reverseComparisonOp(Opcode Opc) { |
3926 | 137k | switch (Opc) { |
3927 | 0 | default: |
3928 | 0 | llvm_unreachable("Not a comparison operator."); |
3929 | 29.3k | case BO_LT: return BO_GT; |
3930 | 27.3k | case BO_GT: return BO_LT; |
3931 | 27.3k | case BO_LE: return BO_GE; |
3932 | 18.7k | case BO_GE: return BO_LE; |
3933 | 17.5k | case BO_EQ: |
3934 | 34.7k | case BO_NE: |
3935 | 34.7k | return Opc; |
3936 | 137k | } |
3937 | 137k | } |
3938 | | |
3939 | 28.2M | static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr26.6M ; } |
3940 | 28.2M | bool isLogicalOp() const { return isLogicalOp(getOpcode()); } |
3941 | | |
3942 | 11.5M | static bool isAssignmentOp(Opcode Opc) { |
3943 | 11.5M | return Opc >= BO_Assign && Opc <= BO_OrAssign1.94M ; |
3944 | 11.5M | } |
3945 | 11.5M | bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } |
3946 | | |
3947 | 11.5M | static bool isCompoundAssignmentOp(Opcode Opc) { |
3948 | 11.5M | return Opc > BO_Assign && Opc <= BO_OrAssign755k ; |
3949 | 11.5M | } |
3950 | 10.3M | bool isCompoundAssignmentOp() const { |
3951 | 10.3M | return isCompoundAssignmentOp(getOpcode()); |
3952 | 10.3M | } |
3953 | 37.7k | static Opcode getOpForCompoundAssignment(Opcode Opc) { |
3954 | 37.7k | assert(isCompoundAssignmentOp(Opc)); |
3955 | 37.7k | if (Opc >= BO_AndAssign) |
3956 | 6.15k | return Opcode(unsigned(Opc) - BO_AndAssign + BO_And); |
3957 | 31.5k | else |
3958 | 31.5k | return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul); |
3959 | 37.7k | } |
3960 | | |
3961 | 382 | static bool isShiftAssignOp(Opcode Opc) { |
3962 | 382 | return Opc == BO_ShlAssign || Opc == BO_ShrAssign378 ; |
3963 | 382 | } |
3964 | 0 | bool isShiftAssignOp() const { |
3965 | 0 | return isShiftAssignOp(getOpcode()); |
3966 | 0 | } |
3967 | | |
3968 | | // Return true if a binary operator using the specified opcode and operands |
3969 | | // would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized |
3970 | | // integer to a pointer. |
3971 | | static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc, |
3972 | | Expr *LHS, Expr *RHS); |
3973 | | |
3974 | 386M | static bool classof(const Stmt *S) { |
3975 | 386M | return S->getStmtClass() >= firstBinaryOperatorConstant && |
3976 | 386M | S->getStmtClass() <= lastBinaryOperatorConstant379M ; |
3977 | 386M | } |
3978 | | |
3979 | | // Iterators |
3980 | 10.5M | child_range children() { |
3981 | 10.5M | return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); |
3982 | 10.5M | } |
3983 | 0 | const_child_range children() const { |
3984 | 0 | return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); |
3985 | 0 | } |
3986 | | |
3987 | | /// Set and fetch the bit that shows whether FPFeatures needs to be |
3988 | | /// allocated in Trailing Storage |
3989 | 817k | void setHasStoredFPFeatures(bool B) { BinaryOperatorBits.HasFPFeatures = B; } |
3990 | 8.71M | bool hasStoredFPFeatures() const { return BinaryOperatorBits.HasFPFeatures; } |
3991 | | |
3992 | | /// Get FPFeatures from trailing storage |
3993 | 1.43k | FPOptionsOverride getStoredFPFeatures() const { |
3994 | 1.43k | assert(hasStoredFPFeatures()); |
3995 | 0 | return *getTrailingFPFeatures(); |
3996 | 1.43k | } |
3997 | | /// Set FPFeatures in trailing storage, used only by Serialization |
3998 | 14.5k | void setStoredFPFeatures(FPOptionsOverride F) { |
3999 | 14.5k | assert(BinaryOperatorBits.HasFPFeatures); |
4000 | 0 | *getTrailingFPFeatures() = F; |
4001 | 14.5k | } |
4002 | | |
4003 | | // Get the FP features status of this operator. Only meaningful for |
4004 | | // operations on floating point types. |
4005 | 584k | FPOptions getFPFeaturesInEffect(const LangOptions &LO) const { |
4006 | 584k | if (BinaryOperatorBits.HasFPFeatures) |
4007 | 1.33k | return getStoredFPFeatures().applyOverrides(LO); |
4008 | 583k | return FPOptions::defaultWithoutTrailingStorage(LO); |
4009 | 584k | } |
4010 | | |
4011 | | // This is used in ASTImporter |
4012 | 1.30M | FPOptionsOverride getFPFeatures(const LangOptions &LO) const { |
4013 | 1.30M | if (BinaryOperatorBits.HasFPFeatures) |
4014 | 47 | return getStoredFPFeatures(); |
4015 | 1.30M | return FPOptionsOverride(); |
4016 | 1.30M | } |
4017 | | |
4018 | | // Get the FP contractability status of this operator. Only meaningful for |
4019 | | // operations on floating point types. |
4020 | 0 | bool isFPContractableWithinStatement(const LangOptions &LO) const { |
4021 | 0 | return getFPFeaturesInEffect(LO).allowFPContractWithinStatement(); |
4022 | 0 | } |
4023 | | |
4024 | | // Get the FENV_ACCESS status of this operator. Only meaningful for |
4025 | | // operations on floating point types. |
4026 | 0 | bool isFEnvAccessOn(const LangOptions &LO) const { |
4027 | 0 | return getFPFeaturesInEffect(LO).getAllowFEnvAccess(); |
4028 | 0 | } |
4029 | | |
4030 | | protected: |
4031 | | BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc, |
4032 | | QualType ResTy, ExprValueKind VK, ExprObjectKind OK, |
4033 | | SourceLocation opLoc, FPOptionsOverride FPFeatures, |
4034 | | bool dead2); |
4035 | | |
4036 | | /// Construct an empty BinaryOperator, SC is CompoundAssignOperator. |
4037 | 42.9k | BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) { |
4038 | 42.9k | BinaryOperatorBits.Opc = BO_MulAssign; |
4039 | 42.9k | } |
4040 | | |
4041 | | /// Return the size in bytes needed for the trailing objects. |
4042 | | /// Used to allocate the right amount of storage. |
4043 | 9.14M | static unsigned sizeOfTrailingObjects(bool HasFPFeatures) { |
4044 | 9.14M | return HasFPFeatures * sizeof(FPOptionsOverride); |
4045 | 9.14M | } |
4046 | | }; |
4047 | | |
4048 | | /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep |
4049 | | /// track of the type the operation is performed in. Due to the semantics of |
4050 | | /// these operators, the operands are promoted, the arithmetic performed, an |
4051 | | /// implicit conversion back to the result type done, then the assignment takes |
4052 | | /// place. This captures the intermediate type which the computation is done |
4053 | | /// in. |
4054 | | class CompoundAssignOperator : public BinaryOperator { |
4055 | | QualType ComputationLHSType; |
4056 | | QualType ComputationResultType; |
4057 | | |
4058 | | /// Construct an empty CompoundAssignOperator. |
4059 | | explicit CompoundAssignOperator(const ASTContext &C, EmptyShell Empty, |
4060 | | bool hasFPFeatures) |
4061 | 42.9k | : BinaryOperator(CompoundAssignOperatorClass, Empty) {} |
4062 | | |
4063 | | protected: |
4064 | | CompoundAssignOperator(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, |
4065 | | QualType ResType, ExprValueKind VK, ExprObjectKind OK, |
4066 | | SourceLocation OpLoc, FPOptionsOverride FPFeatures, |
4067 | | QualType CompLHSType, QualType CompResultType) |
4068 | | : BinaryOperator(C, lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures, |
4069 | | true), |
4070 | 209k | ComputationLHSType(CompLHSType), ComputationResultType(CompResultType) { |
4071 | 209k | assert(isCompoundAssignmentOp() && |
4072 | 209k | "Only should be used for compound assignments"); |
4073 | 209k | } |
4074 | | |
4075 | | public: |
4076 | | static CompoundAssignOperator *CreateEmpty(const ASTContext &C, |
4077 | | bool hasFPFeatures); |
4078 | | |
4079 | | static CompoundAssignOperator * |
4080 | | Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, |
4081 | | ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, |
4082 | | FPOptionsOverride FPFeatures, QualType CompLHSType = QualType(), |
4083 | | QualType CompResultType = QualType()); |
4084 | | |
4085 | | // The two computation types are the type the LHS is converted |
4086 | | // to for the computation and the type of the result; the two are |
4087 | | // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). |
4088 | 109k | QualType getComputationLHSType() const { return ComputationLHSType; } |
4089 | 42.9k | void setComputationLHSType(QualType T) { ComputationLHSType = T; } |
4090 | | |
4091 | 179k | QualType getComputationResultType() const { return ComputationResultType; } |
4092 | 42.9k | void setComputationResultType(QualType T) { ComputationResultType = T; } |
4093 | | |
4094 | 1.59M | static bool classof(const Stmt *S) { |
4095 | 1.59M | return S->getStmtClass() == CompoundAssignOperatorClass; |
4096 | 1.59M | } |
4097 | | }; |
4098 | | |
4099 | 16.0k | inline size_t BinaryOperator::offsetOfTrailingStorage() const { |
4100 | 16.0k | assert(BinaryOperatorBits.HasFPFeatures); |
4101 | 16.0k | return isa<CompoundAssignOperator>(this) ? sizeof(CompoundAssignOperator)432 |
4102 | 16.0k | : sizeof(BinaryOperator)15.5k ; |
4103 | 16.0k | } |
4104 | | |
4105 | | /// AbstractConditionalOperator - An abstract base class for |
4106 | | /// ConditionalOperator and BinaryConditionalOperator. |
4107 | | class AbstractConditionalOperator : public Expr { |
4108 | | SourceLocation QuestionLoc, ColonLoc; |
4109 | | friend class ASTStmtReader; |
4110 | | |
4111 | | protected: |
4112 | | AbstractConditionalOperator(StmtClass SC, QualType T, ExprValueKind VK, |
4113 | | ExprObjectKind OK, SourceLocation qloc, |
4114 | | SourceLocation cloc) |
4115 | 274k | : Expr(SC, T, VK, OK), QuestionLoc(qloc), ColonLoc(cloc) {} |
4116 | | |
4117 | | AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) |
4118 | 23.3k | : Expr(SC, Empty) { } |
4119 | | |
4120 | | public: |
4121 | | // getCond - Return the expression representing the condition for |
4122 | | // the ?: operator. |
4123 | | Expr *getCond() const; |
4124 | | |
4125 | | // getTrueExpr - Return the subexpression representing the value of |
4126 | | // the expression if the condition evaluates to true. |
4127 | | Expr *getTrueExpr() const; |
4128 | | |
4129 | | // getFalseExpr - Return the subexpression representing the value of |
4130 | | // the expression if the condition evaluates to false. This is |
4131 | | // the same as getRHS. |
4132 | | Expr *getFalseExpr() const; |
4133 | | |
4134 | 273k | SourceLocation getQuestionLoc() const { return QuestionLoc; } |
4135 | 66.9k | SourceLocation getColonLoc() const { return ColonLoc; } |
4136 | | |
4137 | 41.3M | static bool classof(const Stmt *T) { |
4138 | 41.3M | return T->getStmtClass() == ConditionalOperatorClass || |
4139 | 41.3M | T->getStmtClass() == BinaryConditionalOperatorClass41.0M ; |
4140 | 41.3M | } |
4141 | | }; |
4142 | | |
4143 | | /// ConditionalOperator - The ?: ternary operator. The GNU "missing |
4144 | | /// middle" extension is a BinaryConditionalOperator. |
4145 | | class ConditionalOperator : public AbstractConditionalOperator { |
4146 | | enum { COND, LHS, RHS, END_EXPR }; |
4147 | | Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. |
4148 | | |
4149 | | friend class ASTStmtReader; |
4150 | | public: |
4151 | | ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, |
4152 | | SourceLocation CLoc, Expr *rhs, QualType t, |
4153 | | ExprValueKind VK, ExprObjectKind OK) |
4154 | | : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, QLoc, |
4155 | 274k | CLoc) { |
4156 | 274k | SubExprs[COND] = cond; |
4157 | 274k | SubExprs[LHS] = lhs; |
4158 | 274k | SubExprs[RHS] = rhs; |
4159 | 274k | setDependence(computeDependence(this)); |
4160 | 274k | } |
4161 | | |
4162 | | /// Build an empty conditional operator. |
4163 | | explicit ConditionalOperator(EmptyShell Empty) |
4164 | 23.3k | : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } |
4165 | | |
4166 | | // getCond - Return the expression representing the condition for |
4167 | | // the ?: operator. |
4168 | 2.17M | Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } |
4169 | | |
4170 | | // getTrueExpr - Return the subexpression representing the value of |
4171 | | // the expression if the condition evaluates to true. |
4172 | 709k | Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } |
4173 | | |
4174 | | // getFalseExpr - Return the subexpression representing the value of |
4175 | | // the expression if the condition evaluates to false. This is |
4176 | | // the same as getRHS. |
4177 | 758k | Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } |
4178 | | |
4179 | 565k | Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } |
4180 | 575k | Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } |
4181 | | |
4182 | 617k | SourceLocation getBeginLoc() const LLVM_READONLY { |
4183 | 617k | return getCond()->getBeginLoc(); |
4184 | 617k | } |
4185 | 15.4k | SourceLocation getEndLoc() const LLVM_READONLY { |
4186 | 15.4k | return getRHS()->getEndLoc(); |
4187 | 15.4k | } |
4188 | | |
4189 | 3.28M | static bool classof(const Stmt *T) { |
4190 | 3.28M | return T->getStmtClass() == ConditionalOperatorClass; |
4191 | 3.28M | } |
4192 | | |
4193 | | // Iterators |
4194 | 51.2k | child_range children() { |
4195 | 51.2k | return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); |
4196 | 51.2k | } |
4197 | 0 | const_child_range children() const { |
4198 | 0 | return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); |
4199 | 0 | } |
4200 | | }; |
4201 | | |
4202 | | /// BinaryConditionalOperator - The GNU extension to the conditional |
4203 | | /// operator which allows the middle operand to be omitted. |
4204 | | /// |
4205 | | /// This is a different expression kind on the assumption that almost |
4206 | | /// every client ends up needing to know that these are different. |
4207 | | class BinaryConditionalOperator : public AbstractConditionalOperator { |
4208 | | enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; |
4209 | | |
4210 | | /// - the common condition/left-hand-side expression, which will be |
4211 | | /// evaluated as the opaque value |
4212 | | /// - the condition, expressed in terms of the opaque value |
4213 | | /// - the left-hand-side, expressed in terms of the opaque value |
4214 | | /// - the right-hand-side |
4215 | | Stmt *SubExprs[NUM_SUBEXPRS]; |
4216 | | OpaqueValueExpr *OpaqueValue; |
4217 | | |
4218 | | friend class ASTStmtReader; |
4219 | | public: |
4220 | | BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, |
4221 | | Expr *cond, Expr *lhs, Expr *rhs, |
4222 | | SourceLocation qloc, SourceLocation cloc, |
4223 | | QualType t, ExprValueKind VK, ExprObjectKind OK) |
4224 | | : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, |
4225 | | qloc, cloc), |
4226 | 279 | OpaqueValue(opaqueValue) { |
4227 | 279 | SubExprs[COMMON] = common; |
4228 | 279 | SubExprs[COND] = cond; |
4229 | 279 | SubExprs[LHS] = lhs; |
4230 | 279 | SubExprs[RHS] = rhs; |
4231 | 279 | assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value"); |
4232 | 0 | setDependence(computeDependence(this)); |
4233 | 279 | } |
4234 | | |
4235 | | /// Build an empty conditional operator. |
4236 | | explicit BinaryConditionalOperator(EmptyShell Empty) |
4237 | 3 | : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } |
4238 | | |
4239 | | /// getCommon - Return the common expression, written to the |
4240 | | /// left of the condition. The opaque value will be bound to the |
4241 | | /// result of this expression. |
4242 | 3.62k | Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } |
4243 | | |
4244 | | /// getOpaqueValue - Return the opaque value placeholder. |
4245 | 3.07k | OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } |
4246 | | |
4247 | | /// getCond - Return the condition expression; this is defined |
4248 | | /// in terms of the opaque value. |
4249 | 2.94k | Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } |
4250 | | |
4251 | | /// getTrueExpr - Return the subexpression which will be |
4252 | | /// evaluated if the condition evaluates to true; this is defined |
4253 | | /// in terms of the opaque value. |
4254 | 2.45k | Expr *getTrueExpr() const { |
4255 | 2.45k | return cast<Expr>(SubExprs[LHS]); |
4256 | 2.45k | } |
4257 | | |
4258 | | /// getFalseExpr - Return the subexpression which will be |
4259 | | /// evaluated if the condnition evaluates to false; this is |
4260 | | /// defined in terms of the opaque value. |
4261 | 2.14k | Expr *getFalseExpr() const { |
4262 | 2.14k | return cast<Expr>(SubExprs[RHS]); |
4263 | 2.14k | } |
4264 | | |
4265 | 1.31k | SourceLocation getBeginLoc() const LLVM_READONLY { |
4266 | 1.31k | return getCommon()->getBeginLoc(); |
4267 | 1.31k | } |
4268 | 322 | SourceLocation getEndLoc() const LLVM_READONLY { |
4269 | 322 | return getFalseExpr()->getEndLoc(); |
4270 | 322 | } |
4271 | | |
4272 | 247k | static bool classof(const Stmt *T) { |
4273 | 247k | return T->getStmtClass() == BinaryConditionalOperatorClass; |
4274 | 247k | } |
4275 | | |
4276 | | // Iterators |
4277 | 354 | child_range children() { |
4278 | 354 | return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); |
4279 | 354 | } |
4280 | 0 | const_child_range children() const { |
4281 | 0 | return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS); |
4282 | 0 | } |
4283 | | }; |
4284 | | |
4285 | 646k | inline Expr *AbstractConditionalOperator::getCond() const { |
4286 | 646k | if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) |
4287 | 645k | return co->getCond(); |
4288 | 1.40k | return cast<BinaryConditionalOperator>(this)->getCond(); |
4289 | 646k | } |
4290 | | |
4291 | 504k | inline Expr *AbstractConditionalOperator::getTrueExpr() const { |
4292 | 504k | if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) |
4293 | 503k | return co->getTrueExpr(); |
4294 | 1.09k | return cast<BinaryConditionalOperator>(this)->getTrueExpr(); |
4295 | 504k | } |
4296 | | |
4297 | 514k | inline Expr *AbstractConditionalOperator::getFalseExpr() const { |
4298 | 514k | if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) |
4299 | 513k | return co->getFalseExpr(); |
4300 | 1.00k | return cast<BinaryConditionalOperator>(this)->getFalseExpr(); |
4301 | 514k | } |
4302 | | |
4303 | | /// AddrLabelExpr - The GNU address of label extension, representing &&label. |
4304 | | class AddrLabelExpr : public Expr { |
4305 | | SourceLocation AmpAmpLoc, LabelLoc; |
4306 | | LabelDecl *Label; |
4307 | | public: |
4308 | | AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, |
4309 | | QualType t) |
4310 | | : Expr(AddrLabelExprClass, t, VK_PRValue, OK_Ordinary), AmpAmpLoc(AALoc), |
4311 | 520 | LabelLoc(LLoc), Label(L) { |
4312 | 520 | setDependence(ExprDependence::None); |
4313 | 520 | } |
4314 | | |
4315 | | /// Build an empty address of a label expression. |
4316 | | explicit AddrLabelExpr(EmptyShell Empty) |
4317 | 6 | : Expr(AddrLabelExprClass, Empty) { } |
4318 | | |
4319 | 18 | SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } |
4320 | 6 | void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } |
4321 | 19 | SourceLocation getLabelLoc() const { return LabelLoc; } |
4322 | 6 | void setLabelLoc(SourceLocation L) { LabelLoc = L; } |
4323 | | |
4324 | 2.36k | SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; } |
4325 | 822 | SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; } |
4326 | | |
4327 | 1.29k | LabelDecl *getLabel() const { return Label; } |
4328 | 6 | void setLabel(LabelDecl *L) { Label = L; } |
4329 | | |
4330 | 3.03k | static bool classof(const Stmt *T) { |
4331 | 3.03k | return T->getStmtClass() == AddrLabelExprClass; |
4332 | 3.03k | } |
4333 | | |
4334 | | // Iterators |
4335 | 1.38k | child_range children() { |
4336 | 1.38k | return child_range(child_iterator(), child_iterator()); |
4337 | 1.38k | } |
4338 | 0 | const_child_range children() const { |
4339 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
4340 | 0 | } |
4341 | | }; |
4342 | | |
4343 | | /// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). |
4344 | | /// The StmtExpr contains a single CompoundStmt node, which it evaluates and |
4345 | | /// takes the value of the last subexpression. |
4346 | | /// |
4347 | | /// A StmtExpr is always an r-value; values "returned" out of a |
4348 | | /// StmtExpr will be copied. |
4349 | | class StmtExpr : public Expr { |
4350 | | Stmt *SubStmt; |
4351 | | SourceLocation LParenLoc, RParenLoc; |
4352 | | public: |
4353 | | StmtExpr(CompoundStmt *SubStmt, QualType T, SourceLocation LParenLoc, |
4354 | | SourceLocation RParenLoc, unsigned TemplateDepth) |
4355 | | : Expr(StmtExprClass, T, VK_PRValue, OK_Ordinary), SubStmt(SubStmt), |
4356 | 8.98k | LParenLoc(LParenLoc), RParenLoc(RParenLoc) { |
4357 | 8.98k | setDependence(computeDependence(this, TemplateDepth)); |
4358 | | // FIXME: A templated statement expression should have an associated |
4359 | | // DeclContext so that nested declarations always have a dependent context. |
4360 | 8.98k | StmtExprBits.TemplateDepth = TemplateDepth; |
4361 | 8.98k | } |
4362 | | |
4363 | | /// Build an empty statement expression. |
4364 | 27 | explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } |
4365 | | |
4366 | 13.7k | CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } |
4367 | 12.2k | const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } |
4368 | 27 | void setSubStmt(CompoundStmt *S) { SubStmt = S; } |
4369 | | |
4370 | 12.8k | SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; } |
4371 | 358 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
4372 | | |
4373 | 815 | SourceLocation getLParenLoc() const { return LParenLoc; } |
4374 | 27 | void setLParenLoc(SourceLocation L) { LParenLoc = L; } |
4375 | 811 | SourceLocation getRParenLoc() const { return RParenLoc; } |
4376 | 27 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
4377 | | |
4378 | 815 | unsigned getTemplateDepth() const { return StmtExprBits.TemplateDepth; } |
4379 | | |
4380 | 34.9M | static bool classof(const Stmt *T) { |
4381 | 34.9M | return T->getStmtClass() == StmtExprClass; |
4382 | 34.9M | } |
4383 | | |
4384 | | // Iterators |
4385 | 11.9k | child_range children() { return child_range(&SubStmt, &SubStmt+1); } |
4386 | 0 | const_child_range children() const { |
4387 | 0 | return const_child_range(&SubStmt, &SubStmt + 1); |
4388 | 0 | } |
4389 | | }; |
4390 | | |
4391 | | /// ShuffleVectorExpr - clang-specific builtin-in function |
4392 | | /// __builtin_shufflevector. |
4393 | | /// This AST node represents a operator that does a constant |
4394 | | /// shuffle, similar to LLVM's shufflevector instruction. It takes |
4395 | | /// two vectors and a variable number of constant indices, |
4396 | | /// and returns the appropriately shuffled vector. |
4397 | | class ShuffleVectorExpr : public Expr { |
4398 | | SourceLocation BuiltinLoc, RParenLoc; |
4399 | | |
4400 | | // SubExprs - the list of values passed to the __builtin_shufflevector |
4401 | | // function. The first two are vectors, and the rest are constant |
4402 | | // indices. The number of values in this list is always |
4403 | | // 2+the number of indices in the vector type. |
4404 | | Stmt **SubExprs; |
4405 | | unsigned NumExprs; |
4406 | | |
4407 | | public: |
4408 | | ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr*> args, QualType Type, |
4409 | | SourceLocation BLoc, SourceLocation RP); |
4410 | | |
4411 | | /// Build an empty vector-shuffle expression. |
4412 | | explicit ShuffleVectorExpr(EmptyShell Empty) |
4413 | 2 | : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { } |
4414 | | |
4415 | 2.30k | SourceLocation getBuiltinLoc() const { return BuiltinLoc; } |
4416 | 2 | void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } |
4417 | | |
4418 | 2.30k | SourceLocation getRParenLoc() const { return RParenLoc; } |
4419 | 2 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
4420 | | |
4421 | 507k | SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; } |
4422 | 32.1k | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
4423 | | |
4424 | 52 | static bool classof(const Stmt *T) { |
4425 | 52 | return T->getStmtClass() == ShuffleVectorExprClass; |
4426 | 52 | } |
4427 | | |
4428 | | /// getNumSubExprs - Return the size of the SubExprs array. This includes the |
4429 | | /// constant expression, the actual arguments passed in, and the function |
4430 | | /// pointers. |
4431 | 171k | unsigned getNumSubExprs() const { return NumExprs; } |
4432 | | |
4433 | | /// Retrieve the array of expressions. |
4434 | 157k | Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } |
4435 | | |
4436 | | /// getExpr - Return the Expr at the specified index. |
4437 | 26.8k | Expr *getExpr(unsigned Index) { |
4438 | 26.8k | assert((Index < NumExprs) && "Arg access out of range!"); |
4439 | 0 | return cast<Expr>(SubExprs[Index]); |
4440 | 26.8k | } |
4441 | 7.50k | const Expr *getExpr(unsigned Index) const { |
4442 | 7.50k | assert((Index < NumExprs) && "Arg access out of range!"); |
4443 | 0 | return cast<Expr>(SubExprs[Index]); |
4444 | 7.50k | } |
4445 | | |
4446 | | void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs); |
4447 | | |
4448 | 7.50k | llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const { |
4449 | 7.50k | assert((N < NumExprs - 2) && "Shuffle idx out of range!"); |
4450 | 0 | return getExpr(N+2)->EvaluateKnownConstInt(Ctx); |
4451 | 7.50k | } |
4452 | | |
4453 | | // Iterators |
4454 | 318k | child_range children() { |
4455 | 318k | return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); |
4456 | 318k | } |
4457 | 0 | const_child_range children() const { |
4458 | 0 | return const_child_range(&SubExprs[0], &SubExprs[0] + NumExprs); |
4459 | 0 | } |
4460 | | }; |
4461 | | |
4462 | | /// ConvertVectorExpr - Clang builtin function __builtin_convertvector |
4463 | | /// This AST node provides support for converting a vector type to another |
4464 | | /// vector type of the same arity. |
4465 | | class ConvertVectorExpr : public Expr { |
4466 | | private: |
4467 | | Stmt *SrcExpr; |
4468 | | TypeSourceInfo *TInfo; |
4469 | | SourceLocation BuiltinLoc, RParenLoc; |
4470 | | |
4471 | | friend class ASTReader; |
4472 | | friend class ASTStmtReader; |
4473 | 0 | explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {} |
4474 | | |
4475 | | public: |
4476 | | ConvertVectorExpr(Expr *SrcExpr, TypeSourceInfo *TI, QualType DstType, |
4477 | | ExprValueKind VK, ExprObjectKind OK, |
4478 | | SourceLocation BuiltinLoc, SourceLocation RParenLoc) |
4479 | | : Expr(ConvertVectorExprClass, DstType, VK, OK), SrcExpr(SrcExpr), |
4480 | 21.8k | TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) { |
4481 | 21.8k | setDependence(computeDependence(this)); |
4482 | 21.8k | } |
4483 | | |
4484 | | /// getSrcExpr - Return the Expr to be converted. |
4485 | 23.2k | Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); } |
4486 | | |
4487 | | /// getTypeSourceInfo - Return the destination type. |
4488 | 22.7k | TypeSourceInfo *getTypeSourceInfo() const { |
4489 | 22.7k | return TInfo; |
4490 | 22.7k | } |
4491 | 0 | void setTypeSourceInfo(TypeSourceInfo *ti) { |
4492 | 0 | TInfo = ti; |
4493 | 0 | } |
4494 | | |
4495 | | /// getBuiltinLoc - Return the location of the __builtin_convertvector token. |
4496 | 854 | SourceLocation getBuiltinLoc() const { return BuiltinLoc; } |
4497 | | |
4498 | | /// getRParenLoc - Return the location of final right parenthesis. |
4499 | 854 | SourceLocation getRParenLoc() const { return RParenLoc; } |
4500 | | |
4501 | 26.8k | SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; } |
4502 | 20.7k | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
4503 | | |
4504 | 1 | static bool classof(const Stmt *T) { |
4505 | 1 | return T->getStmtClass() == ConvertVectorExprClass; |
4506 | 1 | } |
4507 | | |
4508 | | // Iterators |
4509 | 45.0k | child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } |
4510 | 0 | const_child_range children() const { |
4511 | 0 | return const_child_range(&SrcExpr, &SrcExpr + 1); |
4512 | 0 | } |
4513 | | }; |
4514 | | |
4515 | | /// ChooseExpr - GNU builtin-in function __builtin_choose_expr. |
4516 | | /// This AST node is similar to the conditional operator (?:) in C, with |
4517 | | /// the following exceptions: |
4518 | | /// - the test expression must be a integer constant expression. |
4519 | | /// - the expression returned acts like the chosen subexpression in every |
4520 | | /// visible way: the type is the same as that of the chosen subexpression, |
4521 | | /// and all predicates (whether it's an l-value, whether it's an integer |
4522 | | /// constant expression, etc.) return the same result as for the chosen |
4523 | | /// sub-expression. |
4524 | | class ChooseExpr : public Expr { |
4525 | | enum { COND, LHS, RHS, END_EXPR }; |
4526 | | Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. |
4527 | | SourceLocation BuiltinLoc, RParenLoc; |
4528 | | bool CondIsTrue; |
4529 | | public: |
4530 | | ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, |
4531 | | ExprValueKind VK, ExprObjectKind OK, SourceLocation RP, |
4532 | | bool condIsTrue) |
4533 | | : Expr(ChooseExprClass, t, VK, OK), BuiltinLoc(BLoc), RParenLoc(RP), |
4534 | 76 | CondIsTrue(condIsTrue) { |
4535 | 76 | SubExprs[COND] = cond; |
4536 | 76 | SubExprs[LHS] = lhs; |
4537 | 76 | SubExprs[RHS] = rhs; |
4538 | | |
4539 | 76 | setDependence(computeDependence(this)); |
4540 | 76 | } |
4541 | | |
4542 | | /// Build an empty __builtin_choose_expr. |
4543 | 3 | explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } |
4544 | | |
4545 | | /// isConditionTrue - Return whether the condition is true (i.e. not |
4546 | | /// equal to zero). |
4547 | 449 | bool isConditionTrue() const { |
4548 | 449 | assert(!isConditionDependent() && |
4549 | 449 | "Dependent condition isn't true or false"); |
4550 | 0 | return CondIsTrue; |
4551 | 449 | } |
4552 | 3 | void setIsConditionTrue(bool isTrue) { CondIsTrue = isTrue; } |
4553 | | |
4554 | 827 | bool isConditionDependent() const { |
4555 | 827 | return getCond()->isTypeDependent() || getCond()->isValueDependent(); |
4556 | 827 | } |
4557 | | |
4558 | | /// getChosenSubExpr - Return the subexpression chosen according to the |
4559 | | /// condition. |
4560 | 354 | Expr *getChosenSubExpr() const { |
4561 | 354 | return isConditionTrue() ? getLHS()216 : getRHS()138 ; |
4562 | 354 | } |
4563 | | |
4564 | 1.80k | Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } |
4565 | 3 | void setCond(Expr *E) { SubExprs[COND] = E; } |
4566 | 325 | Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } |
4567 | 3 | void setLHS(Expr *E) { SubExprs[LHS] = E; } |
4568 | 237 | Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } |
4569 | 3 | void setRHS(Expr *E) { SubExprs[RHS] = E; } |
4570 | | |
4571 | 19 | SourceLocation getBuiltinLoc() const { return BuiltinLoc; } |
4572 | 3 | void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } |
4573 | | |
4574 | 19 | SourceLocation getRParenLoc() const { return RParenLoc; } |
4575 | 3 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
4576 | | |
4577 | 79 | SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; } |
4578 | 44 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
4579 | | |
4580 | 375M | static bool classof(const Stmt *T) { |
4581 | 375M | return T->getStmtClass() == ChooseExprClass; |
4582 | 375M | } |
4583 | | |
4584 | | // Iterators |
4585 | 55 | child_range children() { |
4586 | 55 | return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); |
4587 | 55 | } |
4588 | 0 | const_child_range children() const { |
4589 | 0 | return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); |
4590 | 0 | } |
4591 | | }; |
4592 | | |
4593 | | /// GNUNullExpr - Implements the GNU __null extension, which is a name |
4594 | | /// for a null pointer constant that has integral type (e.g., int or |
4595 | | /// long) and is the same size and alignment as a pointer. The __null |
4596 | | /// extension is typically only used by system headers, which define |
4597 | | /// NULL as __null in C++ rather than using 0 (which is an integer |
4598 | | /// that may not match the size of a pointer). |
4599 | | class GNUNullExpr : public Expr { |
4600 | | /// TokenLoc - The location of the __null keyword. |
4601 | | SourceLocation TokenLoc; |
4602 | | |
4603 | | public: |
4604 | | GNUNullExpr(QualType Ty, SourceLocation Loc) |
4605 | 3.61k | : Expr(GNUNullExprClass, Ty, VK_PRValue, OK_Ordinary), TokenLoc(Loc) { |
4606 | 3.61k | setDependence(ExprDependence::None); |
4607 | 3.61k | } |
4608 | | |
4609 | | /// Build an empty GNU __null expression. |
4610 | 63 | explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } |
4611 | | |
4612 | | /// getTokenLocation - The location of the __null token. |
4613 | 97 | SourceLocation getTokenLocation() const { return TokenLoc; } |
4614 | 63 | void setTokenLocation(SourceLocation L) { TokenLoc = L; } |
4615 | | |
4616 | 12.9k | SourceLocation getBeginLoc() const LLVM_READONLY { return TokenLoc; } |
4617 | 727 | SourceLocation getEndLoc() const LLVM_READONLY { return TokenLoc; } |
4618 | | |
4619 | 11.8M | static bool classof(const Stmt *T) { |
4620 | 11.8M | return T->getStmtClass() == GNUNullExprClass; |
4621 | 11.8M | } |
4622 | | |
4623 | | // Iterators |
4624 | 9.99k | child_range children() { |
4625 | 9.99k | return child_range(child_iterator(), child_iterator()); |
4626 | 9.99k | } |
4627 | 0 | const_child_range children() const { |
4628 | 0 | return const_child_range(const_child_iterator(), const_child_iterator()); |
4629 | 0 | } |
4630 | | }; |
4631 | | |
4632 | | /// Represents a call to the builtin function \c __builtin_va_arg. |
4633 | | class VAArgExpr : public Expr { |
4634 | | Stmt *Val; |
4635 | | llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfo; |
4636 | | SourceLocation BuiltinLoc, RParenLoc; |
4637 | | public: |
4638 | | VAArgExpr(SourceLocation BLoc, Expr *e, TypeSourceInfo *TInfo, |
4639 | | SourceLocation RPLoc, QualType t, bool IsMS) |
4640 | | : Expr(VAArgExprClass, t, VK_PRValue, OK_Ordinary), Val(e), |
4641 | 1.11k | TInfo(TInfo, IsMS), BuiltinLoc(BLoc), RParenLoc(RPLoc) { |
4642 | 1.11k | setDependence(computeDependence(this)); |
4643 | 1.11k | } |
4644 | | |
4645 | | /// Create an empty __builtin_va_arg expression. |
4646 | | explicit VAArgExpr(EmptyShell Empty) |
4647 | 2 | : Expr(VAArgExprClass, Empty), Val(nullptr), TInfo(nullptr, false) {} |
4648 | | |
4649 | 54 | const Expr *getSubExpr() const { return cast<Expr>(Val); } |
4650 | 1.99k | Expr *getSubExpr() { return cast<Expr>(Val); } |
4651 | 2 | void setSubExpr(Expr *E) { Val = E; } |
4652 | | |
4653 | | /// Returns whether this is really a Win64 ABI va_arg expression. |
4654 | 1.72k | bool isMicrosoftABI() const { return TInfo.getInt(); } |
4655 | 2 | void setIsMicrosoftABI(bool IsMS) { TInfo.setInt(IsMS); } |
4656 | | |
4657 | 1.21k | TypeSourceInfo *getWrittenTypeInfo() const { return TInfo.getPointer(); } |
4658 | 2 | void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo.setPointer(TI); } |
4659 | | |
4660 | 15 | SourceLocation getBuiltinLoc() const { return BuiltinLoc; } |
4661 | 2 | void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } |
4662 | | |
4663 | 15 | SourceLocation getRParenLoc() const { return RParenLoc; } |
4664 | 2 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
4665 | | |
4666 | 5.22k | SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; } |
4667 | 489 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
4668 | | |
4669 | 125 | static bool classof(const Stmt *T) { |
4670 | 125 | return T->getStmtClass() == VAArgExprClass; |
4671 | 125 | } |
4672 | | |
4673 | | // Iterators |
4674 | 3.40k | child_range children() { return child_range(&Val, &Val+1); } |
4675 | 0 | const_child_range children() const { |
4676 | 0 | return const_child_range(&Val, &Val + 1); |
4677 | 0 | } |
4678 | | }; |
4679 | | |
4680 | | /// Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), |
4681 | | /// __builtin_FUNCTION(), __builtin_FILE(), or __builtin_source_location(). |
4682 | | class SourceLocExpr final : public Expr { |
4683 | | SourceLocation BuiltinLoc, RParenLoc; |
4684 | | DeclContext *ParentContext; |
4685 | | |
4686 | | public: |
4687 | | enum IdentKind { Function, File, Line, Column, SourceLocStruct }; |
4688 | | |
4689 | | SourceLocExpr(const ASTContext &Ctx, IdentKind Type, QualType ResultTy, |
4690 | | SourceLocation BLoc, SourceLocation RParenLoc, |
4691 | | DeclContext *Context); |
4692 | | |
4693 | | /// Build an empty call expression. |
4694 | 0 | explicit SourceLocExpr(EmptyShell Empty) : Expr(SourceLocExprClass, Empty) {} |
4695 | | |
4696 | | /// Return the result of evaluating this SourceLocExpr in the specified |
4697 | | /// (and possibly null) default argument or initialization context. |
4698 | | APValue EvaluateInContext(const ASTContext &Ctx, |
4699 | | const Expr *DefaultExpr) const; |
4700 | | |
4701 | | /// Return a string representing the name of the specific builtin function. |
4702 | | StringRef getBuiltinStr() const; |
4703 | | |
4704 | 759 | IdentKind getIdentKind() const { |
4705 | 759 | return static_cast<IdentKind>(SourceLocExprBits.Kind); |
4706 | 759 | } |
4707 | | |
4708 | 172 | bool isIntType() const { |
4709 | 172 | switch (getIdentKind()) { |
4710 | 32 | case File: |
4711 | 73 | case Function: |
4712 | 172 | case SourceLocStruct: |
4713 | 172 | return false; |
4714 | 0 | case Line: |
4715 | 0 | case Column: |
4716 | 0 | return true; |
4717 | 172 | } |
4718 | 0 | llvm_unreachable("unknown source location expression kind"); |
4719 | 0 | } |
4720 | | |
4721 | | /// If the SourceLocExpr has been resolved return the subexpression |
4722 | | /// representing the resolved value. Otherwise return null. |
4723 | 140 | const DeclContext *getParentContext() const { return ParentContext; } |
4724 | 8 | DeclContext *getParentContext() { return ParentContext; } |
4725 | | |
4726 | 191 | SourceLocation getLocation() const { return BuiltinLoc; } |
4727 | 741 | SourceLocation getBeginLoc() const { return BuiltinLoc; } |
4728 | 58 | SourceLocation getEndLoc() const { return RParenLoc; } |
4729 | | |
4730 | 413 | child_range children() { |
4731 | 413 | return child_range(child_iterator(), child_iterator()); |
4732 | 413 | } |
4733 | | |
4734 | 0 | const_child_range children() const { |
4735 | 0 | return const_child_range(child_iterator(), child_iterator()); |
4736 | 0 | } |
4737 | | |
4738 | 27.5k | static bool classof(const Stmt *T) { |
4739 | 27.5k | return T->getStmtClass() == SourceLocExprClass; |
4740 | 27.5k | } |
4741 | | |
4742 | | private: |
4743 | | friend class ASTStmtReader; |
4744 | | }; |
4745 | | |
4746 | | /// Describes an C or C++ initializer list. |
4747 | | /// |
4748 | | /// InitListExpr describes an initializer list, which can be used to |
4749 | | /// initialize objects of different types, including |
4750 | | /// struct/class/union types, arrays, and vectors. For example: |
4751 | | /// |
4752 | | /// @code |
4753 | | /// struct foo x = { 1, { 2, 3 } }; |
4754 | | /// @endcode |
4755 | | /// |
4756 | | /// Prior to semantic analysis, an initializer list will represent the |
4757 | | /// initializer list as written by the user, but will have the |
4758 | | /// placeholder type "void". This initializer list is called the |
4759 | | /// syntactic form of the initializer, and may contain C99 designated |
4760 | | /// initializers (represented as DesignatedInitExprs), initializations |
4761 | | /// of subobject members without explicit braces, and so on. Clients |
4762 | | /// interested in the original syntax of the initializer list should |
4763 | | /// use the syntactic form of the initializer list. |
4764 | | /// |
4765 | | /// After semantic analysis, the initializer list will represent the |
4766 | | /// semantic form of the initializer, where the initializations of all |
4767 | | /// subobjects are made explicit with nested InitListExpr nodes and |
4768 | | /// C99 designators have been eliminated by placing the designated |
4769 | | /// initializations into the subobject they initialize. Additionally, |
4770 | | /// any "holes" in the initialization, where no initializer has been |
4771 | | /// specified for a particular subobject, will be replaced with |
4772 | | /// implicitly-generated ImplicitValueInitExpr expressions that |
4773 | | /// value-initialize the subobjects. Note, however, that the |
4774 | | /// initializer lists may still have fewer initializers than there are |
4775 | | /// elements to initialize within the object. |
4776 | | /// |
4777 | | /// After semantic analysis has completed, given an initializer list, |
4778 | | /// method isSemanticForm() returns true if and only if this is the |
4779 | | /// semantic form of the initializer list (note: the same AST node |
4780 | | /// may at the same time be the syntactic form). |
4781 | | /// Given the semantic form of the initializer list, one can retrieve |
4782 | | /// the syntactic form of that initializer list (when different) |
4783 | | /// using method getSyntacticForm(); the method returns null if applied |
4784 | | /// to a initializer list which is already in syntactic form. |
4785 | | /// Similarly, given the syntactic form (i.e., an initializer list such |
4786 | | /// that isSemanticForm() returns false), one can retrieve the semantic |
4787 | | /// form using method getSemanticForm(). |
4788 | | /// Since many initializer lists have the same syntactic and semantic forms, |
4789 | | /// getSyntacticForm() may return NULL, indicating that the current |
4790 | | /// semantic initializer list also serves as its syntactic form. |
4791 | | class InitListExpr : public Expr { |
4792 | | // FIXME: Eliminate this vector in favor of ASTContext allocation |
4793 | | typedef ASTVector<Stmt *> InitExprsTy; |
4794 | | InitExprsTy InitExprs; |
4795 | | SourceLocation LBraceLoc, RBraceLoc; |
4796 | | |
4797 | | /// The alternative form of the initializer list (if it exists). |
4798 | | /// The int part of the pair stores whether this initializer list is |
4799 | | /// in semantic form. If not null, the pointer points to: |
4800 | | /// - the syntactic form, if this is in semantic form; |
4801 | | /// - the semantic form, if this is in syntactic form. |
4802 | | llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm; |
4803 | | |
4804 | | /// Either: |
4805 | | /// If this initializer list initializes an array with more elements than |
4806 | | /// there are initializers in the list, specifies an expression to be used |
4807 | | /// for value initialization of the rest of the elements. |
4808 | | /// Or |
4809 | | /// If this initializer list initializes a union, specifies which |
4810 | | /// field within the union will be initialized. |
4811 | | llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; |
4812 | | |
4813 | | public: |
4814 | | InitListExpr(const ASTContext &C, SourceLocation lbraceloc, |
4815 | | ArrayRef<Expr*> initExprs, SourceLocation rbraceloc); |
4816 | | |
4817 | | /// Build an empty initializer list. |
4818 | | explicit InitListExpr(EmptyShell Empty) |
4819 | 5.48k | : Expr(InitListExprClass, Empty), AltForm(nullptr, true) { } |
4820 | | |
4821 | 6.81M | unsigned getNumInits() const { return InitExprs.size(); } |
4822 | | |
4823 | | /// Retrieve the set of initializers. |
4824 | 357k | Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } |
4825 | | |
4826 | | /// Retrieve the set of initializers. |
4827 | 33 | Expr * const *getInits() const { |
4828 | 33 | return reinterpret_cast<Expr * const *>(InitExprs.data()); |
4829 | 33 | } |
4830 | | |
4831 | 322k | ArrayRef<Expr *> inits() { |
4832 | 322k | return llvm::makeArrayRef(getInits(), getNumInits()); |
4833 | 322k | } |
4834 | | |
4835 | 33 | ArrayRef<Expr *> inits() const { |
4836 | 33 | return llvm::makeArrayRef(getInits(), getNumInits()); |
4837 | 33 | } |
4838 | | |
4839 | 357k | const Expr *getInit(unsigned Init) const { |
4840 | 357k | assert(Init < getNumInits() && "Initializer access out of range!"); |
4841 | 0 | return cast_or_null<Expr>(InitExprs[Init]); |
4842 | 357k | } |
4843 | | |
4844 | 2.58M | Expr *getInit(unsigned Init) { |
4845 | 2.58M | assert(Init < getNumInits() && "Initializer access out of range!"); |
4846 | 0 | return cast_or_null<Expr>(InitExprs[Init]); |
4847 | 2.58M | } |
4848 | | |
4849 | 764k | void setInit(unsigned Init, Expr *expr) { |
4850 | 764k | assert(Init < getNumInits() && "Initializer access out of range!"); |
4851 | 0 | InitExprs[Init] = expr; |
4852 | | |
4853 | 764k | if (expr) |
4854 | 763k | setDependence(getDependence() | expr->getDependence()); |
4855 | 764k | } |
4856 | | |
4857 | | /// Mark the semantic form of the InitListExpr as error when the semantic |
4858 | | /// analysis fails. |
4859 | 708 | void markError() { |
4860 | 708 | assert(isSemanticForm()); |
4861 | 0 | setDependence(getDependence() | ExprDependence::ErrorDependent); |
4862 | 708 | } |
4863 | | |
4864 | | /// Reserve space for some number of initializers. |
4865 | | void reserveInits(const ASTContext &C, unsigned NumInits); |
4866 | | |
4867 | | /// Specify the number of initializers |
4868 | | /// |
4869 | | /// If there are more than @p NumInits initializers, the remaining |
4870 | | /// initializers will be destroyed. If there are fewer than @p |
4871 | | /// NumInits initializers, NULL expressions will be added for the |
4872 | | /// unknown initializers. |
4873 | | void resizeInits(const ASTContext &Context, unsigned NumInits); |
4874 | | |
4875 | | /// Updates the initializer at index @p Init with the new |
4876 | | /// expression @p expr, and returns the old expression at that |
4877 | | /// location. |
4878 | | /// |
4879 | | /// When @p Init is out of range for this initializer list, the |
4880 | | /// initializer list will be extended with NULL expressions to |
4881 | | /// accommodate the new entry. |
4882 | | Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr); |
4883 | | |
4884 | | /// If this initializer list initializes an array with more elements |
4885 | | /// than there are initializers in the list, specifies an expression to be |
4886 | | /// used for value initialization of the rest of the elements. |
4887 | 99.7k | Expr *getArrayFiller() { |
4888 | 99.7k | return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); |
4889 | 99.7k | } |
4890 | 77.6k | const Expr *getArrayFiller() const { |
4891 | 77.6k | return const_cast<InitListExpr *>(this)->getArrayFiller(); |
4892 | 77.6k | } |
4893 | | void setArrayFiller(Expr *filler); |
4894 | | |
4895 | | /// Return true if this is an array initializer and its array "filler" |
4896 | | /// has been set. |
4897 | 56.4k | bool hasArrayFiller() const { return getArrayFiller(); } |
4898 | | |
4899 | | /// If this initializes a union, specifies which field in the |
4900 | | /// union to initialize. |
4901 | | /// |
4902 | | /// Typically, this field is the first named field within the |
4903 | | /// union. However, a designated initializer can specify the |
4904 | | /// initialization of a different field within the union. |
4905 | 11.7k | FieldDecl *getInitializedFieldInUnion() { |
4906 | 11.7k | return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); |
4907 | 11.7k | } |
4908 | 2.25k | const FieldDecl *getInitializedFieldInUnion() const { |
4909 | 2.25k | return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); |
4910 | 2.25k | } |
4911 | 1.57k | void setInitializedFieldInUnion(FieldDecl *FD) { |
4912 | 1.57k | assert((FD == nullptr |
4913 | 1.57k | || getInitializedFieldInUnion() == nullptr |
4914 | 1.57k | || getInitializedFieldInUnion() == FD) |
4915 | 1.57k | && "Only one field of a union may be initialized at a time!"); |
4916 | 0 | ArrayFillerOrUnionFieldInit = FD; |
4917 | 1.57k | } |
4918 | | |
4919 | | // Explicit InitListExpr's originate from source code (and have valid source |
4920 | | // locations). Implicit InitListExpr's are created by the semantic analyzer. |
4921 | | // FIXME: This is wrong; InitListExprs created by semantic analysis have |
4922 | | // valid source locations too! |
4923 | 0 | bool isExplicit() const { |
4924 | 0 | return LBraceLoc.isValid() && RBraceLoc.isValid(); |
4925 | 0 | } |
4926 | | |
4927 | | // Is this an initializer for an array of characters, initialized by a string |
4928 | | // literal or an @encode? |
4929 | | bool isStringLiteralInit() const; |
4930 | | |
4931 | | /// Is this a transparent initializer list (that is, an InitListExpr that is |
4932 | | /// purely syntactic, and whose semantics are that of the sole contained |
4933 | | /// initializer)? |
4934 | | bool isTransparent() const; |
4935 | | |
4936 | | /// Is this the zero initializer {0} in a language which considers it |
4937 | | /// idiomatic? |
4938 | | bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const; |
4939 | | |
4940 | 28.4k | SourceLocation getLBraceLoc() const { return LBraceLoc; } |
4941 | 5.48k | void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } |
4942 | 28.4k | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
4943 | 6.68k | void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } |
4944 | | |
4945 | 1.23M | bool isSemanticForm() const { return AltForm.getInt(); } |
4946 | 28 | InitListExpr *getSemanticForm() const { |
4947 | 28 | return isSemanticForm() ? nullptr0 : AltForm.getPointer(); |
4948 | 28 | } |
4949 | 62.3k | bool isSyntacticForm() const { |
4950 | 62.3k | return !AltForm.getInt() || !AltForm.getPointer()37.4k ; |
4951 | 62.3k | } |
4952 | 1.07M | InitListExpr *getSyntacticForm() const { |
4953 | 1.07M | return isSemanticForm() ? AltForm.getPointer()792k : nullptr278k ; |
4954 | 1.07M | } |
4955 | | |
4956 | 99.9k | void setSyntacticForm(InitListExpr *Init) { |
4957 | 99.9k | AltForm.setPointer(Init); |
4958 | 99.9k | AltForm.setInt(true); |
4959 | 99.9k | Init->AltForm.setPointer(this); |
4960 | 99.9k | Init->AltForm.setInt(false); |
4961 | 99.9k | } |
4962 | | |
4963 | 17.7k | bool hadArrayRangeDesignator() const { |
4964 | 17.7k | return InitListExprBits.HadArrayRangeDesignator != 0; |
4965 | 17.7k | } |
4966 | 262k | void sawArrayRangeDesignator(bool ARD = true) { |
4967 | 262k | InitListExprBits.HadArrayRangeDesignator = ARD; |
4968 | 262k | } |
4969 | | |
4970 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
4971 | | SourceLocation getEndLoc() const LLVM_READONLY; |
4972 | | |
4973 | 134M | static bool classof(const Stmt *T) { |
4974 | 134M | return T->getStmtClass() == InitListExprClass; |
4975 | 134M | } |
4976 | | |
4977 | | // Iterators |
4978 | 244k | child_range children() { |
4979 | 244k | const_child_range CCR = const_cast<const InitListExpr *>(this)->children(); |
4980 | 244k | return child_range(cast_away_const(CCR.begin()), |
4981 | 244k | cast_away_const(CCR.end())); |
4982 | 244k | } |
4983 | | |
4984 | 244k | const_child_range children() const { |
4985 | | // FIXME: This does not include the array filler expression. |
4986 | 244k | if (InitExprs.empty()) |
4987 | 53.9k | return const_child_range(const_child_iterator(), const_child_iterator()); |
4988 | 191k | return const_child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); |
4989 | 244k | } |
4990 | | |
4991 | | typedef InitExprsTy::iterator iterator; |
4992 | | typedef InitExprsTy::const_iterator const_iterator; |
4993 | | typedef InitExprsTy::reverse_iterator reverse_iterator; |
4994 | | typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; |
4995 | | |
4996 | 0 | iterator begin() { return InitExprs.begin(); } |
4997 | 104k | const_iterator begin() const { return InitExprs.begin(); } |
4998 | 0 | iterator end() { return InitExprs.end(); } |
4999 | 104k | const_iterator end() const { return InitExprs.end(); } |
5000 | 0 | reverse_iterator rbegin() { return InitExprs.rbegin(); } |
5001 | 1.08k | const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } |
5002 | 0 | reverse_iterator rend() { return InitExprs.rend(); } |
5003 | 1.08k | const_reverse_iterator rend() const { return InitExprs.rend(); } |
5004 | | |
5005 | | friend class ASTStmtReader; |
5006 | | friend class ASTStmtWriter; |
5007 | | }; |
5008 | | |
5009 | | /// Represents a C99 designated initializer expression. |
5010 | | /// |
5011 | | /// A designated initializer expression (C99 6.7.8) contains one or |
5012 | | /// more designators (which can be field designators, array |
5013 | | /// designators, or GNU array-range designators) followed by an |
5014 | | /// expression that initializes the field or element(s) that the |
5015 | | /// designators refer to. For example, given: |
5016 | | /// |
5017 | | /// @code |
5018 | | /// struct point { |
5019 | | /// double x; |
5020 | | /// double y; |
5021 | | /// }; |
5022 | | /// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; |
5023 | | /// @endcode |
5024 | | /// |
5025 | | /// The InitListExpr contains three DesignatedInitExprs, the first of |
5026 | | /// which covers @c [2].y=1.0. This DesignatedInitExpr will have two |
5027 | | /// designators, one array designator for @c [2] followed by one field |
5028 | | /// designator for @c .y. The initialization expression will be 1.0. |
5029 | | class DesignatedInitExpr final |
5030 | | : public Expr, |
5031 | | private llvm::TrailingObjects<DesignatedInitExpr, Stmt *> { |
5032 | | public: |
5033 | | /// Forward declaration of the Designator class. |
5034 | | class Designator; |
5035 | | |
5036 | | private: |
5037 | | /// The location of the '=' or ':' prior to the actual initializer |
5038 | | /// expression. |
5039 | | SourceLocation EqualOrColonLoc; |
5040 | | |
5041 | | /// Whether this designated initializer used the GNU deprecated |
5042 | | /// syntax rather than the C99 '=' syntax. |
5043 | | unsigned GNUSyntax : 1; |
5044 | | |
5045 | | /// The number of designators in this initializer expression. |
5046 | | unsigned NumDesignators : 15; |
5047 | | |
5048 | | /// The number of subexpressions of this initializer expression, |
5049 | | /// which contains both the initializer and any additional |
5050 | | /// expressions used by array and array-range designators. |
5051 | | unsigned NumSubExprs : 16; |
5052 | | |
5053 | | /// The designators in this designated initialization |
5054 | | /// expression. |
5055 | | Designator *Designators; |
5056 | | |
5057 | | DesignatedInitExpr(const ASTContext &C, QualType Ty, |
5058 | | llvm::ArrayRef<Designator> Designators, |
5059 | | SourceLocation EqualOrColonLoc, bool GNUSyntax, |
5060 | | ArrayRef<Expr *> IndexExprs, Expr *Init); |
5061 | | |
5062 | | explicit DesignatedInitExpr(unsigned NumSubExprs) |
5063 | | : Expr(DesignatedInitExprClass, EmptyShell()), |
5064 | 56 | NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { } |
5065 | | |
5066 | | public: |
5067 | | /// A field designator, e.g., ".x". |
5068 | | struct FieldDesignator { |
5069 | | /// Refers to the field that is being initialized. The low bit |
5070 | | /// of this field determines whether this is actually a pointer |
5071 | | /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When |
5072 | | /// initially constructed, a field designator will store an |
5073 | | /// IdentifierInfo*. After semantic analysis has resolved that |
5074 | | /// name, the field designator will instead store a FieldDecl*. |
5075 | | uintptr_t NameOrField; |
5076 | | |
5077 | | /// The location of the '.' in the designated initializer. |
5078 | | SourceLocation DotLoc; |
5079 | | |
5080 | | /// The location of the field name in the designated initializer. |
5081 | | SourceLocation FieldLoc; |
5082 | | }; |
5083 | | |
5084 | | /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". |
5085 | | struct ArrayOrRangeDesignator { |
5086 | | /// Location of the first index expression within the designated |
5087 | | /// initializer expression's list of subexpressions. |
5088 | | unsigned Index; |
5089 | | /// The location of the '[' starting the array range designator. |
5090 | | SourceLocation LBracketLoc; |
5091 | | /// The location of the ellipsis separating the start and end |
5092 | | /// indices. Only valid for GNU array-range designators. |
5093 | | SourceLocation EllipsisLoc; |
5094 | | /// The location of the ']' terminating the array range designator. |
5095 | | SourceLocation RBracketLoc; |
5096 | | }; |
5097 | | |
5098 | | /// Represents a single C99 designator. |
5099 | | /// |
5100 | | /// @todo This class is infuriatingly similar to clang::Designator, |
5101 | | /// but minor differences (storing indices vs. storing pointers) |
5102 | | /// keep us from reusing it. Try harder, later, to rectify these |
5103 | | /// differences. |
5104 | | class Designator { |
5105 | | /// The kind of designator this describes. |
5106 | | enum { |
5107 | | FieldDesignator, |
5108 | | ArrayDesignator, |
5109 | | ArrayRangeDesignator |
5110 | | } Kind; |
5111 | | |
5112 | | union { |
5113 | | /// A field designator, e.g., ".x". |
5114 | | struct FieldDesignator Field; |
5115 | | /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". |
5116 | | struct ArrayOrRangeDesignator ArrayOrRange; |
5117 | | }; |
5118 | | friend class DesignatedInitExpr; |
5119 | | |
5120 | | public: |
5121 | 2.75k | Designator() {} |
5122 | | |
5123 | | /// Initializes a field designator. |
5124 | | Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, |
5125 | | SourceLocation FieldLoc) |
5126 | 2.24k | : Kind(FieldDesignator) { |
5127 | 2.24k | new (&Field) DesignatedInitExpr::FieldDesignator; |
5128 | 2.24k | Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; |
5129 | 2.24k | Field.DotLoc = DotLoc; |
5130 | 2.24k | Field.FieldLoc = FieldLoc; |
5131 | 2.24k | } |
5132 | | |
5133 | | /// Initializes an array designator. |
5134 | | Designator(unsigned Index, SourceLocation LBracketLoc, |
5135 | | SourceLocation RBracketLoc) |
5136 | 408 | : Kind(ArrayDesignator) { |
5137 | 408 | new (&ArrayOrRange) DesignatedInitExpr::ArrayOrRangeDesignator; |
5138 | 408 | ArrayOrRange.Index = Index; |
5139 | 408 | ArrayOrRange.LBracketLoc = LBracketLoc; |
5140 | 408 | ArrayOrRange.EllipsisLoc = SourceLocation(); |
5141 | 408 | ArrayOrRange.RBracketLoc = RBracketLoc; |
5142 | 408 | } |
5143 | | |
5144 | | /// Initializes a GNU array-range designator. |
5145 | | Designator(unsigned Index, SourceLocation LBracketLoc, |
5146 | | SourceLocation EllipsisLoc, SourceLocation RBracketLoc) |
5147 | 27 | : Kind(ArrayRangeDesignator) { |
5148 | 27 | new (&ArrayOrRange) DesignatedInitExpr::ArrayOrRangeDesignator; |
5149 | 27 | ArrayOrRange.Index = Index; |
5150 | 27 | ArrayOrRange.LBracketLoc = LBracketLoc; |
5151 | 27 | ArrayOrRange.EllipsisLoc = EllipsisLoc; |
5152 | 27 | ArrayOrRange.RBracketLoc = RBracketLoc; |
5153 | 27 | } |
5154 | | |
5155 | 13.1k | bool isFieldDesignator() const { return Kind == FieldDesignator; } |
5156 | 6.03k | bool isArrayDesignator() const { return Kind == ArrayDesignator; } |
5157 | 4.39k | bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } |
5158 | | |
5159 | | IdentifierInfo *getFieldName() const; |
5160 | | |
5161 | 5.03k | FieldDecl *getField() const { |
5162 | 5.03k | assert(Kind == FieldDesignator && "Only valid on a field designator"); |
5163 | 5.03k | if (Field.NameOrField & 0x01) |
5164 | 4.39k | return nullptr; |
5165 | 645 | else |
5166 | 645 | return reinterpret_cast<FieldDecl *>(Field.NameOrField); |
5167 | 5.03k | } |
5168 | | |
5169 | 2.07k | void setField(FieldDecl *FD) { |
5170 | 2.07k | assert(Kind == FieldDesignator && "Only valid on a field designator"); |
5171 | 0 | Field.NameOrField = reinterpret_cast<uintptr_t>(FD); |
5172 | 2.07k | } |
5173 | | |
5174 | 1.86k | SourceLocation getDotLoc() const { |
5175 | 1.86k | assert(Kind == FieldDesignator && "Only valid on a field designator"); |
5176 | 0 | return Field.DotLoc; |
5177 | 1.86k | } |
5178 | | |
5179 | 2.64k | SourceLocation getFieldLoc() const { |
5180 | 2.64k | assert(Kind == FieldDesignator && "Only valid on a field designator"); |
5181 | 0 | return Field.FieldLoc; |
5182 | 2.64k | } |
5183 | | |
5184 | 423 | SourceLocation getLBracketLoc() const { |
5185 | 423 | assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && |
5186 | 423 | "Only valid on an array or array-range designator"); |
5187 | 0 | return ArrayOrRange.LBracketLoc; |
5188 | 423 | } |
5189 | | |
5190 | 157 | SourceLocation getRBracketLoc() const { |
5191 | 157 | assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && |
5192 | 157 | "Only valid on an array or array-range designator"); |
5193 | 0 | return ArrayOrRange.RBracketLoc; |
5194 | 157 | } |
5195 | | |
5196 | 8 | SourceLocation getEllipsisLoc() const { |
5197 | 8 | assert(Kind == ArrayRangeDesignator && |
5198 | 8 | "Only valid on an array-range designator"); |
5199 | 0 | return ArrayOrRange.EllipsisLoc; |
5200 | 8 | } |
5201 | | |
5202 | 61 | unsigned getFirstExprIndex() const { |
5203 | 61 | assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && |
5204 | 61 | "Only valid on an array or array-range designator"); |
5205 | 0 | return ArrayOrRange.Index; |
5206 | 61 | } |
5207 | | |
5208 | 979 | SourceLocation getBeginLoc() const LLVM_READONLY { |
5209 | 979 | if (Kind == FieldDesignator) |
5210 | 641 | return getDotLoc().isInvalid()? getFieldLoc()16 : getDotLoc()625 ; |
5211 | 338 | else |
5212 | 338 | return getLBracketLoc(); |
5213 | 979 | } |
5214 | 163 | SourceLocation getEndLoc() const LLVM_READONLY { |
5215 | 163 | return Kind == FieldDesignator ? getFieldLoc()58 : getRBracketLoc()105 ; |
5216 | 163 | } |
5217 | 92 | SourceRange getSourceRange() const LLVM_READONLY { |
5218 | 92 | return SourceRange(getBeginLoc(), getEndLoc()); |
5219 | 92 | } |
5220 | | }; |
5221 | | |
5222 | | static DesignatedInitExpr *Create(const ASTContext &C, |
5223 | | llvm::ArrayRef<Designator> Designators, |
5224 | | ArrayRef<Expr*> IndexExprs, |
5225 | | SourceLocation EqualOrColonLoc, |
5226 | | bool GNUSyntax, Expr *Init); |
5227 | | |
5228 | | static DesignatedInitExpr *CreateEmpty(const ASTContext &C, |
5229 | | unsigned NumIndexExprs); |
5230 | | |
5231 | | /// Returns the number of designators in this initializer. |
5232 | 10.9k | unsigned size() const { return NumDesignators; } |
5233 | | |
5234 | | // Iterator access to the designators. |
5235 | 15.1k | llvm::MutableArrayRef<Designator> designators() { |
5236 | 15.1k | return {Designators, NumDesignators}; |
5237 | 15.1k | } |
5238 | | |
5239 | 232 | llvm::ArrayRef<Designator> designators() const { |
5240 | 232 | return {Designators, NumDesignators}; |
5241 | 232 | } |
5242 | | |
5243 | 11.0k | Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; } |
5244 | 10 | const Designator *getDesignator(unsigned Idx) const { |
5245 | 10 | return &designators()[Idx]; |
5246 | 10 | } |
5247 | | |
5248 | | void setDesignators(const ASTContext &C, const Designator *Desigs, |
5249 | | unsigned NumDesigs); |
5250 | | |
5251 | | Expr *getArrayIndex(const Designator &D) const; |
5252 | | Expr *getArrayRangeStart(const Designator &D) const; |
5253 | | Expr *getArrayRangeEnd(const Designator &D) const; |
5254 | | |
5255 | | /// Retrieve the location of the '=' that precedes the |
5256 | | /// initializer value itself, if present. |
5257 | 582 | SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } |
5258 | 56 | void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } |
5259 | | |
5260 | | /// Whether this designated initializer should result in direct-initialization |
5261 | | /// of the designated subobject (eg, '{.foo{1, 2, 3}}'). |
5262 | 4.33k | bool isDirectInit() const { return EqualOrColonLoc.isInvalid(); } |
5263 | | |
5264 | | /// Determines whether this designated initializer used the |
5265 | | /// deprecated GNU syntax for designated initializers. |
5266 | 788 | bool usesGNUSyntax() const { return GNUSyntax; } |
5267 | 56 | void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } |
5268 | | |
5269 | | /// Retrieve the initializer value. |
5270 | 12.6k | Expr *getInit() const { |
5271 | 12.6k | return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); |
5272 | 12.6k | } |
5273 | | |
5274 | 231 | void setInit(Expr *init) { |
5275 | 231 | *child_begin() = init; |
5276 | 231 | } |
5277 | | |
5278 | | /// Retrieve the total number of subexpressions in this |
5279 | | /// designated initializer expression, including the actual |
5280 | | /// initialized value and any expressions that occur within array |
5281 | | /// and array-range designators. |
5282 | 666 | unsigned getNumSubExprs() const { return NumSubExprs; } |
5283 | | |
5284 | 1.72k | Expr *getSubExpr(unsigned Idx) const { |
5285 | 1.72k | assert(Idx < NumSubExprs && "Subscript out of range"); |
5286 | 0 | return cast<Expr>(getTrailingObjects<Stmt *>()[Idx]); |
5287 | 1.72k | } |
5288 | | |
5289 | 61 | void setSubExpr(unsigned Idx, Expr *E) { |
5290 | 61 | assert(Idx < NumSubExprs && "Subscript out of range"); |
5291 | 0 | getTrailingObjects<Stmt *>()[Idx] = E; |
5292 | 61 | } |
5293 | | |
5294 | | /// Replaces the designator at index @p Idx with the series |
5295 | | /// of designators in [First, Last). |
5296 | | void ExpandDesignator(const ASTContext &C, unsigned Idx, |
5297 | | const Designator *First, const Designator *Last); |
5298 | | |
5299 | | SourceRange getDesignatorsSourceRange() const; |
5300 | | |
5301 | | SourceLocation getBeginLoc() const LLVM_READONLY; |
5302 | | SourceLocation getEndLoc() const LLVM_READONLY; |
5303 | | |
5304 | 1.75M | static bool classof(const Stmt *T) { |
5305 | 1.75M | return T->getStmtClass() == DesignatedInitExprClass; |
5306 | 1.75M | } |
5307 | | |
5308 | | // Iterators |
5309 | 15.9k | child_range children() { |
5310 | 15.9k | Stmt **begin = getTrailingObjects<Stmt *>(); |
5311 | 15.9k | return child_range(begin, begin + NumSubExprs); |
5312 | 15.9k | } |
5313 | 0 | const_child_range children() const { |
5314 | 0 | Stmt * const *begin = getTrailingObjects<Stmt *>(); |
5315 | 0 | return const_child_range(begin, begin + NumSubExprs); |
5316 | 0 | } |
5317 | | |
5318 | | friend TrailingObjects; |
5319 | | }; |
5320 | | |
5321 | | /// Represents a place-holder for an object not to be initialized by |
5322 | | /// anything. |
5323 | | /// |
5324 | | /// This only makes sense when it appears as part of an updater of a |
5325 | | /// DesignatedInitUpdateExpr (see below). The base expression of a DIUE |
5326 | | /// initializes a big object, and the NoInitExpr's mark the spots within the |
5327 | | /// big object not to be overwritten by the updater. |
5328 | | /// |
5329 | | /// \see DesignatedInitUpdateExpr |
5330 | | class NoInitExpr : public Expr { |
5331 | | public: |
5332 | | explicit NoInitExpr(QualType ty) |
5333 | 55.6k | : Expr(NoInitExprClass, ty, VK_PRValue, OK_Ordinary) { |
5334 | |