Expr.cpp revision 4204f07fc8bffe6d320b2de95fea274ccf37a17b
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" 231b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 24da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h" 25cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor#include "llvm/Support/ErrorHandling.h" 263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson#include "llvm/Support/raw_ostream.h" 27ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm> 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 30bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattnervoid Expr::ANCHOR() {} // key function for Expr class. 31bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner 322b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// isKnownToHaveBooleanValue - Return true if this is an integer expression 332b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// that is known to return 0 or 1. This happens for _Bool/bool expressions 342b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// but also int expressions which are produced by things like comparisons in 352b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// C. 362b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerbool Expr::isKnownToHaveBooleanValue() const { 372b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // If this value has _Bool type, it is obvious 0/1. 382b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (getType()->isBooleanType()) return true; 39c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // If this is a non-scalar-integer type, we don't care enough to try. 402ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (!getType()->isIntegralOrEnumerationType()) return false; 41c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 422b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) 432b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return PE->getSubExpr()->isKnownToHaveBooleanValue(); 44c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 452b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(this)) { 462b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (UO->getOpcode()) { 472b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case UnaryOperator::Plus: 482b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case UnaryOperator::Extension: 492b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return UO->getSubExpr()->isKnownToHaveBooleanValue(); 502b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: 512b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 522b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 532b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 54c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 556907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // Only look through implicit casts. If the user writes 566907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // '(int) (a && b)' treat it as an arbitrary int. 576907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(this)) 582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CE->getSubExpr()->isKnownToHaveBooleanValue(); 59c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 602b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(this)) { 612b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (BO->getOpcode()) { 622b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: return false; 632b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::LT: // Relational operators. 642b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::GT: 652b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::LE: 662b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::GE: 672b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::EQ: // Equality operators. 682b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::NE: 692b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::LAnd: // AND operator. 702b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::LOr: // Logical OR operator. 712b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return true; 72c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 732b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::And: // Bitwise AND operator. 742b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::Xor: // Bitwise XOR operator. 752b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::Or: // Bitwise OR operator. 762b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // Handle things like (x==2)|(y==12). 772b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getLHS()->isKnownToHaveBooleanValue() && 782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner BO->getRHS()->isKnownToHaveBooleanValue(); 79c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 802b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::Comma: 812b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner case BinaryOperator::Assign: 822b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getRHS()->isKnownToHaveBooleanValue(); 832b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 842b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 85c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 862b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(this)) 872b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CO->getTrueExpr()->isKnownToHaveBooleanValue() && 882b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner CO->getFalseExpr()->isKnownToHaveBooleanValue(); 89c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 902b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 912b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner} 922b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 97d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::initializeFrom( 98d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Info) { 99d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall LAngleLoc = Info.getLAngleLoc(); 100d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall RAngleLoc = Info.getRAngleLoc(); 101d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NumTemplateArgs = Info.size(); 102d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 103d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); 104d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall for (unsigned i = 0; i != NumTemplateArgs; ++i) 105d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); 106d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 107d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 108d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::copyInto( 109d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo &Info) const { 110d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.setLAngleLoc(LAngleLoc); 111d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.setRAngleLoc(RAngleLoc); 112d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall for (unsigned I = 0; I != NumTemplateArgs; ++I) 113d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.addArgument(getTemplateArgs()[I]); 114d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 115d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1168dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidisstd::size_t ExplicitTemplateArgumentList::sizeFor(unsigned NumTemplateArgs) { 1178dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis return sizeof(ExplicitTemplateArgumentList) + 1188dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis sizeof(TemplateArgumentLoc) * NumTemplateArgs; 1198dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis} 1208dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 121d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallstd::size_t ExplicitTemplateArgumentList::sizeFor( 122d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Info) { 1238dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis return sizeFor(Info.size()); 124d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 125d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1260da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregorvoid DeclRefExpr::computeDependence() { 1270da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TypeDependent = false; 1280da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = false; 129c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1300da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor NamedDecl *D = getDecl(); 1310da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 1320da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 1330da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An id-expression is type-dependent if it contains: 1340da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 135c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // and 1360da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 1370da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 1380da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An identifier is value-dependent if it is: 1390da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 1400da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - an identifier that was declared with dependent type 1410da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a name declared with a dependent type, 1420da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor if (getType()->isDependentType()) { 1430da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TypeDependent = true; 1440da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = true; 1450da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 1460da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a conversion-function-id that specifies a dependent type 147c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt else if (D->getDeclName().getNameKind() 1480da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor == DeclarationName::CXXConversionFunctionName && 1490da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor D->getDeclName().getCXXNameType()->isDependentType()) { 1500da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TypeDependent = true; 1510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = true; 1520da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 1530da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a template-id that is dependent, 154c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt else if (hasExplicitTemplateArgumentList() && 1550da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TemplateSpecializationType::anyDependentTemplateArguments( 156c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt getTemplateArgs(), 1570da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor getNumTemplateArgs())) { 1580da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TypeDependent = true; 1590da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = true; 1600da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 1610da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - the name of a non-type template parameter, 1620da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor else if (isa<NonTypeTemplateParmDecl>(D)) 1630da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = true; 1640da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a constant with integral or enumeration type and is 1650da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // initialized with an expression that is value-dependent. 1660da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor else if (VarDecl *Var = dyn_cast<VarDecl>(D)) { 1672ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (Var->getType()->isIntegralOrEnumerationType() && 168501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor Var->getType().getCVRQualifiers() == Qualifiers::Const) { 16931310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl if (const Expr *Init = Var->getAnyInitializer()) 170501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor if (Init->isValueDependent()) 171501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor ValueDependent = true; 172bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor } 173bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 174bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 175bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 176bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor else if (Var->isStaticDataMember() && 1777ed5bd3e27a6f2b37ee0449aa818116cbd03306eDouglas Gregor Var->getDeclContext()->isDependentContext()) 178bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor ValueDependent = true; 179bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor } 180bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 181bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 182bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 183bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor else if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) 184bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor ValueDependent = true; 1850da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a nested-name-specifier or a qualified-id that names a 1860da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // member of an unknown specialization. 1870da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (handled by DependentScopeDeclRefExpr) 1880da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor} 1890da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 190c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, 191a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 192dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 193d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 1940da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T) 1950da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor : Expr(DeclRefExprClass, T, false, false), 196a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DecoratedD(D, 197a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor (Qualifier? HasQualifierFlag : 0) | 198d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), 199a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Loc(NameLoc) { 200a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (Qualifier) { 201a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *NQ = getNameQualifier(); 202a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NQ->NNS = Qualifier; 203a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NQ->Range = QualifierRange; 204a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 205c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 206d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 207d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs); 208a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 2090da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 210a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 211a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 212a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 213a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 214a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 215dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 216a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 2170da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 2180da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs) { 219a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor std::size_t Size = sizeof(DeclRefExpr); 220a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (Qualifier != 0) 221a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Size += sizeof(NameQualifier); 222c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 223d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 224d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); 225c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 226a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>()); 227a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameLoc, 2280da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TemplateArgs, T); 229a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 230a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 231663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios KyrtzidisDeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, bool HasQualifier, 232663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis unsigned NumTemplateArgs) { 233663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis std::size_t Size = sizeof(DeclRefExpr); 234663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (HasQualifier) 235663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis Size += sizeof(NameQualifier); 236663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 237663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (NumTemplateArgs) 238663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis Size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); 239663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 240663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>()); 241663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis return new (Mem) DeclRefExpr(EmptyShell()); 242663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis} 243663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 244a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorSourceRange DeclRefExpr::getSourceRange() const { 245a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // FIXME: Does not handle multi-token names well, e.g., operator[]. 246a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange R(Loc); 247c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 248a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (hasQualifier()) 249a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setBegin(getQualifierRange().getBegin()); 250a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (hasExplicitTemplateArgumentList()) 251a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setEnd(getRAngleLoc()); 252a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return R; 253a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 254a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 2553a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined 2563a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead. 257848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlssonstd::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 258848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson ASTContext &Context = CurrentDecl->getASTContext(); 259848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson 2603a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { 261848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) 2623a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return FD->getNameAsString(); 2633a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2643a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 2653a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 2663a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2673a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 268848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) 2693a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << "virtual "; 2704eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (MD->isStatic()) 2714eadcc569223135e13353c9381b448986e3f7053Sam Weinig Out << "static "; 2723a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2733a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson PrintingPolicy Policy(Context.getLangOptions()); 2753a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Proto = FD->getQualifiedNameAsString(Policy); 2773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 278183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *AFT = FD->getType()->getAs<FunctionType>(); 2793a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const FunctionProtoType *FT = 0; 2803a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->hasWrittenPrototype()) 2813a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FT = dyn_cast<FunctionProtoType>(AFT); 2823a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2833a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += "("; 2843a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT) { 2853a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_string_ostream POut(Proto); 2863a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { 2873a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (i) POut << ", "; 2883a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Param; 2893a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy); 2903a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << Param; 2913a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2923a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2933a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT->isVariadic()) { 2943a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->getNumParams()) POut << ", "; 2953a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << "..."; 2963a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += ")"; 2993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3004eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 3014eadcc569223135e13353c9381b448986e3f7053Sam Weinig Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers()); 3024eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasConst()) 3034eadcc569223135e13353c9381b448986e3f7053Sam Weinig Proto += " const"; 3044eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasVolatile()) 3054eadcc569223135e13353c9381b448986e3f7053Sam Weinig Proto += " volatile"; 3064eadcc569223135e13353c9381b448986e3f7053Sam Weinig } 3074eadcc569223135e13353c9381b448986e3f7053Sam Weinig 3083a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) 3093a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig AFT->getResultType().getAsStringInternal(Proto, Policy); 3103a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3113a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << Proto; 3123a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3133a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 3143a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 3153a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3163a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { 3173a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 3183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 3193a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << (MD->isInstanceMethod() ? '-' : '+'); 3203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '['; 321b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 322b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // For incorrect code, there might not be an ObjCInterfaceDecl. Do 323b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // a null check to avoid a crash. 324b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) 325900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer Out << ID; 326b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 3273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCCategoryImplDecl *CID = 328900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) 329900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer Out << '(' << CID << ')'; 330900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 3313a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ' '; 3323a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getSelector().getAsString(); 3333a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ']'; 3343a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3353a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 3363a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 3373a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3383a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { 3393a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. 3403a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return "top level"; 3413a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3423a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return ""; 3433a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 3443a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 345da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 346da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 347da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 348da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 349da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 350ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 351ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 352ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 353da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 354da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 355da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 3562085fd6cd22ec5c268175251db10d7c60caf7aaaChris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData, 3572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, 3582085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner QualType Ty, 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const SourceLocation *Loc, 360a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 3612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 3622085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 3632085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 3642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 3652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner llvm::alignof<StringLiteral>()); 3662085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 3692085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner char *AStrData = new (C, 1) char[ByteLength]; 3702085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(AStrData, StrData, ByteLength); 3712085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->StrData = AStrData; 3722085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->ByteLength = ByteLength; 3732085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->IsWide = Wide; 3742085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 3752085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 377726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 3782085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 3792085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 380726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 381726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 382673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 383673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 384673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 385673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor llvm::alignof<StringLiteral>()); 386673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 387673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->StrData = 0; 388673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->ByteLength = 0; 389673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 390673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 391673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 392673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 393b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbarvoid StringLiteral::setString(ASTContext &C, llvm::StringRef Str) { 394b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar char *AStrData = new (C, 1) char[Str.size()]; 395b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar memcpy(AStrData, Str.data(), Str.size()); 396673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StrData = AStrData; 397b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar ByteLength = Str.size(); 398673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 399673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) { 4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: assert(0 && "Unknown unary operator"); 4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PostInc: return "++"; 4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PostDec: return "--"; 4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PreInc: return "++"; 4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PreDec: return "--"; 4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case AddrOf: return "&"; 4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Deref: return "*"; 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Plus: return "+"; 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Minus: return "-"; 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Not: return "~"; 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LNot: return "!"; 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Real: return "__real"; 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Imag: return "__imag"; 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Extension: return "__extension__"; 41873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner case OffsetOf: return "__builtin_offsetof"; 4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpUnaryOperator::Opcode 423bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 424bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 425bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: assert(false && "No unary operator for overloaded function"); 426b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_PlusPlus: return Postfix ? PostInc : PreInc; 427b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_MinusMinus: return Postfix ? PostDec : PreDec; 428b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Amp: return AddrOf; 429b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Star: return Deref; 430b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Plus: return Plus; 431b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Minus: return Minus; 432b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Tilde: return Not; 433b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Exclaim: return LNot; 434bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 435bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 436bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 437bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 438bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 439bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case PostInc: case PreInc: return OO_PlusPlus; 440bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case PostDec: case PreDec: return OO_MinusMinus; 441bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case AddrOf: return OO_Amp; 442bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Deref: return OO_Star; 443bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Plus: return OO_Plus; 444bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Minus: return OO_Minus; 445bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Not: return OO_Tilde; 446bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case LNot: return OO_Exclaim; 447bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 448bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 449bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 450bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 451bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 456668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, 4578189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek unsigned numargs, QualType t, SourceLocation rparenloc) 4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, t, 459898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), 460d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), 461898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 463668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek SubExprs = new (C) Stmt*[numargs+1]; 464b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 465b4609806e9232593ece09ce08b630836e825865cDouglas Gregor for (unsigned i = 0; i != numargs; ++i) 466b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[i+ARGS_START] = args[i]; 467668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 468b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 469b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 470e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 471668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 472668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc) 473898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(CallExprClass, t, 474898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), 475d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), 476898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 477668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 478668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek SubExprs = new (C) Stmt*[numargs+1]; 47977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numargs; ++i) 48177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[i+ARGS_START] = args[i]; 482668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 4881f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor SubExprs = new (C) Stmt*[1]; 4891f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 4901f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 491d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() { 492a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu Expr *CEE = getCallee()->IgnoreParenCasts(); 4936346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 494d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return DRE->getDecl(); 495cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) 496cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes return ME->getMemberDecl(); 497a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 498a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 499a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 500a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 501d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() { 502caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); 503d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes} 504d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 505d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 506d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 507d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 5088189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 509d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 510d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 5111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 512d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 513d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 514d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 515d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 516d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 517d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 518d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 51968a049cab6015a7437bec5661601b7d37d23c70cDaniel Dunbar Stmt **NewSubExprs = new (C) Stmt*[NumArgs+1]; 520d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 521d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i) 522d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 523d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 524d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i) 525d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 5261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52788c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 528d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 529d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 530d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 531d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 532cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 533cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 5343c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregorunsigned CallExpr::isBuiltinCall(ASTContext &Context) const { 535c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // function. As a result, we try and obtain the DeclRefExpr from the 537c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 538c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 539c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 540cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 5411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 542c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 543c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 544cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 5451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 546bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 547bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 548cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 5491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5504fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 5514fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 5524fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 5537814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor return FDecl->getBuiltinID(); 554cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 555bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 5566dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 5576dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 5586217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 5596dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 5606217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 5616dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 5625291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor else if (const MemberPointerType *MPT 5635291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor = CalleeType->getAs<MemberPointerType>()) 5645291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor CalleeType = MPT->getPointeeType(); 5655291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 566183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *FnType = CalleeType->getAs<FunctionType>(); 5676dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 5686dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 569cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 570c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, 5718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, 572c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TypeSourceInfo *tsi, 573c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 5748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 5758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 5768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 577c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt sizeof(OffsetOfNode) * numComps + 5788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 5798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 5808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps, 5818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor exprsPtr, numExprs, RParenLoc); 5828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 5838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 5848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, 5858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned numComps, unsigned numExprs) { 5868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 5878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(OffsetOfNode) * numComps + 5888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 5898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(numComps, numExprs); 5908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 5918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 592c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, 5938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 594c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 5958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 5968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) 597c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Expr(OffsetOfExprClass, type, /*TypeDependent=*/false, 5988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /*ValueDependent=*/tsi->getType()->isDependentType() || 5998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor hasAnyTypeDependentArguments(exprsPtr, numExprs) || 6008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor hasAnyValueDependentArguments(exprsPtr, numExprs)), 601c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), 602c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NumComps(numComps), NumExprs(numExprs) 6038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{ 6048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numComps; ++i) { 6058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setComponent(i, compsPtr[i]); 6068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 607c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numExprs; ++i) { 6098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setIndexExpr(i, exprsPtr[i]); 6108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 6128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 6138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { 6148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field || getKind() == Identifier); 6158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (getKind() == Field) 6168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getField()->getIdentifier(); 617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); 6198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 6208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 6211eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *qual, 62383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor SourceRange qualrange, 624f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 625161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair founddecl, 6261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation l, 627d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 628c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor QualType ty) { 62983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 6306bb8017bb9e828d118e15e59d71c66bba323c364John McCall 631161755a09898c95d21bfff33707da9ca41cd53c5John McCall bool hasQualOrFound = (qual != 0 || 632161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getDecl() != memberdecl || 633161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getAccess() != memberdecl->getAccess()); 6346bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) 6356bb8017bb9e828d118e15e59d71c66bba323c364John McCall Size += sizeof(MemberNameQualifier); 6361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 637d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 638d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Size += ExplicitTemplateArgumentList::sizeFor(*targs); 6391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor void *Mem = C.Allocate(Size, llvm::alignof<MemberExpr>()); 6416bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, l, ty); 6426bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6436bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) { 6446bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (qual && qual->isDependent()) { 6456bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setValueDependent(true); 6466bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setTypeDependent(true); 6476bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 6486bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasQualifierOrFoundDecl = true; 6496bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6506bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *NQ = E->getMemberQualifier(); 6516bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->NNS = qual; 6526bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->Range = qualrange; 6536bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->FoundDecl = founddecl; 6546bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 6556bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6566bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (targs) { 6576bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasExplicitTemplateArgumentList = true; 6586bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->getExplicitTemplateArgumentList()->initializeFrom(*targs); 6596bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 6606bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6616bb8017bb9e828d118e15e59d71c66bba323c364John McCall return E; 66283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 66383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 664f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 665f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 666f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_Unknown: 667f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Unknown"; 668f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_BitCast: 669f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 670e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor case CastExpr::CK_LValueBitCast: 671e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor return "LValueBitCast"; 672f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_NoOp: 673f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 67411de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson case CastExpr::CK_BaseToDerived: 67511de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson return "BaseToDerived"; 676f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_DerivedToBase: 677f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 67823cba801e11b03929c44f8cf54578305963a3476John McCall case CastExpr::CK_UncheckedDerivedToBase: 67923cba801e11b03929c44f8cf54578305963a3476John McCall return "UncheckedDerivedToBase"; 680f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_Dynamic: 681f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 682f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_ToUnion: 683f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 684f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_ArrayToPointerDecay: 685f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 686f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_FunctionToPointerDecay: 687f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 688f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_NullToMemberPointer: 689f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 690f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_BaseToDerivedMemberPointer: 691f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 6921a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson case CastExpr::CK_DerivedToBaseMemberPointer: 6931a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson return "DerivedToBaseMemberPointer"; 694f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_UserDefinedConversion: 695f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 696f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_ConstructorConversion: 697f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 6987f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson case CastExpr::CK_IntegralToPointer: 6997f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "IntegralToPointer"; 7007f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson case CastExpr::CK_PointerToIntegral: 7017f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "PointerToIntegral"; 702ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson case CastExpr::CK_ToVoid: 703ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson return "ToVoid"; 70416a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson case CastExpr::CK_VectorSplat: 70516a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson return "VectorSplat"; 70682debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson case CastExpr::CK_IntegralCast: 70782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralCast"; 70882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson case CastExpr::CK_IntegralToFloating: 70982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralToFloating"; 71082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson case CastExpr::CK_FloatingToIntegral: 71182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "FloatingToIntegral"; 712c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer case CastExpr::CK_FloatingCast: 713c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer return "FloatingCast"; 714bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson case CastExpr::CK_MemberPointerToBoolean: 715bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson return "MemberPointerToBoolean"; 7164cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian case CastExpr::CK_AnyPointerToObjCPointerCast: 7174cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian return "AnyPointerToObjCPointerCast"; 7183b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian case CastExpr::CK_AnyPointerToBlockPointerCast: 7193b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian return "AnyPointerToBlockPointerCast"; 720f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 7211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 722f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson assert(0 && "Unhandled cast kind!"); 723f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return 0; 724f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 725f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 7266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() { 7276eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *SubExpr = 0; 7286eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor CastExpr *E = this; 7296eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor do { 7306eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = E->getSubExpr(); 731c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Skip any temporary bindings; they're implicit. 7336eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) 7346eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = Binder->getSubExpr(); 735c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7366eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Conversions by constructor and conversion functions have a 7376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // subexpression describing the call; strip it off. 7386eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (E->getCastKind() == CastExpr::CK_ConstructorConversion) 7396eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); 7406eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor else if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) 7416eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); 742c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // If the subexpression we're left with is an implicit cast, look 7446eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // through that, too. 745c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); 746c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7476eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return SubExpr; 7486eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 7496eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) { 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 754baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor case PtrMemD: return ".*"; 755baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor case PtrMemI: return "->*"; 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Mul: return "*"; 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Div: return "/"; 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Rem: return "%"; 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Add: return "+"; 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Sub: return "-"; 7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Shl: return "<<"; 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Shr: return ">>"; 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LT: return "<"; 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case GT: return ">"; 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LE: return "<="; 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case GE: return ">="; 7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case EQ: return "=="; 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case NE: return "!="; 7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case And: return "&"; 7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Xor: return "^"; 7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Or: return "|"; 7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LAnd: return "&&"; 7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LOr: return "||"; 7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Assign: return "="; 7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MulAssign: return "*="; 7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DivAssign: return "/="; 7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case RemAssign: return "%="; 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case AddAssign: return "+="; 7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SubAssign: return "-="; 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ShlAssign: return "<<="; 7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ShrAssign: return ">>="; 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case AndAssign: return "&="; 7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case XorAssign: return "^="; 7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case OrAssign: return "|="; 7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Comma: return ","; 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 787baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 788baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor return ""; 7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpBinaryOperator::Opcode 792063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 793063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 794b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner default: assert(false && "Not an overloadable binary operator"); 795063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Plus: return Add; 796063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Minus: return Sub; 797063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Star: return Mul; 798063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Slash: return Div; 799063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Percent: return Rem; 800063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Caret: return Xor; 801063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Amp: return And; 802063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Pipe: return Or; 803063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Equal: return Assign; 804063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Less: return LT; 805063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Greater: return GT; 806063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PlusEqual: return AddAssign; 807063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_MinusEqual: return SubAssign; 808063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_StarEqual: return MulAssign; 809063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_SlashEqual: return DivAssign; 810063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PercentEqual: return RemAssign; 811063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_CaretEqual: return XorAssign; 812063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_AmpEqual: return AndAssign; 813063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PipeEqual: return OrAssign; 814063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_LessLess: return Shl; 815063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_GreaterGreater: return Shr; 816063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_LessLessEqual: return ShlAssign; 817063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_GreaterGreaterEqual: return ShrAssign; 818063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_EqualEqual: return EQ; 819063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_ExclaimEqual: return NE; 820063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_LessEqual: return LE; 821063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_GreaterEqual: return GE; 822063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_AmpAmp: return LAnd; 823063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PipePipe: return LOr; 824063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Comma: return Comma; 825063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_ArrowStar: return PtrMemI; 826063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 827063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 828063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 829063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 830063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 831063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 832063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 833063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 834063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 835063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 836063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 837063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 838063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 839063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 840063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 841063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 842063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 843063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 844063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 845063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 846063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 847063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 848063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 849063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 850063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 851063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 852063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 853709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, 854418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner Expr **initExprs, unsigned numInits, 8554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc) 85673460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor : Expr(InitListExprClass, QualType(), false, false), 857709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs(C, numInits), 8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0), 859c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt UnionFieldInit(0), HadArrayRangeDesignator(false) 860c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt{ 861ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek for (unsigned I = 0; I != numInits; ++I) { 862ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isTypeDependent()) 86373460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor TypeDependent = true; 864ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isValueDependent()) 86573460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor ValueDependent = true; 86673460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor } 867c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 868709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits); 86966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 871709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { 872ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (NumInits > InitExprs.size()) 873709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.reserve(C, NumInits); 874fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 875fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 876709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { 877709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.resize(C, NumInits, 0); 8784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 8794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 880709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { 881ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (Init >= InitExprs.size()) { 882709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); 883ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek InitExprs.back() = expr; 884ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return 0; 8854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 8884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 8894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 8904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 8914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 892bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 8934eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 8944eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const { 8956217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<BlockPointerType>()-> 896183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall getPointeeType()->getAs<FunctionType>(); 8974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 8984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 8991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const { 9001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getCaretLocation(); 90156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 9021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const { 9037297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 9047297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 9051eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() { 9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getBody(); 9077297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 90856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 90956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 914026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 915026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 916026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 917026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 918026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattnerbool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 919df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const { 920ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 921ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 922ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 923ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 9270faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 9280faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 929026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 930026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 931026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 933026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 934df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump isUnusedResultAWarning(Loc, R1, R2, Ctx); 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 9371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 939026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner default: break; 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::PostInc: 9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::PostDec: 9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::PreInc: 943026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner case UnaryOperator::PreDec: // ++/-- 944026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Deref: 9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Dereferencing a volatile pointer is a side-effect. 947df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 948026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 949026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Real: 9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Imag: 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 953df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) 954df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump .isVolatileQualified()) 955026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 956026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Extension: 958df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 960026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 961026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 962026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 964e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 965026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 966c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek switch (BO->getOpcode()) { 967c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek default: 968c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek break; 96925973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider the RHS of comma for side effects. LHS was checked by 97025973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Sema::CheckCommaOperands. 971c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek case BinaryOperator::Comma: 972c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // ((foo = <blah>), 0) is an idiom for hiding the result (and 973c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // lvalue-ness) of an assignment written in a macro. 974c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IntegerLiteral *IE = 975c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) 976c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IE->getValue() == 0) 977c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek return false; 97825973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 97925973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider '||', '&&' to have side effects if the LHS or RHS does. 980c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek case BinaryOperator::LAnd: 981c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek case BinaryOperator::LOr: 98225973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis if (!BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) || 98325973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis !BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) 98425973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return false; 98525973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis break; 986bf0ee354163f87623a4b60412544243911332343John McCall } 987026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 988026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 989026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 990026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 991026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 992026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 993e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 994eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 995c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor case VAArgExprClass: 996026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 998ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 999026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // The condition must be evaluated, but if either the LHS or RHS is a 1000026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // warning, warn about them. 1001ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Exp->getLHS() && 1003df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) 1004026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1005df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1006ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 1007ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 1009026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the base pointer or element is to a volatile pointer/field, accessing 1010026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 1011df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1012026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1013026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 1014026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 1015026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 1016026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the base pointer or element is to a volatile pointer/field, accessing 1020026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 1021df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1022026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1023026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 1024026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 1025026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 1026026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1027211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 1029852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXOperatorCallExprClass: 1030852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXMemberCallExprClass: { 1031026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 1032026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 1033d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes if (const Decl *FD = CE->getCalleeDecl()) { 1034026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 1035026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 1036bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // 1037bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // Note: If new cases are added here, DiagnoseUnusedExprResult should be 1038bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // updated to match for QoI. 1039bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (FD->getAttr<WarnUnusedResultAttr>() || 1040bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 1041bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner Loc = CE->getCallee()->getLocStart(); 1042bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R1 = CE->getCallee()->getSourceRange(); 1043bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner 1044bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 1045bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 1046bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 1047bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return true; 1048bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1049026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 1050026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1051026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 105258beed91d468863b8c85bce43425422703838d27Anders Carlsson 105358beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXTemporaryObjectExprClass: 105458beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXConstructExprClass: 105558beed91d468863b8c85bce43425422703838d27Anders Carlsson return false; 105658beed91d468863b8c85bce43425422703838d27Anders Carlsson 1057f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian case ObjCMessageExprClass: { 1058f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); 1059f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMethodDecl *MD = ME->getMethodDecl(); 1060f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 1061f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian Loc = getExprLoc(); 1062f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian return true; 1063f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 1064026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1065f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 10661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 106709105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian case ObjCImplicitSetterGetterRefExprClass: { // Dot syntax for message send. 1068a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#if 0 10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCImplicitSetterGetterRefExpr *Ref = 107009105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian cast<ObjCImplicitSetterGetterRefExpr>(this); 1071a50089ec68a583d13718107c1b0c898f0903709eChris Lattner // FIXME: We really want the location of the '.' here. 1072154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian Loc = Ref->getLocation(); 1073154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian R1 = SourceRange(Ref->getLocation(), Ref->getLocation()); 1074154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian if (Ref->getBase()) 1075154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian R2 = Ref->getBase()->getSourceRange(); 10765e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner#else 10775e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 10785e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 1079a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#endif 1080a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 1081a50089ec68a583d13718107c1b0c898f0903709eChris Lattner } 1082611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 1083611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 1084611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 1085611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 1086611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 1087611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 1088611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 1089611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (!CS->body_empty()) 1090611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 1091df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); 10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10930faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 10940faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1095026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 1096026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1097026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1098611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 10996eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor case CStyleCastExprClass: 1100fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // If this is an explicit cast to void, allow it. People do this when they 1101fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // think they know what they're doing :). 1102026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (getType()->isVoidType()) 1103fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner return false; 1104026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); 1105026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); 1106026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 110758beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXFunctionalCastExprClass: { 11080faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 11090faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 111058beed91d468863b8c85bce43425422703838d27Anders Carlsson const CastExpr *CE = cast<CastExpr>(this); 1111c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 111258beed91d468863b8c85bce43425422703838d27Anders Carlsson // If this is a cast to void or a constructor conversion, check the operand. 111358beed91d468863b8c85bce43425422703838d27Anders Carlsson // Otherwise, the result of the cast is unused. 111458beed91d468863b8c85bce43425422703838d27Anders Carlsson if (CE->getCastKind() == CastExpr::CK_ToVoid || 111558beed91d468863b8c85bce43425422703838d27Anders Carlsson CE->getCastKind() == CastExpr::CK_ConstructorConversion) 1116df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CastExpr>(this)->getSubExpr() 1117df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 1118026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); 1119026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); 1120026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 112158beed91d468863b8c85bce43425422703838d27Anders Carlsson } 11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11234be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman case ImplicitCastExprClass: 11244be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman // Check the operand, since implicit casts are inserted by Sema 1125df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<ImplicitCastExpr>(this) 1126df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 11274be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 112804421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 1129df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXDefaultArgExpr>(this) 1130df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 11314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 11324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 11334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 11344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 11354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 1136026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 11372d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 1138df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXBindTemporaryExpr>(this) 1139df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 11406b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson case CXXExprWithTemporariesClass: 1141df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXExprWithTemporaries>(this) 1142df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 11434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 114644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 11477f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise. 1148102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 114944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian switch (getStmtClass()) { 115044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 115144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 115244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 115344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 1154207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 1155102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 115644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ParenExprClass: 1157102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 115844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 1159102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 116006b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 1161102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 1162a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { 116344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const Decl *D = cast<DeclRefExpr>(this)->getDecl(); 1164102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 1165102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 1166102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 1167102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 116859a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // dereferencing to a pointer is always a gc'able candidate, 116959a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // unless it is __weak. 11707e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar return T->isPointerType() && 11710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); 1172102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 117344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 117444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 117583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 117644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const MemberExpr *M = cast<MemberExpr>(this); 1177102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 117844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 117944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 1180102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx); 118144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 118244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 11834e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 11844e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 11854e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek while (ParenExpr* P = dyn_cast<ParenExpr>(E)) 11864e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek E = P->getSubExpr(); 11871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11884e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return E; 11894e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 11904e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 119156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 119256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 119356f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 119456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 119556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 119656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) 119756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 119856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner else if (CastExpr *P = dyn_cast<CastExpr>(E)) 119956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 120056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner else 120156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return E; 120256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 120356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 120456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 12052fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() { 12062fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *E = this; 12072fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall while (true) { 12082fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall if (ParenExpr *P = dyn_cast<ParenExpr>(E)) 12092fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 12102fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall else if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) 12112fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 12122fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall else 12132fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall return E; 12142fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall } 12152fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall} 12162fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 1217ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 1218ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 1219ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 1220ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 1221ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 1222ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 1223ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 1224ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 1225ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1226ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1228ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 1229ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 12302ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor // ptr<->int casts of the same width. We also ignore all identity casts. 1231ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 12321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1233ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 1234ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1235ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1236ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 12371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12389d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor if ((E->getType()->isPointerType() || 12399d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor E->getType()->isIntegralType(Ctx)) && 12409d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor (SE->getType()->isPointerType() || 12419d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor SE->getType()->isIntegralType(Ctx)) && 1242ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 1243ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1244ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1245ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1246ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 12471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1248ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 1249ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1250ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 1251ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 12526eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const { 12536eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *E = this; 12546eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) 12556eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor E = ICE->getSubExprAsWritten(); 1256c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12576eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return isa<CXXDefaultArgExpr>(E); 12586eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 1259ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 12602f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding 12612f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions. 12622f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregorstatic const Expr *skipTemporaryBindingsAndNoOpCasts(const Expr *E) { 12632f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 12642f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (ICE->getCastKind() == CastExpr::CK_NoOp) 12652f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 12662f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 12672f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 12682f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 12692f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 12702f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) 12712f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = BE->getSubExpr(); 12722f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 12732f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 12742f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (ICE->getCastKind() == CastExpr::CK_NoOp) 12752f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 12762f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 12772f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 12782f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 1279c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 12802f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor return E; 12812f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 12822f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 12832f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregorconst Expr *Expr::getTemporaryObject() const { 12842f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor const Expr *E = skipTemporaryBindingsAndNoOpCasts(this); 12852f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 12862f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // A cast can produce a temporary object. The object's construction 12872f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // is represented as a CXXConstructExpr. 12882f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (const CastExpr *Cast = dyn_cast<CastExpr>(E)) { 12892f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // Only user-defined and constructor conversions can produce 12902f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // temporary objects. 12912f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (Cast->getCastKind() != CastExpr::CK_ConstructorConversion && 12922f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor Cast->getCastKind() != CastExpr::CK_UserDefinedConversion) 12932f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor return 0; 12942f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 12952f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // Strip off temporary bindings and no-op casts. 12962f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor const Expr *Sub = skipTemporaryBindingsAndNoOpCasts(Cast->getSubExpr()); 12972f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 12982f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // If this is a constructor conversion, see if we have an object 12992f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // construction. 13002f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (Cast->getCastKind() == CastExpr::CK_ConstructorConversion) 13012f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor return dyn_cast<CXXConstructExpr>(Sub); 13022f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 13032f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // If this is a user-defined conversion, see if we have a call to 13042f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // a function that itself returns a temporary object. 13052f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (Cast->getCastKind() == CastExpr::CK_UserDefinedConversion) 13062f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (const CallExpr *CE = dyn_cast<CallExpr>(Sub)) 13072f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (CE->getCallReturnType()->isRecordType()) 13082f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor return CE; 13092f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 13102f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor return 0; 13112f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 13122f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 13132f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // A call returning a class type returns a temporary. 13142f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { 13152f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor if (CE->getCallReturnType()->isRecordType()) 13162f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor return CE; 13172f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 13182f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor return 0; 13192f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 13202f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 13212f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor // Explicit temporary object constructors create temporaries. 13222f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor return dyn_cast<CXXTemporaryObjectExpr>(E); 13232f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 13242f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 1325898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 1326898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 1327898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) { 1328898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 1329898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 1330898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 1331898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1332898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1333898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1334898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1335898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyValueDependentArguments - Determines if any of the expressions 1336898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is value-dependent. 1337898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) { 1338898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 1339898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isValueDependent()) 1340898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 1341898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1342898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1343898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1344898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 13454204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { 1346c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 1347c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 1348c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 1349c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 1350c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 1351c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 13524204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // If we ever capture reference-binding directly in the AST, we can 13534204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // kill the second parameter. 13544204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 13554204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (IsForRef) { 13564204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall EvalResult Result; 13574204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; 13584204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall } 13591f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 1360e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 1361c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 1362e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 136314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 1364eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 1365e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 1366b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXTemporaryObjectExprClass: 1367b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXConstructExprClass: { 1368b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 13694204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 13704204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // Only if it's 13714204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // 1) an application of the trivial default constructor or 1372b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall if (!CE->getConstructor()->isTrivial()) return false; 13734204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!CE->getNumArgs()) return true; 13744204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 13754204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // 2) an elidable trivial copy construction of an operand which is 13764204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // itself a constant initializer. Note that we consider the 13774204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // operand on its own, *not* as a reference binding. 13784204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return CE->isElidable() && 13794204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall CE->getArg(0)->isConstantInitializer(Ctx, false); 1380b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall } 138159b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 13821f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 13831f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 13841f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 138559b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 13864204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->isConstantInitializer(Ctx, false); 138759b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 1388e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 13891f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 13901f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 13911f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 1392e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 1393e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 1394e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 13954204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) 1396e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 1397e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 1398c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 1399e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 14003498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 14013498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 14023ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case ParenExprClass: 14034204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<ParenExpr>(this)->getSubExpr() 14044204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, IsForRef); 1405c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 1406c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 1407c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman if (Exp->getOpcode() == UnaryOperator::Extension) 14084204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->getSubExpr()->isConstantInitializer(Ctx, false); 1409c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 1410c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 14113ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case BinaryOperatorClass: { 14123ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // Special case &&foo - &&bar. It would be nice to generalize this somehow 14133ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // but this handles the common case. 14143ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner const BinaryOperator *Exp = cast<BinaryOperator>(this); 14153ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner if (Exp->getOpcode() == BinaryOperator::Sub && 14163ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) && 14173ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx))) 14183ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner return true; 14193ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner break; 14203ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner } 14214204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall case CXXFunctionalCastExprClass: 1422b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXStaticCastExprClass: 142381045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 1424c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case CStyleCastExprClass: 1425c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // Handle casts with a destination that's a struct or union; this 1426c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // deals with both the gcc no-op struct cast extension and the 1427c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // cast-to-union extension. 1428c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman if (getType()->isRecordType()) 14294204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<CastExpr>(this)->getSubExpr() 14304204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, false); 1431c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1432430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // Integer->integer casts can be handled here, which is important for 1433430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // things like (int)(&&x-&&y). Scary but true. 1434430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner if (getType()->isIntegerType() && 1435430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType()) 14364204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<CastExpr>(this)->getSubExpr() 14374204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, false); 1438c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1439c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 1440e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 1441c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 144238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 144338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 14455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// integer constant expression with the value zero, or if this is one that is 14465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// cast to void*. 1447ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregorbool Expr::isNullPointerConstant(ASTContext &Ctx, 1448ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NullPointerConstantValueDependence NPC) const { 1449ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor if (isValueDependent()) { 1450ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor switch (NPC) { 1451ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_NeverValueDependent: 1452ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor assert(false && "Unexpected value dependent expression!"); 1453ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor // If the unthinkable happens, fall through to the safest alternative. 1454c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1455ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNull: 14569d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor return isTypeDependent() || getType()->isIntegralType(Ctx); 1457c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1458ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNotNull: 1459ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return false; 1460ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 1461ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 1462f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar 14630777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 14640835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 14656215dee86c0e715b9f2b0d401ab2a5fcf629f1afSebastian Redl if (!Ctx.getLangOptions().CPlusPlus) { 14660777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 14676217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 14680777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 14690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Pointee.hasQualifiers() && 14700777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 14710777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 1472ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 14730777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 14745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1475aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 1476aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 1477ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 1478aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 1479aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 1480aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 1481ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (const CXXDefaultArgExpr *DefaultArg 14838123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 148404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 1485ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); 14862d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 14872d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 14882d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return true; 1489aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 14902d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 14916e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // C++0x nullptr_t is always a null pointer constant. 14926e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 14936e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return true; 14946e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 1495aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 1496c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (!getType()->isIntegerType() || 149756fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType())) 1498aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff return false; 14991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 15015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // test for the value 0. 150209de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman llvm::APSInt Result; 150309de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman return isIntegerConstantExpr(Result, Ctx) && Result == 0; 15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 150531a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 150633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 15076f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 150833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 1509de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 1510906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl if (ICE->getCategory() != ImplicitCastExpr::RValue && 1511906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl ICE->getCastKind() == CastExpr::CK_NoOp) 1512de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor E = ICE->getSubExpr()->IgnoreParens(); 1513de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor else 1514de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor break; 1515de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor } 1516de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor 151727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 151886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 151933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 152033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 152133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 152233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) 152333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 152433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 152533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 152633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 152727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 152827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 1529093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const { 1530093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson const Expr *E = this->IgnoreParens(); 1531c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1532093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 1533906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl if (ICE->getCategory() != ImplicitCastExpr::RValue && 1534906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl ICE->getCastKind() == CastExpr::CK_NoOp) 1535093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson E = ICE->getSubExpr()->IgnoreParens(); 1536093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson else 1537093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson break; 1538093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson } 1539c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1540093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) 1541093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return ASE->getBase()->getType()->isVectorType(); 1542093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 1543093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (isa<ExtVectorElementExpr>(E)) 1544093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return true; 1545093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 1546093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return false; 1547093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson} 1548093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 15492140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 15502140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 15512140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 15522140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 15532140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 15542140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 1555213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 1556183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const VectorType *VT = getType()->getAs<VectorType>()) 15578a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 15588a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 15594d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 15604d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 15618a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 1562213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 1563a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // FIXME: Refactor this code to an accessor on the AST node which returns the 1564a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // "type" of component access, and share with code below and in Sema. 156501eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar llvm::StringRef Comp = Accessor->getName(); 1566190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 1567190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 1568150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") 1569190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1571190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 1572150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 1573150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar Comp = Comp.substr(1); 15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1575150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar for (unsigned i = 0, e = Comp.size(); i != e; ++i) 1576150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp.substr(i + 1).find(Comp[i]) != llvm::StringRef::npos) 1577fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 1578150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar 1579fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 1580fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 1581b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 15828a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 15833b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 15843b8d116703db8018f855cbb4733ace426422623bNate Begeman llvm::SmallVectorImpl<unsigned> &Elts) const { 15854b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar llvm::StringRef Comp = Accessor->getName(); 15864b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 15874b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Comp = Comp.substr(1); 15881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15894b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isHi = Comp == "hi"; 15904b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isLo = Comp == "lo"; 15914b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isEven = Comp == "even"; 15924b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isOdd = Comp == "odd"; 15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15948a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 15958a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15978a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 15988a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 15998a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 16008a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 16018a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 16028a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 16038a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 16048a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 16058a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 16064b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Index = ExtVectorType::getAccessorIdx(Comp[i]); 1607b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 16083b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 1609b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 16108a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 16118a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 161204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 161304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 161404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 161504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 161604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 1617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 161804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 161904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 162004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 162104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Expr(ObjCMessageExprClass, T, /*TypeDependent=*/false, 162292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*ValueDependent=*/false), 162304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs(NumArgs), Kind(IsInstanceSuper? SuperInstance : SuperClass), 162404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor HasMethod(Method != 0), SuperLoc(SuperLoc), 162504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 162604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 1627c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt LBracLoc(LBracLoc), RBracLoc(RBracLoc) 1628c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{ 162904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(SuperType.getAsOpaquePtr()); 163004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (NumArgs) 163104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); 163204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 163304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 163404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 163504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 163604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 1637c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 163804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 163904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 164004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 164104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Expr(ObjCMessageExprClass, T, T->isDependentType(), 1642c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (T->isDependentType() || 164304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor hasAnyValueDependentArguments(Args, NumArgs))), 164404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs(NumArgs), Kind(Class), HasMethod(Method != 0), 164504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 164604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 1647c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt LBracLoc(LBracLoc), RBracLoc(RBracLoc) 164804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 164904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 165004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (NumArgs) 165104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); 165204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 165304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 165404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 165504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 165604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 1657c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 165804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 165904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 166004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 166192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor : Expr(ObjCMessageExprClass, T, Receiver->isTypeDependent(), 1662c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (Receiver->isTypeDependent() || 166304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor hasAnyValueDependentArguments(Args, NumArgs))), 166404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs(NumArgs), Kind(Instance), HasMethod(Method != 0), 166504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 166604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 1667c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt LBracLoc(LBracLoc), RBracLoc(RBracLoc) 166804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 166904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 167004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (NumArgs) 167104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); 167204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 167304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 167404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 167504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 167604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 167704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 167804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 1679c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 168004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 168104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 168204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 1683c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 168404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 168504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 168604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return new (Mem) ObjCMessageExpr(T, LBracLoc, SuperLoc, IsInstanceSuper, 1687c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SuperType, Sel, Method, Args, NumArgs, 168804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor RBracLoc); 168904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 169004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 169104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 169204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 169304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 1694c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 169504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 169604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 169704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 1698c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 169904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 170004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 1701c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return new (Mem) ObjCMessageExpr(T, LBracLoc, Receiver, Sel, Method, Args, 170204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs, RBracLoc); 170304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 170404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 170504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 170604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 170704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 1708c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 170904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 171004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 171104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 1712c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 171304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 171404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 1715c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return new (Mem) ObjCMessageExpr(T, LBracLoc, Receiver, Sel, Method, Args, 171604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs, RBracLoc); 171704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 171804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 1719c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, 172004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor unsigned NumArgs) { 1721c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 172204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 172304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 172404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); 172504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 1726c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 172704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const { 172804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 172904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) 173004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ->getSelector(); 1731c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Selector(SelectorOrMethod); 173204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 173304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 173404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { 173504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor switch (getReceiverKind()) { 173604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Instance: 173704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 173804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) 173904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 174004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 17414df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 174204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Class: 1743c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *Ty 1744c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall = getClassReceiver()->getAs<ObjCObjectType>()) 1745c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return Ty->getInterface(); 174604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 17474df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 174804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperInstance: 174904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 175004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getSuperType()->getAs<ObjCObjectPointerType>()) 175104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 175204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 1753c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 175404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperClass: 175504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Iface 175604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getSuperType()->getAs<ObjCObjectPointerType>()) 175704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Iface->getInterfaceDecl(); 175804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 175904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 17600389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 176104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 1762eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek} 17630389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 176427437caadea35f84d550cd29f024fcf3ea240eecChris Lattnerbool ChooseExpr::isConditionTrue(ASTContext &C) const { 17659a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getCond()->EvaluateAsInt(C) != 0; 176627437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 176727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 1768888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 1769888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 1770888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 1771888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 1772888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 177394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 177494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 17751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 1776888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 177777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 177805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 177905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 178005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 178105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() { 178205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 178305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 178405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 178505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 178605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 178705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 178805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 1789c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, 1790319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesignators, 1791ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 17921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation EqualOrColonLoc, 1793ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **IndexExprs, 17959ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned NumIndexExprs, 17969ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 17971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(DesignatedInitExprClass, Ty, 17989ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Init->isTypeDependent(), Init->isValueDependent()), 17991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 18001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { 1801319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor this->Designators = new (C) Designator[NumDesignators]; 18029ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 18039ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 18049ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor child_iterator Child = child_begin(); 18059ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 18069ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 18079ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 18089ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 18099ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 18109ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 1811ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 18129ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 18139ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 18149ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 18159ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 18161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDependent = ValueDependent || 18179ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Index->isTypeDependent() || Index->isValueDependent(); 18189ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 18199ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 18209ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 18219ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 18229ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 18239ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 18249ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 18251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDependent = ValueDependent || 18269ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Start->isTypeDependent() || Start->isValueDependent() || 18279ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor End->isTypeDependent() || End->isValueDependent(); 18289ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 18299ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 18309ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 18319ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 18329ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 18339ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 18349ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 18359ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); 1836ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 1837ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 183805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 18391eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 184005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 184105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 184205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 184305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 1844c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 1845c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff sizeof(Stmt *) * (NumIndexExprs + 1), 8); 1846319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, 18479ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 18489ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor IndexExprs, NumIndexExprs, Init); 184905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 185005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 18511eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 1852d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 1853d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 1854d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 1855d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 1856d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 1857d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 1858319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C, 1859319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor const Designator *Desigs, 1860d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 1861319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor Designators = new (C) Designator[NumDesigs]; 1862d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 1863d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 1864d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 1865d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 1866d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 186705c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const { 186805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 1869d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 1870d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 187105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 1872eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 187305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 187405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 187505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 187605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 1877d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 1878d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 187905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); 188005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 188105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 188205c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) { 188305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 188405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 188505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 188605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 188705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 188805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 188905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 189005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { 18911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 189205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 189305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 189405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 189505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 189605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 189705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 189805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 189905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { 19001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 190105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 190205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 190305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 190405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 190505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 190605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 190705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 1908ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 1909ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 1910319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, 19111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Designator *First, 1912ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 1913ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 1914ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 1915ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 1916ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 1917ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 1918ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 1919ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 1920ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 1921ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 1922ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 1923ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 1924ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 19251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator *NewDesignators 1926319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; 1927ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 1928ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 1929ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 1930ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 1931ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 1932ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 1933ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 1934ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 19351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 19362ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Expr **exprs, unsigned nexprs, 19372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation rparenloc) 19382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman: Expr(ParenListExprClass, QualType(), 19392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman hasAnyTypeDependentArguments(exprs, nexprs), 19401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump hasAnyValueDependentArguments(exprs, nexprs)), 19412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { 19421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs = new (C) Stmt*[nexprs]; 19442ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman for (unsigned i = 0; i != nexprs; ++i) 19452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 19462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 19472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 194805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 1949ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 1950ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 1951ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1952ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 1953ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 1954ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 1955ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 1956ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 1957ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 1958ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 1959ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 1960ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1961ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 196277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 196377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 196477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 196577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// DeclRefExpr 19669ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); } 19679ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); } 196877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 19697779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff// ObjCIvarRefExpr 19705549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; } 19715549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; } 19727779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff 1973e3e9add4fd788927df6f545570e7838db59c01d7Steve Naroff// ObjCPropertyRefExpr 19745549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; } 19755549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; } 1976ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff 197709105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian// ObjCImplicitSetterGetterRefExpr 19781eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_begin() { 19792fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall // If this is accessing a class member, skip that entry. 19802fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall if (Base) return &Base; 19812fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall return &Base+1; 1982154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian} 19831eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_end() { 19841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return &Base+1; 1985154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian} 19865daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian 1987cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor// ObjCSuperExpr 1988cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); } 1989cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); } 1990cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor 1991f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff// ObjCIsaExpr 1992f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; } 1993f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; } 1994f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 1995d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner// PredefinedExpr 1996d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); } 1997d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); } 199877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 199977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// IntegerLiteral 20009ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); } 20019ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); } 200277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 200377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CharacterLiteral 2004d603eaa682cecac2c10771a700cb83aa301653b4Chris LattnerStmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();} 20059ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); } 200677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 200777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// FloatingLiteral 20089ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); } 20099ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); } 201077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 20115d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner// ImaginaryLiteral 20125549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; } 20135549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; } 20145d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 201577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// StringLiteral 20169ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_begin() { return child_iterator(); } 20179ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_end() { return child_iterator(); } 201877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 201977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ParenExpr 20205549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_begin() { return &Val; } 20215549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_end() { return &Val+1; } 202277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 202377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// UnaryOperator 20245549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_begin() { return &Val; } 20255549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_end() { return &Val+1; } 202677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 20278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor// OffsetOfExpr 20288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorStmt::child_iterator OffsetOfExpr::child_begin() { 20298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Stmt **> (reinterpret_cast<OffsetOfNode *> (this + 1) 20308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor + NumComps); 20318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 20328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorStmt::child_iterator OffsetOfExpr::child_end() { 20338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return child_iterator(&*child_begin() + NumExprs); 20348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 20358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 20360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl// SizeOfAlignOfExpr 20371eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator SizeOfAlignOfExpr::child_begin() { 20380518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 20390518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 20400518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 20410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 20420518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (VariableArrayType* T = dyn_cast<VariableArrayType>( 20430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 20440518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(T); 20450518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(); 20460518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 2047d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return child_iterator(&Argument.Ex); 20489ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 20490518999d3adcc289997bd974dce90cc97f5c1c44Sebastian RedlStmt::child_iterator SizeOfAlignOfExpr::child_end() { 20500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) 20510518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(); 2052d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return child_iterator(&Argument.Ex + 1); 20539ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 205477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 205577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ArraySubscriptExpr 20561237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_begin() { 20575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 205877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 20591237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_end() { 20605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 206177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 206277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 206377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CallExpr 20641237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_begin() { 20655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 206677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 20671237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_end() { 20685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+NumArgs+ARGS_START; 206977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 20701237c673c07f9d827129ba02720108816abde562Ted Kremenek 20711237c673c07f9d827129ba02720108816abde562Ted Kremenek// MemberExpr 20725549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_begin() { return &Base; } 20735549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_end() { return &Base+1; } 20741237c673c07f9d827129ba02720108816abde562Ted Kremenek 2075213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman// ExtVectorElementExpr 20765549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; } 20775549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; } 20781237c673c07f9d827129ba02720108816abde562Ted Kremenek 20791237c673c07f9d827129ba02720108816abde562Ted Kremenek// CompoundLiteralExpr 20805549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; } 20815549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; } 20821237c673c07f9d827129ba02720108816abde562Ted Kremenek 20831237c673c07f9d827129ba02720108816abde562Ted Kremenek// CastExpr 20845549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_begin() { return &Op; } 20855549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_end() { return &Op+1; } 20861237c673c07f9d827129ba02720108816abde562Ted Kremenek 20871237c673c07f9d827129ba02720108816abde562Ted Kremenek// BinaryOperator 20881237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_begin() { 20895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 20901237c673c07f9d827129ba02720108816abde562Ted Kremenek} 20911237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_end() { 20925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 20931237c673c07f9d827129ba02720108816abde562Ted Kremenek} 20941237c673c07f9d827129ba02720108816abde562Ted Kremenek 20951237c673c07f9d827129ba02720108816abde562Ted Kremenek// ConditionalOperator 20961237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_begin() { 20975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 20981237c673c07f9d827129ba02720108816abde562Ted Kremenek} 20991237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_end() { 21005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 21011237c673c07f9d827129ba02720108816abde562Ted Kremenek} 21021237c673c07f9d827129ba02720108816abde562Ted Kremenek 21031237c673c07f9d827129ba02720108816abde562Ted Kremenek// AddrLabelExpr 21049ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); } 21059ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); } 21061237c673c07f9d827129ba02720108816abde562Ted Kremenek 21071237c673c07f9d827129ba02720108816abde562Ted Kremenek// StmtExpr 21085549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_begin() { return &SubStmt; } 21095549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; } 21101237c673c07f9d827129ba02720108816abde562Ted Kremenek 21111237c673c07f9d827129ba02720108816abde562Ted Kremenek// TypesCompatibleExpr 21129ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_begin() { 21139ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 21149ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21159ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek 21169ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_end() { 21179ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 21189ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21191237c673c07f9d827129ba02720108816abde562Ted Kremenek 21201237c673c07f9d827129ba02720108816abde562Ted Kremenek// ChooseExpr 21215549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; } 21225549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; } 21232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 21242d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor// GNUNullExpr 21252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); } 21262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); } 21271237c673c07f9d827129ba02720108816abde562Ted Kremenek 2128d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman// ShuffleVectorExpr 2129d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_begin() { 21305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 2131d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman} 2132d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_end() { 21335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+NumExprs; 2134d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman} 2135d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 21367c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson// VAArgExpr 21375549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_begin() { return &Val; } 21385549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_end() { return &Val+1; } 21397c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 214066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson// InitListExpr 2141ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed KremenekStmt::child_iterator InitListExpr::child_begin() { 2142ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return InitExprs.size() ? &InitExprs[0] : 0; 2143ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek} 2144ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed KremenekStmt::child_iterator InitListExpr::child_end() { 2145ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0; 2146ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek} 214766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 21483498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// DesignatedInitExpr 214905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_begin() { 215005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 215105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 215205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 215305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 215405c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_end() { 215505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return child_iterator(&*child_begin() + NumSubExprs); 215605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 215705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 21583498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// ImplicitValueInitExpr 21591eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_begin() { 21601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return child_iterator(); 21613498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor} 21623498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 21631eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_end() { 21641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return child_iterator(); 21653498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor} 21663498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 21672ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman// ParenListExpr 21682ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_begin() { 21692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return &Exprs[0]; 21702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 21712ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_end() { 21722ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return &Exprs[0]+NumExprs; 21732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 21742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 21751237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCStringLiteral 21761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCStringLiteral::child_begin() { 2177c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner return &String; 21789ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21799ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_end() { 2180c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner return &String+1; 21819ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21821237c673c07f9d827129ba02720108816abde562Ted Kremenek 21831237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCEncodeExpr 21849ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); } 21859ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); } 21861237c673c07f9d827129ba02720108816abde562Ted Kremenek 2187b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian// ObjCSelectorExpr 21881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCSelectorExpr::child_begin() { 21899ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 21909ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21919ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_end() { 21929ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 21939ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 2194b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 2195390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian// ObjCProtocolExpr 21969ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_begin() { 21979ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 21989ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21999ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_end() { 22009ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 22019ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 2202390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 2203563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 22041eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCMessageExpr::child_begin() { 220504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 220604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<Stmt **>(this + 1); 220704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getArgs(); 2208563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2209563477da25f824e37c535131695dc4dc9b68c465Steve NaroffStmt::child_iterator ObjCMessageExpr::child_end() { 221004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getArgs() + getNumArgs(); 2211563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2212563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 22134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks 221456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_begin() { return child_iterator(); } 221556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_end() { return child_iterator(); } 22164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 22179da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();} 22189da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); } 2219