1 //===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the Expr interface and subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_EXPR_H
15 #define LLVM_CLANG_AST_EXPR_H
16
17 #include "clang/AST/APValue.h"
18 #include "clang/AST/Stmt.h"
19 #include "clang/AST/Type.h"
20 #include "clang/AST/DeclAccessPair.h"
21 #include "clang/AST/OperationKinds.h"
22 #include "clang/AST/ASTVector.h"
23 #include "clang/AST/TemplateBase.h"
24 #include "clang/Basic/TargetInfo.h"
25 #include "clang/Basic/TypeTraits.h"
26 #include "llvm/ADT/APSInt.h"
27 #include "llvm/ADT/APFloat.h"
28 #include "llvm/ADT/SmallVector.h"
29 #include "llvm/ADT/StringRef.h"
30 #include "llvm/Support/Compiler.h"
31 #include <cctype>
32
33 namespace clang {
34 class ASTContext;
35 class APValue;
36 class Decl;
37 class IdentifierInfo;
38 class ParmVarDecl;
39 class NamedDecl;
40 class ValueDecl;
41 class BlockDecl;
42 class CXXBaseSpecifier;
43 class CXXOperatorCallExpr;
44 class CXXMemberCallExpr;
45 class ObjCPropertyRefExpr;
46 class OpaqueValueExpr;
47
48 /// \brief A simple array of base specifiers.
49 typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
50
51 /// Expr - This represents one expression. Note that Expr's are subclasses of
52 /// Stmt. This allows an expression to be transparently used any place a Stmt
53 /// is required.
54 ///
55 class Expr : public Stmt {
56 QualType TR;
57
58 protected:
Expr(StmtClass SC,QualType T,ExprValueKind VK,ExprObjectKind OK,bool TD,bool VD,bool ID,bool ContainsUnexpandedParameterPack)59 Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
60 bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
61 : Stmt(SC)
62 {
63 ExprBits.TypeDependent = TD;
64 ExprBits.ValueDependent = VD;
65 ExprBits.InstantiationDependent = ID;
66 ExprBits.ValueKind = VK;
67 ExprBits.ObjectKind = OK;
68 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
69 setType(T);
70 }
71
72 /// \brief Construct an empty expression.
Expr(StmtClass SC,EmptyShell)73 explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
74
75 public:
getType()76 QualType getType() const { return TR; }
setType(QualType t)77 void setType(QualType t) {
78 // In C++, the type of an expression is always adjusted so that it
79 // will not have reference type an expression will never have
80 // reference type (C++ [expr]p6). Use
81 // QualType::getNonReferenceType() to retrieve the non-reference
82 // type. Additionally, inspect Expr::isLvalue to determine whether
83 // an expression that is adjusted in this manner should be
84 // considered an lvalue.
85 assert((t.isNull() || !t->isReferenceType()) &&
86 "Expressions can't have reference type");
87
88 TR = t;
89 }
90
91 /// isValueDependent - Determines whether this expression is
92 /// value-dependent (C++ [temp.dep.constexpr]). For example, the
93 /// array bound of "Chars" in the following example is
94 /// value-dependent.
95 /// @code
96 /// template<int Size, char (&Chars)[Size]> struct meta_string;
97 /// @endcode
isValueDependent()98 bool isValueDependent() const { return ExprBits.ValueDependent; }
99
100 /// \brief Set whether this expression is value-dependent or not.
setValueDependent(bool VD)101 void setValueDependent(bool VD) {
102 ExprBits.ValueDependent = VD;
103 if (VD)
104 ExprBits.InstantiationDependent = true;
105 }
106
107 /// isTypeDependent - Determines whether this expression is
108 /// type-dependent (C++ [temp.dep.expr]), which means that its type
109 /// could change from one template instantiation to the next. For
110 /// example, the expressions "x" and "x + y" are type-dependent in
111 /// the following code, but "y" is not type-dependent:
112 /// @code
113 /// template<typename T>
114 /// void add(T x, int y) {
115 /// x + y;
116 /// }
117 /// @endcode
isTypeDependent()118 bool isTypeDependent() const { return ExprBits.TypeDependent; }
119
120 /// \brief Set whether this expression is type-dependent or not.
setTypeDependent(bool TD)121 void setTypeDependent(bool TD) {
122 ExprBits.TypeDependent = TD;
123 if (TD)
124 ExprBits.InstantiationDependent = true;
125 }
126
127 /// \brief Whether this expression is instantiation-dependent, meaning that
128 /// it depends in some way on a template parameter, even if neither its type
129 /// nor (constant) value can change due to the template instantiation.
130 ///
131 /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
132 /// instantiation-dependent (since it involves a template parameter \c T), but
133 /// is neither type- nor value-dependent, since the type of the inner
134 /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
135 /// \c sizeof is known.
136 ///
137 /// \code
138 /// template<typename T>
139 /// void f(T x, T y) {
140 /// sizeof(sizeof(T() + T());
141 /// }
142 /// \endcode
143 ///
isInstantiationDependent()144 bool isInstantiationDependent() const {
145 return ExprBits.InstantiationDependent;
146 }
147
148 /// \brief Set whether this expression is instantiation-dependent or not.
setInstantiationDependent(bool ID)149 void setInstantiationDependent(bool ID) {
150 ExprBits.InstantiationDependent = ID;
151 }
152
153 /// \brief Whether this expression contains an unexpanded parameter
154 /// pack (for C++0x variadic templates).
155 ///
156 /// Given the following function template:
157 ///
158 /// \code
159 /// template<typename F, typename ...Types>
160 /// void forward(const F &f, Types &&...args) {
161 /// f(static_cast<Types&&>(args)...);
162 /// }
163 /// \endcode
164 ///
165 /// The expressions \c args and \c static_cast<Types&&>(args) both
166 /// contain parameter packs.
containsUnexpandedParameterPack()167 bool containsUnexpandedParameterPack() const {
168 return ExprBits.ContainsUnexpandedParameterPack;
169 }
170
171 /// \brief Set the bit that describes whether this expression
172 /// contains an unexpanded parameter pack.
173 void setContainsUnexpandedParameterPack(bool PP = true) {
174 ExprBits.ContainsUnexpandedParameterPack = PP;
175 }
176
177 /// getExprLoc - Return the preferred location for the arrow when diagnosing
178 /// a problem with a generic expression.
179 SourceLocation getExprLoc() const LLVM_READONLY;
180
181 /// isUnusedResultAWarning - Return true if this immediate expression should
182 /// be warned about if the result is unused. If so, fill in Loc and Ranges
183 /// with location to warn on and the source range[s] to report with the
184 /// warning.
185 bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
186 SourceRange &R2, ASTContext &Ctx) const;
187
188 /// isLValue - True if this expression is an "l-value" according to
189 /// the rules of the current language. C and C++ give somewhat
190 /// different rules for this concept, but in general, the result of
191 /// an l-value expression identifies a specific object whereas the
192 /// result of an r-value expression is a value detached from any
193 /// specific storage.
194 ///
195 /// C++0x divides the concept of "r-value" into pure r-values
196 /// ("pr-values") and so-called expiring values ("x-values"), which
197 /// identify specific objects that can be safely cannibalized for
198 /// their resources. This is an unfortunate abuse of terminology on
199 /// the part of the C++ committee. In Clang, when we say "r-value",
200 /// we generally mean a pr-value.
isLValue()201 bool isLValue() const { return getValueKind() == VK_LValue; }
isRValue()202 bool isRValue() const { return getValueKind() == VK_RValue; }
isXValue()203 bool isXValue() const { return getValueKind() == VK_XValue; }
isGLValue()204 bool isGLValue() const { return getValueKind() != VK_RValue; }
205
206 enum LValueClassification {
207 LV_Valid,
208 LV_NotObjectType,
209 LV_IncompleteVoidType,
210 LV_DuplicateVectorComponents,
211 LV_InvalidExpression,
212 LV_InvalidMessageExpression,
213 LV_MemberFunction,
214 LV_SubObjCPropertySetting,
215 LV_ClassTemporary
216 };
217 /// Reasons why an expression might not be an l-value.
218 LValueClassification ClassifyLValue(ASTContext &Ctx) const;
219
220 /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
221 /// does not have an incomplete type, does not have a const-qualified type,
222 /// and if it is a structure or union, does not have any member (including,
223 /// recursively, any member or element of all contained aggregates or unions)
224 /// with a const-qualified type.
225 ///
226 /// \param Loc [in] [out] - A source location which *may* be filled
227 /// in with the location of the expression making this a
228 /// non-modifiable lvalue, if specified.
229 enum isModifiableLvalueResult {
230 MLV_Valid,
231 MLV_NotObjectType,
232 MLV_IncompleteVoidType,
233 MLV_DuplicateVectorComponents,
234 MLV_InvalidExpression,
235 MLV_LValueCast, // Specialized form of MLV_InvalidExpression.
236 MLV_IncompleteType,
237 MLV_ConstQualified,
238 MLV_ArrayType,
239 MLV_ReadonlyProperty,
240 MLV_NoSetterProperty,
241 MLV_MemberFunction,
242 MLV_SubObjCPropertySetting,
243 MLV_InvalidMessageExpression,
244 MLV_ClassTemporary
245 };
246 isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
247 SourceLocation *Loc = 0) const;
248
249 /// \brief The return type of classify(). Represents the C++0x expression
250 /// taxonomy.
251 class Classification {
252 public:
253 /// \brief The various classification results. Most of these mean prvalue.
254 enum Kinds {
255 CL_LValue,
256 CL_XValue,
257 CL_Function, // Functions cannot be lvalues in C.
258 CL_Void, // Void cannot be an lvalue in C.
259 CL_AddressableVoid, // Void expression whose address can be taken in C.
260 CL_DuplicateVectorComponents, // A vector shuffle with dupes.
261 CL_MemberFunction, // An expression referring to a member function
262 CL_SubObjCPropertySetting,
263 CL_ClassTemporary, // A prvalue of class type
264 CL_ObjCMessageRValue, // ObjC message is an rvalue
265 CL_PRValue // A prvalue for any other reason, of any other type
266 };
267 /// \brief The results of modification testing.
268 enum ModifiableType {
269 CM_Untested, // testModifiable was false.
270 CM_Modifiable,
271 CM_RValue, // Not modifiable because it's an rvalue
272 CM_Function, // Not modifiable because it's a function; C++ only
273 CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
274 CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
275 CM_ConstQualified,
276 CM_ArrayType,
277 CM_IncompleteType
278 };
279
280 private:
281 friend class Expr;
282
283 unsigned short Kind;
284 unsigned short Modifiable;
285
Classification(Kinds k,ModifiableType m)286 explicit Classification(Kinds k, ModifiableType m)
287 : Kind(k), Modifiable(m)
288 {}
289
290 public:
Classification()291 Classification() {}
292
getKind()293 Kinds getKind() const { return static_cast<Kinds>(Kind); }
getModifiable()294 ModifiableType getModifiable() const {
295 assert(Modifiable != CM_Untested && "Did not test for modifiability.");
296 return static_cast<ModifiableType>(Modifiable);
297 }
isLValue()298 bool isLValue() const { return Kind == CL_LValue; }
isXValue()299 bool isXValue() const { return Kind == CL_XValue; }
isGLValue()300 bool isGLValue() const { return Kind <= CL_XValue; }
isPRValue()301 bool isPRValue() const { return Kind >= CL_Function; }
isRValue()302 bool isRValue() const { return Kind >= CL_XValue; }
isModifiable()303 bool isModifiable() const { return getModifiable() == CM_Modifiable; }
304
305 /// \brief Create a simple, modifiably lvalue
makeSimpleLValue()306 static Classification makeSimpleLValue() {
307 return Classification(CL_LValue, CM_Modifiable);
308 }
309
310 };
311 /// \brief Classify - Classify this expression according to the C++0x
312 /// expression taxonomy.
313 ///
314 /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the
315 /// old lvalue vs rvalue. This function determines the type of expression this
316 /// is. There are three expression types:
317 /// - lvalues are classical lvalues as in C++03.
318 /// - prvalues are equivalent to rvalues in C++03.
319 /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
320 /// function returning an rvalue reference.
321 /// lvalues and xvalues are collectively referred to as glvalues, while
322 /// prvalues and xvalues together form rvalues.
Classify(ASTContext & Ctx)323 Classification Classify(ASTContext &Ctx) const {
324 return ClassifyImpl(Ctx, 0);
325 }
326
327 /// \brief ClassifyModifiable - Classify this expression according to the
328 /// C++0x expression taxonomy, and see if it is valid on the left side
329 /// of an assignment.
330 ///
331 /// This function extends classify in that it also tests whether the
332 /// expression is modifiable (C99 6.3.2.1p1).
333 /// \param Loc A source location that might be filled with a relevant location
334 /// if the expression is not modifiable.
ClassifyModifiable(ASTContext & Ctx,SourceLocation & Loc)335 Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
336 return ClassifyImpl(Ctx, &Loc);
337 }
338
339 /// getValueKindForType - Given a formal return or parameter type,
340 /// give its value kind.
getValueKindForType(QualType T)341 static ExprValueKind getValueKindForType(QualType T) {
342 if (const ReferenceType *RT = T->getAs<ReferenceType>())
343 return (isa<LValueReferenceType>(RT)
344 ? VK_LValue
345 : (RT->getPointeeType()->isFunctionType()
346 ? VK_LValue : VK_XValue));
347 return VK_RValue;
348 }
349
350 /// getValueKind - The value kind that this expression produces.
getValueKind()351 ExprValueKind getValueKind() const {
352 return static_cast<ExprValueKind>(ExprBits.ValueKind);
353 }
354
355 /// getObjectKind - The object kind that this expression produces.
356 /// Object kinds are meaningful only for expressions that yield an
357 /// l-value or x-value.
getObjectKind()358 ExprObjectKind getObjectKind() const {
359 return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
360 }
361
isOrdinaryOrBitFieldObject()362 bool isOrdinaryOrBitFieldObject() const {
363 ExprObjectKind OK = getObjectKind();
364 return (OK == OK_Ordinary || OK == OK_BitField);
365 }
366
367 /// setValueKind - Set the value kind produced by this expression.
setValueKind(ExprValueKind Cat)368 void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
369
370 /// setObjectKind - Set the object kind produced by this expression.
setObjectKind(ExprObjectKind Cat)371 void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
372
373 private:
374 Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
375
376 public:
377
378 /// \brief If this expression refers to a bit-field, retrieve the
379 /// declaration of that bit-field.
380 FieldDecl *getBitField();
381
getBitField()382 const FieldDecl *getBitField() const {
383 return const_cast<Expr*>(this)->getBitField();
384 }
385
386 /// \brief If this expression is an l-value for an Objective C
387 /// property, find the underlying property reference expression.
388 const ObjCPropertyRefExpr *getObjCProperty() const;
389
390 /// \brief Returns whether this expression refers to a vector element.
391 bool refersToVectorElement() const;
392
393 /// \brief Returns whether this expression has a placeholder type.
hasPlaceholderType()394 bool hasPlaceholderType() const {
395 return getType()->isPlaceholderType();
396 }
397
398 /// \brief Returns whether this expression has a specific placeholder type.
hasPlaceholderType(BuiltinType::Kind K)399 bool hasPlaceholderType(BuiltinType::Kind K) const {
400 assert(BuiltinType::isPlaceholderTypeKind(K));
401 if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
402 return BT->getKind() == K;
403 return false;
404 }
405
406 /// isKnownToHaveBooleanValue - Return true if this is an integer expression
407 /// that is known to return 0 or 1. This happens for _Bool/bool expressions
408 /// but also int expressions which are produced by things like comparisons in
409 /// C.
410 bool isKnownToHaveBooleanValue() const;
411
412 /// isIntegerConstantExpr - Return true if this expression is a valid integer
413 /// constant expression, and, if so, return its value in Result. If not a
414 /// valid i-c-e, return false and fill in Loc (if specified) with the location
415 /// of the invalid expression.
416 ///
417 /// Note: This does not perform the implicit conversions required by C++11
418 /// [expr.const]p5.
419 bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
420 SourceLocation *Loc = 0,
421 bool isEvaluated = true) const;
422 bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const;
423
424 /// isCXX98IntegralConstantExpr - Return true if this expression is an
425 /// integral constant expression in C++98. Can only be used in C++.
426 bool isCXX98IntegralConstantExpr(ASTContext &Ctx) const;
427
428 /// isCXX11ConstantExpr - Return true if this expression is a constant
429 /// expression in C++11. Can only be used in C++.
430 ///
431 /// Note: This does not perform the implicit conversions required by C++11
432 /// [expr.const]p5.
433 bool isCXX11ConstantExpr(ASTContext &Ctx, APValue *Result = 0,
434 SourceLocation *Loc = 0) const;
435
436 /// isPotentialConstantExpr - Return true if this function's definition
437 /// might be usable in a constant expression in C++11, if it were marked
438 /// constexpr. Return false if the function can never produce a constant
439 /// expression, along with diagnostics describing why not.
440 static bool isPotentialConstantExpr(const FunctionDecl *FD,
441 llvm::SmallVectorImpl<
442 PartialDiagnosticAt> &Diags);
443
444 /// isConstantInitializer - Returns true if this expression can be emitted to
445 /// IR as a constant, and thus can be used as a constant initializer in C.
446 bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const;
447
448 /// EvalStatus is a struct with detailed info about an evaluation in progress.
449 struct EvalStatus {
450 /// HasSideEffects - Whether the evaluated expression has side effects.
451 /// For example, (f() && 0) can be folded, but it still has side effects.
452 bool HasSideEffects;
453
454 /// Diag - If this is non-null, it will be filled in with a stack of notes
455 /// indicating why evaluation failed (or why it failed to produce a constant
456 /// expression).
457 /// If the expression is unfoldable, the notes will indicate why it's not
458 /// foldable. If the expression is foldable, but not a constant expression,
459 /// the notes will describes why it isn't a constant expression. If the
460 /// expression *is* a constant expression, no notes will be produced.
461 llvm::SmallVectorImpl<PartialDiagnosticAt> *Diag;
462
EvalStatusEvalStatus463 EvalStatus() : HasSideEffects(false), Diag(0) {}
464
465 // hasSideEffects - Return true if the evaluated expression has
466 // side effects.
hasSideEffectsEvalStatus467 bool hasSideEffects() const {
468 return HasSideEffects;
469 }
470 };
471
472 /// EvalResult is a struct with detailed info about an evaluated expression.
473 struct EvalResult : EvalStatus {
474 /// Val - This is the value the expression can be folded to.
475 APValue Val;
476
477 // isGlobalLValue - Return true if the evaluated lvalue expression
478 // is global.
479 bool isGlobalLValue() const;
480 };
481
482 /// EvaluateAsRValue - Return true if this is a constant which we can fold to
483 /// an rvalue using any crazy technique (that has nothing to do with language
484 /// standards) that we want to, even if the expression has side-effects. If
485 /// this function returns true, it returns the folded constant in Result. If
486 /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
487 /// applied.
488 bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const;
489
490 /// EvaluateAsBooleanCondition - Return true if this is a constant
491 /// which we we can fold and convert to a boolean condition using
492 /// any crazy technique that we want to, even if the expression has
493 /// side-effects.
494 bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
495
496 enum SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects };
497
498 /// EvaluateAsInt - Return true if this is a constant which we can fold and
499 /// convert to an integer, using any crazy technique that we want to.
500 bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx,
501 SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
502
503 /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
504 /// constant folded without side-effects, but discard the result.
505 bool isEvaluatable(const ASTContext &Ctx) const;
506
507 /// HasSideEffects - This routine returns true for all those expressions
508 /// which must be evaluated each time and must not be optimized away
509 /// or evaluated at compile time. Example is a function call, volatile
510 /// variable read.
511 bool HasSideEffects(const ASTContext &Ctx) const;
512
513 /// \brief Determine whether this expression involves a call to any function
514 /// that is not trivial.
515 bool hasNonTrivialCall(ASTContext &Ctx);
516
517 /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
518 /// integer. This must be called on an expression that constant folds to an
519 /// integer.
520 llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const;
521
522 /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
523 /// lvalue with link time known address, with no side-effects.
524 bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
525
526 /// EvaluateAsInitializer - Evaluate an expression as if it were the
527 /// initializer of the given declaration. Returns true if the initializer
528 /// can be folded to a constant, and produces any relevant notes. In C++11,
529 /// notes will be produced if the expression is not a constant expression.
530 bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
531 const VarDecl *VD,
532 llvm::SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
533
534 /// \brief Enumeration used to describe the kind of Null pointer constant
535 /// returned from \c isNullPointerConstant().
536 enum NullPointerConstantKind {
537 /// \brief Expression is not a Null pointer constant.
538 NPCK_NotNull = 0,
539
540 /// \brief Expression is a Null pointer constant built from a zero integer.
541 NPCK_ZeroInteger,
542
543 /// \brief Expression is a C++0X nullptr.
544 NPCK_CXX0X_nullptr,
545
546 /// \brief Expression is a GNU-style __null constant.
547 NPCK_GNUNull
548 };
549
550 /// \brief Enumeration used to describe how \c isNullPointerConstant()
551 /// should cope with value-dependent expressions.
552 enum NullPointerConstantValueDependence {
553 /// \brief Specifies that the expression should never be value-dependent.
554 NPC_NeverValueDependent = 0,
555
556 /// \brief Specifies that a value-dependent expression of integral or
557 /// dependent type should be considered a null pointer constant.
558 NPC_ValueDependentIsNull,
559
560 /// \brief Specifies that a value-dependent expression should be considered
561 /// to never be a null pointer constant.
562 NPC_ValueDependentIsNotNull
563 };
564
565 /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
566 /// a Null pointer constant. The return value can further distinguish the
567 /// kind of NULL pointer constant that was detected.
568 NullPointerConstantKind isNullPointerConstant(
569 ASTContext &Ctx,
570 NullPointerConstantValueDependence NPC) const;
571
572 /// isOBJCGCCandidate - Return true if this expression may be used in a read/
573 /// write barrier.
574 bool isOBJCGCCandidate(ASTContext &Ctx) const;
575
576 /// \brief Returns true if this expression is a bound member function.
577 bool isBoundMemberFunction(ASTContext &Ctx) const;
578
579 /// \brief Given an expression of bound-member type, find the type
580 /// of the member. Returns null if this is an *overloaded* bound
581 /// member expression.
582 static QualType findBoundMemberType(const Expr *expr);
583
584 /// IgnoreImpCasts - Skip past any implicit casts which might
585 /// surround this expression. Only skips ImplicitCastExprs.
586 Expr *IgnoreImpCasts() LLVM_READONLY;
587
588 /// IgnoreImplicit - Skip past any implicit AST nodes which might
589 /// surround this expression.
IgnoreImplicit()590 Expr *IgnoreImplicit() LLVM_READONLY {
591 return cast<Expr>(Stmt::IgnoreImplicit());
592 }
593
594 /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return
595 /// its subexpression. If that subexpression is also a ParenExpr,
596 /// then this method recursively returns its subexpression, and so forth.
597 /// Otherwise, the method returns the current Expr.
598 Expr *IgnoreParens() LLVM_READONLY;
599
600 /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr
601 /// or CastExprs, returning their operand.
602 Expr *IgnoreParenCasts() LLVM_READONLY;
603
604 /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off
605 /// any ParenExpr or ImplicitCastExprs, returning their operand.
606 Expr *IgnoreParenImpCasts() LLVM_READONLY;
607
608 /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a
609 /// call to a conversion operator, return the argument.
610 Expr *IgnoreConversionOperator() LLVM_READONLY;
611
IgnoreConversionOperator()612 const Expr *IgnoreConversionOperator() const LLVM_READONLY {
613 return const_cast<Expr*>(this)->IgnoreConversionOperator();
614 }
615
IgnoreParenImpCasts()616 const Expr *IgnoreParenImpCasts() const LLVM_READONLY {
617 return const_cast<Expr*>(this)->IgnoreParenImpCasts();
618 }
619
620 /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and
621 /// CastExprs that represent lvalue casts, returning their operand.
622 Expr *IgnoreParenLValueCasts() LLVM_READONLY;
623
IgnoreParenLValueCasts()624 const Expr *IgnoreParenLValueCasts() const LLVM_READONLY {
625 return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
626 }
627
628 /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
629 /// value (including ptr->int casts of the same size). Strip off any
630 /// ParenExpr or CastExprs, returning their operand.
631 Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY;
632
633 /// \brief Determine whether this expression is a default function argument.
634 ///
635 /// Default arguments are implicitly generated in the abstract syntax tree
636 /// by semantic analysis for function calls, object constructions, etc. in
637 /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
638 /// this routine also looks through any implicit casts to determine whether
639 /// the expression is a default argument.
640 bool isDefaultArgument() const;
641
642 /// \brief Determine whether the result of this expression is a
643 /// temporary object of the given class type.
644 bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
645
646 /// \brief Whether this expression is an implicit reference to 'this' in C++.
647 bool isImplicitCXXThis() const;
648
IgnoreImpCasts()649 const Expr *IgnoreImpCasts() const LLVM_READONLY {
650 return const_cast<Expr*>(this)->IgnoreImpCasts();
651 }
IgnoreParens()652 const Expr *IgnoreParens() const LLVM_READONLY {
653 return const_cast<Expr*>(this)->IgnoreParens();
654 }
IgnoreParenCasts()655 const Expr *IgnoreParenCasts() const LLVM_READONLY {
656 return const_cast<Expr*>(this)->IgnoreParenCasts();
657 }
IgnoreParenNoopCasts(ASTContext & Ctx)658 const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY {
659 return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
660 }
661
662 static bool hasAnyTypeDependentArguments(llvm::ArrayRef<Expr *> Exprs);
663
classof(const Stmt * T)664 static bool classof(const Stmt *T) {
665 return T->getStmtClass() >= firstExprConstant &&
666 T->getStmtClass() <= lastExprConstant;
667 }
classof(const Expr *)668 static bool classof(const Expr *) { return true; }
669 };
670
671
672 //===----------------------------------------------------------------------===//
673 // Primary Expressions.
674 //===----------------------------------------------------------------------===//
675
676 /// OpaqueValueExpr - An expression referring to an opaque object of a
677 /// fixed type and value class. These don't correspond to concrete
678 /// syntax; instead they're used to express operations (usually copy
679 /// operations) on values whose source is generally obvious from
680 /// context.
681 class OpaqueValueExpr : public Expr {
682 friend class ASTStmtReader;
683 Expr *SourceExpr;
684 SourceLocation Loc;
685
686 public:
687 OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK,
688 ExprObjectKind OK = OK_Ordinary,
689 Expr *SourceExpr = 0)
690 : Expr(OpaqueValueExprClass, T, VK, OK,
691 T->isDependentType(),
692 T->isDependentType() ||
693 (SourceExpr && SourceExpr->isValueDependent()),
694 T->isInstantiationDependentType(),
695 false),
696 SourceExpr(SourceExpr), Loc(Loc) {
697 }
698
699 /// Given an expression which invokes a copy constructor --- i.e. a
700 /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
701 /// find the OpaqueValueExpr that's the source of the construction.
702 static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
703
OpaqueValueExpr(EmptyShell Empty)704 explicit OpaqueValueExpr(EmptyShell Empty)
705 : Expr(OpaqueValueExprClass, Empty) { }
706
707 /// \brief Retrieve the location of this expression.
getLocation()708 SourceLocation getLocation() const { return Loc; }
709
getSourceRange()710 SourceRange getSourceRange() const LLVM_READONLY {
711 if (SourceExpr) return SourceExpr->getSourceRange();
712 return Loc;
713 }
getExprLoc()714 SourceLocation getExprLoc() const LLVM_READONLY {
715 if (SourceExpr) return SourceExpr->getExprLoc();
716 return Loc;
717 }
718
children()719 child_range children() { return child_range(); }
720
721 /// The source expression of an opaque value expression is the
722 /// expression which originally generated the value. This is
723 /// provided as a convenience for analyses that don't wish to
724 /// precisely model the execution behavior of the program.
725 ///
726 /// The source expression is typically set when building the
727 /// expression which binds the opaque value expression in the first
728 /// place.
getSourceExpr()729 Expr *getSourceExpr() const { return SourceExpr; }
730
classof(const Stmt * T)731 static bool classof(const Stmt *T) {
732 return T->getStmtClass() == OpaqueValueExprClass;
733 }
classof(const OpaqueValueExpr *)734 static bool classof(const OpaqueValueExpr *) { return true; }
735 };
736
737 /// \brief A reference to a declared variable, function, enum, etc.
738 /// [C99 6.5.1p2]
739 ///
740 /// This encodes all the information about how a declaration is referenced
741 /// within an expression.
742 ///
743 /// There are several optional constructs attached to DeclRefExprs only when
744 /// they apply in order to conserve memory. These are laid out past the end of
745 /// the object, and flags in the DeclRefExprBitfield track whether they exist:
746 ///
747 /// DeclRefExprBits.HasQualifier:
748 /// Specifies when this declaration reference expression has a C++
749 /// nested-name-specifier.
750 /// DeclRefExprBits.HasFoundDecl:
751 /// Specifies when this declaration reference expression has a record of
752 /// a NamedDecl (different from the referenced ValueDecl) which was found
753 /// during name lookup and/or overload resolution.
754 /// DeclRefExprBits.HasTemplateKWAndArgsInfo:
755 /// Specifies when this declaration reference expression has an explicit
756 /// C++ template keyword and/or template argument list.
757 /// DeclRefExprBits.RefersToEnclosingLocal
758 /// Specifies when this declaration reference expression (validly)
759 /// refers to a local variable from a different function.
760 class DeclRefExpr : public Expr {
761 /// \brief The declaration that we are referencing.
762 ValueDecl *D;
763
764 /// \brief The location of the declaration name itself.
765 SourceLocation Loc;
766
767 /// \brief Provides source/type location info for the declaration name
768 /// embedded in D.
769 DeclarationNameLoc DNLoc;
770
771 /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
getInternalQualifierLoc()772 NestedNameSpecifierLoc &getInternalQualifierLoc() {
773 assert(hasQualifier());
774 return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1);
775 }
776
777 /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
getInternalQualifierLoc()778 const NestedNameSpecifierLoc &getInternalQualifierLoc() const {
779 return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc();
780 }
781
782 /// \brief Test whether there is a distinct FoundDecl attached to the end of
783 /// this DRE.
hasFoundDecl()784 bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
785
786 /// \brief Helper to retrieve the optional NamedDecl through which this
787 /// reference occured.
getInternalFoundDecl()788 NamedDecl *&getInternalFoundDecl() {
789 assert(hasFoundDecl());
790 if (hasQualifier())
791 return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1);
792 return *reinterpret_cast<NamedDecl **>(this + 1);
793 }
794
795 /// \brief Helper to retrieve the optional NamedDecl through which this
796 /// reference occured.
getInternalFoundDecl()797 NamedDecl *getInternalFoundDecl() const {
798 return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl();
799 }
800
801 DeclRefExpr(ASTContext &Ctx,
802 NestedNameSpecifierLoc QualifierLoc,
803 SourceLocation TemplateKWLoc,
804 ValueDecl *D, bool refersToEnclosingLocal,
805 const DeclarationNameInfo &NameInfo,
806 NamedDecl *FoundD,
807 const TemplateArgumentListInfo *TemplateArgs,
808 QualType T, ExprValueKind VK);
809
810 /// \brief Construct an empty declaration reference expression.
DeclRefExpr(EmptyShell Empty)811 explicit DeclRefExpr(EmptyShell Empty)
812 : Expr(DeclRefExprClass, Empty) { }
813
814 /// \brief Computes the type- and value-dependence flags for this
815 /// declaration reference expression.
816 void computeDependence(ASTContext &C);
817
818 public:
819 DeclRefExpr(ValueDecl *D, bool refersToEnclosingLocal, QualType T,
820 ExprValueKind VK, SourceLocation L,
821 const DeclarationNameLoc &LocInfo = DeclarationNameLoc())
Expr(DeclRefExprClass,T,VK,OK_Ordinary,false,false,false,false)822 : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false),
823 D(D), Loc(L), DNLoc(LocInfo) {
824 DeclRefExprBits.HasQualifier = 0;
825 DeclRefExprBits.HasTemplateKWAndArgsInfo = 0;
826 DeclRefExprBits.HasFoundDecl = 0;
827 DeclRefExprBits.HadMultipleCandidates = 0;
828 DeclRefExprBits.RefersToEnclosingLocal = refersToEnclosingLocal;
829 computeDependence(D->getASTContext());
830 }
831
832 static DeclRefExpr *Create(ASTContext &Context,
833 NestedNameSpecifierLoc QualifierLoc,
834 SourceLocation TemplateKWLoc,
835 ValueDecl *D,
836 bool isEnclosingLocal,
837 SourceLocation NameLoc,
838 QualType T, ExprValueKind VK,
839 NamedDecl *FoundD = 0,
840 const TemplateArgumentListInfo *TemplateArgs = 0);
841
842 static DeclRefExpr *Create(ASTContext &Context,
843 NestedNameSpecifierLoc QualifierLoc,
844 SourceLocation TemplateKWLoc,
845 ValueDecl *D,
846 bool isEnclosingLocal,
847 const DeclarationNameInfo &NameInfo,
848 QualType T, ExprValueKind VK,
849 NamedDecl *FoundD = 0,
850 const TemplateArgumentListInfo *TemplateArgs = 0);
851
852 /// \brief Construct an empty declaration reference expression.
853 static DeclRefExpr *CreateEmpty(ASTContext &Context,
854 bool HasQualifier,
855 bool HasFoundDecl,
856 bool HasTemplateKWAndArgsInfo,
857 unsigned NumTemplateArgs);
858
getDecl()859 ValueDecl *getDecl() { return D; }
getDecl()860 const ValueDecl *getDecl() const { return D; }
setDecl(ValueDecl * NewD)861 void setDecl(ValueDecl *NewD) { D = NewD; }
862
getNameInfo()863 DeclarationNameInfo getNameInfo() const {
864 return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
865 }
866
getLocation()867 SourceLocation getLocation() const { return Loc; }
setLocation(SourceLocation L)868 void setLocation(SourceLocation L) { Loc = L; }
869 SourceRange getSourceRange() const LLVM_READONLY;
870 SourceLocation getLocStart() const LLVM_READONLY;
871 SourceLocation getLocEnd() const LLVM_READONLY;
872
873 /// \brief Determine whether this declaration reference was preceded by a
874 /// C++ nested-name-specifier, e.g., \c N::foo.
hasQualifier()875 bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
876
877 /// \brief If the name was qualified, retrieves the nested-name-specifier
878 /// that precedes the name. Otherwise, returns NULL.
getQualifier()879 NestedNameSpecifier *getQualifier() const {
880 if (!hasQualifier())
881 return 0;
882
883 return getInternalQualifierLoc().getNestedNameSpecifier();
884 }
885
886 /// \brief If the name was qualified, retrieves the nested-name-specifier
887 /// that precedes the name, with source-location information.
getQualifierLoc()888 NestedNameSpecifierLoc getQualifierLoc() const {
889 if (!hasQualifier())
890 return NestedNameSpecifierLoc();
891
892 return getInternalQualifierLoc();
893 }
894
895 /// \brief Get the NamedDecl through which this reference occured.
896 ///
897 /// This Decl may be different from the ValueDecl actually referred to in the
898 /// presence of using declarations, etc. It always returns non-NULL, and may
899 /// simple return the ValueDecl when appropriate.
getFoundDecl()900 NamedDecl *getFoundDecl() {
901 return hasFoundDecl() ? getInternalFoundDecl() : D;
902 }
903
904 /// \brief Get the NamedDecl through which this reference occurred.
905 /// See non-const variant.
getFoundDecl()906 const NamedDecl *getFoundDecl() const {
907 return hasFoundDecl() ? getInternalFoundDecl() : D;
908 }
909
hasTemplateKWAndArgsInfo()910 bool hasTemplateKWAndArgsInfo() const {
911 return DeclRefExprBits.HasTemplateKWAndArgsInfo;
912 }
913
914 /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()915 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
916 if (!hasTemplateKWAndArgsInfo())
917 return 0;
918
919 if (hasFoundDecl())
920 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
921 &getInternalFoundDecl() + 1);
922
923 if (hasQualifier())
924 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
925 &getInternalQualifierLoc() + 1);
926
927 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1);
928 }
929
930 /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()931 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
932 return const_cast<DeclRefExpr*>(this)->getTemplateKWAndArgsInfo();
933 }
934
935 /// \brief Retrieve the location of the template keyword preceding
936 /// this name, if any.
getTemplateKeywordLoc()937 SourceLocation getTemplateKeywordLoc() const {
938 if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
939 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
940 }
941
942 /// \brief Retrieve the location of the left angle bracket starting the
943 /// explicit template argument list following the name, if any.
getLAngleLoc()944 SourceLocation getLAngleLoc() const {
945 if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
946 return getTemplateKWAndArgsInfo()->LAngleLoc;
947 }
948
949 /// \brief Retrieve the location of the right angle bracket ending the
950 /// explicit template argument list following the name, if any.
getRAngleLoc()951 SourceLocation getRAngleLoc() const {
952 if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
953 return getTemplateKWAndArgsInfo()->RAngleLoc;
954 }
955
956 /// \brief Determines whether the name in this declaration reference
957 /// was preceded by the template keyword.
hasTemplateKeyword()958 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
959
960 /// \brief Determines whether this declaration reference was followed by an
961 /// explicit template argument list.
hasExplicitTemplateArgs()962 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
963
964 /// \brief Retrieve the explicit template argument list that followed the
965 /// member template name.
getExplicitTemplateArgs()966 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
967 assert(hasExplicitTemplateArgs());
968 return *getTemplateKWAndArgsInfo();
969 }
970
971 /// \brief Retrieve the explicit template argument list that followed the
972 /// member template name.
getExplicitTemplateArgs()973 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
974 return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs();
975 }
976
977 /// \brief Retrieves the optional explicit template arguments.
978 /// This points to the same data as getExplicitTemplateArgs(), but
979 /// returns null if there are no explicit template arguments.
getOptionalExplicitTemplateArgs()980 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
981 if (!hasExplicitTemplateArgs()) return 0;
982 return &getExplicitTemplateArgs();
983 }
984
985 /// \brief Copies the template arguments (if present) into the given
986 /// structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)987 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
988 if (hasExplicitTemplateArgs())
989 getExplicitTemplateArgs().copyInto(List);
990 }
991
992 /// \brief Retrieve the template arguments provided as part of this
993 /// template-id.
getTemplateArgs()994 const TemplateArgumentLoc *getTemplateArgs() const {
995 if (!hasExplicitTemplateArgs())
996 return 0;
997
998 return getExplicitTemplateArgs().getTemplateArgs();
999 }
1000
1001 /// \brief Retrieve the number of template arguments provided as part of this
1002 /// template-id.
getNumTemplateArgs()1003 unsigned getNumTemplateArgs() const {
1004 if (!hasExplicitTemplateArgs())
1005 return 0;
1006
1007 return getExplicitTemplateArgs().NumTemplateArgs;
1008 }
1009
1010 /// \brief Returns true if this expression refers to a function that
1011 /// was resolved from an overloaded set having size greater than 1.
hadMultipleCandidates()1012 bool hadMultipleCandidates() const {
1013 return DeclRefExprBits.HadMultipleCandidates;
1014 }
1015 /// \brief Sets the flag telling whether this expression refers to
1016 /// a function that was resolved from an overloaded set having size
1017 /// greater than 1.
1018 void setHadMultipleCandidates(bool V = true) {
1019 DeclRefExprBits.HadMultipleCandidates = V;
1020 }
1021
1022 /// Does this DeclRefExpr refer to a local declaration from an
1023 /// enclosing function scope?
refersToEnclosingLocal()1024 bool refersToEnclosingLocal() const {
1025 return DeclRefExprBits.RefersToEnclosingLocal;
1026 }
1027
classof(const Stmt * T)1028 static bool classof(const Stmt *T) {
1029 return T->getStmtClass() == DeclRefExprClass;
1030 }
classof(const DeclRefExpr *)1031 static bool classof(const DeclRefExpr *) { return true; }
1032
1033 // Iterators
children()1034 child_range children() { return child_range(); }
1035
1036 friend class ASTStmtReader;
1037 friend class ASTStmtWriter;
1038 };
1039
1040 /// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
1041 class PredefinedExpr : public Expr {
1042 public:
1043 enum IdentType {
1044 Func,
1045 Function,
1046 PrettyFunction,
1047 /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
1048 /// 'virtual' keyword is omitted for virtual member functions.
1049 PrettyFunctionNoVirtual
1050 };
1051
1052 private:
1053 SourceLocation Loc;
1054 IdentType Type;
1055 public:
PredefinedExpr(SourceLocation l,QualType type,IdentType IT)1056 PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
1057 : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary,
1058 type->isDependentType(), type->isDependentType(),
1059 type->isInstantiationDependentType(),
1060 /*ContainsUnexpandedParameterPack=*/false),
1061 Loc(l), Type(IT) {}
1062
1063 /// \brief Construct an empty predefined expression.
PredefinedExpr(EmptyShell Empty)1064 explicit PredefinedExpr(EmptyShell Empty)
1065 : Expr(PredefinedExprClass, Empty) { }
1066
getIdentType()1067 IdentType getIdentType() const { return Type; }
setIdentType(IdentType IT)1068 void setIdentType(IdentType IT) { Type = IT; }
1069
getLocation()1070 SourceLocation getLocation() const { return Loc; }
setLocation(SourceLocation L)1071 void setLocation(SourceLocation L) { Loc = L; }
1072
1073 static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
1074
getSourceRange()1075 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
1076
classof(const Stmt * T)1077 static bool classof(const Stmt *T) {
1078 return T->getStmtClass() == PredefinedExprClass;
1079 }
classof(const PredefinedExpr *)1080 static bool classof(const PredefinedExpr *) { return true; }
1081
1082 // Iterators
children()1083 child_range children() { return child_range(); }
1084 };
1085
1086 /// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without
1087 /// leaking memory.
1088 ///
1089 /// For large floats/integers, APFloat/APInt will allocate memory from the heap
1090 /// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator
1091 /// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
1092 /// the APFloat/APInt values will never get freed. APNumericStorage uses
1093 /// ASTContext's allocator for memory allocation.
1094 class APNumericStorage {
1095 union {
1096 uint64_t VAL; ///< Used to store the <= 64 bits integer value.
1097 uint64_t *pVal; ///< Used to store the >64 bits integer value.
1098 };
1099 unsigned BitWidth;
1100
hasAllocation()1101 bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
1102
1103 APNumericStorage(const APNumericStorage&); // do not implement
1104 APNumericStorage& operator=(const APNumericStorage&); // do not implement
1105
1106 protected:
APNumericStorage()1107 APNumericStorage() : VAL(0), BitWidth(0) { }
1108
getIntValue()1109 llvm::APInt getIntValue() const {
1110 unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
1111 if (NumWords > 1)
1112 return llvm::APInt(BitWidth, NumWords, pVal);
1113 else
1114 return llvm::APInt(BitWidth, VAL);
1115 }
1116 void setIntValue(ASTContext &C, const llvm::APInt &Val);
1117 };
1118
1119 class APIntStorage : private APNumericStorage {
1120 public:
getValue()1121 llvm::APInt getValue() const { return getIntValue(); }
setValue(ASTContext & C,const llvm::APInt & Val)1122 void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); }
1123 };
1124
1125 class APFloatStorage : private APNumericStorage {
1126 public:
getValue(bool IsIEEE)1127 llvm::APFloat getValue(bool IsIEEE) const {
1128 return llvm::APFloat(getIntValue(), IsIEEE);
1129 }
setValue(ASTContext & C,const llvm::APFloat & Val)1130 void setValue(ASTContext &C, const llvm::APFloat &Val) {
1131 setIntValue(C, Val.bitcastToAPInt());
1132 }
1133 };
1134
1135 class IntegerLiteral : public Expr, public APIntStorage {
1136 SourceLocation Loc;
1137
1138 /// \brief Construct an empty integer literal.
IntegerLiteral(EmptyShell Empty)1139 explicit IntegerLiteral(EmptyShell Empty)
1140 : Expr(IntegerLiteralClass, Empty) { }
1141
1142 public:
1143 // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
1144 // or UnsignedLongLongTy
IntegerLiteral(ASTContext & C,const llvm::APInt & V,QualType type,SourceLocation l)1145 IntegerLiteral(ASTContext &C, const llvm::APInt &V,
1146 QualType type, SourceLocation l)
1147 : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
1148 false, false),
1149 Loc(l) {
1150 assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
1151 assert(V.getBitWidth() == C.getIntWidth(type) &&
1152 "Integer type is not the correct size for constant.");
1153 setValue(C, V);
1154 }
1155
1156 /// \brief Returns a new integer literal with value 'V' and type 'type'.
1157 /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
1158 /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
1159 /// \param V - the value that the returned integer literal contains.
1160 static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V,
1161 QualType type, SourceLocation l);
1162 /// \brief Returns a new empty integer literal.
1163 static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty);
1164
getSourceRange()1165 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
1166
1167 /// \brief Retrieve the location of the literal.
getLocation()1168 SourceLocation getLocation() const { return Loc; }
1169
setLocation(SourceLocation Location)1170 void setLocation(SourceLocation Location) { Loc = Location; }
1171
classof(const Stmt * T)1172 static bool classof(const Stmt *T) {
1173 return T->getStmtClass() == IntegerLiteralClass;
1174 }
classof(const IntegerLiteral *)1175 static bool classof(const IntegerLiteral *) { return true; }
1176
1177 // Iterators
children()1178 child_range children() { return child_range(); }
1179 };
1180
1181 class CharacterLiteral : public Expr {
1182 public:
1183 enum CharacterKind {
1184 Ascii,
1185 Wide,
1186 UTF16,
1187 UTF32
1188 };
1189
1190 private:
1191 unsigned Value;
1192 SourceLocation Loc;
1193 public:
1194 // type should be IntTy
CharacterLiteral(unsigned value,CharacterKind kind,QualType type,SourceLocation l)1195 CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
1196 SourceLocation l)
1197 : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
1198 false, false),
1199 Value(value), Loc(l) {
1200 CharacterLiteralBits.Kind = kind;
1201 }
1202
1203 /// \brief Construct an empty character literal.
CharacterLiteral(EmptyShell Empty)1204 CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
1205
getLocation()1206 SourceLocation getLocation() const { return Loc; }
getKind()1207 CharacterKind getKind() const {
1208 return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
1209 }
1210
getSourceRange()1211 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
1212
getValue()1213 unsigned getValue() const { return Value; }
1214
setLocation(SourceLocation Location)1215 void setLocation(SourceLocation Location) { Loc = Location; }
setKind(CharacterKind kind)1216 void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
setValue(unsigned Val)1217 void setValue(unsigned Val) { Value = Val; }
1218
classof(const Stmt * T)1219 static bool classof(const Stmt *T) {
1220 return T->getStmtClass() == CharacterLiteralClass;
1221 }
classof(const CharacterLiteral *)1222 static bool classof(const CharacterLiteral *) { return true; }
1223
1224 // Iterators
children()1225 child_range children() { return child_range(); }
1226 };
1227
1228 class FloatingLiteral : public Expr, private APFloatStorage {
1229 SourceLocation Loc;
1230
FloatingLiteral(ASTContext & C,const llvm::APFloat & V,bool isexact,QualType Type,SourceLocation L)1231 FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact,
1232 QualType Type, SourceLocation L)
1233 : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false,
1234 false, false), Loc(L) {
1235 FloatingLiteralBits.IsIEEE =
1236 &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad;
1237 FloatingLiteralBits.IsExact = isexact;
1238 setValue(C, V);
1239 }
1240
1241 /// \brief Construct an empty floating-point literal.
FloatingLiteral(ASTContext & C,EmptyShell Empty)1242 explicit FloatingLiteral(ASTContext &C, EmptyShell Empty)
1243 : Expr(FloatingLiteralClass, Empty) {
1244 FloatingLiteralBits.IsIEEE =
1245 &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad;
1246 FloatingLiteralBits.IsExact = false;
1247 }
1248
1249 public:
1250 static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V,
1251 bool isexact, QualType Type, SourceLocation L);
1252 static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty);
1253
getValue()1254 llvm::APFloat getValue() const {
1255 return APFloatStorage::getValue(FloatingLiteralBits.IsIEEE);
1256 }
setValue(ASTContext & C,const llvm::APFloat & Val)1257 void setValue(ASTContext &C, const llvm::APFloat &Val) {
1258 APFloatStorage::setValue(C, Val);
1259 }
1260
isExact()1261 bool isExact() const { return FloatingLiteralBits.IsExact; }
setExact(bool E)1262 void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1263
1264 /// getValueAsApproximateDouble - This returns the value as an inaccurate
1265 /// double. Note that this may cause loss of precision, but is useful for
1266 /// debugging dumps, etc.
1267 double getValueAsApproximateDouble() const;
1268
getLocation()1269 SourceLocation getLocation() const { return Loc; }
setLocation(SourceLocation L)1270 void setLocation(SourceLocation L) { Loc = L; }
1271
getSourceRange()1272 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
1273
classof(const Stmt * T)1274 static bool classof(const Stmt *T) {
1275 return T->getStmtClass() == FloatingLiteralClass;
1276 }
classof(const FloatingLiteral *)1277 static bool classof(const FloatingLiteral *) { return true; }
1278
1279 // Iterators
children()1280 child_range children() { return child_range(); }
1281 };
1282
1283 /// ImaginaryLiteral - We support imaginary integer and floating point literals,
1284 /// like "1.0i". We represent these as a wrapper around FloatingLiteral and
1285 /// IntegerLiteral classes. Instances of this class always have a Complex type
1286 /// whose element type matches the subexpression.
1287 ///
1288 class ImaginaryLiteral : public Expr {
1289 Stmt *Val;
1290 public:
ImaginaryLiteral(Expr * val,QualType Ty)1291 ImaginaryLiteral(Expr *val, QualType Ty)
1292 : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
1293 false, false),
1294 Val(val) {}
1295
1296 /// \brief Build an empty imaginary literal.
ImaginaryLiteral(EmptyShell Empty)1297 explicit ImaginaryLiteral(EmptyShell Empty)
1298 : Expr(ImaginaryLiteralClass, Empty) { }
1299
getSubExpr()1300 const Expr *getSubExpr() const { return cast<Expr>(Val); }
getSubExpr()1301 Expr *getSubExpr() { return cast<Expr>(Val); }
setSubExpr(Expr * E)1302 void setSubExpr(Expr *E) { Val = E; }
1303
getSourceRange()1304 SourceRange getSourceRange() const LLVM_READONLY { return Val->getSourceRange(); }
classof(const Stmt * T)1305 static bool classof(const Stmt *T) {
1306 return T->getStmtClass() == ImaginaryLiteralClass;
1307 }
classof(const ImaginaryLiteral *)1308 static bool classof(const ImaginaryLiteral *) { return true; }
1309
1310 // Iterators
children()1311 child_range children() { return child_range(&Val, &Val+1); }
1312 };
1313
1314 /// StringLiteral - This represents a string literal expression, e.g. "foo"
1315 /// or L"bar" (wide strings). The actual string is returned by getStrData()
1316 /// is NOT null-terminated, and the length of the string is determined by
1317 /// calling getByteLength(). The C type for a string is always a
1318 /// ConstantArrayType. In C++, the char type is const qualified, in C it is
1319 /// not.
1320 ///
1321 /// Note that strings in C can be formed by concatenation of multiple string
1322 /// literal pptokens in translation phase #6. This keeps track of the locations
1323 /// of each of these pieces.
1324 ///
1325 /// Strings in C can also be truncated and extended by assigning into arrays,
1326 /// e.g. with constructs like:
1327 /// char X[2] = "foobar";
1328 /// In this case, getByteLength() will return 6, but the string literal will
1329 /// have type "char[2]".
1330 class StringLiteral : public Expr {
1331 public:
1332 enum StringKind {
1333 Ascii,
1334 Wide,
1335 UTF8,
1336 UTF16,
1337 UTF32
1338 };
1339
1340 private:
1341 friend class ASTStmtReader;
1342
1343 union {
1344 const char *asChar;
1345 const uint16_t *asUInt16;
1346 const uint32_t *asUInt32;
1347 } StrData;
1348 unsigned Length;
1349 unsigned CharByteWidth : 4;
1350 unsigned Kind : 3;
1351 unsigned IsPascal : 1;
1352 unsigned NumConcatenated;
1353 SourceLocation TokLocs[1];
1354
StringLiteral(QualType Ty)1355 StringLiteral(QualType Ty) :
1356 Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false,
1357 false) {}
1358
1359 static int mapCharByteWidth(TargetInfo const &target,StringKind k);
1360
1361 public:
1362 /// This is the "fully general" constructor that allows representation of
1363 /// strings formed from multiple concatenated tokens.
1364 static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
1365 bool Pascal, QualType Ty,
1366 const SourceLocation *Loc, unsigned NumStrs);
1367
1368 /// Simple constructor for string literals made from one token.
Create(ASTContext & C,StringRef Str,StringKind Kind,bool Pascal,QualType Ty,SourceLocation Loc)1369 static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
1370 bool Pascal, QualType Ty,
1371 SourceLocation Loc) {
1372 return Create(C, Str, Kind, Pascal, Ty, &Loc, 1);
1373 }
1374
1375 /// \brief Construct an empty string literal.
1376 static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
1377
getString()1378 StringRef getString() const {
1379 assert(CharByteWidth==1
1380 && "This function is used in places that assume strings use char");
1381 return StringRef(StrData.asChar, getByteLength());
1382 }
1383
1384 /// Allow clients that need the byte representation, such as ASTWriterStmt
1385 /// ::VisitStringLiteral(), access.
getBytes()1386 StringRef getBytes() const {
1387 // FIXME: StringRef may not be the right type to use as a result for this.
1388 if (CharByteWidth == 1)
1389 return StringRef(StrData.asChar, getByteLength());
1390 if (CharByteWidth == 4)
1391 return StringRef(reinterpret_cast<const char*>(StrData.asUInt32),
1392 getByteLength());
1393 assert(CharByteWidth == 2 && "unsupported CharByteWidth");
1394 return StringRef(reinterpret_cast<const char*>(StrData.asUInt16),
1395 getByteLength());
1396 }
1397
getCodeUnit(size_t i)1398 uint32_t getCodeUnit(size_t i) const {
1399 assert(i < Length && "out of bounds access");
1400 if (CharByteWidth == 1)
1401 return static_cast<unsigned char>(StrData.asChar[i]);
1402 if (CharByteWidth == 4)
1403 return StrData.asUInt32[i];
1404 assert(CharByteWidth == 2 && "unsupported CharByteWidth");
1405 return StrData.asUInt16[i];
1406 }
1407
getByteLength()1408 unsigned getByteLength() const { return CharByteWidth*Length; }
getLength()1409 unsigned getLength() const { return Length; }
getCharByteWidth()1410 unsigned getCharByteWidth() const { return CharByteWidth; }
1411
1412 /// \brief Sets the string data to the given string data.
1413 void setString(ASTContext &C, StringRef Str,
1414 StringKind Kind, bool IsPascal);
1415
getKind()1416 StringKind getKind() const { return static_cast<StringKind>(Kind); }
1417
1418
isAscii()1419 bool isAscii() const { return Kind == Ascii; }
isWide()1420 bool isWide() const { return Kind == Wide; }
isUTF8()1421 bool isUTF8() const { return Kind == UTF8; }
isUTF16()1422 bool isUTF16() const { return Kind == UTF16; }
isUTF32()1423 bool isUTF32() const { return Kind == UTF32; }
isPascal()1424 bool isPascal() const { return IsPascal; }
1425
containsNonAsciiOrNull()1426 bool containsNonAsciiOrNull() const {
1427 StringRef Str = getString();
1428 for (unsigned i = 0, e = Str.size(); i != e; ++i)
1429 if (!isascii(Str[i]) || !Str[i])
1430 return true;
1431 return false;
1432 }
1433
1434 /// getNumConcatenated - Get the number of string literal tokens that were
1435 /// concatenated in translation phase #6 to form this string literal.
getNumConcatenated()1436 unsigned getNumConcatenated() const { return NumConcatenated; }
1437
getStrTokenLoc(unsigned TokNum)1438 SourceLocation getStrTokenLoc(unsigned TokNum) const {
1439 assert(TokNum < NumConcatenated && "Invalid tok number");
1440 return TokLocs[TokNum];
1441 }
setStrTokenLoc(unsigned TokNum,SourceLocation L)1442 void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1443 assert(TokNum < NumConcatenated && "Invalid tok number");
1444 TokLocs[TokNum] = L;
1445 }
1446
1447 /// getLocationOfByte - Return a source location that points to the specified
1448 /// byte of this string literal.
1449 ///
1450 /// Strings are amazingly complex. They can be formed from multiple tokens
1451 /// and can have escape sequences in them in addition to the usual trigraph
1452 /// and escaped newline business. This routine handles this complexity.
1453 ///
1454 SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1455 const LangOptions &Features,
1456 const TargetInfo &Target) const;
1457
1458 typedef const SourceLocation *tokloc_iterator;
tokloc_begin()1459 tokloc_iterator tokloc_begin() const { return TokLocs; }
tokloc_end()1460 tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
1461
getSourceRange()1462 SourceRange getSourceRange() const LLVM_READONLY {
1463 return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
1464 }
classof(const Stmt * T)1465 static bool classof(const Stmt *T) {
1466 return T->getStmtClass() == StringLiteralClass;
1467 }
classof(const StringLiteral *)1468 static bool classof(const StringLiteral *) { return true; }
1469
1470 // Iterators
children()1471 child_range children() { return child_range(); }
1472 };
1473
1474 /// ParenExpr - This represents a parethesized expression, e.g. "(1)". This
1475 /// AST node is only formed if full location information is requested.
1476 class ParenExpr : public Expr {
1477 SourceLocation L, R;
1478 Stmt *Val;
1479 public:
ParenExpr(SourceLocation l,SourceLocation r,Expr * val)1480 ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
1481 : Expr(ParenExprClass, val->getType(),
1482 val->getValueKind(), val->getObjectKind(),
1483 val->isTypeDependent(), val->isValueDependent(),
1484 val->isInstantiationDependent(),
1485 val->containsUnexpandedParameterPack()),
1486 L(l), R(r), Val(val) {}
1487
1488 /// \brief Construct an empty parenthesized expression.
ParenExpr(EmptyShell Empty)1489 explicit ParenExpr(EmptyShell Empty)
1490 : Expr(ParenExprClass, Empty) { }
1491
getSubExpr()1492 const Expr *getSubExpr() const { return cast<Expr>(Val); }
getSubExpr()1493 Expr *getSubExpr() { return cast<Expr>(Val); }
setSubExpr(Expr * E)1494 void setSubExpr(Expr *E) { Val = E; }
1495
getSourceRange()1496 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(L, R); }
1497
1498 /// \brief Get the location of the left parentheses '('.
getLParen()1499 SourceLocation getLParen() const { return L; }
setLParen(SourceLocation Loc)1500 void setLParen(SourceLocation Loc) { L = Loc; }
1501
1502 /// \brief Get the location of the right parentheses ')'.
getRParen()1503 SourceLocation getRParen() const { return R; }
setRParen(SourceLocation Loc)1504 void setRParen(SourceLocation Loc) { R = Loc; }
1505
classof(const Stmt * T)1506 static bool classof(const Stmt *T) {
1507 return T->getStmtClass() == ParenExprClass;
1508 }
classof(const ParenExpr *)1509 static bool classof(const ParenExpr *) { return true; }
1510
1511 // Iterators
children()1512 child_range children() { return child_range(&Val, &Val+1); }
1513 };
1514
1515
1516 /// UnaryOperator - This represents the unary-expression's (except sizeof and
1517 /// alignof), the postinc/postdec operators from postfix-expression, and various
1518 /// extensions.
1519 ///
1520 /// Notes on various nodes:
1521 ///
1522 /// Real/Imag - These return the real/imag part of a complex operand. If
1523 /// applied to a non-complex value, the former returns its operand and the
1524 /// later returns zero in the type of the operand.
1525 ///
1526 class UnaryOperator : public Expr {
1527 public:
1528 typedef UnaryOperatorKind Opcode;
1529
1530 private:
1531 unsigned Opc : 5;
1532 SourceLocation Loc;
1533 Stmt *Val;
1534 public:
1535
UnaryOperator(Expr * input,Opcode opc,QualType type,ExprValueKind VK,ExprObjectKind OK,SourceLocation l)1536 UnaryOperator(Expr *input, Opcode opc, QualType type,
1537 ExprValueKind VK, ExprObjectKind OK, SourceLocation l)
1538 : Expr(UnaryOperatorClass, type, VK, OK,
1539 input->isTypeDependent() || type->isDependentType(),
1540 input->isValueDependent(),
1541 (input->isInstantiationDependent() ||
1542 type->isInstantiationDependentType()),
1543 input->containsUnexpandedParameterPack()),
1544 Opc(opc), Loc(l), Val(input) {}
1545
1546 /// \brief Build an empty unary operator.
UnaryOperator(EmptyShell Empty)1547 explicit UnaryOperator(EmptyShell Empty)
1548 : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { }
1549
getOpcode()1550 Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
setOpcode(Opcode O)1551 void setOpcode(Opcode O) { Opc = O; }
1552
getSubExpr()1553 Expr *getSubExpr() const { return cast<Expr>(Val); }
setSubExpr(Expr * E)1554 void setSubExpr(Expr *E) { Val = E; }
1555
1556 /// getOperatorLoc - Return the location of the operator.
getOperatorLoc()1557 SourceLocation getOperatorLoc() const { return Loc; }
setOperatorLoc(SourceLocation L)1558 void setOperatorLoc(SourceLocation L) { Loc = L; }
1559
1560 /// isPostfix - Return true if this is a postfix operation, like x++.
isPostfix(Opcode Op)1561 static bool isPostfix(Opcode Op) {
1562 return Op == UO_PostInc || Op == UO_PostDec;
1563 }
1564
1565 /// isPrefix - Return true if this is a prefix operation, like --x.
isPrefix(Opcode Op)1566 static bool isPrefix(Opcode Op) {
1567 return Op == UO_PreInc || Op == UO_PreDec;
1568 }
1569
isPrefix()1570 bool isPrefix() const { return isPrefix(getOpcode()); }
isPostfix()1571 bool isPostfix() const { return isPostfix(getOpcode()); }
1572
isIncrementOp(Opcode Op)1573 static bool isIncrementOp(Opcode Op) {
1574 return Op == UO_PreInc || Op == UO_PostInc;
1575 }
isIncrementOp()1576 bool isIncrementOp() const {
1577 return isIncrementOp(getOpcode());
1578 }
1579
isDecrementOp(Opcode Op)1580 static bool isDecrementOp(Opcode Op) {
1581 return Op == UO_PreDec || Op == UO_PostDec;
1582 }
isDecrementOp()1583 bool isDecrementOp() const {
1584 return isDecrementOp(getOpcode());
1585 }
1586
isIncrementDecrementOp(Opcode Op)1587 static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
isIncrementDecrementOp()1588 bool isIncrementDecrementOp() const {
1589 return isIncrementDecrementOp(getOpcode());
1590 }
1591
isArithmeticOp(Opcode Op)1592 static bool isArithmeticOp(Opcode Op) {
1593 return Op >= UO_Plus && Op <= UO_LNot;
1594 }
isArithmeticOp()1595 bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
1596
1597 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1598 /// corresponds to, e.g. "sizeof" or "[pre]++"
1599 static const char *getOpcodeStr(Opcode Op);
1600
1601 /// \brief Retrieve the unary opcode that corresponds to the given
1602 /// overloaded operator.
1603 static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
1604
1605 /// \brief Retrieve the overloaded operator kind that corresponds to
1606 /// the given unary opcode.
1607 static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1608
getSourceRange()1609 SourceRange getSourceRange() const LLVM_READONLY {
1610 if (isPostfix())
1611 return SourceRange(Val->getLocStart(), Loc);
1612 else
1613 return SourceRange(Loc, Val->getLocEnd());
1614 }
getExprLoc()1615 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
1616
classof(const Stmt * T)1617 static bool classof(const Stmt *T) {
1618 return T->getStmtClass() == UnaryOperatorClass;
1619 }
classof(const UnaryOperator *)1620 static bool classof(const UnaryOperator *) { return true; }
1621
1622 // Iterators
children()1623 child_range children() { return child_range(&Val, &Val+1); }
1624 };
1625
1626 /// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
1627 /// offsetof(record-type, member-designator). For example, given:
1628 /// @code
1629 /// struct S {
1630 /// float f;
1631 /// double d;
1632 /// };
1633 /// struct T {
1634 /// int i;
1635 /// struct S s[10];
1636 /// };
1637 /// @endcode
1638 /// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
1639
1640 class OffsetOfExpr : public Expr {
1641 public:
1642 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
1643 class OffsetOfNode {
1644 public:
1645 /// \brief The kind of offsetof node we have.
1646 enum Kind {
1647 /// \brief An index into an array.
1648 Array = 0x00,
1649 /// \brief A field.
1650 Field = 0x01,
1651 /// \brief A field in a dependent type, known only by its name.
1652 Identifier = 0x02,
1653 /// \brief An implicit indirection through a C++ base class, when the
1654 /// field found is in a base class.
1655 Base = 0x03
1656 };
1657
1658 private:
1659 enum { MaskBits = 2, Mask = 0x03 };
1660
1661 /// \brief The source range that covers this part of the designator.
1662 SourceRange Range;
1663
1664 /// \brief The data describing the designator, which comes in three
1665 /// different forms, depending on the lower two bits.
1666 /// - An unsigned index into the array of Expr*'s stored after this node
1667 /// in memory, for [constant-expression] designators.
1668 /// - A FieldDecl*, for references to a known field.
1669 /// - An IdentifierInfo*, for references to a field with a given name
1670 /// when the class type is dependent.
1671 /// - A CXXBaseSpecifier*, for references that look at a field in a
1672 /// base class.
1673 uintptr_t Data;
1674
1675 public:
1676 /// \brief Create an offsetof node that refers to an array element.
OffsetOfNode(SourceLocation LBracketLoc,unsigned Index,SourceLocation RBracketLoc)1677 OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
1678 SourceLocation RBracketLoc)
1679 : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
1680
1681 /// \brief Create an offsetof node that refers to a field.
OffsetOfNode(SourceLocation DotLoc,FieldDecl * Field,SourceLocation NameLoc)1682 OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
1683 SourceLocation NameLoc)
1684 : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
1685 Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
1686
1687 /// \brief Create an offsetof node that refers to an identifier.
OffsetOfNode(SourceLocation DotLoc,IdentifierInfo * Name,SourceLocation NameLoc)1688 OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
1689 SourceLocation NameLoc)
1690 : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
1691 Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
1692
1693 /// \brief Create an offsetof node that refers into a C++ base class.
OffsetOfNode(const CXXBaseSpecifier * Base)1694 explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1695 : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1696
1697 /// \brief Determine what kind of offsetof node this is.
getKind()1698 Kind getKind() const {
1699 return static_cast<Kind>(Data & Mask);
1700 }
1701
1702 /// \brief For an array element node, returns the index into the array
1703 /// of expressions.
getArrayExprIndex()1704 unsigned getArrayExprIndex() const {
1705 assert(getKind() == Array);
1706 return Data >> 2;
1707 }
1708
1709 /// \brief For a field offsetof node, returns the field.
getField()1710 FieldDecl *getField() const {
1711 assert(getKind() == Field);
1712 return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
1713 }
1714
1715 /// \brief For a field or identifier offsetof node, returns the name of
1716 /// the field.
1717 IdentifierInfo *getFieldName() const;
1718
1719 /// \brief For a base class node, returns the base specifier.
getBase()1720 CXXBaseSpecifier *getBase() const {
1721 assert(getKind() == Base);
1722 return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
1723 }
1724
1725 /// \brief Retrieve the source range that covers this offsetof node.
1726 ///
1727 /// For an array element node, the source range contains the locations of
1728 /// the square brackets. For a field or identifier node, the source range
1729 /// contains the location of the period (if there is one) and the
1730 /// identifier.
getSourceRange()1731 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
1732 };
1733
1734 private:
1735
1736 SourceLocation OperatorLoc, RParenLoc;
1737 // Base type;
1738 TypeSourceInfo *TSInfo;
1739 // Number of sub-components (i.e. instances of OffsetOfNode).
1740 unsigned NumComps;
1741 // Number of sub-expressions (i.e. array subscript expressions).
1742 unsigned NumExprs;
1743
1744 OffsetOfExpr(ASTContext &C, QualType type,
1745 SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1746 OffsetOfNode* compsPtr, unsigned numComps,
1747 Expr** exprsPtr, unsigned numExprs,
1748 SourceLocation RParenLoc);
1749
OffsetOfExpr(unsigned numComps,unsigned numExprs)1750 explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
1751 : Expr(OffsetOfExprClass, EmptyShell()),
1752 TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
1753
1754 public:
1755
1756 static OffsetOfExpr *Create(ASTContext &C, QualType type,
1757 SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1758 OffsetOfNode* compsPtr, unsigned numComps,
1759 Expr** exprsPtr, unsigned numExprs,
1760 SourceLocation RParenLoc);
1761
1762 static OffsetOfExpr *CreateEmpty(ASTContext &C,
1763 unsigned NumComps, unsigned NumExprs);
1764
1765 /// getOperatorLoc - Return the location of the operator.
getOperatorLoc()1766 SourceLocation getOperatorLoc() const { return OperatorLoc; }
setOperatorLoc(SourceLocation L)1767 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1768
1769 /// \brief Return the location of the right parentheses.
getRParenLoc()1770 SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation R)1771 void setRParenLoc(SourceLocation R) { RParenLoc = R; }
1772
getTypeSourceInfo()1773 TypeSourceInfo *getTypeSourceInfo() const {
1774 return TSInfo;
1775 }
setTypeSourceInfo(TypeSourceInfo * tsi)1776 void setTypeSourceInfo(TypeSourceInfo *tsi) {
1777 TSInfo = tsi;
1778 }
1779
getComponent(unsigned Idx)1780 const OffsetOfNode &getComponent(unsigned Idx) const {
1781 assert(Idx < NumComps && "Subscript out of range");
1782 return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx];
1783 }
1784
setComponent(unsigned Idx,OffsetOfNode ON)1785 void setComponent(unsigned Idx, OffsetOfNode ON) {
1786 assert(Idx < NumComps && "Subscript out of range");
1787 reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
1788 }
1789
getNumComponents()1790 unsigned getNumComponents() const {
1791 return NumComps;
1792 }
1793
getIndexExpr(unsigned Idx)1794 Expr* getIndexExpr(unsigned Idx) {
1795 assert(Idx < NumExprs && "Subscript out of range");
1796 return reinterpret_cast<Expr **>(
1797 reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
1798 }
getIndexExpr(unsigned Idx)1799 const Expr *getIndexExpr(unsigned Idx) const {
1800 return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx);
1801 }
1802
setIndexExpr(unsigned Idx,Expr * E)1803 void setIndexExpr(unsigned Idx, Expr* E) {
1804 assert(Idx < NumComps && "Subscript out of range");
1805 reinterpret_cast<Expr **>(
1806 reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
1807 }
1808
getNumExpressions()1809 unsigned getNumExpressions() const {
1810 return NumExprs;
1811 }
1812
getSourceRange()1813 SourceRange getSourceRange() const LLVM_READONLY {
1814 return SourceRange(OperatorLoc, RParenLoc);
1815 }
1816
classof(const Stmt * T)1817 static bool classof(const Stmt *T) {
1818 return T->getStmtClass() == OffsetOfExprClass;
1819 }
1820
classof(const OffsetOfExpr *)1821 static bool classof(const OffsetOfExpr *) { return true; }
1822
1823 // Iterators
children()1824 child_range children() {
1825 Stmt **begin =
1826 reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1)
1827 + NumComps);
1828 return child_range(begin, begin + NumExprs);
1829 }
1830 };
1831
1832 /// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
1833 /// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and
1834 /// vec_step (OpenCL 1.1 6.11.12).
1835 class UnaryExprOrTypeTraitExpr : public Expr {
1836 union {
1837 TypeSourceInfo *Ty;
1838 Stmt *Ex;
1839 } Argument;
1840 SourceLocation OpLoc, RParenLoc;
1841
1842 public:
UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind,TypeSourceInfo * TInfo,QualType resultType,SourceLocation op,SourceLocation rp)1843 UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
1844 QualType resultType, SourceLocation op,
1845 SourceLocation rp) :
1846 Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1847 false, // Never type-dependent (C++ [temp.dep.expr]p3).
1848 // Value-dependent if the argument is type-dependent.
1849 TInfo->getType()->isDependentType(),
1850 TInfo->getType()->isInstantiationDependentType(),
1851 TInfo->getType()->containsUnexpandedParameterPack()),
1852 OpLoc(op), RParenLoc(rp) {
1853 UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1854 UnaryExprOrTypeTraitExprBits.IsType = true;
1855 Argument.Ty = TInfo;
1856 }
1857
UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind,Expr * E,QualType resultType,SourceLocation op,SourceLocation rp)1858 UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
1859 QualType resultType, SourceLocation op,
1860 SourceLocation rp) :
1861 Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1862 false, // Never type-dependent (C++ [temp.dep.expr]p3).
1863 // Value-dependent if the argument is type-dependent.
1864 E->isTypeDependent(),
1865 E->isInstantiationDependent(),
1866 E->containsUnexpandedParameterPack()),
1867 OpLoc(op), RParenLoc(rp) {
1868 UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1869 UnaryExprOrTypeTraitExprBits.IsType = false;
1870 Argument.Ex = E;
1871 }
1872
1873 /// \brief Construct an empty sizeof/alignof expression.
UnaryExprOrTypeTraitExpr(EmptyShell Empty)1874 explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty)
1875 : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
1876
getKind()1877 UnaryExprOrTypeTrait getKind() const {
1878 return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
1879 }
setKind(UnaryExprOrTypeTrait K)1880 void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;}
1881
isArgumentType()1882 bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
getArgumentType()1883 QualType getArgumentType() const {
1884 return getArgumentTypeInfo()->getType();
1885 }
getArgumentTypeInfo()1886 TypeSourceInfo *getArgumentTypeInfo() const {
1887 assert(isArgumentType() && "calling getArgumentType() when arg is expr");
1888 return Argument.Ty;
1889 }
getArgumentExpr()1890 Expr *getArgumentExpr() {
1891 assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1892 return static_cast<Expr*>(Argument.Ex);
1893 }
getArgumentExpr()1894 const Expr *getArgumentExpr() const {
1895 return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
1896 }
1897
setArgument(Expr * E)1898 void setArgument(Expr *E) {
1899 Argument.Ex = E;
1900 UnaryExprOrTypeTraitExprBits.IsType = false;
1901 }
setArgument(TypeSourceInfo * TInfo)1902 void setArgument(TypeSourceInfo *TInfo) {
1903 Argument.Ty = TInfo;
1904 UnaryExprOrTypeTraitExprBits.IsType = true;
1905 }
1906
1907 /// Gets the argument type, or the type of the argument expression, whichever
1908 /// is appropriate.
getTypeOfArgument()1909 QualType getTypeOfArgument() const {
1910 return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
1911 }
1912
getOperatorLoc()1913 SourceLocation getOperatorLoc() const { return OpLoc; }
setOperatorLoc(SourceLocation L)1914 void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1915
getRParenLoc()1916 SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)1917 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1918
getSourceRange()1919 SourceRange getSourceRange() const LLVM_READONLY {
1920 return SourceRange(OpLoc, RParenLoc);
1921 }
1922
classof(const Stmt * T)1923 static bool classof(const Stmt *T) {
1924 return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
1925 }
classof(const UnaryExprOrTypeTraitExpr *)1926 static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; }
1927
1928 // Iterators
1929 child_range children();
1930 };
1931
1932 //===----------------------------------------------------------------------===//
1933 // Postfix Operators.
1934 //===----------------------------------------------------------------------===//
1935
1936 /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
1937 class ArraySubscriptExpr : public Expr {
1938 enum { LHS, RHS, END_EXPR=2 };
1939 Stmt* SubExprs[END_EXPR];
1940 SourceLocation RBracketLoc;
1941 public:
ArraySubscriptExpr(Expr * lhs,Expr * rhs,QualType t,ExprValueKind VK,ExprObjectKind OK,SourceLocation rbracketloc)1942 ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
1943 ExprValueKind VK, ExprObjectKind OK,
1944 SourceLocation rbracketloc)
1945 : Expr(ArraySubscriptExprClass, t, VK, OK,
1946 lhs->isTypeDependent() || rhs->isTypeDependent(),
1947 lhs->isValueDependent() || rhs->isValueDependent(),
1948 (lhs->isInstantiationDependent() ||
1949 rhs->isInstantiationDependent()),
1950 (lhs->containsUnexpandedParameterPack() ||
1951 rhs->containsUnexpandedParameterPack())),
1952 RBracketLoc(rbracketloc) {
1953 SubExprs[LHS] = lhs;
1954 SubExprs[RHS] = rhs;
1955 }
1956
1957 /// \brief Create an empty array subscript expression.
ArraySubscriptExpr(EmptyShell Shell)1958 explicit ArraySubscriptExpr(EmptyShell Shell)
1959 : Expr(ArraySubscriptExprClass, Shell) { }
1960
1961 /// An array access can be written A[4] or 4[A] (both are equivalent).
1962 /// - getBase() and getIdx() always present the normalized view: A[4].
1963 /// In this case getBase() returns "A" and getIdx() returns "4".
1964 /// - getLHS() and getRHS() present the syntactic view. e.g. for
1965 /// 4[A] getLHS() returns "4".
1966 /// Note: Because vector element access is also written A[4] we must
1967 /// predicate the format conversion in getBase and getIdx only on the
1968 /// the type of the RHS, as it is possible for the LHS to be a vector of
1969 /// integer type
getLHS()1970 Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
getLHS()1971 const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
setLHS(Expr * E)1972 void setLHS(Expr *E) { SubExprs[LHS] = E; }
1973
getRHS()1974 Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
getRHS()1975 const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
setRHS(Expr * E)1976 void setRHS(Expr *E) { SubExprs[RHS] = E; }
1977
getBase()1978 Expr *getBase() {
1979 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1980 }
1981
getBase()1982 const Expr *getBase() const {
1983 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1984 }
1985
getIdx()1986 Expr *getIdx() {
1987 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1988 }
1989
getIdx()1990 const Expr *getIdx() const {
1991 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1992 }
1993
getSourceRange()1994 SourceRange getSourceRange() const LLVM_READONLY {
1995 return SourceRange(getLHS()->getLocStart(), RBracketLoc);
1996 }
1997
getRBracketLoc()1998 SourceLocation getRBracketLoc() const { return RBracketLoc; }
setRBracketLoc(SourceLocation L)1999 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
2000
getExprLoc()2001 SourceLocation getExprLoc() const LLVM_READONLY { return getBase()->getExprLoc(); }
2002
classof(const Stmt * T)2003 static bool classof(const Stmt *T) {
2004 return T->getStmtClass() == ArraySubscriptExprClass;
2005 }
classof(const ArraySubscriptExpr *)2006 static bool classof(const ArraySubscriptExpr *) { return true; }
2007
2008 // Iterators
children()2009 child_range children() {
2010 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2011 }
2012 };
2013
2014
2015 /// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2016 /// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2017 /// while its subclasses may represent alternative syntax that (semantically)
2018 /// results in a function call. For example, CXXOperatorCallExpr is
2019 /// a subclass for overloaded operator calls that use operator syntax, e.g.,
2020 /// "str1 + str2" to resolve to a function call.
2021 class CallExpr : public Expr {
2022 enum { FN=0, PREARGS_START=1 };
2023 Stmt **SubExprs;
2024 unsigned NumArgs;
2025 SourceLocation RParenLoc;
2026
2027 protected:
2028 // These versions of the constructor are for derived classes.
2029 CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs,
2030 Expr **args, unsigned numargs, QualType t, ExprValueKind VK,
2031 SourceLocation rparenloc);
2032 CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty);
2033
getPreArg(unsigned i)2034 Stmt *getPreArg(unsigned i) {
2035 assert(i < getNumPreArgs() && "Prearg access out of range!");
2036 return SubExprs[PREARGS_START+i];
2037 }
getPreArg(unsigned i)2038 const Stmt *getPreArg(unsigned i) const {
2039 assert(i < getNumPreArgs() && "Prearg access out of range!");
2040 return SubExprs[PREARGS_START+i];
2041 }
setPreArg(unsigned i,Stmt * PreArg)2042 void setPreArg(unsigned i, Stmt *PreArg) {
2043 assert(i < getNumPreArgs() && "Prearg access out of range!");
2044 SubExprs[PREARGS_START+i] = PreArg;
2045 }
2046
getNumPreArgs()2047 unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
2048
2049 public:
2050 CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
2051 ExprValueKind VK, SourceLocation rparenloc);
2052
2053 /// \brief Build an empty call expression.
2054 CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
2055
getCallee()2056 const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
getCallee()2057 Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
setCallee(Expr * F)2058 void setCallee(Expr *F) { SubExprs[FN] = F; }
2059
2060 Decl *getCalleeDecl();
getCalleeDecl()2061 const Decl *getCalleeDecl() const {
2062 return const_cast<CallExpr*>(this)->getCalleeDecl();
2063 }
2064
2065 /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
2066 FunctionDecl *getDirectCallee();
getDirectCallee()2067 const FunctionDecl *getDirectCallee() const {
2068 return const_cast<CallExpr*>(this)->getDirectCallee();
2069 }
2070
2071 /// getNumArgs - Return the number of actual arguments to this call.
2072 ///
getNumArgs()2073 unsigned getNumArgs() const { return NumArgs; }
2074
2075 /// \brief Retrieve the call arguments.
getArgs()2076 Expr **getArgs() {
2077 return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START);
2078 }
getArgs()2079 const Expr *const *getArgs() const {
2080 return const_cast<CallExpr*>(this)->getArgs();
2081 }
2082
2083 /// getArg - Return the specified argument.
getArg(unsigned Arg)2084 Expr *getArg(unsigned Arg) {
2085 assert(Arg < NumArgs && "Arg access out of range!");
2086 return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
2087 }
getArg(unsigned Arg)2088 const Expr *getArg(unsigned Arg) const {
2089 assert(Arg < NumArgs && "Arg access out of range!");
2090 return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
2091 }
2092
2093 /// setArg - Set the specified argument.
setArg(unsigned Arg,Expr * ArgExpr)2094 void setArg(unsigned Arg, Expr *ArgExpr) {
2095 assert(Arg < NumArgs && "Arg access out of range!");
2096 SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr;
2097 }
2098
2099 /// setNumArgs - This changes the number of arguments present in this call.
2100 /// Any orphaned expressions are deleted by this, and any new operands are set
2101 /// to null.
2102 void setNumArgs(ASTContext& C, unsigned NumArgs);
2103
2104 typedef ExprIterator arg_iterator;
2105 typedef ConstExprIterator const_arg_iterator;
2106
arg_begin()2107 arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); }
arg_end()2108 arg_iterator arg_end() {
2109 return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2110 }
arg_begin()2111 const_arg_iterator arg_begin() const {
2112 return SubExprs+PREARGS_START+getNumPreArgs();
2113 }
arg_end()2114 const_arg_iterator arg_end() const {
2115 return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2116 }
2117
2118 /// getNumCommas - Return the number of commas that must have been present in
2119 /// this function call.
getNumCommas()2120 unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
2121
2122 /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If
2123 /// not, return 0.
2124 unsigned isBuiltinCall() const;
2125
2126 /// getCallReturnType - Get the return type of the call expr. This is not
2127 /// always the type of the expr itself, if the return type is a reference
2128 /// type.
2129 QualType getCallReturnType() const;
2130
getRParenLoc()2131 SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)2132 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2133
2134 SourceRange getSourceRange() const LLVM_READONLY;
2135 SourceLocation getLocStart() const LLVM_READONLY;
2136 SourceLocation getLocEnd() const LLVM_READONLY;
2137
classof(const Stmt * T)2138 static bool classof(const Stmt *T) {
2139 return T->getStmtClass() >= firstCallExprConstant &&
2140 T->getStmtClass() <= lastCallExprConstant;
2141 }
classof(const CallExpr *)2142 static bool classof(const CallExpr *) { return true; }
2143
2144 // Iterators
children()2145 child_range children() {
2146 return child_range(&SubExprs[0],
2147 &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START);
2148 }
2149 };
2150
2151 /// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F.
2152 ///
2153 class MemberExpr : public Expr {
2154 /// Extra data stored in some member expressions.
2155 struct MemberNameQualifier {
2156 /// \brief The nested-name-specifier that qualifies the name, including
2157 /// source-location information.
2158 NestedNameSpecifierLoc QualifierLoc;
2159
2160 /// \brief The DeclAccessPair through which the MemberDecl was found due to
2161 /// name qualifiers.
2162 DeclAccessPair FoundDecl;
2163 };
2164
2165 /// Base - the expression for the base pointer or structure references. In
2166 /// X.F, this is "X".
2167 Stmt *Base;
2168
2169 /// MemberDecl - This is the decl being referenced by the field/member name.
2170 /// In X.F, this is the decl referenced by F.
2171 ValueDecl *MemberDecl;
2172
2173 /// MemberDNLoc - Provides source/type location info for the
2174 /// declaration name embedded in MemberDecl.
2175 DeclarationNameLoc MemberDNLoc;
2176
2177 /// MemberLoc - This is the location of the member name.
2178 SourceLocation MemberLoc;
2179
2180 /// IsArrow - True if this is "X->F", false if this is "X.F".
2181 bool IsArrow : 1;
2182
2183 /// \brief True if this member expression used a nested-name-specifier to
2184 /// refer to the member, e.g., "x->Base::f", or found its member via a using
2185 /// declaration. When true, a MemberNameQualifier
2186 /// structure is allocated immediately after the MemberExpr.
2187 bool HasQualifierOrFoundDecl : 1;
2188
2189 /// \brief True if this member expression specified a template keyword
2190 /// and/or a template argument list explicitly, e.g., x->f<int>,
2191 /// x->template f, x->template f<int>.
2192 /// When true, an ASTTemplateKWAndArgsInfo structure and its
2193 /// TemplateArguments (if any) are allocated immediately after
2194 /// the MemberExpr or, if the member expression also has a qualifier,
2195 /// after the MemberNameQualifier structure.
2196 bool HasTemplateKWAndArgsInfo : 1;
2197
2198 /// \brief True if this member expression refers to a method that
2199 /// was resolved from an overloaded set having size greater than 1.
2200 bool HadMultipleCandidates : 1;
2201
2202 /// \brief Retrieve the qualifier that preceded the member name, if any.
getMemberQualifier()2203 MemberNameQualifier *getMemberQualifier() {
2204 assert(HasQualifierOrFoundDecl);
2205 return reinterpret_cast<MemberNameQualifier *> (this + 1);
2206 }
2207
2208 /// \brief Retrieve the qualifier that preceded the member name, if any.
getMemberQualifier()2209 const MemberNameQualifier *getMemberQualifier() const {
2210 return const_cast<MemberExpr *>(this)->getMemberQualifier();
2211 }
2212
2213 public:
MemberExpr(Expr * base,bool isarrow,ValueDecl * memberdecl,const DeclarationNameInfo & NameInfo,QualType ty,ExprValueKind VK,ExprObjectKind OK)2214 MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
2215 const DeclarationNameInfo &NameInfo, QualType ty,
2216 ExprValueKind VK, ExprObjectKind OK)
2217 : Expr(MemberExprClass, ty, VK, OK,
2218 base->isTypeDependent(),
2219 base->isValueDependent(),
2220 base->isInstantiationDependent(),
2221 base->containsUnexpandedParameterPack()),
2222 Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()),
2223 MemberLoc(NameInfo.getLoc()), IsArrow(isarrow),
2224 HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
2225 HadMultipleCandidates(false) {
2226 assert(memberdecl->getDeclName() == NameInfo.getName());
2227 }
2228
2229 // NOTE: this constructor should be used only when it is known that
2230 // the member name can not provide additional syntactic info
2231 // (i.e., source locations for C++ operator names or type source info
2232 // for constructors, destructors and conversion operators).
MemberExpr(Expr * base,bool isarrow,ValueDecl * memberdecl,SourceLocation l,QualType ty,ExprValueKind VK,ExprObjectKind OK)2233 MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
2234 SourceLocation l, QualType ty,
2235 ExprValueKind VK, ExprObjectKind OK)
2236 : Expr(MemberExprClass, ty, VK, OK,
2237 base->isTypeDependent(), base->isValueDependent(),
2238 base->isInstantiationDependent(),
2239 base->containsUnexpandedParameterPack()),
2240 Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l),
2241 IsArrow(isarrow),
2242 HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
2243 HadMultipleCandidates(false) {}
2244
2245 static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
2246 NestedNameSpecifierLoc QualifierLoc,
2247 SourceLocation TemplateKWLoc,
2248 ValueDecl *memberdecl, DeclAccessPair founddecl,
2249 DeclarationNameInfo MemberNameInfo,
2250 const TemplateArgumentListInfo *targs,
2251 QualType ty, ExprValueKind VK, ExprObjectKind OK);
2252
setBase(Expr * E)2253 void setBase(Expr *E) { Base = E; }
getBase()2254 Expr *getBase() const { return cast<Expr>(Base); }
2255
2256 /// \brief Retrieve the member declaration to which this expression refers.
2257 ///
2258 /// The returned declaration will either be a FieldDecl or (in C++)
2259 /// a CXXMethodDecl.
getMemberDecl()2260 ValueDecl *getMemberDecl() const { return MemberDecl; }
setMemberDecl(ValueDecl * D)2261 void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
2262
2263 /// \brief Retrieves the declaration found by lookup.
getFoundDecl()2264 DeclAccessPair getFoundDecl() const {
2265 if (!HasQualifierOrFoundDecl)
2266 return DeclAccessPair::make(getMemberDecl(),
2267 getMemberDecl()->getAccess());
2268 return getMemberQualifier()->FoundDecl;
2269 }
2270
2271 /// \brief Determines whether this member expression actually had
2272 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2273 /// x->Base::foo.
hasQualifier()2274 bool hasQualifier() const { return getQualifier() != 0; }
2275
2276 /// \brief If the member name was qualified, retrieves the
2277 /// nested-name-specifier that precedes the member name. Otherwise, returns
2278 /// NULL.
getQualifier()2279 NestedNameSpecifier *getQualifier() const {
2280 if (!HasQualifierOrFoundDecl)
2281 return 0;
2282
2283 return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier();
2284 }
2285
2286 /// \brief If the member name was qualified, retrieves the
2287 /// nested-name-specifier that precedes the member name, with source-location
2288 /// information.
getQualifierLoc()2289 NestedNameSpecifierLoc getQualifierLoc() const {
2290 if (!hasQualifier())
2291 return NestedNameSpecifierLoc();
2292
2293 return getMemberQualifier()->QualifierLoc;
2294 }
2295
2296 /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2297 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2298 if (!HasTemplateKWAndArgsInfo)
2299 return 0;
2300
2301 if (!HasQualifierOrFoundDecl)
2302 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1);
2303
2304 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
2305 getMemberQualifier() + 1);
2306 }
2307
2308 /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2309 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2310 return const_cast<MemberExpr*>(this)->getTemplateKWAndArgsInfo();
2311 }
2312
2313 /// \brief Retrieve the location of the template keyword preceding
2314 /// the member name, if any.
getTemplateKeywordLoc()2315 SourceLocation getTemplateKeywordLoc() const {
2316 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2317 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2318 }
2319
2320 /// \brief Retrieve the location of the left angle bracket starting the
2321 /// explicit template argument list following the member name, if any.
getLAngleLoc()2322 SourceLocation getLAngleLoc() const {
2323 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2324 return getTemplateKWAndArgsInfo()->LAngleLoc;
2325 }
2326
2327 /// \brief Retrieve the location of the right angle bracket ending the
2328 /// explicit template argument list following the member name, if any.
getRAngleLoc()2329 SourceLocation getRAngleLoc() const {
2330 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2331 return getTemplateKWAndArgsInfo()->RAngleLoc;
2332 }
2333
2334 /// Determines whether the member name was preceded by the template keyword.
hasTemplateKeyword()2335 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2336
2337 /// \brief Determines whether the member name was followed by an
2338 /// explicit template argument list.
hasExplicitTemplateArgs()2339 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2340
2341 /// \brief Copies the template arguments (if present) into the given
2342 /// structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)2343 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2344 if (hasExplicitTemplateArgs())
2345 getExplicitTemplateArgs().copyInto(List);
2346 }
2347
2348 /// \brief Retrieve the explicit template argument list that
2349 /// follow the member template name. This must only be called on an
2350 /// expression with explicit template arguments.
getExplicitTemplateArgs()2351 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2352 assert(hasExplicitTemplateArgs());
2353 return *getTemplateKWAndArgsInfo();
2354 }
2355
2356 /// \brief Retrieve the explicit template argument list that
2357 /// followed the member template name. This must only be called on
2358 /// an expression with explicit template arguments.
getExplicitTemplateArgs()2359 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2360 return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs();
2361 }
2362
2363 /// \brief Retrieves the optional explicit template arguments.
2364 /// This points to the same data as getExplicitTemplateArgs(), but
2365 /// returns null if there are no explicit template arguments.
getOptionalExplicitTemplateArgs()2366 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2367 if (!hasExplicitTemplateArgs()) return 0;
2368 return &getExplicitTemplateArgs();
2369 }
2370
2371 /// \brief Retrieve the template arguments provided as part of this
2372 /// template-id.
getTemplateArgs()2373 const TemplateArgumentLoc *getTemplateArgs() const {
2374 if (!hasExplicitTemplateArgs())
2375 return 0;
2376
2377 return getExplicitTemplateArgs().getTemplateArgs();
2378 }
2379
2380 /// \brief Retrieve the number of template arguments provided as part of this
2381 /// template-id.
getNumTemplateArgs()2382 unsigned getNumTemplateArgs() const {
2383 if (!hasExplicitTemplateArgs())
2384 return 0;
2385
2386 return getExplicitTemplateArgs().NumTemplateArgs;
2387 }
2388
2389 /// \brief Retrieve the member declaration name info.
getMemberNameInfo()2390 DeclarationNameInfo getMemberNameInfo() const {
2391 return DeclarationNameInfo(MemberDecl->getDeclName(),
2392 MemberLoc, MemberDNLoc);
2393 }
2394
isArrow()2395 bool isArrow() const { return IsArrow; }
setArrow(bool A)2396 void setArrow(bool A) { IsArrow = A; }
2397
2398 /// getMemberLoc - Return the location of the "member", in X->F, it is the
2399 /// location of 'F'.
getMemberLoc()2400 SourceLocation getMemberLoc() const { return MemberLoc; }
setMemberLoc(SourceLocation L)2401 void setMemberLoc(SourceLocation L) { MemberLoc = L; }
2402
2403 SourceRange getSourceRange() const LLVM_READONLY;
2404 SourceLocation getLocStart() const LLVM_READONLY;
2405 SourceLocation getLocEnd() const LLVM_READONLY;
2406
getExprLoc()2407 SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
2408
2409 /// \brief Determine whether the base of this explicit is implicit.
isImplicitAccess()2410 bool isImplicitAccess() const {
2411 return getBase() && getBase()->isImplicitCXXThis();
2412 }
2413
2414 /// \brief Returns true if this member expression refers to a method that
2415 /// was resolved from an overloaded set having size greater than 1.
hadMultipleCandidates()2416 bool hadMultipleCandidates() const {
2417 return HadMultipleCandidates;
2418 }
2419 /// \brief Sets the flag telling whether this expression refers to
2420 /// a method that was resolved from an overloaded set having size
2421 /// greater than 1.
2422 void setHadMultipleCandidates(bool V = true) {
2423 HadMultipleCandidates = V;
2424 }
2425
classof(const Stmt * T)2426 static bool classof(const Stmt *T) {
2427 return T->getStmtClass() == MemberExprClass;
2428 }
classof(const MemberExpr *)2429 static bool classof(const MemberExpr *) { return true; }
2430
2431 // Iterators
children()2432 child_range children() { return child_range(&Base, &Base+1); }
2433
2434 friend class ASTReader;
2435 friend class ASTStmtWriter;
2436 };
2437
2438 /// CompoundLiteralExpr - [C99 6.5.2.5]
2439 ///
2440 class CompoundLiteralExpr : public Expr {
2441 /// LParenLoc - If non-null, this is the location of the left paren in a
2442 /// compound literal like "(int){4}". This can be null if this is a
2443 /// synthesized compound expression.
2444 SourceLocation LParenLoc;
2445
2446 /// The type as written. This can be an incomplete array type, in
2447 /// which case the actual expression type will be different.
2448 /// The int part of the pair stores whether this expr is file scope.
2449 llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
2450 Stmt *Init;
2451 public:
CompoundLiteralExpr(SourceLocation lparenloc,TypeSourceInfo * tinfo,QualType T,ExprValueKind VK,Expr * init,bool fileScope)2452 CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
2453 QualType T, ExprValueKind VK, Expr *init, bool fileScope)
2454 : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
2455 tinfo->getType()->isDependentType(),
2456 init->isValueDependent(),
2457 (init->isInstantiationDependent() ||
2458 tinfo->getType()->isInstantiationDependentType()),
2459 init->containsUnexpandedParameterPack()),
2460 LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {}
2461
2462 /// \brief Construct an empty compound literal.
CompoundLiteralExpr(EmptyShell Empty)2463 explicit CompoundLiteralExpr(EmptyShell Empty)
2464 : Expr(CompoundLiteralExprClass, Empty) { }
2465
getInitializer()2466 const Expr *getInitializer() const { return cast<Expr>(Init); }
getInitializer()2467 Expr *getInitializer() { return cast<Expr>(Init); }
setInitializer(Expr * E)2468 void setInitializer(Expr *E) { Init = E; }
2469
isFileScope()2470 bool isFileScope() const { return TInfoAndScope.getInt(); }
setFileScope(bool FS)2471 void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
2472
getLParenLoc()2473 SourceLocation getLParenLoc() const { return LParenLoc; }
setLParenLoc(SourceLocation L)2474 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2475
getTypeSourceInfo()2476 TypeSourceInfo *getTypeSourceInfo() const {
2477 return TInfoAndScope.getPointer();
2478 }
setTypeSourceInfo(TypeSourceInfo * tinfo)2479 void setTypeSourceInfo(TypeSourceInfo *tinfo) {
2480 TInfoAndScope.setPointer(tinfo);
2481 }
2482
getSourceRange()2483 SourceRange getSourceRange() const LLVM_READONLY {
2484 // FIXME: Init should never be null.
2485 if (!Init)
2486 return SourceRange();
2487 if (LParenLoc.isInvalid())
2488 return Init->getSourceRange();
2489 return SourceRange(LParenLoc, Init->getLocEnd());
2490 }
2491
classof(const Stmt * T)2492 static bool classof(const Stmt *T) {
2493 return T->getStmtClass() == CompoundLiteralExprClass;
2494 }
classof(const CompoundLiteralExpr *)2495 static bool classof(const CompoundLiteralExpr *) { return true; }
2496
2497 // Iterators
children()2498 child_range children() { return child_range(&Init, &Init+1); }
2499 };
2500
2501 /// CastExpr - Base class for type casts, including both implicit
2502 /// casts (ImplicitCastExpr) and explicit casts that have some
2503 /// representation in the source code (ExplicitCastExpr's derived
2504 /// classes).
2505 class CastExpr : public Expr {
2506 public:
2507 typedef clang::CastKind CastKind;
2508
2509 private:
2510 Stmt *Op;
2511
2512 void CheckCastConsistency() const;
2513
path_buffer()2514 const CXXBaseSpecifier * const *path_buffer() const {
2515 return const_cast<CastExpr*>(this)->path_buffer();
2516 }
2517 CXXBaseSpecifier **path_buffer();
2518
setBasePathSize(unsigned basePathSize)2519 void setBasePathSize(unsigned basePathSize) {
2520 CastExprBits.BasePathSize = basePathSize;
2521 assert(CastExprBits.BasePathSize == basePathSize &&
2522 "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!");
2523 }
2524
2525 protected:
CastExpr(StmtClass SC,QualType ty,ExprValueKind VK,const CastKind kind,Expr * op,unsigned BasePathSize)2526 CastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
2527 const CastKind kind, Expr *op, unsigned BasePathSize) :
2528 Expr(SC, ty, VK, OK_Ordinary,
2529 // Cast expressions are type-dependent if the type is
2530 // dependent (C++ [temp.dep.expr]p3).
2531 ty->isDependentType(),
2532 // Cast expressions are value-dependent if the type is
2533 // dependent or if the subexpression is value-dependent.
2534 ty->isDependentType() || (op && op->isValueDependent()),
2535 (ty->isInstantiationDependentType() ||
2536 (op && op->isInstantiationDependent())),
2537 (ty->containsUnexpandedParameterPack() ||
2538 op->containsUnexpandedParameterPack())),
2539 Op(op) {
2540 assert(kind != CK_Invalid && "creating cast with invalid cast kind");
2541 CastExprBits.Kind = kind;
2542 setBasePathSize(BasePathSize);
2543 #ifndef NDEBUG
2544 CheckCastConsistency();
2545 #endif
2546 }
2547
2548 /// \brief Construct an empty cast.
CastExpr(StmtClass SC,EmptyShell Empty,unsigned BasePathSize)2549 CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
2550 : Expr(SC, Empty) {
2551 setBasePathSize(BasePathSize);
2552 }
2553
2554 public:
getCastKind()2555 CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
setCastKind(CastKind K)2556 void setCastKind(CastKind K) { CastExprBits.Kind = K; }
2557 const char *getCastKindName() const;
2558
getSubExpr()2559 Expr *getSubExpr() { return cast<Expr>(Op); }
getSubExpr()2560 const Expr *getSubExpr() const { return cast<Expr>(Op); }
setSubExpr(Expr * E)2561 void setSubExpr(Expr *E) { Op = E; }
2562
2563 /// \brief Retrieve the cast subexpression as it was written in the source
2564 /// code, looking through any implicit casts or other intermediate nodes
2565 /// introduced by semantic analysis.
2566 Expr *getSubExprAsWritten();
getSubExprAsWritten()2567 const Expr *getSubExprAsWritten() const {
2568 return const_cast<CastExpr *>(this)->getSubExprAsWritten();
2569 }
2570
2571 typedef CXXBaseSpecifier **path_iterator;
2572 typedef const CXXBaseSpecifier * const *path_const_iterator;
path_empty()2573 bool path_empty() const { return CastExprBits.BasePathSize == 0; }
path_size()2574 unsigned path_size() const { return CastExprBits.BasePathSize; }
path_begin()2575 path_iterator path_begin() { return path_buffer(); }
path_end()2576 path_iterator path_end() { return path_buffer() + path_size(); }
path_begin()2577 path_const_iterator path_begin() const { return path_buffer(); }
path_end()2578 path_const_iterator path_end() const { return path_buffer() + path_size(); }
2579
2580 void setCastPath(const CXXCastPath &Path);
2581
classof(const Stmt * T)2582 static bool classof(const Stmt *T) {
2583 return T->getStmtClass() >= firstCastExprConstant &&
2584 T->getStmtClass() <= lastCastExprConstant;
2585 }
classof(const CastExpr *)2586 static bool classof(const CastExpr *) { return true; }
2587
2588 // Iterators
children()2589 child_range children() { return child_range(&Op, &Op+1); }
2590 };
2591
2592 /// ImplicitCastExpr - Allows us to explicitly represent implicit type
2593 /// conversions, which have no direct representation in the original
2594 /// source code. For example: converting T[]->T*, void f()->void
2595 /// (*f)(), float->double, short->int, etc.
2596 ///
2597 /// In C, implicit casts always produce rvalues. However, in C++, an
2598 /// implicit cast whose result is being bound to a reference will be
2599 /// an lvalue or xvalue. For example:
2600 ///
2601 /// @code
2602 /// class Base { };
2603 /// class Derived : public Base { };
2604 /// Derived &&ref();
2605 /// void f(Derived d) {
2606 /// Base& b = d; // initializer is an ImplicitCastExpr
2607 /// // to an lvalue of type Base
2608 /// Base&& r = ref(); // initializer is an ImplicitCastExpr
2609 /// // to an xvalue of type Base
2610 /// }
2611 /// @endcode
2612 class ImplicitCastExpr : public CastExpr {
2613 private:
ImplicitCastExpr(QualType ty,CastKind kind,Expr * op,unsigned BasePathLength,ExprValueKind VK)2614 ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
2615 unsigned BasePathLength, ExprValueKind VK)
2616 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) {
2617 }
2618
2619 /// \brief Construct an empty implicit cast.
ImplicitCastExpr(EmptyShell Shell,unsigned PathSize)2620 explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
2621 : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
2622
2623 public:
2624 enum OnStack_t { OnStack };
ImplicitCastExpr(OnStack_t _,QualType ty,CastKind kind,Expr * op,ExprValueKind VK)2625 ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
2626 ExprValueKind VK)
2627 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
2628 }
2629
2630 static ImplicitCastExpr *Create(ASTContext &Context, QualType T,
2631 CastKind Kind, Expr *Operand,
2632 const CXXCastPath *BasePath,
2633 ExprValueKind Cat);
2634
2635 static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2636
getSourceRange()2637 SourceRange getSourceRange() const LLVM_READONLY {
2638 return getSubExpr()->getSourceRange();
2639 }
getLocStart()2640 SourceLocation getLocStart() const LLVM_READONLY {
2641 return getSubExpr()->getLocStart();
2642 }
getLocEnd()2643 SourceLocation getLocEnd() const LLVM_READONLY {
2644 return getSubExpr()->getLocEnd();
2645 }
2646
classof(const Stmt * T)2647 static bool classof(const Stmt *T) {
2648 return T->getStmtClass() == ImplicitCastExprClass;
2649 }
classof(const ImplicitCastExpr *)2650 static bool classof(const ImplicitCastExpr *) { return true; }
2651 };
2652
IgnoreImpCasts()2653 inline Expr *Expr::IgnoreImpCasts() {
2654 Expr *e = this;
2655 while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
2656 e = ice->getSubExpr();
2657 return e;
2658 }
2659
2660 /// ExplicitCastExpr - An explicit cast written in the source
2661 /// code.
2662 ///
2663 /// This class is effectively an abstract class, because it provides
2664 /// the basic representation of an explicitly-written cast without
2665 /// specifying which kind of cast (C cast, functional cast, static
2666 /// cast, etc.) was written; specific derived classes represent the
2667 /// particular style of cast and its location information.
2668 ///
2669 /// Unlike implicit casts, explicit cast nodes have two different
2670 /// types: the type that was written into the source code, and the
2671 /// actual type of the expression as determined by semantic
2672 /// analysis. These types may differ slightly. For example, in C++ one
2673 /// can cast to a reference type, which indicates that the resulting
2674 /// expression will be an lvalue or xvalue. The reference type, however,
2675 /// will not be used as the type of the expression.
2676 class ExplicitCastExpr : public CastExpr {
2677 /// TInfo - Source type info for the (written) type
2678 /// this expression is casting to.
2679 TypeSourceInfo *TInfo;
2680
2681 protected:
ExplicitCastExpr(StmtClass SC,QualType exprTy,ExprValueKind VK,CastKind kind,Expr * op,unsigned PathSize,TypeSourceInfo * writtenTy)2682 ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK,
2683 CastKind kind, Expr *op, unsigned PathSize,
2684 TypeSourceInfo *writtenTy)
2685 : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
2686
2687 /// \brief Construct an empty explicit cast.
ExplicitCastExpr(StmtClass SC,EmptyShell Shell,unsigned PathSize)2688 ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
2689 : CastExpr(SC, Shell, PathSize) { }
2690
2691 public:
2692 /// getTypeInfoAsWritten - Returns the type source info for the type
2693 /// that this expression is casting to.
getTypeInfoAsWritten()2694 TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
setTypeInfoAsWritten(TypeSourceInfo * writtenTy)2695 void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
2696
2697 /// getTypeAsWritten - Returns the type that this expression is
2698 /// casting to, as written in the source code.
getTypeAsWritten()2699 QualType getTypeAsWritten() const { return TInfo->getType(); }
2700
classof(const Stmt * T)2701 static bool classof(const Stmt *T) {
2702 return T->getStmtClass() >= firstExplicitCastExprConstant &&
2703 T->getStmtClass() <= lastExplicitCastExprConstant;
2704 }
classof(const ExplicitCastExpr *)2705 static bool classof(const ExplicitCastExpr *) { return true; }
2706 };
2707
2708 /// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
2709 /// cast in C++ (C++ [expr.cast]), which uses the syntax
2710 /// (Type)expr. For example: @c (int)f.
2711 class CStyleCastExpr : public ExplicitCastExpr {
2712 SourceLocation LPLoc; // the location of the left paren
2713 SourceLocation RPLoc; // the location of the right paren
2714
CStyleCastExpr(QualType exprTy,ExprValueKind vk,CastKind kind,Expr * op,unsigned PathSize,TypeSourceInfo * writtenTy,SourceLocation l,SourceLocation r)2715 CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
2716 unsigned PathSize, TypeSourceInfo *writtenTy,
2717 SourceLocation l, SourceLocation r)
2718 : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
2719 writtenTy), LPLoc(l), RPLoc(r) {}
2720
2721 /// \brief Construct an empty C-style explicit cast.
CStyleCastExpr(EmptyShell Shell,unsigned PathSize)2722 explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
2723 : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
2724
2725 public:
2726 static CStyleCastExpr *Create(ASTContext &Context, QualType T,
2727 ExprValueKind VK, CastKind K,
2728 Expr *Op, const CXXCastPath *BasePath,
2729 TypeSourceInfo *WrittenTy, SourceLocation L,
2730 SourceLocation R);
2731
2732 static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2733
getLParenLoc()2734 SourceLocation getLParenLoc() const { return LPLoc; }
setLParenLoc(SourceLocation L)2735 void setLParenLoc(SourceLocation L) { LPLoc = L; }
2736
getRParenLoc()2737 SourceLocation getRParenLoc() const { return RPLoc; }
setRParenLoc(SourceLocation L)2738 void setRParenLoc(SourceLocation L) { RPLoc = L; }
2739
getSourceRange()2740 SourceRange getSourceRange() const LLVM_READONLY {
2741 return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
2742 }
classof(const Stmt * T)2743 static bool classof(const Stmt *T) {
2744 return T->getStmtClass() == CStyleCastExprClass;
2745 }
classof(const CStyleCastExpr *)2746 static bool classof(const CStyleCastExpr *) { return true; }
2747 };
2748
2749 /// \brief A builtin binary operation expression such as "x + y" or "x <= y".
2750 ///
2751 /// This expression node kind describes a builtin binary operation,
2752 /// such as "x + y" for integer values "x" and "y". The operands will
2753 /// already have been converted to appropriate types (e.g., by
2754 /// performing promotions or conversions).
2755 ///
2756 /// In C++, where operators may be overloaded, a different kind of
2757 /// expression node (CXXOperatorCallExpr) is used to express the
2758 /// invocation of an overloaded operator with operator syntax. Within
2759 /// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
2760 /// used to store an expression "x + y" depends on the subexpressions
2761 /// for x and y. If neither x or y is type-dependent, and the "+"
2762 /// operator resolves to a built-in operation, BinaryOperator will be
2763 /// used to express the computation (x and y may still be
2764 /// value-dependent). If either x or y is type-dependent, or if the
2765 /// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
2766 /// be used to express the computation.
2767 class BinaryOperator : public Expr {
2768 public:
2769 typedef BinaryOperatorKind Opcode;
2770
2771 private:
2772 unsigned Opc : 6;
2773 SourceLocation OpLoc;
2774
2775 enum { LHS, RHS, END_EXPR };
2776 Stmt* SubExprs[END_EXPR];
2777 public:
2778
BinaryOperator(Expr * lhs,Expr * rhs,Opcode opc,QualType ResTy,ExprValueKind VK,ExprObjectKind OK,SourceLocation opLoc)2779 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2780 ExprValueKind VK, ExprObjectKind OK,
2781 SourceLocation opLoc)
2782 : Expr(BinaryOperatorClass, ResTy, VK, OK,
2783 lhs->isTypeDependent() || rhs->isTypeDependent(),
2784 lhs->isValueDependent() || rhs->isValueDependent(),
2785 (lhs->isInstantiationDependent() ||
2786 rhs->isInstantiationDependent()),
2787 (lhs->containsUnexpandedParameterPack() ||
2788 rhs->containsUnexpandedParameterPack())),
2789 Opc(opc), OpLoc(opLoc) {
2790 SubExprs[LHS] = lhs;
2791 SubExprs[RHS] = rhs;
2792 assert(!isCompoundAssignmentOp() &&
2793 "Use ArithAssignBinaryOperator for compound assignments");
2794 }
2795
2796 /// \brief Construct an empty binary operator.
BinaryOperator(EmptyShell Empty)2797 explicit BinaryOperator(EmptyShell Empty)
2798 : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { }
2799
getExprLoc()2800 SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; }
getOperatorLoc()2801 SourceLocation getOperatorLoc() const { return OpLoc; }
setOperatorLoc(SourceLocation L)2802 void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2803
getOpcode()2804 Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
setOpcode(Opcode O)2805 void setOpcode(Opcode O) { Opc = O; }
2806
getLHS()2807 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
setLHS(Expr * E)2808 void setLHS(Expr *E) { SubExprs[LHS] = E; }
getRHS()2809 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
setRHS(Expr * E)2810 void setRHS(Expr *E) { SubExprs[RHS] = E; }
2811
getSourceRange()2812 SourceRange getSourceRange() const LLVM_READONLY {
2813 return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
2814 }
2815
2816 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2817 /// corresponds to, e.g. "<<=".
2818 static const char *getOpcodeStr(Opcode Op);
2819
getOpcodeStr()2820 const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
2821
2822 /// \brief Retrieve the binary opcode that corresponds to the given
2823 /// overloaded operator.
2824 static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2825
2826 /// \brief Retrieve the overloaded operator kind that corresponds to
2827 /// the given binary opcode.
2828 static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
2829
2830 /// predicates to categorize the respective opcodes.
isPtrMemOp()2831 bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; }
isMultiplicativeOp()2832 bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; }
isAdditiveOp(Opcode Opc)2833 static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
isAdditiveOp()2834 bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
isShiftOp(Opcode Opc)2835 static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
isShiftOp()2836 bool isShiftOp() const { return isShiftOp(getOpcode()); }
2837
isBitwiseOp(Opcode Opc)2838 static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
isBitwiseOp()2839 bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
2840
isRelationalOp(Opcode Opc)2841 static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
isRelationalOp()2842 bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
2843
isEqualityOp(Opcode Opc)2844 static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
isEqualityOp()2845 bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
2846
isComparisonOp(Opcode Opc)2847 static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; }
isComparisonOp()2848 bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
2849
isLogicalOp(Opcode Opc)2850 static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
isLogicalOp()2851 bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
2852
isAssignmentOp(Opcode Opc)2853 static bool isAssignmentOp(Opcode Opc) {
2854 return Opc >= BO_Assign && Opc <= BO_OrAssign;
2855 }
isAssignmentOp()2856 bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
2857
isCompoundAssignmentOp(Opcode Opc)2858 static bool isCompoundAssignmentOp(Opcode Opc) {
2859 return Opc > BO_Assign && Opc <= BO_OrAssign;
2860 }
isCompoundAssignmentOp()2861 bool isCompoundAssignmentOp() const {
2862 return isCompoundAssignmentOp(getOpcode());
2863 }
getOpForCompoundAssignment(Opcode Opc)2864 static Opcode getOpForCompoundAssignment(Opcode Opc) {
2865 assert(isCompoundAssignmentOp(Opc));
2866 if (Opc >= BO_AndAssign)
2867 return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
2868 else
2869 return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
2870 }
2871
isShiftAssignOp(Opcode Opc)2872 static bool isShiftAssignOp(Opcode Opc) {
2873 return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
2874 }
isShiftAssignOp()2875 bool isShiftAssignOp() const {
2876 return isShiftAssignOp(getOpcode());
2877 }
2878
classof(const Stmt * S)2879 static bool classof(const Stmt *S) {
2880 return S->getStmtClass() >= firstBinaryOperatorConstant &&
2881 S->getStmtClass() <= lastBinaryOperatorConstant;
2882 }
classof(const BinaryOperator *)2883 static bool classof(const BinaryOperator *) { return true; }
2884
2885 // Iterators
children()2886 child_range children() {
2887 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2888 }
2889
2890 protected:
BinaryOperator(Expr * lhs,Expr * rhs,Opcode opc,QualType ResTy,ExprValueKind VK,ExprObjectKind OK,SourceLocation opLoc,bool dead)2891 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2892 ExprValueKind VK, ExprObjectKind OK,
2893 SourceLocation opLoc, bool dead)
2894 : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
2895 lhs->isTypeDependent() || rhs->isTypeDependent(),
2896 lhs->isValueDependent() || rhs->isValueDependent(),
2897 (lhs->isInstantiationDependent() ||
2898 rhs->isInstantiationDependent()),
2899 (lhs->containsUnexpandedParameterPack() ||
2900 rhs->containsUnexpandedParameterPack())),
2901 Opc(opc), OpLoc(opLoc) {
2902 SubExprs[LHS] = lhs;
2903 SubExprs[RHS] = rhs;
2904 }
2905
BinaryOperator(StmtClass SC,EmptyShell Empty)2906 BinaryOperator(StmtClass SC, EmptyShell Empty)
2907 : Expr(SC, Empty), Opc(BO_MulAssign) { }
2908 };
2909
2910 /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
2911 /// track of the type the operation is performed in. Due to the semantics of
2912 /// these operators, the operands are promoted, the arithmetic performed, an
2913 /// implicit conversion back to the result type done, then the assignment takes
2914 /// place. This captures the intermediate type which the computation is done
2915 /// in.
2916 class CompoundAssignOperator : public BinaryOperator {
2917 QualType ComputationLHSType;
2918 QualType ComputationResultType;
2919 public:
CompoundAssignOperator(Expr * lhs,Expr * rhs,Opcode opc,QualType ResType,ExprValueKind VK,ExprObjectKind OK,QualType CompLHSType,QualType CompResultType,SourceLocation OpLoc)2920 CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
2921 ExprValueKind VK, ExprObjectKind OK,
2922 QualType CompLHSType, QualType CompResultType,
2923 SourceLocation OpLoc)
2924 : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true),
2925 ComputationLHSType(CompLHSType),
2926 ComputationResultType(CompResultType) {
2927 assert(isCompoundAssignmentOp() &&
2928 "Only should be used for compound assignments");
2929 }
2930
2931 /// \brief Build an empty compound assignment operator expression.
CompoundAssignOperator(EmptyShell Empty)2932 explicit CompoundAssignOperator(EmptyShell Empty)
2933 : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
2934
2935 // The two computation types are the type the LHS is converted
2936 // to for the computation and the type of the result; the two are
2937 // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
getComputationLHSType()2938 QualType getComputationLHSType() const { return ComputationLHSType; }
setComputationLHSType(QualType T)2939 void setComputationLHSType(QualType T) { ComputationLHSType = T; }
2940
getComputationResultType()2941 QualType getComputationResultType() const { return ComputationResultType; }
setComputationResultType(QualType T)2942 void setComputationResultType(QualType T) { ComputationResultType = T; }
2943
classof(const CompoundAssignOperator *)2944 static bool classof(const CompoundAssignOperator *) { return true; }
classof(const Stmt * S)2945 static bool classof(const Stmt *S) {
2946 return S->getStmtClass() == CompoundAssignOperatorClass;
2947 }
2948 };
2949
2950 /// AbstractConditionalOperator - An abstract base class for
2951 /// ConditionalOperator and BinaryConditionalOperator.
2952 class AbstractConditionalOperator : public Expr {
2953 SourceLocation QuestionLoc, ColonLoc;
2954 friend class ASTStmtReader;
2955
2956 protected:
AbstractConditionalOperator(StmtClass SC,QualType T,ExprValueKind VK,ExprObjectKind OK,bool TD,bool VD,bool ID,bool ContainsUnexpandedParameterPack,SourceLocation qloc,SourceLocation cloc)2957 AbstractConditionalOperator(StmtClass SC, QualType T,
2958 ExprValueKind VK, ExprObjectKind OK,
2959 bool TD, bool VD, bool ID,
2960 bool ContainsUnexpandedParameterPack,
2961 SourceLocation qloc,
2962 SourceLocation cloc)
2963 : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack),
2964 QuestionLoc(qloc), ColonLoc(cloc) {}
2965
AbstractConditionalOperator(StmtClass SC,EmptyShell Empty)2966 AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
2967 : Expr(SC, Empty) { }
2968
2969 public:
2970 // getCond - Return the expression representing the condition for
2971 // the ?: operator.
2972 Expr *getCond() const;
2973
2974 // getTrueExpr - Return the subexpression representing the value of
2975 // the expression if the condition evaluates to true.
2976 Expr *getTrueExpr() const;
2977
2978 // getFalseExpr - Return the subexpression representing the value of
2979 // the expression if the condition evaluates to false. This is
2980 // the same as getRHS.
2981 Expr *getFalseExpr() const;
2982
getQuestionLoc()2983 SourceLocation getQuestionLoc() const { return QuestionLoc; }
getColonLoc()2984 SourceLocation getColonLoc() const { return ColonLoc; }
2985
classof(const Stmt * T)2986 static bool classof(const Stmt *T) {
2987 return T->getStmtClass() == ConditionalOperatorClass ||
2988 T->getStmtClass() == BinaryConditionalOperatorClass;
2989 }
classof(const AbstractConditionalOperator *)2990 static bool classof(const AbstractConditionalOperator *) { return true; }
2991 };
2992
2993 /// ConditionalOperator - The ?: ternary operator. The GNU "missing
2994 /// middle" extension is a BinaryConditionalOperator.
2995 class ConditionalOperator : public AbstractConditionalOperator {
2996 enum { COND, LHS, RHS, END_EXPR };
2997 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2998
2999 friend class ASTStmtReader;
3000 public:
ConditionalOperator(Expr * cond,SourceLocation QLoc,Expr * lhs,SourceLocation CLoc,Expr * rhs,QualType t,ExprValueKind VK,ExprObjectKind OK)3001 ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
3002 SourceLocation CLoc, Expr *rhs,
3003 QualType t, ExprValueKind VK, ExprObjectKind OK)
3004 : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK,
3005 // FIXME: the type of the conditional operator doesn't
3006 // depend on the type of the conditional, but the standard
3007 // seems to imply that it could. File a bug!
3008 (lhs->isTypeDependent() || rhs->isTypeDependent()),
3009 (cond->isValueDependent() || lhs->isValueDependent() ||
3010 rhs->isValueDependent()),
3011 (cond->isInstantiationDependent() ||
3012 lhs->isInstantiationDependent() ||
3013 rhs->isInstantiationDependent()),
3014 (cond->containsUnexpandedParameterPack() ||
3015 lhs->containsUnexpandedParameterPack() ||
3016 rhs->containsUnexpandedParameterPack()),
3017 QLoc, CLoc) {
3018 SubExprs[COND] = cond;
3019 SubExprs[LHS] = lhs;
3020 SubExprs[RHS] = rhs;
3021 }
3022
3023 /// \brief Build an empty conditional operator.
ConditionalOperator(EmptyShell Empty)3024 explicit ConditionalOperator(EmptyShell Empty)
3025 : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
3026
3027 // getCond - Return the expression representing the condition for
3028 // the ?: operator.
getCond()3029 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3030
3031 // getTrueExpr - Return the subexpression representing the value of
3032 // the expression if the condition evaluates to true.
getTrueExpr()3033 Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
3034
3035 // getFalseExpr - Return the subexpression representing the value of
3036 // the expression if the condition evaluates to false. This is
3037 // the same as getRHS.
getFalseExpr()3038 Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
3039
getLHS()3040 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
getRHS()3041 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3042
getSourceRange()3043 SourceRange getSourceRange() const LLVM_READONLY {
3044 return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
3045 }
classof(const Stmt * T)3046 static bool classof(const Stmt *T) {
3047 return T->getStmtClass() == ConditionalOperatorClass;
3048 }
classof(const ConditionalOperator *)3049 static bool classof(const ConditionalOperator *) { return true; }
3050
3051 // Iterators
children()3052 child_range children() {
3053 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3054 }
3055 };
3056
3057 /// BinaryConditionalOperator - The GNU extension to the conditional
3058 /// operator which allows the middle operand to be omitted.
3059 ///
3060 /// This is a different expression kind on the assumption that almost
3061 /// every client ends up needing to know that these are different.
3062 class BinaryConditionalOperator : public AbstractConditionalOperator {
3063 enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
3064
3065 /// - the common condition/left-hand-side expression, which will be
3066 /// evaluated as the opaque value
3067 /// - the condition, expressed in terms of the opaque value
3068 /// - the left-hand-side, expressed in terms of the opaque value
3069 /// - the right-hand-side
3070 Stmt *SubExprs[NUM_SUBEXPRS];
3071 OpaqueValueExpr *OpaqueValue;
3072
3073 friend class ASTStmtReader;
3074 public:
BinaryConditionalOperator(Expr * common,OpaqueValueExpr * opaqueValue,Expr * cond,Expr * lhs,Expr * rhs,SourceLocation qloc,SourceLocation cloc,QualType t,ExprValueKind VK,ExprObjectKind OK)3075 BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue,
3076 Expr *cond, Expr *lhs, Expr *rhs,
3077 SourceLocation qloc, SourceLocation cloc,
3078 QualType t, ExprValueKind VK, ExprObjectKind OK)
3079 : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
3080 (common->isTypeDependent() || rhs->isTypeDependent()),
3081 (common->isValueDependent() || rhs->isValueDependent()),
3082 (common->isInstantiationDependent() ||
3083 rhs->isInstantiationDependent()),
3084 (common->containsUnexpandedParameterPack() ||
3085 rhs->containsUnexpandedParameterPack()),
3086 qloc, cloc),
3087 OpaqueValue(opaqueValue) {
3088 SubExprs[COMMON] = common;
3089 SubExprs[COND] = cond;
3090 SubExprs[LHS] = lhs;
3091 SubExprs[RHS] = rhs;
3092 assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
3093 }
3094
3095 /// \brief Build an empty conditional operator.
BinaryConditionalOperator(EmptyShell Empty)3096 explicit BinaryConditionalOperator(EmptyShell Empty)
3097 : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
3098
3099 /// \brief getCommon - Return the common expression, written to the
3100 /// left of the condition. The opaque value will be bound to the
3101 /// result of this expression.
getCommon()3102 Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
3103
3104 /// \brief getOpaqueValue - Return the opaque value placeholder.
getOpaqueValue()3105 OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
3106
3107 /// \brief getCond - Return the condition expression; this is defined
3108 /// in terms of the opaque value.
getCond()3109 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3110
3111 /// \brief getTrueExpr - Return the subexpression which will be
3112 /// evaluated if the condition evaluates to true; this is defined
3113 /// in terms of the opaque value.
getTrueExpr()3114 Expr *getTrueExpr() const {
3115 return cast<Expr>(SubExprs[LHS]);
3116 }
3117
3118 /// \brief getFalseExpr - Return the subexpression which will be
3119 /// evaluated if the condnition evaluates to false; this is
3120 /// defined in terms of the opaque value.
getFalseExpr()3121 Expr *getFalseExpr() const {
3122 return cast<Expr>(SubExprs[RHS]);
3123 }
3124
getSourceRange()3125 SourceRange getSourceRange() const LLVM_READONLY {
3126 return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd());
3127 }
classof(const Stmt * T)3128 static bool classof(const Stmt *T) {
3129 return T->getStmtClass() == BinaryConditionalOperatorClass;
3130 }
classof(const BinaryConditionalOperator *)3131 static bool classof(const BinaryConditionalOperator *) { return true; }
3132
3133 // Iterators
children()3134 child_range children() {
3135 return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3136 }
3137 };
3138
getCond()3139 inline Expr *AbstractConditionalOperator::getCond() const {
3140 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3141 return co->getCond();
3142 return cast<BinaryConditionalOperator>(this)->getCond();
3143 }
3144
getTrueExpr()3145 inline Expr *AbstractConditionalOperator::getTrueExpr() const {
3146 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3147 return co->getTrueExpr();
3148 return cast<BinaryConditionalOperator>(this)->getTrueExpr();
3149 }
3150
getFalseExpr()3151 inline Expr *AbstractConditionalOperator::getFalseExpr() const {
3152 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3153 return co->getFalseExpr();
3154 return cast<BinaryConditionalOperator>(this)->getFalseExpr();
3155 }
3156
3157 /// AddrLabelExpr - The GNU address of label extension, representing &&label.
3158 class AddrLabelExpr : public Expr {
3159 SourceLocation AmpAmpLoc, LabelLoc;
3160 LabelDecl *Label;
3161 public:
AddrLabelExpr(SourceLocation AALoc,SourceLocation LLoc,LabelDecl * L,QualType t)3162 AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L,
3163 QualType t)
3164 : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false,
3165 false),
3166 AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
3167
3168 /// \brief Build an empty address of a label expression.
AddrLabelExpr(EmptyShell Empty)3169 explicit AddrLabelExpr(EmptyShell Empty)
3170 : Expr(AddrLabelExprClass, Empty) { }
3171
getAmpAmpLoc()3172 SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
setAmpAmpLoc(SourceLocation L)3173 void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
getLabelLoc()3174 SourceLocation getLabelLoc() const { return LabelLoc; }
setLabelLoc(SourceLocation L)3175 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
3176
getSourceRange()3177 SourceRange getSourceRange() const LLVM_READONLY {
3178 return SourceRange(AmpAmpLoc, LabelLoc);
3179 }
3180
getLabel()3181 LabelDecl *getLabel() const { return Label; }
setLabel(LabelDecl * L)3182 void setLabel(LabelDecl *L) { Label = L; }
3183
classof(const Stmt * T)3184 static bool classof(const Stmt *T) {
3185 return T->getStmtClass() == AddrLabelExprClass;
3186 }
classof(const AddrLabelExpr *)3187 static bool classof(const AddrLabelExpr *) { return true; }
3188
3189 // Iterators
children()3190 child_range children() { return child_range(); }
3191 };
3192
3193 /// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
3194 /// The StmtExpr contains a single CompoundStmt node, which it evaluates and
3195 /// takes the value of the last subexpression.
3196 ///
3197 /// A StmtExpr is always an r-value; values "returned" out of a
3198 /// StmtExpr will be copied.
3199 class StmtExpr : public Expr {
3200 Stmt *SubStmt;
3201 SourceLocation LParenLoc, RParenLoc;
3202 public:
3203 // FIXME: Does type-dependence need to be computed differently?
3204 // FIXME: Do we need to compute instantiation instantiation-dependence for
3205 // statements? (ugh!)
StmtExpr(CompoundStmt * substmt,QualType T,SourceLocation lp,SourceLocation rp)3206 StmtExpr(CompoundStmt *substmt, QualType T,
3207 SourceLocation lp, SourceLocation rp) :
3208 Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
3209 T->isDependentType(), false, false, false),
3210 SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
3211
3212 /// \brief Build an empty statement expression.
StmtExpr(EmptyShell Empty)3213 explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
3214
getSubStmt()3215 CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
getSubStmt()3216 const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
setSubStmt(CompoundStmt * S)3217 void setSubStmt(CompoundStmt *S) { SubStmt = S; }
3218
getSourceRange()3219 SourceRange getSourceRange() const LLVM_READONLY {
3220 return SourceRange(LParenLoc, RParenLoc);
3221 }
3222
getLParenLoc()3223 SourceLocation getLParenLoc() const { return LParenLoc; }
setLParenLoc(SourceLocation L)3224 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
getRParenLoc()3225 SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)3226 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3227
classof(const Stmt * T)3228 static bool classof(const Stmt *T) {
3229 return T->getStmtClass() == StmtExprClass;
3230 }
classof(const StmtExpr *)3231 static bool classof(const StmtExpr *) { return true; }
3232
3233 // Iterators
children()3234 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
3235 };
3236
3237
3238 /// ShuffleVectorExpr - clang-specific builtin-in function
3239 /// __builtin_shufflevector.
3240 /// This AST node represents a operator that does a constant
3241 /// shuffle, similar to LLVM's shufflevector instruction. It takes
3242 /// two vectors and a variable number of constant indices,
3243 /// and returns the appropriately shuffled vector.
3244 class ShuffleVectorExpr : public Expr {
3245 SourceLocation BuiltinLoc, RParenLoc;
3246
3247 // SubExprs - the list of values passed to the __builtin_shufflevector
3248 // function. The first two are vectors, and the rest are constant
3249 // indices. The number of values in this list is always
3250 // 2+the number of indices in the vector type.
3251 Stmt **SubExprs;
3252 unsigned NumExprs;
3253
3254 public:
3255 ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
3256 QualType Type, SourceLocation BLoc,
3257 SourceLocation RP);
3258
3259 /// \brief Build an empty vector-shuffle expression.
ShuffleVectorExpr(EmptyShell Empty)3260 explicit ShuffleVectorExpr(EmptyShell Empty)
3261 : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
3262
getBuiltinLoc()3263 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
setBuiltinLoc(SourceLocation L)3264 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3265
getRParenLoc()3266 SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)3267 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3268
getSourceRange()3269 SourceRange getSourceRange() const LLVM_READONLY {
3270 return SourceRange(BuiltinLoc, RParenLoc);
3271 }
classof(const Stmt * T)3272 static bool classof(const Stmt *T) {
3273 return T->getStmtClass() == ShuffleVectorExprClass;
3274 }
classof(const ShuffleVectorExpr *)3275 static bool classof(const ShuffleVectorExpr *) { return true; }
3276
3277 /// getNumSubExprs - Return the size of the SubExprs array. This includes the
3278 /// constant expression, the actual arguments passed in, and the function
3279 /// pointers.
getNumSubExprs()3280 unsigned getNumSubExprs() const { return NumExprs; }
3281
3282 /// \brief Retrieve the array of expressions.
getSubExprs()3283 Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
3284
3285 /// getExpr - Return the Expr at the specified index.
getExpr(unsigned Index)3286 Expr *getExpr(unsigned Index) {
3287 assert((Index < NumExprs) && "Arg access out of range!");
3288 return cast<Expr>(SubExprs[Index]);
3289 }
getExpr(unsigned Index)3290 const Expr *getExpr(unsigned Index) const {
3291 assert((Index < NumExprs) && "Arg access out of range!");
3292 return cast<Expr>(SubExprs[Index]);
3293 }
3294
3295 void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
3296
getShuffleMaskIdx(ASTContext & Ctx,unsigned N)3297 unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
3298 assert((N < NumExprs - 2) && "Shuffle idx out of range!");
3299 return getExpr(N+2)->EvaluateKnownConstInt(Ctx).getZExtValue();
3300 }
3301
3302 // Iterators
children()3303 child_range children() {
3304 return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
3305 }
3306 };
3307
3308 /// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
3309 /// This AST node is similar to the conditional operator (?:) in C, with
3310 /// the following exceptions:
3311 /// - the test expression must be a integer constant expression.
3312 /// - the expression returned acts like the chosen subexpression in every
3313 /// visible way: the type is the same as that of the chosen subexpression,
3314 /// and all predicates (whether it's an l-value, whether it's an integer
3315 /// constant expression, etc.) return the same result as for the chosen
3316 /// sub-expression.
3317 class ChooseExpr : public Expr {
3318 enum { COND, LHS, RHS, END_EXPR };
3319 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3320 SourceLocation BuiltinLoc, RParenLoc;
3321 public:
ChooseExpr(SourceLocation BLoc,Expr * cond,Expr * lhs,Expr * rhs,QualType t,ExprValueKind VK,ExprObjectKind OK,SourceLocation RP,bool TypeDependent,bool ValueDependent)3322 ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
3323 QualType t, ExprValueKind VK, ExprObjectKind OK,
3324 SourceLocation RP, bool TypeDependent, bool ValueDependent)
3325 : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
3326 (cond->isInstantiationDependent() ||
3327 lhs->isInstantiationDependent() ||
3328 rhs->isInstantiationDependent()),
3329 (cond->containsUnexpandedParameterPack() ||
3330 lhs->containsUnexpandedParameterPack() ||
3331 rhs->containsUnexpandedParameterPack())),
3332 BuiltinLoc(BLoc), RParenLoc(RP) {
3333 SubExprs[COND] = cond;
3334 SubExprs[LHS] = lhs;
3335 SubExprs[RHS] = rhs;
3336 }
3337
3338 /// \brief Build an empty __builtin_choose_expr.
ChooseExpr(EmptyShell Empty)3339 explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
3340
3341 /// isConditionTrue - Return whether the condition is true (i.e. not
3342 /// equal to zero).
3343 bool isConditionTrue(const ASTContext &C) const;
3344
3345 /// getChosenSubExpr - Return the subexpression chosen according to the
3346 /// condition.
getChosenSubExpr(const ASTContext & C)3347 Expr *getChosenSubExpr(const ASTContext &C) const {
3348 return isConditionTrue(C) ? getLHS() : getRHS();
3349 }
3350
getCond()3351 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
setCond(Expr * E)3352 void setCond(Expr *E) { SubExprs[COND] = E; }
getLHS()3353 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
setLHS(Expr * E)3354 void setLHS(Expr *E) { SubExprs[LHS] = E; }
getRHS()3355 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
setRHS(Expr * E)3356 void setRHS(Expr *E) { SubExprs[RHS] = E; }
3357
getBuiltinLoc()3358 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
setBuiltinLoc(SourceLocation L)3359 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3360
getRParenLoc()3361 SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)3362 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3363
getSourceRange()3364 SourceRange getSourceRange() const LLVM_READONLY {
3365 return SourceRange(BuiltinLoc, RParenLoc);
3366 }
classof(const Stmt * T)3367 static bool classof(const Stmt *T) {
3368 return T->getStmtClass() == ChooseExprClass;
3369 }
classof(const ChooseExpr *)3370 static bool classof(const ChooseExpr *) { return true; }
3371
3372 // Iterators
children()3373 child_range children() {
3374 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3375 }
3376 };
3377
3378 /// GNUNullExpr - Implements the GNU __null extension, which is a name
3379 /// for a null pointer constant that has integral type (e.g., int or
3380 /// long) and is the same size and alignment as a pointer. The __null
3381 /// extension is typically only used by system headers, which define
3382 /// NULL as __null in C++ rather than using 0 (which is an integer
3383 /// that may not match the size of a pointer).
3384 class GNUNullExpr : public Expr {
3385 /// TokenLoc - The location of the __null keyword.
3386 SourceLocation TokenLoc;
3387
3388 public:
GNUNullExpr(QualType Ty,SourceLocation Loc)3389 GNUNullExpr(QualType Ty, SourceLocation Loc)
3390 : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false,
3391 false),
3392 TokenLoc(Loc) { }
3393
3394 /// \brief Build an empty GNU __null expression.
GNUNullExpr(EmptyShell Empty)3395 explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
3396
3397 /// getTokenLocation - The location of the __null token.
getTokenLocation()3398 SourceLocation getTokenLocation() const { return TokenLoc; }
setTokenLocation(SourceLocation L)3399 void setTokenLocation(SourceLocation L) { TokenLoc = L; }
3400
getSourceRange()3401 SourceRange getSourceRange() const LLVM_READONLY {
3402 return SourceRange(TokenLoc);
3403 }
classof(const Stmt * T)3404 static bool classof(const Stmt *T) {
3405 return T->getStmtClass() == GNUNullExprClass;
3406 }
classof(const GNUNullExpr *)3407 static bool classof(const GNUNullExpr *) { return true; }
3408
3409 // Iterators
children()3410 child_range children() { return child_range(); }
3411 };
3412
3413 /// VAArgExpr, used for the builtin function __builtin_va_arg.
3414 class VAArgExpr : public Expr {
3415 Stmt *Val;
3416 TypeSourceInfo *TInfo;
3417 SourceLocation BuiltinLoc, RParenLoc;
3418 public:
VAArgExpr(SourceLocation BLoc,Expr * e,TypeSourceInfo * TInfo,SourceLocation RPLoc,QualType t)3419 VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo,
3420 SourceLocation RPLoc, QualType t)
3421 : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary,
3422 t->isDependentType(), false,
3423 (TInfo->getType()->isInstantiationDependentType() ||
3424 e->isInstantiationDependent()),
3425 (TInfo->getType()->containsUnexpandedParameterPack() ||
3426 e->containsUnexpandedParameterPack())),
3427 Val(e), TInfo(TInfo),
3428 BuiltinLoc(BLoc),
3429 RParenLoc(RPLoc) { }
3430
3431 /// \brief Create an empty __builtin_va_arg expression.
VAArgExpr(EmptyShell Empty)3432 explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
3433
getSubExpr()3434 const Expr *getSubExpr() const { return cast<Expr>(Val); }
getSubExpr()3435 Expr *getSubExpr() { return cast<Expr>(Val); }
setSubExpr(Expr * E)3436 void setSubExpr(Expr *E) { Val = E; }
3437
getWrittenTypeInfo()3438 TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; }
setWrittenTypeInfo(TypeSourceInfo * TI)3439 void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; }
3440
getBuiltinLoc()3441 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
setBuiltinLoc(SourceLocation L)3442 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3443
getRParenLoc()3444 SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)3445 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3446
getSourceRange()3447 SourceRange getSourceRange() const LLVM_READONLY {
3448 return SourceRange(BuiltinLoc, RParenLoc);
3449 }
classof(const Stmt * T)3450 static bool classof(const Stmt *T) {
3451 return T->getStmtClass() == VAArgExprClass;
3452 }
classof(const VAArgExpr *)3453 static bool classof(const VAArgExpr *) { return true; }
3454
3455 // Iterators
children()3456 child_range children() { return child_range(&Val, &Val+1); }
3457 };
3458
3459 /// @brief Describes an C or C++ initializer list.
3460 ///
3461 /// InitListExpr describes an initializer list, which can be used to
3462 /// initialize objects of different types, including
3463 /// struct/class/union types, arrays, and vectors. For example:
3464 ///
3465 /// @code
3466 /// struct foo x = { 1, { 2, 3 } };
3467 /// @endcode
3468 ///
3469 /// Prior to semantic analysis, an initializer list will represent the
3470 /// initializer list as written by the user, but will have the
3471 /// placeholder type "void". This initializer list is called the
3472 /// syntactic form of the initializer, and may contain C99 designated
3473 /// initializers (represented as DesignatedInitExprs), initializations
3474 /// of subobject members without explicit braces, and so on. Clients
3475 /// interested in the original syntax of the initializer list should
3476 /// use the syntactic form of the initializer list.
3477 ///
3478 /// After semantic analysis, the initializer list will represent the
3479 /// semantic form of the initializer, where the initializations of all
3480 /// subobjects are made explicit with nested InitListExpr nodes and
3481 /// C99 designators have been eliminated by placing the designated
3482 /// initializations into the subobject they initialize. Additionally,
3483 /// any "holes" in the initialization, where no initializer has been
3484 /// specified for a particular subobject, will be replaced with
3485 /// implicitly-generated ImplicitValueInitExpr expressions that
3486 /// value-initialize the subobjects. Note, however, that the
3487 /// initializer lists may still have fewer initializers than there are
3488 /// elements to initialize within the object.
3489 ///
3490 /// Given the semantic form of the initializer list, one can retrieve
3491 /// the original syntactic form of that initializer list (if it
3492 /// exists) using getSyntacticForm(). Since many initializer lists
3493 /// have the same syntactic and semantic forms, getSyntacticForm() may
3494 /// return NULL, indicating that the current initializer list also
3495 /// serves as its syntactic form.
3496 class InitListExpr : public Expr {
3497 // FIXME: Eliminate this vector in favor of ASTContext allocation
3498 typedef ASTVector<Stmt *> InitExprsTy;
3499 InitExprsTy InitExprs;
3500 SourceLocation LBraceLoc, RBraceLoc;
3501
3502 /// Contains the initializer list that describes the syntactic form
3503 /// written in the source code.
3504 InitListExpr *SyntacticForm;
3505
3506 /// \brief Either:
3507 /// If this initializer list initializes an array with more elements than
3508 /// there are initializers in the list, specifies an expression to be used
3509 /// for value initialization of the rest of the elements.
3510 /// Or
3511 /// If this initializer list initializes a union, specifies which
3512 /// field within the union will be initialized.
3513 llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
3514
3515 public:
3516 InitListExpr(ASTContext &C, SourceLocation lbraceloc,
3517 Expr **initexprs, unsigned numinits,
3518 SourceLocation rbraceloc);
3519
3520 /// \brief Build an empty initializer list.
InitListExpr(ASTContext & C,EmptyShell Empty)3521 explicit InitListExpr(ASTContext &C, EmptyShell Empty)
3522 : Expr(InitListExprClass, Empty), InitExprs(C) { }
3523
getNumInits()3524 unsigned getNumInits() const { return InitExprs.size(); }
3525
3526 /// \brief Retrieve the set of initializers.
getInits()3527 Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
3528
getInit(unsigned Init)3529 const Expr *getInit(unsigned Init) const {
3530 assert(Init < getNumInits() && "Initializer access out of range!");
3531 return cast_or_null<Expr>(InitExprs[Init]);
3532 }
3533
getInit(unsigned Init)3534 Expr *getInit(unsigned Init) {
3535 assert(Init < getNumInits() && "Initializer access out of range!");
3536 return cast_or_null<Expr>(InitExprs[Init]);
3537 }
3538
setInit(unsigned Init,Expr * expr)3539 void setInit(unsigned Init, Expr *expr) {
3540 assert(Init < getNumInits() && "Initializer access out of range!");
3541 InitExprs[Init] = expr;
3542 }
3543
3544 /// \brief Reserve space for some number of initializers.
3545 void reserveInits(ASTContext &C, unsigned NumInits);
3546
3547 /// @brief Specify the number of initializers
3548 ///
3549 /// If there are more than @p NumInits initializers, the remaining
3550 /// initializers will be destroyed. If there are fewer than @p
3551 /// NumInits initializers, NULL expressions will be added for the
3552 /// unknown initializers.
3553 void resizeInits(ASTContext &Context, unsigned NumInits);
3554
3555 /// @brief Updates the initializer at index @p Init with the new
3556 /// expression @p expr, and returns the old expression at that
3557 /// location.
3558 ///
3559 /// When @p Init is out of range for this initializer list, the
3560 /// initializer list will be extended with NULL expressions to
3561 /// accommodate the new entry.
3562 Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
3563
3564 /// \brief If this initializer list initializes an array with more elements
3565 /// than there are initializers in the list, specifies an expression to be
3566 /// used for value initialization of the rest of the elements.
getArrayFiller()3567 Expr *getArrayFiller() {
3568 return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
3569 }
getArrayFiller()3570 const Expr *getArrayFiller() const {
3571 return const_cast<InitListExpr *>(this)->getArrayFiller();
3572 }
3573 void setArrayFiller(Expr *filler);
3574
3575 /// \brief Return true if this is an array initializer and its array "filler"
3576 /// has been set.
hasArrayFiller()3577 bool hasArrayFiller() const { return getArrayFiller(); }
3578
3579 /// \brief If this initializes a union, specifies which field in the
3580 /// union to initialize.
3581 ///
3582 /// Typically, this field is the first named field within the
3583 /// union. However, a designated initializer can specify the
3584 /// initialization of a different field within the union.
getInitializedFieldInUnion()3585 FieldDecl *getInitializedFieldInUnion() {
3586 return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
3587 }
getInitializedFieldInUnion()3588 const FieldDecl *getInitializedFieldInUnion() const {
3589 return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
3590 }
setInitializedFieldInUnion(FieldDecl * FD)3591 void setInitializedFieldInUnion(FieldDecl *FD) {
3592 ArrayFillerOrUnionFieldInit = FD;
3593 }
3594
3595 // Explicit InitListExpr's originate from source code (and have valid source
3596 // locations). Implicit InitListExpr's are created by the semantic analyzer.
isExplicit()3597 bool isExplicit() {
3598 return LBraceLoc.isValid() && RBraceLoc.isValid();
3599 }
3600
3601 // Is this an initializer for an array of characters, initialized by a string
3602 // literal or an @encode?
3603 bool isStringLiteralInit() const;
3604
getLBraceLoc()3605 SourceLocation getLBraceLoc() const { return LBraceLoc; }
setLBraceLoc(SourceLocation Loc)3606 void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
getRBraceLoc()3607 SourceLocation getRBraceLoc() const { return RBraceLoc; }
setRBraceLoc(SourceLocation Loc)3608 void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
3609
3610 /// @brief Retrieve the initializer list that describes the
3611 /// syntactic form of the initializer.
3612 ///
3613 ///
getSyntacticForm()3614 InitListExpr *getSyntacticForm() const { return SyntacticForm; }
setSyntacticForm(InitListExpr * Init)3615 void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
3616
hadArrayRangeDesignator()3617 bool hadArrayRangeDesignator() const {
3618 return InitListExprBits.HadArrayRangeDesignator != 0;
3619 }
3620 void sawArrayRangeDesignator(bool ARD = true) {
3621 InitListExprBits.HadArrayRangeDesignator = ARD;
3622 }
3623
initializesStdInitializerList()3624 bool initializesStdInitializerList() const {
3625 return InitListExprBits.InitializesStdInitializerList != 0;
3626 }
3627 void setInitializesStdInitializerList(bool ISIL = true) {
3628 InitListExprBits.InitializesStdInitializerList = ISIL;
3629 }
3630
3631 SourceRange getSourceRange() const LLVM_READONLY;
3632
classof(const Stmt * T)3633 static bool classof(const Stmt *T) {
3634 return T->getStmtClass() == InitListExprClass;
3635 }
classof(const InitListExpr *)3636 static bool classof(const InitListExpr *) { return true; }
3637
3638 // Iterators
children()3639 child_range children() {
3640 if (InitExprs.empty()) return child_range();
3641 return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
3642 }
3643
3644 typedef InitExprsTy::iterator iterator;
3645 typedef InitExprsTy::const_iterator const_iterator;
3646 typedef InitExprsTy::reverse_iterator reverse_iterator;
3647 typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
3648
begin()3649 iterator begin() { return InitExprs.begin(); }
begin()3650 const_iterator begin() const { return InitExprs.begin(); }
end()3651 iterator end() { return InitExprs.end(); }
end()3652 const_iterator end() const { return InitExprs.end(); }
rbegin()3653 reverse_iterator rbegin() { return InitExprs.rbegin(); }
rbegin()3654 const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
rend()3655 reverse_iterator rend() { return InitExprs.rend(); }
rend()3656 const_reverse_iterator rend() const { return InitExprs.rend(); }
3657
3658 friend class ASTStmtReader;
3659 friend class ASTStmtWriter;
3660 };
3661
3662 /// @brief Represents a C99 designated initializer expression.
3663 ///
3664 /// A designated initializer expression (C99 6.7.8) contains one or
3665 /// more designators (which can be field designators, array
3666 /// designators, or GNU array-range designators) followed by an
3667 /// expression that initializes the field or element(s) that the
3668 /// designators refer to. For example, given:
3669 ///
3670 /// @code
3671 /// struct point {
3672 /// double x;
3673 /// double y;
3674 /// };
3675 /// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
3676 /// @endcode
3677 ///
3678 /// The InitListExpr contains three DesignatedInitExprs, the first of
3679 /// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
3680 /// designators, one array designator for @c [2] followed by one field
3681 /// designator for @c .y. The initalization expression will be 1.0.
3682 class DesignatedInitExpr : public Expr {
3683 public:
3684 /// \brief Forward declaration of the Designator class.
3685 class Designator;
3686
3687 private:
3688 /// The location of the '=' or ':' prior to the actual initializer
3689 /// expression.
3690 SourceLocation EqualOrColonLoc;
3691
3692 /// Whether this designated initializer used the GNU deprecated
3693 /// syntax rather than the C99 '=' syntax.
3694 bool GNUSyntax : 1;
3695
3696 /// The number of designators in this initializer expression.
3697 unsigned NumDesignators : 15;
3698
3699 /// The number of subexpressions of this initializer expression,
3700 /// which contains both the initializer and any additional
3701 /// expressions used by array and array-range designators.
3702 unsigned NumSubExprs : 16;
3703
3704 /// \brief The designators in this designated initialization
3705 /// expression.
3706 Designator *Designators;
3707
3708
3709 DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
3710 const Designator *Designators,
3711 SourceLocation EqualOrColonLoc, bool GNUSyntax,
3712 Expr **IndexExprs, unsigned NumIndexExprs,
3713 Expr *Init);
3714
DesignatedInitExpr(unsigned NumSubExprs)3715 explicit DesignatedInitExpr(unsigned NumSubExprs)
3716 : Expr(DesignatedInitExprClass, EmptyShell()),
3717 NumDesignators(0), NumSubExprs(NumSubExprs), Designators(0) { }
3718
3719 public:
3720 /// A field designator, e.g., ".x".
3721 struct FieldDesignator {
3722 /// Refers to the field that is being initialized. The low bit
3723 /// of this field determines whether this is actually a pointer
3724 /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
3725 /// initially constructed, a field designator will store an
3726 /// IdentifierInfo*. After semantic analysis has resolved that
3727 /// name, the field designator will instead store a FieldDecl*.
3728 uintptr_t NameOrField;
3729
3730 /// The location of the '.' in the designated initializer.
3731 unsigned DotLoc;
3732
3733 /// The location of the field name in the designated initializer.
3734 unsigned FieldLoc;
3735 };
3736
3737 /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3738 struct ArrayOrRangeDesignator {
3739 /// Location of the first index expression within the designated
3740 /// initializer expression's list of subexpressions.
3741 unsigned Index;
3742 /// The location of the '[' starting the array range designator.
3743 unsigned LBracketLoc;
3744 /// The location of the ellipsis separating the start and end
3745 /// indices. Only valid for GNU array-range designators.
3746 unsigned EllipsisLoc;
3747 /// The location of the ']' terminating the array range designator.
3748 unsigned RBracketLoc;
3749 };
3750
3751 /// @brief Represents a single C99 designator.
3752 ///
3753 /// @todo This class is infuriatingly similar to clang::Designator,
3754 /// but minor differences (storing indices vs. storing pointers)
3755 /// keep us from reusing it. Try harder, later, to rectify these
3756 /// differences.
3757 class Designator {
3758 /// @brief The kind of designator this describes.
3759 enum {
3760 FieldDesignator,
3761 ArrayDesignator,
3762 ArrayRangeDesignator
3763 } Kind;
3764
3765 union {
3766 /// A field designator, e.g., ".x".
3767 struct FieldDesignator Field;
3768 /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3769 struct ArrayOrRangeDesignator ArrayOrRange;
3770 };
3771 friend class DesignatedInitExpr;
3772
3773 public:
Designator()3774 Designator() {}
3775
3776 /// @brief Initializes a field designator.
Designator(const IdentifierInfo * FieldName,SourceLocation DotLoc,SourceLocation FieldLoc)3777 Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
3778 SourceLocation FieldLoc)
3779 : Kind(FieldDesignator) {
3780 Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
3781 Field.DotLoc = DotLoc.getRawEncoding();
3782 Field.FieldLoc = FieldLoc.getRawEncoding();
3783 }
3784
3785 /// @brief Initializes an array designator.
Designator(unsigned Index,SourceLocation LBracketLoc,SourceLocation RBracketLoc)3786 Designator(unsigned Index, SourceLocation LBracketLoc,
3787 SourceLocation RBracketLoc)
3788 : Kind(ArrayDesignator) {
3789 ArrayOrRange.Index = Index;
3790 ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3791 ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
3792 ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3793 }
3794
3795 /// @brief Initializes a GNU array-range designator.
Designator(unsigned Index,SourceLocation LBracketLoc,SourceLocation EllipsisLoc,SourceLocation RBracketLoc)3796 Designator(unsigned Index, SourceLocation LBracketLoc,
3797 SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
3798 : Kind(ArrayRangeDesignator) {
3799 ArrayOrRange.Index = Index;
3800 ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3801 ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
3802 ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3803 }
3804
isFieldDesignator()3805 bool isFieldDesignator() const { return Kind == FieldDesignator; }
isArrayDesignator()3806 bool isArrayDesignator() const { return Kind == ArrayDesignator; }
isArrayRangeDesignator()3807 bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
3808
3809 IdentifierInfo *getFieldName() const;
3810
getField()3811 FieldDecl *getField() const {
3812 assert(Kind == FieldDesignator && "Only valid on a field designator");
3813 if (Field.NameOrField & 0x01)
3814 return 0;
3815 else
3816 return reinterpret_cast<FieldDecl *>(Field.NameOrField);
3817 }
3818
setField(FieldDecl * FD)3819 void setField(FieldDecl *FD) {
3820 assert(Kind == FieldDesignator && "Only valid on a field designator");
3821 Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
3822 }
3823
getDotLoc()3824 SourceLocation getDotLoc() const {
3825 assert(Kind == FieldDesignator && "Only valid on a field designator");
3826 return SourceLocation::getFromRawEncoding(Field.DotLoc);
3827 }
3828
getFieldLoc()3829 SourceLocation getFieldLoc() const {
3830 assert(Kind == FieldDesignator && "Only valid on a field designator");
3831 return SourceLocation::getFromRawEncoding(Field.FieldLoc);
3832 }
3833
getLBracketLoc()3834 SourceLocation getLBracketLoc() const {
3835 assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3836 "Only valid on an array or array-range designator");
3837 return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
3838 }
3839
getRBracketLoc()3840 SourceLocation getRBracketLoc() const {
3841 assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3842 "Only valid on an array or array-range designator");
3843 return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
3844 }
3845
getEllipsisLoc()3846 SourceLocation getEllipsisLoc() const {
3847 assert(Kind == ArrayRangeDesignator &&
3848 "Only valid on an array-range designator");
3849 return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
3850 }
3851
getFirstExprIndex()3852 unsigned getFirstExprIndex() const {
3853 assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3854 "Only valid on an array or array-range designator");
3855 return ArrayOrRange.Index;
3856 }
3857
getStartLocation()3858 SourceLocation getStartLocation() const {
3859 if (Kind == FieldDesignator)
3860 return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
3861 else
3862 return getLBracketLoc();
3863 }
getEndLocation()3864 SourceLocation getEndLocation() const {
3865 return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc();
3866 }
getSourceRange()3867 SourceRange getSourceRange() const LLVM_READONLY {
3868 return SourceRange(getStartLocation(), getEndLocation());
3869 }
3870 };
3871
3872 static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
3873 unsigned NumDesignators,
3874 Expr **IndexExprs, unsigned NumIndexExprs,
3875 SourceLocation EqualOrColonLoc,
3876 bool GNUSyntax, Expr *Init);
3877
3878 static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3879
3880 /// @brief Returns the number of designators in this initializer.
size()3881 unsigned size() const { return NumDesignators; }
3882
3883 // Iterator access to the designators.
3884 typedef Designator *designators_iterator;
designators_begin()3885 designators_iterator designators_begin() { return Designators; }
designators_end()3886 designators_iterator designators_end() {
3887 return Designators + NumDesignators;
3888 }
3889
3890 typedef const Designator *const_designators_iterator;
designators_begin()3891 const_designators_iterator designators_begin() const { return Designators; }
designators_end()3892 const_designators_iterator designators_end() const {
3893 return Designators + NumDesignators;
3894 }
3895
3896 typedef std::reverse_iterator<designators_iterator>
3897 reverse_designators_iterator;
designators_rbegin()3898 reverse_designators_iterator designators_rbegin() {
3899 return reverse_designators_iterator(designators_end());
3900 }
designators_rend()3901 reverse_designators_iterator designators_rend() {
3902 return reverse_designators_iterator(designators_begin());
3903 }
3904
3905 typedef std::reverse_iterator<const_designators_iterator>
3906 const_reverse_designators_iterator;
designators_rbegin()3907 const_reverse_designators_iterator designators_rbegin() const {
3908 return const_reverse_designators_iterator(designators_end());
3909 }
designators_rend()3910 const_reverse_designators_iterator designators_rend() const {
3911 return const_reverse_designators_iterator(designators_begin());
3912 }
3913
getDesignator(unsigned Idx)3914 Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3915
3916 void setDesignators(ASTContext &C, const Designator *Desigs,
3917 unsigned NumDesigs);
3918
3919 Expr *getArrayIndex(const Designator& D);
3920 Expr *getArrayRangeStart(const Designator& D);
3921 Expr *getArrayRangeEnd(const Designator& D);
3922
3923 /// @brief Retrieve the location of the '=' that precedes the
3924 /// initializer value itself, if present.
getEqualOrColonLoc()3925 SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
setEqualOrColonLoc(SourceLocation L)3926 void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
3927
3928 /// @brief Determines whether this designated initializer used the
3929 /// deprecated GNU syntax for designated initializers.
usesGNUSyntax()3930 bool usesGNUSyntax() const { return GNUSyntax; }
setGNUSyntax(bool GNU)3931 void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
3932
3933 /// @brief Retrieve the initializer value.
getInit()3934 Expr *getInit() const {
3935 return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
3936 }
3937
setInit(Expr * init)3938 void setInit(Expr *init) {
3939 *child_begin() = init;
3940 }
3941
3942 /// \brief Retrieve the total number of subexpressions in this
3943 /// designated initializer expression, including the actual
3944 /// initialized value and any expressions that occur within array
3945 /// and array-range designators.
getNumSubExprs()3946 unsigned getNumSubExprs() const { return NumSubExprs; }
3947
getSubExpr(unsigned Idx)3948 Expr *getSubExpr(unsigned Idx) {
3949 assert(Idx < NumSubExprs && "Subscript out of range");
3950 char* Ptr = static_cast<char*>(static_cast<void *>(this));
3951 Ptr += sizeof(DesignatedInitExpr);
3952 return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3953 }
3954
setSubExpr(unsigned Idx,Expr * E)3955 void setSubExpr(unsigned Idx, Expr *E) {
3956 assert(Idx < NumSubExprs && "Subscript out of range");
3957 char* Ptr = static_cast<char*>(static_cast<void *>(this));
3958 Ptr += sizeof(DesignatedInitExpr);
3959 reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3960 }
3961
3962 /// \brief Replaces the designator at index @p Idx with the series
3963 /// of designators in [First, Last).
3964 void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3965 const Designator *Last);
3966
3967 SourceRange getDesignatorsSourceRange() const;
3968
3969 SourceRange getSourceRange() const LLVM_READONLY;
3970
classof(const Stmt * T)3971 static bool classof(const Stmt *T) {
3972 return T->getStmtClass() == DesignatedInitExprClass;
3973 }
classof(const DesignatedInitExpr *)3974 static bool classof(const DesignatedInitExpr *) { return true; }
3975
3976 // Iterators
children()3977 child_range children() {
3978 Stmt **begin = reinterpret_cast<Stmt**>(this + 1);
3979 return child_range(begin, begin + NumSubExprs);
3980 }
3981 };
3982
3983 /// \brief Represents an implicitly-generated value initialization of
3984 /// an object of a given type.
3985 ///
3986 /// Implicit value initializations occur within semantic initializer
3987 /// list expressions (InitListExpr) as placeholders for subobject
3988 /// initializations not explicitly specified by the user.
3989 ///
3990 /// \see InitListExpr
3991 class ImplicitValueInitExpr : public Expr {
3992 public:
ImplicitValueInitExpr(QualType ty)3993 explicit ImplicitValueInitExpr(QualType ty)
3994 : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary,
3995 false, false, ty->isInstantiationDependentType(), false) { }
3996
3997 /// \brief Construct an empty implicit value initialization.
ImplicitValueInitExpr(EmptyShell Empty)3998 explicit ImplicitValueInitExpr(EmptyShell Empty)
3999 : Expr(ImplicitValueInitExprClass, Empty) { }
4000
classof(const Stmt * T)4001 static bool classof(const Stmt *T) {
4002 return T->getStmtClass() == ImplicitValueInitExprClass;
4003 }
classof(const ImplicitValueInitExpr *)4004 static bool classof(const ImplicitValueInitExpr *) { return true; }
4005
getSourceRange()4006 SourceRange getSourceRange() const LLVM_READONLY {
4007 return SourceRange();
4008 }
4009
4010 // Iterators
children()4011 child_range children() { return child_range(); }
4012 };
4013
4014
4015 class ParenListExpr : public Expr {
4016 Stmt **Exprs;
4017 unsigned NumExprs;
4018 SourceLocation LParenLoc, RParenLoc;
4019
4020 public:
4021 ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
4022 unsigned numexprs, SourceLocation rparenloc);
4023
4024 /// \brief Build an empty paren list.
ParenListExpr(EmptyShell Empty)4025 explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
4026
getNumExprs()4027 unsigned getNumExprs() const { return NumExprs; }
4028
getExpr(unsigned Init)4029 const Expr* getExpr(unsigned Init) const {
4030 assert(Init < getNumExprs() && "Initializer access out of range!");
4031 return cast_or_null<Expr>(Exprs[Init]);
4032 }
4033
getExpr(unsigned Init)4034 Expr* getExpr(unsigned Init) {
4035 assert(Init < getNumExprs() && "Initializer access out of range!");
4036 return cast_or_null<Expr>(Exprs[Init]);
4037 }
4038
getExprs()4039 Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
4040
getLParenLoc()4041 SourceLocation getLParenLoc() const { return LParenLoc; }
getRParenLoc()4042 SourceLocation getRParenLoc() const { return RParenLoc; }
4043
getSourceRange()4044 SourceRange getSourceRange() const LLVM_READONLY {
4045 return SourceRange(LParenLoc, RParenLoc);
4046 }
classof(const Stmt * T)4047 static bool classof(const Stmt *T) {
4048 return T->getStmtClass() == ParenListExprClass;
4049 }
classof(const ParenListExpr *)4050 static bool classof(const ParenListExpr *) { return true; }
4051
4052 // Iterators
children()4053 child_range children() {
4054 return child_range(&Exprs[0], &Exprs[0]+NumExprs);
4055 }
4056
4057 friend class ASTStmtReader;
4058 friend class ASTStmtWriter;
4059 };
4060
4061
4062 /// \brief Represents a C11 generic selection.
4063 ///
4064 /// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
4065 /// expression, followed by one or more generic associations. Each generic
4066 /// association specifies a type name and an expression, or "default" and an
4067 /// expression (in which case it is known as a default generic association).
4068 /// The type and value of the generic selection are identical to those of its
4069 /// result expression, which is defined as the expression in the generic
4070 /// association with a type name that is compatible with the type of the
4071 /// controlling expression, or the expression in the default generic association
4072 /// if no types are compatible. For example:
4073 ///
4074 /// @code
4075 /// _Generic(X, double: 1, float: 2, default: 3)
4076 /// @endcode
4077 ///
4078 /// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
4079 /// or 3 if "hello".
4080 ///
4081 /// As an extension, generic selections are allowed in C++, where the following
4082 /// additional semantics apply:
4083 ///
4084 /// Any generic selection whose controlling expression is type-dependent or
4085 /// which names a dependent type in its association list is result-dependent,
4086 /// which means that the choice of result expression is dependent.
4087 /// Result-dependent generic associations are both type- and value-dependent.
4088 class GenericSelectionExpr : public Expr {
4089 enum { CONTROLLING, END_EXPR };
4090 TypeSourceInfo **AssocTypes;
4091 Stmt **SubExprs;
4092 unsigned NumAssocs, ResultIndex;
4093 SourceLocation GenericLoc, DefaultLoc, RParenLoc;
4094
4095 public:
4096 GenericSelectionExpr(ASTContext &Context,
4097 SourceLocation GenericLoc, Expr *ControllingExpr,
4098 TypeSourceInfo **AssocTypes, Expr **AssocExprs,
4099 unsigned NumAssocs, SourceLocation DefaultLoc,
4100 SourceLocation RParenLoc,
4101 bool ContainsUnexpandedParameterPack,
4102 unsigned ResultIndex);
4103
4104 /// This constructor is used in the result-dependent case.
4105 GenericSelectionExpr(ASTContext &Context,
4106 SourceLocation GenericLoc, Expr *ControllingExpr,
4107 TypeSourceInfo **AssocTypes, Expr **AssocExprs,
4108 unsigned NumAssocs, SourceLocation DefaultLoc,
4109 SourceLocation RParenLoc,
4110 bool ContainsUnexpandedParameterPack);
4111
GenericSelectionExpr(EmptyShell Empty)4112 explicit GenericSelectionExpr(EmptyShell Empty)
4113 : Expr(GenericSelectionExprClass, Empty) { }
4114
getNumAssocs()4115 unsigned getNumAssocs() const { return NumAssocs; }
4116
getGenericLoc()4117 SourceLocation getGenericLoc() const { return GenericLoc; }
getDefaultLoc()4118 SourceLocation getDefaultLoc() const { return DefaultLoc; }
getRParenLoc()4119 SourceLocation getRParenLoc() const { return RParenLoc; }
4120
getAssocExpr(unsigned i)4121 const Expr *getAssocExpr(unsigned i) const {
4122 return cast<Expr>(SubExprs[END_EXPR+i]);
4123 }
getAssocExpr(unsigned i)4124 Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); }
4125
getAssocTypeSourceInfo(unsigned i)4126 const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const {
4127 return AssocTypes[i];
4128 }
getAssocTypeSourceInfo(unsigned i)4129 TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; }
4130
getAssocType(unsigned i)4131 QualType getAssocType(unsigned i) const {
4132 if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i))
4133 return TS->getType();
4134 else
4135 return QualType();
4136 }
4137
getControllingExpr()4138 const Expr *getControllingExpr() const {
4139 return cast<Expr>(SubExprs[CONTROLLING]);
4140 }
getControllingExpr()4141 Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); }
4142
4143 /// Whether this generic selection is result-dependent.
isResultDependent()4144 bool isResultDependent() const { return ResultIndex == -1U; }
4145
4146 /// The zero-based index of the result expression's generic association in
4147 /// the generic selection's association list. Defined only if the
4148 /// generic selection is not result-dependent.
getResultIndex()4149 unsigned getResultIndex() const {
4150 assert(!isResultDependent() && "Generic selection is result-dependent");
4151 return ResultIndex;
4152 }
4153
4154 /// The generic selection's result expression. Defined only if the
4155 /// generic selection is not result-dependent.
getResultExpr()4156 const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); }
getResultExpr()4157 Expr *getResultExpr() { return getAssocExpr(getResultIndex()); }
4158
getSourceRange()4159 SourceRange getSourceRange() const LLVM_READONLY {
4160 return SourceRange(GenericLoc, RParenLoc);
4161 }
classof(const Stmt * T)4162 static bool classof(const Stmt *T) {
4163 return T->getStmtClass() == GenericSelectionExprClass;
4164 }
classof(const GenericSelectionExpr *)4165 static bool classof(const GenericSelectionExpr *) { return true; }
4166
children()4167 child_range children() {
4168 return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs);
4169 }
4170
4171 friend class ASTStmtReader;
4172 };
4173
4174 //===----------------------------------------------------------------------===//
4175 // Clang Extensions
4176 //===----------------------------------------------------------------------===//
4177
4178
4179 /// ExtVectorElementExpr - This represents access to specific elements of a
4180 /// vector, and may occur on the left hand side or right hand side. For example
4181 /// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector.
4182 ///
4183 /// Note that the base may have either vector or pointer to vector type, just
4184 /// like a struct field reference.
4185 ///
4186 class ExtVectorElementExpr : public Expr {
4187 Stmt *Base;
4188 IdentifierInfo *Accessor;
4189 SourceLocation AccessorLoc;
4190 public:
ExtVectorElementExpr(QualType ty,ExprValueKind VK,Expr * base,IdentifierInfo & accessor,SourceLocation loc)4191 ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
4192 IdentifierInfo &accessor, SourceLocation loc)
4193 : Expr(ExtVectorElementExprClass, ty, VK,
4194 (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent),
4195 base->isTypeDependent(), base->isValueDependent(),
4196 base->isInstantiationDependent(),
4197 base->containsUnexpandedParameterPack()),
4198 Base(base), Accessor(&accessor), AccessorLoc(loc) {}
4199
4200 /// \brief Build an empty vector element expression.
ExtVectorElementExpr(EmptyShell Empty)4201 explicit ExtVectorElementExpr(EmptyShell Empty)
4202 : Expr(ExtVectorElementExprClass, Empty) { }
4203
getBase()4204 const Expr *getBase() const { return cast<Expr>(Base); }
getBase()4205 Expr *getBase() { return cast<Expr>(Base); }
setBase(Expr * E)4206 void setBase(Expr *E) { Base = E; }
4207
getAccessor()4208 IdentifierInfo &getAccessor() const { return *Accessor; }
setAccessor(IdentifierInfo * II)4209 void setAccessor(IdentifierInfo *II) { Accessor = II; }
4210
getAccessorLoc()4211 SourceLocation getAccessorLoc() const { return AccessorLoc; }
setAccessorLoc(SourceLocation L)4212 void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
4213
4214 /// getNumElements - Get the number of components being selected.
4215 unsigned getNumElements() const;
4216
4217 /// containsDuplicateElements - Return true if any element access is
4218 /// repeated.
4219 bool containsDuplicateElements() const;
4220
4221 /// getEncodedElementAccess - Encode the elements accessed into an llvm
4222 /// aggregate Constant of ConstantInt(s).
4223 void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const;
4224
getSourceRange()4225 SourceRange getSourceRange() const LLVM_READONLY {
4226 return SourceRange(getBase()->getLocStart(), AccessorLoc);
4227 }
4228
4229 /// isArrow - Return true if the base expression is a pointer to vector,
4230 /// return false if the base expression is a vector.
4231 bool isArrow() const;
4232
classof(const Stmt * T)4233 static bool classof(const Stmt *T) {
4234 return T->getStmtClass() == ExtVectorElementExprClass;
4235 }
classof(const ExtVectorElementExpr *)4236 static bool classof(const ExtVectorElementExpr *) { return true; }
4237
4238 // Iterators
children()4239 child_range children() { return child_range(&Base, &Base+1); }
4240 };
4241
4242
4243 /// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
4244 /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
4245 class BlockExpr : public Expr {
4246 protected:
4247 BlockDecl *TheBlock;
4248 public:
BlockExpr(BlockDecl * BD,QualType ty)4249 BlockExpr(BlockDecl *BD, QualType ty)
4250 : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
4251 ty->isDependentType(), ty->isDependentType(),
4252 ty->isInstantiationDependentType() || BD->isDependentContext(),
4253 false),
4254 TheBlock(BD) {}
4255
4256 /// \brief Build an empty block expression.
BlockExpr(EmptyShell Empty)4257 explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
4258
getBlockDecl()4259 const BlockDecl *getBlockDecl() const { return TheBlock; }
getBlockDecl()4260 BlockDecl *getBlockDecl() { return TheBlock; }
setBlockDecl(BlockDecl * BD)4261 void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
4262
4263 // Convenience functions for probing the underlying BlockDecl.
4264 SourceLocation getCaretLocation() const;
4265 const Stmt *getBody() const;
4266 Stmt *getBody();
4267
getSourceRange()4268 SourceRange getSourceRange() const LLVM_READONLY {
4269 return SourceRange(getCaretLocation(), getBody()->getLocEnd());
4270 }
4271
4272 /// getFunctionType - Return the underlying function type for this block.
4273 const FunctionProtoType *getFunctionType() const;
4274
classof(const Stmt * T)4275 static bool classof(const Stmt *T) {
4276 return T->getStmtClass() == BlockExprClass;
4277 }
classof(const BlockExpr *)4278 static bool classof(const BlockExpr *) { return true; }
4279
4280 // Iterators
children()4281 child_range children() { return child_range(); }
4282 };
4283
4284 /// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
4285 /// This AST node provides support for reinterpreting a type to another
4286 /// type of the same size.
4287 class AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr?
4288 private:
4289 Stmt *SrcExpr;
4290 SourceLocation BuiltinLoc, RParenLoc;
4291
4292 friend class ASTReader;
4293 friend class ASTStmtReader;
AsTypeExpr(EmptyShell Empty)4294 explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
4295
4296 public:
AsTypeExpr(Expr * SrcExpr,QualType DstType,ExprValueKind VK,ExprObjectKind OK,SourceLocation BuiltinLoc,SourceLocation RParenLoc)4297 AsTypeExpr(Expr* SrcExpr, QualType DstType,
4298 ExprValueKind VK, ExprObjectKind OK,
4299 SourceLocation BuiltinLoc, SourceLocation RParenLoc)
4300 : Expr(AsTypeExprClass, DstType, VK, OK,
4301 DstType->isDependentType(),
4302 DstType->isDependentType() || SrcExpr->isValueDependent(),
4303 (DstType->isInstantiationDependentType() ||
4304 SrcExpr->isInstantiationDependent()),
4305 (DstType->containsUnexpandedParameterPack() ||
4306 SrcExpr->containsUnexpandedParameterPack())),
4307 SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
4308
4309 /// getSrcExpr - Return the Expr to be converted.
getSrcExpr()4310 Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
4311
4312 /// getBuiltinLoc - Return the location of the __builtin_astype token.
getBuiltinLoc()4313 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4314
4315 /// getRParenLoc - Return the location of final right parenthesis.
getRParenLoc()4316 SourceLocation getRParenLoc() const { return RParenLoc; }
4317
getSourceRange()4318 SourceRange getSourceRange() const LLVM_READONLY {
4319 return SourceRange(BuiltinLoc, RParenLoc);
4320 }
4321
classof(const Stmt * T)4322 static bool classof(const Stmt *T) {
4323 return T->getStmtClass() == AsTypeExprClass;
4324 }
classof(const AsTypeExpr *)4325 static bool classof(const AsTypeExpr *) { return true; }
4326
4327 // Iterators
children()4328 child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
4329 };
4330
4331 /// PseudoObjectExpr - An expression which accesses a pseudo-object
4332 /// l-value. A pseudo-object is an abstract object, accesses to which
4333 /// are translated to calls. The pseudo-object expression has a
4334 /// syntactic form, which shows how the expression was actually
4335 /// written in the source code, and a semantic form, which is a series
4336 /// of expressions to be executed in order which detail how the
4337 /// operation is actually evaluated. Optionally, one of the semantic
4338 /// forms may also provide a result value for the expression.
4339 ///
4340 /// If any of the semantic-form expressions is an OpaqueValueExpr,
4341 /// that OVE is required to have a source expression, and it is bound
4342 /// to the result of that source expression. Such OVEs may appear
4343 /// only in subsequent semantic-form expressions and as
4344 /// sub-expressions of the syntactic form.
4345 ///
4346 /// PseudoObjectExpr should be used only when an operation can be
4347 /// usefully described in terms of fairly simple rewrite rules on
4348 /// objects and functions that are meant to be used by end-developers.
4349 /// For example, under the Itanium ABI, dynamic casts are implemented
4350 /// as a call to a runtime function called __dynamic_cast; using this
4351 /// class to describe that would be inappropriate because that call is
4352 /// not really part of the user-visible semantics, and instead the
4353 /// cast is properly reflected in the AST and IR-generation has been
4354 /// taught to generate the call as necessary. In contrast, an
4355 /// Objective-C property access is semantically defined to be
4356 /// equivalent to a particular message send, and this is very much
4357 /// part of the user model. The name of this class encourages this
4358 /// modelling design.
4359 class PseudoObjectExpr : public Expr {
4360 // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
4361 // Always at least two, because the first sub-expression is the
4362 // syntactic form.
4363
4364 // PseudoObjectExprBits.ResultIndex - The index of the
4365 // sub-expression holding the result. 0 means the result is void,
4366 // which is unambiguous because it's the index of the syntactic
4367 // form. Note that this is therefore 1 higher than the value passed
4368 // in to Create, which is an index within the semantic forms.
4369 // Note also that ASTStmtWriter assumes this encoding.
4370
getSubExprsBuffer()4371 Expr **getSubExprsBuffer() { return reinterpret_cast<Expr**>(this + 1); }
getSubExprsBuffer()4372 const Expr * const *getSubExprsBuffer() const {
4373 return reinterpret_cast<const Expr * const *>(this + 1);
4374 }
4375
4376 friend class ASTStmtReader;
4377
4378 PseudoObjectExpr(QualType type, ExprValueKind VK,
4379 Expr *syntactic, ArrayRef<Expr*> semantic,
4380 unsigned resultIndex);
4381
4382 PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
4383
getNumSubExprs()4384 unsigned getNumSubExprs() const {
4385 return PseudoObjectExprBits.NumSubExprs;
4386 }
4387
4388 public:
4389 /// NoResult - A value for the result index indicating that there is
4390 /// no semantic result.
4391 enum { NoResult = ~0U };
4392
4393 static PseudoObjectExpr *Create(ASTContext &Context, Expr *syntactic,
4394 ArrayRef<Expr*> semantic,
4395 unsigned resultIndex);
4396
4397 static PseudoObjectExpr *Create(ASTContext &Context, EmptyShell shell,
4398 unsigned numSemanticExprs);
4399
4400 /// Return the syntactic form of this expression, i.e. the
4401 /// expression it actually looks like. Likely to be expressed in
4402 /// terms of OpaqueValueExprs bound in the semantic form.
getSyntacticForm()4403 Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; }
getSyntacticForm()4404 const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; }
4405
4406 /// Return the index of the result-bearing expression into the semantics
4407 /// expressions, or PseudoObjectExpr::NoResult if there is none.
getResultExprIndex()4408 unsigned getResultExprIndex() const {
4409 if (PseudoObjectExprBits.ResultIndex == 0) return NoResult;
4410 return PseudoObjectExprBits.ResultIndex - 1;
4411 }
4412
4413 /// Return the result-bearing expression, or null if there is none.
getResultExpr()4414 Expr *getResultExpr() {
4415 if (PseudoObjectExprBits.ResultIndex == 0)
4416 return 0;
4417 return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex];
4418 }
getResultExpr()4419 const Expr *getResultExpr() const {
4420 return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
4421 }
4422
getNumSemanticExprs()4423 unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
4424
4425 typedef Expr * const *semantics_iterator;
4426 typedef const Expr * const *const_semantics_iterator;
semantics_begin()4427 semantics_iterator semantics_begin() {
4428 return getSubExprsBuffer() + 1;
4429 }
semantics_begin()4430 const_semantics_iterator semantics_begin() const {
4431 return getSubExprsBuffer() + 1;
4432 }
semantics_end()4433 semantics_iterator semantics_end() {
4434 return getSubExprsBuffer() + getNumSubExprs();
4435 }
semantics_end()4436 const_semantics_iterator semantics_end() const {
4437 return getSubExprsBuffer() + getNumSubExprs();
4438 }
getSemanticExpr(unsigned index)4439 Expr *getSemanticExpr(unsigned index) {
4440 assert(index + 1 < getNumSubExprs());
4441 return getSubExprsBuffer()[index + 1];
4442 }
getSemanticExpr(unsigned index)4443 const Expr *getSemanticExpr(unsigned index) const {
4444 return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
4445 }
4446
getExprLoc()4447 SourceLocation getExprLoc() const LLVM_READONLY {
4448 return getSyntacticForm()->getExprLoc();
4449 }
getSourceRange()4450 SourceRange getSourceRange() const LLVM_READONLY {
4451 return getSyntacticForm()->getSourceRange();
4452 }
4453
children()4454 child_range children() {
4455 Stmt **cs = reinterpret_cast<Stmt**>(getSubExprsBuffer());
4456 return child_range(cs, cs + getNumSubExprs());
4457 }
4458
classof(const Stmt * T)4459 static bool classof(const Stmt *T) {
4460 return T->getStmtClass() == PseudoObjectExprClass;
4461 }
classof(const PseudoObjectExpr *)4462 static bool classof(const PseudoObjectExpr *) { return true; }
4463 };
4464
4465 /// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*,
4466 /// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the
4467 /// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>.
4468 /// All of these instructions take one primary pointer and at least one memory
4469 /// order.
4470 class AtomicExpr : public Expr {
4471 public:
4472 enum AtomicOp {
4473 #define BUILTIN(ID, TYPE, ATTRS)
4474 #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
4475 #include "clang/Basic/Builtins.def"
4476 // Avoid trailing comma
4477 BI_First = 0
4478 };
4479
4480 private:
4481 enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR };
4482 Stmt* SubExprs[END_EXPR];
4483 unsigned NumSubExprs;
4484 SourceLocation BuiltinLoc, RParenLoc;
4485 AtomicOp Op;
4486
4487 friend class ASTStmtReader;
4488
4489 public:
4490 AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, QualType t,
4491 AtomicOp op, SourceLocation RP);
4492
4493 /// \brief Determine the number of arguments the specified atomic builtin
4494 /// should have.
4495 static unsigned getNumSubExprs(AtomicOp Op);
4496
4497 /// \brief Build an empty AtomicExpr.
AtomicExpr(EmptyShell Empty)4498 explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { }
4499
getPtr()4500 Expr *getPtr() const {
4501 return cast<Expr>(SubExprs[PTR]);
4502 }
getOrder()4503 Expr *getOrder() const {
4504 return cast<Expr>(SubExprs[ORDER]);
4505 }
getVal1()4506