Expr.cpp revision b8da98a2182d2c69c72136b9a9ebabd4694f3d6b
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.cpp - Expression AST Node Implementation --------------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements the Expr class and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar#include "clang/AST/Expr.h" 150979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor#include "clang/AST/ExprCXX.h" 16a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/APValue.h" 172eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner#include "clang/AST/ASTContext.h" 18a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/DeclObjC.h" 1998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor#include "clang/AST/DeclCXX.h" 20aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 2119cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h" 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/StmtVisitor.h" 2308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Lex/LiteralSupport.h" 2408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Lex/Lexer.h" 257a614d8380297fcd2bc23986241905d97222948cRichard Smith#include "clang/Sema/SemaDiagnostic.h" 261b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 2708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Basic/SourceManager.h" 28da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h" 29cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor#include "llvm/Support/ErrorHandling.h" 303a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson#include "llvm/Support/raw_ostream.h" 31ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm> 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 342b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// isKnownToHaveBooleanValue - Return true if this is an integer expression 352b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// that is known to return 0 or 1. This happens for _Bool/bool expressions 362b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// but also int expressions which are produced by things like comparisons in 372b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// C. 382b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerbool Expr::isKnownToHaveBooleanValue() const { 39f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 40f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 412b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // If this value has _Bool type, it is obvious 0/1. 42f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (E->getType()->isBooleanType()) return true; 43c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // If this is a non-scalar-integer type, we don't care enough to try. 44f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!E->getType()->isIntegralOrEnumerationType()) return false; 45c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 46f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { 472b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (UO->getOpcode()) { 482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: 492b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return UO->getSubExpr()->isKnownToHaveBooleanValue(); 502b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: 512b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 522b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 532b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 54c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 556907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // Only look through implicit casts. If the user writes 566907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // '(int) (a && b)' treat it as an arbitrary int. 57f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) 582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CE->getSubExpr()->isKnownToHaveBooleanValue(); 59c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 612b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (BO->getOpcode()) { 622b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: return false; 632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: // Relational operators. 642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: 652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: 662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: 672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: // Equality operators. 682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: 692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: // AND operator. 702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: // Logical OR operator. 712b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return true; 72c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: // Bitwise AND operator. 742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: // Bitwise XOR operator. 752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: // Bitwise OR operator. 762b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // Handle things like (x==2)|(y==12). 772b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getLHS()->isKnownToHaveBooleanValue() && 782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner BO->getRHS()->isKnownToHaveBooleanValue(); 79c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: 822b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getRHS()->isKnownToHaveBooleanValue(); 832b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 842b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 85c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 86f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) 872b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CO->getTrueExpr()->isKnownToHaveBooleanValue() && 882b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner CO->getFalseExpr()->isKnownToHaveBooleanValue(); 89c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 902b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 912b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner} 922b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner 9363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// Amusing macro metaprogramming hack: check whether a class provides 9463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// a more specific implementation of getExprLoc(). 9563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallnamespace { 9663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class provides a custom 9763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// implementation of getExprLoc. 9863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E, class T> 9963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 10063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (T::*v)() const) { 10163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return static_cast<const E*>(expr)->getExprLoc(); 10263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 10463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class doesn't provide 10563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// a custom implementation of getExprLoc. Overload resolution 10663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// should pick it over the implementation above because it's 10763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// more specialized according to function template partial ordering. 10863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E> 10963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 11063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (Expr::*v)() const) { 11163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return static_cast<const E*>(expr)->getSourceRange().getBegin(); 11263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 11463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 11563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallSourceLocation Expr::getExprLoc() const { 11663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall switch (getStmtClass()) { 11763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 11863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(type) 11963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define STMT(type, base) \ 12063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: llvm_unreachable(#type " is not an Expr"); break; 12163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define EXPR(type, base) \ 12263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); 12363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#include "clang/AST/StmtNodes.inc" 12463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 12563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall llvm_unreachable("unknown statement kind"); 12663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return SourceLocation(); 12763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 12863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// \brief Compute the type-, value-, and instantiation-dependence of a 134561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor/// declaration reference 135d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor/// based on the declaration being referenced. 136d967e31ee796efff24b84b704a063634f6b55627Douglas Gregorstatic void computeDeclRefDependence(NamedDecl *D, QualType T, 137d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool &TypeDependent, 138561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &ValueDependent, 139561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 140d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = false; 141d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = false; 142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = false; 1430da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 1440da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 1450da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An id-expression is type-dependent if it contains: 1460da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 147c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // and 1480da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 1490da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 1500da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An identifier is value-dependent if it is: 151d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 1520da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - an identifier that was declared with dependent type 1530da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a name declared with a dependent type, 154d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (T->isDependentType()) { 155d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 156d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 157561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 158d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 159561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (T->isInstantiationDependentType()) { 160561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1610da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 162d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 1630da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a conversion-function-id that specifies a dependent type 164d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (D->getDeclName().getNameKind() 165561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor == DeclarationName::CXXConversionFunctionName) { 166561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualType T = D->getDeclName().getCXXNameType(); 167561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isDependentType()) { 168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TypeDependent = true; 169561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ValueDependent = true; 170561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 171561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return; 172561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 173561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 174561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (T->isInstantiationDependentType()) 175561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1760da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 177561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1780da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - the name of a non-type template parameter, 179d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<NonTypeTemplateParmDecl>(D)) { 180d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 181561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 182d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 183d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 184d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 1850da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a constant with integral or enumeration type and is 1860da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // initialized with an expression that is value-dependent. 187d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (VarDecl *Var = dyn_cast<VarDecl>(D)) { 1882ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (Var->getType()->isIntegralOrEnumerationType() && 189501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor Var->getType().getCVRQualifiers() == Qualifiers::Const) { 19031310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl if (const Expr *Init = Var->getAnyInitializer()) 191561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Init->isValueDependent()) { 192d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 193561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 194561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 195bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor } 196d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 197bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 198bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 199bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 200bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor else if (Var->isStaticDataMember() && 201561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Var->getDeclContext()->isDependentContext()) { 202d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 203561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 204561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 205d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 206d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 207d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 208d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 209bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 210bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 211bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 212d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) { 213d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 214561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 215d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 216d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 217d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor} 218d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 219d967e31ee796efff24b84b704a063634f6b55627Douglas Gregorvoid DeclRefExpr::computeDependence() { 220d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool TypeDependent = false; 221d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool ValueDependent = false; 222561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 223561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor computeDeclRefDependence(getDecl(), getType(), TypeDependent, ValueDependent, 224561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent); 225d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 226d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 227d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An id-expression is type-dependent if it contains: 228d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 229d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // and 230d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 231d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 232d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An identifier is value-dependent if it is: 233d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (!TypeDependent && !ValueDependent && 234d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor hasExplicitTemplateArgs() && 235d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TemplateSpecializationType::anyDependentTemplateArguments( 236d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor getTemplateArgs(), 237561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor getNumTemplateArgs(), 238561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent)) { 239d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 240d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 241561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 242d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 243d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 244d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.TypeDependent = TypeDependent; 245d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.ValueDependent = ValueDependent; 246561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = InstantiationDependent; 247d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 24810738d36b150aa65206890c1c845cdba076e4200Douglas Gregor // Is the declaration a parameter pack? 249d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (getDecl()->isParameterPack()) 2501fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor} 2520da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 2533aa8140bde5b9bedf13e46ec0a668daa54814196Chandler CarruthDeclRefExpr::DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 2542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 2553aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 2562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 257f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK) 258561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 259cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth D(D), Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { 260cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0; 2617e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth if (QualifierLoc) 2626857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth getInternalQualifierLoc() = QualifierLoc; 2633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = FoundD ? 1 : 0; 2643aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 2653aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth getInternalFoundDecl() = FoundD; 266cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasExplicitTemplateArgs = TemplateArgs ? 1 : 0; 267561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TemplateArgs) { 268561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 269561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 270561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 271561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor getExplicitTemplateArgs().initializeFrom(*TemplateArgs, Dependent, 272561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent, 273561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ContainsUnexpandedParameterPack); 274561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 275561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(true); 276561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 277b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer DeclRefExprBits.HadMultipleCandidates = 0; 278b8da98a2182d2c69c72136b9a9ebabd4694f3d6bBenjamin Kramer 2792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara computeDependence(); 2802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 2812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 282a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 28340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 284dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 285a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 2860da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 287f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 2883aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 2890da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs) { 29040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return Create(Context, QualifierLoc, D, 2912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(D->getDeclName(), NameLoc), 2923aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth T, VK, FoundD, TemplateArgs); 2932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 2942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2952577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 29640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 2982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T, 300f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 3013aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 3022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 3033aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth // Filter out cases where the found Decl is the same as the value refenenced. 3043aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (D == FoundD) 3053aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth FoundD = 0; 3063aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 307a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor std::size_t Size = sizeof(DeclRefExpr); 30840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc != 0) 3096857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 3103aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (FoundD) 3113aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 312d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 313b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis Size += ASTTemplateArgumentListInfo::sizeFor(*TemplateArgs); 3143aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 3153248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 3163aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return new (Mem) DeclRefExpr(QualifierLoc, D, NameInfo, FoundD, TemplateArgs, 3173aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth T, VK); 318a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 319a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3203aa8140bde5b9bedf13e46ec0a668daa54814196Chandler CarruthDeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, 321def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasQualifier, 3223aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 323def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasExplicitTemplateArgs, 324663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis unsigned NumTemplateArgs) { 325663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis std::size_t Size = sizeof(DeclRefExpr); 326663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (HasQualifier) 3276857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth Size += sizeof(NestedNameSpecifierLoc); 3283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (HasFoundDecl) 3293aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth Size += sizeof(NamedDecl *); 330def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor if (HasExplicitTemplateArgs) 331b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis Size += ASTTemplateArgumentListInfo::sizeFor(NumTemplateArgs); 3323aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 3333248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 334663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis return new (Mem) DeclRefExpr(EmptyShell()); 335663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis} 336663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 337a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorSourceRange DeclRefExpr::getSourceRange() const { 3382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange R = getNameInfo().getSourceRange(); 339a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (hasQualifier()) 34040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor R.setBegin(getQualifierLoc().getBeginLoc()); 341096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 342a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setEnd(getRAngleLoc()); 343a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return R; 344a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 345a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3463a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined 3473a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead. 348848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlssonstd::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 349848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson ASTContext &Context = CurrentDecl->getASTContext(); 350848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson 3513a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { 352848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) 3533a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return FD->getNameAsString(); 3543a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3553a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 3563a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 3573a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3583a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 359848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) 3603a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << "virtual "; 3614eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (MD->isStatic()) 3624eadcc569223135e13353c9381b448986e3f7053Sam Weinig Out << "static "; 3633a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3643a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3653a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson PrintingPolicy Policy(Context.getLangOptions()); 3663a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3673a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Proto = FD->getQualifiedNameAsString(Policy); 3683a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 369183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *AFT = FD->getType()->getAs<FunctionType>(); 3703a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const FunctionProtoType *FT = 0; 3713a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->hasWrittenPrototype()) 3723a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FT = dyn_cast<FunctionProtoType>(AFT); 3733a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += "("; 3753a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT) { 3763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_string_ostream POut(Proto); 3773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { 3783a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (i) POut << ", "; 3793a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Param; 3803a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy); 3813a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << Param; 3823a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3833a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3843a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT->isVariadic()) { 3853a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->getNumParams()) POut << ", "; 3863a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << "..."; 3873a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3883a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3893a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += ")"; 3903a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3914eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 3924eadcc569223135e13353c9381b448986e3f7053Sam Weinig Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers()); 3934eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasConst()) 3944eadcc569223135e13353c9381b448986e3f7053Sam Weinig Proto += " const"; 3954eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasVolatile()) 3964eadcc569223135e13353c9381b448986e3f7053Sam Weinig Proto += " volatile"; 3974eadcc569223135e13353c9381b448986e3f7053Sam Weinig } 3984eadcc569223135e13353c9381b448986e3f7053Sam Weinig 3993a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) 4003a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig AFT->getResultType().getAsStringInternal(Proto, Policy); 4013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << Proto; 4033a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 4053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 4063a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4073a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { 4083a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 4093a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 4103a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << (MD->isInstanceMethod() ? '-' : '+'); 4113a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '['; 412b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 413b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // For incorrect code, there might not be an ObjCInterfaceDecl. Do 414b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // a null check to avoid a crash. 415b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) 416900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer Out << ID; 417b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 4183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCCategoryImplDecl *CID = 419900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) 420900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer Out << '(' << CID << ')'; 421900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 4223a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ' '; 4233a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getSelector().getAsString(); 4243a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ']'; 4253a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 4273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 4283a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4293a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { 4303a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. 4313a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return "top level"; 4323a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4333a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return ""; 4343a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 4353a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisvoid APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { 4379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (hasAllocation()) 4389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis C.Deallocate(pVal); 4399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis BitWidth = Val.getBitWidth(); 4419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = Val.getNumWords(); 4429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis const uint64_t* Words = Val.getRawData(); 4439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) { 4449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis pVal = new (C) uint64_t[NumWords]; 4459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis std::copy(Words, Words + NumWords, pVal); 4469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } else if (NumWords == 1) 4479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = Words[0]; 4489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 4499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = 0; 4509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 4539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, 4549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) { 4559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(C, V, type, l); 4569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 4599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { 4609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(Empty); 4619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 4649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, 4659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L) { 4669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(C, V, isexact, Type, L); 4679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 4709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { 4719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(Empty); 4729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 474da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 475da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 476da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 477da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 478da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 479ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 480ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 481ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 482da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 483da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 484da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 4855f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, StringRef Str, 4865cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind Kind, bool Pascal, QualType Ty, 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const SourceLocation *Loc, 488a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 4892085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 4902085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 4912085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 4922085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 4933248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 4942085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 49765aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad char *AStrData = new (C, 1) char[Str.size()]; 49865aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad memcpy(AStrData, Str.data(), Str.size()); 4992085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->StrData = AStrData; 50065aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad SL->ByteLength = Str.size(); 5015cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SL->Kind = Kind; 5023e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson SL->IsPascal = Pascal; 5032085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 5042085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 506726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 5072085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 5082085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 509726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 510726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 511673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 512673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 513673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 5143248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 515673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 516673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->StrData = 0; 517673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->ByteLength = 0; 518673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 519673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 520673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 521673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 5225f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid StringLiteral::setString(ASTContext &C, StringRef Str) { 523b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar char *AStrData = new (C, 1) char[Str.size()]; 524b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar memcpy(AStrData, Str.data(), Str.size()); 525673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StrData = AStrData; 526b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar ByteLength = Str.size(); 527673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 528673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 52908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// getLocationOfByte - Return a source location that points to the specified 53008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// byte of this string literal. 53108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 53208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// Strings are amazingly complex. They can be formed from multiple tokens and 53308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// can have escape sequences in them in addition to the usual trigraph and 53408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// escaped newline business. This routine handles this complexity. 53508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 53608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnerSourceLocation StringLiteral:: 53708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnergetLocationOfByte(unsigned ByteNo, const SourceManager &SM, 53808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, const TargetInfo &Target) const { 5395cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor assert(Kind == StringLiteral::Ascii && "This only works for ASCII strings"); 5405cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 54108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Loop over all of the tokens in this string until we find the one that 54208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // contains the byte we're looking for. 54308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNo = 0; 54408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner while (1) { 54508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner assert(TokNo < getNumConcatenated() && "Invalid byte number!"); 54608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokLoc = getStrTokenLoc(TokNo); 54708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 54808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Get the spelling of the string so that we can get the data that makes up 54908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // the string literal, not the identifier for the macro it is potentially 55008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // expanded through. 55108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); 55208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 55308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Re-lex the token to get its length and original spelling. 55408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner std::pair<FileID, unsigned> LocInfo =SM.getDecomposedLoc(StrTokSpellingLoc); 55508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner bool Invalid = false; 5565f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); 55708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (Invalid) 55808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return StrTokSpellingLoc; 55908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 56008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const char *StrData = Buffer.data()+LocInfo.second; 56108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 56208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a langops struct and enable trigraphs. This is sufficient for 56308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // relexing tokens. 56408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner LangOptions LangOpts; 56508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner LangOpts.Trigraphs = true; 56608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 56708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a lexer starting at the beginning of this token. 56808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Lexer TheLexer(StrTokSpellingLoc, Features, Buffer.begin(), StrData, 56908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Buffer.end()); 57008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Token TheTok; 57108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner TheLexer.LexFromRawLexer(TheTok); 57208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 57308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Use the StringLiteralParser to compute the length of the string in bytes. 57408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner StringLiteralParser SLP(&TheTok, 1, SM, Features, Target); 57508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNumBytes = SLP.GetStringLength(); 57608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 57708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // If the byte is in this token, return the location of the byte. 57808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (ByteNo < TokNumBytes || 579935a70c1e76d78985f20d422940280161b941299Hans Wennborg (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) { 58008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); 58108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 58208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Now that we know the offset of the token in the spelling, use the 58308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // preprocessor to get the offset in the original source. 58408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); 58508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 58608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 58708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Move to the next string token. 58808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ++TokNo; 58908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ByteNo -= TokNumBytes; 59008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 59108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner} 59208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 59308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 59408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) { 5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 599b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unknown unary operator"); 6002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: return "++"; 6012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: return "--"; 6022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: return "++"; 6032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: return "--"; 6042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return "&"; 6052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return "*"; 6062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return "+"; 6072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return "-"; 6082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return "~"; 6092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return "!"; 6102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: return "__real"; 6112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: return "__imag"; 6122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: return "__extension__"; 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallUnaryOperatorKind 617bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 618bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 619b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("No unary operator for overloaded function"); 6202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc; 6212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; 6222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return UO_AddrOf; 6232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return UO_Deref; 6242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return UO_Plus; 6252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return UO_Minus; 6262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Tilde: return UO_Not; 6272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Exclaim: return UO_LNot; 628bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 629bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 630bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 631bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 632bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 6332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: case UO_PreInc: return OO_PlusPlus; 6342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: case UO_PreDec: return OO_MinusMinus; 6352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return OO_Amp; 6362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return OO_Star; 6372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return OO_Plus; 6382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return OO_Minus; 6392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return OO_Tilde; 6402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return OO_Exclaim; 641bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 642bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 643bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 644bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 645bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 650cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 651cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 652f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation rparenloc) 653f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(SC, t, VK, OK_Ordinary, 654bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 655bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 656561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 657bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 658898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 660cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[numargs+PREARGS_START+NumPreArgs]; 661b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 662bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != numargs; ++i) { 663bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 664bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 665bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 666bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 667561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 668561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 669bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 670bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 671bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 672cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START+NumPreArgs] = args[i]; 673bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 674668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 675cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 676b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 677b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 678e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 679668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 680f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation rparenloc) 681f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CallExprClass, t, VK, OK_Ordinary, 682bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 683bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 684561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor fn->isInstantiationDependent(), 685bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 686898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 687668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 688cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[numargs+PREARGS_START]; 68977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 690bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != numargs; ++i) { 691bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 692bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 693bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 694bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 695561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 696561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 697bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 698bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 699bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 700cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START] = args[i]; 701bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 702668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 703cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7071eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 709bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // FIXME: Why do we allocate this? 710cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START]; 711cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 712cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne} 713cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 714cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, 715cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne EmptyShell Empty) 716cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 717cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // FIXME: Why do we allocate this? 718cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs]; 719cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 7201f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 7211f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 722d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() { 723e8683d6d389def2fce229325435ba3c2b3f75492John McCall Expr *CEE = getCallee()->IgnoreParenImpCasts(); 7241ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 7251ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor while (SubstNonTypeTemplateParmExpr *NTTP 7261ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) { 7271ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor CEE = NTTP->getReplacement()->IgnoreParenCasts(); 7281ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor } 7291ddc9c4674b7c737ec65241a531df8c64e40b0a9Douglas Gregor 730200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl // If we're calling a dereference, look at the pointer instead. 731200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { 732200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BO->isPtrMemOp()) 733200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = BO->getRHS()->IgnoreParenCasts(); 734200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { 735200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (UO->getOpcode() == UO_Deref) 736200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = UO->getSubExpr()->IgnoreParenCasts(); 737200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } 7386346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 739d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return DRE->getDecl(); 740cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) 741cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes return ME->getMemberDecl(); 742a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 743a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 744a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 745a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 746d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() { 747caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); 748d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes} 749d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 750d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 751d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 752d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 7538189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 754d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 755d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 757d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 758d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 759d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 760d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 761d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 762d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 763d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 764cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs = getNumPreArgs(); 765cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; 766d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 767cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i) 768d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 769d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 770cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = getNumArgs()+PREARGS_START+NumPreArgs; 771cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne i != NumArgs+PREARGS_START+NumPreArgs; ++i) 772d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77488c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 775d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 776d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 777d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 778d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 779cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 780cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 7814ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned CallExpr::isBuiltinCall(const ASTContext &Context) const { 782c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 7831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // function. As a result, we try and obtain the DeclRefExpr from the 784c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 785c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 786c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 787cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 7881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 789c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 790c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 791cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 793bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 794bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 795cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 7961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7974fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 7984fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 7994fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 8007814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor return FDecl->getBuiltinID(); 801cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 802bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 8036dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 8046dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 8056217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 8066dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 8076217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 8086dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 809864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) 810864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // This should never be overloaded and so should never return null. 811864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall CalleeType = Expr::findBoundMemberType(getCallee()); 8125291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 813864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall const FunctionType *FnType = CalleeType->castAs<FunctionType>(); 8146dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 8156dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 816cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 8172882eca5a184c78f793188083f6ce539740a5cf2John McCallSourceRange CallExpr::getSourceRange() const { 8182882eca5a184c78f793188083f6ce539740a5cf2John McCall if (isa<CXXOperatorCallExpr>(this)) 8192882eca5a184c78f793188083f6ce539740a5cf2John McCall return cast<CXXOperatorCallExpr>(this)->getSourceRange(); 8202882eca5a184c78f793188083f6ce539740a5cf2John McCall 8212882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceLocation begin = getCallee()->getLocStart(); 8222882eca5a184c78f793188083f6ce539740a5cf2John McCall if (begin.isInvalid() && getNumArgs() > 0) 8232882eca5a184c78f793188083f6ce539740a5cf2John McCall begin = getArg(0)->getLocStart(); 8242882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceLocation end = getRParenLoc(); 8252882eca5a184c78f793188083f6ce539740a5cf2John McCall if (end.isInvalid() && getNumArgs() > 0) 8262882eca5a184c78f793188083f6ce539740a5cf2John McCall end = getArg(getNumArgs() - 1)->getLocEnd(); 8272882eca5a184c78f793188083f6ce539740a5cf2John McCall return SourceRange(begin, end); 8282882eca5a184c78f793188083f6ce539740a5cf2John McCall} 8292882eca5a184c78f793188083f6ce539740a5cf2John McCall 830c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, 8318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, 832c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TypeSourceInfo *tsi, 833c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 8348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 8358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 8368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 837c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt sizeof(OffsetOfNode) * numComps + 8388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 8398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 8408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps, 8418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor exprsPtr, numExprs, RParenLoc); 8428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 8438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 8448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, 8458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned numComps, unsigned numExprs) { 8468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 8478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(OffsetOfNode) * numComps + 8488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 8498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(numComps, numExprs); 8508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 8518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 852c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, 8538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 854c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 8558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 8568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) 857f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, 858f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent=*/false, 859bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent=*/tsi->getType()->isDependentType(), 860561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tsi->getType()->isInstantiationDependentType(), 861bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tsi->getType()->containsUnexpandedParameterPack()), 862c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), 863c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NumComps(numComps), NumExprs(numExprs) 8648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{ 8658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numComps; ++i) { 8668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setComponent(i, compsPtr[i]); 8678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 868c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numExprs; ++i) { 870bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprsPtr[i]->isTypeDependent() || exprsPtr[i]->isValueDependent()) 871bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 872bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprsPtr[i]->containsUnexpandedParameterPack()) 873bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 874bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 8758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setIndexExpr(i, exprsPtr[i]); 8768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 8778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 8788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 8798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { 8808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field || getKind() == Identifier); 8818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (getKind() == Field) 8828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getField()->getIdentifier(); 883c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); 8858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 8868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 8871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 88840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 889f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 890161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair founddecl, 8912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo nameinfo, 892d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 893f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, 894f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind vk, 895f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind ok) { 89683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 8976bb8017bb9e828d118e15e59d71c66bba323c364John McCall 89840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor bool hasQualOrFound = (QualifierLoc || 899161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getDecl() != memberdecl || 900161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getAccess() != memberdecl->getAccess()); 9016bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) 9026bb8017bb9e828d118e15e59d71c66bba323c364John McCall Size += sizeof(MemberNameQualifier); 9031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 904d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 905b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis Size += ASTTemplateArgumentListInfo::sizeFor(*targs); 9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9073248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); 908f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, 909f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ty, vk, ok); 9106bb8017bb9e828d118e15e59d71c66bba323c364John McCall 9116bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) { 91240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor // FIXME: Wrong. We should be looking at the member declaration we found. 91340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) { 9146bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setValueDependent(true); 9156bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setTypeDependent(true); 916561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 917561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 918561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (QualifierLoc && 919561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) 920561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 921561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 9226bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasQualifierOrFoundDecl = true; 9236bb8017bb9e828d118e15e59d71c66bba323c364John McCall 9246bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *NQ = E->getMemberQualifier(); 92540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NQ->QualifierLoc = QualifierLoc; 9266bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->FoundDecl = founddecl; 9276bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 9286bb8017bb9e828d118e15e59d71c66bba323c364John McCall 9296bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (targs) { 930561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool Dependent = false; 931561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 932561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool ContainsUnexpandedParameterPack = false; 9336bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasExplicitTemplateArgumentList = true; 934561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->getExplicitTemplateArgs().initializeFrom(*targs, Dependent, 935561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent, 936561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ContainsUnexpandedParameterPack); 937561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (InstantiationDependent) 938561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->setInstantiationDependent(true); 9396bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 9406bb8017bb9e828d118e15e59d71c66bba323c364John McCall 9416bb8017bb9e828d118e15e59d71c66bba323c364John McCall return E; 94283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 94383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 94475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas GregorSourceRange MemberExpr::getSourceRange() const { 94575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceLocation StartLoc; 94675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (isImplicitAccess()) { 94775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (hasQualifier()) 94875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor StartLoc = getQualifierLoc().getBeginLoc(); 94975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor else 95075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor StartLoc = MemberLoc; 95175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } else { 95275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor // FIXME: We don't want this to happen. Rather, we should be able to 95375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor // detect all kinds of implicit accesses more cleanly. 95475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor StartLoc = getBase()->getLocStart(); 95575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (StartLoc.isInvalid()) 95675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor StartLoc = MemberLoc; 95775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 95875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 95975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceLocation EndLoc = 96075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor HasExplicitTemplateArgumentList? getRAngleLoc() 96175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor : getMemberNameInfo().getEndLoc(); 96275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 96375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return SourceRange(StartLoc, EndLoc); 96475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 96575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 9661d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCallvoid CastExpr::CheckCastConsistency() const { 9671d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall switch (getCastKind()) { 9681d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBase: 9691d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UncheckedDerivedToBase: 9701d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_DerivedToBaseMemberPointer: 9711d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerived: 9721d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BaseToDerivedMemberPointer: 9731d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 9741d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 9751d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 9761d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 9771d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 9781d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isPointerType()); 9791d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 9801d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 9811d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 9821d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType()); 9831d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isBlockPointerType()); 9841d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 9851d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 9861d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BitCast: 9871d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Arbitrary casts to C pointer types count as bitcasts. 9881d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // Otherwise, we should only have block and ObjC pointer casts 9891d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // here if they stay within the type kind. 9901d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall if (!getType()->isPointerType()) { 9911d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isObjCObjectPointerType() == 9921d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isObjCObjectPointerType()); 9931d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType() == 9941d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall getSubExpr()->getType()->isBlockPointerType()); 9951d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 9961d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 9971d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 9981d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_AnyPointerToBlockPointerCast: 9991d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getType()->isBlockPointerType()); 10001d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(getSubExpr()->getType()->isAnyPointerType() && 10011d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall !getSubExpr()->getType()->isBlockPointerType()); 10021d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 10031d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 10041d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall // These should not have an inheritance path. 10051d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dynamic: 10061d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToUnion: 10071d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ArrayToPointerDecay: 10081d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FunctionToPointerDecay: 10091d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToMemberPointer: 10101d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NullToPointer: 10111d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ConstructorConversion: 10121d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToPointer: 10131d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToIntegral: 10141d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ToVoid: 10151d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_VectorSplat: 10161d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralCast: 10171d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToFloating: 10181d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToIntegral: 10191d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingCast: 10201d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_ObjCObjectLValueCast: 10211d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingRealToComplex: 10221d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToReal: 10231d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexCast: 10241d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToIntegralComplex: 10251d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralRealToComplex: 10261d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToReal: 10271d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexCast: 10281d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToFloatingComplex: 102933e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 103033e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 103133e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 103233e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 10331d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 10341d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall goto CheckNoBasePath; 10351d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 10361d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_Dependent: 10371d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueToRValue: 10381d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_GetObjCProperty: 10391d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_NoOp: 10401d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_PointerToBoolean: 10411d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralToBoolean: 10421d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingToBoolean: 10431d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_MemberPointerToBoolean: 10441d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_FloatingComplexToBoolean: 10451d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_IntegralComplexToBoolean: 10461d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_LValueBitCast: // -> bool& 10471d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_UserDefinedConversion: // operator bool() 10481d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall CheckNoBasePath: 10491d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 10501d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall break; 10511d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } 10521d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall} 10531d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall 1054f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 1055f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 1056daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 1057daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "Dependent"; 10582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BitCast: 1059f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 10602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_LValueBitCast: 1061e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor return "LValueBitCast"; 10620ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 10630ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall return "LValueToRValue"; 1064f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall case CK_GetObjCProperty: 1065f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return "GetObjCProperty"; 10662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NoOp: 1067f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 10682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerived: 106911de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson return "BaseToDerived"; 10702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBase: 1071f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 10722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UncheckedDerivedToBase: 107323cba801e11b03929c44f8cf54578305963a3476John McCall return "UncheckedDerivedToBase"; 10742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_Dynamic: 1075f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 10762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToUnion: 1077f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 10782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ArrayToPointerDecay: 1079f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 10802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FunctionToPointerDecay: 1081f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 10822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NullToMemberPointer: 1083f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 1084404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 1085404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall return "NullToPointer"; 10862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerivedMemberPointer: 1087f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 10882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBaseMemberPointer: 10891a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson return "DerivedToBaseMemberPointer"; 10902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UserDefinedConversion: 1091f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 10922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ConstructorConversion: 1093f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 10942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToPointer: 10957f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "IntegralToPointer"; 10962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_PointerToIntegral: 10977f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "PointerToIntegral"; 1098daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 1099daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "PointerToBoolean"; 11002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToVoid: 1101ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson return "ToVoid"; 11022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_VectorSplat: 110316a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson return "VectorSplat"; 11042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralCast: 110582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralCast"; 1106daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 1107daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "IntegralToBoolean"; 11082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToFloating: 110982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralToFloating"; 11102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingToIntegral: 111182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "FloatingToIntegral"; 11122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingCast: 1113c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer return "FloatingCast"; 1114daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 1115daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "FloatingToBoolean"; 11162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_MemberPointerToBoolean: 1117bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson return "MemberPointerToBoolean"; 11181d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_CPointerToObjCPointerCast: 11191d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "CPointerToObjCPointerCast"; 11201d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall case CK_BlockPointerToObjCPointerCast: 11211d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return "BlockPointerToObjCPointerCast"; 11222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_AnyPointerToBlockPointerCast: 11233b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian return "AnyPointerToBlockPointerCast"; 11242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ObjCObjectLValueCast: 1125569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return "ObjCObjectLValueCast"; 11262bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 11272bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingRealToComplex"; 1128f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 1129f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToReal"; 1130f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToBoolean: 1131f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToBoolean"; 11322bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 11332bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingComplexCast"; 1134f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 1135f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToIntegralComplex"; 11362bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 11372bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralRealToComplex"; 1138f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 1139f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToReal"; 1140f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToBoolean: 1141f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToBoolean"; 11422bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 11432bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralComplexCast"; 1144f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 1145f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToFloatingComplex"; 114633e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCConsumeObject: 114733e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCConsumeObject"; 114833e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCProduceObject: 114933e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCProduceObject"; 115033e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCReclaimReturnedObject: 115133e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCReclaimReturnedObject"; 115233e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall case CK_ARCExtendBlockObject: 115333e56f3273457bfa22c7c50bc46cf5a18216863dJohn McCall return "ARCCExtendBlockObject"; 1154f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11562bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall llvm_unreachable("Unhandled cast kind!"); 1157f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return 0; 1158f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 1159f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 11606eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() { 11616eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *SubExpr = 0; 11626eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor CastExpr *E = this; 11636eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor do { 11646eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = E->getSubExpr(); 116503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 116603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor // Skip through reference binding to temporary. 116703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 116803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(SubExpr)) 116903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor SubExpr = Materialize->GetTemporaryExpr(); 117003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 11716eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Skip any temporary bindings; they're implicit. 11726eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) 11736eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = Binder->getSubExpr(); 1174c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11756eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Conversions by constructor and conversion functions have a 11766eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // subexpression describing the call; strip it off. 11772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (E->getCastKind() == CK_ConstructorConversion) 11786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); 11792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall else if (E->getCastKind() == CK_UserDefinedConversion) 11806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); 1181c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // If the subexpression we're left with is an implicit cast, look 11836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // through that, too. 1184c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); 1185c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11866eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return SubExpr; 11876eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 11886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 1189f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCXXBaseSpecifier **CastExpr::path_buffer() { 1190f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall switch (getStmtClass()) { 1191f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define ABSTRACT_STMT(x) 1192f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define CASTEXPR(Type, Base) \ 1193f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall case Stmt::Type##Class: \ 1194f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1); 1195f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define STMT(Type, Base) 1196f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#include "clang/AST/StmtNodes.inc" 1197f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall default: 1198f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall llvm_unreachable("non-cast expressions not possible here"); 1199f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return 0; 1200f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 1201f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1202f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1203f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallvoid CastExpr::setCastPath(const CXXCastPath &Path) { 1204f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(Path.size() == path_size()); 1205f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); 1206f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1207f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1208f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, 1209f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 1210f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 12115baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) { 1212f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1213f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1214f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1215f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr *E = 12165baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); 1217f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1218f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1219f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1220f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1221f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, 1222f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize) { 1223f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1224f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1225f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); 1226f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1227f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1228f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1229f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, 1230f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 1231f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 1232f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, 1233f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation L, SourceLocation R) { 1234f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1235f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1236f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1237f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CStyleCastExpr *E = 1238f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); 1239f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1240f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1241f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1242f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1243f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { 1244f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1245f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); 1247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1248f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) { 12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 12532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemD: return ".*"; 12542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemI: return "->*"; 12552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Mul: return "*"; 12562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Div: return "/"; 12572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Rem: return "%"; 12582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Add: return "+"; 12592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Sub: return "-"; 12602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shl: return "<<"; 12612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shr: return ">>"; 12622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: return "<"; 12632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: return ">"; 12642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: return "<="; 12652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: return ">="; 12662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: return "=="; 12672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: return "!="; 12682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: return "&"; 12692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: return "^"; 12702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: return "|"; 12712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: return "&&"; 12722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: return "||"; 12732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: return "="; 12742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_MulAssign: return "*="; 12752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_DivAssign: return "/="; 12762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_RemAssign: return "%="; 12772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AddAssign: return "+="; 12782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_SubAssign: return "-="; 12792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShlAssign: return "<<="; 12802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShrAssign: return ">>="; 12812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AndAssign: return "&="; 12822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_XorAssign: return "^="; 12832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_OrAssign: return "|="; 12842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: return ","; 12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1286baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 1287baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor return ""; 12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallBinaryOperatorKind 1291063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 1292063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 1293b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not an overloadable binary operator"); 12942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return BO_Add; 12952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return BO_Sub; 12962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return BO_Mul; 12972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Slash: return BO_Div; 12982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Percent: return BO_Rem; 12992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Caret: return BO_Xor; 13002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return BO_And; 13012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Pipe: return BO_Or; 13022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Equal: return BO_Assign; 13032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Less: return BO_LT; 13042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Greater: return BO_GT; 13052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusEqual: return BO_AddAssign; 13062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusEqual: return BO_SubAssign; 13072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_StarEqual: return BO_MulAssign; 13082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_SlashEqual: return BO_DivAssign; 13092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PercentEqual: return BO_RemAssign; 13102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_CaretEqual: return BO_XorAssign; 13112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpEqual: return BO_AndAssign; 13122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipeEqual: return BO_OrAssign; 13132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLess: return BO_Shl; 13142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreater: return BO_Shr; 13152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLessEqual: return BO_ShlAssign; 13162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreaterEqual: return BO_ShrAssign; 13172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_EqualEqual: return BO_EQ; 13182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ExclaimEqual: return BO_NE; 13192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessEqual: return BO_LE; 13202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterEqual: return BO_GE; 13212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpAmp: return BO_LAnd; 13222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipePipe: return BO_LOr; 13232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Comma: return BO_Comma; 13242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ArrowStar: return BO_PtrMemI; 1325063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 1326063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1327063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1328063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 1329063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 1330063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 1331063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 1332063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 1333063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 1334063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 1335063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 1336063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 1337063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 1338063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 1339063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 1340063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 1341063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 1342063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 1343063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 1344063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 1345063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 1346063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 1347063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 1348063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 1349063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 1350063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1351063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1352709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, 1353418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner Expr **initExprs, unsigned numInits, 13544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc) 1355bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, 1356561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1357709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs(C, numInits), 13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0), 13594423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis HadArrayRangeDesignator(false) 1360c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt{ 1361ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek for (unsigned I = 0; I != numInits; ++I) { 1362ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isTypeDependent()) 13638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1364ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isValueDependent()) 13658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1366561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (initExprs[I]->isInstantiationDependent()) 1367561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 1368bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (initExprs[I]->containsUnexpandedParameterPack()) 1369bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 137073460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor } 1371c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1372709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits); 137366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 13745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1375709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { 1376ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (NumInits > InitExprs.size()) 1377709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.reserve(C, NumInits); 1378fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 1379fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 1380709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { 1381709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.resize(C, NumInits, 0); 13824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 13834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1384709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { 1385ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (Init >= InitExprs.size()) { 1386709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); 1387ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek InitExprs.back() = expr; 1388ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return 0; 13894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 13901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 13924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 13934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 13944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 13954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 13963e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidisvoid InitListExpr::setArrayFiller(Expr *filler) { 13973e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis ArrayFillerOrUnionFieldInit = filler; 13983e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis // Fill out any "holes" in the array due to designated initializers. 13993e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis Expr **inits = getInits(); 14003e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis for (unsigned i = 0, e = getNumInits(); i != e; ++i) 14013e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis if (inits[i] == 0) 14023e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis inits[i] = filler; 14033e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis} 14043e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis 1405c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted KremenekSourceRange InitListExpr::getSourceRange() const { 1406c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (SyntacticForm) 1407c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SyntacticForm->getSourceRange(); 1408c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek SourceLocation Beg = LBraceLoc, End = RBraceLoc; 1409c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Beg.isInvalid()) { 1410c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer. 1411c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_iterator I = InitExprs.begin(), 1412c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.end(); 1413c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1414c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1415c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek Beg = S->getLocStart(); 1416c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1417c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1418c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1419c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1420c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (End.isInvalid()) { 1421c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer from the end. 1422c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), 1423c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.rend(); 1424c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1425c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1426c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek End = S->getSourceRange().getEnd(); 1427c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1428c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1429c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1430c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1431c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SourceRange(Beg, End); 1432c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek} 1433c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 1434bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 14354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 14364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const { 14376217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<BlockPointerType>()-> 1438183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall getPointeeType()->getAs<FunctionType>(); 14394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 14404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 14411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const { 14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getCaretLocation(); 144356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const { 14457297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 14467297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 14471eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() { 14481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getBody(); 14497297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 145056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 145156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1456026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 1457026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 1458026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 1459026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 1460026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattnerbool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 1461df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const { 1462ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 1463ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 1464ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 1465ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 14685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 14690faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 14700faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1471026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 1472026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1473026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 14745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 1475026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 1476df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump isUnusedResultAWarning(Loc, R1, R2, Ctx); 1477f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 1478f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr()-> 1479f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne isUnusedResultAWarning(Loc, R1, R2, Ctx); 14805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 1484026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner default: break; 14852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: 14862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: 14872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: 14882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: // ++/-- 1489026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 14902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: 14915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Dereferencing a volatile pointer is a side-effect. 1492df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1493026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1494026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 14952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: 14962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: 14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 1498df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) 1499df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump .isVolatileQualified()) 1500026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1501026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 15022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: 1503df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1505026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 1506026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 1507026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 15085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1509e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 1510026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 1511c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek switch (BO->getOpcode()) { 1512c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek default: 1513c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek break; 151425973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider the RHS of comma for side effects. LHS was checked by 151525973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Sema::CheckCommaOperands. 15162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 1517c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // ((foo = <blah>), 0) is an idiom for hiding the result (and 1518c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // lvalue-ness) of an assignment written in a macro. 1519c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IntegerLiteral *IE = 1520c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) 1521c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IE->getValue() == 0) 1522c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek return false; 152325973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 152425973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider '||', '&&' to have side effects if the LHS or RHS does. 15252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: 15262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: 152725973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis if (!BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) || 152825973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis !BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) 152925973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return false; 153025973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis break; 1531bf0ee354163f87623a4b60412544243911332343John McCall } 1532026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 1533026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1534026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 1535026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 1536026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 1537026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1538e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 1539eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 1540c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor case VAArgExprClass: 1541026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 15425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1543ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 1544fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // If only one of the LHS or RHS is a warning, the operator might 1545fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // be being used for control flow. Only warn if both the LHS and 1546fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek // RHS are warnings. 1547ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 1548fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek if (!Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) 1549fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek return false; 1550fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek if (!Exp->getLHS()) 1551026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1552fb7cb35fa0a8131853b1b049ca7be77980e144f5Ted Kremenek return Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1553ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 1554ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 15555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 1556026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the base pointer or element is to a volatile pointer/field, accessing 1557026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 1558df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1559026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1560026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 1561026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 1562026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 1563026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 15665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the base pointer or element is to a volatile pointer/field, accessing 1567026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 1568df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1569026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1570026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 1571026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 1572026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 1573026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1574211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 15759b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth case CXXOperatorCallExprClass: { 15769b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // We warn about operator== and operator!= even when user-defined operator 15779b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // overloads as there is no reasonable way to define these such that they 15789b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // have non-trivial, desirable side-effects. See the -Wunused-comparison 15799b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // warning: these operators are commonly typo'ed, and so warning on them 15809b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // provides additional value as well. If this list is updated, 15819b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // DiagnoseUnusedComparison should be as well. 15829b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); 15839b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth if (Op->getOperator() == OO_EqualEqual || 15846e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Op->getOperator() == OO_ExclaimEqual) { 15856e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay Loc = Op->getOperatorLoc(); 15866e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay R1 = Op->getSourceRange(); 15879b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth return true; 15886e5218367c513fe02d1c7210023d40739ecb1572Matt Beaumont-Gay } 15899b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth 15909b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth // Fallthrough for generic call handling. 15919b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth } 15925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 1593852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXMemberCallExprClass: { 1594026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 1595026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 1596d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes if (const Decl *FD = CE->getCalleeDecl()) { 1597026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 1598026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 1599bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // 1600bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // Note: If new cases are added here, DiagnoseUnusedExprResult should be 1601bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // updated to match for QoI. 1602bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (FD->getAttr<WarnUnusedResultAttr>() || 1603bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 1604bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner Loc = CE->getCallee()->getLocStart(); 1605bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R1 = CE->getCallee()->getSourceRange(); 1606bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner 1607bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 1608bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 1609bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 1610bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return true; 1611bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1612026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 1613026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1614026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 161558beed91d468863b8c85bce43425422703838d27Anders Carlsson 161658beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXTemporaryObjectExprClass: 161758beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXConstructExprClass: 161858beed91d468863b8c85bce43425422703838d27Anders Carlsson return false; 161958beed91d468863b8c85bce43425422703838d27Anders Carlsson 1620f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian case ObjCMessageExprClass: { 1621f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); 1622f85e193739c953358c865005855253af4f68a497John McCall if (Ctx.getLangOptions().ObjCAutoRefCount && 1623f85e193739c953358c865005855253af4f68a497John McCall ME->isInstanceMessage() && 1624f85e193739c953358c865005855253af4f68a497John McCall !ME->getType()->isVoidType() && 1625f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) && 1626f85e193739c953358c865005855253af4f68a497John McCall ME->getSelector().getIdentifierInfoForSlot(0) 1627f85e193739c953358c865005855253af4f68a497John McCall ->getName().startswith("init")) { 1628f85e193739c953358c865005855253af4f68a497John McCall Loc = getExprLoc(); 1629f85e193739c953358c865005855253af4f68a497John McCall R1 = ME->getSourceRange(); 1630f85e193739c953358c865005855253af4f68a497John McCall return true; 1631f85e193739c953358c865005855253af4f68a497John McCall } 1632f85e193739c953358c865005855253af4f68a497John McCall 1633f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMethodDecl *MD = ME->getMethodDecl(); 1634f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 1635f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian Loc = getExprLoc(); 1636f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian return true; 1637f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 1638026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1639f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 164112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall case ObjCPropertyRefExprClass: 16425e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 16435e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 1644a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 164512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 1646611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 1647611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 1648611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 1649611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 1650611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 1651611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 1652611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 1653d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (!CS->body_empty()) { 1654611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 1655df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1656d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) 1657d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) 1658d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1659d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis } 16601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16610faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 16620faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1663026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 1664026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1665026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1666611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 16676eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor case CStyleCastExprClass: 1668fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // If this is an explicit cast to void, allow it. People do this when they 1669fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // think they know what they're doing :). 1670026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (getType()->isVoidType()) 1671fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner return false; 1672026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); 1673026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); 1674026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 167558beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXFunctionalCastExprClass: { 16760faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 16770faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 167858beed91d468863b8c85bce43425422703838d27Anders Carlsson const CastExpr *CE = cast<CastExpr>(this); 1679c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 168058beed91d468863b8c85bce43425422703838d27Anders Carlsson // If this is a cast to void or a constructor conversion, check the operand. 168158beed91d468863b8c85bce43425422703838d27Anders Carlsson // Otherwise, the result of the cast is unused. 16822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (CE->getCastKind() == CK_ToVoid || 16832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall CE->getCastKind() == CK_ConstructorConversion) 1684df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CastExpr>(this)->getSubExpr() 1685df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 1686026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); 1687026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); 1688026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 168958beed91d468863b8c85bce43425422703838d27Anders Carlsson } 16901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16914be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman case ImplicitCastExprClass: 16924be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman // Check the operand, since implicit casts are inserted by Sema 1693df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<ImplicitCastExpr>(this) 1694df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 16954be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 169604421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 1697df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXDefaultArgExpr>(this) 1698df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 16994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 17014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 17024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 17034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 1704026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 17052d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 1706df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXBindTemporaryExpr>(this) 1707df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 17084765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall case ExprWithCleanupsClass: 17094765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return (cast<ExprWithCleanups>(this) 1710df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 17114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 171444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 17157f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise. 1716102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 1717f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *E = IgnoreParens(); 1718f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne switch (E->getStmtClass()) { 171944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 172044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 172144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 172244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 1723207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 1724f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 172544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 1726f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 172703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 172803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr() 172903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isOBJCGCCandidate(Ctx); 173006b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 1731f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); 1732e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian case BlockDeclRefExprClass: 1733a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { 1734e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian 1735e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian const Decl *D; 1736e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian if (const BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E)) 1737e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian D = BDRE->getDecl(); 1738e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian else 1739e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian D = cast<DeclRefExpr>(E)->getDecl(); 1740e3f834950801f1334f1b3f3f7e9a34062905fe1dFariborz Jahanian 1741102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 1742102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 1743102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 1744102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 174559a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // dereferencing to a pointer is always a gc'able candidate, 174659a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // unless it is __weak. 17477e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar return T->isPointerType() && 17480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); 1749102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 175044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 175144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 175283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 1753f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const MemberExpr *M = cast<MemberExpr>(E); 1754102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 175544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 175644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 1757f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx); 175844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 175944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 1760369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 176111ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidisbool Expr::isBoundMemberFunction(ASTContext &Ctx) const { 176211ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis if (isTypeDependent()) 176311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis return false; 17647eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; 176511ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis} 176611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 1767864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallQualType Expr::findBoundMemberType(const Expr *expr) { 1768864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(expr->getType()->isSpecificPlaceholderType(BuiltinType::BoundMember)); 1769864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1770864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // Bound member expressions are always one of these possibilities: 1771864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // x->m x.m x->*y x.*y 1772864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // (possibly parenthesized) 1773864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1774864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall expr = expr->IgnoreParens(); 1775864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) { 1776864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<CXXMethodDecl>(mem->getMemberDecl())); 1777864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return mem->getMemberDecl()->getType(); 1778864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 1779864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1780864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) { 1781864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall QualType type = op->getRHS()->getType()->castAs<MemberPointerType>() 1782864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall ->getPointeeType(); 1783864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(type->isFunctionType()); 1784864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return type; 1785864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall } 1786864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1787864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall assert(isa<UnresolvedMemberExpr>(expr)); 1788864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall return QualType(); 1789864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall} 1790864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 1791369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult MergeCanThrow(Expr::CanThrowResult CT1, 1792369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr::CanThrowResult CT2) { 1793369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // CanThrowResult constants are ordered so that the maximum is the correct 1794369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // merge result. 1795369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT1 > CT2 ? CT1 : CT2; 1796369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1797369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1798369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanSubExprsThrow(ASTContext &C, const Expr *CE) { 1799369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr *E = const_cast<Expr*>(CE); 1800369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr::CanThrowResult R = Expr::CT_Cannot; 18017502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall for (Expr::child_range I = E->children(); I && R != Expr::CT_Can; ++I) { 1802369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl R = MergeCanThrow(R, cast<Expr>(*I)->CanThrow(C)); 1803369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1804369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return R; 1805369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1806369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 18077a614d8380297fcd2bc23986241905d97222948cRichard Smithstatic Expr::CanThrowResult CanCalleeThrow(ASTContext &Ctx, const Expr *E, 18087a614d8380297fcd2bc23986241905d97222948cRichard Smith const Decl *D, 1809369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl bool NullThrows = true) { 1810369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!D) 1811369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return NullThrows ? Expr::CT_Can : Expr::CT_Cannot; 1812369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1813369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // See if we can get a function type from the decl somehow. 1814369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const ValueDecl *VD = dyn_cast<ValueDecl>(D); 1815369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!VD) // If we have no clue what we're calling, assume the worst. 1816369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Can; 1817369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 18185221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl // As an extension, we assume that __attribute__((nothrow)) functions don't 18195221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl // throw. 18205221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl if (isa<FunctionDecl>(D) && D->hasAttr<NoThrowAttr>()) 18215221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl return Expr::CT_Cannot; 18225221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl 1823369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl QualType T = VD->getType(); 1824369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const FunctionProtoType *FT; 1825369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if ((FT = T->getAs<FunctionProtoType>())) { 1826369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } else if (const PointerType *PT = T->getAs<PointerType>()) 1827369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = PT->getPointeeType()->getAs<FunctionProtoType>(); 1828369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 1829369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = RT->getPointeeType()->getAs<FunctionProtoType>(); 1830369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl else if (const MemberPointerType *MT = T->getAs<MemberPointerType>()) 1831369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = MT->getPointeeType()->getAs<FunctionProtoType>(); 1832369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl else if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) 1833369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = BT->getPointeeType()->getAs<FunctionProtoType>(); 1834369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1835369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!FT) 1836369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Can; 1837369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 18387a614d8380297fcd2bc23986241905d97222948cRichard Smith if (FT->getExceptionSpecType() == EST_Delayed) { 18397a614d8380297fcd2bc23986241905d97222948cRichard Smith assert(isa<CXXConstructorDecl>(D) && 18407a614d8380297fcd2bc23986241905d97222948cRichard Smith "only constructor exception specs can be unknown"); 18417a614d8380297fcd2bc23986241905d97222948cRichard Smith Ctx.getDiagnostics().Report(E->getLocStart(), 18427a614d8380297fcd2bc23986241905d97222948cRichard Smith diag::err_exception_spec_unknown) 18437a614d8380297fcd2bc23986241905d97222948cRichard Smith << E->getSourceRange(); 18447a614d8380297fcd2bc23986241905d97222948cRichard Smith return Expr::CT_Can; 18457a614d8380297fcd2bc23986241905d97222948cRichard Smith } 18467a614d8380297fcd2bc23986241905d97222948cRichard Smith 18478026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl return FT->isNothrow(Ctx) ? Expr::CT_Cannot : Expr::CT_Can; 1848369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1849369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1850369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanDynamicCastThrow(const CXXDynamicCastExpr *DC) { 1851369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (DC->isTypeDependent()) 1852369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Dependent; 1853369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1854295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl if (!DC->getTypeAsWritten()->isReferenceType()) 1855295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl return Expr::CT_Cannot; 1856295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl 1857be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman if (DC->getSubExpr()->isTypeDependent()) 1858be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman return Expr::CT_Dependent; 1859be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman 1860369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return DC->getCastKind() == clang::CK_Dynamic? Expr::CT_Can : Expr::CT_Cannot; 1861369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1862369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1863369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanTypeidThrow(ASTContext &C, 1864369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const CXXTypeidExpr *DC) { 1865369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (DC->isTypeOperand()) 1866369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1867369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1868369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr *Op = DC->getExprOperand(); 1869369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (Op->isTypeDependent()) 1870369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Dependent; 1871369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1872369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const RecordType *RT = Op->getType()->getAs<RecordType>(); 1873369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!RT) 1874369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1875369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1876369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!cast<CXXRecordDecl>(RT->getDecl())->isPolymorphic()) 1877369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1878369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1879369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (Op->Classify(C).isPRValue()) 1880369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1881369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1882369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Can; 1883369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1884369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1885369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian RedlExpr::CanThrowResult Expr::CanThrow(ASTContext &C) const { 1886369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // C++ [expr.unary.noexcept]p3: 1887369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // [Can throw] if in a potentially-evaluated context the expression would 1888369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // contain: 1889369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl switch (getStmtClass()) { 1890369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXThrowExprClass: 1891369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated throw-expression 1892369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Can; 1893369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1894369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDynamicCastExprClass: { 1895369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated dynamic_cast expression dynamic_cast<T>(v), 1896369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // where T is a reference type, that requires a run-time check 1897369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = CanDynamicCastThrow(cast<CXXDynamicCastExpr>(this)); 1898369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1899369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1900369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1901369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1902369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1903369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXTypeidExprClass: 1904369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated typeid expression applied to a glvalue 1905369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // expression whose type is a polymorphic class type 1906369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CanTypeidThrow(C, cast<CXXTypeidExpr>(this)); 1907369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1908369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated call to a function, member function, function 1909369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // pointer, or member function pointer that does not have a non-throwing 1910369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // exception-specification 1911369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CallExprClass: 1912369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXOperatorCallExprClass: 1913369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXMemberCallExprClass: { 1914ebc93e176dad36fa8a28dd3a36c5b3dc7630d87dEli Friedman const CallExpr *CE = cast<CallExpr>(this); 1915be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman CanThrowResult CT; 1916be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman if (isTypeDependent()) 1917be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman CT = CT_Dependent; 1918ebc93e176dad36fa8a28dd3a36c5b3dc7630d87dEli Friedman else if (isa<CXXPseudoDestructorExpr>(CE->getCallee()->IgnoreParens())) 1919ebc93e176dad36fa8a28dd3a36c5b3dc7630d87dEli Friedman CT = CT_Cannot; 1920be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman else 19217a614d8380297fcd2bc23986241905d97222948cRichard Smith CT = CanCalleeThrow(C, this, CE->getCalleeDecl()); 1922369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1923369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1924369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1925369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1926369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1927295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl case CXXConstructExprClass: 1928295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl case CXXTemporaryObjectExprClass: { 19297a614d8380297fcd2bc23986241905d97222948cRichard Smith CanThrowResult CT = CanCalleeThrow(C, this, 1930369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl cast<CXXConstructExpr>(this)->getConstructor()); 1931369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1932369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1933369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1934369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1935369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1936369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXNewExprClass: { 1937be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman CanThrowResult CT; 1938be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman if (isTypeDependent()) 1939be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman CT = CT_Dependent; 1940be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman else 1941be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman CT = MergeCanThrow( 19427a614d8380297fcd2bc23986241905d97222948cRichard Smith CanCalleeThrow(C, this, cast<CXXNewExpr>(this)->getOperatorNew()), 19437a614d8380297fcd2bc23986241905d97222948cRichard Smith CanCalleeThrow(C, this, cast<CXXNewExpr>(this)->getConstructor(), 1944369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /*NullThrows*/false)); 1945369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1946369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1947369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1948369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1949369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1950369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDeleteExprClass: { 1951be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman CanThrowResult CT; 1952be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman QualType DTy = cast<CXXDeleteExpr>(this)->getDestroyedType(); 1953be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman if (DTy.isNull() || DTy->isDependentType()) { 1954be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman CT = CT_Dependent; 1955be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman } else { 19567a614d8380297fcd2bc23986241905d97222948cRichard Smith CT = CanCalleeThrow(C, this, 19577a614d8380297fcd2bc23986241905d97222948cRichard Smith cast<CXXDeleteExpr>(this)->getOperatorDelete()); 1958be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman if (const RecordType *RT = DTy->getAs<RecordType>()) { 1959be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); 19607a614d8380297fcd2bc23986241905d97222948cRichard Smith CT = MergeCanThrow(CT, CanCalleeThrow(C, this, RD->getDestructor())); 19610b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl } 1962be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman if (CT == CT_Can) 1963be57cf41fb55b48e3f889787960b3ac2eb5e4dbdEli Friedman return CT; 19640b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl } 19650b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 19660b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl } 19670b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl 19680b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl case CXXBindTemporaryExprClass: { 19690b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl // The bound temporary has to be destroyed again, which might throw. 19707a614d8380297fcd2bc23986241905d97222948cRichard Smith CanThrowResult CT = CanCalleeThrow(C, this, 19710b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl cast<CXXBindTemporaryExpr>(this)->getTemporary()->getDestructor()); 19720b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (CT == CT_Can) 19730b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl return CT; 1974369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1975369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1976369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1977369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // ObjC message sends are like function calls, but never have exception 1978369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // specs. 1979369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCMessageExprClass: 1980369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCPropertyRefExprClass: 1981369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Can; 1982369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1983369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Many other things have subexpressions, so we have to test those. 1984369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Some are simple: 1985369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ParenExprClass: 1986369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case MemberExprClass: 1987369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXReinterpretCastExprClass: 1988369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXConstCastExprClass: 1989369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ConditionalOperatorClass: 1990369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CompoundLiteralExprClass: 1991369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ExtVectorElementExprClass: 1992369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case InitListExprClass: 1993369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case DesignatedInitExprClass: 1994369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ParenListExprClass: 1995369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case VAArgExprClass: 1996369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDefaultArgExprClass: 19974765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall case ExprWithCleanupsClass: 1998369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCIvarRefExprClass: 1999369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCIsaExprClass: 2000369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ShuffleVectorExprClass: 2001369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CanSubExprsThrow(C, this); 2002369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 2003369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Some might be dependent for other reasons. 2004369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case UnaryOperatorClass: 2005369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ArraySubscriptExprClass: 2006369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ImplicitCastExprClass: 2007369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CStyleCastExprClass: 2008369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXStaticCastExprClass: 2009369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXFunctionalCastExprClass: 2010369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case BinaryOperatorClass: 201103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case CompoundAssignOperatorClass: 201203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: { 2013369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = isTypeDependent() ? CT_Dependent : CT_Cannot; 2014369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 2015369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 2016369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 2017369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // FIXME: We should handle StmtExpr, but that opens a MASSIVE can of worms. 2018369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case StmtExprClass: 2019369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Can; 2020369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 2021369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ChooseExprClass: 2022369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (isTypeDependent() || isValueDependent()) 2023369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Dependent; 2024369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return cast<ChooseExpr>(this)->getChosenSubExpr(C)->CanThrow(C); 2025369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 2026f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 2027f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (cast<GenericSelectionExpr>(this)->isResultDependent()) 2028f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return CT_Dependent; 2029f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr()->CanThrow(C); 2030f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 2031369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Some expressions are always dependent. 2032369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case DependentScopeDeclRefExprClass: 2033369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXUnresolvedConstructExprClass: 2034369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDependentScopeMemberExprClass: 2035369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Dependent; 2036369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 2037369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl default: 2038369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // All other expressions don't have subexpressions, or else they are 2039369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // unevaluated. 2040369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Cannot; 2041369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 2042369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 2043369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 20444e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 20454e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 2046b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara while (true) { 2047b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 2048b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2049b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2050b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2051b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2052b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2053b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2054b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2055b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2056b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2057f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2058f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2059f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2060f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2061f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2062f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2063b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 2064b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 20654e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 20664e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 206756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 206856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 206956f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 207056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 207156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 2072b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 207356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2074b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2075b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2076b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (CastExpr *P = dyn_cast<CastExpr>(E)) { 207756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 2078b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2079b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2080b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2081b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2082b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2083b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2084b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2085b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2086f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2087f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2088f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2089f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2090f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2091f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 209203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 209303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 209403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 209503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 209603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2097c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2098c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2099c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2100c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2101c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2102b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 210356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 210456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 210556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 21069c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue 21079c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts. This is intended purely as a temporary workaround for code 21089c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// that hasn't yet been rewritten to do the right thing about those 21099c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts, and may disappear along with the last internal use. 2110f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallExpr *Expr::IgnoreParenLValueCasts() { 2111f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *E = this; 21129c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall while (true) { 2113f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2114f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2115f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 21169c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2117f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (P->getCastKind() == CK_LValueToRValue) { 2118f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 2119f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 2120f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 21219c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 21229c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall if (P->getOpcode() == UO_Extension) { 21239c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall E = P->getSubExpr(); 21249c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall continue; 21259c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } 2126f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2127f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2128f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2129f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2130f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 213103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (MaterializeTemporaryExpr *Materialize 213203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 213303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 213403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 2135c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } else if (SubstNonTypeTemplateParmExpr *NTTP 2136c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2137c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2138c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2139f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2140f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 2141f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2142f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return E; 2143f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 2144f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 21452fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() { 21462fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *E = this; 21472fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall while (true) { 2148b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 21492fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2150b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2151b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2152b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) { 21532fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 2154b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2155b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2156b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2157b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2158b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2159b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2160b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2161b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2162f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2163f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2164f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2165f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2166f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2167f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 216803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (MaterializeTemporaryExpr *Materialize 216903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 217003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = Materialize->GetTemporaryExpr(); 217103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 217203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 2173c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2174c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2175c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2176c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2177c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2178b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 21792fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall } 21802fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall} 21812fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 21822f072b442879b8bba8c5dea11d7c61bedb1924aeHans WennborgExpr *Expr::IgnoreConversionOperator() { 21832f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg if (CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(this)) { 218414d251cd62942bf7d56bb87a267ba2ca2f7fae3eChandler Carruth if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl())) 21852f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return MCE->getImplicitObjectArgument(); 21862f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 21872f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return this; 21882f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg} 21892f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 2190ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 2191ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 2192ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 2193ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 2194ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 2195ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 2196ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 2197ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 2198ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2199ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 22001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2201ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 2202ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 22032ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor // ptr<->int casts of the same width. We also ignore all identity casts. 2204ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 22051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2206ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 2207ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2208ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2209ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 22101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2211b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if ((E->getType()->isPointerType() || 22129d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor E->getType()->isIntegralType(Ctx)) && 2213b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara (SE->getType()->isPointerType() || 22149d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor SE->getType()->isIntegralType(Ctx)) && 2215ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 2216ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 2217ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 2218ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2219ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 22201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2221b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 2222b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 2223b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 2224b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 2225b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2226b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 2227b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara 2228f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) { 2229f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!P->isResultDependent()) { 2230f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E = P->getResultExpr(); 2231f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne continue; 2232f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2233f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 2234f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 2235c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor if (SubstNonTypeTemplateParmExpr *NTTP 2236c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { 2237c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor E = NTTP->getReplacement(); 2238c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor continue; 2239c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor } 2240c0244c5c351db18c6c35c1594872dde072b90df9Douglas Gregor 2241ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 2242ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 2243ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 2244ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 22456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const { 22466eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *E = this; 224703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 224803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 224903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 22506eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) 22516eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor E = ICE->getSubExprAsWritten(); 2252c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 22536eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return isa<CXXDefaultArgExpr>(E); 22546eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 2255ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 22562f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding 22572f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions. 2258f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlssonstatic const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { 225903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) 226003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 226103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 22622f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 22632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 22642f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 22652f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 22662f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 22672f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 22682f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 22692f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) 22702f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = BE->getSubExpr(); 22712f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 22722f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 22732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 22742f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 22752f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 22762f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 22772f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 2278f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson 2279f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson return E->IgnoreParens(); 22802f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 22812f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2282558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// isTemporaryObject - Determines if this expression produces a 2283558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// temporary of the given class type. 2284558d2abc7f9fd6801cc7677200992313ae90b5d8John McCallbool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { 2285558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) 2286558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 22872f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2288f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); 22892f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 229058277b57f9492d0234748be89bcad48b322c5cf7John McCall // Temporaries are by definition pr-values of class type. 2291db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian if (!E->Classify(C).isPRValue()) { 2292db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian // In this context, property reference is a message call and is pr-value. 229312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!isa<ObjCPropertyRefExpr>(E)) 2294db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian return false; 2295db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian } 22962f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 229719e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // Black-list a few cases which yield pr-values of class type that don't 229819e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // refer to temporaries of that type: 229919e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 230019e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - implicit derived-to-base conversions 2301558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (isa<ImplicitCastExpr>(E)) { 2302558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall switch (cast<ImplicitCastExpr>(E)->getCastKind()) { 2303558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_DerivedToBase: 2304558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_UncheckedDerivedToBase: 2305558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 2306558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall default: 2307558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall break; 2308558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 23092f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 23102f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 231119e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - member expressions (all) 231219e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall if (isa<MemberExpr>(E)) 231319e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall return false; 231419e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 231556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // - opaque values (all) 231656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (isa<OpaqueValueExpr>(E)) 231756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return false; 231856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 2319558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return true; 23202f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 23212f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 232275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregorbool Expr::isImplicitCXXThis() const { 232375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor const Expr *E = this; 232475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 232575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor // Strip away parentheses and casts we don't care about. 232675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor while (true) { 232775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) { 232875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = Paren->getSubExpr(); 232975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 233075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 233175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 233275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 233375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (ICE->getCastKind() == CK_NoOp || 233475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_LValueToRValue || 233575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_DerivedToBase || 233675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor ICE->getCastKind() == CK_UncheckedDerivedToBase) { 233775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = ICE->getSubExpr(); 233875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 233975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 234075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 234175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 234275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) { 234375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (UnOp->getOpcode() == UO_Extension) { 234475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor E = UnOp->getSubExpr(); 234575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor continue; 234675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 234775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 234875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 234903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *M 235003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(E)) { 235103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor E = M->GetTemporaryExpr(); 235203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor continue; 235303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 235403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 235575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor break; 235675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 235775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 235875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E)) 235975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return This->isImplicit(); 236075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 236175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return false; 236275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor} 236375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 2364898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 2365898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 2366898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) { 2367898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 2368898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 2369898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 2370898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2371898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 2372898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2373898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2374898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyValueDependentArguments - Determines if any of the expressions 2375898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is value-dependent. 2376898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) { 2377898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 2378898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isValueDependent()) 2379898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 2380898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2381898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 2382898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2383898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 23844204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { 2385c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 2386c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 2387c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 2388c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 2389c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 2390c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 23914204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // If we ever capture reference-binding directly in the AST, we can 23924204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // kill the second parameter. 23934204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 23944204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (IsForRef) { 23954204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall EvalResult Result; 23964204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; 23974204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall } 23981f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 2399e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 2400c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 2401e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 240214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 2403eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 2404e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 2405b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXTemporaryObjectExprClass: 2406b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXConstructExprClass: { 2407b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 24084204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 24094204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // Only if it's 24104204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // 1) an application of the trivial default constructor or 2411b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall if (!CE->getConstructor()->isTrivial()) return false; 24124204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!CE->getNumArgs()) return true; 24134204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 24144204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // 2) an elidable trivial copy construction of an operand which is 24154204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // itself a constant initializer. Note that we consider the 24164204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // operand on its own, *not* as a reference binding. 24174204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return CE->isElidable() && 24184204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall CE->getArg(0)->isConstantInitializer(Ctx, false); 2419b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall } 242059b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 24211f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 24221f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 24231f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 242459b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 24254204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->isConstantInitializer(Ctx, false); 242659b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 2427e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 24281f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 24291f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 24301f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 2431e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 2432e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 2433e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 24344204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) 2435e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 2436e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2437c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 2438e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 24393498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 24403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 24413ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case ParenExprClass: 24424204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<ParenExpr>(this)->getSubExpr() 24434204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, IsForRef); 2444f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case GenericSelectionExprClass: 2445f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (cast<GenericSelectionExpr>(this)->isResultDependent()) 2446f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return false; 2447f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<GenericSelectionExpr>(this)->getResultExpr() 2448f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ->isConstantInitializer(Ctx, IsForRef); 24495cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara case ChooseExprClass: 24505cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx) 24515cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara ->isConstantInitializer(Ctx, IsForRef); 2452c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 2453c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 24542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == UO_Extension) 24554204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->getSubExpr()->isConstantInitializer(Ctx, false); 2456c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2457c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 24583ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case BinaryOperatorClass: { 24593ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // Special case &&foo - &&bar. It would be nice to generalize this somehow 24603ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // but this handles the common case. 24613ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner const BinaryOperator *Exp = cast<BinaryOperator>(this); 24622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == BO_Sub && 24633ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) && 24643ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx))) 24653ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner return true; 24663ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner break; 24673ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner } 24684204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall case CXXFunctionalCastExprClass: 2469b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXStaticCastExprClass: 247081045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 2471c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case CStyleCastExprClass: 2472c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // Handle casts with a destination that's a struct or union; this 2473c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // deals with both the gcc no-op struct cast extension and the 2474c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // cast-to-union extension. 2475c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman if (getType()->isRecordType()) 24764204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<CastExpr>(this)->getSubExpr() 24774204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, false); 2478c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2479430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // Integer->integer casts can be handled here, which is important for 2480430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // things like (int)(&&x-&&y). Scary but true. 2481430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner if (getType()->isIntegerType() && 2482430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType()) 24834204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<CastExpr>(this)->getSubExpr() 24844204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, false); 2485c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2486c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 248703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 248803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case MaterializeTemporaryExprClass: 24895f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() 249003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor ->isConstantInitializer(Ctx, false); 2491e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2492c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 249338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 249438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 249582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null 249682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// pointer constant or not, as well as the specific kind of constant detected. 249782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// Null pointer constants can be integer constant expressions with the 249882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// value zero, casts of zero to void*, nullptr (C++0X), or __null 249982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// (a GNU extension). 250082214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::NullPointerConstantKind 250182214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::isNullPointerConstant(ASTContext &Ctx, 250282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const { 2503ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor if (isValueDependent()) { 2504ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor switch (NPC) { 2505ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_NeverValueDependent: 2506b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unexpected value dependent expression!"); 2507ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNull: 250882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth if (isTypeDependent() || getType()->isIntegralType(Ctx)) 250982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_ZeroInteger; 251082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth else 251182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 2512c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2513ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNotNull: 251482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 2515ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2516ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2517f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar 25180777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 25190835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 25206215dee86c0e715b9f2b0d401ab2a5fcf629f1afSebastian Redl if (!Ctx.getLangOptions().CPlusPlus) { 25210777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 25226217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 25230777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 25240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Pointee.hasQualifiers() && 25250777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 25260777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 2527ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 25280777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 25295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2530aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 2531aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 2532ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 2533aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 2534aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 2535aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 2536ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 2537f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else if (const GenericSelectionExpr *GE = 2538f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne dyn_cast<GenericSelectionExpr>(this)) { 2539f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); 25401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (const CXXDefaultArgExpr *DefaultArg 25418123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 254204421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 2543ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); 25442d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 25452d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 254682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_GNUNull; 254703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } else if (const MaterializeTemporaryExpr *M 254803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor = dyn_cast<MaterializeTemporaryExpr>(this)) { 254903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); 2550aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 25512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 25526e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // C++0x nullptr_t is always a null pointer constant. 25536e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 255482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_CXX0X_nullptr; 25556e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 2556ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const RecordType *UT = getType()->getAsUnionType()) 2557ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) 2558ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ 2559ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian const Expr *InitExpr = CLE->getInitializer(); 2560ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) 2561ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); 2562ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian } 2563aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 2564c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (!getType()->isIntegerType() || 256556fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType())) 256682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 25671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 25695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // test for the value 0. 257009de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman llvm::APSInt Result; 257182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth bool IsNull = isIntegerConstantExpr(Result, Ctx) && Result == 0; 257282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 257382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return (IsNull ? NPCK_ZeroInteger : NPCK_NotNull); 25745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 257531a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 2576f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// \brief If this expression is an l-value for an Objective C 2577f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// property, find the underlying property reference expression. 2578f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallconst ObjCPropertyRefExpr *Expr::getObjCProperty() const { 2579f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *E = this; 2580f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall while (true) { 2581f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall assert((E->getValueKind() == VK_LValue && 2582f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E->getObjectKind() == OK_ObjCProperty) && 2583f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall "expression is not a property reference"); 2584f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = E->IgnoreParenCasts(); 2585f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 2586f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (BO->getOpcode() == BO_Comma) { 2587f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = BO->getRHS(); 2588f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 2589f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2590f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2591f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 2592f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 2593f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2594f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 2595f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return cast<ObjCPropertyRefExpr>(E); 2596f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 2597f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 259833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 25996f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 260033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 2601de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 2602f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ICE->getCastKind() == CK_LValueToRValue || 2603f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) 2604de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor E = ICE->getSubExpr()->IgnoreParens(); 2605de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor else 2606de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor break; 2607de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor } 2608de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor 260927c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 261086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 261133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 261233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 261333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 26140f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) 26150f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) 26160f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (Field->isBitField()) 26170f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis return Field; 26180f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis 261942068e9d420889014ee26894e421fead336b239dEli Friedman if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) { 262033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 262133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 262233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 262342068e9d420889014ee26894e421fead336b239dEli Friedman if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS()) 262442068e9d420889014ee26894e421fead336b239dEli Friedman return BinOp->getRHS()->getBitField(); 262542068e9d420889014ee26894e421fead336b239dEli Friedman } 262642068e9d420889014ee26894e421fead336b239dEli Friedman 262733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 262827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 262927c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 2630093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const { 2631093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson const Expr *E = this->IgnoreParens(); 2632c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2633093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 26345baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall if (ICE->getValueKind() != VK_RValue && 26352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall ICE->getCastKind() == CK_NoOp) 2636093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson E = ICE->getSubExpr()->IgnoreParens(); 2637093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson else 2638093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson break; 2639093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson } 2640c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2641093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) 2642093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return ASE->getBase()->getType()->isVectorType(); 2643093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2644093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (isa<ExtVectorElementExpr>(E)) 2645093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return true; 2646093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2647093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return false; 2648093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson} 2649093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 26502140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 26512140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 26522140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 26532140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 26542140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 26552140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 2656213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 2657183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const VectorType *VT = getType()->getAs<VectorType>()) 26588a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 26598a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 26604d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 26614d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 26628a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 2663213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 2664a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // FIXME: Refactor this code to an accessor on the AST node which returns the 2665a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // "type" of component access, and share with code below and in Sema. 26665f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 2667190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 2668190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 2669150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") 2670190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 26711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2672190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 2673150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 2674150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar Comp = Comp.substr(1); 26751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2676150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar for (unsigned i = 0, e = Comp.size(); i != e; ++i) 26775f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner if (Comp.substr(i + 1).find(Comp[i]) != StringRef::npos) 2678fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 2679150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar 2680fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 2681fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 2682b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 26838a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 26843b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 26855f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<unsigned> &Elts) const { 26865f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Comp = Accessor->getName(); 26874b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 26884b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Comp = Comp.substr(1); 26891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26904b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isHi = Comp == "hi"; 26914b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isLo = Comp == "lo"; 26924b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isEven = Comp == "even"; 26934b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isOdd = Comp == "odd"; 26941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26958a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 26968a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 26971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26988a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 26998a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 27008a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 27018a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 27028a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 27038a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 27048a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 27058a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 27068a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 27074b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Index = ExtVectorType::getAccessorIdx(Comp[i]); 2708b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 27093b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 2710b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 27118a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 27128a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 271304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2714f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 271504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 271604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 271704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 271804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 2719c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2720207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2721207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 272204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 27238d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 272404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 2725f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, 2726bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 2727561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/false, 2728bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 272904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 273004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2731b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(IsInstanceSuper? SuperInstance : SuperClass), 2732b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), SuperLoc(SuperLoc), 2733207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 2734c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{ 2735207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 273604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(SuperType.getAsOpaquePtr()); 273704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 273804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 273904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2740f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 274104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 274204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 2743f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 2744207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2745207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 274604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 27478d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 274804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 2749f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(), 2750561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), T->isInstantiationDependentType(), 2751561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->containsUnexpandedParameterPack()), 275204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 275304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2754b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Class), 2755b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), 2756207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 275704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 2758207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 275904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 276004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 276104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 276204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2763f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 276404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 276504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 2766c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2767207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2768207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK, 276904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 27708d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 277104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 2772f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(), 2773bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->isTypeDependent(), 2774561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Receiver->isInstantiationDependent(), 2775bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->containsUnexpandedParameterPack()), 277604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 277704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2778b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis Kind(Instance), 2779b994e6c7d57b00e3e0f69d152065e2cf85d1de33Argyrios Kyrtzidis HasMethod(Method != 0), IsDelegateInitCall(false), 2780207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis LBracLoc(LBracLoc), RBracLoc(RBracLoc) 278104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 2782207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis initArgsAndSelLocs(Args, SelLocs, SelLocsK); 278304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 2784207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 2785207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 2786207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::initArgsAndSelLocs(ArrayRef<Expr *> Args, 2787207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2788207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK) { 2789207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis setNumArgs(Args.size()); 2790aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **MyArgs = getArgs(); 27918d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis for (unsigned I = 0; I != Args.size(); ++I) { 2792bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isTypeDependent()) 2793bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 2794bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isValueDependent()) 2795bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 2796561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[I]->isInstantiationDependent()) 2797561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 2798bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->containsUnexpandedParameterPack()) 2799bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2800bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2801bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor MyArgs[I] = Args[I]; 2802bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 2803207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 2804207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocsKind = SelLocsK; 2805207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis if (SelLocsK == SelLoc_NonStandard) 2806207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); 280704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 280804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 280904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2810f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 281104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 281204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 281304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 281404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 2815c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2816951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 281704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 28188d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 281904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 2820207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK; 2821207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ObjCMessageExpr *Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 2822f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper, 2823207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SuperType, Sel, SelLocs, SelLocsK, 2824207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Method, Args, RBracLoc); 282504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 282604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 282704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2828f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 282904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 283004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 2831c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2832951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 283304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 28348d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 283504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 2836207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK; 2837207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ObjCMessageExpr *Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 2838951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 2839207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc); 284004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 284104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 284204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2843f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 284404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 284504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 2846f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 2847951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 284804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 28498d9ed7980405e91a12e33338a78fb99620adf553Argyrios Kyrtzidis ArrayRef<Expr *> Args, 285004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 2851207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind SelLocsK; 2852207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ObjCMessageExpr *Mem = alloc(Context, Args, RBracLoc, SelLocs, Sel, SelLocsK); 2853951376242c076c3f62dd78bf672909fc011991dbArgyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, 2854207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, SelLocsK, Method, Args, RBracLoc); 285504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 285604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 2857c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, 2858207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 2859207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 2860207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ObjCMessageExpr *Mem = alloc(Context, NumArgs, NumStoredSelLocs); 286104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); 286204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 2863e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2864207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 2865207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<Expr *> Args, 2866207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SourceLocation RBraceLoc, 2867207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelLocs, 2868207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Selector Sel, 2869207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelectorLocationsKind &SelLocsK) { 2870207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocsK = hasStandardSelectorLocs(Sel, SelLocs, Args, RBraceLoc); 2871207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs = (SelLocsK == SelLoc_NonStandard) ? SelLocs.size() 2872207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis : 0; 2873207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return alloc(C, Args.size(), NumStoredSelLocs); 2874207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 2875207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 2876207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios KyrtzidisObjCMessageExpr *ObjCMessageExpr::alloc(ASTContext &C, 2877207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumArgs, 2878207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned NumStoredSelLocs) { 2879207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 2880207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis NumArgs * sizeof(Expr *) + NumStoredSelLocs * sizeof(SourceLocation); 2881207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis return (ObjCMessageExpr *)C.Allocate(Size, 2882207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis llvm::AlignOf<ObjCMessageExpr>::Alignment); 2883207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 2884207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 2885207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidisvoid ObjCMessageExpr::getSelectorLocs( 2886207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVectorImpl<SourceLocation> &SelLocs) const { 2887207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) 2888207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs.push_back(getSelectorLoc(i)); 2889207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis} 2890207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis 2891e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios KyrtzidisSourceRange ObjCMessageExpr::getReceiverRange() const { 2892e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis switch (getReceiverKind()) { 2893e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Instance: 2894e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getInstanceReceiver()->getSourceRange(); 2895e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2896e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Class: 2897e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getClassReceiverTypeInfo()->getTypeLoc().getSourceRange(); 2898e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2899e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperInstance: 2900e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperClass: 2901e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getSuperLoc(); 2902e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis } 2903e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2904e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return SourceLocation(); 2905e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis} 2906e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 290704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const { 290804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 290904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) 291004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ->getSelector(); 2911c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Selector(SelectorOrMethod); 291204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 291304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 291404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { 291504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor switch (getReceiverKind()) { 291604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Instance: 291704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 291804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) 291904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 292004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 29214df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 292204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Class: 2923c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *Ty 2924c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall = getClassReceiver()->getAs<ObjCObjectType>()) 2925c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return Ty->getInterface(); 292604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 29274df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 292804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperInstance: 292904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 293004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getSuperType()->getAs<ObjCObjectPointerType>()) 293104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 293204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 2933c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 293404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperClass: 2935ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis if (const ObjCObjectType *Iface 2936ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis = getSuperType()->getAs<ObjCObjectType>()) 2937ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis return Iface->getInterface(); 293804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 293904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 29400389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 294104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 2942eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek} 29430389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 29445f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringRef ObjCBridgedCastExpr::getBridgeKindName() const { 2945f85e193739c953358c865005855253af4f68a497John McCall switch (getBridgeKind()) { 2946f85e193739c953358c865005855253af4f68a497John McCall case OBC_Bridge: 2947f85e193739c953358c865005855253af4f68a497John McCall return "__bridge"; 2948f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeTransfer: 2949f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_transfer"; 2950f85e193739c953358c865005855253af4f68a497John McCall case OBC_BridgeRetained: 2951f85e193739c953358c865005855253af4f68a497John McCall return "__bridge_retained"; 2952f85e193739c953358c865005855253af4f68a497John McCall } 2953f85e193739c953358c865005855253af4f68a497John McCall 2954f85e193739c953358c865005855253af4f68a497John McCall return "__bridge"; 2955f85e193739c953358c865005855253af4f68a497John McCall} 2956f85e193739c953358c865005855253af4f68a497John McCall 29574ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ChooseExpr::isConditionTrue(const ASTContext &C) const { 29589a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getCond()->EvaluateAsInt(C) != 0; 295927437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 296027437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 2961bebbe0d9b7568ce43a464286bee49429489ef483Douglas GregorShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 2962bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor QualType Type, SourceLocation BLoc, 2963bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP) 2964bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, 2965bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 2966561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Type->isInstantiationDependentType(), 2967bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->containsUnexpandedParameterPack()), 2968bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) 2969bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor{ 2970bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExprs = new (C) Stmt*[nexpr]; 2971bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i < nexpr; i++) { 2972bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 2973bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 2974bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 2975bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 2976561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (args[i]->isInstantiationDependent()) 2977561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 2978bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 2979bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2980bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2981bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExprs[i] = args[i]; 2982bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 2983bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor} 2984bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2985888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 2986888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 2987888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 2988888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 2989888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 299094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 299194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 29921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 2993888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 2994f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 2995f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 2996f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 2997f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 2998f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 2999f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3000f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex) 3001f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3002f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getType(), 3003f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getValueKind(), 3004f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->getObjectKind(), 3005f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isTypeDependent(), 3006f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs[ResultIndex]->isValueDependent(), 3007561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor AssocExprs[ResultIndex]->isInstantiationDependent(), 3008f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 3009f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes(new (Context) TypeSourceInfo*[NumAssocs]), 3010f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs(new (Context) Stmt*[END_EXPR+NumAssocs]), NumAssocs(NumAssocs), 3011f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ResultIndex(ResultIndex), GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), 3012f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne RParenLoc(RParenLoc) { 3013f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 3014f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne std::copy(AssocTypes, AssocTypes+NumAssocs, this->AssocTypes); 3015f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne std::copy(AssocExprs, AssocExprs+NumAssocs, SubExprs+END_EXPR); 3016f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3017f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3018f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneGenericSelectionExpr::GenericSelectionExpr(ASTContext &Context, 3019f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3020f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3021f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3022f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3023f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack) 3024f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, 3025f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Context.DependentTy, 3026f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne VK_RValue, 3027f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne OK_Ordinary, 3028561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isTypeDependent=*/true, 3029561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isValueDependent=*/true, 3030561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*isInstantiationDependent=*/true, 3031f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ContainsUnexpandedParameterPack), 3032f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes(new (Context) TypeSourceInfo*[NumAssocs]), 3033f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs(new (Context) Stmt*[END_EXPR+NumAssocs]), NumAssocs(NumAssocs), 3034f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ResultIndex(-1U), GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), 3035f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne RParenLoc(RParenLoc) { 3036f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SubExprs[CONTROLLING] = ControllingExpr; 3037f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne std::copy(AssocTypes, AssocTypes+NumAssocs, this->AssocTypes); 3038f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne std::copy(AssocExprs, AssocExprs+NumAssocs, SubExprs+END_EXPR); 3039f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 3040f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 304177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 304205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 304305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 304405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3045b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler CarruthIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { 304605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 304705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 304805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 304905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 305005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 305105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 305205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3053c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, 3054319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesignators, 3055ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 30561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation EqualOrColonLoc, 3057ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 30581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **IndexExprs, 30599ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned NumIndexExprs, 30609ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 30611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(DesignatedInitExprClass, Ty, 3062f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Init->getValueKind(), Init->getObjectKind(), 3063bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->isTypeDependent(), Init->isValueDependent(), 3064561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Init->isInstantiationDependent(), 3065bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->containsUnexpandedParameterPack()), 30661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 30671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { 3068319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor this->Designators = new (C) Designator[NumDesignators]; 30699ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 30709ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 30717502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall child_range Child = children(); 30729ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 30739ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 30749ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 30759ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 30769ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 30779ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 3078ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 30799ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 30809ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 30819ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 30829ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 3083bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->isTypeDependent() || Index->isValueDependent()) 3084bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3085561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Index->isInstantiationDependent()) 3086561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3087bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3088bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->containsUnexpandedParameterPack()) 3089bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 30909ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 30919ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 30929ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 30939ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 30949ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 30959ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 30969ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 3097bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->isTypeDependent() || Start->isValueDependent() || 3098561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isTypeDependent() || End->isValueDependent()) { 3099bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3100561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3101561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } else if (Start->isInstantiationDependent() || 3102561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor End->isInstantiationDependent()) { 3103561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 3105561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 3106bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 3107bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->containsUnexpandedParameterPack() || 3108bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor End->containsUnexpandedParameterPack()) 3109bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 31109ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 31119ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 31129ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 31139ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 31149ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 31159ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 31169ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 31179ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); 3118ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3119ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 312005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 31211eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 312205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 312305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 312405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 312505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 3126c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 3127c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff sizeof(Stmt *) * (NumIndexExprs + 1), 8); 3128319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, 31299ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 31309ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor IndexExprs, NumIndexExprs, Init); 313105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 313205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 31331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 3134d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 3135d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 3136d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 3137d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 3138d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3139d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3140319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C, 3141319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor const Designator *Desigs, 3142d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 3143319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor Designators = new (C) Designator[NumDesigs]; 3144d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 3145d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 3146d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 3147d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 3148d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 314924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo BagnaraSourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { 315024f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this); 315124f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara if (size() == 1) 315224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return DIE->getDesignator(0)->getSourceRange(); 315324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(DIE->getDesignator(0)->getStartLocation(), 315424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara DIE->getDesignator(size()-1)->getEndLocation()); 315524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara} 315624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 315705c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const { 315805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 3159d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 3160d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 316105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 3162eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 316305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 316405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 316505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 316605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 3167d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 3168d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 316905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); 317005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 317105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 317205c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) { 317305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 317405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 317505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 317605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 317705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 317805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 317905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 318005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { 31811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 318205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 318305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 318405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 318505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 318605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 318705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 318805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 318905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { 31901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 319105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 319205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 319305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 319405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 319505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 319605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 319705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3198ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 3199ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 3200319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, 32011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Designator *First, 3202ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 3203ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 3204ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 3205ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 3206ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 3207ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 3208ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 3209ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3210ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 3211ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 3212ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 3213ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 3214ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 32151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator *NewDesignators 3216319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; 3217ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 3218ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 3219ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 3220ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 3221ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 3222ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 3223ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 3224ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 32251eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 32262ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Expr **exprs, unsigned nexprs, 32270d9106fc97cde979a995e26b18bcd2643f8afb55Manuel Klimek SourceLocation rparenloc, QualType T) 32280d9106fc97cde979a995e26b18bcd2643f8afb55Manuel Klimek : Expr(ParenListExprClass, T, VK_RValue, OK_Ordinary, 3229561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, false, false), 3230bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { 32310d9106fc97cde979a995e26b18bcd2643f8afb55Manuel Klimek assert(!T.isNull() && "ParenListExpr must have a valid type"); 32322ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs = new (C) Stmt*[nexprs]; 3233bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != nexprs; ++i) { 3234bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isTypeDependent()) 3235bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 3236bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isValueDependent()) 3237bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 3238561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (exprs[i]->isInstantiationDependent()) 3239561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 3240bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->containsUnexpandedParameterPack()) 3241bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 3242bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 32432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 3244bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 32452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 32462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 3247e996ffd240f20a1048179d7727a6ee3227261921John McCallconst OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { 3248e996ffd240f20a1048179d7727a6ee3227261921John McCall if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e)) 3249e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ewc->getSubExpr(); 325003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e)) 325103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor e = m->GetTemporaryExpr(); 3252e996ffd240f20a1048179d7727a6ee3227261921John McCall e = cast<CXXConstructExpr>(e)->getArg(0); 3253e996ffd240f20a1048179d7727a6ee3227261921John McCall while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 3254e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ice->getSubExpr(); 3255e996ffd240f20a1048179d7727a6ee3227261921John McCall return cast<OpaqueValueExpr>(e); 3256e996ffd240f20a1048179d7727a6ee3227261921John McCall} 3257e996ffd240f20a1048179d7727a6ee3227261921John McCall 325805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 3259ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 3260ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 3261ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3262ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 3263ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 3264ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 3265ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 3266ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 3267ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 3268ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 3269ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 3270ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 3271ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 327277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 327377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 327477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 3275f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne// UnaryExprOrTypeTraitExpr 3276f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneStmt::child_range UnaryExprOrTypeTraitExpr::children() { 32770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 32780518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 32790518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 32800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 3281f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const VariableArrayType* T = dyn_cast<VariableArrayType>( 32820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 328363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(T), child_iterator()); 328463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 32850518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 328663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Argument.Ex, &Argument.Ex + 1); 32879ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 3288390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 3289563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 329063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallStmt::child_range ObjCMessageExpr::children() { 329163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin; 329204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 329363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(this + 1); 329463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall else 329563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(getArgs()); 329663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, 329763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt **>(getArgs() + getNumArgs())); 3298563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 3299563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 33004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks 33016b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCallBlockDeclRefExpr::BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 3302a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor SourceLocation l, bool ByRef, 33036b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall bool constAdded) 3304561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(BlockDeclRefExprClass, t, VK, OK_Ordinary, false, false, false, 3305a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor d->isParameterPack()), 33066b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall D(d), Loc(l), IsByRef(ByRef), ConstQualAdded(constAdded) 3307a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor{ 3308d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool TypeDependent = false; 3309d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool ValueDependent = false; 3310561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent = false; 3311561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor computeDeclRefDependence(D, getType(), TypeDependent, ValueDependent, 3312561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent); 3313d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.TypeDependent = TypeDependent; 3314d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.ValueDependent = ValueDependent; 3315561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = InstantiationDependent; 3316a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor} 3317