clang API Documentation
00001 //===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the Expr interface and subclasses. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_AST_EXPR_H 00015 #define LLVM_CLANG_AST_EXPR_H 00016 00017 #include "clang/AST/APValue.h" 00018 #include "clang/AST/Stmt.h" 00019 #include "clang/AST/Type.h" 00020 #include "clang/AST/DeclAccessPair.h" 00021 #include "clang/AST/OperationKinds.h" 00022 #include "clang/AST/ASTVector.h" 00023 #include "clang/AST/TemplateBase.h" 00024 #include "clang/Basic/TargetInfo.h" 00025 #include "clang/Basic/TypeTraits.h" 00026 #include "llvm/ADT/APSInt.h" 00027 #include "llvm/ADT/APFloat.h" 00028 #include "llvm/ADT/SmallVector.h" 00029 #include "llvm/ADT/StringRef.h" 00030 #include "llvm/Support/Compiler.h" 00031 #include <cctype> 00032 00033 namespace clang { 00034 class ASTContext; 00035 class APValue; 00036 class Decl; 00037 class IdentifierInfo; 00038 class ParmVarDecl; 00039 class NamedDecl; 00040 class ValueDecl; 00041 class BlockDecl; 00042 class CXXBaseSpecifier; 00043 class CXXOperatorCallExpr; 00044 class CXXMemberCallExpr; 00045 class ObjCPropertyRefExpr; 00046 class OpaqueValueExpr; 00047 00048 /// \brief A simple array of base specifiers. 00049 typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 00050 00051 /// Expr - This represents one expression. Note that Expr's are subclasses of 00052 /// Stmt. This allows an expression to be transparently used any place a Stmt 00053 /// is required. 00054 /// 00055 class Expr : public Stmt { 00056 QualType TR; 00057 00058 protected: 00059 Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 00060 bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) 00061 : Stmt(SC) 00062 { 00063 ExprBits.TypeDependent = TD; 00064 ExprBits.ValueDependent = VD; 00065 ExprBits.InstantiationDependent = ID; 00066 ExprBits.ValueKind = VK; 00067 ExprBits.ObjectKind = OK; 00068 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 00069 setType(T); 00070 } 00071 00072 /// \brief Construct an empty expression. 00073 explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 00074 00075 public: 00076 QualType getType() const { return TR; } 00077 void setType(QualType t) { 00078 // In C++, the type of an expression is always adjusted so that it 00079 // will not have reference type an expression will never have 00080 // reference type (C++ [expr]p6). Use 00081 // QualType::getNonReferenceType() to retrieve the non-reference 00082 // type. Additionally, inspect Expr::isLvalue to determine whether 00083 // an expression that is adjusted in this manner should be 00084 // considered an lvalue. 00085 assert((t.isNull() || !t->isReferenceType()) && 00086 "Expressions can't have reference type"); 00087 00088 TR = t; 00089 } 00090 00091 /// isValueDependent - Determines whether this expression is 00092 /// value-dependent (C++ [temp.dep.constexpr]). For example, the 00093 /// array bound of "Chars" in the following example is 00094 /// value-dependent. 00095 /// @code 00096 /// template<int Size, char (&Chars)[Size]> struct meta_string; 00097 /// @endcode 00098 bool isValueDependent() const { return ExprBits.ValueDependent; } 00099 00100 /// \brief Set whether this expression is value-dependent or not. 00101 void setValueDependent(bool VD) { 00102 ExprBits.ValueDependent = VD; 00103 if (VD) 00104 ExprBits.InstantiationDependent = true; 00105 } 00106 00107 /// isTypeDependent - Determines whether this expression is 00108 /// type-dependent (C++ [temp.dep.expr]), which means that its type 00109 /// could change from one template instantiation to the next. For 00110 /// example, the expressions "x" and "x + y" are type-dependent in 00111 /// the following code, but "y" is not type-dependent: 00112 /// @code 00113 /// template<typename T> 00114 /// void add(T x, int y) { 00115 /// x + y; 00116 /// } 00117 /// @endcode 00118 bool isTypeDependent() const { return ExprBits.TypeDependent; } 00119 00120 /// \brief Set whether this expression is type-dependent or not. 00121 void setTypeDependent(bool TD) { 00122 ExprBits.TypeDependent = TD; 00123 if (TD) 00124 ExprBits.InstantiationDependent = true; 00125 } 00126 00127 /// \brief Whether this expression is instantiation-dependent, meaning that 00128 /// it depends in some way on a template parameter, even if neither its type 00129 /// nor (constant) value can change due to the template instantiation. 00130 /// 00131 /// In the following example, the expression \c sizeof(sizeof(T() + T())) is 00132 /// instantiation-dependent (since it involves a template parameter \c T), but 00133 /// is neither type- nor value-dependent, since the type of the inner 00134 /// \c sizeof is known (\c std::size_t) and therefore the size of the outer 00135 /// \c sizeof is known. 00136 /// 00137 /// \code 00138 /// template<typename T> 00139 /// void f(T x, T y) { 00140 /// sizeof(sizeof(T() + T()); 00141 /// } 00142 /// \endcode 00143 /// 00144 bool isInstantiationDependent() const { 00145 return ExprBits.InstantiationDependent; 00146 } 00147 00148 /// \brief Set whether this expression is instantiation-dependent or not. 00149 void setInstantiationDependent(bool ID) { 00150 ExprBits.InstantiationDependent = ID; 00151 } 00152 00153 /// \brief Whether this expression contains an unexpanded parameter 00154 /// pack (for C++0x variadic templates). 00155 /// 00156 /// Given the following function template: 00157 /// 00158 /// \code 00159 /// template<typename F, typename ...Types> 00160 /// void forward(const F &f, Types &&...args) { 00161 /// f(static_cast<Types&&>(args)...); 00162 /// } 00163 /// \endcode 00164 /// 00165 /// The expressions \c args and \c static_cast<Types&&>(args) both 00166 /// contain parameter packs. 00167 bool containsUnexpandedParameterPack() const { 00168 return ExprBits.ContainsUnexpandedParameterPack; 00169 } 00170 00171 /// \brief Set the bit that describes whether this expression 00172 /// contains an unexpanded parameter pack. 00173 void setContainsUnexpandedParameterPack(bool PP = true) { 00174 ExprBits.ContainsUnexpandedParameterPack = PP; 00175 } 00176 00177 /// getExprLoc - Return the preferred location for the arrow when diagnosing 00178 /// a problem with a generic expression. 00179 SourceLocation getExprLoc() const LLVM_READONLY; 00180 00181 /// isUnusedResultAWarning - Return true if this immediate expression should 00182 /// be warned about if the result is unused. If so, fill in Loc and Ranges 00183 /// with location to warn on and the source range[s] to report with the 00184 /// warning. 00185 bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 00186 SourceRange &R2, ASTContext &Ctx) const; 00187 00188 /// isLValue - True if this expression is an "l-value" according to 00189 /// the rules of the current language. C and C++ give somewhat 00190 /// different rules for this concept, but in general, the result of 00191 /// an l-value expression identifies a specific object whereas the 00192 /// result of an r-value expression is a value detached from any 00193 /// specific storage. 00194 /// 00195 /// C++0x divides the concept of "r-value" into pure r-values 00196 /// ("pr-values") and so-called expiring values ("x-values"), which 00197 /// identify specific objects that can be safely cannibalized for 00198 /// their resources. This is an unfortunate abuse of terminology on 00199 /// the part of the C++ committee. In Clang, when we say "r-value", 00200 /// we generally mean a pr-value. 00201 bool isLValue() const { return getValueKind() == VK_LValue; } 00202 bool isRValue() const { return getValueKind() == VK_RValue; } 00203 bool isXValue() const { return getValueKind() == VK_XValue; } 00204 bool isGLValue() const { return getValueKind() != VK_RValue; } 00205 00206 enum LValueClassification { 00207 LV_Valid, 00208 LV_NotObjectType, 00209 LV_IncompleteVoidType, 00210 LV_DuplicateVectorComponents, 00211 LV_InvalidExpression, 00212 LV_InvalidMessageExpression, 00213 LV_MemberFunction, 00214 LV_SubObjCPropertySetting, 00215 LV_ClassTemporary 00216 }; 00217 /// Reasons why an expression might not be an l-value. 00218 LValueClassification ClassifyLValue(ASTContext &Ctx) const; 00219 00220 /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 00221 /// does not have an incomplete type, does not have a const-qualified type, 00222 /// and if it is a structure or union, does not have any member (including, 00223 /// recursively, any member or element of all contained aggregates or unions) 00224 /// with a const-qualified type. 00225 /// 00226 /// \param Loc [in] [out] - A source location which *may* be filled 00227 /// in with the location of the expression making this a 00228 /// non-modifiable lvalue, if specified. 00229 enum isModifiableLvalueResult { 00230 MLV_Valid, 00231 MLV_NotObjectType, 00232 MLV_IncompleteVoidType, 00233 MLV_DuplicateVectorComponents, 00234 MLV_InvalidExpression, 00235 MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 00236 MLV_IncompleteType, 00237 MLV_ConstQualified, 00238 MLV_ArrayType, 00239 MLV_ReadonlyProperty, 00240 MLV_NoSetterProperty, 00241 MLV_MemberFunction, 00242 MLV_SubObjCPropertySetting, 00243 MLV_InvalidMessageExpression, 00244 MLV_ClassTemporary 00245 }; 00246 isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 00247 SourceLocation *Loc = 0) const; 00248 00249 /// \brief The return type of classify(). Represents the C++0x expression 00250 /// taxonomy. 00251 class Classification { 00252 public: 00253 /// \brief The various classification results. Most of these mean prvalue. 00254 enum Kinds { 00255 CL_LValue, 00256 CL_XValue, 00257 CL_Function, // Functions cannot be lvalues in C. 00258 CL_Void, // Void cannot be an lvalue in C. 00259 CL_AddressableVoid, // Void expression whose address can be taken in C. 00260 CL_DuplicateVectorComponents, // A vector shuffle with dupes. 00261 CL_MemberFunction, // An expression referring to a member function 00262 CL_SubObjCPropertySetting, 00263 CL_ClassTemporary, // A prvalue of class type 00264 CL_ObjCMessageRValue, // ObjC message is an rvalue 00265 CL_PRValue // A prvalue for any other reason, of any other type 00266 }; 00267 /// \brief The results of modification testing. 00268 enum ModifiableType { 00269 CM_Untested, // testModifiable was false. 00270 CM_Modifiable, 00271 CM_RValue, // Not modifiable because it's an rvalue 00272 CM_Function, // Not modifiable because it's a function; C++ only 00273 CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 00274 CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 00275 CM_ConstQualified, 00276 CM_ArrayType, 00277 CM_IncompleteType 00278 }; 00279 00280 private: 00281 friend class Expr; 00282 00283 unsigned short Kind; 00284 unsigned short Modifiable; 00285 00286 explicit Classification(Kinds k, ModifiableType m) 00287 : Kind(k), Modifiable(m) 00288 {} 00289 00290 public: 00291 Classification() {} 00292 00293 Kinds getKind() const { return static_cast<Kinds>(Kind); } 00294 ModifiableType getModifiable() const { 00295 assert(Modifiable != CM_Untested && "Did not test for modifiability."); 00296 return static_cast<ModifiableType>(Modifiable); 00297 } 00298 bool isLValue() const { return Kind == CL_LValue; } 00299 bool isXValue() const { return Kind == CL_XValue; } 00300 bool isGLValue() const { return Kind <= CL_XValue; } 00301 bool isPRValue() const { return Kind >= CL_Function; } 00302 bool isRValue() const { return Kind >= CL_XValue; } 00303 bool isModifiable() const { return getModifiable() == CM_Modifiable; } 00304 00305 /// \brief Create a simple, modifiably lvalue 00306 static Classification makeSimpleLValue() { 00307 return Classification(CL_LValue, CM_Modifiable); 00308 } 00309 00310 }; 00311 /// \brief Classify - Classify this expression according to the C++0x 00312 /// expression taxonomy. 00313 /// 00314 /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 00315 /// old lvalue vs rvalue. This function determines the type of expression this 00316 /// is. There are three expression types: 00317 /// - lvalues are classical lvalues as in C++03. 00318 /// - prvalues are equivalent to rvalues in C++03. 00319 /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 00320 /// function returning an rvalue reference. 00321 /// lvalues and xvalues are collectively referred to as glvalues, while 00322 /// prvalues and xvalues together form rvalues. 00323 Classification Classify(ASTContext &Ctx) const { 00324 return ClassifyImpl(Ctx, 0); 00325 } 00326 00327 /// \brief ClassifyModifiable - Classify this expression according to the 00328 /// C++0x expression taxonomy, and see if it is valid on the left side 00329 /// of an assignment. 00330 /// 00331 /// This function extends classify in that it also tests whether the 00332 /// expression is modifiable (C99 6.3.2.1p1). 00333 /// \param Loc A source location that might be filled with a relevant location 00334 /// if the expression is not modifiable. 00335 Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 00336 return ClassifyImpl(Ctx, &Loc); 00337 } 00338 00339 /// getValueKindForType - Given a formal return or parameter type, 00340 /// give its value kind. 00341 static ExprValueKind getValueKindForType(QualType T) { 00342 if (const ReferenceType *RT = T->getAs<ReferenceType>()) 00343 return (isa<LValueReferenceType>(RT) 00344 ? VK_LValue 00345 : (RT->getPointeeType()->isFunctionType() 00346 ? VK_LValue : VK_XValue)); 00347 return VK_RValue; 00348 } 00349 00350 /// getValueKind - The value kind that this expression produces. 00351 ExprValueKind getValueKind() const { 00352 return static_cast<ExprValueKind>(ExprBits.ValueKind); 00353 } 00354 00355 /// getObjectKind - The object kind that this expression produces. 00356 /// Object kinds are meaningful only for expressions that yield an 00357 /// l-value or x-value. 00358 ExprObjectKind getObjectKind() const { 00359 return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 00360 } 00361 00362 bool isOrdinaryOrBitFieldObject() const { 00363 ExprObjectKind OK = getObjectKind(); 00364 return (OK == OK_Ordinary || OK == OK_BitField); 00365 } 00366 00367 /// setValueKind - Set the value kind produced by this expression. 00368 void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 00369 00370 /// setObjectKind - Set the object kind produced by this expression. 00371 void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 00372 00373 private: 00374 Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 00375 00376 public: 00377 00378 /// \brief If this expression refers to a bit-field, retrieve the 00379 /// declaration of that bit-field. 00380 FieldDecl *getBitField(); 00381 00382 const FieldDecl *getBitField() const { 00383 return const_cast<Expr*>(this)->getBitField(); 00384 } 00385 00386 /// \brief If this expression is an l-value for an Objective C 00387 /// property, find the underlying property reference expression. 00388 const ObjCPropertyRefExpr *getObjCProperty() const; 00389 00390 /// \brief Returns whether this expression refers to a vector element. 00391 bool refersToVectorElement() const; 00392 00393 /// \brief Returns whether this expression has a placeholder type. 00394 bool hasPlaceholderType() const { 00395 return getType()->isPlaceholderType(); 00396 } 00397 00398 /// \brief Returns whether this expression has a specific placeholder type. 00399 bool hasPlaceholderType(BuiltinType::Kind K) const { 00400 assert(BuiltinType::isPlaceholderTypeKind(K)); 00401 if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType())) 00402 return BT->getKind() == K; 00403 return false; 00404 } 00405 00406 /// isKnownToHaveBooleanValue - Return true if this is an integer expression 00407 /// that is known to return 0 or 1. This happens for _Bool/bool expressions 00408 /// but also int expressions which are produced by things like comparisons in 00409 /// C. 00410 bool isKnownToHaveBooleanValue() const; 00411 00412 /// isIntegerConstantExpr - Return true if this expression is a valid integer 00413 /// constant expression, and, if so, return its value in Result. If not a 00414 /// valid i-c-e, return false and fill in Loc (if specified) with the location 00415 /// of the invalid expression. 00416 /// 00417 /// Note: This does not perform the implicit conversions required by C++11 00418 /// [expr.const]p5. 00419 bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 00420 SourceLocation *Loc = 0, 00421 bool isEvaluated = true) const; 00422 bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const; 00423 00424 /// isCXX98IntegralConstantExpr - Return true if this expression is an 00425 /// integral constant expression in C++98. Can only be used in C++. 00426 bool isCXX98IntegralConstantExpr(ASTContext &Ctx) const; 00427 00428 /// isCXX11ConstantExpr - Return true if this expression is a constant 00429 /// expression in C++11. Can only be used in C++. 00430 /// 00431 /// Note: This does not perform the implicit conversions required by C++11 00432 /// [expr.const]p5. 00433 bool isCXX11ConstantExpr(ASTContext &Ctx, APValue *Result = 0, 00434 SourceLocation *Loc = 0) const; 00435 00436 /// isPotentialConstantExpr - Return true if this function's definition 00437 /// might be usable in a constant expression in C++11, if it were marked 00438 /// constexpr. Return false if the function can never produce a constant 00439 /// expression, along with diagnostics describing why not. 00440 static bool isPotentialConstantExpr(const FunctionDecl *FD, 00441 llvm::SmallVectorImpl< 00442 PartialDiagnosticAt> &Diags); 00443 00444 /// isConstantInitializer - Returns true if this expression can be emitted to 00445 /// IR as a constant, and thus can be used as a constant initializer in C. 00446 bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 00447 00448 /// EvalStatus is a struct with detailed info about an evaluation in progress. 00449 struct EvalStatus { 00450 /// HasSideEffects - Whether the evaluated expression has side effects. 00451 /// For example, (f() && 0) can be folded, but it still has side effects. 00452 bool HasSideEffects; 00453 00454 /// Diag - If this is non-null, it will be filled in with a stack of notes 00455 /// indicating why evaluation failed (or why it failed to produce a constant 00456 /// expression). 00457 /// If the expression is unfoldable, the notes will indicate why it's not 00458 /// foldable. If the expression is foldable, but not a constant expression, 00459 /// the notes will describes why it isn't a constant expression. If the 00460 /// expression *is* a constant expression, no notes will be produced. 00461 llvm::SmallVectorImpl<PartialDiagnosticAt> *Diag; 00462 00463 EvalStatus() : HasSideEffects(false), Diag(0) {} 00464 00465 // hasSideEffects - Return true if the evaluated expression has 00466 // side effects. 00467 bool hasSideEffects() const { 00468 return HasSideEffects; 00469 } 00470 }; 00471 00472 /// EvalResult is a struct with detailed info about an evaluated expression. 00473 struct EvalResult : EvalStatus { 00474 /// Val - This is the value the expression can be folded to. 00475 APValue Val; 00476 00477 // isGlobalLValue - Return true if the evaluated lvalue expression 00478 // is global. 00479 bool isGlobalLValue() const; 00480 }; 00481 00482 /// EvaluateAsRValue - Return true if this is a constant which we can fold to 00483 /// an rvalue using any crazy technique (that has nothing to do with language 00484 /// standards) that we want to, even if the expression has side-effects. If 00485 /// this function returns true, it returns the folded constant in Result. If 00486 /// the expression is a glvalue, an lvalue-to-rvalue conversion will be 00487 /// applied. 00488 bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const; 00489 00490 /// EvaluateAsBooleanCondition - Return true if this is a constant 00491 /// which we we can fold and convert to a boolean condition using 00492 /// any crazy technique that we want to, even if the expression has 00493 /// side-effects. 00494 bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 00495 00496 enum SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects }; 00497 00498 /// EvaluateAsInt - Return true if this is a constant which we can fold and 00499 /// convert to an integer, using any crazy technique that we want to. 00500 bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, 00501 SideEffectsKind AllowSideEffects = SE_NoSideEffects) const; 00502 00503 /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be 00504 /// constant folded without side-effects, but discard the result. 00505 bool isEvaluatable(const ASTContext &Ctx) const; 00506 00507 /// HasSideEffects - This routine returns true for all those expressions 00508 /// which must be evaluated each time and must not be optimized away 00509 /// or evaluated at compile time. Example is a function call, volatile 00510 /// variable read. 00511 bool HasSideEffects(const ASTContext &Ctx) const; 00512 00513 /// \brief Determine whether this expression involves a call to any function 00514 /// that is not trivial. 00515 bool hasNonTrivialCall(ASTContext &Ctx); 00516 00517 /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded 00518 /// integer. This must be called on an expression that constant folds to an 00519 /// integer. 00520 llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const; 00521 00522 /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an 00523 /// lvalue with link time known address, with no side-effects. 00524 bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 00525 00526 /// EvaluateAsInitializer - Evaluate an expression as if it were the 00527 /// initializer of the given declaration. Returns true if the initializer 00528 /// can be folded to a constant, and produces any relevant notes. In C++11, 00529 /// notes will be produced if the expression is not a constant expression. 00530 bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx, 00531 const VarDecl *VD, 00532 llvm::SmallVectorImpl<PartialDiagnosticAt> &Notes) const; 00533 00534 /// \brief Enumeration used to describe the kind of Null pointer constant 00535 /// returned from \c isNullPointerConstant(). 00536 enum NullPointerConstantKind { 00537 /// \brief Expression is not a Null pointer constant. 00538 NPCK_NotNull = 0, 00539 00540 /// \brief Expression is a Null pointer constant built from a zero integer. 00541 NPCK_ZeroInteger, 00542 00543 /// \brief Expression is a C++0X nullptr. 00544 NPCK_CXX0X_nullptr, 00545 00546 /// \brief Expression is a GNU-style __null constant. 00547 NPCK_GNUNull 00548 }; 00549 00550 /// \brief Enumeration used to describe how \c isNullPointerConstant() 00551 /// should cope with value-dependent expressions. 00552 enum NullPointerConstantValueDependence { 00553 /// \brief Specifies that the expression should never be value-dependent. 00554 NPC_NeverValueDependent = 0, 00555 00556 /// \brief Specifies that a value-dependent expression of integral or 00557 /// dependent type should be considered a null pointer constant. 00558 NPC_ValueDependentIsNull, 00559 00560 /// \brief Specifies that a value-dependent expression should be considered 00561 /// to never be a null pointer constant. 00562 NPC_ValueDependentIsNotNull 00563 }; 00564 00565 /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 00566 /// a Null pointer constant. The return value can further distinguish the 00567 /// kind of NULL pointer constant that was detected. 00568 NullPointerConstantKind isNullPointerConstant( 00569 ASTContext &Ctx, 00570 NullPointerConstantValueDependence NPC) const; 00571 00572 /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 00573 /// write barrier. 00574 bool isOBJCGCCandidate(ASTContext &Ctx) const; 00575 00576 /// \brief Returns true if this expression is a bound member function. 00577 bool isBoundMemberFunction(ASTContext &Ctx) const; 00578 00579 /// \brief Given an expression of bound-member type, find the type 00580 /// of the member. Returns null if this is an *overloaded* bound 00581 /// member expression. 00582 static QualType findBoundMemberType(const Expr *expr); 00583 00584 /// IgnoreImpCasts - Skip past any implicit casts which might 00585 /// surround this expression. Only skips ImplicitCastExprs. 00586 Expr *IgnoreImpCasts() LLVM_READONLY; 00587 00588 /// IgnoreImplicit - Skip past any implicit AST nodes which might 00589 /// surround this expression. 00590 Expr *IgnoreImplicit() LLVM_READONLY { 00591 return cast<Expr>(Stmt::IgnoreImplicit()); 00592 } 00593 00594 /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 00595 /// its subexpression. If that subexpression is also a ParenExpr, 00596 /// then this method recursively returns its subexpression, and so forth. 00597 /// Otherwise, the method returns the current Expr. 00598 Expr *IgnoreParens() LLVM_READONLY; 00599 00600 /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 00601 /// or CastExprs, returning their operand. 00602 Expr *IgnoreParenCasts() LLVM_READONLY; 00603 00604 /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off 00605 /// any ParenExpr or ImplicitCastExprs, returning their operand. 00606 Expr *IgnoreParenImpCasts() LLVM_READONLY; 00607 00608 /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a 00609 /// call to a conversion operator, return the argument. 00610 Expr *IgnoreConversionOperator() LLVM_READONLY; 00611 00612 const Expr *IgnoreConversionOperator() const LLVM_READONLY { 00613 return const_cast<Expr*>(this)->IgnoreConversionOperator(); 00614 } 00615 00616 const Expr *IgnoreParenImpCasts() const LLVM_READONLY { 00617 return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 00618 } 00619 00620 /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 00621 /// CastExprs that represent lvalue casts, returning their operand. 00622 Expr *IgnoreParenLValueCasts() LLVM_READONLY; 00623 00624 const Expr *IgnoreParenLValueCasts() const LLVM_READONLY { 00625 return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 00626 } 00627 00628 /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 00629 /// value (including ptr->int casts of the same size). Strip off any 00630 /// ParenExpr or CastExprs, returning their operand. 00631 Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY; 00632 00633 /// \brief Determine whether this expression is a default function argument. 00634 /// 00635 /// Default arguments are implicitly generated in the abstract syntax tree 00636 /// by semantic analysis for function calls, object constructions, etc. in 00637 /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 00638 /// this routine also looks through any implicit casts to determine whether 00639 /// the expression is a default argument. 00640 bool isDefaultArgument() const; 00641 00642 /// \brief Determine whether the result of this expression is a 00643 /// temporary object of the given class type. 00644 bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 00645 00646 /// \brief Whether this expression is an implicit reference to 'this' in C++. 00647 bool isImplicitCXXThis() const; 00648 00649 const Expr *IgnoreImpCasts() const LLVM_READONLY { 00650 return const_cast<Expr*>(this)->IgnoreImpCasts(); 00651 } 00652 const Expr *IgnoreParens() const LLVM_READONLY { 00653 return const_cast<Expr*>(this)->IgnoreParens(); 00654 } 00655 const Expr *IgnoreParenCasts() const LLVM_READONLY { 00656 return const_cast<Expr*>(this)->IgnoreParenCasts(); 00657 } 00658 const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY { 00659 return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 00660 } 00661 00662 static bool hasAnyTypeDependentArguments(llvm::ArrayRef<Expr *> Exprs); 00663 00664 static bool classof(const Stmt *T) { 00665 return T->getStmtClass() >= firstExprConstant && 00666 T->getStmtClass() <= lastExprConstant; 00667 } 00668 static bool classof(const Expr *) { return true; } 00669 }; 00670 00671 00672 //===----------------------------------------------------------------------===// 00673 // Primary Expressions. 00674 //===----------------------------------------------------------------------===// 00675 00676 /// OpaqueValueExpr - An expression referring to an opaque object of a 00677 /// fixed type and value class. These don't correspond to concrete 00678 /// syntax; instead they're used to express operations (usually copy 00679 /// operations) on values whose source is generally obvious from 00680 /// context. 00681 class OpaqueValueExpr : public Expr { 00682 friend class ASTStmtReader; 00683 Expr *SourceExpr; 00684 SourceLocation Loc; 00685 00686 public: 00687 OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 00688 ExprObjectKind OK = OK_Ordinary, 00689 Expr *SourceExpr = 0) 00690 : Expr(OpaqueValueExprClass, T, VK, OK, 00691 T->isDependentType(), 00692 T->isDependentType() || 00693 (SourceExpr && SourceExpr->isValueDependent()), 00694 T->isInstantiationDependentType(), 00695 false), 00696 SourceExpr(SourceExpr), Loc(Loc) { 00697 } 00698 00699 /// Given an expression which invokes a copy constructor --- i.e. a 00700 /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 00701 /// find the OpaqueValueExpr that's the source of the construction. 00702 static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 00703 00704 explicit OpaqueValueExpr(EmptyShell Empty) 00705 : Expr(OpaqueValueExprClass, Empty) { } 00706 00707 /// \brief Retrieve the location of this expression. 00708 SourceLocation getLocation() const { return Loc; } 00709 00710 SourceRange getSourceRange() const LLVM_READONLY { 00711 if (SourceExpr) return SourceExpr->getSourceRange(); 00712 return Loc; 00713 } 00714 SourceLocation getExprLoc() const LLVM_READONLY { 00715 if (SourceExpr) return SourceExpr->getExprLoc(); 00716 return Loc; 00717 } 00718 00719 child_range children() { return child_range(); } 00720 00721 /// The source expression of an opaque value expression is the 00722 /// expression which originally generated the value. This is 00723 /// provided as a convenience for analyses that don't wish to 00724 /// precisely model the execution behavior of the program. 00725 /// 00726 /// The source expression is typically set when building the 00727 /// expression which binds the opaque value expression in the first 00728 /// place. 00729 Expr *getSourceExpr() const { return SourceExpr; } 00730 00731 static bool classof(const Stmt *T) { 00732 return T->getStmtClass() == OpaqueValueExprClass; 00733 } 00734 static bool classof(const OpaqueValueExpr *) { return true; } 00735 }; 00736 00737 /// \brief A reference to a declared variable, function, enum, etc. 00738 /// [C99 6.5.1p2] 00739 /// 00740 /// This encodes all the information about how a declaration is referenced 00741 /// within an expression. 00742 /// 00743 /// There are several optional constructs attached to DeclRefExprs only when 00744 /// they apply in order to conserve memory. These are laid out past the end of 00745 /// the object, and flags in the DeclRefExprBitfield track whether they exist: 00746 /// 00747 /// DeclRefExprBits.HasQualifier: 00748 /// Specifies when this declaration reference expression has a C++ 00749 /// nested-name-specifier. 00750 /// DeclRefExprBits.HasFoundDecl: 00751 /// Specifies when this declaration reference expression has a record of 00752 /// a NamedDecl (different from the referenced ValueDecl) which was found 00753 /// during name lookup and/or overload resolution. 00754 /// DeclRefExprBits.HasTemplateKWAndArgsInfo: 00755 /// Specifies when this declaration reference expression has an explicit 00756 /// C++ template keyword and/or template argument list. 00757 /// DeclRefExprBits.RefersToEnclosingLocal 00758 /// Specifies when this declaration reference expression (validly) 00759 /// refers to a local variable from a different function. 00760 class DeclRefExpr : public Expr { 00761 /// \brief The declaration that we are referencing. 00762 ValueDecl *D; 00763 00764 /// \brief The location of the declaration name itself. 00765 SourceLocation Loc; 00766 00767 /// \brief Provides source/type location info for the declaration name 00768 /// embedded in D. 00769 DeclarationNameLoc DNLoc; 00770 00771 /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 00772 NestedNameSpecifierLoc &getInternalQualifierLoc() { 00773 assert(hasQualifier()); 00774 return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1); 00775 } 00776 00777 /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 00778 const NestedNameSpecifierLoc &getInternalQualifierLoc() const { 00779 return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc(); 00780 } 00781 00782 /// \brief Test whether there is a distinct FoundDecl attached to the end of 00783 /// this DRE. 00784 bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } 00785 00786 /// \brief Helper to retrieve the optional NamedDecl through which this 00787 /// reference occured. 00788 NamedDecl *&getInternalFoundDecl() { 00789 assert(hasFoundDecl()); 00790 if (hasQualifier()) 00791 return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1); 00792 return *reinterpret_cast<NamedDecl **>(this + 1); 00793 } 00794 00795 /// \brief Helper to retrieve the optional NamedDecl through which this 00796 /// reference occured. 00797 NamedDecl *getInternalFoundDecl() const { 00798 return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl(); 00799 } 00800 00801 DeclRefExpr(ASTContext &Ctx, 00802 NestedNameSpecifierLoc QualifierLoc, 00803 SourceLocation TemplateKWLoc, 00804 ValueDecl *D, bool refersToEnclosingLocal, 00805 const DeclarationNameInfo &NameInfo, 00806 NamedDecl *FoundD, 00807 const TemplateArgumentListInfo *TemplateArgs, 00808 QualType T, ExprValueKind VK); 00809 00810 /// \brief Construct an empty declaration reference expression. 00811 explicit DeclRefExpr(EmptyShell Empty) 00812 : Expr(DeclRefExprClass, Empty) { } 00813 00814 /// \brief Computes the type- and value-dependence flags for this 00815 /// declaration reference expression. 00816 void computeDependence(ASTContext &C); 00817 00818 public: 00819 DeclRefExpr(ValueDecl *D, bool refersToEnclosingLocal, QualType T, 00820 ExprValueKind VK, SourceLocation L, 00821 const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) 00822 : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 00823 D(D), Loc(L), DNLoc(LocInfo) { 00824 DeclRefExprBits.HasQualifier = 0; 00825 DeclRefExprBits.HasTemplateKWAndArgsInfo = 0; 00826 DeclRefExprBits.HasFoundDecl = 0; 00827 DeclRefExprBits.HadMultipleCandidates = 0; 00828 DeclRefExprBits.RefersToEnclosingLocal = refersToEnclosingLocal; 00829 computeDependence(D->getASTContext()); 00830 } 00831 00832 static DeclRefExpr *Create(ASTContext &Context, 00833 NestedNameSpecifierLoc QualifierLoc, 00834 SourceLocation TemplateKWLoc, 00835 ValueDecl *D, 00836 bool isEnclosingLocal, 00837 SourceLocation NameLoc, 00838 QualType T, ExprValueKind VK, 00839 NamedDecl *FoundD = 0, 00840 const TemplateArgumentListInfo *TemplateArgs = 0); 00841 00842 static DeclRefExpr *Create(ASTContext &Context, 00843 NestedNameSpecifierLoc QualifierLoc, 00844 SourceLocation TemplateKWLoc, 00845 ValueDecl *D, 00846 bool isEnclosingLocal, 00847 const DeclarationNameInfo &NameInfo, 00848 QualType T, ExprValueKind VK, 00849 NamedDecl *FoundD = 0, 00850 const TemplateArgumentListInfo *TemplateArgs = 0); 00851 00852 /// \brief Construct an empty declaration reference expression. 00853 static DeclRefExpr *CreateEmpty(ASTContext &Context, 00854 bool HasQualifier, 00855 bool HasFoundDecl, 00856 bool HasTemplateKWAndArgsInfo, 00857 unsigned NumTemplateArgs); 00858 00859 ValueDecl *getDecl() { return D; } 00860 const ValueDecl *getDecl() const { return D; } 00861 void setDecl(ValueDecl *NewD) { D = NewD; } 00862 00863 DeclarationNameInfo getNameInfo() const { 00864 return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 00865 } 00866 00867 SourceLocation getLocation() const { return Loc; } 00868 void setLocation(SourceLocation L) { Loc = L; } 00869 SourceRange getSourceRange() const LLVM_READONLY; 00870 SourceLocation getLocStart() const LLVM_READONLY; 00871 SourceLocation getLocEnd() const LLVM_READONLY; 00872 00873 /// \brief Determine whether this declaration reference was preceded by a 00874 /// C++ nested-name-specifier, e.g., \c N::foo. 00875 bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } 00876 00877 /// \brief If the name was qualified, retrieves the nested-name-specifier 00878 /// that precedes the name. Otherwise, returns NULL. 00879 NestedNameSpecifier *getQualifier() const { 00880 if (!hasQualifier()) 00881 return 0; 00882 00883 return getInternalQualifierLoc().getNestedNameSpecifier(); 00884 } 00885 00886 /// \brief If the name was qualified, retrieves the nested-name-specifier 00887 /// that precedes the name, with source-location information. 00888 NestedNameSpecifierLoc getQualifierLoc() const { 00889 if (!hasQualifier()) 00890 return NestedNameSpecifierLoc(); 00891 00892 return getInternalQualifierLoc(); 00893 } 00894 00895 /// \brief Get the NamedDecl through which this reference occured. 00896 /// 00897 /// This Decl may be different from the ValueDecl actually referred to in the 00898 /// presence of using declarations, etc. It always returns non-NULL, and may 00899 /// simple return the ValueDecl when appropriate. 00900 NamedDecl *getFoundDecl() { 00901 return hasFoundDecl() ? getInternalFoundDecl() : D; 00902 } 00903 00904 /// \brief Get the NamedDecl through which this reference occurred. 00905 /// See non-const variant. 00906 const NamedDecl *getFoundDecl() const { 00907 return hasFoundDecl() ? getInternalFoundDecl() : D; 00908 } 00909 00910 bool hasTemplateKWAndArgsInfo() const { 00911 return DeclRefExprBits.HasTemplateKWAndArgsInfo; 00912 } 00913 00914 /// \brief Return the optional template keyword and arguments info. 00915 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 00916 if (!hasTemplateKWAndArgsInfo()) 00917 return 0; 00918 00919 if (hasFoundDecl()) 00920 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 00921 &getInternalFoundDecl() + 1); 00922 00923 if (hasQualifier()) 00924 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 00925 &getInternalQualifierLoc() + 1); 00926 00927 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1); 00928 } 00929 00930 /// \brief Return the optional template keyword and arguments info. 00931 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 00932 return const_cast<DeclRefExpr*>(this)->getTemplateKWAndArgsInfo(); 00933 } 00934 00935 /// \brief Retrieve the location of the template keyword preceding 00936 /// this name, if any. 00937 SourceLocation getTemplateKeywordLoc() const { 00938 if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 00939 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 00940 } 00941 00942 /// \brief Retrieve the location of the left angle bracket starting the 00943 /// explicit template argument list following the name, if any. 00944 SourceLocation getLAngleLoc() const { 00945 if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 00946 return getTemplateKWAndArgsInfo()->LAngleLoc; 00947 } 00948 00949 /// \brief Retrieve the location of the right angle bracket ending the 00950 /// explicit template argument list following the name, if any. 00951 SourceLocation getRAngleLoc() const { 00952 if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 00953 return getTemplateKWAndArgsInfo()->RAngleLoc; 00954 } 00955 00956 /// \brief Determines whether the name in this declaration reference 00957 /// was preceded by the template keyword. 00958 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 00959 00960 /// \brief Determines whether this declaration reference was followed by an 00961 /// explicit template argument list. 00962 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 00963 00964 /// \brief Retrieve the explicit template argument list that followed the 00965 /// member template name. 00966 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 00967 assert(hasExplicitTemplateArgs()); 00968 return *getTemplateKWAndArgsInfo(); 00969 } 00970 00971 /// \brief Retrieve the explicit template argument list that followed the 00972 /// member template name. 00973 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 00974 return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 00975 } 00976 00977 /// \brief Retrieves the optional explicit template arguments. 00978 /// This points to the same data as getExplicitTemplateArgs(), but 00979 /// returns null if there are no explicit template arguments. 00980 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 00981 if (!hasExplicitTemplateArgs()) return 0; 00982 return &getExplicitTemplateArgs(); 00983 } 00984 00985 /// \brief Copies the template arguments (if present) into the given 00986 /// structure. 00987 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 00988 if (hasExplicitTemplateArgs()) 00989 getExplicitTemplateArgs().copyInto(List); 00990 } 00991 00992 /// \brief Retrieve the template arguments provided as part of this 00993 /// template-id. 00994 const TemplateArgumentLoc *getTemplateArgs() const { 00995 if (!hasExplicitTemplateArgs()) 00996 return 0; 00997 00998 return getExplicitTemplateArgs().getTemplateArgs(); 00999 } 01000 01001 /// \brief Retrieve the number of template arguments provided as part of this 01002 /// template-id. 01003 unsigned getNumTemplateArgs() const { 01004 if (!hasExplicitTemplateArgs()) 01005 return 0; 01006 01007 return getExplicitTemplateArgs().NumTemplateArgs; 01008 } 01009 01010 /// \brief Returns true if this expression refers to a function that 01011 /// was resolved from an overloaded set having size greater than 1. 01012 bool hadMultipleCandidates() const { 01013 return DeclRefExprBits.HadMultipleCandidates; 01014 } 01015 /// \brief Sets the flag telling whether this expression refers to 01016 /// a function that was resolved from an overloaded set having size 01017 /// greater than 1. 01018 void setHadMultipleCandidates(bool V = true) { 01019 DeclRefExprBits.HadMultipleCandidates = V; 01020 } 01021 01022 /// Does this DeclRefExpr refer to a local declaration from an 01023 /// enclosing function scope? 01024 bool refersToEnclosingLocal() const { 01025 return DeclRefExprBits.RefersToEnclosingLocal; 01026 } 01027 01028 static bool classof(const Stmt *T) { 01029 return T->getStmtClass() == DeclRefExprClass; 01030 } 01031 static bool classof(const DeclRefExpr *) { return true; } 01032 01033 // Iterators 01034 child_range children() { return child_range(); } 01035 01036 friend class ASTStmtReader; 01037 friend class ASTStmtWriter; 01038 }; 01039 01040 /// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 01041 class PredefinedExpr : public Expr { 01042 public: 01043 enum IdentType { 01044 Func, 01045 Function, 01046 PrettyFunction, 01047 /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 01048 /// 'virtual' keyword is omitted for virtual member functions. 01049 PrettyFunctionNoVirtual 01050 }; 01051 01052 private: 01053 SourceLocation Loc; 01054 IdentType Type; 01055 public: 01056 PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 01057 : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 01058 type->isDependentType(), type->isDependentType(), 01059 type->isInstantiationDependentType(), 01060 /*ContainsUnexpandedParameterPack=*/false), 01061 Loc(l), Type(IT) {} 01062 01063 /// \brief Construct an empty predefined expression. 01064 explicit PredefinedExpr(EmptyShell Empty) 01065 : Expr(PredefinedExprClass, Empty) { } 01066 01067 IdentType getIdentType() const { return Type; } 01068 void setIdentType(IdentType IT) { Type = IT; } 01069 01070 SourceLocation getLocation() const { return Loc; } 01071 void setLocation(SourceLocation L) { Loc = L; } 01072 01073 static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 01074 01075 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 01076 01077 static bool classof(const Stmt *T) { 01078 return T->getStmtClass() == PredefinedExprClass; 01079 } 01080 static bool classof(const PredefinedExpr *) { return true; } 01081 01082 // Iterators 01083 child_range children() { return child_range(); } 01084 }; 01085 01086 /// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 01087 /// leaking memory. 01088 /// 01089 /// For large floats/integers, APFloat/APInt will allocate memory from the heap 01090 /// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 01091 /// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 01092 /// the APFloat/APInt values will never get freed. APNumericStorage uses 01093 /// ASTContext's allocator for memory allocation. 01094 class APNumericStorage { 01095 union { 01096 uint64_t VAL; ///< Used to store the <= 64 bits integer value. 01097 uint64_t *pVal; ///< Used to store the >64 bits integer value. 01098 }; 01099 unsigned BitWidth; 01100 01101 bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 01102 01103 APNumericStorage(const APNumericStorage&); // do not implement 01104 APNumericStorage& operator=(const APNumericStorage&); // do not implement 01105 01106 protected: 01107 APNumericStorage() : VAL(0), BitWidth(0) { } 01108 01109 llvm::APInt getIntValue() const { 01110 unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 01111 if (NumWords > 1) 01112 return llvm::APInt(BitWidth, NumWords, pVal); 01113 else 01114 return llvm::APInt(BitWidth, VAL); 01115 } 01116 void setIntValue(ASTContext &C, const llvm::APInt &Val); 01117 }; 01118 01119 class APIntStorage : private APNumericStorage { 01120 public: 01121 llvm::APInt getValue() const { return getIntValue(); } 01122 void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 01123 }; 01124 01125 class APFloatStorage : private APNumericStorage { 01126 public: 01127 llvm::APFloat getValue(bool IsIEEE) const { 01128 return llvm::APFloat(getIntValue(), IsIEEE); 01129 } 01130 void setValue(ASTContext &C, const llvm::APFloat &Val) { 01131 setIntValue(C, Val.bitcastToAPInt()); 01132 } 01133 }; 01134 01135 class IntegerLiteral : public Expr, public APIntStorage { 01136 SourceLocation Loc; 01137 01138 /// \brief Construct an empty integer literal. 01139 explicit IntegerLiteral(EmptyShell Empty) 01140 : Expr(IntegerLiteralClass, Empty) { } 01141 01142 public: 01143 // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 01144 // or UnsignedLongLongTy 01145 IntegerLiteral(ASTContext &C, const llvm::APInt &V, 01146 QualType type, SourceLocation l) 01147 : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 01148 false, false), 01149 Loc(l) { 01150 assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 01151 assert(V.getBitWidth() == C.getIntWidth(type) && 01152 "Integer type is not the correct size for constant."); 01153 setValue(C, V); 01154 } 01155 01156 /// \brief Returns a new integer literal with value 'V' and type 'type'. 01157 /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, 01158 /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V 01159 /// \param V - the value that the returned integer literal contains. 01160 static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 01161 QualType type, SourceLocation l); 01162 /// \brief Returns a new empty integer literal. 01163 static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 01164 01165 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 01166 01167 /// \brief Retrieve the location of the literal. 01168 SourceLocation getLocation() const { return Loc; } 01169 01170 void setLocation(SourceLocation Location) { Loc = Location; } 01171 01172 static bool classof(const Stmt *T) { 01173 return T->getStmtClass() == IntegerLiteralClass; 01174 } 01175 static bool classof(const IntegerLiteral *) { return true; } 01176 01177 // Iterators 01178 child_range children() { return child_range(); } 01179 }; 01180 01181 class CharacterLiteral : public Expr { 01182 public: 01183 enum CharacterKind { 01184 Ascii, 01185 Wide, 01186 UTF16, 01187 UTF32 01188 }; 01189 01190 private: 01191 unsigned Value; 01192 SourceLocation Loc; 01193 public: 01194 // type should be IntTy 01195 CharacterLiteral(unsigned value, CharacterKind kind, QualType type, 01196 SourceLocation l) 01197 : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 01198 false, false), 01199 Value(value), Loc(l) { 01200 CharacterLiteralBits.Kind = kind; 01201 } 01202 01203 /// \brief Construct an empty character literal. 01204 CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 01205 01206 SourceLocation getLocation() const { return Loc; } 01207 CharacterKind getKind() const { 01208 return static_cast<CharacterKind>(CharacterLiteralBits.Kind); 01209 } 01210 01211 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 01212 01213 unsigned getValue() const { return Value; } 01214 01215 void setLocation(SourceLocation Location) { Loc = Location; } 01216 void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; } 01217 void setValue(unsigned Val) { Value = Val; } 01218 01219 static bool classof(const Stmt *T) { 01220 return T->getStmtClass() == CharacterLiteralClass; 01221 } 01222 static bool classof(const CharacterLiteral *) { return true; } 01223 01224 // Iterators 01225 child_range children() { return child_range(); } 01226 }; 01227 01228 class FloatingLiteral : public Expr, private APFloatStorage { 01229 SourceLocation Loc; 01230 01231 FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 01232 QualType Type, SourceLocation L) 01233 : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 01234 false, false), Loc(L) { 01235 FloatingLiteralBits.IsIEEE = 01236 &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; 01237 FloatingLiteralBits.IsExact = isexact; 01238 setValue(C, V); 01239 } 01240 01241 /// \brief Construct an empty floating-point literal. 01242 explicit FloatingLiteral(ASTContext &C, EmptyShell Empty) 01243 : Expr(FloatingLiteralClass, Empty) { 01244 FloatingLiteralBits.IsIEEE = 01245 &C.getTargetInfo().getLongDoubleFormat() == &llvm::APFloat::IEEEquad; 01246 FloatingLiteralBits.IsExact = false; 01247 } 01248 01249 public: 01250 static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 01251 bool isexact, QualType Type, SourceLocation L); 01252 static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 01253 01254 llvm::APFloat getValue() const { 01255 return APFloatStorage::getValue(FloatingLiteralBits.IsIEEE); 01256 } 01257 void setValue(ASTContext &C, const llvm::APFloat &Val) { 01258 APFloatStorage::setValue(C, Val); 01259 } 01260 01261 bool isExact() const { return FloatingLiteralBits.IsExact; } 01262 void setExact(bool E) { FloatingLiteralBits.IsExact = E; } 01263 01264 /// getValueAsApproximateDouble - This returns the value as an inaccurate 01265 /// double. Note that this may cause loss of precision, but is useful for 01266 /// debugging dumps, etc. 01267 double getValueAsApproximateDouble() const; 01268 01269 SourceLocation getLocation() const { return Loc; } 01270 void setLocation(SourceLocation L) { Loc = L; } 01271 01272 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 01273 01274 static bool classof(const Stmt *T) { 01275 return T->getStmtClass() == FloatingLiteralClass; 01276 } 01277 static bool classof(const FloatingLiteral *) { return true; } 01278 01279 // Iterators 01280 child_range children() { return child_range(); } 01281 }; 01282 01283 /// ImaginaryLiteral - We support imaginary integer and floating point literals, 01284 /// like "1.0i". We represent these as a wrapper around FloatingLiteral and 01285 /// IntegerLiteral classes. Instances of this class always have a Complex type 01286 /// whose element type matches the subexpression. 01287 /// 01288 class ImaginaryLiteral : public Expr { 01289 Stmt *Val; 01290 public: 01291 ImaginaryLiteral(Expr *val, QualType Ty) 01292 : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 01293 false, false), 01294 Val(val) {} 01295 01296 /// \brief Build an empty imaginary literal. 01297 explicit ImaginaryLiteral(EmptyShell Empty) 01298 : Expr(ImaginaryLiteralClass, Empty) { } 01299 01300 const Expr *getSubExpr() const { return cast<Expr>(Val); } 01301 Expr *getSubExpr() { return cast<Expr>(Val); } 01302 void setSubExpr(Expr *E) { Val = E; } 01303 01304 SourceRange getSourceRange() const LLVM_READONLY { return Val->getSourceRange(); } 01305 static bool classof(const Stmt *T) { 01306 return T->getStmtClass() == ImaginaryLiteralClass; 01307 } 01308 static bool classof(const ImaginaryLiteral *) { return true; } 01309 01310 // Iterators 01311 child_range children() { return child_range(&Val, &Val+1); } 01312 }; 01313 01314 /// StringLiteral - This represents a string literal expression, e.g. "foo" 01315 /// or L"bar" (wide strings). The actual string is returned by getStrData() 01316 /// is NOT null-terminated, and the length of the string is determined by 01317 /// calling getByteLength(). The C type for a string is always a 01318 /// ConstantArrayType. In C++, the char type is const qualified, in C it is 01319 /// not. 01320 /// 01321 /// Note that strings in C can be formed by concatenation of multiple string 01322 /// literal pptokens in translation phase #6. This keeps track of the locations 01323 /// of each of these pieces. 01324 /// 01325 /// Strings in C can also be truncated and extended by assigning into arrays, 01326 /// e.g. with constructs like: 01327 /// char X[2] = "foobar"; 01328 /// In this case, getByteLength() will return 6, but the string literal will 01329 /// have type "char[2]". 01330 class StringLiteral : public Expr { 01331 public: 01332 enum StringKind { 01333 Ascii, 01334 Wide, 01335 UTF8, 01336 UTF16, 01337 UTF32 01338 }; 01339 01340 private: 01341 friend class ASTStmtReader; 01342 01343 union { 01344 const char *asChar; 01345 const uint16_t *asUInt16; 01346 const uint32_t *asUInt32; 01347 } StrData; 01348 unsigned Length; 01349 unsigned CharByteWidth : 4; 01350 unsigned Kind : 3; 01351 unsigned IsPascal : 1; 01352 unsigned NumConcatenated; 01353 SourceLocation TokLocs[1]; 01354 01355 StringLiteral(QualType Ty) : 01356 Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, 01357 false) {} 01358 01359 static int mapCharByteWidth(TargetInfo const &target,StringKind k); 01360 01361 public: 01362 /// This is the "fully general" constructor that allows representation of 01363 /// strings formed from multiple concatenated tokens. 01364 static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 01365 bool Pascal, QualType Ty, 01366 const SourceLocation *Loc, unsigned NumStrs); 01367 01368 /// Simple constructor for string literals made from one token. 01369 static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 01370 bool Pascal, QualType Ty, 01371 SourceLocation Loc) { 01372 return Create(C, Str, Kind, Pascal, Ty, &Loc, 1); 01373 } 01374 01375 /// \brief Construct an empty string literal. 01376 static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 01377 01378 StringRef getString() const { 01379 assert(CharByteWidth==1 01380 && "This function is used in places that assume strings use char"); 01381 return StringRef(StrData.asChar, getByteLength()); 01382 } 01383 01384 /// Allow clients that need the byte representation, such as ASTWriterStmt 01385 /// ::VisitStringLiteral(), access. 01386 StringRef getBytes() const { 01387 // FIXME: StringRef may not be the right type to use as a result for this. 01388 if (CharByteWidth == 1) 01389 return StringRef(StrData.asChar, getByteLength()); 01390 if (CharByteWidth == 4) 01391 return StringRef(reinterpret_cast<const char*>(StrData.asUInt32), 01392 getByteLength()); 01393 assert(CharByteWidth == 2 && "unsupported CharByteWidth"); 01394 return StringRef(reinterpret_cast<const char*>(StrData.asUInt16), 01395 getByteLength()); 01396 } 01397 01398 uint32_t getCodeUnit(size_t i) const { 01399 assert(i < Length && "out of bounds access"); 01400 if (CharByteWidth == 1) 01401 return static_cast<unsigned char>(StrData.asChar[i]); 01402 if (CharByteWidth == 4) 01403 return StrData.asUInt32[i]; 01404 assert(CharByteWidth == 2 && "unsupported CharByteWidth"); 01405 return StrData.asUInt16[i]; 01406 } 01407 01408 unsigned getByteLength() const { return CharByteWidth*Length; } 01409 unsigned getLength() const { return Length; } 01410 unsigned getCharByteWidth() const { return CharByteWidth; } 01411 01412 /// \brief Sets the string data to the given string data. 01413 void setString(ASTContext &C, StringRef Str, 01414 StringKind Kind, bool IsPascal); 01415 01416 StringKind getKind() const { return static_cast<StringKind>(Kind); } 01417 01418 01419 bool isAscii() const { return Kind == Ascii; } 01420 bool isWide() const { return Kind == Wide; } 01421 bool isUTF8() const { return Kind == UTF8; } 01422 bool isUTF16() const { return Kind == UTF16; } 01423 bool isUTF32() const { return Kind == UTF32; } 01424 bool isPascal() const { return IsPascal; } 01425 01426 bool containsNonAsciiOrNull() const { 01427 StringRef Str = getString(); 01428 for (unsigned i = 0, e = Str.size(); i != e; ++i) 01429 if (!isascii(Str[i]) || !Str[i]) 01430 return true; 01431 return false; 01432 } 01433 01434 /// getNumConcatenated - Get the number of string literal tokens that were 01435 /// concatenated in translation phase #6 to form this string literal. 01436 unsigned getNumConcatenated() const { return NumConcatenated; } 01437 01438 SourceLocation getStrTokenLoc(unsigned TokNum) const { 01439 assert(TokNum < NumConcatenated && "Invalid tok number"); 01440 return TokLocs[TokNum]; 01441 } 01442 void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 01443 assert(TokNum < NumConcatenated && "Invalid tok number"); 01444 TokLocs[TokNum] = L; 01445 } 01446 01447 /// getLocationOfByte - Return a source location that points to the specified 01448 /// byte of this string literal. 01449 /// 01450 /// Strings are amazingly complex. They can be formed from multiple tokens 01451 /// and can have escape sequences in them in addition to the usual trigraph 01452 /// and escaped newline business. This routine handles this complexity. 01453 /// 01454 SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 01455 const LangOptions &Features, 01456 const TargetInfo &Target) const; 01457 01458 typedef const SourceLocation *tokloc_iterator; 01459 tokloc_iterator tokloc_begin() const { return TokLocs; } 01460 tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 01461 01462 SourceRange getSourceRange() const LLVM_READONLY { 01463 return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 01464 } 01465 static bool classof(const Stmt *T) { 01466 return T->getStmtClass() == StringLiteralClass; 01467 } 01468 static bool classof(const StringLiteral *) { return true; } 01469 01470 // Iterators 01471 child_range children() { return child_range(); } 01472 }; 01473 01474 /// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 01475 /// AST node is only formed if full location information is requested. 01476 class ParenExpr : public Expr { 01477 SourceLocation L, R; 01478 Stmt *Val; 01479 public: 01480 ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 01481 : Expr(ParenExprClass, val->getType(), 01482 val->getValueKind(), val->getObjectKind(), 01483 val->isTypeDependent(), val->isValueDependent(), 01484 val->isInstantiationDependent(), 01485 val->containsUnexpandedParameterPack()), 01486 L(l), R(r), Val(val) {} 01487 01488 /// \brief Construct an empty parenthesized expression. 01489 explicit ParenExpr(EmptyShell Empty) 01490 : Expr(ParenExprClass, Empty) { } 01491 01492 const Expr *getSubExpr() const { return cast<Expr>(Val); } 01493 Expr *getSubExpr() { return cast<Expr>(Val); } 01494 void setSubExpr(Expr *E) { Val = E; } 01495 01496 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(L, R); } 01497 01498 /// \brief Get the location of the left parentheses '('. 01499 SourceLocation getLParen() const { return L; } 01500 void setLParen(SourceLocation Loc) { L = Loc; } 01501 01502 /// \brief Get the location of the right parentheses ')'. 01503 SourceLocation getRParen() const { return R; } 01504 void setRParen(SourceLocation Loc) { R = Loc; } 01505 01506 static bool classof(const Stmt *T) { 01507 return T->getStmtClass() == ParenExprClass; 01508 } 01509 static bool classof(const ParenExpr *) { return true; } 01510 01511 // Iterators 01512 child_range children() { return child_range(&Val, &Val+1); } 01513 }; 01514 01515 01516 /// UnaryOperator - This represents the unary-expression's (except sizeof and 01517 /// alignof), the postinc/postdec operators from postfix-expression, and various 01518 /// extensions. 01519 /// 01520 /// Notes on various nodes: 01521 /// 01522 /// Real/Imag - These return the real/imag part of a complex operand. If 01523 /// applied to a non-complex value, the former returns its operand and the 01524 /// later returns zero in the type of the operand. 01525 /// 01526 class UnaryOperator : public Expr { 01527 public: 01528 typedef UnaryOperatorKind Opcode; 01529 01530 private: 01531 unsigned Opc : 5; 01532 SourceLocation Loc; 01533 Stmt *Val; 01534 public: 01535 01536 UnaryOperator(Expr *input, Opcode opc, QualType type, 01537 ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 01538 : Expr(UnaryOperatorClass, type, VK, OK, 01539 input->isTypeDependent() || type->isDependentType(), 01540 input->isValueDependent(), 01541 (input->isInstantiationDependent() || 01542 type->isInstantiationDependentType()), 01543 input->containsUnexpandedParameterPack()), 01544 Opc(opc), Loc(l), Val(input) {} 01545 01546 /// \brief Build an empty unary operator. 01547 explicit UnaryOperator(EmptyShell Empty) 01548 : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 01549 01550 Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 01551 void setOpcode(Opcode O) { Opc = O; } 01552 01553 Expr *getSubExpr() const { return cast<Expr>(Val); } 01554 void setSubExpr(Expr *E) { Val = E; } 01555 01556 /// getOperatorLoc - Return the location of the operator. 01557 SourceLocation getOperatorLoc() const { return Loc; } 01558 void setOperatorLoc(SourceLocation L) { Loc = L; } 01559 01560 /// isPostfix - Return true if this is a postfix operation, like x++. 01561 static bool isPostfix(Opcode Op) { 01562 return Op == UO_PostInc || Op == UO_PostDec; 01563 } 01564 01565 /// isPrefix - Return true if this is a prefix operation, like --x. 01566 static bool isPrefix(Opcode Op) { 01567 return Op == UO_PreInc || Op == UO_PreDec; 01568 } 01569 01570 bool isPrefix() const { return isPrefix(getOpcode()); } 01571 bool isPostfix() const { return isPostfix(getOpcode()); } 01572 01573 static bool isIncrementOp(Opcode Op) { 01574 return Op == UO_PreInc || Op == UO_PostInc; 01575 } 01576 bool isIncrementOp() const { 01577 return isIncrementOp(getOpcode()); 01578 } 01579 01580 static bool isDecrementOp(Opcode Op) { 01581 return Op == UO_PreDec || Op == UO_PostDec; 01582 } 01583 bool isDecrementOp() const { 01584 return isDecrementOp(getOpcode()); 01585 } 01586 01587 static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; } 01588 bool isIncrementDecrementOp() const { 01589 return isIncrementDecrementOp(getOpcode()); 01590 } 01591 01592 static bool isArithmeticOp(Opcode Op) { 01593 return Op >= UO_Plus && Op <= UO_LNot; 01594 } 01595 bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 01596 01597 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 01598 /// corresponds to, e.g. "sizeof" or "[pre]++" 01599 static const char *getOpcodeStr(Opcode Op); 01600 01601 /// \brief Retrieve the unary opcode that corresponds to the given 01602 /// overloaded operator. 01603 static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 01604 01605 /// \brief Retrieve the overloaded operator kind that corresponds to 01606 /// the given unary opcode. 01607 static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 01608 01609 SourceRange getSourceRange() const LLVM_READONLY { 01610 if (isPostfix()) 01611 return SourceRange(Val->getLocStart(), Loc); 01612 else 01613 return SourceRange(Loc, Val->getLocEnd()); 01614 } 01615 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } 01616 01617 static bool classof(const Stmt *T) { 01618 return T->getStmtClass() == UnaryOperatorClass; 01619 } 01620 static bool classof(const UnaryOperator *) { return true; } 01621 01622 // Iterators 01623 child_range children() { return child_range(&Val, &Val+1); } 01624 }; 01625 01626 /// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 01627 /// offsetof(record-type, member-designator). For example, given: 01628 /// @code 01629 /// struct S { 01630 /// float f; 01631 /// double d; 01632 /// }; 01633 /// struct T { 01634 /// int i; 01635 /// struct S s[10]; 01636 /// }; 01637 /// @endcode 01638 /// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 01639 01640 class OffsetOfExpr : public Expr { 01641 public: 01642 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 01643 class OffsetOfNode { 01644 public: 01645 /// \brief The kind of offsetof node we have. 01646 enum Kind { 01647 /// \brief An index into an array. 01648 Array = 0x00, 01649 /// \brief A field. 01650 Field = 0x01, 01651 /// \brief A field in a dependent type, known only by its name. 01652 Identifier = 0x02, 01653 /// \brief An implicit indirection through a C++ base class, when the 01654 /// field found is in a base class. 01655 Base = 0x03 01656 }; 01657 01658 private: 01659 enum { MaskBits = 2, Mask = 0x03 }; 01660 01661 /// \brief The source range that covers this part of the designator. 01662 SourceRange Range; 01663 01664 /// \brief The data describing the designator, which comes in three 01665 /// different forms, depending on the lower two bits. 01666 /// - An unsigned index into the array of Expr*'s stored after this node 01667 /// in memory, for [constant-expression] designators. 01668 /// - A FieldDecl*, for references to a known field. 01669 /// - An IdentifierInfo*, for references to a field with a given name 01670 /// when the class type is dependent. 01671 /// - A CXXBaseSpecifier*, for references that look at a field in a 01672 /// base class. 01673 uintptr_t Data; 01674 01675 public: 01676 /// \brief Create an offsetof node that refers to an array element. 01677 OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 01678 SourceLocation RBracketLoc) 01679 : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 01680 01681 /// \brief Create an offsetof node that refers to a field. 01682 OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 01683 SourceLocation NameLoc) 01684 : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 01685 Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 01686 01687 /// \brief Create an offsetof node that refers to an identifier. 01688 OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 01689 SourceLocation NameLoc) 01690 : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 01691 Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 01692 01693 /// \brief Create an offsetof node that refers into a C++ base class. 01694 explicit OffsetOfNode(const CXXBaseSpecifier *Base) 01695 : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 01696 01697 /// \brief Determine what kind of offsetof node this is. 01698 Kind getKind() const { 01699 return static_cast<Kind>(Data & Mask); 01700 } 01701 01702 /// \brief For an array element node, returns the index into the array 01703 /// of expressions. 01704 unsigned getArrayExprIndex() const { 01705 assert(getKind() == Array); 01706 return Data >> 2; 01707 } 01708 01709 /// \brief For a field offsetof node, returns the field. 01710 FieldDecl *getField() const { 01711 assert(getKind() == Field); 01712 return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 01713 } 01714 01715 /// \brief For a field or identifier offsetof node, returns the name of 01716 /// the field. 01717 IdentifierInfo *getFieldName() const; 01718 01719 /// \brief For a base class node, returns the base specifier. 01720 CXXBaseSpecifier *getBase() const { 01721 assert(getKind() == Base); 01722 return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 01723 } 01724 01725 /// \brief Retrieve the source range that covers this offsetof node. 01726 /// 01727 /// For an array element node, the source range contains the locations of 01728 /// the square brackets. For a field or identifier node, the source range 01729 /// contains the location of the period (if there is one) and the 01730 /// identifier. 01731 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 01732 }; 01733 01734 private: 01735 01736 SourceLocation OperatorLoc, RParenLoc; 01737 // Base type; 01738 TypeSourceInfo *TSInfo; 01739 // Number of sub-components (i.e. instances of OffsetOfNode). 01740 unsigned NumComps; 01741 // Number of sub-expressions (i.e. array subscript expressions). 01742 unsigned NumExprs; 01743 01744 OffsetOfExpr(ASTContext &C, QualType type, 01745 SourceLocation OperatorLoc, TypeSourceInfo *tsi, 01746 OffsetOfNode* compsPtr, unsigned numComps, 01747 Expr** exprsPtr, unsigned numExprs, 01748 SourceLocation RParenLoc); 01749 01750 explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 01751 : Expr(OffsetOfExprClass, EmptyShell()), 01752 TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 01753 01754 public: 01755 01756 static OffsetOfExpr *Create(ASTContext &C, QualType type, 01757 SourceLocation OperatorLoc, TypeSourceInfo *tsi, 01758 OffsetOfNode* compsPtr, unsigned numComps, 01759 Expr** exprsPtr, unsigned numExprs, 01760 SourceLocation RParenLoc); 01761 01762 static OffsetOfExpr *CreateEmpty(ASTContext &C, 01763 unsigned NumComps, unsigned NumExprs); 01764 01765 /// getOperatorLoc - Return the location of the operator. 01766 SourceLocation getOperatorLoc() const { return OperatorLoc; } 01767 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 01768 01769 /// \brief Return the location of the right parentheses. 01770 SourceLocation getRParenLoc() const { return RParenLoc; } 01771 void setRParenLoc(SourceLocation R) { RParenLoc = R; } 01772 01773 TypeSourceInfo *getTypeSourceInfo() const { 01774 return TSInfo; 01775 } 01776 void setTypeSourceInfo(TypeSourceInfo *tsi) { 01777 TSInfo = tsi; 01778 } 01779 01780 const OffsetOfNode &getComponent(unsigned Idx) const { 01781 assert(Idx < NumComps && "Subscript out of range"); 01782 return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx]; 01783 } 01784 01785 void setComponent(unsigned Idx, OffsetOfNode ON) { 01786 assert(Idx < NumComps && "Subscript out of range"); 01787 reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 01788 } 01789 01790 unsigned getNumComponents() const { 01791 return NumComps; 01792 } 01793 01794 Expr* getIndexExpr(unsigned Idx) { 01795 assert(Idx < NumExprs && "Subscript out of range"); 01796 return reinterpret_cast<Expr **>( 01797 reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 01798 } 01799 const Expr *getIndexExpr(unsigned Idx) const { 01800 return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx); 01801 } 01802 01803 void setIndexExpr(unsigned Idx, Expr* E) { 01804 assert(Idx < NumComps && "Subscript out of range"); 01805 reinterpret_cast<Expr **>( 01806 reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 01807 } 01808 01809 unsigned getNumExpressions() const { 01810 return NumExprs; 01811 } 01812 01813 SourceRange getSourceRange() const LLVM_READONLY { 01814 return SourceRange(OperatorLoc, RParenLoc); 01815 } 01816 01817 static bool classof(const Stmt *T) { 01818 return T->getStmtClass() == OffsetOfExprClass; 01819 } 01820 01821 static bool classof(const OffsetOfExpr *) { return true; } 01822 01823 // Iterators 01824 child_range children() { 01825 Stmt **begin = 01826 reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 01827 + NumComps); 01828 return child_range(begin, begin + NumExprs); 01829 } 01830 }; 01831 01832 /// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 01833 /// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 01834 /// vec_step (OpenCL 1.1 6.11.12). 01835 class UnaryExprOrTypeTraitExpr : public Expr { 01836 union { 01837 TypeSourceInfo *Ty; 01838 Stmt *Ex; 01839 } Argument; 01840 SourceLocation OpLoc, RParenLoc; 01841 01842 public: 01843 UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 01844 QualType resultType, SourceLocation op, 01845 SourceLocation rp) : 01846 Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 01847 false, // Never type-dependent (C++ [temp.dep.expr]p3). 01848 // Value-dependent if the argument is type-dependent. 01849 TInfo->getType()->isDependentType(), 01850 TInfo->getType()->isInstantiationDependentType(), 01851 TInfo->getType()->containsUnexpandedParameterPack()), 01852 OpLoc(op), RParenLoc(rp) { 01853 UnaryExprOrTypeTraitExprBits.Kind = ExprKind; 01854 UnaryExprOrTypeTraitExprBits.IsType = true; 01855 Argument.Ty = TInfo; 01856 } 01857 01858 UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 01859 QualType resultType, SourceLocation op, 01860 SourceLocation rp) : 01861 Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 01862 false, // Never type-dependent (C++ [temp.dep.expr]p3). 01863 // Value-dependent if the argument is type-dependent. 01864 E->isTypeDependent(), 01865 E->isInstantiationDependent(), 01866 E->containsUnexpandedParameterPack()), 01867 OpLoc(op), RParenLoc(rp) { 01868 UnaryExprOrTypeTraitExprBits.Kind = ExprKind; 01869 UnaryExprOrTypeTraitExprBits.IsType = false; 01870 Argument.Ex = E; 01871 } 01872 01873 /// \brief Construct an empty sizeof/alignof expression. 01874 explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 01875 : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 01876 01877 UnaryExprOrTypeTrait getKind() const { 01878 return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind); 01879 } 01880 void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;} 01881 01882 bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; } 01883 QualType getArgumentType() const { 01884 return getArgumentTypeInfo()->getType(); 01885 } 01886 TypeSourceInfo *getArgumentTypeInfo() const { 01887 assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 01888 return Argument.Ty; 01889 } 01890 Expr *getArgumentExpr() { 01891 assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 01892 return static_cast<Expr*>(Argument.Ex); 01893 } 01894 const Expr *getArgumentExpr() const { 01895 return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 01896 } 01897 01898 void setArgument(Expr *E) { 01899 Argument.Ex = E; 01900 UnaryExprOrTypeTraitExprBits.IsType = false; 01901 } 01902 void setArgument(TypeSourceInfo *TInfo) { 01903 Argument.Ty = TInfo; 01904 UnaryExprOrTypeTraitExprBits.IsType = true; 01905 } 01906 01907 /// Gets the argument type, or the type of the argument expression, whichever 01908 /// is appropriate. 01909 QualType getTypeOfArgument() const { 01910 return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 01911 } 01912 01913 SourceLocation getOperatorLoc() const { return OpLoc; } 01914 void setOperatorLoc(SourceLocation L) { OpLoc = L; } 01915 01916 SourceLocation getRParenLoc() const { return RParenLoc; } 01917 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 01918 01919 SourceRange getSourceRange() const LLVM_READONLY { 01920 return SourceRange(OpLoc, RParenLoc); 01921 } 01922 01923 static bool classof(const Stmt *T) { 01924 return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 01925 } 01926 static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; } 01927 01928 // Iterators 01929 child_range children(); 01930 }; 01931 01932 //===----------------------------------------------------------------------===// 01933 // Postfix Operators. 01934 //===----------------------------------------------------------------------===// 01935 01936 /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 01937 class ArraySubscriptExpr : public Expr { 01938 enum { LHS, RHS, END_EXPR=2 }; 01939 Stmt* SubExprs[END_EXPR]; 01940 SourceLocation RBracketLoc; 01941 public: 01942 ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 01943 ExprValueKind VK, ExprObjectKind OK, 01944 SourceLocation rbracketloc) 01945 : Expr(ArraySubscriptExprClass, t, VK, OK, 01946 lhs->isTypeDependent() || rhs->isTypeDependent(), 01947 lhs->isValueDependent() || rhs->isValueDependent(), 01948 (lhs->isInstantiationDependent() || 01949 rhs->isInstantiationDependent()), 01950 (lhs->containsUnexpandedParameterPack() || 01951 rhs->containsUnexpandedParameterPack())), 01952 RBracketLoc(rbracketloc) { 01953 SubExprs[LHS] = lhs; 01954 SubExprs[RHS] = rhs; 01955 } 01956 01957 /// \brief Create an empty array subscript expression. 01958 explicit ArraySubscriptExpr(EmptyShell Shell) 01959 : Expr(ArraySubscriptExprClass, Shell) { } 01960 01961 /// An array access can be written A[4] or 4[A] (both are equivalent). 01962 /// - getBase() and getIdx() always present the normalized view: A[4]. 01963 /// In this case getBase() returns "A" and getIdx() returns "4". 01964 /// - getLHS() and getRHS() present the syntactic view. e.g. for 01965 /// 4[A] getLHS() returns "4". 01966 /// Note: Because vector element access is also written A[4] we must 01967 /// predicate the format conversion in getBase and getIdx only on the 01968 /// the type of the RHS, as it is possible for the LHS to be a vector of 01969 /// integer type 01970 Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 01971 const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 01972 void setLHS(Expr *E) { SubExprs[LHS] = E; } 01973 01974 Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 01975 const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 01976 void setRHS(Expr *E) { SubExprs[RHS] = E; } 01977 01978 Expr *getBase() { 01979 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 01980 } 01981 01982 const Expr *getBase() const { 01983 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 01984 } 01985 01986 Expr *getIdx() { 01987 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 01988 } 01989 01990 const Expr *getIdx() const { 01991 return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 01992 } 01993 01994 SourceRange getSourceRange() const LLVM_READONLY { 01995 return SourceRange(getLHS()->getLocStart(), RBracketLoc); 01996 } 01997 01998 SourceLocation getRBracketLoc() const { return RBracketLoc; } 01999 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 02000 02001 SourceLocation getExprLoc() const LLVM_READONLY { return getBase()->getExprLoc(); } 02002 02003 static bool classof(const Stmt *T) { 02004 return T->getStmtClass() == ArraySubscriptExprClass; 02005 } 02006 static bool classof(const ArraySubscriptExpr *) { return true; } 02007 02008 // Iterators 02009 child_range children() { 02010 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 02011 } 02012 }; 02013 02014 02015 /// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 02016 /// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 02017 /// while its subclasses may represent alternative syntax that (semantically) 02018 /// results in a function call. For example, CXXOperatorCallExpr is 02019 /// a subclass for overloaded operator calls that use operator syntax, e.g., 02020 /// "str1 + str2" to resolve to a function call. 02021 class CallExpr : public Expr { 02022 enum { FN=0, PREARGS_START=1 }; 02023 Stmt **SubExprs; 02024 unsigned NumArgs; 02025 SourceLocation RParenLoc; 02026 02027 protected: 02028 // These versions of the constructor are for derived classes. 02029 CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 02030 Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 02031 SourceLocation rparenloc); 02032 CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 02033 02034 Stmt *getPreArg(unsigned i) { 02035 assert(i < getNumPreArgs() && "Prearg access out of range!"); 02036 return SubExprs[PREARGS_START+i]; 02037 } 02038 const Stmt *getPreArg(unsigned i) const { 02039 assert(i < getNumPreArgs() && "Prearg access out of range!"); 02040 return SubExprs[PREARGS_START+i]; 02041 } 02042 void setPreArg(unsigned i, Stmt *PreArg) { 02043 assert(i < getNumPreArgs() && "Prearg access out of range!"); 02044 SubExprs[PREARGS_START+i] = PreArg; 02045 } 02046 02047 unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 02048 02049 public: 02050 CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 02051 ExprValueKind VK, SourceLocation rparenloc); 02052 02053 /// \brief Build an empty call expression. 02054 CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 02055 02056 const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 02057 Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 02058 void setCallee(Expr *F) { SubExprs[FN] = F; } 02059 02060 Decl *getCalleeDecl(); 02061 const Decl *getCalleeDecl() const { 02062 return const_cast<CallExpr*>(this)->getCalleeDecl(); 02063 } 02064 02065 /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 02066 FunctionDecl *getDirectCallee(); 02067 const FunctionDecl *getDirectCallee() const { 02068 return const_cast<CallExpr*>(this)->getDirectCallee(); 02069 } 02070 02071 /// getNumArgs - Return the number of actual arguments to this call. 02072 /// 02073 unsigned getNumArgs() const { return NumArgs; } 02074 02075 /// \brief Retrieve the call arguments. 02076 Expr **getArgs() { 02077 return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 02078 } 02079 const Expr *const *getArgs() const { 02080 return const_cast<CallExpr*>(this)->getArgs(); 02081 } 02082 02083 /// getArg - Return the specified argument. 02084 Expr *getArg(unsigned Arg) { 02085 assert(Arg < NumArgs && "Arg access out of range!"); 02086 return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 02087 } 02088 const Expr *getArg(unsigned Arg) const { 02089 assert(Arg < NumArgs && "Arg access out of range!"); 02090 return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 02091 } 02092 02093 /// setArg - Set the specified argument. 02094 void setArg(unsigned Arg, Expr *ArgExpr) { 02095 assert(Arg < NumArgs && "Arg access out of range!"); 02096 SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 02097 } 02098 02099 /// setNumArgs - This changes the number of arguments present in this call. 02100 /// Any orphaned expressions are deleted by this, and any new operands are set 02101 /// to null. 02102 void setNumArgs(ASTContext& C, unsigned NumArgs); 02103 02104 typedef ExprIterator arg_iterator; 02105 typedef ConstExprIterator const_arg_iterator; 02106 02107 arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 02108 arg_iterator arg_end() { 02109 return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 02110 } 02111 const_arg_iterator arg_begin() const { 02112 return SubExprs+PREARGS_START+getNumPreArgs(); 02113 } 02114 const_arg_iterator arg_end() const { 02115 return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 02116 } 02117 02118 /// getNumCommas - Return the number of commas that must have been present in 02119 /// this function call. 02120 unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 02121 02122 /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 02123 /// not, return 0. 02124 unsigned isBuiltinCall() const; 02125 02126 /// getCallReturnType - Get the return type of the call expr. This is not 02127 /// always the type of the expr itself, if the return type is a reference 02128 /// type. 02129 QualType getCallReturnType() const; 02130 02131 SourceLocation getRParenLoc() const { return RParenLoc; } 02132 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 02133 02134 SourceRange getSourceRange() const LLVM_READONLY; 02135 SourceLocation getLocStart() const LLVM_READONLY; 02136 SourceLocation getLocEnd() const LLVM_READONLY; 02137 02138 static bool classof(const Stmt *T) { 02139 return T->getStmtClass() >= firstCallExprConstant && 02140 T->getStmtClass() <= lastCallExprConstant; 02141 } 02142 static bool classof(const CallExpr *) { return true; } 02143 02144 // Iterators 02145 child_range children() { 02146 return child_range(&SubExprs[0], 02147 &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 02148 } 02149 }; 02150 02151 /// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 02152 /// 02153 class MemberExpr : public Expr { 02154 /// Extra data stored in some member expressions. 02155 struct MemberNameQualifier { 02156 /// \brief The nested-name-specifier that qualifies the name, including 02157 /// source-location information. 02158 NestedNameSpecifierLoc QualifierLoc; 02159 02160 /// \brief The DeclAccessPair through which the MemberDecl was found due to 02161 /// name qualifiers. 02162 DeclAccessPair FoundDecl; 02163 }; 02164 02165 /// Base - the expression for the base pointer or structure references. In 02166 /// X.F, this is "X". 02167 Stmt *Base; 02168 02169 /// MemberDecl - This is the decl being referenced by the field/member name. 02170 /// In X.F, this is the decl referenced by F. 02171 ValueDecl *MemberDecl; 02172 02173 /// MemberDNLoc - Provides source/type location info for the 02174 /// declaration name embedded in MemberDecl. 02175 DeclarationNameLoc MemberDNLoc; 02176 02177 /// MemberLoc - This is the location of the member name. 02178 SourceLocation MemberLoc; 02179 02180 /// IsArrow - True if this is "X->F", false if this is "X.F". 02181 bool IsArrow : 1; 02182 02183 /// \brief True if this member expression used a nested-name-specifier to 02184 /// refer to the member, e.g., "x->Base::f", or found its member via a using 02185 /// declaration. When true, a MemberNameQualifier 02186 /// structure is allocated immediately after the MemberExpr. 02187 bool HasQualifierOrFoundDecl : 1; 02188 02189 /// \brief True if this member expression specified a template keyword 02190 /// and/or a template argument list explicitly, e.g., x->f<int>, 02191 /// x->template f, x->template f<int>. 02192 /// When true, an ASTTemplateKWAndArgsInfo structure and its 02193 /// TemplateArguments (if any) are allocated immediately after 02194 /// the MemberExpr or, if the member expression also has a qualifier, 02195 /// after the MemberNameQualifier structure. 02196 bool HasTemplateKWAndArgsInfo : 1; 02197 02198 /// \brief True if this member expression refers to a method that 02199 /// was resolved from an overloaded set having size greater than 1. 02200 bool HadMultipleCandidates : 1; 02201 02202 /// \brief Retrieve the qualifier that preceded the member name, if any. 02203 MemberNameQualifier *getMemberQualifier() { 02204 assert(HasQualifierOrFoundDecl); 02205 return reinterpret_cast<MemberNameQualifier *> (this + 1); 02206 } 02207 02208 /// \brief Retrieve the qualifier that preceded the member name, if any. 02209 const MemberNameQualifier *getMemberQualifier() const { 02210 return const_cast<MemberExpr *>(this)->getMemberQualifier(); 02211 } 02212 02213 public: 02214 MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 02215 const DeclarationNameInfo &NameInfo, QualType ty, 02216 ExprValueKind VK, ExprObjectKind OK) 02217 : Expr(MemberExprClass, ty, VK, OK, 02218 base->isTypeDependent(), 02219 base->isValueDependent(), 02220 base->isInstantiationDependent(), 02221 base->containsUnexpandedParameterPack()), 02222 Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()), 02223 MemberLoc(NameInfo.getLoc()), IsArrow(isarrow), 02224 HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), 02225 HadMultipleCandidates(false) { 02226 assert(memberdecl->getDeclName() == NameInfo.getName()); 02227 } 02228 02229 // NOTE: this constructor should be used only when it is known that 02230 // the member name can not provide additional syntactic info 02231 // (i.e., source locations for C++ operator names or type source info 02232 // for constructors, destructors and conversion operators). 02233 MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 02234 SourceLocation l, QualType ty, 02235 ExprValueKind VK, ExprObjectKind OK) 02236 : Expr(MemberExprClass, ty, VK, OK, 02237 base->isTypeDependent(), base->isValueDependent(), 02238 base->isInstantiationDependent(), 02239 base->containsUnexpandedParameterPack()), 02240 Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l), 02241 IsArrow(isarrow), 02242 HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), 02243 HadMultipleCandidates(false) {} 02244 02245 static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 02246 NestedNameSpecifierLoc QualifierLoc, 02247 SourceLocation TemplateKWLoc, 02248 ValueDecl *memberdecl, DeclAccessPair founddecl, 02249 DeclarationNameInfo MemberNameInfo, 02250 const TemplateArgumentListInfo *targs, 02251 QualType ty, ExprValueKind VK, ExprObjectKind OK); 02252 02253 void setBase(Expr *E) { Base = E; } 02254 Expr *getBase() const { return cast<Expr>(Base); } 02255 02256 /// \brief Retrieve the member declaration to which this expression refers. 02257 /// 02258 /// The returned declaration will either be a FieldDecl or (in C++) 02259 /// a CXXMethodDecl. 02260 ValueDecl *getMemberDecl() const { return MemberDecl; } 02261 void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 02262 02263 /// \brief Retrieves the declaration found by lookup. 02264 DeclAccessPair getFoundDecl() const { 02265 if (!HasQualifierOrFoundDecl) 02266 return DeclAccessPair::make(getMemberDecl(), 02267 getMemberDecl()->getAccess()); 02268 return getMemberQualifier()->FoundDecl; 02269 } 02270 02271 /// \brief Determines whether this member expression actually had 02272 /// a C++ nested-name-specifier prior to the name of the member, e.g., 02273 /// x->Base::foo. 02274 bool hasQualifier() const { return getQualifier() != 0; } 02275 02276 /// \brief If the member name was qualified, retrieves the 02277 /// nested-name-specifier that precedes the member name. Otherwise, returns 02278 /// NULL. 02279 NestedNameSpecifier *getQualifier() const { 02280 if (!HasQualifierOrFoundDecl) 02281 return 0; 02282 02283 return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 02284 } 02285 02286 /// \brief If the member name was qualified, retrieves the 02287 /// nested-name-specifier that precedes the member name, with source-location 02288 /// information. 02289 NestedNameSpecifierLoc getQualifierLoc() const { 02290 if (!hasQualifier()) 02291 return NestedNameSpecifierLoc(); 02292 02293 return getMemberQualifier()->QualifierLoc; 02294 } 02295 02296 /// \brief Return the optional template keyword and arguments info. 02297 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 02298 if (!HasTemplateKWAndArgsInfo) 02299 return 0; 02300 02301 if (!HasQualifierOrFoundDecl) 02302 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1); 02303 02304 return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 02305 getMemberQualifier() + 1); 02306 } 02307 02308 /// \brief Return the optional template keyword and arguments info. 02309 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 02310 return const_cast<MemberExpr*>(this)->getTemplateKWAndArgsInfo(); 02311 } 02312 02313 /// \brief Retrieve the location of the template keyword preceding 02314 /// the member name, if any. 02315 SourceLocation getTemplateKeywordLoc() const { 02316 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 02317 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 02318 } 02319 02320 /// \brief Retrieve the location of the left angle bracket starting the 02321 /// explicit template argument list following the member name, if any. 02322 SourceLocation getLAngleLoc() const { 02323 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 02324 return getTemplateKWAndArgsInfo()->LAngleLoc; 02325 } 02326 02327 /// \brief Retrieve the location of the right angle bracket ending the 02328 /// explicit template argument list following the member name, if any. 02329 SourceLocation getRAngleLoc() const { 02330 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 02331 return getTemplateKWAndArgsInfo()->RAngleLoc; 02332 } 02333 02334 /// Determines whether the member name was preceded by the template keyword. 02335 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 02336 02337 /// \brief Determines whether the member name was followed by an 02338 /// explicit template argument list. 02339 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 02340 02341 /// \brief Copies the template arguments (if present) into the given 02342 /// structure. 02343 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 02344 if (hasExplicitTemplateArgs()) 02345 getExplicitTemplateArgs().copyInto(List); 02346 } 02347 02348 /// \brief Retrieve the explicit template argument list that 02349 /// follow the member template name. This must only be called on an 02350 /// expression with explicit template arguments. 02351 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 02352 assert(hasExplicitTemplateArgs()); 02353 return *getTemplateKWAndArgsInfo(); 02354 } 02355 02356 /// \brief Retrieve the explicit template argument list that 02357 /// followed the member template name. This must only be called on 02358 /// an expression with explicit template arguments. 02359 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 02360 return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 02361 } 02362 02363 /// \brief Retrieves the optional explicit template arguments. 02364 /// This points to the same data as getExplicitTemplateArgs(), but 02365 /// returns null if there are no explicit template arguments. 02366 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 02367 if (!hasExplicitTemplateArgs()) return 0; 02368 return &getExplicitTemplateArgs(); 02369 } 02370 02371 /// \brief Retrieve the template arguments provided as part of this 02372 /// template-id. 02373 const TemplateArgumentLoc *getTemplateArgs() const { 02374 if (!hasExplicitTemplateArgs()) 02375 return 0; 02376 02377 return getExplicitTemplateArgs().getTemplateArgs(); 02378 } 02379 02380 /// \brief Retrieve the number of template arguments provided as part of this 02381 /// template-id. 02382 unsigned getNumTemplateArgs() const { 02383 if (!hasExplicitTemplateArgs()) 02384 return 0; 02385 02386 return getExplicitTemplateArgs().NumTemplateArgs; 02387 } 02388 02389 /// \brief Retrieve the member declaration name info. 02390 DeclarationNameInfo getMemberNameInfo() const { 02391 return DeclarationNameInfo(MemberDecl->getDeclName(), 02392 MemberLoc, MemberDNLoc); 02393 } 02394 02395 bool isArrow() const { return IsArrow; } 02396 void setArrow(bool A) { IsArrow = A; } 02397 02398 /// getMemberLoc - Return the location of the "member", in X->F, it is the 02399 /// location of 'F'. 02400 SourceLocation getMemberLoc() const { return MemberLoc; } 02401 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 02402 02403 SourceRange getSourceRange() const LLVM_READONLY; 02404 SourceLocation getLocStart() const LLVM_READONLY; 02405 SourceLocation getLocEnd() const LLVM_READONLY; 02406 02407 SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; } 02408 02409 /// \brief Determine whether the base of this explicit is implicit. 02410 bool isImplicitAccess() const { 02411 return getBase() && getBase()->isImplicitCXXThis(); 02412 } 02413 02414 /// \brief Returns true if this member expression refers to a method that 02415 /// was resolved from an overloaded set having size greater than 1. 02416 bool hadMultipleCandidates() const { 02417 return HadMultipleCandidates; 02418 } 02419 /// \brief Sets the flag telling whether this expression refers to 02420 /// a method that was resolved from an overloaded set having size 02421 /// greater than 1. 02422 void setHadMultipleCandidates(bool V = true) { 02423 HadMultipleCandidates = V; 02424 } 02425 02426 static bool classof(const Stmt *T) { 02427 return T->getStmtClass() == MemberExprClass; 02428 } 02429 static bool classof(const MemberExpr *) { return true; } 02430 02431 // Iterators 02432 child_range children() { return child_range(&Base, &Base+1); } 02433 02434 friend class ASTReader; 02435 friend class ASTStmtWriter; 02436 }; 02437 02438 /// CompoundLiteralExpr - [C99 6.5.2.5] 02439 /// 02440 class CompoundLiteralExpr : public Expr { 02441 /// LParenLoc - If non-null, this is the location of the left paren in a 02442 /// compound literal like "(int){4}". This can be null if this is a 02443 /// synthesized compound expression. 02444 SourceLocation LParenLoc; 02445 02446 /// The type as written. This can be an incomplete array type, in 02447 /// which case the actual expression type will be different. 02448 /// The int part of the pair stores whether this expr is file scope. 02449 llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope; 02450 Stmt *Init; 02451 public: 02452 CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 02453 QualType T, ExprValueKind VK, Expr *init, bool fileScope) 02454 : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 02455 tinfo->getType()->isDependentType(), 02456 init->isValueDependent(), 02457 (init->isInstantiationDependent() || 02458 tinfo->getType()->isInstantiationDependentType()), 02459 init->containsUnexpandedParameterPack()), 02460 LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {} 02461 02462 /// \brief Construct an empty compound literal. 02463 explicit CompoundLiteralExpr(EmptyShell Empty) 02464 : Expr(CompoundLiteralExprClass, Empty) { } 02465 02466 const Expr *getInitializer() const { return cast<Expr>(Init); } 02467 Expr *getInitializer() { return cast<Expr>(Init); } 02468 void setInitializer(Expr *E) { Init = E; } 02469 02470 bool isFileScope() const { return TInfoAndScope.getInt(); } 02471 void setFileScope(bool FS) { TInfoAndScope.setInt(FS); } 02472 02473 SourceLocation getLParenLoc() const { return LParenLoc; } 02474 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 02475 02476 TypeSourceInfo *getTypeSourceInfo() const { 02477 return TInfoAndScope.getPointer(); 02478 } 02479 void setTypeSourceInfo(TypeSourceInfo *tinfo) { 02480 TInfoAndScope.setPointer(tinfo); 02481 } 02482 02483 SourceRange getSourceRange() const LLVM_READONLY { 02484 // FIXME: Init should never be null. 02485 if (!Init) 02486 return SourceRange(); 02487 if (LParenLoc.isInvalid()) 02488 return Init->getSourceRange(); 02489 return SourceRange(LParenLoc, Init->getLocEnd()); 02490 } 02491 02492 static bool classof(const Stmt *T) { 02493 return T->getStmtClass() == CompoundLiteralExprClass; 02494 } 02495 static bool classof(const CompoundLiteralExpr *) { return true; } 02496 02497 // Iterators 02498 child_range children() { return child_range(&Init, &Init+1); } 02499 }; 02500 02501 /// CastExpr - Base class for type casts, including both implicit 02502 /// casts (ImplicitCastExpr) and explicit casts that have some 02503 /// representation in the source code (ExplicitCastExpr's derived 02504 /// classes). 02505 class CastExpr : public Expr { 02506 public: 02507 typedef clang::CastKind CastKind; 02508 02509 private: 02510 Stmt *Op; 02511 02512 void CheckCastConsistency() const; 02513 02514 const CXXBaseSpecifier * const *path_buffer() const { 02515 return const_cast<CastExpr*>(this)->path_buffer(); 02516 } 02517 CXXBaseSpecifier **path_buffer(); 02518 02519 void setBasePathSize(unsigned basePathSize) { 02520 CastExprBits.BasePathSize = basePathSize; 02521 assert(CastExprBits.BasePathSize == basePathSize && 02522 "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!"); 02523 } 02524 02525 protected: 02526 CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 02527 const CastKind kind, Expr *op, unsigned BasePathSize) : 02528 Expr(SC, ty, VK, OK_Ordinary, 02529 // Cast expressions are type-dependent if the type is 02530 // dependent (C++ [temp.dep.expr]p3). 02531 ty->isDependentType(), 02532 // Cast expressions are value-dependent if the type is 02533 // dependent or if the subexpression is value-dependent. 02534 ty->isDependentType() || (op && op->isValueDependent()), 02535 (ty->isInstantiationDependentType() || 02536 (op && op->isInstantiationDependent())), 02537 (ty->containsUnexpandedParameterPack() || 02538 op->containsUnexpandedParameterPack())), 02539 Op(op) { 02540 assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 02541 CastExprBits.Kind = kind; 02542 setBasePathSize(BasePathSize); 02543 #ifndef NDEBUG 02544 CheckCastConsistency(); 02545 #endif 02546 } 02547 02548 /// \brief Construct an empty cast. 02549 CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 02550 : Expr(SC, Empty) { 02551 setBasePathSize(BasePathSize); 02552 } 02553 02554 public: 02555 CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 02556 void setCastKind(CastKind K) { CastExprBits.Kind = K; } 02557 const char *getCastKindName() const; 02558 02559 Expr *getSubExpr() { return cast<Expr>(Op); } 02560 const Expr *getSubExpr() const { return cast<Expr>(Op); } 02561 void setSubExpr(Expr *E) { Op = E; } 02562 02563 /// \brief Retrieve the cast subexpression as it was written in the source 02564 /// code, looking through any implicit casts or other intermediate nodes 02565 /// introduced by semantic analysis. 02566 Expr *getSubExprAsWritten(); 02567 const Expr *getSubExprAsWritten() const { 02568 return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 02569 } 02570 02571 typedef CXXBaseSpecifier **path_iterator; 02572 typedef const CXXBaseSpecifier * const *path_const_iterator; 02573 bool path_empty() const { return CastExprBits.BasePathSize == 0; } 02574 unsigned path_size() const { return CastExprBits.BasePathSize; } 02575 path_iterator path_begin() { return path_buffer(); } 02576 path_iterator path_end() { return path_buffer() + path_size(); } 02577 path_const_iterator path_begin() const { return path_buffer(); } 02578 path_const_iterator path_end() const { return path_buffer() + path_size(); } 02579 02580 void setCastPath(const CXXCastPath &Path); 02581 02582 static bool classof(const Stmt *T) { 02583 return T->getStmtClass() >= firstCastExprConstant && 02584 T->getStmtClass() <= lastCastExprConstant; 02585 } 02586 static bool classof(const CastExpr *) { return true; } 02587 02588 // Iterators 02589 child_range children() { return child_range(&Op, &Op+1); } 02590 }; 02591 02592 /// ImplicitCastExpr - Allows us to explicitly represent implicit type 02593 /// conversions, which have no direct representation in the original 02594 /// source code. For example: converting T[]->T*, void f()->void 02595 /// (*f)(), float->double, short->int, etc. 02596 /// 02597 /// In C, implicit casts always produce rvalues. However, in C++, an 02598 /// implicit cast whose result is being bound to a reference will be 02599 /// an lvalue or xvalue. For example: 02600 /// 02601 /// @code 02602 /// class Base { }; 02603 /// class Derived : public Base { }; 02604 /// Derived &&ref(); 02605 /// void f(Derived d) { 02606 /// Base& b = d; // initializer is an ImplicitCastExpr 02607 /// // to an lvalue of type Base 02608 /// Base&& r = ref(); // initializer is an ImplicitCastExpr 02609 /// // to an xvalue of type Base 02610 /// } 02611 /// @endcode 02612 class ImplicitCastExpr : public CastExpr { 02613 private: 02614 ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 02615 unsigned BasePathLength, ExprValueKind VK) 02616 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 02617 } 02618 02619 /// \brief Construct an empty implicit cast. 02620 explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 02621 : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 02622 02623 public: 02624 enum OnStack_t { OnStack }; 02625 ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 02626 ExprValueKind VK) 02627 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 02628 } 02629 02630 static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 02631 CastKind Kind, Expr *Operand, 02632 const CXXCastPath *BasePath, 02633 ExprValueKind Cat); 02634 02635 static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 02636 02637 SourceRange getSourceRange() const LLVM_READONLY { 02638 return getSubExpr()->getSourceRange(); 02639 } 02640 SourceLocation getLocStart() const LLVM_READONLY { 02641 return getSubExpr()->getLocStart(); 02642 } 02643 SourceLocation getLocEnd() const LLVM_READONLY { 02644 return getSubExpr()->getLocEnd(); 02645 } 02646 02647 static bool classof(const Stmt *T) { 02648 return T->getStmtClass() == ImplicitCastExprClass; 02649 } 02650 static bool classof(const ImplicitCastExpr *) { return true; } 02651 }; 02652 02653 inline Expr *Expr::IgnoreImpCasts() { 02654 Expr *e = this; 02655 while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 02656 e = ice->getSubExpr(); 02657 return e; 02658 } 02659 02660 /// ExplicitCastExpr - An explicit cast written in the source 02661 /// code. 02662 /// 02663 /// This class is effectively an abstract class, because it provides 02664 /// the basic representation of an explicitly-written cast without 02665 /// specifying which kind of cast (C cast, functional cast, static 02666 /// cast, etc.) was written; specific derived classes represent the 02667 /// particular style of cast and its location information. 02668 /// 02669 /// Unlike implicit casts, explicit cast nodes have two different 02670 /// types: the type that was written into the source code, and the 02671 /// actual type of the expression as determined by semantic 02672 /// analysis. These types may differ slightly. For example, in C++ one 02673 /// can cast to a reference type, which indicates that the resulting 02674 /// expression will be an lvalue or xvalue. The reference type, however, 02675 /// will not be used as the type of the expression. 02676 class ExplicitCastExpr : public CastExpr { 02677 /// TInfo - Source type info for the (written) type 02678 /// this expression is casting to. 02679 TypeSourceInfo *TInfo; 02680 02681 protected: 02682 ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 02683 CastKind kind, Expr *op, unsigned PathSize, 02684 TypeSourceInfo *writtenTy) 02685 : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 02686 02687 /// \brief Construct an empty explicit cast. 02688 ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 02689 : CastExpr(SC, Shell, PathSize) { } 02690 02691 public: 02692 /// getTypeInfoAsWritten - Returns the type source info for the type 02693 /// that this expression is casting to. 02694 TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 02695 void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 02696 02697 /// getTypeAsWritten - Returns the type that this expression is 02698 /// casting to, as written in the source code. 02699 QualType getTypeAsWritten() const { return TInfo->getType(); } 02700 02701 static bool classof(const Stmt *T) { 02702 return T->getStmtClass() >= firstExplicitCastExprConstant && 02703 T->getStmtClass() <= lastExplicitCastExprConstant; 02704 } 02705 static bool classof(const ExplicitCastExpr *) { return true; } 02706 }; 02707 02708 /// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 02709 /// cast in C++ (C++ [expr.cast]), which uses the syntax 02710 /// (Type)expr. For example: @c (int)f. 02711 class CStyleCastExpr : public ExplicitCastExpr { 02712 SourceLocation LPLoc; // the location of the left paren 02713 SourceLocation RPLoc; // the location of the right paren 02714 02715 CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 02716 unsigned PathSize, TypeSourceInfo *writtenTy, 02717 SourceLocation l, SourceLocation r) 02718 : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 02719 writtenTy), LPLoc(l), RPLoc(r) {} 02720 02721 /// \brief Construct an empty C-style explicit cast. 02722 explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 02723 : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 02724 02725 public: 02726 static CStyleCastExpr *Create(ASTContext &Context, QualType T, 02727 ExprValueKind VK, CastKind K, 02728 Expr *Op, const CXXCastPath *BasePath, 02729 TypeSourceInfo *WrittenTy, SourceLocation L, 02730 SourceLocation R); 02731 02732 static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 02733 02734 SourceLocation getLParenLoc() const { return LPLoc; } 02735 void setLParenLoc(SourceLocation L) { LPLoc = L; } 02736 02737 SourceLocation getRParenLoc() const { return RPLoc; } 02738 void setRParenLoc(SourceLocation L) { RPLoc = L; } 02739 02740 SourceRange getSourceRange() const LLVM_READONLY { 02741 return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 02742 } 02743 static bool classof(const Stmt *T) { 02744 return T->getStmtClass() == CStyleCastExprClass; 02745 } 02746 static bool classof(const CStyleCastExpr *) { return true; } 02747 }; 02748 02749 /// \brief A builtin binary operation expression such as "x + y" or "x <= y". 02750 /// 02751 /// This expression node kind describes a builtin binary operation, 02752 /// such as "x + y" for integer values "x" and "y". The operands will 02753 /// already have been converted to appropriate types (e.g., by 02754 /// performing promotions or conversions). 02755 /// 02756 /// In C++, where operators may be overloaded, a different kind of 02757 /// expression node (CXXOperatorCallExpr) is used to express the 02758 /// invocation of an overloaded operator with operator syntax. Within 02759 /// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 02760 /// used to store an expression "x + y" depends on the subexpressions 02761 /// for x and y. If neither x or y is type-dependent, and the "+" 02762 /// operator resolves to a built-in operation, BinaryOperator will be 02763 /// used to express the computation (x and y may still be 02764 /// value-dependent). If either x or y is type-dependent, or if the 02765 /// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 02766 /// be used to express the computation. 02767 class BinaryOperator : public Expr { 02768 public: 02769 typedef BinaryOperatorKind Opcode; 02770 02771 private: 02772 unsigned Opc : 6; 02773 SourceLocation OpLoc; 02774 02775 enum { LHS, RHS, END_EXPR }; 02776 Stmt* SubExprs[END_EXPR]; 02777 public: 02778 02779 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 02780 ExprValueKind VK, ExprObjectKind OK, 02781 SourceLocation opLoc) 02782 : Expr(BinaryOperatorClass, ResTy, VK, OK, 02783 lhs->isTypeDependent() || rhs->isTypeDependent(), 02784 lhs->isValueDependent() || rhs->isValueDependent(), 02785 (lhs->isInstantiationDependent() || 02786 rhs->isInstantiationDependent()), 02787 (lhs->containsUnexpandedParameterPack() || 02788 rhs->containsUnexpandedParameterPack())), 02789 Opc(opc), OpLoc(opLoc) { 02790 SubExprs[LHS] = lhs; 02791 SubExprs[RHS] = rhs; 02792 assert(!isCompoundAssignmentOp() && 02793 "Use ArithAssignBinaryOperator for compound assignments"); 02794 } 02795 02796 /// \brief Construct an empty binary operator. 02797 explicit BinaryOperator(EmptyShell Empty) 02798 : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 02799 02800 SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; } 02801 SourceLocation getOperatorLoc() const { return OpLoc; } 02802 void setOperatorLoc(SourceLocation L) { OpLoc = L; } 02803 02804 Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 02805 void setOpcode(Opcode O) { Opc = O; } 02806 02807 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 02808 void setLHS(Expr *E) { SubExprs[LHS] = E; } 02809 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 02810 void setRHS(Expr *E) { SubExprs[RHS] = E; } 02811 02812 SourceRange getSourceRange() const LLVM_READONLY { 02813 return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 02814 } 02815 02816 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 02817 /// corresponds to, e.g. "<<=". 02818 static const char *getOpcodeStr(Opcode Op); 02819 02820 const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 02821 02822 /// \brief Retrieve the binary opcode that corresponds to the given 02823 /// overloaded operator. 02824 static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 02825 02826 /// \brief Retrieve the overloaded operator kind that corresponds to 02827 /// the given binary opcode. 02828 static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 02829 02830 /// predicates to categorize the respective opcodes. 02831 bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 02832 bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 02833 static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 02834 bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 02835 static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 02836 bool isShiftOp() const { return isShiftOp(getOpcode()); } 02837 02838 static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 02839 bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 02840 02841 static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 02842 bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 02843 02844 static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 02845 bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 02846 02847 static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 02848 bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 02849 02850 static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 02851 bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 02852 02853 static bool isAssignmentOp(Opcode Opc) { 02854 return Opc >= BO_Assign && Opc <= BO_OrAssign; 02855 } 02856 bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 02857 02858 static bool isCompoundAssignmentOp(Opcode Opc) { 02859 return Opc > BO_Assign && Opc <= BO_OrAssign; 02860 } 02861 bool isCompoundAssignmentOp() const { 02862 return isCompoundAssignmentOp(getOpcode()); 02863 } 02864 static Opcode getOpForCompoundAssignment(Opcode Opc) { 02865 assert(isCompoundAssignmentOp(Opc)); 02866 if (Opc >= BO_AndAssign) 02867 return Opcode(unsigned(Opc) - BO_AndAssign + BO_And); 02868 else 02869 return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul); 02870 } 02871 02872 static bool isShiftAssignOp(Opcode Opc) { 02873 return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 02874 } 02875 bool isShiftAssignOp() const { 02876 return isShiftAssignOp(getOpcode()); 02877 } 02878 02879 static bool classof(const Stmt *S) { 02880 return S->getStmtClass() >= firstBinaryOperatorConstant && 02881 S->getStmtClass() <= lastBinaryOperatorConstant; 02882 } 02883 static bool classof(const BinaryOperator *) { return true; } 02884 02885 // Iterators 02886 child_range children() { 02887 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 02888 } 02889 02890 protected: 02891 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 02892 ExprValueKind VK, ExprObjectKind OK, 02893 SourceLocation opLoc, bool dead) 02894 : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 02895 lhs->isTypeDependent() || rhs->isTypeDependent(), 02896 lhs->isValueDependent() || rhs->isValueDependent(), 02897 (lhs->isInstantiationDependent() || 02898 rhs->isInstantiationDependent()), 02899 (lhs->containsUnexpandedParameterPack() || 02900 rhs->containsUnexpandedParameterPack())), 02901 Opc(opc), OpLoc(opLoc) { 02902 SubExprs[LHS] = lhs; 02903 SubExprs[RHS] = rhs; 02904 } 02905 02906 BinaryOperator(StmtClass SC, EmptyShell Empty) 02907 : Expr(SC, Empty), Opc(BO_MulAssign) { } 02908 }; 02909 02910 /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 02911 /// track of the type the operation is performed in. Due to the semantics of 02912 /// these operators, the operands are promoted, the arithmetic performed, an 02913 /// implicit conversion back to the result type done, then the assignment takes 02914 /// place. This captures the intermediate type which the computation is done 02915 /// in. 02916 class CompoundAssignOperator : public BinaryOperator { 02917 QualType ComputationLHSType; 02918 QualType ComputationResultType; 02919 public: 02920 CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 02921 ExprValueKind VK, ExprObjectKind OK, 02922 QualType CompLHSType, QualType CompResultType, 02923 SourceLocation OpLoc) 02924 : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 02925 ComputationLHSType(CompLHSType), 02926 ComputationResultType(CompResultType) { 02927 assert(isCompoundAssignmentOp() && 02928 "Only should be used for compound assignments"); 02929 } 02930 02931 /// \brief Build an empty compound assignment operator expression. 02932 explicit CompoundAssignOperator(EmptyShell Empty) 02933 : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 02934 02935 // The two computation types are the type the LHS is converted 02936 // to for the computation and the type of the result; the two are 02937 // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 02938 QualType getComputationLHSType() const { return ComputationLHSType; } 02939 void setComputationLHSType(QualType T) { ComputationLHSType = T; } 02940 02941 QualType getComputationResultType() const { return ComputationResultType; } 02942 void setComputationResultType(QualType T) { ComputationResultType = T; } 02943 02944 static bool classof(const CompoundAssignOperator *) { return true; } 02945 static bool classof(const Stmt *S) { 02946 return S->getStmtClass() == CompoundAssignOperatorClass; 02947 } 02948 }; 02949 02950 /// AbstractConditionalOperator - An abstract base class for 02951 /// ConditionalOperator and BinaryConditionalOperator. 02952 class AbstractConditionalOperator : public Expr { 02953 SourceLocation QuestionLoc, ColonLoc; 02954 friend class ASTStmtReader; 02955 02956 protected: 02957 AbstractConditionalOperator(StmtClass SC, QualType T, 02958 ExprValueKind VK, ExprObjectKind OK, 02959 bool TD, bool VD, bool ID, 02960 bool ContainsUnexpandedParameterPack, 02961 SourceLocation qloc, 02962 SourceLocation cloc) 02963 : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack), 02964 QuestionLoc(qloc), ColonLoc(cloc) {} 02965 02966 AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 02967 : Expr(SC, Empty) { } 02968 02969 public: 02970 // getCond - Return the expression representing the condition for 02971 // the ?: operator. 02972 Expr *getCond() const; 02973 02974 // getTrueExpr - Return the subexpression representing the value of 02975 // the expression if the condition evaluates to true. 02976 Expr *getTrueExpr() const; 02977 02978 // getFalseExpr - Return the subexpression representing the value of 02979 // the expression if the condition evaluates to false. This is 02980 // the same as getRHS. 02981 Expr *getFalseExpr() const; 02982 02983 SourceLocation getQuestionLoc() const { return QuestionLoc; } 02984 SourceLocation getColonLoc() const { return ColonLoc; } 02985 02986 static bool classof(const Stmt *T) { 02987 return T->getStmtClass() == ConditionalOperatorClass || 02988 T->getStmtClass() == BinaryConditionalOperatorClass; 02989 } 02990 static bool classof(const AbstractConditionalOperator *) { return true; } 02991 }; 02992 02993 /// ConditionalOperator - The ?: ternary operator. The GNU "missing 02994 /// middle" extension is a BinaryConditionalOperator. 02995 class ConditionalOperator : public AbstractConditionalOperator { 02996 enum { COND, LHS, RHS, END_EXPR }; 02997 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 02998 02999 friend class ASTStmtReader; 03000 public: 03001 ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 03002 SourceLocation CLoc, Expr *rhs, 03003 QualType t, ExprValueKind VK, ExprObjectKind OK) 03004 : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 03005 // FIXME: the type of the conditional operator doesn't 03006 // depend on the type of the conditional, but the standard 03007 // seems to imply that it could. File a bug! 03008 (lhs->isTypeDependent() || rhs->isTypeDependent()), 03009 (cond->isValueDependent() || lhs->isValueDependent() || 03010 rhs->isValueDependent()), 03011 (cond->isInstantiationDependent() || 03012 lhs->isInstantiationDependent() || 03013 rhs->isInstantiationDependent()), 03014 (cond->containsUnexpandedParameterPack() || 03015 lhs->containsUnexpandedParameterPack() || 03016 rhs->containsUnexpandedParameterPack()), 03017 QLoc, CLoc) { 03018 SubExprs[COND] = cond; 03019 SubExprs[LHS] = lhs; 03020 SubExprs[RHS] = rhs; 03021 } 03022 03023 /// \brief Build an empty conditional operator. 03024 explicit ConditionalOperator(EmptyShell Empty) 03025 : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 03026 03027 // getCond - Return the expression representing the condition for 03028 // the ?: operator. 03029 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 03030 03031 // getTrueExpr - Return the subexpression representing the value of 03032 // the expression if the condition evaluates to true. 03033 Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 03034 03035 // getFalseExpr - Return the subexpression representing the value of 03036 // the expression if the condition evaluates to false. This is 03037 // the same as getRHS. 03038 Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 03039 03040 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 03041 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 03042 03043 SourceRange getSourceRange() const LLVM_READONLY { 03044 return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 03045 } 03046 static bool classof(const Stmt *T) { 03047 return T->getStmtClass() == ConditionalOperatorClass; 03048 } 03049 static bool classof(const ConditionalOperator *) { return true; } 03050 03051 // Iterators 03052 child_range children() { 03053 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 03054 } 03055 }; 03056 03057 /// BinaryConditionalOperator - The GNU extension to the conditional 03058 /// operator which allows the middle operand to be omitted. 03059 /// 03060 /// This is a different expression kind on the assumption that almost 03061 /// every client ends up needing to know that these are different. 03062 class BinaryConditionalOperator : public AbstractConditionalOperator { 03063 enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 03064 03065 /// - the common condition/left-hand-side expression, which will be 03066 /// evaluated as the opaque value 03067 /// - the condition, expressed in terms of the opaque value 03068 /// - the left-hand-side, expressed in terms of the opaque value 03069 /// - the right-hand-side 03070 Stmt *SubExprs[NUM_SUBEXPRS]; 03071 OpaqueValueExpr *OpaqueValue; 03072 03073 friend class ASTStmtReader; 03074 public: 03075 BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 03076 Expr *cond, Expr *lhs, Expr *rhs, 03077 SourceLocation qloc, SourceLocation cloc, 03078 QualType t, ExprValueKind VK, ExprObjectKind OK) 03079 : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 03080 (common->isTypeDependent() || rhs->isTypeDependent()), 03081 (common->isValueDependent() || rhs->isValueDependent()), 03082 (common->isInstantiationDependent() || 03083 rhs->isInstantiationDependent()), 03084 (common->containsUnexpandedParameterPack() || 03085 rhs->containsUnexpandedParameterPack()), 03086 qloc, cloc), 03087 OpaqueValue(opaqueValue) { 03088 SubExprs[COMMON] = common; 03089 SubExprs[COND] = cond; 03090 SubExprs[LHS] = lhs; 03091 SubExprs[RHS] = rhs; 03092 assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value"); 03093 } 03094 03095 /// \brief Build an empty conditional operator. 03096 explicit BinaryConditionalOperator(EmptyShell Empty) 03097 : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 03098 03099 /// \brief getCommon - Return the common expression, written to the 03100 /// left of the condition. The opaque value will be bound to the 03101 /// result of this expression. 03102 Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 03103 03104 /// \brief getOpaqueValue - Return the opaque value placeholder. 03105 OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 03106 03107 /// \brief getCond - Return the condition expression; this is defined 03108 /// in terms of the opaque value. 03109 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 03110 03111 /// \brief getTrueExpr - Return the subexpression which will be 03112 /// evaluated if the condition evaluates to true; this is defined 03113 /// in terms of the opaque value. 03114 Expr *getTrueExpr() const { 03115 return cast<Expr>(SubExprs[LHS]); 03116 } 03117 03118 /// \brief getFalseExpr - Return the subexpression which will be 03119 /// evaluated if the condnition evaluates to false; this is 03120 /// defined in terms of the opaque value. 03121 Expr *getFalseExpr() const { 03122 return cast<Expr>(SubExprs[RHS]); 03123 } 03124 03125 SourceRange getSourceRange() const LLVM_READONLY { 03126 return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 03127 } 03128 static bool classof(const Stmt *T) { 03129 return T->getStmtClass() == BinaryConditionalOperatorClass; 03130 } 03131 static bool classof(const BinaryConditionalOperator *) { return true; } 03132 03133 // Iterators 03134 child_range children() { 03135 return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 03136 } 03137 }; 03138 03139 inline Expr *AbstractConditionalOperator::getCond() const { 03140 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 03141 return co->getCond(); 03142 return cast<BinaryConditionalOperator>(this)->getCond(); 03143 } 03144 03145 inline Expr *AbstractConditionalOperator::getTrueExpr() const { 03146 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 03147 return co->getTrueExpr(); 03148 return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 03149 } 03150 03151 inline Expr *AbstractConditionalOperator::getFalseExpr() const { 03152 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 03153 return co->getFalseExpr(); 03154 return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 03155 } 03156 03157 /// AddrLabelExpr - The GNU address of label extension, representing &&label. 03158 class AddrLabelExpr : public Expr { 03159 SourceLocation AmpAmpLoc, LabelLoc; 03160 LabelDecl *Label; 03161 public: 03162 AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 03163 QualType t) 03164 : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false, 03165 false), 03166 AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 03167 03168 /// \brief Build an empty address of a label expression. 03169 explicit AddrLabelExpr(EmptyShell Empty) 03170 : Expr(AddrLabelExprClass, Empty) { } 03171 03172 SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 03173 void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 03174 SourceLocation getLabelLoc() const { return LabelLoc; } 03175 void setLabelLoc(SourceLocation L) { LabelLoc = L; } 03176 03177 SourceRange getSourceRange() const LLVM_READONLY { 03178 return SourceRange(AmpAmpLoc, LabelLoc); 03179 } 03180 03181 LabelDecl *getLabel() const { return Label; } 03182 void setLabel(LabelDecl *L) { Label = L; } 03183 03184 static bool classof(const Stmt *T) { 03185 return T->getStmtClass() == AddrLabelExprClass; 03186 } 03187 static bool classof(const AddrLabelExpr *) { return true; } 03188 03189 // Iterators 03190 child_range children() { return child_range(); } 03191 }; 03192 03193 /// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 03194 /// The StmtExpr contains a single CompoundStmt node, which it evaluates and 03195 /// takes the value of the last subexpression. 03196 /// 03197 /// A StmtExpr is always an r-value; values "returned" out of a 03198 /// StmtExpr will be copied. 03199 class StmtExpr : public Expr { 03200 Stmt *SubStmt; 03201 SourceLocation LParenLoc, RParenLoc; 03202 public: 03203 // FIXME: Does type-dependence need to be computed differently? 03204 // FIXME: Do we need to compute instantiation instantiation-dependence for 03205 // statements? (ugh!) 03206 StmtExpr(CompoundStmt *substmt, QualType T, 03207 SourceLocation lp, SourceLocation rp) : 03208 Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 03209 T->isDependentType(), false, false, false), 03210 SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 03211 03212 /// \brief Build an empty statement expression. 03213 explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 03214 03215 CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 03216 const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 03217 void setSubStmt(CompoundStmt *S) { SubStmt = S; } 03218 03219 SourceRange getSourceRange() const LLVM_READONLY { 03220 return SourceRange(LParenLoc, RParenLoc); 03221 } 03222 03223 SourceLocation getLParenLoc() const { return LParenLoc; } 03224 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 03225 SourceLocation getRParenLoc() const { return RParenLoc; } 03226 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 03227 03228 static bool classof(const Stmt *T) { 03229 return T->getStmtClass() == StmtExprClass; 03230 } 03231 static bool classof(const StmtExpr *) { return true; } 03232 03233 // Iterators 03234 child_range children() { return child_range(&SubStmt, &SubStmt+1); } 03235 }; 03236 03237 03238 /// ShuffleVectorExpr - clang-specific builtin-in function 03239 /// __builtin_shufflevector. 03240 /// This AST node represents a operator that does a constant 03241 /// shuffle, similar to LLVM's shufflevector instruction. It takes 03242 /// two vectors and a variable number of constant indices, 03243 /// and returns the appropriately shuffled vector. 03244 class ShuffleVectorExpr : public Expr { 03245 SourceLocation BuiltinLoc, RParenLoc; 03246 03247 // SubExprs - the list of values passed to the __builtin_shufflevector 03248 // function. The first two are vectors, and the rest are constant 03249 // indices. The number of values in this list is always 03250 // 2+the number of indices in the vector type. 03251 Stmt **SubExprs; 03252 unsigned NumExprs; 03253 03254 public: 03255 ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 03256 QualType Type, SourceLocation BLoc, 03257 SourceLocation RP); 03258 03259 /// \brief Build an empty vector-shuffle expression. 03260 explicit ShuffleVectorExpr(EmptyShell Empty) 03261 : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 03262 03263 SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 03264 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 03265 03266 SourceLocation getRParenLoc() const { return RParenLoc; } 03267 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 03268 03269 SourceRange getSourceRange() const LLVM_READONLY { 03270 return SourceRange(BuiltinLoc, RParenLoc); 03271 } 03272 static bool classof(const Stmt *T) { 03273 return T->getStmtClass() == ShuffleVectorExprClass; 03274 } 03275 static bool classof(const ShuffleVectorExpr *) { return true; } 03276 03277 /// getNumSubExprs - Return the size of the SubExprs array. This includes the 03278 /// constant expression, the actual arguments passed in, and the function 03279 /// pointers. 03280 unsigned getNumSubExprs() const { return NumExprs; } 03281 03282 /// \brief Retrieve the array of expressions. 03283 Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 03284 03285 /// getExpr - Return the Expr at the specified index. 03286 Expr *getExpr(unsigned Index) { 03287 assert((Index < NumExprs) && "Arg access out of range!"); 03288 return cast<Expr>(SubExprs[Index]); 03289 } 03290 const Expr *getExpr(unsigned Index) const { 03291 assert((Index < NumExprs) && "Arg access out of range!"); 03292 return cast<Expr>(SubExprs[Index]); 03293 } 03294 03295 void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 03296 03297 unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 03298 assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 03299 return getExpr(N+2)->EvaluateKnownConstInt(Ctx).getZExtValue(); 03300 } 03301 03302 // Iterators 03303 child_range children() { 03304 return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 03305 } 03306 }; 03307 03308 /// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 03309 /// This AST node is similar to the conditional operator (?:) in C, with 03310 /// the following exceptions: 03311 /// - the test expression must be a integer constant expression. 03312 /// - the expression returned acts like the chosen subexpression in every 03313 /// visible way: the type is the same as that of the chosen subexpression, 03314 /// and all predicates (whether it's an l-value, whether it's an integer 03315 /// constant expression, etc.) return the same result as for the chosen 03316 /// sub-expression. 03317 class ChooseExpr : public Expr { 03318 enum { COND, LHS, RHS, END_EXPR }; 03319 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 03320 SourceLocation BuiltinLoc, RParenLoc; 03321 public: 03322 ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 03323 QualType t, ExprValueKind VK, ExprObjectKind OK, 03324 SourceLocation RP, bool TypeDependent, bool ValueDependent) 03325 : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 03326 (cond->isInstantiationDependent() || 03327 lhs->isInstantiationDependent() || 03328 rhs->isInstantiationDependent()), 03329 (cond->containsUnexpandedParameterPack() || 03330 lhs->containsUnexpandedParameterPack() || 03331 rhs->containsUnexpandedParameterPack())), 03332 BuiltinLoc(BLoc), RParenLoc(RP) { 03333 SubExprs[COND] = cond; 03334 SubExprs[LHS] = lhs; 03335 SubExprs[RHS] = rhs; 03336 } 03337 03338 /// \brief Build an empty __builtin_choose_expr. 03339 explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 03340 03341 /// isConditionTrue - Return whether the condition is true (i.e. not 03342 /// equal to zero). 03343 bool isConditionTrue(const ASTContext &C) const; 03344 03345 /// getChosenSubExpr - Return the subexpression chosen according to the 03346 /// condition. 03347 Expr *getChosenSubExpr(const ASTContext &C) const { 03348 return isConditionTrue(C) ? getLHS() : getRHS(); 03349 } 03350 03351 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 03352 void setCond(Expr *E) { SubExprs[COND] = E; } 03353 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 03354 void setLHS(Expr *E) { SubExprs[LHS] = E; } 03355 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 03356 void setRHS(Expr *E) { SubExprs[RHS] = E; } 03357 03358 SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 03359 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 03360 03361 SourceLocation getRParenLoc() const { return RParenLoc; } 03362 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 03363 03364 SourceRange getSourceRange() const LLVM_READONLY { 03365 return SourceRange(BuiltinLoc, RParenLoc); 03366 } 03367 static bool classof(const Stmt *T) { 03368 return T->getStmtClass() == ChooseExprClass; 03369 } 03370 static bool classof(const ChooseExpr *) { return true; } 03371 03372 // Iterators 03373 child_range children() { 03374 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 03375 } 03376 }; 03377 03378 /// GNUNullExpr - Implements the GNU __null extension, which is a name 03379 /// for a null pointer constant that has integral type (e.g., int or 03380 /// long) and is the same size and alignment as a pointer. The __null 03381 /// extension is typically only used by system headers, which define 03382 /// NULL as __null in C++ rather than using 0 (which is an integer 03383 /// that may not match the size of a pointer). 03384 class GNUNullExpr : public Expr { 03385 /// TokenLoc - The location of the __null keyword. 03386 SourceLocation TokenLoc; 03387 03388 public: 03389 GNUNullExpr(QualType Ty, SourceLocation Loc) 03390 : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, 03391 false), 03392 TokenLoc(Loc) { } 03393 03394 /// \brief Build an empty GNU __null expression. 03395 explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 03396 03397 /// getTokenLocation - The location of the __null token. 03398 SourceLocation getTokenLocation() const { return TokenLoc; } 03399 void setTokenLocation(SourceLocation L) { TokenLoc = L; } 03400 03401 SourceRange getSourceRange() const LLVM_READONLY { 03402 return SourceRange(TokenLoc); 03403 } 03404 static bool classof(const Stmt *T) { 03405 return T->getStmtClass() == GNUNullExprClass; 03406 } 03407 static bool classof(const GNUNullExpr *) { return true; } 03408 03409 // Iterators 03410 child_range children() { return child_range(); } 03411 }; 03412 03413 /// VAArgExpr, used for the builtin function __builtin_va_arg. 03414 class VAArgExpr : public Expr { 03415 Stmt *Val; 03416 TypeSourceInfo *TInfo; 03417 SourceLocation BuiltinLoc, RParenLoc; 03418 public: 03419 VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 03420 SourceLocation RPLoc, QualType t) 03421 : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 03422 t->isDependentType(), false, 03423 (TInfo->getType()->isInstantiationDependentType() || 03424 e->isInstantiationDependent()), 03425 (TInfo->getType()->containsUnexpandedParameterPack() || 03426 e->containsUnexpandedParameterPack())), 03427 Val(e), TInfo(TInfo), 03428 BuiltinLoc(BLoc), 03429 RParenLoc(RPLoc) { } 03430 03431 /// \brief Create an empty __builtin_va_arg expression. 03432 explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 03433 03434 const Expr *getSubExpr() const { return cast<Expr>(Val); } 03435 Expr *getSubExpr() { return cast<Expr>(Val); } 03436 void setSubExpr(Expr *E) { Val = E; } 03437 03438 TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 03439 void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 03440 03441 SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 03442 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 03443 03444 SourceLocation getRParenLoc() const { return RParenLoc; } 03445 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 03446 03447 SourceRange getSourceRange() const LLVM_READONLY { 03448 return SourceRange(BuiltinLoc, RParenLoc); 03449 } 03450 static bool classof(const Stmt *T) { 03451 return T->getStmtClass() == VAArgExprClass; 03452 } 03453 static bool classof(const VAArgExpr *) { return true; } 03454 03455 // Iterators 03456 child_range children() { return child_range(&Val, &Val+1); } 03457 }; 03458 03459 /// @brief Describes an C or C++ initializer list. 03460 /// 03461 /// InitListExpr describes an initializer list, which can be used to 03462 /// initialize objects of different types, including 03463 /// struct/class/union types, arrays, and vectors. For example: 03464 /// 03465 /// @code 03466 /// struct foo x = { 1, { 2, 3 } }; 03467 /// @endcode 03468 /// 03469 /// Prior to semantic analysis, an initializer list will represent the 03470 /// initializer list as written by the user, but will have the 03471 /// placeholder type "void". This initializer list is called the 03472 /// syntactic form of the initializer, and may contain C99 designated 03473 /// initializers (represented as DesignatedInitExprs), initializations 03474 /// of subobject members without explicit braces, and so on. Clients 03475 /// interested in the original syntax of the initializer list should 03476 /// use the syntactic form of the initializer list. 03477 /// 03478 /// After semantic analysis, the initializer list will represent the 03479 /// semantic form of the initializer, where the initializations of all 03480 /// subobjects are made explicit with nested InitListExpr nodes and 03481 /// C99 designators have been eliminated by placing the designated 03482 /// initializations into the subobject they initialize. Additionally, 03483 /// any "holes" in the initialization, where no initializer has been 03484 /// specified for a particular subobject, will be replaced with 03485 /// implicitly-generated ImplicitValueInitExpr expressions that 03486 /// value-initialize the subobjects. Note, however, that the 03487 /// initializer lists may still have fewer initializers than there are 03488 /// elements to initialize within the object. 03489 /// 03490 /// Given the semantic form of the initializer list, one can retrieve 03491 /// the original syntactic form of that initializer list (if it 03492 /// exists) using getSyntacticForm(). Since many initializer lists 03493 /// have the same syntactic and semantic forms, getSyntacticForm() may 03494 /// return NULL, indicating that the current initializer list also 03495 /// serves as its syntactic form. 03496 class InitListExpr : public Expr { 03497 // FIXME: Eliminate this vector in favor of ASTContext allocation 03498 typedef ASTVector<Stmt *> InitExprsTy; 03499 InitExprsTy InitExprs; 03500 SourceLocation LBraceLoc, RBraceLoc; 03501 03502 /// Contains the initializer list that describes the syntactic form 03503 /// written in the source code. 03504 InitListExpr *SyntacticForm; 03505 03506 /// \brief Either: 03507 /// If this initializer list initializes an array with more elements than 03508 /// there are initializers in the list, specifies an expression to be used 03509 /// for value initialization of the rest of the elements. 03510 /// Or 03511 /// If this initializer list initializes a union, specifies which 03512 /// field within the union will be initialized. 03513 llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; 03514 03515 public: 03516 InitListExpr(ASTContext &C, SourceLocation lbraceloc, 03517 Expr **initexprs, unsigned numinits, 03518 SourceLocation rbraceloc); 03519 03520 /// \brief Build an empty initializer list. 03521 explicit InitListExpr(ASTContext &C, EmptyShell Empty) 03522 : Expr(InitListExprClass, Empty), InitExprs(C) { } 03523 03524 unsigned getNumInits() const { return InitExprs.size(); } 03525 03526 /// \brief Retrieve the set of initializers. 03527 Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 03528 03529 const Expr *getInit(unsigned Init) const { 03530 assert(Init < getNumInits() && "Initializer access out of range!"); 03531 return cast_or_null<Expr>(InitExprs[Init]); 03532 } 03533 03534 Expr *getInit(unsigned Init) { 03535 assert(Init < getNumInits() && "Initializer access out of range!"); 03536 return cast_or_null<Expr>(InitExprs[Init]); 03537 } 03538 03539 void setInit(unsigned Init, Expr *expr) { 03540 assert(Init < getNumInits() && "Initializer access out of range!"); 03541 InitExprs[Init] = expr; 03542 } 03543 03544 /// \brief Reserve space for some number of initializers. 03545 void reserveInits(ASTContext &C, unsigned NumInits); 03546 03547 /// @brief Specify the number of initializers 03548 /// 03549 /// If there are more than @p NumInits initializers, the remaining 03550 /// initializers will be destroyed. If there are fewer than @p 03551 /// NumInits initializers, NULL expressions will be added for the 03552 /// unknown initializers. 03553 void resizeInits(ASTContext &Context, unsigned NumInits); 03554 03555 /// @brief Updates the initializer at index @p Init with the new 03556 /// expression @p expr, and returns the old expression at that 03557 /// location. 03558 /// 03559 /// When @p Init is out of range for this initializer list, the 03560 /// initializer list will be extended with NULL expressions to 03561 /// accommodate the new entry. 03562 Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 03563 03564 /// \brief If this initializer list initializes an array with more elements 03565 /// than there are initializers in the list, specifies an expression to be 03566 /// used for value initialization of the rest of the elements. 03567 Expr *getArrayFiller() { 03568 return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); 03569 } 03570 const Expr *getArrayFiller() const { 03571 return const_cast<InitListExpr *>(this)->getArrayFiller(); 03572 } 03573 void setArrayFiller(Expr *filler); 03574 03575 /// \brief Return true if this is an array initializer and its array "filler" 03576 /// has been set. 03577 bool hasArrayFiller() const { return getArrayFiller(); } 03578 03579 /// \brief If this initializes a union, specifies which field in the 03580 /// union to initialize. 03581 /// 03582 /// Typically, this field is the first named field within the 03583 /// union. However, a designated initializer can specify the 03584 /// initialization of a different field within the union. 03585 FieldDecl *getInitializedFieldInUnion() { 03586 return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); 03587 } 03588 const FieldDecl *getInitializedFieldInUnion() const { 03589 return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); 03590 } 03591 void setInitializedFieldInUnion(FieldDecl *FD) { 03592 ArrayFillerOrUnionFieldInit = FD; 03593 } 03594 03595 // Explicit InitListExpr's originate from source code (and have valid source 03596 // locations). Implicit InitListExpr's are created by the semantic analyzer. 03597 bool isExplicit() { 03598 return LBraceLoc.isValid() && RBraceLoc.isValid(); 03599 } 03600 03601 // Is this an initializer for an array of characters, initialized by a string 03602 // literal or an @encode? 03603 bool isStringLiteralInit() const; 03604 03605 SourceLocation getLBraceLoc() const { return LBraceLoc; } 03606 void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 03607 SourceLocation getRBraceLoc() const { return RBraceLoc; } 03608 void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 03609 03610 /// @brief Retrieve the initializer list that describes the 03611 /// syntactic form of the initializer. 03612 /// 03613 /// 03614 InitListExpr *getSyntacticForm() const { return SyntacticForm; } 03615 void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 03616 03617 bool hadArrayRangeDesignator() const { 03618 return InitListExprBits.HadArrayRangeDesignator != 0; 03619 } 03620 void sawArrayRangeDesignator(bool ARD = true) { 03621 InitListExprBits.HadArrayRangeDesignator = ARD; 03622 } 03623 03624 bool initializesStdInitializerList() const { 03625 return InitListExprBits.InitializesStdInitializerList != 0; 03626 } 03627 void setInitializesStdInitializerList(bool ISIL = true) { 03628 InitListExprBits.InitializesStdInitializerList = ISIL; 03629 } 03630 03631 SourceRange getSourceRange() const LLVM_READONLY; 03632 03633 static bool classof(const Stmt *T) { 03634 return T->getStmtClass() == InitListExprClass; 03635 } 03636 static bool classof(const InitListExpr *) { return true; } 03637 03638 // Iterators 03639 child_range children() { 03640 if (InitExprs.empty()) return child_range(); 03641 return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 03642 } 03643 03644 typedef InitExprsTy::iterator iterator; 03645 typedef InitExprsTy::const_iterator const_iterator; 03646 typedef InitExprsTy::reverse_iterator reverse_iterator; 03647 typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 03648 03649 iterator begin() { return InitExprs.begin(); } 03650 const_iterator begin() const { return InitExprs.begin(); } 03651 iterator end() { return InitExprs.end(); } 03652 const_iterator end() const { return InitExprs.end(); } 03653 reverse_iterator rbegin() { return InitExprs.rbegin(); } 03654 const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 03655 reverse_iterator rend() { return InitExprs.rend(); } 03656 const_reverse_iterator rend() const { return InitExprs.rend(); } 03657 03658 friend class ASTStmtReader; 03659 friend class ASTStmtWriter; 03660 }; 03661 03662 /// @brief Represents a C99 designated initializer expression. 03663 /// 03664 /// A designated initializer expression (C99 6.7.8) contains one or 03665 /// more designators (which can be field designators, array 03666 /// designators, or GNU array-range designators) followed by an 03667 /// expression that initializes the field or element(s) that the 03668 /// designators refer to. For example, given: 03669 /// 03670 /// @code 03671 /// struct point { 03672 /// double x; 03673 /// double y; 03674 /// }; 03675 /// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 03676 /// @endcode 03677 /// 03678 /// The InitListExpr contains three DesignatedInitExprs, the first of 03679 /// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 03680 /// designators, one array designator for @c [2] followed by one field 03681 /// designator for @c .y. The initalization expression will be 1.0. 03682 class DesignatedInitExpr : public Expr { 03683 public: 03684 /// \brief Forward declaration of the Designator class. 03685 class Designator; 03686 03687 private: 03688 /// The location of the '=' or ':' prior to the actual initializer 03689 /// expression. 03690 SourceLocation EqualOrColonLoc; 03691 03692 /// Whether this designated initializer used the GNU deprecated 03693 /// syntax rather than the C99 '=' syntax. 03694 bool GNUSyntax : 1; 03695 03696 /// The number of designators in this initializer expression. 03697 unsigned NumDesignators : 15; 03698 03699 /// The number of subexpressions of this initializer expression, 03700 /// which contains both the initializer and any additional 03701 /// expressions used by array and array-range designators. 03702 unsigned NumSubExprs : 16; 03703 03704 /// \brief The designators in this designated initialization 03705 /// expression. 03706 Designator *Designators; 03707 03708 03709 DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 03710 const Designator *Designators, 03711 SourceLocation EqualOrColonLoc, bool GNUSyntax, 03712 Expr **IndexExprs, unsigned NumIndexExprs, 03713 Expr *Init); 03714 03715 explicit DesignatedInitExpr(unsigned NumSubExprs) 03716 : Expr(DesignatedInitExprClass, EmptyShell()), 03717 NumDesignators(0), NumSubExprs(NumSubExprs), Designators(0) { } 03718 03719 public: 03720 /// A field designator, e.g., ".x". 03721 struct FieldDesignator { 03722 /// Refers to the field that is being initialized. The low bit 03723 /// of this field determines whether this is actually a pointer 03724 /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 03725 /// initially constructed, a field designator will store an 03726 /// IdentifierInfo*. After semantic analysis has resolved that 03727 /// name, the field designator will instead store a FieldDecl*. 03728 uintptr_t NameOrField; 03729 03730 /// The location of the '.' in the designated initializer. 03731 unsigned DotLoc; 03732 03733 /// The location of the field name in the designated initializer. 03734 unsigned FieldLoc; 03735 }; 03736 03737 /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 03738 struct ArrayOrRangeDesignator { 03739 /// Location of the first index expression within the designated 03740 /// initializer expression's list of subexpressions. 03741 unsigned Index; 03742 /// The location of the '[' starting the array range designator. 03743 unsigned LBracketLoc; 03744 /// The location of the ellipsis separating the start and end 03745 /// indices. Only valid for GNU array-range designators. 03746 unsigned EllipsisLoc; 03747 /// The location of the ']' terminating the array range designator. 03748 unsigned RBracketLoc; 03749 }; 03750 03751 /// @brief Represents a single C99 designator. 03752 /// 03753 /// @todo This class is infuriatingly similar to clang::Designator, 03754 /// but minor differences (storing indices vs. storing pointers) 03755 /// keep us from reusing it. Try harder, later, to rectify these 03756 /// differences. 03757 class Designator { 03758 /// @brief The kind of designator this describes. 03759 enum { 03760 FieldDesignator, 03761 ArrayDesignator, 03762 ArrayRangeDesignator 03763 } Kind; 03764 03765 union { 03766 /// A field designator, e.g., ".x". 03767 struct FieldDesignator Field; 03768 /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 03769 struct ArrayOrRangeDesignator ArrayOrRange; 03770 }; 03771 friend class DesignatedInitExpr; 03772 03773 public: 03774 Designator() {} 03775 03776 /// @brief Initializes a field designator. 03777 Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 03778 SourceLocation FieldLoc) 03779 : Kind(FieldDesignator) { 03780 Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 03781 Field.DotLoc = DotLoc.getRawEncoding(); 03782 Field.FieldLoc = FieldLoc.getRawEncoding(); 03783 } 03784 03785 /// @brief Initializes an array designator. 03786 Designator(unsigned Index, SourceLocation LBracketLoc, 03787 SourceLocation RBracketLoc) 03788 : Kind(ArrayDesignator) { 03789 ArrayOrRange.Index = Index; 03790 ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 03791 ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 03792 ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 03793 } 03794 03795 /// @brief Initializes a GNU array-range designator. 03796 Designator(unsigned Index, SourceLocation LBracketLoc, 03797 SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 03798 : Kind(ArrayRangeDesignator) { 03799 ArrayOrRange.Index = Index; 03800 ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 03801 ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 03802 ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 03803 } 03804 03805 bool isFieldDesignator() const { return Kind == FieldDesignator; } 03806 bool isArrayDesignator() const { return Kind == ArrayDesignator; } 03807 bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 03808 03809 IdentifierInfo *getFieldName() const; 03810 03811 FieldDecl *getField() const { 03812 assert(Kind == FieldDesignator && "Only valid on a field designator"); 03813 if (Field.NameOrField & 0x01) 03814 return 0; 03815 else 03816 return reinterpret_cast<FieldDecl *>(Field.NameOrField); 03817 } 03818 03819 void setField(FieldDecl *FD) { 03820 assert(Kind == FieldDesignator && "Only valid on a field designator"); 03821 Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 03822 } 03823 03824 SourceLocation getDotLoc() const { 03825 assert(Kind == FieldDesignator && "Only valid on a field designator"); 03826 return SourceLocation::getFromRawEncoding(Field.DotLoc); 03827 } 03828 03829 SourceLocation getFieldLoc() const { 03830 assert(Kind == FieldDesignator && "Only valid on a field designator"); 03831 return SourceLocation::getFromRawEncoding(Field.FieldLoc); 03832 } 03833 03834 SourceLocation getLBracketLoc() const { 03835 assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 03836 "Only valid on an array or array-range designator"); 03837 return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 03838 } 03839 03840 SourceLocation getRBracketLoc() const { 03841 assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 03842 "Only valid on an array or array-range designator"); 03843 return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 03844 } 03845 03846 SourceLocation getEllipsisLoc() const { 03847 assert(Kind == ArrayRangeDesignator && 03848 "Only valid on an array-range designator"); 03849 return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 03850 } 03851 03852 unsigned getFirstExprIndex() const { 03853 assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 03854 "Only valid on an array or array-range designator"); 03855 return ArrayOrRange.Index; 03856 } 03857 03858 SourceLocation getStartLocation() const { 03859 if (Kind == FieldDesignator) 03860 return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 03861 else 03862 return getLBracketLoc(); 03863 } 03864 SourceLocation getEndLocation() const { 03865 return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 03866 } 03867 SourceRange getSourceRange() const LLVM_READONLY { 03868 return SourceRange(getStartLocation(), getEndLocation()); 03869 } 03870 }; 03871 03872 static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 03873 unsigned NumDesignators, 03874 Expr **IndexExprs, unsigned NumIndexExprs, 03875 SourceLocation EqualOrColonLoc, 03876 bool GNUSyntax, Expr *Init); 03877 03878 static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 03879 03880 /// @brief Returns the number of designators in this initializer. 03881 unsigned size() const { return NumDesignators; } 03882 03883 // Iterator access to the designators. 03884 typedef Designator *designators_iterator; 03885 designators_iterator designators_begin() { return Designators; } 03886 designators_iterator designators_end() { 03887 return Designators + NumDesignators; 03888 } 03889 03890 typedef const Designator *const_designators_iterator; 03891 const_designators_iterator designators_begin() const { return Designators; } 03892 const_designators_iterator designators_end() const { 03893 return Designators + NumDesignators; 03894 } 03895 03896 typedef std::reverse_iterator<designators_iterator> 03897 reverse_designators_iterator; 03898 reverse_designators_iterator designators_rbegin() { 03899 return reverse_designators_iterator(designators_end()); 03900 } 03901 reverse_designators_iterator designators_rend() { 03902 return reverse_designators_iterator(designators_begin()); 03903 } 03904 03905 typedef std::reverse_iterator<const_designators_iterator> 03906 const_reverse_designators_iterator; 03907 const_reverse_designators_iterator designators_rbegin() const { 03908 return const_reverse_designators_iterator(designators_end()); 03909 } 03910 const_reverse_designators_iterator designators_rend() const { 03911 return const_reverse_designators_iterator(designators_begin()); 03912 } 03913 03914 Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 03915 03916 void setDesignators(ASTContext &C, const Designator *Desigs, 03917 unsigned NumDesigs); 03918 03919 Expr *getArrayIndex(const Designator& D); 03920 Expr *getArrayRangeStart(const Designator& D); 03921 Expr *getArrayRangeEnd(const Designator& D); 03922 03923 /// @brief Retrieve the location of the '=' that precedes the 03924 /// initializer value itself, if present. 03925 SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 03926 void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 03927 03928 /// @brief Determines whether this designated initializer used the 03929 /// deprecated GNU syntax for designated initializers. 03930 bool usesGNUSyntax() const { return GNUSyntax; } 03931 void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 03932 03933 /// @brief Retrieve the initializer value. 03934 Expr *getInit() const { 03935 return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 03936 } 03937 03938 void setInit(Expr *init) { 03939 *child_begin() = init; 03940 } 03941 03942 /// \brief Retrieve the total number of subexpressions in this 03943 /// designated initializer expression, including the actual 03944 /// initialized value and any expressions that occur within array 03945 /// and array-range designators. 03946 unsigned getNumSubExprs() const { return NumSubExprs; } 03947 03948 Expr *getSubExpr(unsigned Idx) { 03949 assert(Idx < NumSubExprs && "Subscript out of range"); 03950 char* Ptr = static_cast<char*>(static_cast<void *>(this)); 03951 Ptr += sizeof(DesignatedInitExpr); 03952 return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 03953 } 03954 03955 void setSubExpr(unsigned Idx, Expr *E) { 03956 assert(Idx < NumSubExprs && "Subscript out of range"); 03957 char* Ptr = static_cast<char*>(static_cast<void *>(this)); 03958 Ptr += sizeof(DesignatedInitExpr); 03959 reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 03960 } 03961 03962 /// \brief Replaces the designator at index @p Idx with the series 03963 /// of designators in [First, Last). 03964 void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 03965 const Designator *Last); 03966 03967 SourceRange getDesignatorsSourceRange() const; 03968 03969 SourceRange getSourceRange() const LLVM_READONLY; 03970 03971 static bool classof(const Stmt *T) { 03972 return T->getStmtClass() == DesignatedInitExprClass; 03973 } 03974 static bool classof(const DesignatedInitExpr *) { return true; } 03975 03976 // Iterators 03977 child_range children() { 03978 Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 03979 return child_range(begin, begin + NumSubExprs); 03980 } 03981 }; 03982 03983 /// \brief Represents an implicitly-generated value initialization of 03984 /// an object of a given type. 03985 /// 03986 /// Implicit value initializations occur within semantic initializer 03987 /// list expressions (InitListExpr) as placeholders for subobject 03988 /// initializations not explicitly specified by the user. 03989 /// 03990 /// \see InitListExpr 03991 class ImplicitValueInitExpr : public Expr { 03992 public: 03993 explicit ImplicitValueInitExpr(QualType ty) 03994 : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 03995 false, false, ty->isInstantiationDependentType(), false) { } 03996 03997 /// \brief Construct an empty implicit value initialization. 03998 explicit ImplicitValueInitExpr(EmptyShell Empty) 03999 : Expr(ImplicitValueInitExprClass, Empty) { } 04000 04001 static bool classof(const Stmt *T) { 04002 return T->getStmtClass() == ImplicitValueInitExprClass; 04003 } 04004 static bool classof(const ImplicitValueInitExpr *) { return true; } 04005 04006 SourceRange getSourceRange() const LLVM_READONLY { 04007 return SourceRange(); 04008 } 04009 04010 // Iterators 04011 child_range children() { return child_range(); } 04012 }; 04013 04014 04015 class ParenListExpr : public Expr { 04016 Stmt **Exprs; 04017 unsigned NumExprs; 04018 SourceLocation LParenLoc, RParenLoc; 04019 04020 public: 04021 ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 04022 unsigned numexprs, SourceLocation rparenloc); 04023 04024 /// \brief Build an empty paren list. 04025 explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 04026 04027 unsigned getNumExprs() const { return NumExprs; } 04028 04029 const Expr* getExpr(unsigned Init) const { 04030 assert(Init < getNumExprs() && "Initializer access out of range!"); 04031 return cast_or_null<Expr>(Exprs[Init]); 04032 } 04033 04034 Expr* getExpr(unsigned Init) { 04035 assert(Init < getNumExprs() && "Initializer access out of range!"); 04036 return cast_or_null<Expr>(Exprs[Init]); 04037 } 04038 04039 Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 04040 04041 SourceLocation getLParenLoc() const { return LParenLoc; } 04042 SourceLocation getRParenLoc() const { return RParenLoc; } 04043 04044 SourceRange getSourceRange() const LLVM_READONLY { 04045 return SourceRange(LParenLoc, RParenLoc); 04046 } 04047 static bool classof(const Stmt *T) { 04048 return T->getStmtClass() == ParenListExprClass; 04049 } 04050 static bool classof(const ParenListExpr *) { return true; } 04051 04052 // Iterators 04053 child_range children() { 04054 return child_range(&Exprs[0], &Exprs[0]+NumExprs); 04055 } 04056 04057 friend class ASTStmtReader; 04058 friend class ASTStmtWriter; 04059 }; 04060 04061 04062 /// \brief Represents a C11 generic selection. 04063 /// 04064 /// A generic selection (C11 6.5.1.1) contains an unevaluated controlling 04065 /// expression, followed by one or more generic associations. Each generic 04066 /// association specifies a type name and an expression, or "default" and an 04067 /// expression (in which case it is known as a default generic association). 04068 /// The type and value of the generic selection are identical to those of its 04069 /// result expression, which is defined as the expression in the generic 04070 /// association with a type name that is compatible with the type of the 04071 /// controlling expression, or the expression in the default generic association 04072 /// if no types are compatible. For example: 04073 /// 04074 /// @code 04075 /// _Generic(X, double: 1, float: 2, default: 3) 04076 /// @endcode 04077 /// 04078 /// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 04079 /// or 3 if "hello". 04080 /// 04081 /// As an extension, generic selections are allowed in C++, where the following 04082 /// additional semantics apply: 04083 /// 04084 /// Any generic selection whose controlling expression is type-dependent or 04085 /// which names a dependent type in its association list is result-dependent, 04086 /// which means that the choice of result expression is dependent. 04087 /// Result-dependent generic associations are both type- and value-dependent. 04088 class GenericSelectionExpr : public Expr { 04089 enum { CONTROLLING, END_EXPR }; 04090 TypeSourceInfo **AssocTypes; 04091 Stmt **SubExprs; 04092 unsigned NumAssocs, ResultIndex; 04093 SourceLocation GenericLoc, DefaultLoc, RParenLoc; 04094 04095 public: 04096 GenericSelectionExpr(ASTContext &Context, 04097 SourceLocation GenericLoc, Expr *ControllingExpr, 04098 TypeSourceInfo **AssocTypes, Expr **AssocExprs, 04099 unsigned NumAssocs, SourceLocation DefaultLoc, 04100 SourceLocation RParenLoc, 04101 bool ContainsUnexpandedParameterPack, 04102 unsigned ResultIndex); 04103 04104 /// This constructor is used in the result-dependent case. 04105 GenericSelectionExpr(ASTContext &Context, 04106 SourceLocation GenericLoc, Expr *ControllingExpr, 04107 TypeSourceInfo **AssocTypes, Expr **AssocExprs, 04108 unsigned NumAssocs, SourceLocation DefaultLoc, 04109 SourceLocation RParenLoc, 04110 bool ContainsUnexpandedParameterPack); 04111 04112 explicit GenericSelectionExpr(EmptyShell Empty) 04113 : Expr(GenericSelectionExprClass, Empty) { } 04114 04115 unsigned getNumAssocs() const { return NumAssocs; } 04116 04117 SourceLocation getGenericLoc() const { return GenericLoc; } 04118 SourceLocation getDefaultLoc() const { return DefaultLoc; } 04119 SourceLocation getRParenLoc() const { return RParenLoc; } 04120 04121 const Expr *getAssocExpr(unsigned i) const { 04122 return cast<Expr>(SubExprs[END_EXPR+i]); 04123 } 04124 Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 04125 04126 const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 04127 return AssocTypes[i]; 04128 } 04129 TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 04130 04131 QualType getAssocType(unsigned i) const { 04132 if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 04133 return TS->getType(); 04134 else 04135 return QualType(); 04136 } 04137 04138 const Expr *getControllingExpr() const { 04139 return cast<Expr>(SubExprs[CONTROLLING]); 04140 } 04141 Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 04142 04143 /// Whether this generic selection is result-dependent. 04144 bool isResultDependent() const { return ResultIndex == -1U; } 04145 04146 /// The zero-based index of the result expression's generic association in 04147 /// the generic selection's association list. Defined only if the 04148 /// generic selection is not result-dependent. 04149 unsigned getResultIndex() const { 04150 assert(!isResultDependent() && "Generic selection is result-dependent"); 04151 return ResultIndex; 04152 } 04153 04154 /// The generic selection's result expression. Defined only if the 04155 /// generic selection is not result-dependent. 04156 const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 04157 Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 04158 04159 SourceRange getSourceRange() const LLVM_READONLY { 04160 return SourceRange(GenericLoc, RParenLoc); 04161 } 04162 static bool classof(const Stmt *T) { 04163 return T->getStmtClass() == GenericSelectionExprClass; 04164 } 04165 static bool classof(const GenericSelectionExpr *) { return true; } 04166 04167 child_range children() { 04168 return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 04169 } 04170 04171 friend class ASTStmtReader; 04172 }; 04173 04174 //===----------------------------------------------------------------------===// 04175 // Clang Extensions 04176 //===----------------------------------------------------------------------===// 04177 04178 04179 /// ExtVectorElementExpr - This represents access to specific elements of a 04180 /// vector, and may occur on the left hand side or right hand side. For example 04181 /// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 04182 /// 04183 /// Note that the base may have either vector or pointer to vector type, just 04184 /// like a struct field reference. 04185 /// 04186 class ExtVectorElementExpr : public Expr { 04187 Stmt *Base; 04188 IdentifierInfo *Accessor; 04189 SourceLocation AccessorLoc; 04190 public: 04191 ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 04192 IdentifierInfo &accessor, SourceLocation loc) 04193 : Expr(ExtVectorElementExprClass, ty, VK, 04194 (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 04195 base->isTypeDependent(), base->isValueDependent(), 04196 base->isInstantiationDependent(), 04197 base->containsUnexpandedParameterPack()), 04198 Base(base), Accessor(&accessor), AccessorLoc(loc) {} 04199 04200 /// \brief Build an empty vector element expression. 04201 explicit ExtVectorElementExpr(EmptyShell Empty) 04202 : Expr(ExtVectorElementExprClass, Empty) { } 04203 04204 const Expr *getBase() const { return cast<Expr>(Base); } 04205 Expr *getBase() { return cast<Expr>(Base); } 04206 void setBase(Expr *E) { Base = E; } 04207 04208 IdentifierInfo &getAccessor() const { return *Accessor; } 04209 void setAccessor(IdentifierInfo *II) { Accessor = II; } 04210 04211 SourceLocation getAccessorLoc() const { return AccessorLoc; } 04212 void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 04213 04214 /// getNumElements - Get the number of components being selected. 04215 unsigned getNumElements() const; 04216 04217 /// containsDuplicateElements - Return true if any element access is 04218 /// repeated. 04219 bool containsDuplicateElements() const; 04220 04221 /// getEncodedElementAccess - Encode the elements accessed into an llvm 04222 /// aggregate Constant of ConstantInt(s). 04223 void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const; 04224 04225 SourceRange getSourceRange() const LLVM_READONLY { 04226 return SourceRange(getBase()->getLocStart(), AccessorLoc); 04227 } 04228 04229 /// isArrow - Return true if the base expression is a pointer to vector, 04230 /// return false if the base expression is a vector. 04231 bool isArrow() const; 04232 04233 static bool classof(const Stmt *T) { 04234 return T->getStmtClass() == ExtVectorElementExprClass; 04235 } 04236 static bool classof(const ExtVectorElementExpr *) { return true; } 04237 04238 // Iterators 04239 child_range children() { return child_range(&Base, &Base+1); } 04240 }; 04241 04242 04243 /// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 04244 /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 04245 class BlockExpr : public Expr { 04246 protected: 04247 BlockDecl *TheBlock; 04248 public: 04249 BlockExpr(BlockDecl *BD, QualType ty) 04250 : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 04251 ty->isDependentType(), ty->isDependentType(), 04252 ty->isInstantiationDependentType() || BD->isDependentContext(), 04253 false), 04254 TheBlock(BD) {} 04255 04256 /// \brief Build an empty block expression. 04257 explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 04258 04259 const BlockDecl *getBlockDecl() const { return TheBlock; } 04260 BlockDecl *getBlockDecl() { return TheBlock; } 04261 void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 04262 04263 // Convenience functions for probing the underlying BlockDecl. 04264 SourceLocation getCaretLocation() const; 04265 const Stmt *getBody() const; 04266 Stmt *getBody(); 04267 04268 SourceRange getSourceRange() const LLVM_READONLY { 04269 return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 04270 } 04271 04272 /// getFunctionType - Return the underlying function type for this block. 04273 const FunctionProtoType *getFunctionType() const; 04274 04275 static bool classof(const Stmt *T) { 04276 return T->getStmtClass() == BlockExprClass; 04277 } 04278 static bool classof(const BlockExpr *) { return true; } 04279 04280 // Iterators 04281 child_range children() { return child_range(); } 04282 }; 04283 04284 /// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] 04285 /// This AST node provides support for reinterpreting a type to another 04286 /// type of the same size. 04287 class AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr? 04288 private: 04289 Stmt *SrcExpr; 04290 SourceLocation BuiltinLoc, RParenLoc; 04291 04292 friend class ASTReader; 04293 friend class ASTStmtReader; 04294 explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} 04295 04296 public: 04297 AsTypeExpr(Expr* SrcExpr, QualType DstType, 04298 ExprValueKind VK, ExprObjectKind OK, 04299 SourceLocation BuiltinLoc, SourceLocation RParenLoc) 04300 : Expr(AsTypeExprClass, DstType, VK, OK, 04301 DstType->isDependentType(), 04302 DstType->isDependentType() || SrcExpr->isValueDependent(), 04303 (DstType->isInstantiationDependentType() || 04304 SrcExpr->isInstantiationDependent()), 04305 (DstType->containsUnexpandedParameterPack() || 04306 SrcExpr->containsUnexpandedParameterPack())), 04307 SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 04308 04309 /// getSrcExpr - Return the Expr to be converted. 04310 Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); } 04311 04312 /// getBuiltinLoc - Return the location of the __builtin_astype token. 04313 SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 04314 04315 /// getRParenLoc - Return the location of final right parenthesis. 04316 SourceLocation getRParenLoc() const { return RParenLoc; } 04317 04318 SourceRange getSourceRange() const LLVM_READONLY { 04319 return SourceRange(BuiltinLoc, RParenLoc); 04320 } 04321 04322 static bool classof(const Stmt *T) { 04323 return T->getStmtClass() == AsTypeExprClass; 04324 } 04325 static bool classof(const AsTypeExpr *) { return true; } 04326 04327 // Iterators 04328 child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } 04329 }; 04330 04331 /// PseudoObjectExpr - An expression which accesses a pseudo-object 04332 /// l-value. A pseudo-object is an abstract object, accesses to which 04333 /// are translated to calls. The pseudo-object expression has a 04334 /// syntactic form, which shows how the expression was actually 04335 /// written in the source code, and a semantic form, which is a series 04336 /// of expressions to be executed in order which detail how the 04337 /// operation is actually evaluated. Optionally, one of the semantic 04338 /// forms may also provide a result value for the expression. 04339 /// 04340 /// If any of the semantic-form expressions is an OpaqueValueExpr, 04341 /// that OVE is required to have a source expression, and it is bound 04342 /// to the result of that source expression. Such OVEs may appear 04343 /// only in subsequent semantic-form expressions and as 04344 /// sub-expressions of the syntactic form. 04345 /// 04346 /// PseudoObjectExpr should be used only when an operation can be 04347 /// usefully described in terms of fairly simple rewrite rules on 04348 /// objects and functions that are meant to be used by end-developers. 04349 /// For example, under the Itanium ABI, dynamic casts are implemented 04350 /// as a call to a runtime function called __dynamic_cast; using this 04351 /// class to describe that would be inappropriate because that call is 04352 /// not really part of the user-visible semantics, and instead the 04353 /// cast is properly reflected in the AST and IR-generation has been 04354 /// taught to generate the call as necessary. In contrast, an 04355 /// Objective-C property access is semantically defined to be 04356 /// equivalent to a particular message send, and this is very much 04357 /// part of the user model. The name of this class encourages this 04358 /// modelling design. 04359 class PseudoObjectExpr : public Expr { 04360 // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions. 04361 // Always at least two, because the first sub-expression is the 04362 // syntactic form. 04363 04364 // PseudoObjectExprBits.ResultIndex - The index of the 04365 // sub-expression holding the result. 0 means the result is void, 04366 // which is unambiguous because it's the index of the syntactic 04367 // form. Note that this is therefore 1 higher than the value passed 04368 // in to Create, which is an index within the semantic forms. 04369 // Note also that ASTStmtWriter assumes this encoding. 04370 04371 Expr **getSubExprsBuffer() { return reinterpret_cast<Expr**>(this + 1); } 04372 const Expr * const *getSubExprsBuffer() const { 04373 return reinterpret_cast<const Expr * const *>(this + 1); 04374 } 04375 04376 friend class ASTStmtReader; 04377 04378 PseudoObjectExpr(QualType type, ExprValueKind VK, 04379 Expr *syntactic, ArrayRef<Expr*> semantic, 04380 unsigned resultIndex); 04381 04382 PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs); 04383 04384 unsigned getNumSubExprs() const { 04385 return PseudoObjectExprBits.NumSubExprs; 04386 } 04387 04388 public: 04389 /// NoResult - A value for the result index indicating that there is 04390 /// no semantic result. 04391 enum { NoResult = ~0U }; 04392 04393 static PseudoObjectExpr *Create(ASTContext &Context, Expr *syntactic, 04394 ArrayRef<Expr*> semantic, 04395 unsigned resultIndex); 04396 04397 static PseudoObjectExpr *Create(ASTContext &Context, EmptyShell shell, 04398 unsigned numSemanticExprs); 04399 04400 /// Return the syntactic form of this expression, i.e. the 04401 /// expression it actually looks like. Likely to be expressed in 04402 /// terms of OpaqueValueExprs bound in the semantic form. 04403 Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; } 04404 const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; } 04405 04406 /// Return the index of the result-bearing expression into the semantics 04407 /// expressions, or PseudoObjectExpr::NoResult if there is none. 04408 unsigned getResultExprIndex() const { 04409 if (PseudoObjectExprBits.ResultIndex == 0) return NoResult; 04410 return PseudoObjectExprBits.ResultIndex - 1; 04411 } 04412 04413 /// Return the result-bearing expression, or null if there is none. 04414 Expr *getResultExpr() { 04415 if (PseudoObjectExprBits.ResultIndex == 0) 04416 return 0; 04417 return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex]; 04418 } 04419 const Expr *getResultExpr() const { 04420 return const_cast<PseudoObjectExpr*>(this)->getResultExpr(); 04421 } 04422 04423 unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; } 04424 04425 typedef Expr * const *semantics_iterator; 04426 typedef const Expr * const *const_semantics_iterator; 04427 semantics_iterator semantics_begin() { 04428 return getSubExprsBuffer() + 1; 04429 } 04430 const_semantics_iterator semantics_begin() const { 04431 return getSubExprsBuffer() + 1; 04432 } 04433 semantics_iterator semantics_end() { 04434 return getSubExprsBuffer() + getNumSubExprs(); 04435 } 04436 const_semantics_iterator semantics_end() const { 04437 return getSubExprsBuffer() + getNumSubExprs(); 04438 } 04439 Expr *getSemanticExpr(unsigned index) { 04440 assert(index + 1 < getNumSubExprs()); 04441 return getSubExprsBuffer()[index + 1]; 04442 } 04443 const Expr *getSemanticExpr(unsigned index) const { 04444 return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index); 04445 } 04446 04447 SourceLocation getExprLoc() const LLVM_READONLY { 04448 return getSyntacticForm()->getExprLoc(); 04449 } 04450 SourceRange getSourceRange() const LLVM_READONLY { 04451 return getSyntacticForm()->getSourceRange(); 04452 } 04453 04454 child_range children() { 04455 Stmt **cs = reinterpret_cast<Stmt**>(getSubExprsBuffer()); 04456 return child_range(cs, cs + getNumSubExprs()); 04457 } 04458 04459 static bool classof(const Stmt *T) { 04460 return T->getStmtClass() == PseudoObjectExprClass; 04461 } 04462 static bool classof(const PseudoObjectExpr *) { return true; } 04463 }; 04464 04465 /// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, 04466 /// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the 04467 /// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>. 04468 /// All of these instructions take one primary pointer and at least one memory 04469 /// order. 04470 class AtomicExpr : public Expr { 04471 public: 04472 enum AtomicOp { 04473 #define BUILTIN(ID, TYPE, ATTRS) 04474 #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID, 04475 #include "clang/Basic/Builtins.def" 04476 // Avoid trailing comma 04477 BI_First = 0 04478 }; 04479 04480 private: 04481 enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR }; 04482 Stmt* SubExprs[END_EXPR]; 04483 unsigned NumSubExprs; 04484 SourceLocation BuiltinLoc, RParenLoc; 04485 AtomicOp Op; 04486 04487 friend class ASTStmtReader; 04488 04489 public: 04490 AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, QualType t, 04491 AtomicOp op, SourceLocation RP); 04492 04493 /// \brief Determine the number of arguments the specified atomic builtin 04494 /// should have. 04495 static unsigned getNumSubExprs(AtomicOp Op); 04496 04497 /// \brief Build an empty AtomicExpr. 04498 explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { } 04499 04500 Expr *getPtr() const { 04501 return cast<Expr>(SubExprs[PTR]); 04502 } 04503 Expr *getOrder() const { 04504 return cast<Expr>(SubExprs[ORDER]); 04505 } 04506 Expr *getVal1() const { 04507 if (Op == AO__c11_atomic_init) 04508 return cast<Expr>(SubExprs[ORDER]); 04509 assert(NumSubExprs > VAL1); 04510 return cast<Expr>(SubExprs[VAL1]); 04511 } 04512 Expr *getOrderFail() const { 04513 assert(NumSubExprs > ORDER_FAIL); 04514 return cast<Expr>(SubExprs[ORDER_FAIL]); 04515 } 04516 Expr *getVal2() const { 04517 if (Op == AO__atomic_exchange) 04518 return cast<Expr>(SubExprs[ORDER_FAIL]); 04519 assert(NumSubExprs > VAL2); 04520 return cast<Expr>(SubExprs[VAL2]); 04521 } 04522 Expr *getWeak() const { 04523 assert(NumSubExprs > WEAK); 04524 return cast<Expr>(SubExprs[WEAK]); 04525 } 04526 04527 AtomicOp getOp() const { return Op; } 04528 unsigned getNumSubExprs() { return NumSubExprs; } 04529 04530 Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 04531 04532 bool isVolatile() const { 04533 return getPtr()->getType()->getPointeeType().isVolatileQualified(); 04534 } 04535 04536 bool isCmpXChg() const { 04537 return getOp() == AO__c11_atomic_compare_exchange_strong || 04538 getOp() == AO__c11_atomic_compare_exchange_weak || 04539 getOp() == AO__atomic_compare_exchange || 04540 getOp() == AO__atomic_compare_exchange_n; 04541 } 04542 04543 SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 04544 SourceLocation getRParenLoc() const { return RParenLoc; } 04545 04546 SourceRange getSourceRange() const LLVM_READONLY { 04547 return SourceRange(BuiltinLoc, RParenLoc); 04548 } 04549 static bool classof(const Stmt *T) { 04550 return T->getStmtClass() == AtomicExprClass; 04551 } 04552 static bool classof(const AtomicExpr *) { return true; } 04553 04554 // Iterators 04555 child_range children() { 04556 return child_range(SubExprs, SubExprs+NumSubExprs); 04557 } 04558 }; 04559 } // end namespace clang 04560 04561 #endif