Expr.h revision 569c3166874324c24011f8ade6978421f0d39b3c
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/ASTVector.h" 22#include "clang/AST/UsuallyTinyPtrVector.h" 23#include "llvm/ADT/APSInt.h" 24#include "llvm/ADT/APFloat.h" 25#include "llvm/ADT/SmallVector.h" 26#include "llvm/ADT/StringRef.h" 27#include <vector> 28 29namespace clang { 30 class ASTContext; 31 class APValue; 32 class Decl; 33 class IdentifierInfo; 34 class ParmVarDecl; 35 class NamedDecl; 36 class ValueDecl; 37 class BlockDecl; 38 class CXXBaseSpecifier; 39 class CXXOperatorCallExpr; 40 class CXXMemberCallExpr; 41 class TemplateArgumentLoc; 42 class TemplateArgumentListInfo; 43 44/// \brief A simple array of base specifiers. 45typedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 46 47/// Expr - This represents one expression. Note that Expr's are subclasses of 48/// Stmt. This allows an expression to be transparently used any place a Stmt 49/// is required. 50/// 51class Expr : public Stmt { 52 QualType TR; 53 54 virtual void ANCHOR(); // key function. 55protected: 56 /// TypeDependent - Whether this expression is type-dependent 57 /// (C++ [temp.dep.expr]). 58 bool TypeDependent : 1; 59 60 /// ValueDependent - Whether this expression is value-dependent 61 /// (C++ [temp.dep.constexpr]). 62 bool ValueDependent : 1; 63 64 enum { BitsRemaining = 30 }; 65 66 Expr(StmtClass SC, QualType T, bool TD, bool VD) 67 : Stmt(SC), TypeDependent(TD), ValueDependent(VD) { 68 setType(T); 69 } 70 71 /// \brief Construct an empty expression. 72 explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 73 74public: 75 /// \brief Increases the reference count for this expression. 76 /// 77 /// Invoke the Retain() operation when this expression 78 /// is being shared by another owner. 79 Expr *Retain() { 80 Stmt::Retain(); 81 return this; 82 } 83 84 QualType getType() const { return TR; } 85 void setType(QualType t) { 86 // In C++, the type of an expression is always adjusted so that it 87 // will not have reference type an expression will never have 88 // reference type (C++ [expr]p6). Use 89 // QualType::getNonReferenceType() to retrieve the non-reference 90 // type. Additionally, inspect Expr::isLvalue to determine whether 91 // an expression that is adjusted in this manner should be 92 // considered an lvalue. 93 assert((t.isNull() || !t->isReferenceType()) && 94 "Expressions can't have reference type"); 95 96 TR = t; 97 } 98 99 /// isValueDependent - Determines whether this expression is 100 /// value-dependent (C++ [temp.dep.constexpr]). For example, the 101 /// array bound of "Chars" in the following example is 102 /// value-dependent. 103 /// @code 104 /// template<int Size, char (&Chars)[Size]> struct meta_string; 105 /// @endcode 106 bool isValueDependent() const { return ValueDependent; } 107 108 /// \brief Set whether this expression is value-dependent or not. 109 void setValueDependent(bool VD) { ValueDependent = VD; } 110 111 /// isTypeDependent - Determines whether this expression is 112 /// type-dependent (C++ [temp.dep.expr]), which means that its type 113 /// could change from one template instantiation to the next. For 114 /// example, the expressions "x" and "x + y" are type-dependent in 115 /// the following code, but "y" is not type-dependent: 116 /// @code 117 /// template<typename T> 118 /// void add(T x, int y) { 119 /// x + y; 120 /// } 121 /// @endcode 122 bool isTypeDependent() const { return TypeDependent; } 123 124 /// \brief Set whether this expression is type-dependent or not. 125 void setTypeDependent(bool TD) { TypeDependent = TD; } 126 127 /// SourceLocation tokens are not useful in isolation - they are low level 128 /// value objects created/interpreted by SourceManager. We assume AST 129 /// clients will have a pointer to the respective SourceManager. 130 virtual SourceRange getSourceRange() const = 0; 131 132 /// getExprLoc - Return the preferred location for the arrow when diagnosing 133 /// a problem with a generic expression. 134 virtual SourceLocation getExprLoc() const { return getLocStart(); } 135 136 /// isUnusedResultAWarning - Return true if this immediate expression should 137 /// be warned about if the result is unused. If so, fill in Loc and Ranges 138 /// with location to warn on and the source range[s] to report with the 139 /// warning. 140 bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 141 SourceRange &R2, ASTContext &Ctx) const; 142 143 /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 144 /// incomplete type other than void. Nonarray expressions that can be lvalues: 145 /// - name, where name must be a variable 146 /// - e[i] 147 /// - (e), where e must be an lvalue 148 /// - e.name, where e must be an lvalue 149 /// - e->name 150 /// - *e, the type of e cannot be a function type 151 /// - string-constant 152 /// - reference type [C++ [expr]] 153 /// - b ? x : y, where x and y are lvalues of suitable types [C++] 154 /// 155 enum isLvalueResult { 156 LV_Valid, 157 LV_NotObjectType, 158 LV_IncompleteVoidType, 159 LV_DuplicateVectorComponents, 160 LV_InvalidExpression, 161 LV_MemberFunction, 162 LV_SubObjCPropertySetting, 163 LV_ClassTemporary 164 }; 165 isLvalueResult isLvalue(ASTContext &Ctx) const; 166 167 /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 168 /// does not have an incomplete type, does not have a const-qualified type, 169 /// and if it is a structure or union, does not have any member (including, 170 /// recursively, any member or element of all contained aggregates or unions) 171 /// with a const-qualified type. 172 /// 173 /// \param Loc [in] [out] - A source location which *may* be filled 174 /// in with the location of the expression making this a 175 /// non-modifiable lvalue, if specified. 176 enum isModifiableLvalueResult { 177 MLV_Valid, 178 MLV_NotObjectType, 179 MLV_IncompleteVoidType, 180 MLV_DuplicateVectorComponents, 181 MLV_InvalidExpression, 182 MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 183 MLV_IncompleteType, 184 MLV_ConstQualified, 185 MLV_ArrayType, 186 MLV_NotBlockQualified, 187 MLV_ReadonlyProperty, 188 MLV_NoSetterProperty, 189 MLV_MemberFunction, 190 MLV_SubObjCPropertySetting, 191 MLV_ClassTemporary 192 }; 193 isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 194 SourceLocation *Loc = 0) const; 195 196 /// \brief The return type of classify(). Represents the C++0x expression 197 /// taxonomy. 198 class Classification { 199 public: 200 /// \brief The various classification results. Most of these mean prvalue. 201 enum Kinds { 202 CL_LValue, 203 CL_XValue, 204 CL_Function, // Functions cannot be lvalues in C. 205 CL_Void, // Void cannot be an lvalue in C. 206 CL_DuplicateVectorComponents, // A vector shuffle with dupes. 207 CL_MemberFunction, // An expression referring to a member function 208 CL_SubObjCPropertySetting, 209 CL_ClassTemporary, // A prvalue of class type 210 CL_PRValue // A prvalue for any other reason, of any other type 211 }; 212 /// \brief The results of modification testing. 213 enum ModifiableType { 214 CM_Untested, // testModifiable was false. 215 CM_Modifiable, 216 CM_RValue, // Not modifiable because it's an rvalue 217 CM_Function, // Not modifiable because it's a function; C++ only 218 CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 219 CM_NotBlockQualified, // Not captured in the closure 220 CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 221 CM_ConstQualified, 222 CM_ArrayType, 223 CM_IncompleteType 224 }; 225 226 private: 227 friend class Expr; 228 229 unsigned short Kind; 230 unsigned short Modifiable; 231 232 explicit Classification(Kinds k, ModifiableType m) 233 : Kind(k), Modifiable(m) 234 {} 235 236 public: 237 Classification() {} 238 239 Kinds getKind() const { return static_cast<Kinds>(Kind); } 240 ModifiableType getModifiable() const { 241 assert(Modifiable != CM_Untested && "Did not test for modifiability."); 242 return static_cast<ModifiableType>(Modifiable); 243 } 244 bool isLValue() const { return Kind == CL_LValue; } 245 bool isXValue() const { return Kind == CL_XValue; } 246 bool isGLValue() const { return Kind <= CL_XValue; } 247 bool isPRValue() const { return Kind >= CL_Function; } 248 bool isRValue() const { return Kind >= CL_XValue; } 249 bool isModifiable() const { return getModifiable() == CM_Modifiable; } 250 }; 251 /// \brief classify - Classify this expression according to the C++0x 252 /// expression taxonomy. 253 /// 254 /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 255 /// old lvalue vs rvalue. This function determines the type of expression this 256 /// is. There are three expression types: 257 /// - lvalues are classical lvalues as in C++03. 258 /// - prvalues are equivalent to rvalues in C++03. 259 /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 260 /// function returning an rvalue reference. 261 /// lvalues and xvalues are collectively referred to as glvalues, while 262 /// prvalues and xvalues together form rvalues. 263 Classification Classify(ASTContext &Ctx) const { 264 return ClassifyImpl(Ctx, 0); 265 } 266 267 /// \brief classifyModifiable - Classify this expression according to the 268 /// C++0x expression taxonomy, and see if it is valid on the left side 269 /// of an assignment. 270 /// 271 /// This function extends classify in that it also tests whether the 272 /// expression is modifiable (C99 6.3.2.1p1). 273 /// \param Loc A source location that might be filled with a relevant location 274 /// if the expression is not modifiable. 275 Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 276 return ClassifyImpl(Ctx, &Loc); 277 } 278 279private: 280 Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 281 282public: 283 284 /// \brief If this expression refers to a bit-field, retrieve the 285 /// declaration of that bit-field. 286 FieldDecl *getBitField(); 287 288 const FieldDecl *getBitField() const { 289 return const_cast<Expr*>(this)->getBitField(); 290 } 291 292 /// \brief Returns whether this expression refers to a vector element. 293 bool refersToVectorElement() const; 294 295 /// isKnownToHaveBooleanValue - Return true if this is an integer expression 296 /// that is known to return 0 or 1. This happens for _Bool/bool expressions 297 /// but also int expressions which are produced by things like comparisons in 298 /// C. 299 bool isKnownToHaveBooleanValue() const; 300 301 /// isIntegerConstantExpr - Return true if this expression is a valid integer 302 /// constant expression, and, if so, return its value in Result. If not a 303 /// valid i-c-e, return false and fill in Loc (if specified) with the location 304 /// of the invalid expression. 305 bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 306 SourceLocation *Loc = 0, 307 bool isEvaluated = true) const; 308 bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 309 llvm::APSInt X; 310 return isIntegerConstantExpr(X, Ctx, Loc); 311 } 312 /// isConstantInitializer - Returns true if this expression is a constant 313 /// initializer, which can be emitted at compile-time. 314 bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 315 316 /// EvalResult is a struct with detailed info about an evaluated expression. 317 struct EvalResult { 318 /// Val - This is the value the expression can be folded to. 319 APValue Val; 320 321 /// HasSideEffects - Whether the evaluated expression has side effects. 322 /// For example, (f() && 0) can be folded, but it still has side effects. 323 bool HasSideEffects; 324 325 /// Diag - If the expression is unfoldable, then Diag contains a note 326 /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 327 /// position for the error, and DiagExpr is the expression that caused 328 /// the error. 329 /// If the expression is foldable, but not an integer constant expression, 330 /// Diag contains a note diagnostic that describes why it isn't an integer 331 /// constant expression. If the expression *is* an integer constant 332 /// expression, then Diag will be zero. 333 unsigned Diag; 334 const Expr *DiagExpr; 335 SourceLocation DiagLoc; 336 337 EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 338 339 // isGlobalLValue - Return true if the evaluated lvalue expression 340 // is global. 341 bool isGlobalLValue() const; 342 // hasSideEffects - Return true if the evaluated expression has 343 // side effects. 344 bool hasSideEffects() const { 345 return HasSideEffects; 346 } 347 }; 348 349 /// Evaluate - Return true if this is a constant which we can fold using 350 /// any crazy technique (that has nothing to do with language standards) that 351 /// we want to. If this function returns true, it returns the folded constant 352 /// in Result. 353 bool Evaluate(EvalResult &Result, ASTContext &Ctx) const; 354 355 /// EvaluateAsBooleanCondition - Return true if this is a constant 356 /// which we we can fold and convert to a boolean condition using 357 /// any crazy technique that we want to. 358 bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const; 359 360 /// isEvaluatable - Call Evaluate to see if this expression can be constant 361 /// folded, but discard the result. 362 bool isEvaluatable(ASTContext &Ctx) const; 363 364 /// HasSideEffects - This routine returns true for all those expressions 365 /// which must be evaluated each time and must not be optimization away 366 /// or evaluated at compile time. Example is a function call, volatile 367 /// variable read. 368 bool HasSideEffects(ASTContext &Ctx) const; 369 370 /// EvaluateAsInt - Call Evaluate and return the folded integer. This 371 /// must be called on an expression that constant folds to an integer. 372 llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const; 373 374 /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 375 /// with link time known address. 376 bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const; 377 378 /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 379 bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const; 380 381 /// \brief Enumeration used to describe how \c isNullPointerConstant() 382 /// should cope with value-dependent expressions. 383 enum NullPointerConstantValueDependence { 384 /// \brief Specifies that the expression should never be value-dependent. 385 NPC_NeverValueDependent = 0, 386 387 /// \brief Specifies that a value-dependent expression of integral or 388 /// dependent type should be considered a null pointer constant. 389 NPC_ValueDependentIsNull, 390 391 /// \brief Specifies that a value-dependent expression should be considered 392 /// to never be a null pointer constant. 393 NPC_ValueDependentIsNotNull 394 }; 395 396 /// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 397 /// integer constant expression with the value zero, or if this is one that is 398 /// cast to void*. 399 bool isNullPointerConstant(ASTContext &Ctx, 400 NullPointerConstantValueDependence NPC) const; 401 402 /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 403 /// write barrier. 404 bool isOBJCGCCandidate(ASTContext &Ctx) const; 405 406 /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 407 /// its subexpression. If that subexpression is also a ParenExpr, 408 /// then this method recursively returns its subexpression, and so forth. 409 /// Otherwise, the method returns the current Expr. 410 Expr *IgnoreParens(); 411 412 /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 413 /// or CastExprs, returning their operand. 414 Expr *IgnoreParenCasts(); 415 416 /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 417 /// ParenExpr or ImplicitCastExprs, returning their operand. 418 Expr *IgnoreParenImpCasts(); 419 420 /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 421 /// value (including ptr->int casts of the same size). Strip off any 422 /// ParenExpr or CastExprs, returning their operand. 423 Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 424 425 /// \brief Determine whether this expression is a default function argument. 426 /// 427 /// Default arguments are implicitly generated in the abstract syntax tree 428 /// by semantic analysis for function calls, object constructions, etc. in 429 /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 430 /// this routine also looks through any implicit casts to determine whether 431 /// the expression is a default argument. 432 bool isDefaultArgument() const; 433 434 /// \brief Determine whether this expression directly creates a 435 /// temporary object (of class type). 436 bool isTemporaryObject() const { return getTemporaryObject() != 0; } 437 438 /// \brief If this expression directly creates a temporary object of 439 /// class type, return the expression that actually constructs that 440 /// temporary object. 441 const Expr *getTemporaryObject() const; 442 443 const Expr *IgnoreParens() const { 444 return const_cast<Expr*>(this)->IgnoreParens(); 445 } 446 const Expr *IgnoreParenCasts() const { 447 return const_cast<Expr*>(this)->IgnoreParenCasts(); 448 } 449 const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 450 return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 451 } 452 453 static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 454 static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 455 456 static bool classof(const Stmt *T) { 457 return T->getStmtClass() >= firstExprConstant && 458 T->getStmtClass() <= lastExprConstant; 459 } 460 static bool classof(const Expr *) { return true; } 461}; 462 463 464//===----------------------------------------------------------------------===// 465// Primary Expressions. 466//===----------------------------------------------------------------------===// 467 468/// \brief Represents the qualifier that may precede a C++ name, e.g., the 469/// "std::" in "std::sort". 470struct NameQualifier { 471 /// \brief The nested name specifier. 472 NestedNameSpecifier *NNS; 473 474 /// \brief The source range covered by the nested name specifier. 475 SourceRange Range; 476}; 477 478/// \brief Represents an explicit template argument list in C++, e.g., 479/// the "<int>" in "sort<int>". 480struct ExplicitTemplateArgumentList { 481 /// \brief The source location of the left angle bracket ('<'); 482 SourceLocation LAngleLoc; 483 484 /// \brief The source location of the right angle bracket ('>'); 485 SourceLocation RAngleLoc; 486 487 /// \brief The number of template arguments in TemplateArgs. 488 /// The actual template arguments (if any) are stored after the 489 /// ExplicitTemplateArgumentList structure. 490 unsigned NumTemplateArgs; 491 492 /// \brief Retrieve the template arguments 493 TemplateArgumentLoc *getTemplateArgs() { 494 return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 495 } 496 497 /// \brief Retrieve the template arguments 498 const TemplateArgumentLoc *getTemplateArgs() const { 499 return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 500 } 501 502 void initializeFrom(const TemplateArgumentListInfo &List); 503 void copyInto(TemplateArgumentListInfo &List) const; 504 static std::size_t sizeFor(unsigned NumTemplateArgs); 505 static std::size_t sizeFor(const TemplateArgumentListInfo &List); 506}; 507 508/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 509/// enum, etc. 510class DeclRefExpr : public Expr { 511 enum { 512 // Flag on DecoratedD that specifies when this declaration reference 513 // expression has a C++ nested-name-specifier. 514 HasQualifierFlag = 0x01, 515 // Flag on DecoratedD that specifies when this declaration reference 516 // expression has an explicit C++ template argument list. 517 HasExplicitTemplateArgumentListFlag = 0x02 518 }; 519 520 // DecoratedD - The declaration that we are referencing, plus two bits to 521 // indicate whether (1) the declaration's name was explicitly qualified and 522 // (2) the declaration's name was followed by an explicit template 523 // argument list. 524 llvm::PointerIntPair<ValueDecl *, 2> DecoratedD; 525 526 // Loc - The location of the declaration name itself. 527 SourceLocation Loc; 528 529 /// \brief Retrieve the qualifier that preceded the declaration name, if any. 530 NameQualifier *getNameQualifier() { 531 if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 532 return 0; 533 534 return reinterpret_cast<NameQualifier *> (this + 1); 535 } 536 537 /// \brief Retrieve the qualifier that preceded the member name, if any. 538 const NameQualifier *getNameQualifier() const { 539 return const_cast<DeclRefExpr *>(this)->getNameQualifier(); 540 } 541 542 /// \brief Retrieve the explicit template argument list that followed the 543 /// member template name, if any. 544 ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 545 if ((DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag) == 0) 546 return 0; 547 548 if ((DecoratedD.getInt() & HasQualifierFlag) == 0) 549 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 550 551 return reinterpret_cast<ExplicitTemplateArgumentList *>( 552 getNameQualifier() + 1); 553 } 554 555 /// \brief Retrieve the explicit template argument list that followed the 556 /// member template name, if any. 557 const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 558 return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgumentList(); 559 } 560 561 DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange, 562 ValueDecl *D, SourceLocation NameLoc, 563 const TemplateArgumentListInfo *TemplateArgs, 564 QualType T); 565 566 /// \brief Construct an empty declaration reference expression. 567 explicit DeclRefExpr(EmptyShell Empty) 568 : Expr(DeclRefExprClass, Empty) { } 569 570 /// \brief Computes the type- and value-dependence flags for this 571 /// declaration reference expression. 572 void computeDependence(); 573 574public: 575 DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) : 576 Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) { 577 computeDependence(); 578 } 579 580 static DeclRefExpr *Create(ASTContext &Context, 581 NestedNameSpecifier *Qualifier, 582 SourceRange QualifierRange, 583 ValueDecl *D, 584 SourceLocation NameLoc, 585 QualType T, 586 const TemplateArgumentListInfo *TemplateArgs = 0); 587 588 /// \brief Construct an empty declaration reference expression. 589 static DeclRefExpr *CreateEmpty(ASTContext &Context, 590 bool HasQualifier, unsigned NumTemplateArgs); 591 592 ValueDecl *getDecl() { return DecoratedD.getPointer(); } 593 const ValueDecl *getDecl() const { return DecoratedD.getPointer(); } 594 void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); } 595 596 SourceLocation getLocation() const { return Loc; } 597 void setLocation(SourceLocation L) { Loc = L; } 598 virtual SourceRange getSourceRange() const; 599 600 /// \brief Determine whether this declaration reference was preceded by a 601 /// C++ nested-name-specifier, e.g., \c N::foo. 602 bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; } 603 604 /// \brief If the name was qualified, retrieves the source range of 605 /// the nested-name-specifier that precedes the name. Otherwise, 606 /// returns an empty source range. 607 SourceRange getQualifierRange() const { 608 if (!hasQualifier()) 609 return SourceRange(); 610 611 return getNameQualifier()->Range; 612 } 613 614 /// \brief If the name was qualified, retrieves the nested-name-specifier 615 /// that precedes the name. Otherwise, returns NULL. 616 NestedNameSpecifier *getQualifier() const { 617 if (!hasQualifier()) 618 return 0; 619 620 return getNameQualifier()->NNS; 621 } 622 623 /// \brief Determines whether this member expression actually had a C++ 624 /// template argument list explicitly specified, e.g., x.f<int>. 625 bool hasExplicitTemplateArgumentList() const { 626 return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag; 627 } 628 629 /// \brief Copies the template arguments (if present) into the given 630 /// structure. 631 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 632 if (hasExplicitTemplateArgumentList()) 633 getExplicitTemplateArgumentList()->copyInto(List); 634 } 635 636 /// \brief Retrieve the location of the left angle bracket following the 637 /// member name ('<'), if any. 638 SourceLocation getLAngleLoc() const { 639 if (!hasExplicitTemplateArgumentList()) 640 return SourceLocation(); 641 642 return getExplicitTemplateArgumentList()->LAngleLoc; 643 } 644 645 /// \brief Retrieve the template arguments provided as part of this 646 /// template-id. 647 const TemplateArgumentLoc *getTemplateArgs() const { 648 if (!hasExplicitTemplateArgumentList()) 649 return 0; 650 651 return getExplicitTemplateArgumentList()->getTemplateArgs(); 652 } 653 654 /// \brief Retrieve the number of template arguments provided as part of this 655 /// template-id. 656 unsigned getNumTemplateArgs() const { 657 if (!hasExplicitTemplateArgumentList()) 658 return 0; 659 660 return getExplicitTemplateArgumentList()->NumTemplateArgs; 661 } 662 663 /// \brief Retrieve the location of the right angle bracket following the 664 /// template arguments ('>'). 665 SourceLocation getRAngleLoc() const { 666 if (!hasExplicitTemplateArgumentList()) 667 return SourceLocation(); 668 669 return getExplicitTemplateArgumentList()->RAngleLoc; 670 } 671 672 static bool classof(const Stmt *T) { 673 return T->getStmtClass() == DeclRefExprClass; 674 } 675 static bool classof(const DeclRefExpr *) { return true; } 676 677 // Iterators 678 virtual child_iterator child_begin(); 679 virtual child_iterator child_end(); 680 681 friend class PCHStmtReader; 682 friend class PCHStmtWriter; 683}; 684 685/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 686class PredefinedExpr : public Expr { 687public: 688 enum IdentType { 689 Func, 690 Function, 691 PrettyFunction, 692 /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 693 /// 'virtual' keyword is omitted for virtual member functions. 694 PrettyFunctionNoVirtual 695 }; 696 697private: 698 SourceLocation Loc; 699 IdentType Type; 700public: 701 PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 702 : Expr(PredefinedExprClass, type, type->isDependentType(), 703 type->isDependentType()), Loc(l), Type(IT) {} 704 705 /// \brief Construct an empty predefined expression. 706 explicit PredefinedExpr(EmptyShell Empty) 707 : Expr(PredefinedExprClass, Empty) { } 708 709 IdentType getIdentType() const { return Type; } 710 void setIdentType(IdentType IT) { Type = IT; } 711 712 SourceLocation getLocation() const { return Loc; } 713 void setLocation(SourceLocation L) { Loc = L; } 714 715 static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 716 717 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 718 719 static bool classof(const Stmt *T) { 720 return T->getStmtClass() == PredefinedExprClass; 721 } 722 static bool classof(const PredefinedExpr *) { return true; } 723 724 // Iterators 725 virtual child_iterator child_begin(); 726 virtual child_iterator child_end(); 727}; 728 729class IntegerLiteral : public Expr { 730 llvm::APInt Value; 731 SourceLocation Loc; 732public: 733 // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 734 // or UnsignedLongLongTy 735 IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 736 : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) { 737 assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 738 } 739 740 /// \brief Construct an empty integer literal. 741 explicit IntegerLiteral(EmptyShell Empty) 742 : Expr(IntegerLiteralClass, Empty) { } 743 744 const llvm::APInt &getValue() const { return Value; } 745 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 746 747 /// \brief Retrieve the location of the literal. 748 SourceLocation getLocation() const { return Loc; } 749 750 void setValue(const llvm::APInt &Val) { Value = Val; } 751 void setLocation(SourceLocation Location) { Loc = Location; } 752 753 static bool classof(const Stmt *T) { 754 return T->getStmtClass() == IntegerLiteralClass; 755 } 756 static bool classof(const IntegerLiteral *) { return true; } 757 758 // Iterators 759 virtual child_iterator child_begin(); 760 virtual child_iterator child_end(); 761}; 762 763class CharacterLiteral : public Expr { 764 unsigned Value; 765 SourceLocation Loc; 766 bool IsWide; 767public: 768 // type should be IntTy 769 CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 770 : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l), 771 IsWide(iswide) { 772 } 773 774 /// \brief Construct an empty character literal. 775 CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 776 777 SourceLocation getLocation() const { return Loc; } 778 bool isWide() const { return IsWide; } 779 780 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 781 782 unsigned getValue() const { return Value; } 783 784 void setLocation(SourceLocation Location) { Loc = Location; } 785 void setWide(bool W) { IsWide = W; } 786 void setValue(unsigned Val) { Value = Val; } 787 788 static bool classof(const Stmt *T) { 789 return T->getStmtClass() == CharacterLiteralClass; 790 } 791 static bool classof(const CharacterLiteral *) { return true; } 792 793 // Iterators 794 virtual child_iterator child_begin(); 795 virtual child_iterator child_end(); 796}; 797 798class FloatingLiteral : public Expr { 799 llvm::APFloat Value; 800 bool IsExact : 1; 801 SourceLocation Loc; 802public: 803 FloatingLiteral(const llvm::APFloat &V, bool isexact, 804 QualType Type, SourceLocation L) 805 : Expr(FloatingLiteralClass, Type, false, false), Value(V), 806 IsExact(isexact), Loc(L) {} 807 808 /// \brief Construct an empty floating-point literal. 809 explicit FloatingLiteral(EmptyShell Empty) 810 : Expr(FloatingLiteralClass, Empty), Value(0.0) { } 811 812 const llvm::APFloat &getValue() const { return Value; } 813 void setValue(const llvm::APFloat &Val) { Value = Val; } 814 815 bool isExact() const { return IsExact; } 816 void setExact(bool E) { IsExact = E; } 817 818 /// getValueAsApproximateDouble - This returns the value as an inaccurate 819 /// double. Note that this may cause loss of precision, but is useful for 820 /// debugging dumps, etc. 821 double getValueAsApproximateDouble() const; 822 823 SourceLocation getLocation() const { return Loc; } 824 void setLocation(SourceLocation L) { Loc = L; } 825 826 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 827 828 static bool classof(const Stmt *T) { 829 return T->getStmtClass() == FloatingLiteralClass; 830 } 831 static bool classof(const FloatingLiteral *) { return true; } 832 833 // Iterators 834 virtual child_iterator child_begin(); 835 virtual child_iterator child_end(); 836}; 837 838/// ImaginaryLiteral - We support imaginary integer and floating point literals, 839/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 840/// IntegerLiteral classes. Instances of this class always have a Complex type 841/// whose element type matches the subexpression. 842/// 843class ImaginaryLiteral : public Expr { 844 Stmt *Val; 845public: 846 ImaginaryLiteral(Expr *val, QualType Ty) 847 : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {} 848 849 /// \brief Build an empty imaginary literal. 850 explicit ImaginaryLiteral(EmptyShell Empty) 851 : Expr(ImaginaryLiteralClass, Empty) { } 852 853 const Expr *getSubExpr() const { return cast<Expr>(Val); } 854 Expr *getSubExpr() { return cast<Expr>(Val); } 855 void setSubExpr(Expr *E) { Val = E; } 856 857 virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 858 static bool classof(const Stmt *T) { 859 return T->getStmtClass() == ImaginaryLiteralClass; 860 } 861 static bool classof(const ImaginaryLiteral *) { return true; } 862 863 // Iterators 864 virtual child_iterator child_begin(); 865 virtual child_iterator child_end(); 866}; 867 868/// StringLiteral - This represents a string literal expression, e.g. "foo" 869/// or L"bar" (wide strings). The actual string is returned by getStrData() 870/// is NOT null-terminated, and the length of the string is determined by 871/// calling getByteLength(). The C type for a string is always a 872/// ConstantArrayType. In C++, the char type is const qualified, in C it is 873/// not. 874/// 875/// Note that strings in C can be formed by concatenation of multiple string 876/// literal pptokens in translation phase #6. This keeps track of the locations 877/// of each of these pieces. 878/// 879/// Strings in C can also be truncated and extended by assigning into arrays, 880/// e.g. with constructs like: 881/// char X[2] = "foobar"; 882/// In this case, getByteLength() will return 6, but the string literal will 883/// have type "char[2]". 884class StringLiteral : public Expr { 885 const char *StrData; 886 unsigned ByteLength; 887 bool IsWide; 888 unsigned NumConcatenated; 889 SourceLocation TokLocs[1]; 890 891 StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {} 892 893public: 894 /// This is the "fully general" constructor that allows representation of 895 /// strings formed from multiple concatenated tokens. 896 static StringLiteral *Create(ASTContext &C, const char *StrData, 897 unsigned ByteLength, bool Wide, QualType Ty, 898 const SourceLocation *Loc, unsigned NumStrs); 899 900 /// Simple constructor for string literals made from one token. 901 static StringLiteral *Create(ASTContext &C, const char *StrData, 902 unsigned ByteLength, 903 bool Wide, QualType Ty, SourceLocation Loc) { 904 return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); 905 } 906 907 /// \brief Construct an empty string literal. 908 static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 909 910 llvm::StringRef getString() const { 911 return llvm::StringRef(StrData, ByteLength); 912 } 913 // FIXME: These are deprecated, replace with StringRef. 914 const char *getStrData() const { return StrData; } 915 unsigned getByteLength() const { return ByteLength; } 916 917 /// \brief Sets the string data to the given string data. 918 void setString(ASTContext &C, llvm::StringRef Str); 919 920 bool isWide() const { return IsWide; } 921 void setWide(bool W) { IsWide = W; } 922 923 bool containsNonAsciiOrNull() const { 924 llvm::StringRef Str = getString(); 925 for (unsigned i = 0, e = Str.size(); i != e; ++i) 926 if (!isascii(Str[i]) || !Str[i]) 927 return true; 928 return false; 929 } 930 /// getNumConcatenated - Get the number of string literal tokens that were 931 /// concatenated in translation phase #6 to form this string literal. 932 unsigned getNumConcatenated() const { return NumConcatenated; } 933 934 SourceLocation getStrTokenLoc(unsigned TokNum) const { 935 assert(TokNum < NumConcatenated && "Invalid tok number"); 936 return TokLocs[TokNum]; 937 } 938 void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 939 assert(TokNum < NumConcatenated && "Invalid tok number"); 940 TokLocs[TokNum] = L; 941 } 942 943 typedef const SourceLocation *tokloc_iterator; 944 tokloc_iterator tokloc_begin() const { return TokLocs; } 945 tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 946 947 virtual SourceRange getSourceRange() const { 948 return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 949 } 950 static bool classof(const Stmt *T) { 951 return T->getStmtClass() == StringLiteralClass; 952 } 953 static bool classof(const StringLiteral *) { return true; } 954 955 // Iterators 956 virtual child_iterator child_begin(); 957 virtual child_iterator child_end(); 958}; 959 960/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 961/// AST node is only formed if full location information is requested. 962class ParenExpr : public Expr { 963 SourceLocation L, R; 964 Stmt *Val; 965public: 966 ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 967 : Expr(ParenExprClass, val->getType(), 968 val->isTypeDependent(), val->isValueDependent()), 969 L(l), R(r), Val(val) {} 970 971 /// \brief Construct an empty parenthesized expression. 972 explicit ParenExpr(EmptyShell Empty) 973 : Expr(ParenExprClass, Empty) { } 974 975 const Expr *getSubExpr() const { return cast<Expr>(Val); } 976 Expr *getSubExpr() { return cast<Expr>(Val); } 977 void setSubExpr(Expr *E) { Val = E; } 978 979 virtual SourceRange getSourceRange() const { return SourceRange(L, R); } 980 981 /// \brief Get the location of the left parentheses '('. 982 SourceLocation getLParen() const { return L; } 983 void setLParen(SourceLocation Loc) { L = Loc; } 984 985 /// \brief Get the location of the right parentheses ')'. 986 SourceLocation getRParen() const { return R; } 987 void setRParen(SourceLocation Loc) { R = Loc; } 988 989 static bool classof(const Stmt *T) { 990 return T->getStmtClass() == ParenExprClass; 991 } 992 static bool classof(const ParenExpr *) { return true; } 993 994 // Iterators 995 virtual child_iterator child_begin(); 996 virtual child_iterator child_end(); 997}; 998 999 1000/// UnaryOperator - This represents the unary-expression's (except sizeof and 1001/// alignof), the postinc/postdec operators from postfix-expression, and various 1002/// extensions. 1003/// 1004/// Notes on various nodes: 1005/// 1006/// Real/Imag - These return the real/imag part of a complex operand. If 1007/// applied to a non-complex value, the former returns its operand and the 1008/// later returns zero in the type of the operand. 1009/// 1010/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose 1011/// subexpression is a compound literal with the various MemberExpr and 1012/// ArraySubscriptExpr's applied to it. (This is only used in C) 1013/// 1014class UnaryOperator : public Expr { 1015public: 1016 // Note that additions to this should also update the StmtVisitor class. 1017 enum Opcode { 1018 PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators 1019 PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. 1020 AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators. 1021 Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators. 1022 Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators. 1023 Real, Imag, // "__real expr"/"__imag expr" Extension. 1024 Extension, // __extension__ marker. 1025 OffsetOf // __builtin_offsetof 1026 }; 1027private: 1028 Stmt *Val; 1029 Opcode Opc; 1030 SourceLocation Loc; 1031public: 1032 1033 UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 1034 : Expr(UnaryOperatorClass, type, 1035 opc != OffsetOf && (input->isTypeDependent() || 1036 type->isDependentType()), 1037 input->isValueDependent()), 1038 Val(input), Opc(opc), Loc(l) {} 1039 1040 /// \brief Build an empty unary operator. 1041 explicit UnaryOperator(EmptyShell Empty) 1042 : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { } 1043 1044 Opcode getOpcode() const { return Opc; } 1045 void setOpcode(Opcode O) { Opc = O; } 1046 1047 Expr *getSubExpr() const { return cast<Expr>(Val); } 1048 void setSubExpr(Expr *E) { Val = E; } 1049 1050 /// getOperatorLoc - Return the location of the operator. 1051 SourceLocation getOperatorLoc() const { return Loc; } 1052 void setOperatorLoc(SourceLocation L) { Loc = L; } 1053 1054 /// isPostfix - Return true if this is a postfix operation, like x++. 1055 static bool isPostfix(Opcode Op) { 1056 return Op == PostInc || Op == PostDec; 1057 } 1058 1059 /// isPostfix - Return true if this is a prefix operation, like --x. 1060 static bool isPrefix(Opcode Op) { 1061 return Op == PreInc || Op == PreDec; 1062 } 1063 1064 bool isPrefix() const { return isPrefix(Opc); } 1065 bool isPostfix() const { return isPostfix(Opc); } 1066 bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; } 1067 bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 1068 bool isOffsetOfOp() const { return Opc == OffsetOf; } 1069 static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 1070 bool isArithmeticOp() const { return isArithmeticOp(Opc); } 1071 1072 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 1073 /// corresponds to, e.g. "sizeof" or "[pre]++" 1074 static const char *getOpcodeStr(Opcode Op); 1075 1076 /// \brief Retrieve the unary opcode that corresponds to the given 1077 /// overloaded operator. 1078 static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1079 1080 /// \brief Retrieve the overloaded operator kind that corresponds to 1081 /// the given unary opcode. 1082 static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1083 1084 virtual SourceRange getSourceRange() const { 1085 if (isPostfix()) 1086 return SourceRange(Val->getLocStart(), Loc); 1087 else 1088 return SourceRange(Loc, Val->getLocEnd()); 1089 } 1090 virtual SourceLocation getExprLoc() const { return Loc; } 1091 1092 static bool classof(const Stmt *T) { 1093 return T->getStmtClass() == UnaryOperatorClass; 1094 } 1095 static bool classof(const UnaryOperator *) { return true; } 1096 1097 // Iterators 1098 virtual child_iterator child_begin(); 1099 virtual child_iterator child_end(); 1100}; 1101 1102/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 1103/// offsetof(record-type, member-designator). For example, given: 1104/// @code 1105/// struct S { 1106/// float f; 1107/// double d; 1108/// }; 1109/// struct T { 1110/// int i; 1111/// struct S s[10]; 1112/// }; 1113/// @endcode 1114/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 1115 1116class OffsetOfExpr : public Expr { 1117public: 1118 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 1119 class OffsetOfNode { 1120 public: 1121 /// \brief The kind of offsetof node we have. 1122 enum Kind { 1123 /// \brief An index into an array. 1124 Array = 0x00, 1125 /// \brief A field. 1126 Field = 0x01, 1127 /// \brief A field in a dependent type, known only by its name. 1128 Identifier = 0x02, 1129 /// \brief An implicit indirection through a C++ base class, when the 1130 /// field found is in a base class. 1131 Base = 0x03 1132 }; 1133 1134 private: 1135 enum { MaskBits = 2, Mask = 0x03 }; 1136 1137 /// \brief The source range that covers this part of the designator. 1138 SourceRange Range; 1139 1140 /// \brief The data describing the designator, which comes in three 1141 /// different forms, depending on the lower two bits. 1142 /// - An unsigned index into the array of Expr*'s stored after this node 1143 /// in memory, for [constant-expression] designators. 1144 /// - A FieldDecl*, for references to a known field. 1145 /// - An IdentifierInfo*, for references to a field with a given name 1146 /// when the class type is dependent. 1147 /// - A CXXBaseSpecifier*, for references that look at a field in a 1148 /// base class. 1149 uintptr_t Data; 1150 1151 public: 1152 /// \brief Create an offsetof node that refers to an array element. 1153 OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 1154 SourceLocation RBracketLoc) 1155 : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1156 1157 /// \brief Create an offsetof node that refers to a field. 1158 OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 1159 SourceLocation NameLoc) 1160 : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 1161 Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1162 1163 /// \brief Create an offsetof node that refers to an identifier. 1164 OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 1165 SourceLocation NameLoc) 1166 : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 1167 Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1168 1169 /// \brief Create an offsetof node that refers into a C++ base class. 1170 explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1171 : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1172 1173 /// \brief Determine what kind of offsetof node this is. 1174 Kind getKind() const { 1175 return static_cast<Kind>(Data & Mask); 1176 } 1177 1178 /// \brief For an array element node, returns the index into the array 1179 /// of expressions. 1180 unsigned getArrayExprIndex() const { 1181 assert(getKind() == Array); 1182 return Data >> 2; 1183 } 1184 1185 /// \brief For a field offsetof node, returns the field. 1186 FieldDecl *getField() const { 1187 assert(getKind() == Field); 1188 return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 1189 } 1190 1191 /// \brief For a field or identifier offsetof node, returns the name of 1192 /// the field. 1193 IdentifierInfo *getFieldName() const; 1194 1195 /// \brief For a base class node, returns the base specifier. 1196 CXXBaseSpecifier *getBase() const { 1197 assert(getKind() == Base); 1198 return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1199 } 1200 1201 /// \brief Retrieve the source range that covers this offsetof node. 1202 /// 1203 /// For an array element node, the source range contains the locations of 1204 /// the square brackets. For a field or identifier node, the source range 1205 /// contains the location of the period (if there is one) and the 1206 /// identifier. 1207 SourceRange getRange() const { return Range; } 1208 }; 1209 1210private: 1211 1212 SourceLocation OperatorLoc, RParenLoc; 1213 // Base type; 1214 TypeSourceInfo *TSInfo; 1215 // Number of sub-components (i.e. instances of OffsetOfNode). 1216 unsigned NumComps; 1217 // Number of sub-expressions (i.e. array subscript expressions). 1218 unsigned NumExprs; 1219 1220 OffsetOfExpr(ASTContext &C, QualType type, 1221 SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1222 OffsetOfNode* compsPtr, unsigned numComps, 1223 Expr** exprsPtr, unsigned numExprs, 1224 SourceLocation RParenLoc); 1225 1226 explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 1227 : Expr(OffsetOfExprClass, EmptyShell()), 1228 TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 1229 1230public: 1231 1232 static OffsetOfExpr *Create(ASTContext &C, QualType type, 1233 SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1234 OffsetOfNode* compsPtr, unsigned numComps, 1235 Expr** exprsPtr, unsigned numExprs, 1236 SourceLocation RParenLoc); 1237 1238 static OffsetOfExpr *CreateEmpty(ASTContext &C, 1239 unsigned NumComps, unsigned NumExprs); 1240 1241 /// getOperatorLoc - Return the location of the operator. 1242 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1243 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1244 1245 /// \brief Return the location of the right parentheses. 1246 SourceLocation getRParenLoc() const { return RParenLoc; } 1247 void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1248 1249 TypeSourceInfo *getTypeSourceInfo() const { 1250 return TSInfo; 1251 } 1252 void setTypeSourceInfo(TypeSourceInfo *tsi) { 1253 TSInfo = tsi; 1254 } 1255 1256 const OffsetOfNode &getComponent(unsigned Idx) { 1257 assert(Idx < NumComps && "Subscript out of range"); 1258 return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx]; 1259 } 1260 1261 void setComponent(unsigned Idx, OffsetOfNode ON) { 1262 assert(Idx < NumComps && "Subscript out of range"); 1263 reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 1264 } 1265 1266 unsigned getNumComponents() const { 1267 return NumComps; 1268 } 1269 1270 Expr* getIndexExpr(unsigned Idx) { 1271 assert(Idx < NumExprs && "Subscript out of range"); 1272 return reinterpret_cast<Expr **>( 1273 reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 1274 } 1275 1276 void setIndexExpr(unsigned Idx, Expr* E) { 1277 assert(Idx < NumComps && "Subscript out of range"); 1278 reinterpret_cast<Expr **>( 1279 reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 1280 } 1281 1282 unsigned getNumExpressions() const { 1283 return NumExprs; 1284 } 1285 1286 virtual SourceRange getSourceRange() const { 1287 return SourceRange(OperatorLoc, RParenLoc); 1288 } 1289 1290 static bool classof(const Stmt *T) { 1291 return T->getStmtClass() == OffsetOfExprClass; 1292 } 1293 1294 static bool classof(const OffsetOfExpr *) { return true; } 1295 1296 // Iterators 1297 virtual child_iterator child_begin(); 1298 virtual child_iterator child_end(); 1299}; 1300 1301/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of 1302/// types and expressions. 1303class SizeOfAlignOfExpr : public Expr { 1304 bool isSizeof : 1; // true if sizeof, false if alignof. 1305 bool isType : 1; // true if operand is a type, false if an expression 1306 union { 1307 TypeSourceInfo *Ty; 1308 Stmt *Ex; 1309 } Argument; 1310 SourceLocation OpLoc, RParenLoc; 1311 1312public: 1313 SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo, 1314 QualType resultType, SourceLocation op, 1315 SourceLocation rp) : 1316 Expr(SizeOfAlignOfExprClass, resultType, 1317 false, // Never type-dependent (C++ [temp.dep.expr]p3). 1318 // Value-dependent if the argument is type-dependent. 1319 TInfo->getType()->isDependentType()), 1320 isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) { 1321 Argument.Ty = TInfo; 1322 } 1323 1324 SizeOfAlignOfExpr(bool issizeof, Expr *E, 1325 QualType resultType, SourceLocation op, 1326 SourceLocation rp) : 1327 Expr(SizeOfAlignOfExprClass, resultType, 1328 false, // Never type-dependent (C++ [temp.dep.expr]p3). 1329 // Value-dependent if the argument is type-dependent. 1330 E->isTypeDependent()), 1331 isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) { 1332 Argument.Ex = E; 1333 } 1334 1335 /// \brief Construct an empty sizeof/alignof expression. 1336 explicit SizeOfAlignOfExpr(EmptyShell Empty) 1337 : Expr(SizeOfAlignOfExprClass, Empty) { } 1338 1339 bool isSizeOf() const { return isSizeof; } 1340 void setSizeof(bool S) { isSizeof = S; } 1341 1342 bool isArgumentType() const { return isType; } 1343 QualType getArgumentType() const { 1344 return getArgumentTypeInfo()->getType(); 1345 } 1346 TypeSourceInfo *getArgumentTypeInfo() const { 1347 assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 1348 return Argument.Ty; 1349 } 1350 Expr *getArgumentExpr() { 1351 assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1352 return static_cast<Expr*>(Argument.Ex); 1353 } 1354 const Expr *getArgumentExpr() const { 1355 return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr(); 1356 } 1357 1358 void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1359 void setArgument(TypeSourceInfo *TInfo) { 1360 Argument.Ty = TInfo; 1361 isType = true; 1362 } 1363 1364 /// Gets the argument type, or the type of the argument expression, whichever 1365 /// is appropriate. 1366 QualType getTypeOfArgument() const { 1367 return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 1368 } 1369 1370 SourceLocation getOperatorLoc() const { return OpLoc; } 1371 void setOperatorLoc(SourceLocation L) { OpLoc = L; } 1372 1373 SourceLocation getRParenLoc() const { return RParenLoc; } 1374 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1375 1376 virtual SourceRange getSourceRange() const { 1377 return SourceRange(OpLoc, RParenLoc); 1378 } 1379 1380 static bool classof(const Stmt *T) { 1381 return T->getStmtClass() == SizeOfAlignOfExprClass; 1382 } 1383 static bool classof(const SizeOfAlignOfExpr *) { return true; } 1384 1385 // Iterators 1386 virtual child_iterator child_begin(); 1387 virtual child_iterator child_end(); 1388}; 1389 1390//===----------------------------------------------------------------------===// 1391// Postfix Operators. 1392//===----------------------------------------------------------------------===// 1393 1394/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 1395class ArraySubscriptExpr : public Expr { 1396 enum { LHS, RHS, END_EXPR=2 }; 1397 Stmt* SubExprs[END_EXPR]; 1398 SourceLocation RBracketLoc; 1399public: 1400 ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1401 SourceLocation rbracketloc) 1402 : Expr(ArraySubscriptExprClass, t, 1403 lhs->isTypeDependent() || rhs->isTypeDependent(), 1404 lhs->isValueDependent() || rhs->isValueDependent()), 1405 RBracketLoc(rbracketloc) { 1406 SubExprs[LHS] = lhs; 1407 SubExprs[RHS] = rhs; 1408 } 1409 1410 /// \brief Create an empty array subscript expression. 1411 explicit ArraySubscriptExpr(EmptyShell Shell) 1412 : Expr(ArraySubscriptExprClass, Shell) { } 1413 1414 /// An array access can be written A[4] or 4[A] (both are equivalent). 1415 /// - getBase() and getIdx() always present the normalized view: A[4]. 1416 /// In this case getBase() returns "A" and getIdx() returns "4". 1417 /// - getLHS() and getRHS() present the syntactic view. e.g. for 1418 /// 4[A] getLHS() returns "4". 1419 /// Note: Because vector element access is also written A[4] we must 1420 /// predicate the format conversion in getBase and getIdx only on the 1421 /// the type of the RHS, as it is possible for the LHS to be a vector of 1422 /// integer type 1423 Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 1424 const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1425 void setLHS(Expr *E) { SubExprs[LHS] = E; } 1426 1427 Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 1428 const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1429 void setRHS(Expr *E) { SubExprs[RHS] = E; } 1430 1431 Expr *getBase() { 1432 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 1433 } 1434 1435 const Expr *getBase() const { 1436 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 1437 } 1438 1439 Expr *getIdx() { 1440 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 1441 } 1442 1443 const Expr *getIdx() const { 1444 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 1445 } 1446 1447 virtual SourceRange getSourceRange() const { 1448 return SourceRange(getLHS()->getLocStart(), RBracketLoc); 1449 } 1450 1451 SourceLocation getRBracketLoc() const { return RBracketLoc; } 1452 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1453 1454 virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 1455 1456 static bool classof(const Stmt *T) { 1457 return T->getStmtClass() == ArraySubscriptExprClass; 1458 } 1459 static bool classof(const ArraySubscriptExpr *) { return true; } 1460 1461 // Iterators 1462 virtual child_iterator child_begin(); 1463 virtual child_iterator child_end(); 1464}; 1465 1466 1467/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 1468/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1469/// while its subclasses may represent alternative syntax that (semantically) 1470/// results in a function call. For example, CXXOperatorCallExpr is 1471/// a subclass for overloaded operator calls that use operator syntax, e.g., 1472/// "str1 + str2" to resolve to a function call. 1473class CallExpr : public Expr { 1474 enum { FN=0, ARGS_START=1 }; 1475 Stmt **SubExprs; 1476 unsigned NumArgs; 1477 SourceLocation RParenLoc; 1478 1479protected: 1480 // This version of the constructor is for derived classes. 1481 CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs, 1482 QualType t, SourceLocation rparenloc); 1483 1484public: 1485 CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 1486 SourceLocation rparenloc); 1487 1488 /// \brief Build an empty call expression. 1489 CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 1490 1491 const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 1492 Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 1493 void setCallee(Expr *F) { SubExprs[FN] = F; } 1494 1495 Decl *getCalleeDecl(); 1496 const Decl *getCalleeDecl() const { 1497 return const_cast<CallExpr*>(this)->getCalleeDecl(); 1498 } 1499 1500 /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1501 FunctionDecl *getDirectCallee(); 1502 const FunctionDecl *getDirectCallee() const { 1503 return const_cast<CallExpr*>(this)->getDirectCallee(); 1504 } 1505 1506 /// getNumArgs - Return the number of actual arguments to this call. 1507 /// 1508 unsigned getNumArgs() const { return NumArgs; } 1509 1510 /// getArg - Return the specified argument. 1511 Expr *getArg(unsigned Arg) { 1512 assert(Arg < NumArgs && "Arg access out of range!"); 1513 return cast<Expr>(SubExprs[Arg+ARGS_START]); 1514 } 1515 const Expr *getArg(unsigned Arg) const { 1516 assert(Arg < NumArgs && "Arg access out of range!"); 1517 return cast<Expr>(SubExprs[Arg+ARGS_START]); 1518 } 1519 1520 /// setArg - Set the specified argument. 1521 void setArg(unsigned Arg, Expr *ArgExpr) { 1522 assert(Arg < NumArgs && "Arg access out of range!"); 1523 SubExprs[Arg+ARGS_START] = ArgExpr; 1524 } 1525 1526 /// setNumArgs - This changes the number of arguments present in this call. 1527 /// Any orphaned expressions are deleted by this, and any new operands are set 1528 /// to null. 1529 void setNumArgs(ASTContext& C, unsigned NumArgs); 1530 1531 typedef ExprIterator arg_iterator; 1532 typedef ConstExprIterator const_arg_iterator; 1533 1534 arg_iterator arg_begin() { return SubExprs+ARGS_START; } 1535 arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 1536 const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; } 1537 const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();} 1538 1539 /// getNumCommas - Return the number of commas that must have been present in 1540 /// this function call. 1541 unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 1542 1543 /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1544 /// not, return 0. 1545 unsigned isBuiltinCall(ASTContext &Context) const; 1546 1547 /// getCallReturnType - Get the return type of the call expr. This is not 1548 /// always the type of the expr itself, if the return type is a reference 1549 /// type. 1550 QualType getCallReturnType() const; 1551 1552 SourceLocation getRParenLoc() const { return RParenLoc; } 1553 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1554 1555 virtual SourceRange getSourceRange() const { 1556 return SourceRange(getCallee()->getLocStart(), RParenLoc); 1557 } 1558 1559 static bool classof(const Stmt *T) { 1560 return T->getStmtClass() >= firstCallExprConstant && 1561 T->getStmtClass() <= lastCallExprConstant; 1562 } 1563 static bool classof(const CallExpr *) { return true; } 1564 1565 // Iterators 1566 virtual child_iterator child_begin(); 1567 virtual child_iterator child_end(); 1568}; 1569 1570/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 1571/// 1572class MemberExpr : public Expr { 1573 /// Extra data stored in some member expressions. 1574 struct MemberNameQualifier : public NameQualifier { 1575 DeclAccessPair FoundDecl; 1576 }; 1577 1578 /// Base - the expression for the base pointer or structure references. In 1579 /// X.F, this is "X". 1580 Stmt *Base; 1581 1582 /// MemberDecl - This is the decl being referenced by the field/member name. 1583 /// In X.F, this is the decl referenced by F. 1584 ValueDecl *MemberDecl; 1585 1586 /// MemberLoc - This is the location of the member name. 1587 SourceLocation MemberLoc; 1588 1589 /// IsArrow - True if this is "X->F", false if this is "X.F". 1590 bool IsArrow : 1; 1591 1592 /// \brief True if this member expression used a nested-name-specifier to 1593 /// refer to the member, e.g., "x->Base::f", or found its member via a using 1594 /// declaration. When true, a MemberNameQualifier 1595 /// structure is allocated immediately after the MemberExpr. 1596 bool HasQualifierOrFoundDecl : 1; 1597 1598 /// \brief True if this member expression specified a template argument list 1599 /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 1600 /// structure (and its TemplateArguments) are allocated immediately after 1601 /// the MemberExpr or, if the member expression also has a qualifier, after 1602 /// the MemberNameQualifier structure. 1603 bool HasExplicitTemplateArgumentList : 1; 1604 1605 /// \brief Retrieve the qualifier that preceded the member name, if any. 1606 MemberNameQualifier *getMemberQualifier() { 1607 assert(HasQualifierOrFoundDecl); 1608 return reinterpret_cast<MemberNameQualifier *> (this + 1); 1609 } 1610 1611 /// \brief Retrieve the qualifier that preceded the member name, if any. 1612 const MemberNameQualifier *getMemberQualifier() const { 1613 return const_cast<MemberExpr *>(this)->getMemberQualifier(); 1614 } 1615 1616 /// \brief Retrieve the explicit template argument list that followed the 1617 /// member template name, if any. 1618 ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 1619 if (!HasExplicitTemplateArgumentList) 1620 return 0; 1621 1622 if (!HasQualifierOrFoundDecl) 1623 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1624 1625 return reinterpret_cast<ExplicitTemplateArgumentList *>( 1626 getMemberQualifier() + 1); 1627 } 1628 1629 /// \brief Retrieve the explicit template argument list that followed the 1630 /// member template name, if any. 1631 const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 1632 return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList(); 1633 } 1634 1635public: 1636 MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 1637 SourceLocation l, QualType ty) 1638 : Expr(MemberExprClass, ty, 1639 base->isTypeDependent(), base->isValueDependent()), 1640 Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow), 1641 HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 1642 1643 static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 1644 NestedNameSpecifier *qual, SourceRange qualrange, 1645 ValueDecl *memberdecl, DeclAccessPair founddecl, 1646 SourceLocation l, 1647 const TemplateArgumentListInfo *targs, 1648 QualType ty); 1649 1650 void setBase(Expr *E) { Base = E; } 1651 Expr *getBase() const { return cast<Expr>(Base); } 1652 1653 /// \brief Retrieve the member declaration to which this expression refers. 1654 /// 1655 /// The returned declaration will either be a FieldDecl or (in C++) 1656 /// a CXXMethodDecl. 1657 ValueDecl *getMemberDecl() const { return MemberDecl; } 1658 void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 1659 1660 /// \brief Retrieves the declaration found by lookup. 1661 DeclAccessPair getFoundDecl() const { 1662 if (!HasQualifierOrFoundDecl) 1663 return DeclAccessPair::make(getMemberDecl(), 1664 getMemberDecl()->getAccess()); 1665 return getMemberQualifier()->FoundDecl; 1666 } 1667 1668 /// \brief Determines whether this member expression actually had 1669 /// a C++ nested-name-specifier prior to the name of the member, e.g., 1670 /// x->Base::foo. 1671 bool hasQualifier() const { return getQualifier() != 0; } 1672 1673 /// \brief If the member name was qualified, retrieves the source range of 1674 /// the nested-name-specifier that precedes the member name. Otherwise, 1675 /// returns an empty source range. 1676 SourceRange getQualifierRange() const { 1677 if (!HasQualifierOrFoundDecl) 1678 return SourceRange(); 1679 1680 return getMemberQualifier()->Range; 1681 } 1682 1683 /// \brief If the member name was qualified, retrieves the 1684 /// nested-name-specifier that precedes the member name. Otherwise, returns 1685 /// NULL. 1686 NestedNameSpecifier *getQualifier() const { 1687 if (!HasQualifierOrFoundDecl) 1688 return 0; 1689 1690 return getMemberQualifier()->NNS; 1691 } 1692 1693 /// \brief Determines whether this member expression actually had a C++ 1694 /// template argument list explicitly specified, e.g., x.f<int>. 1695 bool hasExplicitTemplateArgumentList() const { 1696 return HasExplicitTemplateArgumentList; 1697 } 1698 1699 /// \brief Copies the template arguments (if present) into the given 1700 /// structure. 1701 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1702 if (hasExplicitTemplateArgumentList()) 1703 getExplicitTemplateArgumentList()->copyInto(List); 1704 } 1705 1706 /// \brief Retrieve the location of the left angle bracket following the 1707 /// member name ('<'), if any. 1708 SourceLocation getLAngleLoc() const { 1709 if (!HasExplicitTemplateArgumentList) 1710 return SourceLocation(); 1711 1712 return getExplicitTemplateArgumentList()->LAngleLoc; 1713 } 1714 1715 /// \brief Retrieve the template arguments provided as part of this 1716 /// template-id. 1717 const TemplateArgumentLoc *getTemplateArgs() const { 1718 if (!HasExplicitTemplateArgumentList) 1719 return 0; 1720 1721 return getExplicitTemplateArgumentList()->getTemplateArgs(); 1722 } 1723 1724 /// \brief Retrieve the number of template arguments provided as part of this 1725 /// template-id. 1726 unsigned getNumTemplateArgs() const { 1727 if (!HasExplicitTemplateArgumentList) 1728 return 0; 1729 1730 return getExplicitTemplateArgumentList()->NumTemplateArgs; 1731 } 1732 1733 /// \brief Retrieve the location of the right angle bracket following the 1734 /// template arguments ('>'). 1735 SourceLocation getRAngleLoc() const { 1736 if (!HasExplicitTemplateArgumentList) 1737 return SourceLocation(); 1738 1739 return getExplicitTemplateArgumentList()->RAngleLoc; 1740 } 1741 1742 bool isArrow() const { return IsArrow; } 1743 void setArrow(bool A) { IsArrow = A; } 1744 1745 /// getMemberLoc - Return the location of the "member", in X->F, it is the 1746 /// location of 'F'. 1747 SourceLocation getMemberLoc() const { return MemberLoc; } 1748 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 1749 1750 virtual SourceRange getSourceRange() const { 1751 // If we have an implicit base (like a C++ implicit this), 1752 // make sure not to return its location 1753 SourceLocation EndLoc = MemberLoc; 1754 if (HasExplicitTemplateArgumentList) 1755 EndLoc = getRAngleLoc(); 1756 1757 SourceLocation BaseLoc = getBase()->getLocStart(); 1758 if (BaseLoc.isInvalid()) 1759 return SourceRange(MemberLoc, EndLoc); 1760 return SourceRange(BaseLoc, EndLoc); 1761 } 1762 1763 virtual SourceLocation getExprLoc() const { return MemberLoc; } 1764 1765 static bool classof(const Stmt *T) { 1766 return T->getStmtClass() == MemberExprClass; 1767 } 1768 static bool classof(const MemberExpr *) { return true; } 1769 1770 // Iterators 1771 virtual child_iterator child_begin(); 1772 virtual child_iterator child_end(); 1773}; 1774 1775/// CompoundLiteralExpr - [C99 6.5.2.5] 1776/// 1777class CompoundLiteralExpr : public Expr { 1778 /// LParenLoc - If non-null, this is the location of the left paren in a 1779 /// compound literal like "(int){4}". This can be null if this is a 1780 /// synthesized compound expression. 1781 SourceLocation LParenLoc; 1782 1783 /// The type as written. This can be an incomplete array type, in 1784 /// which case the actual expression type will be different. 1785 TypeSourceInfo *TInfo; 1786 Stmt *Init; 1787 bool FileScope; 1788public: 1789 // FIXME: Can compound literals be value-dependent? 1790 CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 1791 QualType T, Expr *init, bool fileScope) 1792 : Expr(CompoundLiteralExprClass, T, 1793 tinfo->getType()->isDependentType(), false), 1794 LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 1795 1796 /// \brief Construct an empty compound literal. 1797 explicit CompoundLiteralExpr(EmptyShell Empty) 1798 : Expr(CompoundLiteralExprClass, Empty) { } 1799 1800 const Expr *getInitializer() const { return cast<Expr>(Init); } 1801 Expr *getInitializer() { return cast<Expr>(Init); } 1802 void setInitializer(Expr *E) { Init = E; } 1803 1804 bool isFileScope() const { return FileScope; } 1805 void setFileScope(bool FS) { FileScope = FS; } 1806 1807 SourceLocation getLParenLoc() const { return LParenLoc; } 1808 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1809 1810 TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 1811 void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 1812 1813 virtual SourceRange getSourceRange() const { 1814 // FIXME: Init should never be null. 1815 if (!Init) 1816 return SourceRange(); 1817 if (LParenLoc.isInvalid()) 1818 return Init->getSourceRange(); 1819 return SourceRange(LParenLoc, Init->getLocEnd()); 1820 } 1821 1822 static bool classof(const Stmt *T) { 1823 return T->getStmtClass() == CompoundLiteralExprClass; 1824 } 1825 static bool classof(const CompoundLiteralExpr *) { return true; } 1826 1827 // Iterators 1828 virtual child_iterator child_begin(); 1829 virtual child_iterator child_end(); 1830}; 1831 1832/// CastExpr - Base class for type casts, including both implicit 1833/// casts (ImplicitCastExpr) and explicit casts that have some 1834/// representation in the source code (ExplicitCastExpr's derived 1835/// classes). 1836class CastExpr : public Expr { 1837public: 1838 /// CastKind - the kind of cast this represents. 1839 enum CastKind { 1840 /// CK_Unknown - Unknown cast kind. 1841 /// FIXME: The goal is to get rid of this and make all casts have a 1842 /// kind so that the AST client doesn't have to try to figure out what's 1843 /// going on. 1844 CK_Unknown, 1845 1846 /// CK_BitCast - Used for reinterpret_cast. 1847 CK_BitCast, 1848 1849 /// CK_LValueBitCast - Used for reinterpret_cast of expressions to 1850 /// a reference type. 1851 CK_LValueBitCast, 1852 1853 /// CK_NoOp - Used for const_cast. 1854 CK_NoOp, 1855 1856 /// CK_BaseToDerived - Base to derived class casts. 1857 CK_BaseToDerived, 1858 1859 /// CK_DerivedToBase - Derived to base class casts. 1860 CK_DerivedToBase, 1861 1862 /// CK_UncheckedDerivedToBase - Derived to base class casts that 1863 /// assume that the derived pointer is not null. 1864 CK_UncheckedDerivedToBase, 1865 1866 /// CK_Dynamic - Dynamic cast. 1867 CK_Dynamic, 1868 1869 /// CK_ToUnion - Cast to union (GCC extension). 1870 CK_ToUnion, 1871 1872 /// CK_ArrayToPointerDecay - Array to pointer decay. 1873 CK_ArrayToPointerDecay, 1874 1875 // CK_FunctionToPointerDecay - Function to pointer decay. 1876 CK_FunctionToPointerDecay, 1877 1878 /// CK_NullToMemberPointer - Null pointer to member pointer. 1879 CK_NullToMemberPointer, 1880 1881 /// CK_BaseToDerivedMemberPointer - Member pointer in base class to 1882 /// member pointer in derived class. 1883 CK_BaseToDerivedMemberPointer, 1884 1885 /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to 1886 /// member pointer in base class. 1887 CK_DerivedToBaseMemberPointer, 1888 1889 /// CK_UserDefinedConversion - Conversion using a user defined type 1890 /// conversion function. 1891 CK_UserDefinedConversion, 1892 1893 /// CK_ConstructorConversion - Conversion by constructor 1894 CK_ConstructorConversion, 1895 1896 /// CK_IntegralToPointer - Integral to pointer 1897 CK_IntegralToPointer, 1898 1899 /// CK_PointerToIntegral - Pointer to integral 1900 CK_PointerToIntegral, 1901 1902 /// CK_ToVoid - Cast to void. 1903 CK_ToVoid, 1904 1905 /// CK_VectorSplat - Casting from an integer/floating type to an extended 1906 /// vector type with the same element type as the src type. Splats the 1907 /// src expression into the destination expression. 1908 CK_VectorSplat, 1909 1910 /// CK_IntegralCast - Casting between integral types of different size. 1911 CK_IntegralCast, 1912 1913 /// CK_IntegralToFloating - Integral to floating point. 1914 CK_IntegralToFloating, 1915 1916 /// CK_FloatingToIntegral - Floating point to integral. 1917 CK_FloatingToIntegral, 1918 1919 /// CK_FloatingCast - Casting between floating types of different size. 1920 CK_FloatingCast, 1921 1922 /// CK_MemberPointerToBoolean - Member pointer to boolean 1923 CK_MemberPointerToBoolean, 1924 1925 /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c 1926 /// pointer 1927 CK_AnyPointerToObjCPointerCast, 1928 /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block 1929 /// pointer 1930 CK_AnyPointerToBlockPointerCast, 1931 1932 /// \brief Converting between two Objective-C object types, which 1933 /// can occur when performing reference binding to an Objective-C 1934 /// object. 1935 CK_ObjCObjectLValueCast 1936 }; 1937 1938private: 1939 unsigned Kind : 5; 1940 unsigned BasePathSize : BitsRemaining - 5; 1941 Stmt *Op; 1942 1943 void CheckBasePath() const { 1944#ifndef NDEBUG 1945 switch (getCastKind()) { 1946 case CK_DerivedToBase: 1947 case CK_UncheckedDerivedToBase: 1948 case CK_DerivedToBaseMemberPointer: 1949 case CK_BaseToDerived: 1950 case CK_BaseToDerivedMemberPointer: 1951 assert(!path_empty() && "Cast kind should have a base path!"); 1952 break; 1953 1954 // These should not have an inheritance path. 1955 case CK_Unknown: 1956 case CK_BitCast: 1957 case CK_LValueBitCast: 1958 case CK_NoOp: 1959 case CK_Dynamic: 1960 case CK_ToUnion: 1961 case CK_ArrayToPointerDecay: 1962 case CK_FunctionToPointerDecay: 1963 case CK_NullToMemberPointer: 1964 case CK_UserDefinedConversion: 1965 case CK_ConstructorConversion: 1966 case CK_IntegralToPointer: 1967 case CK_PointerToIntegral: 1968 case CK_ToVoid: 1969 case CK_VectorSplat: 1970 case CK_IntegralCast: 1971 case CK_IntegralToFloating: 1972 case CK_FloatingToIntegral: 1973 case CK_FloatingCast: 1974 case CK_MemberPointerToBoolean: 1975 case CK_AnyPointerToObjCPointerCast: 1976 case CK_AnyPointerToBlockPointerCast: 1977 case CK_ObjCObjectLValueCast: 1978 assert(path_empty() && "Cast kind should not have a base path!"); 1979 break; 1980 } 1981#endif 1982 } 1983 1984 const CXXBaseSpecifier * const *path_buffer() const { 1985 return const_cast<CastExpr*>(this)->path_buffer(); 1986 } 1987 CXXBaseSpecifier **path_buffer(); 1988 1989protected: 1990 CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op, 1991 unsigned BasePathSize) : 1992 Expr(SC, ty, 1993 // Cast expressions are type-dependent if the type is 1994 // dependent (C++ [temp.dep.expr]p3). 1995 ty->isDependentType(), 1996 // Cast expressions are value-dependent if the type is 1997 // dependent or if the subexpression is value-dependent. 1998 ty->isDependentType() || (op && op->isValueDependent())), 1999 Kind(kind), BasePathSize(BasePathSize), Op(op) { 2000 CheckBasePath(); 2001 } 2002 2003 /// \brief Construct an empty cast. 2004 CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 2005 : Expr(SC, Empty), BasePathSize(BasePathSize) { } 2006 2007public: 2008 CastKind getCastKind() const { return static_cast<CastKind>(Kind); } 2009 void setCastKind(CastKind K) { Kind = K; } 2010 const char *getCastKindName() const; 2011 2012 Expr *getSubExpr() { return cast<Expr>(Op); } 2013 const Expr *getSubExpr() const { return cast<Expr>(Op); } 2014 void setSubExpr(Expr *E) { Op = E; } 2015 2016 /// \brief Retrieve the cast subexpression as it was written in the source 2017 /// code, looking through any implicit casts or other intermediate nodes 2018 /// introduced by semantic analysis. 2019 Expr *getSubExprAsWritten(); 2020 const Expr *getSubExprAsWritten() const { 2021 return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 2022 } 2023 2024 typedef CXXBaseSpecifier **path_iterator; 2025 typedef const CXXBaseSpecifier * const *path_const_iterator; 2026 bool path_empty() const { return BasePathSize == 0; } 2027 unsigned path_size() const { return BasePathSize; } 2028 path_iterator path_begin() { return path_buffer(); } 2029 path_iterator path_end() { return path_buffer() + path_size(); } 2030 path_const_iterator path_begin() const { return path_buffer(); } 2031 path_const_iterator path_end() const { return path_buffer() + path_size(); } 2032 2033 void setCastPath(const CXXCastPath &Path); 2034 2035 static bool classof(const Stmt *T) { 2036 return T->getStmtClass() >= firstCastExprConstant && 2037 T->getStmtClass() <= lastCastExprConstant; 2038 } 2039 static bool classof(const CastExpr *) { return true; } 2040 2041 // Iterators 2042 virtual child_iterator child_begin(); 2043 virtual child_iterator child_end(); 2044}; 2045 2046/// ImplicitCastExpr - Allows us to explicitly represent implicit type 2047/// conversions, which have no direct representation in the original 2048/// source code. For example: converting T[]->T*, void f()->void 2049/// (*f)(), float->double, short->int, etc. 2050/// 2051/// In C, implicit casts always produce rvalues. However, in C++, an 2052/// implicit cast whose result is being bound to a reference will be 2053/// an lvalue or xvalue. For example: 2054/// 2055/// @code 2056/// class Base { }; 2057/// class Derived : public Base { }; 2058/// Derived &&ref(); 2059/// void f(Derived d) { 2060/// Base& b = d; // initializer is an ImplicitCastExpr 2061/// // to an lvalue of type Base 2062/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2063/// // to an xvalue of type Base 2064/// } 2065/// @endcode 2066class ImplicitCastExpr : public CastExpr { 2067public: 2068 enum ResultCategory { 2069 RValue, LValue, XValue 2070 }; 2071 2072private: 2073 /// Category - The category this cast produces. 2074 ResultCategory Category; 2075 2076 ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 2077 unsigned BasePathLength, ResultCategory Cat) 2078 : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePathLength), 2079 Category(Cat) { } 2080 2081 /// \brief Construct an empty implicit cast. 2082 explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2083 : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2084 2085public: 2086 enum OnStack_t { OnStack }; 2087 ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 2088 ResultCategory Cat) 2089 : CastExpr(ImplicitCastExprClass, ty, kind, op, 0), 2090 Category(Cat) { } 2091 2092 static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2093 CastKind Kind, Expr *Operand, 2094 const CXXCastPath *BasePath, 2095 ResultCategory Cat); 2096 2097 static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2098 2099 virtual SourceRange getSourceRange() const { 2100 return getSubExpr()->getSourceRange(); 2101 } 2102 2103 /// getCategory - The value category this cast produces. 2104 ResultCategory getCategory() const { return Category; } 2105 2106 /// setCategory - Set the value category this cast produces. 2107 void setCategory(ResultCategory Cat) { Category = Cat; } 2108 2109 static bool classof(const Stmt *T) { 2110 return T->getStmtClass() == ImplicitCastExprClass; 2111 } 2112 static bool classof(const ImplicitCastExpr *) { return true; } 2113}; 2114 2115/// ExplicitCastExpr - An explicit cast written in the source 2116/// code. 2117/// 2118/// This class is effectively an abstract class, because it provides 2119/// the basic representation of an explicitly-written cast without 2120/// specifying which kind of cast (C cast, functional cast, static 2121/// cast, etc.) was written; specific derived classes represent the 2122/// particular style of cast and its location information. 2123/// 2124/// Unlike implicit casts, explicit cast nodes have two different 2125/// types: the type that was written into the source code, and the 2126/// actual type of the expression as determined by semantic 2127/// analysis. These types may differ slightly. For example, in C++ one 2128/// can cast to a reference type, which indicates that the resulting 2129/// expression will be an lvalue or xvalue. The reference type, however, 2130/// will not be used as the type of the expression. 2131class ExplicitCastExpr : public CastExpr { 2132 /// TInfo - Source type info for the (written) type 2133 /// this expression is casting to. 2134 TypeSourceInfo *TInfo; 2135 2136protected: 2137 ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind, 2138 Expr *op, unsigned PathSize, TypeSourceInfo *writtenTy) 2139 : CastExpr(SC, exprTy, kind, op, PathSize), TInfo(writtenTy) {} 2140 2141 /// \brief Construct an empty explicit cast. 2142 ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2143 : CastExpr(SC, Shell, PathSize) { } 2144 2145public: 2146 /// getTypeInfoAsWritten - Returns the type source info for the type 2147 /// that this expression is casting to. 2148 TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 2149 void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 2150 2151 /// getTypeAsWritten - Returns the type that this expression is 2152 /// casting to, as written in the source code. 2153 QualType getTypeAsWritten() const { return TInfo->getType(); } 2154 2155 static bool classof(const Stmt *T) { 2156 return T->getStmtClass() >= firstExplicitCastExprConstant && 2157 T->getStmtClass() <= lastExplicitCastExprConstant; 2158 } 2159 static bool classof(const ExplicitCastExpr *) { return true; } 2160}; 2161 2162/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 2163/// cast in C++ (C++ [expr.cast]), which uses the syntax 2164/// (Type)expr. For example: @c (int)f. 2165class CStyleCastExpr : public ExplicitCastExpr { 2166 SourceLocation LPLoc; // the location of the left paren 2167 SourceLocation RPLoc; // the location of the right paren 2168 2169 CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op, 2170 unsigned PathSize, TypeSourceInfo *writtenTy, 2171 SourceLocation l, SourceLocation r) 2172 : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, PathSize, 2173 writtenTy), LPLoc(l), RPLoc(r) {} 2174 2175 /// \brief Construct an empty C-style explicit cast. 2176 explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2177 : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2178 2179public: 2180 static CStyleCastExpr *Create(ASTContext &Context, QualType T, CastKind K, 2181 Expr *Op, const CXXCastPath *BasePath, 2182 TypeSourceInfo *WrittenTy, SourceLocation L, 2183 SourceLocation R); 2184 2185 static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2186 2187 SourceLocation getLParenLoc() const { return LPLoc; } 2188 void setLParenLoc(SourceLocation L) { LPLoc = L; } 2189 2190 SourceLocation getRParenLoc() const { return RPLoc; } 2191 void setRParenLoc(SourceLocation L) { RPLoc = L; } 2192 2193 virtual SourceRange getSourceRange() const { 2194 return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 2195 } 2196 static bool classof(const Stmt *T) { 2197 return T->getStmtClass() == CStyleCastExprClass; 2198 } 2199 static bool classof(const CStyleCastExpr *) { return true; } 2200}; 2201 2202/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 2203/// 2204/// This expression node kind describes a builtin binary operation, 2205/// such as "x + y" for integer values "x" and "y". The operands will 2206/// already have been converted to appropriate types (e.g., by 2207/// performing promotions or conversions). 2208/// 2209/// In C++, where operators may be overloaded, a different kind of 2210/// expression node (CXXOperatorCallExpr) is used to express the 2211/// invocation of an overloaded operator with operator syntax. Within 2212/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 2213/// used to store an expression "x + y" depends on the subexpressions 2214/// for x and y. If neither x or y is type-dependent, and the "+" 2215/// operator resolves to a built-in operation, BinaryOperator will be 2216/// used to express the computation (x and y may still be 2217/// value-dependent). If either x or y is type-dependent, or if the 2218/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 2219/// be used to express the computation. 2220class BinaryOperator : public Expr { 2221public: 2222 enum Opcode { 2223 // Operators listed in order of precedence. 2224 // Note that additions to this should also update the StmtVisitor class. 2225 PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators. 2226 Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators. 2227 Add, Sub, // [C99 6.5.6] Additive operators. 2228 Shl, Shr, // [C99 6.5.7] Bitwise shift operators. 2229 LT, GT, LE, GE, // [C99 6.5.8] Relational operators. 2230 EQ, NE, // [C99 6.5.9] Equality operators. 2231 And, // [C99 6.5.10] Bitwise AND operator. 2232 Xor, // [C99 6.5.11] Bitwise XOR operator. 2233 Or, // [C99 6.5.12] Bitwise OR operator. 2234 LAnd, // [C99 6.5.13] Logical AND operator. 2235 LOr, // [C99 6.5.14] Logical OR operator. 2236 Assign, MulAssign,// [C99 6.5.16] Assignment operators. 2237 DivAssign, RemAssign, 2238 AddAssign, SubAssign, 2239 ShlAssign, ShrAssign, 2240 AndAssign, XorAssign, 2241 OrAssign, 2242 Comma // [C99 6.5.17] Comma operator. 2243 }; 2244private: 2245 enum { LHS, RHS, END_EXPR }; 2246 Stmt* SubExprs[END_EXPR]; 2247 Opcode Opc; 2248 SourceLocation OpLoc; 2249public: 2250 2251 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2252 SourceLocation opLoc) 2253 : Expr(BinaryOperatorClass, ResTy, 2254 lhs->isTypeDependent() || rhs->isTypeDependent(), 2255 lhs->isValueDependent() || rhs->isValueDependent()), 2256 Opc(opc), OpLoc(opLoc) { 2257 SubExprs[LHS] = lhs; 2258 SubExprs[RHS] = rhs; 2259 assert(!isCompoundAssignmentOp() && 2260 "Use ArithAssignBinaryOperator for compound assignments"); 2261 } 2262 2263 /// \brief Construct an empty binary operator. 2264 explicit BinaryOperator(EmptyShell Empty) 2265 : Expr(BinaryOperatorClass, Empty), Opc(Comma) { } 2266 2267 SourceLocation getOperatorLoc() const { return OpLoc; } 2268 void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2269 2270 Opcode getOpcode() const { return Opc; } 2271 void setOpcode(Opcode O) { Opc = O; } 2272 2273 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2274 void setLHS(Expr *E) { SubExprs[LHS] = E; } 2275 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2276 void setRHS(Expr *E) { SubExprs[RHS] = E; } 2277 2278 virtual SourceRange getSourceRange() const { 2279 return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 2280 } 2281 2282 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 2283 /// corresponds to, e.g. "<<=". 2284 static const char *getOpcodeStr(Opcode Op); 2285 2286 const char *getOpcodeStr() const { return getOpcodeStr(Opc); } 2287 2288 /// \brief Retrieve the binary opcode that corresponds to the given 2289 /// overloaded operator. 2290 static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2291 2292 /// \brief Retrieve the overloaded operator kind that corresponds to 2293 /// the given binary opcode. 2294 static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2295 2296 /// predicates to categorize the respective opcodes. 2297 bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 2298 static bool isAdditiveOp(Opcode Opc) { return Opc == Add || Opc == Sub; } 2299 bool isAdditiveOp() const { return isAdditiveOp(Opc); } 2300 static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; } 2301 bool isShiftOp() const { return isShiftOp(Opc); } 2302 2303 static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; } 2304 bool isBitwiseOp() const { return isBitwiseOp(Opc); } 2305 2306 static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; } 2307 bool isRelationalOp() const { return isRelationalOp(Opc); } 2308 2309 static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; } 2310 bool isEqualityOp() const { return isEqualityOp(Opc); } 2311 2312 static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; } 2313 bool isComparisonOp() const { return isComparisonOp(Opc); } 2314 2315 static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; } 2316 bool isLogicalOp() const { return isLogicalOp(Opc); } 2317 2318 bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 2319 bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 2320 bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 2321 2322 static bool classof(const Stmt *S) { 2323 return S->getStmtClass() >= firstBinaryOperatorConstant && 2324 S->getStmtClass() <= lastBinaryOperatorConstant; 2325 } 2326 static bool classof(const BinaryOperator *) { return true; } 2327 2328 // Iterators 2329 virtual child_iterator child_begin(); 2330 virtual child_iterator child_end(); 2331 2332protected: 2333 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2334 SourceLocation opLoc, bool dead) 2335 : Expr(CompoundAssignOperatorClass, ResTy, 2336 lhs->isTypeDependent() || rhs->isTypeDependent(), 2337 lhs->isValueDependent() || rhs->isValueDependent()), 2338 Opc(opc), OpLoc(opLoc) { 2339 SubExprs[LHS] = lhs; 2340 SubExprs[RHS] = rhs; 2341 } 2342 2343 BinaryOperator(StmtClass SC, EmptyShell Empty) 2344 : Expr(SC, Empty), Opc(MulAssign) { } 2345}; 2346 2347/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 2348/// track of the type the operation is performed in. Due to the semantics of 2349/// these operators, the operands are promoted, the aritmetic performed, an 2350/// implicit conversion back to the result type done, then the assignment takes 2351/// place. This captures the intermediate type which the computation is done 2352/// in. 2353class CompoundAssignOperator : public BinaryOperator { 2354 QualType ComputationLHSType; 2355 QualType ComputationResultType; 2356public: 2357 CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 2358 QualType ResType, QualType CompLHSType, 2359 QualType CompResultType, 2360 SourceLocation OpLoc) 2361 : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 2362 ComputationLHSType(CompLHSType), 2363 ComputationResultType(CompResultType) { 2364 assert(isCompoundAssignmentOp() && 2365 "Only should be used for compound assignments"); 2366 } 2367 2368 /// \brief Build an empty compound assignment operator expression. 2369 explicit CompoundAssignOperator(EmptyShell Empty) 2370 : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2371 2372 // The two computation types are the type the LHS is converted 2373 // to for the computation and the type of the result; the two are 2374 // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2375 QualType getComputationLHSType() const { return ComputationLHSType; } 2376 void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2377 2378 QualType getComputationResultType() const { return ComputationResultType; } 2379 void setComputationResultType(QualType T) { ComputationResultType = T; } 2380 2381 static bool classof(const CompoundAssignOperator *) { return true; } 2382 static bool classof(const Stmt *S) { 2383 return S->getStmtClass() == CompoundAssignOperatorClass; 2384 } 2385}; 2386 2387/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 2388/// GNU "missing LHS" extension is in use. 2389/// 2390class ConditionalOperator : public Expr { 2391 enum { COND, LHS, RHS, END_EXPR }; 2392 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2393 SourceLocation QuestionLoc, ColonLoc; 2394public: 2395 ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 2396 SourceLocation CLoc, Expr *rhs, QualType t) 2397 : Expr(ConditionalOperatorClass, t, 2398 // FIXME: the type of the conditional operator doesn't 2399 // depend on the type of the conditional, but the standard 2400 // seems to imply that it could. File a bug! 2401 ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())), 2402 (cond->isValueDependent() || 2403 (lhs && lhs->isValueDependent()) || 2404 (rhs && rhs->isValueDependent()))), 2405 QuestionLoc(QLoc), 2406 ColonLoc(CLoc) { 2407 SubExprs[COND] = cond; 2408 SubExprs[LHS] = lhs; 2409 SubExprs[RHS] = rhs; 2410 } 2411 2412 /// \brief Build an empty conditional operator. 2413 explicit ConditionalOperator(EmptyShell Empty) 2414 : Expr(ConditionalOperatorClass, Empty) { } 2415 2416 // getCond - Return the expression representing the condition for 2417 // the ?: operator. 2418 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2419 void setCond(Expr *E) { SubExprs[COND] = E; } 2420 2421 // getTrueExpr - Return the subexpression representing the value of the ?: 2422 // expression if the condition evaluates to true. In most cases this value 2423 // will be the same as getLHS() except a GCC extension allows the left 2424 // subexpression to be omitted, and instead of the condition be returned. 2425 // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x" 2426 // is only evaluated once. 2427 Expr *getTrueExpr() const { 2428 return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]); 2429 } 2430 2431 // getTrueExpr - Return the subexpression representing the value of the ?: 2432 // expression if the condition evaluates to false. This is the same as getRHS. 2433 Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2434 2435 Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); } 2436 void setLHS(Expr *E) { SubExprs[LHS] = E; } 2437 2438 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2439 void setRHS(Expr *E) { SubExprs[RHS] = E; } 2440 2441 SourceLocation getQuestionLoc() const { return QuestionLoc; } 2442 void setQuestionLoc(SourceLocation L) { QuestionLoc = L; } 2443 2444 SourceLocation getColonLoc() const { return ColonLoc; } 2445 void setColonLoc(SourceLocation L) { ColonLoc = L; } 2446 2447 virtual SourceRange getSourceRange() const { 2448 return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 2449 } 2450 static bool classof(const Stmt *T) { 2451 return T->getStmtClass() == ConditionalOperatorClass; 2452 } 2453 static bool classof(const ConditionalOperator *) { return true; } 2454 2455 // Iterators 2456 virtual child_iterator child_begin(); 2457 virtual child_iterator child_end(); 2458}; 2459 2460/// AddrLabelExpr - The GNU address of label extension, representing &&label. 2461class AddrLabelExpr : public Expr { 2462 SourceLocation AmpAmpLoc, LabelLoc; 2463 LabelStmt *Label; 2464public: 2465 AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 2466 QualType t) 2467 : Expr(AddrLabelExprClass, t, false, false), 2468 AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 2469 2470 /// \brief Build an empty address of a label expression. 2471 explicit AddrLabelExpr(EmptyShell Empty) 2472 : Expr(AddrLabelExprClass, Empty) { } 2473 2474 SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 2475 void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 2476 SourceLocation getLabelLoc() const { return LabelLoc; } 2477 void setLabelLoc(SourceLocation L) { LabelLoc = L; } 2478 2479 virtual SourceRange getSourceRange() const { 2480 return SourceRange(AmpAmpLoc, LabelLoc); 2481 } 2482 2483 LabelStmt *getLabel() const { return Label; } 2484 void setLabel(LabelStmt *S) { Label = S; } 2485 2486 static bool classof(const Stmt *T) { 2487 return T->getStmtClass() == AddrLabelExprClass; 2488 } 2489 static bool classof(const AddrLabelExpr *) { return true; } 2490 2491 // Iterators 2492 virtual child_iterator child_begin(); 2493 virtual child_iterator child_end(); 2494}; 2495 2496/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2497/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2498/// takes the value of the last subexpression. 2499class StmtExpr : public Expr { 2500 Stmt *SubStmt; 2501 SourceLocation LParenLoc, RParenLoc; 2502public: 2503 // FIXME: Does type-dependence need to be computed differently? 2504 StmtExpr(CompoundStmt *substmt, QualType T, 2505 SourceLocation lp, SourceLocation rp) : 2506 Expr(StmtExprClass, T, T->isDependentType(), false), 2507 SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 2508 2509 /// \brief Build an empty statement expression. 2510 explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 2511 2512 CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 2513 const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 2514 void setSubStmt(CompoundStmt *S) { SubStmt = S; } 2515 2516 virtual SourceRange getSourceRange() const { 2517 return SourceRange(LParenLoc, RParenLoc); 2518 } 2519 2520 SourceLocation getLParenLoc() const { return LParenLoc; } 2521 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2522 SourceLocation getRParenLoc() const { return RParenLoc; } 2523 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2524 2525 static bool classof(const Stmt *T) { 2526 return T->getStmtClass() == StmtExprClass; 2527 } 2528 static bool classof(const StmtExpr *) { return true; } 2529 2530 // Iterators 2531 virtual child_iterator child_begin(); 2532 virtual child_iterator child_end(); 2533}; 2534 2535/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p. 2536/// This AST node represents a function that returns 1 if two *types* (not 2537/// expressions) are compatible. The result of this built-in function can be 2538/// used in integer constant expressions. 2539class TypesCompatibleExpr : public Expr { 2540 QualType Type1; 2541 QualType Type2; 2542 SourceLocation BuiltinLoc, RParenLoc; 2543public: 2544 TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 2545 QualType t1, QualType t2, SourceLocation RP) : 2546 Expr(TypesCompatibleExprClass, ReturnType, false, false), 2547 Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {} 2548 2549 /// \brief Build an empty __builtin_type_compatible_p expression. 2550 explicit TypesCompatibleExpr(EmptyShell Empty) 2551 : Expr(TypesCompatibleExprClass, Empty) { } 2552 2553 QualType getArgType1() const { return Type1; } 2554 void setArgType1(QualType T) { Type1 = T; } 2555 QualType getArgType2() const { return Type2; } 2556 void setArgType2(QualType T) { Type2 = T; } 2557 2558 SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2559 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 2560 2561 SourceLocation getRParenLoc() const { return RParenLoc; } 2562 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2563 2564 virtual SourceRange getSourceRange() const { 2565 return SourceRange(BuiltinLoc, RParenLoc); 2566 } 2567 static bool classof(const Stmt *T) { 2568 return T->getStmtClass() == TypesCompatibleExprClass; 2569 } 2570 static bool classof(const TypesCompatibleExpr *) { return true; } 2571 2572 // Iterators 2573 virtual child_iterator child_begin(); 2574 virtual child_iterator child_end(); 2575}; 2576 2577/// ShuffleVectorExpr - clang-specific builtin-in function 2578/// __builtin_shufflevector. 2579/// This AST node represents a operator that does a constant 2580/// shuffle, similar to LLVM's shufflevector instruction. It takes 2581/// two vectors and a variable number of constant indices, 2582/// and returns the appropriately shuffled vector. 2583class ShuffleVectorExpr : public Expr { 2584 SourceLocation BuiltinLoc, RParenLoc; 2585 2586 // SubExprs - the list of values passed to the __builtin_shufflevector 2587 // function. The first two are vectors, and the rest are constant 2588 // indices. The number of values in this list is always 2589 // 2+the number of indices in the vector type. 2590 Stmt **SubExprs; 2591 unsigned NumExprs; 2592 2593public: 2594 // FIXME: Can a shufflevector be value-dependent? Does type-dependence need 2595 // to be computed differently? 2596 ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 2597 QualType Type, SourceLocation BLoc, 2598 SourceLocation RP) : 2599 Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false), 2600 BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) { 2601 2602 SubExprs = new (C) Stmt*[nexpr]; 2603 for (unsigned i = 0; i < nexpr; i++) 2604 SubExprs[i] = args[i]; 2605 } 2606 2607 /// \brief Build an empty vector-shuffle expression. 2608 explicit ShuffleVectorExpr(EmptyShell Empty) 2609 : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 2610 2611 SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2612 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 2613 2614 SourceLocation getRParenLoc() const { return RParenLoc; } 2615 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2616 2617 virtual SourceRange getSourceRange() const { 2618 return SourceRange(BuiltinLoc, RParenLoc); 2619 } 2620 static bool classof(const Stmt *T) { 2621 return T->getStmtClass() == ShuffleVectorExprClass; 2622 } 2623 static bool classof(const ShuffleVectorExpr *) { return true; } 2624 2625 /// getNumSubExprs - Return the size of the SubExprs array. This includes the 2626 /// constant expression, the actual arguments passed in, and the function 2627 /// pointers. 2628 unsigned getNumSubExprs() const { return NumExprs; } 2629 2630 /// getExpr - Return the Expr at the specified index. 2631 Expr *getExpr(unsigned Index) { 2632 assert((Index < NumExprs) && "Arg access out of range!"); 2633 return cast<Expr>(SubExprs[Index]); 2634 } 2635 const Expr *getExpr(unsigned Index) const { 2636 assert((Index < NumExprs) && "Arg access out of range!"); 2637 return cast<Expr>(SubExprs[Index]); 2638 } 2639 2640 void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 2641 2642 unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 2643 assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 2644 return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 2645 } 2646 2647 // Iterators 2648 virtual child_iterator child_begin(); 2649 virtual child_iterator child_end(); 2650}; 2651 2652/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 2653/// This AST node is similar to the conditional operator (?:) in C, with 2654/// the following exceptions: 2655/// - the test expression must be a integer constant expression. 2656/// - the expression returned acts like the chosen subexpression in every 2657/// visible way: the type is the same as that of the chosen subexpression, 2658/// and all predicates (whether it's an l-value, whether it's an integer 2659/// constant expression, etc.) return the same result as for the chosen 2660/// sub-expression. 2661class ChooseExpr : public Expr { 2662 enum { COND, LHS, RHS, END_EXPR }; 2663 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 2664 SourceLocation BuiltinLoc, RParenLoc; 2665public: 2666 ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 2667 SourceLocation RP, bool TypeDependent, bool ValueDependent) 2668 : Expr(ChooseExprClass, t, TypeDependent, ValueDependent), 2669 BuiltinLoc(BLoc), RParenLoc(RP) { 2670 SubExprs[COND] = cond; 2671 SubExprs[LHS] = lhs; 2672 SubExprs[RHS] = rhs; 2673 } 2674 2675 /// \brief Build an empty __builtin_choose_expr. 2676 explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 2677 2678 /// isConditionTrue - Return whether the condition is true (i.e. not 2679 /// equal to zero). 2680 bool isConditionTrue(ASTContext &C) const; 2681 2682 /// getChosenSubExpr - Return the subexpression chosen according to the 2683 /// condition. 2684 Expr *getChosenSubExpr(ASTContext &C) const { 2685 return isConditionTrue(C) ? getLHS() : getRHS(); 2686 } 2687 2688 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2689 void setCond(Expr *E) { SubExprs[COND] = E; } 2690 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2691 void setLHS(Expr *E) { SubExprs[LHS] = E; } 2692 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2693 void setRHS(Expr *E) { SubExprs[RHS] = E; } 2694 2695 SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2696 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 2697 2698 SourceLocation getRParenLoc() const { return RParenLoc; } 2699 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2700 2701 virtual SourceRange getSourceRange() const { 2702 return SourceRange(BuiltinLoc, RParenLoc); 2703 } 2704 static bool classof(const Stmt *T) { 2705 return T->getStmtClass() == ChooseExprClass; 2706 } 2707 static bool classof(const ChooseExpr *) { return true; } 2708 2709 // Iterators 2710 virtual child_iterator child_begin(); 2711 virtual child_iterator child_end(); 2712}; 2713 2714/// GNUNullExpr - Implements the GNU __null extension, which is a name 2715/// for a null pointer constant that has integral type (e.g., int or 2716/// long) and is the same size and alignment as a pointer. The __null 2717/// extension is typically only used by system headers, which define 2718/// NULL as __null in C++ rather than using 0 (which is an integer 2719/// that may not match the size of a pointer). 2720class GNUNullExpr : public Expr { 2721 /// TokenLoc - The location of the __null keyword. 2722 SourceLocation TokenLoc; 2723 2724public: 2725 GNUNullExpr(QualType Ty, SourceLocation Loc) 2726 : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { } 2727 2728 /// \brief Build an empty GNU __null expression. 2729 explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 2730 2731 /// getTokenLocation - The location of the __null token. 2732 SourceLocation getTokenLocation() const { return TokenLoc; } 2733 void setTokenLocation(SourceLocation L) { TokenLoc = L; } 2734 2735 virtual SourceRange getSourceRange() const { 2736 return SourceRange(TokenLoc); 2737 } 2738 static bool classof(const Stmt *T) { 2739 return T->getStmtClass() == GNUNullExprClass; 2740 } 2741 static bool classof(const GNUNullExpr *) { return true; } 2742 2743 // Iterators 2744 virtual child_iterator child_begin(); 2745 virtual child_iterator child_end(); 2746}; 2747 2748/// VAArgExpr, used for the builtin function __builtin_va_arg. 2749class VAArgExpr : public Expr { 2750 Stmt *Val; 2751 SourceLocation BuiltinLoc, RParenLoc; 2752public: 2753 VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc) 2754 : Expr(VAArgExprClass, t, t->isDependentType(), false), 2755 Val(e), 2756 BuiltinLoc(BLoc), 2757 RParenLoc(RPLoc) { } 2758 2759 /// \brief Create an empty __builtin_va_arg expression. 2760 explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 2761 2762 const Expr *getSubExpr() const { return cast<Expr>(Val); } 2763 Expr *getSubExpr() { return cast<Expr>(Val); } 2764 void setSubExpr(Expr *E) { Val = E; } 2765 2766 SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 2767 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 2768 2769 SourceLocation getRParenLoc() const { return RParenLoc; } 2770 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2771 2772 virtual SourceRange getSourceRange() const { 2773 return SourceRange(BuiltinLoc, RParenLoc); 2774 } 2775 static bool classof(const Stmt *T) { 2776 return T->getStmtClass() == VAArgExprClass; 2777 } 2778 static bool classof(const VAArgExpr *) { return true; } 2779 2780 // Iterators 2781 virtual child_iterator child_begin(); 2782 virtual child_iterator child_end(); 2783}; 2784 2785/// @brief Describes an C or C++ initializer list. 2786/// 2787/// InitListExpr describes an initializer list, which can be used to 2788/// initialize objects of different types, including 2789/// struct/class/union types, arrays, and vectors. For example: 2790/// 2791/// @code 2792/// struct foo x = { 1, { 2, 3 } }; 2793/// @endcode 2794/// 2795/// Prior to semantic analysis, an initializer list will represent the 2796/// initializer list as written by the user, but will have the 2797/// placeholder type "void". This initializer list is called the 2798/// syntactic form of the initializer, and may contain C99 designated 2799/// initializers (represented as DesignatedInitExprs), initializations 2800/// of subobject members without explicit braces, and so on. Clients 2801/// interested in the original syntax of the initializer list should 2802/// use the syntactic form of the initializer list. 2803/// 2804/// After semantic analysis, the initializer list will represent the 2805/// semantic form of the initializer, where the initializations of all 2806/// subobjects are made explicit with nested InitListExpr nodes and 2807/// C99 designators have been eliminated by placing the designated 2808/// initializations into the subobject they initialize. Additionally, 2809/// any "holes" in the initialization, where no initializer has been 2810/// specified for a particular subobject, will be replaced with 2811/// implicitly-generated ImplicitValueInitExpr expressions that 2812/// value-initialize the subobjects. Note, however, that the 2813/// initializer lists may still have fewer initializers than there are 2814/// elements to initialize within the object. 2815/// 2816/// Given the semantic form of the initializer list, one can retrieve 2817/// the original syntactic form of that initializer list (if it 2818/// exists) using getSyntacticForm(). Since many initializer lists 2819/// have the same syntactic and semantic forms, getSyntacticForm() may 2820/// return NULL, indicating that the current initializer list also 2821/// serves as its syntactic form. 2822class InitListExpr : public Expr { 2823 // FIXME: Eliminate this vector in favor of ASTContext allocation 2824 typedef ASTVector<Stmt *> InitExprsTy; 2825 InitExprsTy InitExprs; 2826 SourceLocation LBraceLoc, RBraceLoc; 2827 2828 /// Contains the initializer list that describes the syntactic form 2829 /// written in the source code. 2830 InitListExpr *SyntacticForm; 2831 2832 /// If this initializer list initializes a union, specifies which 2833 /// field within the union will be initialized. 2834 FieldDecl *UnionFieldInit; 2835 2836 /// Whether this initializer list originally had a GNU array-range 2837 /// designator in it. This is a temporary marker used by CodeGen. 2838 bool HadArrayRangeDesignator; 2839 2840public: 2841 InitListExpr(ASTContext &C, SourceLocation lbraceloc, 2842 Expr **initexprs, unsigned numinits, 2843 SourceLocation rbraceloc); 2844 2845 /// \brief Build an empty initializer list. 2846 explicit InitListExpr(ASTContext &C, EmptyShell Empty) 2847 : Expr(InitListExprClass, Empty), InitExprs(C) { } 2848 2849 unsigned getNumInits() const { return InitExprs.size(); } 2850 2851 const Expr* getInit(unsigned Init) const { 2852 assert(Init < getNumInits() && "Initializer access out of range!"); 2853 return cast_or_null<Expr>(InitExprs[Init]); 2854 } 2855 2856 Expr* getInit(unsigned Init) { 2857 assert(Init < getNumInits() && "Initializer access out of range!"); 2858 return cast_or_null<Expr>(InitExprs[Init]); 2859 } 2860 2861 void setInit(unsigned Init, Expr *expr) { 2862 assert(Init < getNumInits() && "Initializer access out of range!"); 2863 InitExprs[Init] = expr; 2864 } 2865 2866 /// \brief Reserve space for some number of initializers. 2867 void reserveInits(ASTContext &C, unsigned NumInits); 2868 2869 /// @brief Specify the number of initializers 2870 /// 2871 /// If there are more than @p NumInits initializers, the remaining 2872 /// initializers will be destroyed. If there are fewer than @p 2873 /// NumInits initializers, NULL expressions will be added for the 2874 /// unknown initializers. 2875 void resizeInits(ASTContext &Context, unsigned NumInits); 2876 2877 /// @brief Updates the initializer at index @p Init with the new 2878 /// expression @p expr, and returns the old expression at that 2879 /// location. 2880 /// 2881 /// When @p Init is out of range for this initializer list, the 2882 /// initializer list will be extended with NULL expressions to 2883 /// accomodate the new entry. 2884 Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 2885 2886 /// \brief If this initializes a union, specifies which field in the 2887 /// union to initialize. 2888 /// 2889 /// Typically, this field is the first named field within the 2890 /// union. However, a designated initializer can specify the 2891 /// initialization of a different field within the union. 2892 FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; } 2893 void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; } 2894 2895 // Explicit InitListExpr's originate from source code (and have valid source 2896 // locations). Implicit InitListExpr's are created by the semantic analyzer. 2897 bool isExplicit() { 2898 return LBraceLoc.isValid() && RBraceLoc.isValid(); 2899 } 2900 2901 SourceLocation getLBraceLoc() const { return LBraceLoc; } 2902 void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 2903 SourceLocation getRBraceLoc() const { return RBraceLoc; } 2904 void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 2905 2906 /// @brief Retrieve the initializer list that describes the 2907 /// syntactic form of the initializer. 2908 /// 2909 /// 2910 InitListExpr *getSyntacticForm() const { return SyntacticForm; } 2911 void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 2912 2913 bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 2914 void sawArrayRangeDesignator(bool ARD = true) { 2915 HadArrayRangeDesignator = ARD; 2916 } 2917 2918 virtual SourceRange getSourceRange() const { 2919 return SourceRange(LBraceLoc, RBraceLoc); 2920 } 2921 static bool classof(const Stmt *T) { 2922 return T->getStmtClass() == InitListExprClass; 2923 } 2924 static bool classof(const InitListExpr *) { return true; } 2925 2926 // Iterators 2927 virtual child_iterator child_begin(); 2928 virtual child_iterator child_end(); 2929 2930 typedef InitExprsTy::iterator iterator; 2931 typedef InitExprsTy::const_iterator const_iterator; 2932 typedef InitExprsTy::reverse_iterator reverse_iterator; 2933 typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 2934 2935 iterator begin() { return InitExprs.begin(); } 2936 const_iterator begin() const { return InitExprs.begin(); } 2937 iterator end() { return InitExprs.end(); } 2938 const_iterator end() const { return InitExprs.end(); } 2939 reverse_iterator rbegin() { return InitExprs.rbegin(); } 2940 const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 2941 reverse_iterator rend() { return InitExprs.rend(); } 2942 const_reverse_iterator rend() const { return InitExprs.rend(); } 2943}; 2944 2945/// @brief Represents a C99 designated initializer expression. 2946/// 2947/// A designated initializer expression (C99 6.7.8) contains one or 2948/// more designators (which can be field designators, array 2949/// designators, or GNU array-range designators) followed by an 2950/// expression that initializes the field or element(s) that the 2951/// designators refer to. For example, given: 2952/// 2953/// @code 2954/// struct point { 2955/// double x; 2956/// double y; 2957/// }; 2958/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 2959/// @endcode 2960/// 2961/// The InitListExpr contains three DesignatedInitExprs, the first of 2962/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 2963/// designators, one array designator for @c [2] followed by one field 2964/// designator for @c .y. The initalization expression will be 1.0. 2965class DesignatedInitExpr : public Expr { 2966public: 2967 /// \brief Forward declaration of the Designator class. 2968 class Designator; 2969 2970private: 2971 /// The location of the '=' or ':' prior to the actual initializer 2972 /// expression. 2973 SourceLocation EqualOrColonLoc; 2974 2975 /// Whether this designated initializer used the GNU deprecated 2976 /// syntax rather than the C99 '=' syntax. 2977 bool GNUSyntax : 1; 2978 2979 /// The number of designators in this initializer expression. 2980 unsigned NumDesignators : 15; 2981 2982 /// \brief The designators in this designated initialization 2983 /// expression. 2984 Designator *Designators; 2985 2986 /// The number of subexpressions of this initializer expression, 2987 /// which contains both the initializer and any additional 2988 /// expressions used by array and array-range designators. 2989 unsigned NumSubExprs : 16; 2990 2991 2992 DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 2993 const Designator *Designators, 2994 SourceLocation EqualOrColonLoc, bool GNUSyntax, 2995 Expr **IndexExprs, unsigned NumIndexExprs, 2996 Expr *Init); 2997 2998 explicit DesignatedInitExpr(unsigned NumSubExprs) 2999 : Expr(DesignatedInitExprClass, EmptyShell()), 3000 NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3001 3002public: 3003 /// A field designator, e.g., ".x". 3004 struct FieldDesignator { 3005 /// Refers to the field that is being initialized. The low bit 3006 /// of this field determines whether this is actually a pointer 3007 /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 3008 /// initially constructed, a field designator will store an 3009 /// IdentifierInfo*. After semantic analysis has resolved that 3010 /// name, the field designator will instead store a FieldDecl*. 3011 uintptr_t NameOrField; 3012 3013 /// The location of the '.' in the designated initializer. 3014 unsigned DotLoc; 3015 3016 /// The location of the field name in the designated initializer. 3017 unsigned FieldLoc; 3018 }; 3019 3020 /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 3021 struct ArrayOrRangeDesignator { 3022 /// Location of the first index expression within the designated 3023 /// initializer expression's list of subexpressions. 3024 unsigned Index; 3025 /// The location of the '[' starting the array range designator. 3026 unsigned LBracketLoc; 3027 /// The location of the ellipsis separating the start and end 3028 /// indices. Only valid for GNU array-range designators. 3029 unsigned EllipsisLoc; 3030 /// The location of the ']' terminating the array range designator. 3031 unsigned RBracketLoc; 3032 }; 3033 3034 /// @brief Represents a single C99 designator. 3035 /// 3036 /// @todo This class is infuriatingly similar to clang::Designator, 3037 /// but minor differences (storing indices vs. storing pointers) 3038 /// keep us from reusing it. Try harder, later, to rectify these 3039 /// differences. 3040 class Designator { 3041 /// @brief The kind of designator this describes. 3042 enum { 3043 FieldDesignator, 3044 ArrayDesignator, 3045 ArrayRangeDesignator 3046 } Kind; 3047 3048 union { 3049 /// A field designator, e.g., ".x". 3050 struct FieldDesignator Field; 3051 /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 3052 struct ArrayOrRangeDesignator ArrayOrRange; 3053 }; 3054 friend class DesignatedInitExpr; 3055 3056 public: 3057 Designator() {} 3058 3059 /// @brief Initializes a field designator. 3060 Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 3061 SourceLocation FieldLoc) 3062 : Kind(FieldDesignator) { 3063 Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 3064 Field.DotLoc = DotLoc.getRawEncoding(); 3065 Field.FieldLoc = FieldLoc.getRawEncoding(); 3066 } 3067 3068 /// @brief Initializes an array designator. 3069 Designator(unsigned Index, SourceLocation LBracketLoc, 3070 SourceLocation RBracketLoc) 3071 : Kind(ArrayDesignator) { 3072 ArrayOrRange.Index = Index; 3073 ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 3074 ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 3075 ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 3076 } 3077 3078 /// @brief Initializes a GNU array-range designator. 3079 Designator(unsigned Index, SourceLocation LBracketLoc, 3080 SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 3081 : Kind(ArrayRangeDesignator) { 3082 ArrayOrRange.Index = Index; 3083 ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 3084 ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 3085 ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 3086 } 3087 3088 bool isFieldDesignator() const { return Kind == FieldDesignator; } 3089 bool isArrayDesignator() const { return Kind == ArrayDesignator; } 3090 bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 3091 3092 IdentifierInfo * getFieldName(); 3093 3094 FieldDecl *getField() { 3095 assert(Kind == FieldDesignator && "Only valid on a field designator"); 3096 if (Field.NameOrField & 0x01) 3097 return 0; 3098 else 3099 return reinterpret_cast<FieldDecl *>(Field.NameOrField); 3100 } 3101 3102 void setField(FieldDecl *FD) { 3103 assert(Kind == FieldDesignator && "Only valid on a field designator"); 3104 Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 3105 } 3106 3107 SourceLocation getDotLoc() const { 3108 assert(Kind == FieldDesignator && "Only valid on a field designator"); 3109 return SourceLocation::getFromRawEncoding(Field.DotLoc); 3110 } 3111 3112 SourceLocation getFieldLoc() const { 3113 assert(Kind == FieldDesignator && "Only valid on a field designator"); 3114 return SourceLocation::getFromRawEncoding(Field.FieldLoc); 3115 } 3116 3117 SourceLocation getLBracketLoc() const { 3118 assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3119 "Only valid on an array or array-range designator"); 3120 return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 3121 } 3122 3123 SourceLocation getRBracketLoc() const { 3124 assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3125 "Only valid on an array or array-range designator"); 3126 return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 3127 } 3128 3129 SourceLocation getEllipsisLoc() const { 3130 assert(Kind == ArrayRangeDesignator && 3131 "Only valid on an array-range designator"); 3132 return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 3133 } 3134 3135 unsigned getFirstExprIndex() const { 3136 assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3137 "Only valid on an array or array-range designator"); 3138 return ArrayOrRange.Index; 3139 } 3140 3141 SourceLocation getStartLocation() const { 3142 if (Kind == FieldDesignator) 3143 return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 3144 else 3145 return getLBracketLoc(); 3146 } 3147 }; 3148 3149 static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 3150 unsigned NumDesignators, 3151 Expr **IndexExprs, unsigned NumIndexExprs, 3152 SourceLocation EqualOrColonLoc, 3153 bool GNUSyntax, Expr *Init); 3154 3155 static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3156 3157 /// @brief Returns the number of designators in this initializer. 3158 unsigned size() const { return NumDesignators; } 3159 3160 // Iterator access to the designators. 3161 typedef Designator* designators_iterator; 3162 designators_iterator designators_begin() { return Designators; } 3163 designators_iterator designators_end() { 3164 return Designators + NumDesignators; 3165 } 3166 3167 Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3168 3169 void setDesignators(ASTContext &C, const Designator *Desigs, 3170 unsigned NumDesigs); 3171 3172 Expr *getArrayIndex(const Designator& D); 3173 Expr *getArrayRangeStart(const Designator& D); 3174 Expr *getArrayRangeEnd(const Designator& D); 3175 3176 /// @brief Retrieve the location of the '=' that precedes the 3177 /// initializer value itself, if present. 3178 SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3179 void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 3180 3181 /// @brief Determines whether this designated initializer used the 3182 /// deprecated GNU syntax for designated initializers. 3183 bool usesGNUSyntax() const { return GNUSyntax; } 3184 void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 3185 3186 /// @brief Retrieve the initializer value. 3187 Expr *getInit() const { 3188 return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 3189 } 3190 3191 void setInit(Expr *init) { 3192 *child_begin() = init; 3193 } 3194 3195 /// \brief Retrieve the total number of subexpressions in this 3196 /// designated initializer expression, including the actual 3197 /// initialized value and any expressions that occur within array 3198 /// and array-range designators. 3199 unsigned getNumSubExprs() const { return NumSubExprs; } 3200 3201 Expr *getSubExpr(unsigned Idx) { 3202 assert(Idx < NumSubExprs && "Subscript out of range"); 3203 char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3204 Ptr += sizeof(DesignatedInitExpr); 3205 return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3206 } 3207 3208 void setSubExpr(unsigned Idx, Expr *E) { 3209 assert(Idx < NumSubExprs && "Subscript out of range"); 3210 char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3211 Ptr += sizeof(DesignatedInitExpr); 3212 reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3213 } 3214 3215 /// \brief Replaces the designator at index @p Idx with the series 3216 /// of designators in [First, Last). 3217 void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3218 const Designator *Last); 3219 3220 virtual SourceRange getSourceRange() const; 3221 3222 static bool classof(const Stmt *T) { 3223 return T->getStmtClass() == DesignatedInitExprClass; 3224 } 3225 static bool classof(const DesignatedInitExpr *) { return true; } 3226 3227 // Iterators 3228 virtual child_iterator child_begin(); 3229 virtual child_iterator child_end(); 3230}; 3231 3232/// \brief Represents an implicitly-generated value initialization of 3233/// an object of a given type. 3234/// 3235/// Implicit value initializations occur within semantic initializer 3236/// list expressions (InitListExpr) as placeholders for subobject 3237/// initializations not explicitly specified by the user. 3238/// 3239/// \see InitListExpr 3240class ImplicitValueInitExpr : public Expr { 3241public: 3242 explicit ImplicitValueInitExpr(QualType ty) 3243 : Expr(ImplicitValueInitExprClass, ty, false, false) { } 3244 3245 /// \brief Construct an empty implicit value initialization. 3246 explicit ImplicitValueInitExpr(EmptyShell Empty) 3247 : Expr(ImplicitValueInitExprClass, Empty) { } 3248 3249 static bool classof(const Stmt *T) { 3250 return T->getStmtClass() == ImplicitValueInitExprClass; 3251 } 3252 static bool classof(const ImplicitValueInitExpr *) { return true; } 3253 3254 virtual SourceRange getSourceRange() const { 3255 return SourceRange(); 3256 } 3257 3258 // Iterators 3259 virtual child_iterator child_begin(); 3260 virtual child_iterator child_end(); 3261}; 3262 3263 3264class ParenListExpr : public Expr { 3265 Stmt **Exprs; 3266 unsigned NumExprs; 3267 SourceLocation LParenLoc, RParenLoc; 3268 3269public: 3270 ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 3271 unsigned numexprs, SourceLocation rparenloc); 3272 3273 /// \brief Build an empty paren list. 3274 explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 3275 3276 unsigned getNumExprs() const { return NumExprs; } 3277 3278 const Expr* getExpr(unsigned Init) const { 3279 assert(Init < getNumExprs() && "Initializer access out of range!"); 3280 return cast_or_null<Expr>(Exprs[Init]); 3281 } 3282 3283 Expr* getExpr(unsigned Init) { 3284 assert(Init < getNumExprs() && "Initializer access out of range!"); 3285 return cast_or_null<Expr>(Exprs[Init]); 3286 } 3287 3288 Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 3289 3290 SourceLocation getLParenLoc() const { return LParenLoc; } 3291 SourceLocation getRParenLoc() const { return RParenLoc; } 3292 3293 virtual SourceRange getSourceRange() const { 3294 return SourceRange(LParenLoc, RParenLoc); 3295 } 3296 static bool classof(const Stmt *T) { 3297 return T->getStmtClass() == ParenListExprClass; 3298 } 3299 static bool classof(const ParenListExpr *) { return true; } 3300 3301 // Iterators 3302 virtual child_iterator child_begin(); 3303 virtual child_iterator child_end(); 3304 3305 friend class PCHStmtReader; 3306 friend class PCHStmtWriter; 3307}; 3308 3309 3310//===----------------------------------------------------------------------===// 3311// Clang Extensions 3312//===----------------------------------------------------------------------===// 3313 3314 3315/// ExtVectorElementExpr - This represents access to specific elements of a 3316/// vector, and may occur on the left hand side or right hand side. For example 3317/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3318/// 3319/// Note that the base may have either vector or pointer to vector type, just 3320/// like a struct field reference. 3321/// 3322class ExtVectorElementExpr : public Expr { 3323 Stmt *Base; 3324 IdentifierInfo *Accessor; 3325 SourceLocation AccessorLoc; 3326public: 3327 ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 3328 SourceLocation loc) 3329 : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(), 3330 base->isValueDependent()), 3331 Base(base), Accessor(&accessor), AccessorLoc(loc) {} 3332 3333 /// \brief Build an empty vector element expression. 3334 explicit ExtVectorElementExpr(EmptyShell Empty) 3335 : Expr(ExtVectorElementExprClass, Empty) { } 3336 3337 const Expr *getBase() const { return cast<Expr>(Base); } 3338 Expr *getBase() { return cast<Expr>(Base); } 3339 void setBase(Expr *E) { Base = E; } 3340 3341 IdentifierInfo &getAccessor() const { return *Accessor; } 3342 void setAccessor(IdentifierInfo *II) { Accessor = II; } 3343 3344 SourceLocation getAccessorLoc() const { return AccessorLoc; } 3345 void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 3346 3347 /// getNumElements - Get the number of components being selected. 3348 unsigned getNumElements() const; 3349 3350 /// containsDuplicateElements - Return true if any element access is 3351 /// repeated. 3352 bool containsDuplicateElements() const; 3353 3354 /// getEncodedElementAccess - Encode the elements accessed into an llvm 3355 /// aggregate Constant of ConstantInt(s). 3356 void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 3357 3358 virtual SourceRange getSourceRange() const { 3359 return SourceRange(getBase()->getLocStart(), AccessorLoc); 3360 } 3361 3362 /// isArrow - Return true if the base expression is a pointer to vector, 3363 /// return false if the base expression is a vector. 3364 bool isArrow() const; 3365 3366 static bool classof(const Stmt *T) { 3367 return T->getStmtClass() == ExtVectorElementExprClass; 3368 } 3369 static bool classof(const ExtVectorElementExpr *) { return true; } 3370 3371 // Iterators 3372 virtual child_iterator child_begin(); 3373 virtual child_iterator child_end(); 3374}; 3375 3376 3377/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 3378/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 3379class BlockExpr : public Expr { 3380protected: 3381 BlockDecl *TheBlock; 3382 bool HasBlockDeclRefExprs; 3383public: 3384 BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs) 3385 : Expr(BlockExprClass, ty, ty->isDependentType(), false), 3386 TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {} 3387 3388 /// \brief Build an empty block expression. 3389 explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 3390 3391 const BlockDecl *getBlockDecl() const { return TheBlock; } 3392 BlockDecl *getBlockDecl() { return TheBlock; } 3393 void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 3394 3395 // Convenience functions for probing the underlying BlockDecl. 3396 SourceLocation getCaretLocation() const; 3397 const Stmt *getBody() const; 3398 Stmt *getBody(); 3399 3400 virtual SourceRange getSourceRange() const { 3401 return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 3402 } 3403 3404 /// getFunctionType - Return the underlying function type for this block. 3405 const FunctionType *getFunctionType() const; 3406 3407 /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr 3408 /// inside of the block that reference values outside the block. 3409 bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; } 3410 void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; } 3411 3412 static bool classof(const Stmt *T) { 3413 return T->getStmtClass() == BlockExprClass; 3414 } 3415 static bool classof(const BlockExpr *) { return true; } 3416 3417 // Iterators 3418 virtual child_iterator child_begin(); 3419 virtual child_iterator child_end(); 3420}; 3421 3422/// BlockDeclRefExpr - A reference to a declared variable, function, 3423/// enum, etc. 3424class BlockDeclRefExpr : public Expr { 3425 ValueDecl *D; 3426 SourceLocation Loc; 3427 bool IsByRef : 1; 3428 bool ConstQualAdded : 1; 3429 Stmt *CopyConstructorVal; 3430public: 3431 // FIXME: Fix type/value dependence! 3432 BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef, 3433 bool constAdded = false, 3434 Stmt *copyConstructorVal = 0) 3435 : Expr(BlockDeclRefExprClass, t, (!t.isNull() && t->isDependentType()),false), 3436 D(d), Loc(l), IsByRef(ByRef), 3437 ConstQualAdded(constAdded), CopyConstructorVal(copyConstructorVal) {} 3438 3439 // \brief Build an empty reference to a declared variable in a 3440 // block. 3441 explicit BlockDeclRefExpr(EmptyShell Empty) 3442 : Expr(BlockDeclRefExprClass, Empty) { } 3443 3444 ValueDecl *getDecl() { return D; } 3445 const ValueDecl *getDecl() const { return D; } 3446 void setDecl(ValueDecl *VD) { D = VD; } 3447 3448 SourceLocation getLocation() const { return Loc; } 3449 void setLocation(SourceLocation L) { Loc = L; } 3450 3451 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 3452 3453 bool isByRef() const { return IsByRef; } 3454 void setByRef(bool BR) { IsByRef = BR; } 3455 3456 bool isConstQualAdded() const { return ConstQualAdded; } 3457 void setConstQualAdded(bool C) { ConstQualAdded = C; } 3458 3459 const Expr *getCopyConstructorExpr() const 3460 { return cast_or_null<Expr>(CopyConstructorVal); } 3461 Expr *getCopyConstructorExpr() 3462 { return cast_or_null<Expr>(CopyConstructorVal); } 3463 void setCopyConstructorExpr(Expr *E) { CopyConstructorVal = E; } 3464 3465 static bool classof(const Stmt *T) { 3466 return T->getStmtClass() == BlockDeclRefExprClass; 3467 } 3468 static bool classof(const BlockDeclRefExpr *) { return true; } 3469 3470 // Iterators 3471 virtual child_iterator child_begin(); 3472 virtual child_iterator child_end(); 3473}; 3474 3475} // end namespace clang 3476 3477#endif 3478