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