Expr.cpp revision 82214a80c0163e01e4d8dec1426023c89277dbb4
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" 251b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 2608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Basic/SourceManager.h" 27da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h" 28cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor#include "llvm/Support/ErrorHandling.h" 293a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson#include "llvm/Support/raw_ostream.h" 30ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm> 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 332b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// isKnownToHaveBooleanValue - Return true if this is an integer expression 342b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// that is known to return 0 or 1. This happens for _Bool/bool expressions 352b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// but also int expressions which are produced by things like comparisons in 362b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// C. 372b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerbool Expr::isKnownToHaveBooleanValue() const { 382b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // If this value has _Bool type, it is obvious 0/1. 392b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (getType()->isBooleanType()) return true; 40c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // If this is a non-scalar-integer type, we don't care enough to try. 412ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (!getType()->isIntegralOrEnumerationType()) return false; 42c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 432b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) 442b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return PE->getSubExpr()->isKnownToHaveBooleanValue(); 45c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 462b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(this)) { 472b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (UO->getOpcode()) { 482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: 492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: 502b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return UO->getSubExpr()->isKnownToHaveBooleanValue(); 512b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: 522b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 532b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 542b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 55c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 566907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // Only look through implicit casts. If the user writes 576907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // '(int) (a && b)' treat it as an arbitrary int. 586907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(this)) 592b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CE->getSubExpr()->isKnownToHaveBooleanValue(); 60c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 612b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(this)) { 622b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (BO->getOpcode()) { 632b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: return false; 642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: // Relational operators. 652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: 662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: 672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: 682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: // Equality operators. 692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: 702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: // AND operator. 712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: // Logical OR operator. 722b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return true; 73c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: // Bitwise AND operator. 752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: // Bitwise XOR operator. 762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: // Bitwise OR operator. 772b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // Handle things like (x==2)|(y==12). 782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getLHS()->isKnownToHaveBooleanValue() && 792b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner BO->getRHS()->isKnownToHaveBooleanValue(); 80c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: 832b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getRHS()->isKnownToHaveBooleanValue(); 842b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 852b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 86c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 872b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(this)) 882b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CO->getTrueExpr()->isKnownToHaveBooleanValue() && 892b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner CO->getFalseExpr()->isKnownToHaveBooleanValue(); 90c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 912b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 922b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner} 932b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner 9463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// Amusing macro metaprogramming hack: check whether a class provides 9563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall// a more specific implementation of getExprLoc(). 9663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallnamespace { 9763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class provides a custom 9863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// implementation of getExprLoc. 9963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E, class T> 10063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 10163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (T::*v)() const) { 10263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return static_cast<const E*>(expr)->getExprLoc(); 10363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 10563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// This implementation is used when a class doesn't provide 10663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// a custom implementation of getExprLoc. Overload resolution 10763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// should pick it over the implementation above because it's 10863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall /// more specialized according to function template partial ordering. 10963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall template <class E> 11063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLocImpl(const Expr *expr, 11163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation (Expr::*v)() const) { 11263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return static_cast<const E*>(expr)->getSourceRange().getBegin(); 11363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 11463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 11563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 11663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallSourceLocation Expr::getExprLoc() const { 11763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall switch (getStmtClass()) { 11863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 11963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(type) 12063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define STMT(type, base) \ 12163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: llvm_unreachable(#type " is not an Expr"); break; 12263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define EXPR(type, base) \ 12363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); 12463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#include "clang/AST/StmtNodes.inc" 12563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 12663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall llvm_unreachable("unknown statement kind"); 12763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return SourceLocation(); 12863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} 12963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 134d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::initializeFrom( 135d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Info) { 136d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall LAngleLoc = Info.getLAngleLoc(); 137d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall RAngleLoc = Info.getRAngleLoc(); 138d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NumTemplateArgs = Info.size(); 139d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 140d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); 141d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall for (unsigned i = 0; i != NumTemplateArgs; ++i) 142d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); 143d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 144d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 145bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorvoid ExplicitTemplateArgumentList::initializeFrom( 146bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo &Info, 147bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool &Dependent, 148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool &ContainsUnexpandedParameterPack) { 149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor LAngleLoc = Info.getLAngleLoc(); 150bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor RAngleLoc = Info.getRAngleLoc(); 151bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor NumTemplateArgs = Info.size(); 152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); 154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != NumTemplateArgs; ++i) { 155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Dependent = Dependent || Info[i].getArgument().isDependent(); 156bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ContainsUnexpandedParameterPack 157bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor = ContainsUnexpandedParameterPack || 158bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Info[i].getArgument().containsUnexpandedParameterPack(); 159bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 160bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); 161bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 162bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor} 163bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 164d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::copyInto( 165d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo &Info) const { 166d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.setLAngleLoc(LAngleLoc); 167d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.setRAngleLoc(RAngleLoc); 168d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall for (unsigned I = 0; I != NumTemplateArgs; ++I) 169d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.addArgument(getTemplateArgs()[I]); 170d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 171d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1728dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidisstd::size_t ExplicitTemplateArgumentList::sizeFor(unsigned NumTemplateArgs) { 1738dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis return sizeof(ExplicitTemplateArgumentList) + 1748dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis sizeof(TemplateArgumentLoc) * NumTemplateArgs; 1758dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis} 1768dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 177d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallstd::size_t ExplicitTemplateArgumentList::sizeFor( 178d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Info) { 1798dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis return sizeFor(Info.size()); 180d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 181d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 182d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor/// \brief Compute the type- and value-dependence of a declaration reference 183d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor/// based on the declaration being referenced. 184d967e31ee796efff24b84b704a063634f6b55627Douglas Gregorstatic void computeDeclRefDependence(NamedDecl *D, QualType T, 185d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool &TypeDependent, 186d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool &ValueDependent) { 187d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = false; 188d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = false; 189c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1900da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 1910da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 1920da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An id-expression is type-dependent if it contains: 1930da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 194c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // and 1950da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 1960da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 1970da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An identifier is value-dependent if it is: 198d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 1990da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - an identifier that was declared with dependent type 2000da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a name declared with a dependent type, 201d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (T->isDependentType()) { 202d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 203d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 204d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 2050da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 206d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2070da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a conversion-function-id that specifies a dependent type 208d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (D->getDeclName().getNameKind() 209d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor == DeclarationName::CXXConversionFunctionName && 2100da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor D->getDeclName().getCXXNameType()->isDependentType()) { 211d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 212d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 213d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 2140da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 2150da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - the name of a non-type template parameter, 216d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<NonTypeTemplateParmDecl>(D)) { 217d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 218d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 219d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 220d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 2210da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a constant with integral or enumeration type and is 2220da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // initialized with an expression that is value-dependent. 223d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (VarDecl *Var = dyn_cast<VarDecl>(D)) { 2242ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (Var->getType()->isIntegralOrEnumerationType() && 225501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor Var->getType().getCVRQualifiers() == Qualifiers::Const) { 22631310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl if (const Expr *Init = Var->getAnyInitializer()) 227501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor if (Init->isValueDependent()) 228d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 229bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor } 230d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 231bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 232bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 233bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 234bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor else if (Var->isStaticDataMember() && 2357ed5bd3e27a6f2b37ee0449aa818116cbd03306eDouglas Gregor Var->getDeclContext()->isDependentContext()) 236d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 237d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 238d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 239d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 240d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 241bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 242bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 243bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 244d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) { 245d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 246d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor return; 247d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 248d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor} 249d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 250d967e31ee796efff24b84b704a063634f6b55627Douglas Gregorvoid DeclRefExpr::computeDependence() { 251d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool TypeDependent = false; 252d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool ValueDependent = false; 253d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor computeDeclRefDependence(getDecl(), getType(), TypeDependent, ValueDependent); 254d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 255d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 256d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An id-expression is type-dependent if it contains: 257d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 258d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // and 259d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // 260d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 261d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor // An identifier is value-dependent if it is: 262d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (!TypeDependent && !ValueDependent && 263d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor hasExplicitTemplateArgs() && 264d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TemplateSpecializationType::anyDependentTemplateArguments( 265d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor getTemplateArgs(), 266d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor getNumTemplateArgs())) { 267d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor TypeDependent = true; 268d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ValueDependent = true; 269d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor } 270d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 271d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.TypeDependent = TypeDependent; 272d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.ValueDependent = ValueDependent; 273d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor 27410738d36b150aa65206890c1c845cdba076e4200Douglas Gregor // Is the declaration a parameter pack? 275d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor if (getDecl()->isParameterPack()) 2761fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2770da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor} 2780da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 279c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, 280a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 281dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 282d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 283f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK) 284bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false), 285a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DecoratedD(D, 286a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor (Qualifier? HasQualifierFlag : 0) | 287d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), 288a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Loc(NameLoc) { 289a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (Qualifier) { 290a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *NQ = getNameQualifier(); 291a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NQ->NNS = Qualifier; 292a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NQ->Range = QualifierRange; 293a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 294c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 295d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 296096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().initializeFrom(*TemplateArgs); 297a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 2980da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 299a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 300a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3012577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, 3022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange QualifierRange, 3032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 3042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 305f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK) 306bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false), 3072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DecoratedD(D, 3082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara (Qualifier? HasQualifierFlag : 0) | 3092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), 3102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { 3112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (Qualifier) { 3122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameQualifier *NQ = getNameQualifier(); 3132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NQ->NNS = Qualifier; 3142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NQ->Range = QualifierRange; 3152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 3162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TemplateArgs) 318096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().initializeFrom(*TemplateArgs); 3192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara computeDependence(); 3212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 3222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 323a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 324a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 325a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 326dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 327a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 3280da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 329f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 3300da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs) { 3312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return Create(Context, Qualifier, QualifierRange, D, 3322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(D->getDeclName(), NameLoc), 333f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall T, VK, TemplateArgs); 3342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 3352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3362577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 3372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NestedNameSpecifier *Qualifier, 3382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange QualifierRange, 3392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 3402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 3412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T, 342f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 3432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 344a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor std::size_t Size = sizeof(DeclRefExpr); 345a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (Qualifier != 0) 346a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Size += sizeof(NameQualifier); 347c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 348d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 349d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); 350c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3513248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 3522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameInfo, 353f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TemplateArgs, T, VK); 354a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 355a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 356def0354384d9c4431f7b58b664b59896d4623028Douglas GregorDeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, 357def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasQualifier, 358def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasExplicitTemplateArgs, 359663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis unsigned NumTemplateArgs) { 360663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis std::size_t Size = sizeof(DeclRefExpr); 361663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (HasQualifier) 362663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis Size += sizeof(NameQualifier); 363663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 364def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor if (HasExplicitTemplateArgs) 365663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis Size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); 366663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 3673248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 368663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis return new (Mem) DeclRefExpr(EmptyShell()); 369663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis} 370663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 371a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorSourceRange DeclRefExpr::getSourceRange() const { 3722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange R = getNameInfo().getSourceRange(); 373a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (hasQualifier()) 374a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setBegin(getQualifierRange().getBegin()); 375096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 376a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setEnd(getRAngleLoc()); 377a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return R; 378a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 379a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 3803a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined 3813a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead. 382848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlssonstd::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 383848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson ASTContext &Context = CurrentDecl->getASTContext(); 384848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson 3853a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { 386848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) 3873a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return FD->getNameAsString(); 3883a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3893a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 3903a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 3913a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3923a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 393848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) 3943a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << "virtual "; 3954eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (MD->isStatic()) 3964eadcc569223135e13353c9381b448986e3f7053Sam Weinig Out << "static "; 3973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson PrintingPolicy Policy(Context.getLangOptions()); 4003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Proto = FD->getQualifiedNameAsString(Policy); 4023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 403183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *AFT = FD->getType()->getAs<FunctionType>(); 4043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const FunctionProtoType *FT = 0; 4053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->hasWrittenPrototype()) 4063a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FT = dyn_cast<FunctionProtoType>(AFT); 4073a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4083a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += "("; 4093a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT) { 4103a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_string_ostream POut(Proto); 4113a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { 4123a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (i) POut << ", "; 4133a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Param; 4143a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy); 4153a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << Param; 4163a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4173a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT->isVariadic()) { 4193a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->getNumParams()) POut << ", "; 4203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << "..."; 4213a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4223a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4233a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += ")"; 4243a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4254eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 4264eadcc569223135e13353c9381b448986e3f7053Sam Weinig Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers()); 4274eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasConst()) 4284eadcc569223135e13353c9381b448986e3f7053Sam Weinig Proto += " const"; 4294eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasVolatile()) 4304eadcc569223135e13353c9381b448986e3f7053Sam Weinig Proto += " volatile"; 4314eadcc569223135e13353c9381b448986e3f7053Sam Weinig } 4324eadcc569223135e13353c9381b448986e3f7053Sam Weinig 4333a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) 4343a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig AFT->getResultType().getAsStringInternal(Proto, Policy); 4353a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4363a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << Proto; 4373a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4383a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 4393a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 4403a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4413a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { 4423a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 4433a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 4443a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << (MD->isInstanceMethod() ? '-' : '+'); 4453a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '['; 446b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 447b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // For incorrect code, there might not be an ObjCInterfaceDecl. Do 448b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // a null check to avoid a crash. 449b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) 450900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer Out << ID; 451b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 4523a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCCategoryImplDecl *CID = 453900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) 454900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer Out << '(' << CID << ')'; 455900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 4563a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ' '; 4573a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getSelector().getAsString(); 4583a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ']'; 4593a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4603a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 4613a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 4623a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4633a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { 4643a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. 4653a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return "top level"; 4663a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 4673a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return ""; 4683a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 4693a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 4709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisvoid APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { 4719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (hasAllocation()) 4729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis C.Deallocate(pVal); 4739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis BitWidth = Val.getBitWidth(); 4759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = Val.getNumWords(); 4769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis const uint64_t* Words = Val.getRawData(); 4779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) { 4789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis pVal = new (C) uint64_t[NumWords]; 4799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis std::copy(Words, Words + NumWords, pVal); 4809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } else if (NumWords == 1) 4819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = Words[0]; 4829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 4839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = 0; 4849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 4879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, 4889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) { 4899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(C, V, type, l); 4909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 4939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { 4949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(Empty); 4959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 4989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, 4999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L) { 5009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(C, V, isexact, Type, L); 5019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 5039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 5049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { 5059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(Empty); 5069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 5079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 508da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 509da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 510da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 511da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 512da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 513ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 514ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 515ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 516da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 517da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 518da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 5192085fd6cd22ec5c268175251db10d7c60caf7aaaChris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData, 5202085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, 5212085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner QualType Ty, 5221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const SourceLocation *Loc, 523a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 5242085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 5252085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 5262085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 5272085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 5283248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 5292085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 5301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 5322085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner char *AStrData = new (C, 1) char[ByteLength]; 5332085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(AStrData, StrData, ByteLength); 5342085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->StrData = AStrData; 5352085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->ByteLength = ByteLength; 5362085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->IsWide = Wide; 5372085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 5382085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 540726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 5412085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 5422085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 543726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 544726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 545673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 546673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 547673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 5483248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 549673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 550673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->StrData = 0; 551673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->ByteLength = 0; 552673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 553673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 554673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 555673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 556b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbarvoid StringLiteral::setString(ASTContext &C, llvm::StringRef Str) { 557b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar char *AStrData = new (C, 1) char[Str.size()]; 558b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar memcpy(AStrData, Str.data(), Str.size()); 559673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StrData = AStrData; 560b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar ByteLength = Str.size(); 561673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 562673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 56308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// getLocationOfByte - Return a source location that points to the specified 56408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// byte of this string literal. 56508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 56608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// Strings are amazingly complex. They can be formed from multiple tokens and 56708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// can have escape sequences in them in addition to the usual trigraph and 56808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// escaped newline business. This routine handles this complexity. 56908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 57008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnerSourceLocation StringLiteral:: 57108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnergetLocationOfByte(unsigned ByteNo, const SourceManager &SM, 57208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, const TargetInfo &Target) const { 57308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner assert(!isWide() && "This doesn't work for wide strings yet"); 57408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 57508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Loop over all of the tokens in this string until we find the one that 57608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // contains the byte we're looking for. 57708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNo = 0; 57808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner while (1) { 57908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner assert(TokNo < getNumConcatenated() && "Invalid byte number!"); 58008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokLoc = getStrTokenLoc(TokNo); 58108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 58208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Get the spelling of the string so that we can get the data that makes up 58308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // the string literal, not the identifier for the macro it is potentially 58408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // expanded through. 58508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); 58608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 58708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Re-lex the token to get its length and original spelling. 58808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner std::pair<FileID, unsigned> LocInfo =SM.getDecomposedLoc(StrTokSpellingLoc); 58908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner bool Invalid = false; 59008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner llvm::StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); 59108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (Invalid) 59208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return StrTokSpellingLoc; 59308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 59408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const char *StrData = Buffer.data()+LocInfo.second; 59508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 59608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a langops struct and enable trigraphs. This is sufficient for 59708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // relexing tokens. 59808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner LangOptions LangOpts; 59908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner LangOpts.Trigraphs = true; 60008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 60108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a lexer starting at the beginning of this token. 60208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Lexer TheLexer(StrTokSpellingLoc, Features, Buffer.begin(), StrData, 60308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Buffer.end()); 60408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Token TheTok; 60508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner TheLexer.LexFromRawLexer(TheTok); 60608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 60708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Use the StringLiteralParser to compute the length of the string in bytes. 60808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner StringLiteralParser SLP(&TheTok, 1, SM, Features, Target); 60908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNumBytes = SLP.GetStringLength(); 61008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 61108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // If the byte is in this token, return the location of the byte. 61208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (ByteNo < TokNumBytes || 61308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner (ByteNo == TokNumBytes && TokNo == getNumConcatenated())) { 61408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); 61508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 61608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Now that we know the offset of the token in the spelling, use the 61708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // preprocessor to get the offset in the original source. 61808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); 61908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 62008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 62108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Move to the next string token. 62208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ++TokNo; 62308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ByteNo -= TokNumBytes; 62408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 62508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner} 62608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 62708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 62808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) { 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: assert(0 && "Unknown unary operator"); 6342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: return "++"; 6352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: return "--"; 6362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: return "++"; 6372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: return "--"; 6382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return "&"; 6392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return "*"; 6402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return "+"; 6412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return "-"; 6422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return "~"; 6432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return "!"; 6442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: return "__real"; 6452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: return "__imag"; 6462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: return "__extension__"; 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallUnaryOperatorKind 651bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 652bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 653bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: assert(false && "No unary operator for overloaded function"); 6542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc; 6552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; 6562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return UO_AddrOf; 6572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return UO_Deref; 6582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return UO_Plus; 6592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return UO_Minus; 6602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Tilde: return UO_Not; 6612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Exclaim: return UO_LNot; 662bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 663bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 664bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 665bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 666bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 6672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: case UO_PreInc: return OO_PlusPlus; 6682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: case UO_PreDec: return OO_MinusMinus; 6692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return OO_Amp; 6702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return OO_Star; 6712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return OO_Plus; 6722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return OO_Minus; 6732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return OO_Tilde; 6742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return OO_Exclaim; 675bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 676bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 677bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 678bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 679bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 684cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 685cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 686f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation rparenloc) 687f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(SC, t, VK, OK_Ordinary, 688bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 689bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 690bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 691898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 693cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[numargs+PREARGS_START+NumPreArgs]; 694b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 695bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != numargs; ++i) { 696bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 697bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 698bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 699bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 700bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 701bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 702bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 703cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START+NumPreArgs] = args[i]; 704bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 705668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 706cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 707b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 708b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 709e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 710668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 711f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation rparenloc) 712f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CallExprClass, t, VK, OK_Ordinary, 713bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isTypeDependent(), 714bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->isValueDependent(), 715bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor fn->containsUnexpandedParameterPack()), 716898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 717668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 718cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[numargs+PREARGS_START]; 71977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 720bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != numargs; ++i) { 721bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 722bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 723bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 724bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 725bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 726bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 727bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 728cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[i+PREARGS_START] = args[i]; 729bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 730668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 731cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 7361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 737bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // FIXME: Why do we allocate this? 738cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START]; 739cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = 0; 740cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne} 741cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 742cc324ad80ab940efca006b0064f7ca70a6181816Peter CollingbourneCallExpr::CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, 743cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne EmptyShell Empty) 744cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 745cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // FIXME: Why do we allocate this? 746cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs]; 747cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExprBits.NumPreArgs = NumPreArgs; 7481f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 7491f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 750d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() { 751a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu Expr *CEE = getCallee()->IgnoreParenCasts(); 752200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl // If we're calling a dereference, look at the pointer instead. 753200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { 754200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BO->isPtrMemOp()) 755200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = BO->getRHS()->IgnoreParenCasts(); 756200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { 757200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (UO->getOpcode() == UO_Deref) 758200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = UO->getSubExpr()->IgnoreParenCasts(); 759200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } 7606346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 761d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return DRE->getDecl(); 762cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) 763cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes return ME->getMemberDecl(); 764a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 765a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 766a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 767a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 768d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() { 769caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); 770d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes} 771d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 772d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 773d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 774d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 7758189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 776d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 777d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 7781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 779d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 780d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 781d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 782d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 783d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 784d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 785d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 786cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned NumPreArgs = getNumPreArgs(); 787cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; 788d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 789cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i) 790d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 791d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 792cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne for (unsigned i = getNumArgs()+PREARGS_START+NumPreArgs; 793cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne i != NumArgs+PREARGS_START+NumPreArgs; ++i) 794d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 79688c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 797d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 798d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 799d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 800d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 801cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 802cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 8034ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned CallExpr::isBuiltinCall(const ASTContext &Context) const { 804c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // function. As a result, we try and obtain the DeclRefExpr from the 806c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 807c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 808c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 809cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 8101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 811c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 812c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 813cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 8141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 815bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 816bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 817cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 8181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8194fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 8204fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 8214fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 8227814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor return FDecl->getBuiltinID(); 823cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 824bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 8256dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 8266dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 8276217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 8286dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 8296217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 8306dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 8315291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor else if (const MemberPointerType *MPT 8325291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor = CalleeType->getAs<MemberPointerType>()) 8335291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor CalleeType = MPT->getPointeeType(); 8345291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 835183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *FnType = CalleeType->getAs<FunctionType>(); 8366dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 8376dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 838cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 839c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, 8408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, 841c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TypeSourceInfo *tsi, 842c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 8438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 8448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 8458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 846c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt sizeof(OffsetOfNode) * numComps + 8478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 8488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 8498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps, 8508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor exprsPtr, numExprs, RParenLoc); 8518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 8528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 8538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, 8548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned numComps, unsigned numExprs) { 8558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 8568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(OffsetOfNode) * numComps + 8578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 8588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(numComps, numExprs); 8598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 8608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 861c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, 8628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 863c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 8648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 8658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) 866f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, 867f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent=*/false, 868bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent=*/tsi->getType()->isDependentType(), 869bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tsi->getType()->containsUnexpandedParameterPack()), 870c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), 871c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NumComps(numComps), NumExprs(numExprs) 8728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{ 8738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numComps; ++i) { 8748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setComponent(i, compsPtr[i]); 8758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 876c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numExprs; ++i) { 878bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprsPtr[i]->isTypeDependent() || exprsPtr[i]->isValueDependent()) 879bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 880bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprsPtr[i]->containsUnexpandedParameterPack()) 881bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 882bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 8838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setIndexExpr(i, exprsPtr[i]); 8848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 8858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 8868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 8878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { 8888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field || getKind() == Identifier); 8898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (getKind() == Field) 8908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getField()->getIdentifier(); 891c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); 8938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 8948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 8951eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *qual, 89783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor SourceRange qualrange, 898f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 899161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair founddecl, 9002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo nameinfo, 901d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 902f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, 903f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind vk, 904f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind ok) { 90583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 9066bb8017bb9e828d118e15e59d71c66bba323c364John McCall 907161755a09898c95d21bfff33707da9ca41cd53c5John McCall bool hasQualOrFound = (qual != 0 || 908161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getDecl() != memberdecl || 909161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getAccess() != memberdecl->getAccess()); 9106bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) 9116bb8017bb9e828d118e15e59d71c66bba323c364John McCall Size += sizeof(MemberNameQualifier); 9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 913d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 914d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Size += ExplicitTemplateArgumentList::sizeFor(*targs); 9151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9163248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); 917f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, 918f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ty, vk, ok); 9196bb8017bb9e828d118e15e59d71c66bba323c364John McCall 9206bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) { 9216bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (qual && qual->isDependent()) { 9226bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setValueDependent(true); 9236bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setTypeDependent(true); 9246bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 9256bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasQualifierOrFoundDecl = true; 9266bb8017bb9e828d118e15e59d71c66bba323c364John McCall 9276bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *NQ = E->getMemberQualifier(); 9286bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->NNS = qual; 9296bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->Range = qualrange; 9306bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->FoundDecl = founddecl; 9316bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 9326bb8017bb9e828d118e15e59d71c66bba323c364John McCall 9336bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (targs) { 9346bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasExplicitTemplateArgumentList = true; 935096832c5ed5b9106fa177ebc148489760c3bc496John McCall E->getExplicitTemplateArgs().initializeFrom(*targs); 9366bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 9376bb8017bb9e828d118e15e59d71c66bba323c364John McCall 9386bb8017bb9e828d118e15e59d71c66bba323c364John McCall return E; 93983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 94083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 941f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 942f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 943daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 944daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "Dependent"; 9452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BitCast: 946f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 9472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_LValueBitCast: 948e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor return "LValueBitCast"; 9490ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 9500ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall return "LValueToRValue"; 951f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall case CK_GetObjCProperty: 952f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return "GetObjCProperty"; 9532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NoOp: 954f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 9552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerived: 95611de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson return "BaseToDerived"; 9572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBase: 958f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 9592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UncheckedDerivedToBase: 96023cba801e11b03929c44f8cf54578305963a3476John McCall return "UncheckedDerivedToBase"; 9612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_Dynamic: 962f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 9632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToUnion: 964f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 9652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ArrayToPointerDecay: 966f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 9672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FunctionToPointerDecay: 968f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 9692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NullToMemberPointer: 970f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 971404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 972404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall return "NullToPointer"; 9732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerivedMemberPointer: 974f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 9752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBaseMemberPointer: 9761a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson return "DerivedToBaseMemberPointer"; 9772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UserDefinedConversion: 978f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 9792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ConstructorConversion: 980f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 9812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToPointer: 9827f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "IntegralToPointer"; 9832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_PointerToIntegral: 9847f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "PointerToIntegral"; 985daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 986daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "PointerToBoolean"; 9872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToVoid: 988ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson return "ToVoid"; 9892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_VectorSplat: 99016a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson return "VectorSplat"; 9912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralCast: 99282debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralCast"; 993daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 994daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "IntegralToBoolean"; 9952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToFloating: 99682debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralToFloating"; 9972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingToIntegral: 99882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "FloatingToIntegral"; 9992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingCast: 1000c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer return "FloatingCast"; 1001daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 1002daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "FloatingToBoolean"; 10032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_MemberPointerToBoolean: 1004bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson return "MemberPointerToBoolean"; 10052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_AnyPointerToObjCPointerCast: 10064cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian return "AnyPointerToObjCPointerCast"; 10072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_AnyPointerToBlockPointerCast: 10083b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian return "AnyPointerToBlockPointerCast"; 10092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ObjCObjectLValueCast: 1010569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return "ObjCObjectLValueCast"; 10112bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 10122bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingRealToComplex"; 1013f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 1014f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToReal"; 1015f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToBoolean: 1016f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToBoolean"; 10172bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 10182bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingComplexCast"; 1019f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 1020f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToIntegralComplex"; 10212bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 10222bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralRealToComplex"; 1023f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 1024f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToReal"; 1025f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToBoolean: 1026f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToBoolean"; 10272bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 10282bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralComplexCast"; 1029f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 1030f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToFloatingComplex"; 1031f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10332bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall llvm_unreachable("Unhandled cast kind!"); 1034f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return 0; 1035f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 1036f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 10376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() { 10386eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *SubExpr = 0; 10396eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor CastExpr *E = this; 10406eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor do { 10416eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = E->getSubExpr(); 1042c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 10436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Skip any temporary bindings; they're implicit. 10446eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) 10456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = Binder->getSubExpr(); 1046c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 10476eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Conversions by constructor and conversion functions have a 10486eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // subexpression describing the call; strip it off. 10492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (E->getCastKind() == CK_ConstructorConversion) 10506eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); 10512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall else if (E->getCastKind() == CK_UserDefinedConversion) 10526eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); 1053c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 10546eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // If the subexpression we're left with is an implicit cast, look 10556eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // through that, too. 1056c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); 1057c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 10586eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return SubExpr; 10596eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 10606eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 1061f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCXXBaseSpecifier **CastExpr::path_buffer() { 1062f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall switch (getStmtClass()) { 1063f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define ABSTRACT_STMT(x) 1064f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define CASTEXPR(Type, Base) \ 1065f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall case Stmt::Type##Class: \ 1066f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1); 1067f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define STMT(Type, Base) 1068f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#include "clang/AST/StmtNodes.inc" 1069f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall default: 1070f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall llvm_unreachable("non-cast expressions not possible here"); 1071f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return 0; 1072f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 1073f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1074f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1075f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallvoid CastExpr::setCastPath(const CXXCastPath &Path) { 1076f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(Path.size() == path_size()); 1077f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); 1078f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1079f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1080f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, 1081f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 1082f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 10835baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) { 1084f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1085f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1086f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1087f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr *E = 10885baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); 1089f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1090f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1091f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1092f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1093f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, 1094f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize) { 1095f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1096f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1097f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); 1098f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1099f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1100f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1101f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, 1102f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 1103f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 1104f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, 1105f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation L, SourceLocation R) { 1106f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 1107f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1108f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1109f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CStyleCastExpr *E = 1110f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); 1111f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 1112f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 1113f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1114f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1115f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { 1116f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 1117f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 1118f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); 1119f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 1120f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) { 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 11252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemD: return ".*"; 11262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemI: return "->*"; 11272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Mul: return "*"; 11282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Div: return "/"; 11292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Rem: return "%"; 11302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Add: return "+"; 11312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Sub: return "-"; 11322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shl: return "<<"; 11332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shr: return ">>"; 11342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: return "<"; 11352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: return ">"; 11362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: return "<="; 11372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: return ">="; 11382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: return "=="; 11392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: return "!="; 11402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: return "&"; 11412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: return "^"; 11422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: return "|"; 11432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: return "&&"; 11442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: return "||"; 11452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: return "="; 11462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_MulAssign: return "*="; 11472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_DivAssign: return "/="; 11482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_RemAssign: return "%="; 11492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AddAssign: return "+="; 11502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_SubAssign: return "-="; 11512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShlAssign: return "<<="; 11522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShrAssign: return ">>="; 11532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AndAssign: return "&="; 11542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_XorAssign: return "^="; 11552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_OrAssign: return "|="; 11562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: return ","; 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1158baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 1159baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor return ""; 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallBinaryOperatorKind 1163063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 1164063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 1165b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner default: assert(false && "Not an overloadable binary operator"); 11662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return BO_Add; 11672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return BO_Sub; 11682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return BO_Mul; 11692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Slash: return BO_Div; 11702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Percent: return BO_Rem; 11712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Caret: return BO_Xor; 11722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return BO_And; 11732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Pipe: return BO_Or; 11742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Equal: return BO_Assign; 11752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Less: return BO_LT; 11762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Greater: return BO_GT; 11772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusEqual: return BO_AddAssign; 11782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusEqual: return BO_SubAssign; 11792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_StarEqual: return BO_MulAssign; 11802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_SlashEqual: return BO_DivAssign; 11812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PercentEqual: return BO_RemAssign; 11822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_CaretEqual: return BO_XorAssign; 11832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpEqual: return BO_AndAssign; 11842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipeEqual: return BO_OrAssign; 11852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLess: return BO_Shl; 11862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreater: return BO_Shr; 11872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLessEqual: return BO_ShlAssign; 11882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreaterEqual: return BO_ShrAssign; 11892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_EqualEqual: return BO_EQ; 11902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ExclaimEqual: return BO_NE; 11912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessEqual: return BO_LE; 11922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterEqual: return BO_GE; 11932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpAmp: return BO_LAnd; 11942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipePipe: return BO_LOr; 11952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Comma: return BO_Comma; 11962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ArrowStar: return BO_PtrMemI; 1197063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 1198063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1199063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1200063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 1201063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 1202063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 1203063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 1204063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 1205063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 1206063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 1207063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 1208063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 1209063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 1210063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 1211063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 1212063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 1213063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 1214063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 1215063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 1216063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 1217063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 1218063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 1219063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 1220063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 1221063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 1222063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1223063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1224709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, 1225418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner Expr **initExprs, unsigned numInits, 12264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc) 1227bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, 1228bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false), 1229709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs(C, numInits), 12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0), 1231c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt UnionFieldInit(0), HadArrayRangeDesignator(false) 1232c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt{ 1233ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek for (unsigned I = 0; I != numInits; ++I) { 1234ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isTypeDependent()) 12358e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1236ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isValueDependent()) 12378e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1238bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (initExprs[I]->containsUnexpandedParameterPack()) 1239bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 124073460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor } 1241c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1242709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits); 124366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 12445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1245709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { 1246ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (NumInits > InitExprs.size()) 1247709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.reserve(C, NumInits); 1248fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 1249fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 1250709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { 1251709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.resize(C, NumInits, 0); 12524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 12534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1254709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { 1255ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (Init >= InitExprs.size()) { 1256709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); 1257ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek InitExprs.back() = expr; 1258ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return 0; 12594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 12601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 12624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 12634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 12644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 12654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1266c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted KremenekSourceRange InitListExpr::getSourceRange() const { 1267c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (SyntacticForm) 1268c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SyntacticForm->getSourceRange(); 1269c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek SourceLocation Beg = LBraceLoc, End = RBraceLoc; 1270c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Beg.isInvalid()) { 1271c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer. 1272c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_iterator I = InitExprs.begin(), 1273c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.end(); 1274c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1275c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1276c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek Beg = S->getLocStart(); 1277c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1278c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1279c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1280c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1281c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (End.isInvalid()) { 1282c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer from the end. 1283c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), 1284c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.rend(); 1285c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1286c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1287c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek End = S->getSourceRange().getEnd(); 1288c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1289c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1290c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1291c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1292c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SourceRange(Beg, End); 1293c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek} 1294c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 1295bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 12964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 12974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const { 12986217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<BlockPointerType>()-> 1299183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall getPointeeType()->getAs<FunctionType>(); 13004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 13014eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 13021eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const { 13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getCaretLocation(); 130456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const { 13067297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 13077297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() { 13091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getBody(); 13107297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 131156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 131256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1317026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 1318026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 1319026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 1320026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 1321026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattnerbool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 1322df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const { 1323ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 1324ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 1325ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 1326ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 13300faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 13310faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1332026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 1333026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1334026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 1336026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 1337df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump isUnusedResultAWarning(Loc, R1, R2, Ctx); 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 13401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 1342026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner default: break; 13432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: 13442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: 13452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: 13462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: // ++/-- 1347026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 13482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: 13495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Dereferencing a volatile pointer is a side-effect. 1350df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1351026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1352026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 13532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: 13542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: 13555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 1356df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) 1357df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump .isVolatileQualified()) 1358026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1359026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 13602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: 1361df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1363026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 1364026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 1365026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1367e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 1368026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 1369c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek switch (BO->getOpcode()) { 1370c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek default: 1371c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek break; 137225973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider the RHS of comma for side effects. LHS was checked by 137325973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Sema::CheckCommaOperands. 13742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 1375c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // ((foo = <blah>), 0) is an idiom for hiding the result (and 1376c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // lvalue-ness) of an assignment written in a macro. 1377c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IntegerLiteral *IE = 1378c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) 1379c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IE->getValue() == 0) 1380c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek return false; 138125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 138225973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider '||', '&&' to have side effects if the LHS or RHS does. 13832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: 13842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: 138525973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis if (!BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) || 138625973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis !BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) 138725973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return false; 138825973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis break; 1389bf0ee354163f87623a4b60412544243911332343John McCall } 1390026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 1391026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1392026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 1393026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 1394026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 1395026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1396e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 1397eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 1398c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor case VAArgExprClass: 1399026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 14005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1401ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 1402026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // The condition must be evaluated, but if either the LHS or RHS is a 1403026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // warning, warn about them. 1404ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Exp->getLHS() && 1406df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) 1407026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1408df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1409ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 1410ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 14115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 1412026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the base pointer or element is to a volatile pointer/field, accessing 1413026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 1414df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1415026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1416026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 1417026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 1418026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 1419026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the base pointer or element is to a volatile pointer/field, accessing 1423026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 1424df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1425026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1426026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 1427026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 1428026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 1429026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1430211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 1432852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXOperatorCallExprClass: 1433852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXMemberCallExprClass: { 1434026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 1435026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 1436d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes if (const Decl *FD = CE->getCalleeDecl()) { 1437026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 1438026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 1439bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // 1440bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // Note: If new cases are added here, DiagnoseUnusedExprResult should be 1441bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // updated to match for QoI. 1442bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (FD->getAttr<WarnUnusedResultAttr>() || 1443bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 1444bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner Loc = CE->getCallee()->getLocStart(); 1445bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R1 = CE->getCallee()->getSourceRange(); 1446bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner 1447bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 1448bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 1449bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 1450bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return true; 1451bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1452026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 1453026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1454026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 145558beed91d468863b8c85bce43425422703838d27Anders Carlsson 145658beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXTemporaryObjectExprClass: 145758beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXConstructExprClass: 145858beed91d468863b8c85bce43425422703838d27Anders Carlsson return false; 145958beed91d468863b8c85bce43425422703838d27Anders Carlsson 1460f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian case ObjCMessageExprClass: { 1461f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); 1462f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMethodDecl *MD = ME->getMethodDecl(); 1463f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 1464f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian Loc = getExprLoc(); 1465f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian return true; 1466f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 1467026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1468f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 14691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 147012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall case ObjCPropertyRefExprClass: 14715e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 14725e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 1473a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 147412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 1475611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 1476611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 1477611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 1478611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 1479611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 1480611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 1481611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 1482d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (!CS->body_empty()) { 1483611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 1484df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1485d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) 1486d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) 1487d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1488d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis } 14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14900faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 14910faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1492026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 1493026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1494026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1495611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 14966eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor case CStyleCastExprClass: 1497fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // If this is an explicit cast to void, allow it. People do this when they 1498fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // think they know what they're doing :). 1499026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (getType()->isVoidType()) 1500fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner return false; 1501026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); 1502026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); 1503026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 150458beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXFunctionalCastExprClass: { 15050faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 15060faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 150758beed91d468863b8c85bce43425422703838d27Anders Carlsson const CastExpr *CE = cast<CastExpr>(this); 1508c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 150958beed91d468863b8c85bce43425422703838d27Anders Carlsson // If this is a cast to void or a constructor conversion, check the operand. 151058beed91d468863b8c85bce43425422703838d27Anders Carlsson // Otherwise, the result of the cast is unused. 15112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (CE->getCastKind() == CK_ToVoid || 15122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall CE->getCastKind() == CK_ConstructorConversion) 1513df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CastExpr>(this)->getSubExpr() 1514df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 1515026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); 1516026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); 1517026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 151858beed91d468863b8c85bce43425422703838d27Anders Carlsson } 15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15204be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman case ImplicitCastExprClass: 15214be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman // Check the operand, since implicit casts are inserted by Sema 1522df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<ImplicitCastExpr>(this) 1523df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 15244be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 152504421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 1526df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXDefaultArgExpr>(this) 1527df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 15284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 15304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 15314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 15324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 1533026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 15342d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 1535df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXBindTemporaryExpr>(this) 1536df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 15374765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall case ExprWithCleanupsClass: 15384765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return (cast<ExprWithCleanups>(this) 1539df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 15404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 154344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 15447f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise. 1545102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 154644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian switch (getStmtClass()) { 154744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 154844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 154944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 155044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 1551207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 1552102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 155344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ParenExprClass: 1554102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 155544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 1556102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 155706b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 1558102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 1559a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { 156044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const Decl *D = cast<DeclRefExpr>(this)->getDecl(); 1561102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 1562102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 1563102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 1564102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 156559a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // dereferencing to a pointer is always a gc'able candidate, 156659a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // unless it is __weak. 15677e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar return T->isPointerType() && 15680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); 1569102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 157044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 157144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 157283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 157344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const MemberExpr *M = cast<MemberExpr>(this); 1574102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 157544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 157644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 1577102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx); 157844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 157944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 1580369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 158111ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidisbool Expr::isBoundMemberFunction(ASTContext &Ctx) const { 158211ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis if (isTypeDependent()) 158311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis return false; 15847eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; 158511ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis} 158611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 1587369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult MergeCanThrow(Expr::CanThrowResult CT1, 1588369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr::CanThrowResult CT2) { 1589369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // CanThrowResult constants are ordered so that the maximum is the correct 1590369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // merge result. 1591369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT1 > CT2 ? CT1 : CT2; 1592369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1593369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1594369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanSubExprsThrow(ASTContext &C, const Expr *CE) { 1595369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr *E = const_cast<Expr*>(CE); 1596369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr::CanThrowResult R = Expr::CT_Cannot; 15977502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall for (Expr::child_range I = E->children(); I && R != Expr::CT_Can; ++I) { 1598369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl R = MergeCanThrow(R, cast<Expr>(*I)->CanThrow(C)); 1599369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1600369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return R; 1601369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1602369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1603369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanCalleeThrow(const Decl *D, 1604369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl bool NullThrows = true) { 1605369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!D) 1606369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return NullThrows ? Expr::CT_Can : Expr::CT_Cannot; 1607369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1608369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // See if we can get a function type from the decl somehow. 1609369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const ValueDecl *VD = dyn_cast<ValueDecl>(D); 1610369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!VD) // If we have no clue what we're calling, assume the worst. 1611369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Can; 1612369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 16135221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl // As an extension, we assume that __attribute__((nothrow)) functions don't 16145221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl // throw. 16155221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl if (isa<FunctionDecl>(D) && D->hasAttr<NoThrowAttr>()) 16165221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl return Expr::CT_Cannot; 16175221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl 1618369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl QualType T = VD->getType(); 1619369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const FunctionProtoType *FT; 1620369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if ((FT = T->getAs<FunctionProtoType>())) { 1621369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } else if (const PointerType *PT = T->getAs<PointerType>()) 1622369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = PT->getPointeeType()->getAs<FunctionProtoType>(); 1623369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 1624369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = RT->getPointeeType()->getAs<FunctionProtoType>(); 1625369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl else if (const MemberPointerType *MT = T->getAs<MemberPointerType>()) 1626369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = MT->getPointeeType()->getAs<FunctionProtoType>(); 1627369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl else if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) 1628369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = BT->getPointeeType()->getAs<FunctionProtoType>(); 1629369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1630369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!FT) 1631369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Can; 1632369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1633369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return FT->hasEmptyExceptionSpec() ? Expr::CT_Cannot : Expr::CT_Can; 1634369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1635369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1636369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanDynamicCastThrow(const CXXDynamicCastExpr *DC) { 1637369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (DC->isTypeDependent()) 1638369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Dependent; 1639369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1640295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl if (!DC->getTypeAsWritten()->isReferenceType()) 1641295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl return Expr::CT_Cannot; 1642295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl 1643369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return DC->getCastKind() == clang::CK_Dynamic? Expr::CT_Can : Expr::CT_Cannot; 1644369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1645369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1646369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanTypeidThrow(ASTContext &C, 1647369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const CXXTypeidExpr *DC) { 1648369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (DC->isTypeOperand()) 1649369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1650369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1651369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr *Op = DC->getExprOperand(); 1652369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (Op->isTypeDependent()) 1653369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Dependent; 1654369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1655369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const RecordType *RT = Op->getType()->getAs<RecordType>(); 1656369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!RT) 1657369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1658369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1659369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!cast<CXXRecordDecl>(RT->getDecl())->isPolymorphic()) 1660369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1661369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1662369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (Op->Classify(C).isPRValue()) 1663369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1664369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1665369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Can; 1666369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1667369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1668369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian RedlExpr::CanThrowResult Expr::CanThrow(ASTContext &C) const { 1669369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // C++ [expr.unary.noexcept]p3: 1670369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // [Can throw] if in a potentially-evaluated context the expression would 1671369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // contain: 1672369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl switch (getStmtClass()) { 1673369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXThrowExprClass: 1674369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated throw-expression 1675369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Can; 1676369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1677369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDynamicCastExprClass: { 1678369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated dynamic_cast expression dynamic_cast<T>(v), 1679369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // where T is a reference type, that requires a run-time check 1680369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = CanDynamicCastThrow(cast<CXXDynamicCastExpr>(this)); 1681369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1682369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1683369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1684369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1685369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1686369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXTypeidExprClass: 1687369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated typeid expression applied to a glvalue 1688369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // expression whose type is a polymorphic class type 1689369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CanTypeidThrow(C, cast<CXXTypeidExpr>(this)); 1690369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1691369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated call to a function, member function, function 1692369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // pointer, or member function pointer that does not have a non-throwing 1693369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // exception-specification 1694369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CallExprClass: 1695369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXOperatorCallExprClass: 1696369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXMemberCallExprClass: { 1697369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = CanCalleeThrow(cast<CallExpr>(this)->getCalleeDecl()); 1698369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1699369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1700369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1701369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1702369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1703295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl case CXXConstructExprClass: 1704295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl case CXXTemporaryObjectExprClass: { 1705369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = CanCalleeThrow( 1706369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl cast<CXXConstructExpr>(this)->getConstructor()); 1707369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1708369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1709369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1710369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1711369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1712369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXNewExprClass: { 1713369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = MergeCanThrow( 1714369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanCalleeThrow(cast<CXXNewExpr>(this)->getOperatorNew()), 1715369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanCalleeThrow(cast<CXXNewExpr>(this)->getConstructor(), 1716369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /*NullThrows*/false)); 1717369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1718369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1719369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1720369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1721369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1722369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDeleteExprClass: { 1723369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = CanCalleeThrow( 1724369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl cast<CXXDeleteExpr>(this)->getOperatorDelete()); 1725369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1726369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 17270b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl const Expr *Arg = cast<CXXDeleteExpr>(this)->getArgument(); 17280b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl // Unwrap exactly one implicit cast, which converts all pointers to void*. 17290b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (const ImplicitCastExpr *Cast = dyn_cast<ImplicitCastExpr>(Arg)) 17300b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl Arg = Cast->getSubExpr(); 17310b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (const PointerType *PT = Arg->getType()->getAs<PointerType>()) { 17320b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) { 17330b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl CanThrowResult CT2 = CanCalleeThrow( 17340b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl cast<CXXRecordDecl>(RT->getDecl())->getDestructor()); 17350b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (CT2 == CT_Can) 17360b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl return CT2; 17370b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl CT = MergeCanThrow(CT, CT2); 17380b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl } 17390b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl } 17400b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 17410b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl } 17420b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl 17430b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl case CXXBindTemporaryExprClass: { 17440b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl // The bound temporary has to be destroyed again, which might throw. 17450b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl CanThrowResult CT = CanCalleeThrow( 17460b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl cast<CXXBindTemporaryExpr>(this)->getTemporary()->getDestructor()); 17470b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (CT == CT_Can) 17480b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl return CT; 1749369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1750369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1751369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1752369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // ObjC message sends are like function calls, but never have exception 1753369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // specs. 1754369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCMessageExprClass: 1755369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCPropertyRefExprClass: 1756369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Can; 1757369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1758369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Many other things have subexpressions, so we have to test those. 1759369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Some are simple: 1760369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ParenExprClass: 1761369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case MemberExprClass: 1762369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXReinterpretCastExprClass: 1763369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXConstCastExprClass: 1764369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ConditionalOperatorClass: 1765369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CompoundLiteralExprClass: 1766369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ExtVectorElementExprClass: 1767369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case InitListExprClass: 1768369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case DesignatedInitExprClass: 1769369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ParenListExprClass: 1770369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case VAArgExprClass: 1771369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDefaultArgExprClass: 17724765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall case ExprWithCleanupsClass: 1773369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCIvarRefExprClass: 1774369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCIsaExprClass: 1775369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ShuffleVectorExprClass: 1776369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CanSubExprsThrow(C, this); 1777369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1778369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Some might be dependent for other reasons. 1779369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case UnaryOperatorClass: 1780369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ArraySubscriptExprClass: 1781369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ImplicitCastExprClass: 1782369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CStyleCastExprClass: 1783369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXStaticCastExprClass: 1784369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXFunctionalCastExprClass: 1785369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case BinaryOperatorClass: 1786369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CompoundAssignOperatorClass: { 1787369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = isTypeDependent() ? CT_Dependent : CT_Cannot; 1788369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1789369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1790369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1791369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // FIXME: We should handle StmtExpr, but that opens a MASSIVE can of worms. 1792369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case StmtExprClass: 1793369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Can; 1794369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1795369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ChooseExprClass: 1796369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (isTypeDependent() || isValueDependent()) 1797369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Dependent; 1798369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return cast<ChooseExpr>(this)->getChosenSubExpr(C)->CanThrow(C); 1799369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1800369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Some expressions are always dependent. 1801369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case DependentScopeDeclRefExprClass: 1802369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXUnresolvedConstructExprClass: 1803369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDependentScopeMemberExprClass: 1804369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Dependent; 1805369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1806369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl default: 1807369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // All other expressions don't have subexpressions, or else they are 1808369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // unevaluated. 1809369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Cannot; 1810369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1811369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1812369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 18134e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 18144e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 1815b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara while (true) { 1816b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 1817b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1818b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1819b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1820b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 1821b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 1822b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1823b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1824b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1825b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1826b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 1827b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 18284e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 18294e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 183056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 183156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 183256f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 183356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 183456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 1835b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 183656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 1837b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1838b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1839b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (CastExpr *P = dyn_cast<CastExpr>(E)) { 184056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 1841b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1842b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1843b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 1844b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 1845b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1846b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1847b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1848b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1849b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 185056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 185156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 185256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 18539c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue 18549c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts. This is intended purely as a temporary workaround for code 18559c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// that hasn't yet been rewritten to do the right thing about those 18569c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall/// casts, and may disappear along with the last internal use. 1857f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallExpr *Expr::IgnoreParenLValueCasts() { 1858f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *E = this; 18599c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall while (true) { 1860f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 1861f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 1862f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 18639c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (CastExpr *P = dyn_cast<CastExpr>(E)) { 1864f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (P->getCastKind() == CK_LValueToRValue) { 1865f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = P->getSubExpr(); 1866f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 1867f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 18689c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } else if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 18699c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall if (P->getOpcode() == UO_Extension) { 18709c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall E = P->getSubExpr(); 18719c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall continue; 18729c5d70cee1fab3f988f9cd40316071b088a3f19dJohn McCall } 1873f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 1874f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 1875f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 1876f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return E; 1877f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 1878f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 18792fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() { 18802fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *E = this; 18812fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall while (true) { 1882b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 18832fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 1884b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1885b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1886b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) { 18872fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 1888b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1889b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1890b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 1891b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 1892b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1893b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1894b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1895b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1896b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 18972fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall } 18982fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall} 18992fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 1900ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 1901ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 1902ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 1903ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 1904ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 1905ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 1906ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 1907ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 1908ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1909ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 19101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1911ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 1912ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 19132ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor // ptr<->int casts of the same width. We also ignore all identity casts. 1914ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 19151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1916ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 1917ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1918ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1919ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 19201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1921b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if ((E->getType()->isPointerType() || 19229d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor E->getType()->isIntegralType(Ctx)) && 1923b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara (SE->getType()->isPointerType() || 19249d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor SE->getType()->isIntegralType(Ctx)) && 1925ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 1926ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1927ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1928ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1929ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 19301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1931b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 1932b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 1933b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1934b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1935b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1936b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1937b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara 1938ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 1939ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1940ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 1941ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 19426eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const { 19436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *E = this; 19446eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) 19456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor E = ICE->getSubExprAsWritten(); 1946c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 19476eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return isa<CXXDefaultArgExpr>(E); 19486eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 1949ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 19502f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding 19512f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions. 1952f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlssonstatic const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { 19532f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 19542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 19552f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 19562f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 19572f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 19582f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 19592f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 19602f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) 19612f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = BE->getSubExpr(); 19622f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 19632f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 19642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 19652f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 19662f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 19672f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 19682f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 1969f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson 1970f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson return E->IgnoreParens(); 19712f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 19722f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 1973558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// isTemporaryObject - Determines if this expression produces a 1974558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// temporary of the given class type. 1975558d2abc7f9fd6801cc7677200992313ae90b5d8John McCallbool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { 1976558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) 1977558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 19782f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 1979f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); 19802f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 198158277b57f9492d0234748be89bcad48b322c5cf7John McCall // Temporaries are by definition pr-values of class type. 1982db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian if (!E->Classify(C).isPRValue()) { 1983db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian // In this context, property reference is a message call and is pr-value. 198412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!isa<ObjCPropertyRefExpr>(E)) 1985db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian return false; 1986db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian } 19872f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 198819e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // Black-list a few cases which yield pr-values of class type that don't 198919e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // refer to temporaries of that type: 199019e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 199119e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - implicit derived-to-base conversions 1992558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (isa<ImplicitCastExpr>(E)) { 1993558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall switch (cast<ImplicitCastExpr>(E)->getCastKind()) { 1994558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_DerivedToBase: 1995558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_UncheckedDerivedToBase: 1996558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 1997558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall default: 1998558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall break; 1999558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 20002f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 20012f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 200219e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - member expressions (all) 200319e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall if (isa<MemberExpr>(E)) 200419e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall return false; 200519e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 200656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // - opaque values (all) 200756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (isa<OpaqueValueExpr>(E)) 200856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return false; 200956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 2010558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return true; 20112f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 20122f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 2013898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 2014898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 2015898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) { 2016898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 2017898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 2018898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 2019898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2020898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 2021898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2022898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2023898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyValueDependentArguments - Determines if any of the expressions 2024898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is value-dependent. 2025898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) { 2026898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 2027898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isValueDependent()) 2028898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 2029898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2030898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 2031898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2032898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 20334204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { 2034c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 2035c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 2036c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 2037c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 2038c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 2039c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 20404204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // If we ever capture reference-binding directly in the AST, we can 20414204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // kill the second parameter. 20424204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 20434204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (IsForRef) { 20444204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall EvalResult Result; 20454204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; 20464204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall } 20471f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 2048e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 2049c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 2050e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 205114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 2052eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 2053e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 2054b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXTemporaryObjectExprClass: 2055b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXConstructExprClass: { 2056b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 20574204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 20584204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // Only if it's 20594204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // 1) an application of the trivial default constructor or 2060b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall if (!CE->getConstructor()->isTrivial()) return false; 20614204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!CE->getNumArgs()) return true; 20624204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 20634204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // 2) an elidable trivial copy construction of an operand which is 20644204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // itself a constant initializer. Note that we consider the 20654204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // operand on its own, *not* as a reference binding. 20664204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return CE->isElidable() && 20674204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall CE->getArg(0)->isConstantInitializer(Ctx, false); 2068b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall } 206959b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 20701f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 20711f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 20721f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 207359b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 20744204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->isConstantInitializer(Ctx, false); 207559b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 2076e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 20771f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 20781f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 20791f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 2080e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 2081e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 2082e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 20834204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) 2084e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 2085e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2086c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 2087e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 20883498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 20893498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 20903ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case ParenExprClass: 20914204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<ParenExpr>(this)->getSubExpr() 20924204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, IsForRef); 20935cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara case ChooseExprClass: 20945cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx) 20955cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara ->isConstantInitializer(Ctx, IsForRef); 2096c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 2097c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 20982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == UO_Extension) 20994204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->getSubExpr()->isConstantInitializer(Ctx, false); 2100c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2101c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 21023ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case BinaryOperatorClass: { 21033ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // Special case &&foo - &&bar. It would be nice to generalize this somehow 21043ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // but this handles the common case. 21053ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner const BinaryOperator *Exp = cast<BinaryOperator>(this); 21062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == BO_Sub && 21073ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) && 21083ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx))) 21093ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner return true; 21103ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner break; 21113ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner } 21124204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall case CXXFunctionalCastExprClass: 2113b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXStaticCastExprClass: 211481045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 2115c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case CStyleCastExprClass: 2116c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // Handle casts with a destination that's a struct or union; this 2117c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // deals with both the gcc no-op struct cast extension and the 2118c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // cast-to-union extension. 2119c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman if (getType()->isRecordType()) 21204204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<CastExpr>(this)->getSubExpr() 21214204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, false); 2122c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2123430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // Integer->integer casts can be handled here, which is important for 2124430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // things like (int)(&&x-&&y). Scary but true. 2125430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner if (getType()->isIntegerType() && 2126430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType()) 21274204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<CastExpr>(this)->getSubExpr() 21284204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, false); 2129c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2130c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 2131e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 2132c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 213338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 213438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 213582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null 213682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// pointer constant or not, as well as the specific kind of constant detected. 213782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// Null pointer constants can be integer constant expressions with the 213882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// value zero, casts of zero to void*, nullptr (C++0X), or __null 213982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth/// (a GNU extension). 214082214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::NullPointerConstantKind 214182214a80c0163e01e4d8dec1426023c89277dbb4Chandler CarruthExpr::isNullPointerConstant(ASTContext &Ctx, 214282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const { 2143ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor if (isValueDependent()) { 2144ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor switch (NPC) { 2145ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_NeverValueDependent: 2146ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor assert(false && "Unexpected value dependent expression!"); 2147ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor // If the unthinkable happens, fall through to the safest alternative. 2148c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2149ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNull: 215082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth if (isTypeDependent() || getType()->isIntegralType(Ctx)) 215182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_ZeroInteger; 215282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth else 215382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 2154c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2155ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNotNull: 215682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 2157ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2158ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2159f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar 21600777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 21610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 21626215dee86c0e715b9f2b0d401ab2a5fcf629f1afSebastian Redl if (!Ctx.getLangOptions().CPlusPlus) { 21630777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 21646217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 21650777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 21660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Pointee.hasQualifiers() && 21670777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 21680777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 2169ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 21700777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 21715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2172aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 2173aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 2174ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 2175aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 2176aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 2177aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 2178ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 21791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (const CXXDefaultArgExpr *DefaultArg 21808123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 218104421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 2182ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); 21832d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 21842d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 218582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_GNUNull; 2186aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 21872d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 21886e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // C++0x nullptr_t is always a null pointer constant. 21896e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 219082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_CXX0X_nullptr; 21916e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 2192ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const RecordType *UT = getType()->getAsUnionType()) 2193ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) 2194ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ 2195ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian const Expr *InitExpr = CLE->getInitializer(); 2196ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) 2197ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); 2198ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian } 2199aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 2200c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (!getType()->isIntegerType() || 220156fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType())) 220282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return NPCK_NotNull; 22031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 22055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // test for the value 0. 220609de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman llvm::APSInt Result; 220782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth bool IsNull = isIntegerConstantExpr(Result, Ctx) && Result == 0; 220882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 220982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth return (IsNull ? NPCK_ZeroInteger : NPCK_NotNull); 22105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 221131a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 2212f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// \brief If this expression is an l-value for an Objective C 2213f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// property, find the underlying property reference expression. 2214f6a1648197562e0b133440d612d9af297d0a86ccJohn McCallconst ObjCPropertyRefExpr *Expr::getObjCProperty() const { 2215f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *E = this; 2216f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall while (true) { 2217f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall assert((E->getValueKind() == VK_LValue && 2218f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E->getObjectKind() == OK_ObjCProperty) && 2219f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall "expression is not a property reference"); 2220f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = E->IgnoreParenCasts(); 2221f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { 2222f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (BO->getOpcode() == BO_Comma) { 2223f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall E = BO->getRHS(); 2224f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall continue; 2225f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2226f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2227f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 2228f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall break; 2229f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 2230f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 2231f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return cast<ObjCPropertyRefExpr>(E); 2232f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall} 2233f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 223433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 22356f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 223633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 2237de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 2238f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall if (ICE->getCastKind() == CK_LValueToRValue || 2239f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) 2240de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor E = ICE->getSubExpr()->IgnoreParens(); 2241de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor else 2242de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor break; 2243de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor } 2244de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor 224527c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 224686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 224733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 224833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 224933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 22500f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) 22510f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) 22520f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (Field->isBitField()) 22530f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis return Field; 22540f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis 225533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) 225633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 225733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 225833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 225933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 226027c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 226127c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 2262093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const { 2263093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson const Expr *E = this->IgnoreParens(); 2264c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2265093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 22665baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall if (ICE->getValueKind() != VK_RValue && 22672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall ICE->getCastKind() == CK_NoOp) 2268093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson E = ICE->getSubExpr()->IgnoreParens(); 2269093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson else 2270093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson break; 2271093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson } 2272c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2273093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) 2274093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return ASE->getBase()->getType()->isVectorType(); 2275093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2276093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (isa<ExtVectorElementExpr>(E)) 2277093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return true; 2278093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2279093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return false; 2280093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson} 2281093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 22822140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 22832140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 22842140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 22852140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 22862140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 22872140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 2288213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 2289183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const VectorType *VT = getType()->getAs<VectorType>()) 22908a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 22918a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 22924d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 22934d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 22948a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 2295213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 2296a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // FIXME: Refactor this code to an accessor on the AST node which returns the 2297a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // "type" of component access, and share with code below and in Sema. 229801eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar llvm::StringRef Comp = Accessor->getName(); 2299190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 2300190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 2301150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") 2302190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 23031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2304190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 2305150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 2306150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar Comp = Comp.substr(1); 23071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2308150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar for (unsigned i = 0, e = Comp.size(); i != e; ++i) 2309150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp.substr(i + 1).find(Comp[i]) != llvm::StringRef::npos) 2310fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 2311150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar 2312fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 2313fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 2314b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 23158a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 23163b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 23173b8d116703db8018f855cbb4733ace426422623bNate Begeman llvm::SmallVectorImpl<unsigned> &Elts) const { 23184b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar llvm::StringRef Comp = Accessor->getName(); 23194b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 23204b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Comp = Comp.substr(1); 23211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23224b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isHi = Comp == "hi"; 23234b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isLo = Comp == "lo"; 23244b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isEven = Comp == "even"; 23254b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isOdd = Comp == "odd"; 23261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23278a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 23288a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 23291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23308a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 23318a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 23328a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 23338a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 23348a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 23358a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 23368a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 23378a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 23388a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 23394b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Index = ExtVectorType::getAccessorIdx(Comp[i]); 2340b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 23413b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 2342b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 23438a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 23448a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 234504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2346f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 234704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 234804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 234904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 235004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 2351c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2352f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelLoc, 235304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 235404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 235504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 2356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, 2357bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 2358bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 235904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs(NumArgs), Kind(IsInstanceSuper? SuperInstance : SuperClass), 236004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor HasMethod(Method != 0), SuperLoc(SuperLoc), 236104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 236204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2363f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 2364c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{ 236504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(SuperType.getAsOpaquePtr()); 236604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (NumArgs) 236704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); 236804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 236904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 237004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 237204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 237304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 2374f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 2375f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelLoc, 237604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 237704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 237804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 2379f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(), 2380bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor T->isDependentType(), T->containsUnexpandedParameterPack()), 238104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs(NumArgs), Kind(Class), HasMethod(Method != 0), 238204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 238304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2384f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 238504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 238604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 2387aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **MyArgs = getArgs(); 2388bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) { 2389bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isTypeDependent()) 2390bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 2391bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isValueDependent()) 2392bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 2393bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->containsUnexpandedParameterPack()) 2394bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2395bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2396bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor MyArgs[I] = Args[I]; 2397bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 239804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 239904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 240004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2401f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 240204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 240304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 2404c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2405f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelLoc, 240604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 240704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 240804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 2409f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(), 2410bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->isTypeDependent(), 2411bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Receiver->containsUnexpandedParameterPack()), 241204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs(NumArgs), Kind(Instance), HasMethod(Method != 0), 241304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 241404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2415f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SelectorLoc(SelLoc), LBracLoc(LBracLoc), RBracLoc(RBracLoc) 241604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 241704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 2418aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **MyArgs = getArgs(); 2419bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) { 2420bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isTypeDependent()) 2421bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 2422bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->isValueDependent()) 2423bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 2424bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[I]->containsUnexpandedParameterPack()) 2425bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2426bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2427bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor MyArgs[I] = Args[I]; 2428bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 242904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 243004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 243104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2432f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 243304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 243404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 243504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 243604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 2437c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2438f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelLoc, 243904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 244004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 244104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 2442c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 244304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 244404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 2445f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper, 2446f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SuperType, Sel, SelLoc, Method, Args,NumArgs, 244704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor RBracLoc); 244804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 244904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 245004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2451f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 245204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 245304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 2454c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 2455f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelLoc, 245604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 245704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 245804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 2459c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 246004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 246104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 2462f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, SelLoc, 2463f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Method, Args, NumArgs, RBracLoc); 246404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 246504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 246604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2467f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 246804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 246904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 2470f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Selector Sel, 2471f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelLoc, 247204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 247304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 247404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 2475c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 247604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 247704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 2478f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, SelLoc, 2479f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Method, Args, NumArgs, RBracLoc); 248004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 248104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 2482c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, 248304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor unsigned NumArgs) { 2484c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 248504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 248604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 248704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); 248804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 2489e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2490e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios KyrtzidisSourceRange ObjCMessageExpr::getReceiverRange() const { 2491e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis switch (getReceiverKind()) { 2492e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Instance: 2493e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getInstanceReceiver()->getSourceRange(); 2494e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2495e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case Class: 2496e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getClassReceiverTypeInfo()->getTypeLoc().getSourceRange(); 2497e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2498e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperInstance: 2499e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis case SuperClass: 2500e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return getSuperLoc(); 2501e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis } 2502e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 2503e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis return SourceLocation(); 2504e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis} 2505e005d19456e6fb73ace33f25e02ac10e22dd063fArgyrios Kyrtzidis 250604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const { 250704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 250804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) 250904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ->getSelector(); 2510c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Selector(SelectorOrMethod); 251104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 251204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 251304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { 251404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor switch (getReceiverKind()) { 251504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Instance: 251604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 251704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) 251804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 251904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 25204df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 252104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Class: 2522c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *Ty 2523c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall = getClassReceiver()->getAs<ObjCObjectType>()) 2524c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return Ty->getInterface(); 252504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 25264df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 252704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperInstance: 252804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 252904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getSuperType()->getAs<ObjCObjectPointerType>()) 253004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 253104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 2532c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 253304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperClass: 2534ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis if (const ObjCObjectType *Iface 2535ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis = getSuperType()->getAs<ObjCObjectType>()) 2536ee8a6cafe8b69c316dd4fa5f6ea4838ffe15621cArgyrios Kyrtzidis return Iface->getInterface(); 253704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 253804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 25390389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 254004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 2541eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek} 25420389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 25434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ChooseExpr::isConditionTrue(const ASTContext &C) const { 25449a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getCond()->EvaluateAsInt(C) != 0; 254527437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 254627437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 2547bebbe0d9b7568ce43a464286bee49429489ef483Douglas GregorShuffleVectorExpr::ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 2548bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor QualType Type, SourceLocation BLoc, 2549bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP) 2550bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, 2551bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 2552bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->containsUnexpandedParameterPack()), 2553bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) 2554bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor{ 2555bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExprs = new (C) Stmt*[nexpr]; 2556bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i < nexpr; i++) { 2557bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isTypeDependent()) 2558bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 2559bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->isValueDependent()) 2560bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 2561bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (args[i]->containsUnexpandedParameterPack()) 2562bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2563bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2564bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExprs[i] = args[i]; 2565bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 2566bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor} 2567bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2568888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 2569888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 2570888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 2571888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 2572888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 257394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 257494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 25751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 2576888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 257777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 257805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 257905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 258005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 258105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() { 258205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 258305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 258405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 258505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 258605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 258705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 258805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2589c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, 2590319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesignators, 2591ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 25921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation EqualOrColonLoc, 2593ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 25941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **IndexExprs, 25959ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned NumIndexExprs, 25969ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 25971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(DesignatedInitExprClass, Ty, 2598f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Init->getValueKind(), Init->getObjectKind(), 2599bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->isTypeDependent(), Init->isValueDependent(), 2600bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Init->containsUnexpandedParameterPack()), 26011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 26021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { 2603319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor this->Designators = new (C) Designator[NumDesignators]; 26049ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 26059ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 26067502c1d3ce8bb97bcc4f7bebef507040bd93b26fJohn McCall child_range Child = children(); 26079ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 26089ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 26099ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 26109ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 26119ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 26129ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 2613ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 26149ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 26159ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 26169ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 26179ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 2618bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->isTypeDependent() || Index->isValueDependent()) 2619bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 2620bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2621bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 2622bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Index->containsUnexpandedParameterPack()) 2623bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 26249ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 26259ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 26269ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 26279ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 26289ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 26299ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 26309ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 2631bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->isTypeDependent() || Start->isValueDependent() || 2632bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor End->isTypeDependent() || End->isValueDependent()) 2633bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 2634bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2635bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor // Propagate unexpanded parameter packs. 2636bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Start->containsUnexpandedParameterPack() || 2637bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor End->containsUnexpandedParameterPack()) 2638bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 26399ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 26409ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 26419ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 26429ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 26439ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 26449ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 26459ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 26469ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); 2647ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 2648ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 264905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 26501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 265105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 265205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 265305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 265405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 2655c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 2656c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff sizeof(Stmt *) * (NumIndexExprs + 1), 8); 2657319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, 26589ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 26599ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor IndexExprs, NumIndexExprs, Init); 266005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 266105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 26621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 2663d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 2664d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 2665d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 2666d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 2667d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 2668d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2669319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C, 2670319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor const Designator *Desigs, 2671d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 2672319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor Designators = new (C) Designator[NumDesigs]; 2673d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 2674d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 2675d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 2676d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 2677d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 267805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const { 267905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 2680d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 2681d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 268205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 2683eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 268405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 268505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 268605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 268705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 2688d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 2689d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 269005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); 269105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 269205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 269305c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) { 269405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 269505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 269605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 269705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 269805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 269905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 270005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 270105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { 27021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 270305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 270405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 270505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 270605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 270705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 270805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 270905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 271005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { 27111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 271205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 271305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 271405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 271505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 271605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 271705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 271805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2719ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 2720ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 2721319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, 27221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Designator *First, 2723ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 2724ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 2725ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 2726ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 2727ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 2728ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 2729ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 2730ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 2731ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 2732ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 2733ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 2734ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 2735ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 27361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator *NewDesignators 2737319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; 2738ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 2739ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 2740ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 2741ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 2742ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 2743ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 2744ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 2745ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 27461eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 27472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Expr **exprs, unsigned nexprs, 27482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation rparenloc) 2749bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, 2750bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, false, false), 2751bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { 27521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs = new (C) Stmt*[nexprs]; 2754bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor for (unsigned i = 0; i != nexprs; ++i) { 2755bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isTypeDependent()) 2756bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.TypeDependent = true; 2757bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->isValueDependent()) 2758bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ValueDependent = true; 2759bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (exprs[i]->containsUnexpandedParameterPack()) 2760bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = true; 2761bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 27622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 2763bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 27642ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 27652ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 2766e996ffd240f20a1048179d7727a6ee3227261921John McCallconst OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { 2767e996ffd240f20a1048179d7727a6ee3227261921John McCall if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e)) 2768e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ewc->getSubExpr(); 2769e996ffd240f20a1048179d7727a6ee3227261921John McCall e = cast<CXXConstructExpr>(e)->getArg(0); 2770e996ffd240f20a1048179d7727a6ee3227261921John McCall while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 2771e996ffd240f20a1048179d7727a6ee3227261921John McCall e = ice->getSubExpr(); 2772e996ffd240f20a1048179d7727a6ee3227261921John McCall return cast<OpaqueValueExpr>(e); 2773e996ffd240f20a1048179d7727a6ee3227261921John McCall} 2774e996ffd240f20a1048179d7727a6ee3227261921John McCall 277505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 2776ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 2777ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 2778ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 2779ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 2780ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 2781ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 2782ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 2783ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 2784ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 2785ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 2786ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 2787ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 2788ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 278977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 279077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 279177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 27920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl// SizeOfAlignOfExpr 279363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallStmt::child_range SizeOfAlignOfExpr::children() { 27940518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 27950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 27960518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 27970518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 2798f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const VariableArrayType* T = dyn_cast<VariableArrayType>( 27990518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 280063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(child_iterator(T), child_iterator()); 280163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(); 28020518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 280363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Argument.Ex, &Argument.Ex + 1); 28049ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 2805390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 2806563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 280763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCallStmt::child_range ObjCMessageExpr::children() { 280863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin; 280904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 281063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(this + 1); 281163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall else 281263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall begin = reinterpret_cast<Stmt **>(getArgs()); 281363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, 281463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt **>(getArgs() + getNumArgs())); 2815563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2816563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 28174eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks 28186b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCallBlockDeclRefExpr::BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 2819a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor SourceLocation l, bool ByRef, 28206b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall bool constAdded) 2821d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor : Expr(BlockDeclRefExprClass, t, VK, OK_Ordinary, false, false, 2822a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor d->isParameterPack()), 28236b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall D(d), Loc(l), IsByRef(ByRef), ConstQualAdded(constAdded) 2824a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor{ 2825d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool TypeDependent = false; 2826d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor bool ValueDependent = false; 2827d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor computeDeclRefDependence(D, getType(), TypeDependent, ValueDependent); 2828d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.TypeDependent = TypeDependent; 2829d967e31ee796efff24b84b704a063634f6b55627Douglas Gregor ExprBits.ValueDependent = ValueDependent; 2830a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor} 2831a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 2832