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