Expr.cpp revision f8b3015060096a946d91578d0f3b65d3097a4ebb
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.cpp - Expression AST Node Implementation --------------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements the Expr class and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar#include "clang/AST/Expr.h" 150979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor#include "clang/AST/ExprCXX.h" 16a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/APValue.h" 172eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner#include "clang/AST/ASTContext.h" 18a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/DeclObjC.h" 1998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor#include "clang/AST/DeclCXX.h" 20aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 2119cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h" 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/StmtVisitor.h" 2308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Lex/LiteralSupport.h" 2408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Lex/Lexer.h" 251b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 2608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner#include "clang/Basic/SourceManager.h" 27da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h" 28cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor#include "llvm/Support/ErrorHandling.h" 293a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson#include "llvm/Support/raw_ostream.h" 30ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm> 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 33bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattnervoid Expr::ANCHOR() {} // key function for Expr class. 34bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner 352b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// isKnownToHaveBooleanValue - Return true if this is an integer expression 362b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// that is known to return 0 or 1. This happens for _Bool/bool expressions 372b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// but also int expressions which are produced by things like comparisons in 382b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// C. 392b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerbool Expr::isKnownToHaveBooleanValue() const { 402b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // If this value has _Bool type, it is obvious 0/1. 412b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (getType()->isBooleanType()) return true; 42c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // If this is a non-scalar-integer type, we don't care enough to try. 432ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (!getType()->isIntegralOrEnumerationType()) return false; 44c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 452b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) 462b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return PE->getSubExpr()->isKnownToHaveBooleanValue(); 47c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 482b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(this)) { 492b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (UO->getOpcode()) { 502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: 512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: 522b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return UO->getSubExpr()->isKnownToHaveBooleanValue(); 532b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: 542b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 552b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 562b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 57c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 586907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // Only look through implicit casts. If the user writes 596907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall // '(int) (a && b)' treat it as an arbitrary int. 606907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(this)) 612b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CE->getSubExpr()->isKnownToHaveBooleanValue(); 62c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 632b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(this)) { 642b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner switch (BO->getOpcode()) { 652b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner default: return false; 662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: // Relational operators. 672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: 682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: 692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: 702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: // Equality operators. 712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: 722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: // AND operator. 732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: // Logical OR operator. 742b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return true; 75c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: // Bitwise AND operator. 772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: // Bitwise XOR operator. 782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: // Bitwise OR operator. 792b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner // Handle things like (x==2)|(y==12). 802b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getLHS()->isKnownToHaveBooleanValue() && 812b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner BO->getRHS()->isKnownToHaveBooleanValue(); 82c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: 852b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return BO->getRHS()->isKnownToHaveBooleanValue(); 862b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 872b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner } 88c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 892b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(this)) 902b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return CO->getTrueExpr()->isKnownToHaveBooleanValue() && 912b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner CO->getFalseExpr()->isKnownToHaveBooleanValue(); 92c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 932b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner return false; 942b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner} 952b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 100d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::initializeFrom( 101d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Info) { 102d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall LAngleLoc = Info.getLAngleLoc(); 103d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall RAngleLoc = Info.getRAngleLoc(); 104d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NumTemplateArgs = Info.size(); 105d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 106d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); 107d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall for (unsigned i = 0; i != NumTemplateArgs; ++i) 108d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); 109d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 110d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 111d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::copyInto( 112d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo &Info) const { 113d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.setLAngleLoc(LAngleLoc); 114d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.setRAngleLoc(RAngleLoc); 115d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall for (unsigned I = 0; I != NumTemplateArgs; ++I) 116d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.addArgument(getTemplateArgs()[I]); 117d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 118d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1198dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidisstd::size_t ExplicitTemplateArgumentList::sizeFor(unsigned NumTemplateArgs) { 1208dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis return sizeof(ExplicitTemplateArgumentList) + 1218dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis sizeof(TemplateArgumentLoc) * NumTemplateArgs; 1228dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis} 1238dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 124d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallstd::size_t ExplicitTemplateArgumentList::sizeFor( 125d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Info) { 1268dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis return sizeFor(Info.size()); 127d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 128d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1290da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregorvoid DeclRefExpr::computeDependence() { 1308e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = false; 1318e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = false; 132c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1330da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor NamedDecl *D = getDecl(); 1340da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 1350da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 1360da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An id-expression is type-dependent if it contains: 1370da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 138c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // and 1390da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 1400da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 1410da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An identifier is value-dependent if it is: 1420da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 1430da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - an identifier that was declared with dependent type 1440da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a name declared with a dependent type, 1450da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor if (getType()->isDependentType()) { 1468e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1478e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1480da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 1490da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a conversion-function-id that specifies a dependent type 150c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt else if (D->getDeclName().getNameKind() 1510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor == DeclarationName::CXXConversionFunctionName && 1520da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor D->getDeclName().getCXXNameType()->isDependentType()) { 1538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1548e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1550da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 1560da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a template-id that is dependent, 157096832c5ed5b9106fa177ebc148489760c3bc496John McCall else if (hasExplicitTemplateArgs() && 1580da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TemplateSpecializationType::anyDependentTemplateArguments( 159c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt getTemplateArgs(), 1600da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor getNumTemplateArgs())) { 1618e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1630da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 1640da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - the name of a non-type template parameter, 1650da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor else if (isa<NonTypeTemplateParmDecl>(D)) 1668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1670da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a constant with integral or enumeration type and is 1680da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // initialized with an expression that is value-dependent. 1690da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor else if (VarDecl *Var = dyn_cast<VarDecl>(D)) { 1702ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (Var->getType()->isIntegralOrEnumerationType() && 171501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor Var->getType().getCVRQualifiers() == Qualifiers::Const) { 17231310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl if (const Expr *Init = Var->getAnyInitializer()) 173501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor if (Init->isValueDependent()) 1748e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 175bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor } 176bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 177bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 178bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 179bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor else if (Var->isStaticDataMember() && 1807ed5bd3e27a6f2b37ee0449aa818116cbd03306eDouglas Gregor Var->getDeclContext()->isDependentContext()) 1818e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 182bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor } 183bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // (VD) - FIXME: Missing from the standard: 184bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // - a member function or a static data member of the current 185bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor // instantiation 186bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor else if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) 1878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 1880da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a nested-name-specifier or a qualified-id that names a 1890da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // member of an unknown specialization. 1900da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (handled by DependentScopeDeclRefExpr) 1910da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor} 1920da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 193c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, 194a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 195dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 196d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 197f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK) 198f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false), 199a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DecoratedD(D, 200a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor (Qualifier? HasQualifierFlag : 0) | 201d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), 202a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Loc(NameLoc) { 203a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (Qualifier) { 204a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *NQ = getNameQualifier(); 205a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NQ->NNS = Qualifier; 206a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NQ->Range = QualifierRange; 207a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 208c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 209d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 210096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().initializeFrom(*TemplateArgs); 211a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 2120da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 213a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 214a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 2152577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, 2162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange QualifierRange, 2172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 2182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 219f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK) 220f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false), 2212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DecoratedD(D, 2222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara (Qualifier? HasQualifierFlag : 0) | 2232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), 2242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { 2252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (Qualifier) { 2262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameQualifier *NQ = getNameQualifier(); 2272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NQ->NNS = Qualifier; 2282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NQ->Range = QualifierRange; 2292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 2302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TemplateArgs) 232096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().initializeFrom(*TemplateArgs); 2332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara computeDependence(); 2352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 2362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 237a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 238a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 239a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 240dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 241a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 2420da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 243f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 2440da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs) { 2452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return Create(Context, Qualifier, QualifierRange, D, 2462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(D->getDeclName(), NameLoc), 247f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall T, VK, TemplateArgs); 2482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 2492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2502577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 2512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NestedNameSpecifier *Qualifier, 2522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange QualifierRange, 2532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 2542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara QualType T, 256f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 2572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 258a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor std::size_t Size = sizeof(DeclRefExpr); 259a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (Qualifier != 0) 260a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Size += sizeof(NameQualifier); 261c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 262d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 263d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); 264c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2653248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 2662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameInfo, 267f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TemplateArgs, T, VK); 268a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 269a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 270663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios KyrtzidisDeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, bool HasQualifier, 271663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis unsigned NumTemplateArgs) { 272663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis std::size_t Size = sizeof(DeclRefExpr); 273663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (HasQualifier) 274663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis Size += sizeof(NameQualifier); 275663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 276663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis if (NumTemplateArgs) 277663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis Size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs); 278663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 2793248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); 280663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis return new (Mem) DeclRefExpr(EmptyShell()); 281663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis} 282663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 283a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorSourceRange DeclRefExpr::getSourceRange() const { 2842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange R = getNameInfo().getSourceRange(); 285a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (hasQualifier()) 286a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setBegin(getQualifierRange().getBegin()); 287096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 288a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setEnd(getRAngleLoc()); 289a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return R; 290a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 291a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 2923a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined 2933a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead. 294848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlssonstd::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { 295848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson ASTContext &Context = CurrentDecl->getASTContext(); 296848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson 2973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { 298848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual) 2993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return FD->getNameAsString(); 3003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 3023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 3033a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 305848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) 3063a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << "virtual "; 3074eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (MD->isStatic()) 3084eadcc569223135e13353c9381b448986e3f7053Sam Weinig Out << "static "; 3093a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3103a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3113a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson PrintingPolicy Policy(Context.getLangOptions()); 3123a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3133a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Proto = FD->getQualifiedNameAsString(Policy); 3143a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 315183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *AFT = FD->getType()->getAs<FunctionType>(); 3163a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const FunctionProtoType *FT = 0; 3173a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->hasWrittenPrototype()) 3183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FT = dyn_cast<FunctionProtoType>(AFT); 3193a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += "("; 3213a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT) { 3223a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_string_ostream POut(Proto); 3233a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { 3243a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (i) POut << ", "; 3253a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Param; 3263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy); 3273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << Param; 3283a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3293a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3303a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT->isVariadic()) { 3313a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->getNumParams()) POut << ", "; 3323a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << "..."; 3333a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3343a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3353a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += ")"; 3363a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3374eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 3384eadcc569223135e13353c9381b448986e3f7053Sam Weinig Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers()); 3394eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasConst()) 3404eadcc569223135e13353c9381b448986e3f7053Sam Weinig Proto += " const"; 3414eadcc569223135e13353c9381b448986e3f7053Sam Weinig if (ThisQuals.hasVolatile()) 3424eadcc569223135e13353c9381b448986e3f7053Sam Weinig Proto += " volatile"; 3434eadcc569223135e13353c9381b448986e3f7053Sam Weinig } 3444eadcc569223135e13353c9381b448986e3f7053Sam Weinig 3453a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) 3463a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig AFT->getResultType().getAsStringInternal(Proto, Policy); 3473a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3483a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << Proto; 3493a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3503a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 3513a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 3523a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3533a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { 3543a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 3553a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 3563a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << (MD->isInstanceMethod() ? '-' : '+'); 3573a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '['; 358b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 359b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // For incorrect code, there might not be an ObjCInterfaceDecl. Do 360b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek // a null check to avoid a crash. 361b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) 362900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer Out << ID; 363b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek 3643a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCCategoryImplDecl *CID = 365900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) 366900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer Out << '(' << CID << ')'; 367900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer 3683a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ' '; 3693a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getSelector().getAsString(); 3703a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ']'; 3713a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3723a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 3733a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 3743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3753a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { 3763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. 3773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return "top level"; 3783a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 3793a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return ""; 3803a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 3813a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 3829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisvoid APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) { 3839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (hasAllocation()) 3849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis C.Deallocate(pVal); 3859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 3869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis BitWidth = Val.getBitWidth(); 3879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = Val.getNumWords(); 3889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis const uint64_t* Words = Val.getRawData(); 3899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) { 3909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis pVal = new (C) uint64_t[NumWords]; 3919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis std::copy(Words, Words + NumWords, pVal); 3929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } else if (NumWords == 1) 3939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = Words[0]; 3949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 3959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis VAL = 0; 3969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 3979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 3989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 3999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, const llvm::APInt &V, 4009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) { 4019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(C, V, type, l); 4029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral * 4059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, EmptyShell Empty) { 4069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) IntegerLiteral(Empty); 4079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 4109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V, 4119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L) { 4129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(C, V, isexact, Type, L); 4139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 4159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral * 4169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, EmptyShell Empty) { 4179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return new (C) FloatingLiteral(Empty); 4189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis} 4199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 420da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 421da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 422da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 423da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 424da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 425ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 426ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 427ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 428da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 429da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 430da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 4312085fd6cd22ec5c268175251db10d7c60caf7aaaChris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData, 4322085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, 4332085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner QualType Ty, 4341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const SourceLocation *Loc, 435a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 4362085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 4372085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 4382085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 4392085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 4403248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 4412085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 4421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 4442085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner char *AStrData = new (C, 1) char[ByteLength]; 4452085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(AStrData, StrData, ByteLength); 4462085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->StrData = AStrData; 4472085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->ByteLength = ByteLength; 4482085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->IsWide = Wide; 4492085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 4502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 452726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 4532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 4542085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 455726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 456726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 457673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 458673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 459673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 4603248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner llvm::alignOf<StringLiteral>()); 461673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 462673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->StrData = 0; 463673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->ByteLength = 0; 464673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 465673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 466673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 467673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 468b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbarvoid StringLiteral::setString(ASTContext &C, llvm::StringRef Str) { 469b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar char *AStrData = new (C, 1) char[Str.size()]; 470b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar memcpy(AStrData, Str.data(), Str.size()); 471673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StrData = AStrData; 472b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar ByteLength = Str.size(); 473673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 474673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 47508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// getLocationOfByte - Return a source location that points to the specified 47608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// byte of this string literal. 47708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 47808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// Strings are amazingly complex. They can be formed from multiple tokens and 47908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// can have escape sequences in them in addition to the usual trigraph and 48008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// escaped newline business. This routine handles this complexity. 48108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner/// 48208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnerSourceLocation StringLiteral:: 48308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris LattnergetLocationOfByte(unsigned ByteNo, const SourceManager &SM, 48408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, const TargetInfo &Target) const { 48508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner assert(!isWide() && "This doesn't work for wide strings yet"); 48608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 48708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Loop over all of the tokens in this string until we find the one that 48808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // contains the byte we're looking for. 48908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNo = 0; 49008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner while (1) { 49108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner assert(TokNo < getNumConcatenated() && "Invalid byte number!"); 49208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokLoc = getStrTokenLoc(TokNo); 49308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 49408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Get the spelling of the string so that we can get the data that makes up 49508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // the string literal, not the identifier for the macro it is potentially 49608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // expanded through. 49708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); 49808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 49908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Re-lex the token to get its length and original spelling. 50008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner std::pair<FileID, unsigned> LocInfo =SM.getDecomposedLoc(StrTokSpellingLoc); 50108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner bool Invalid = false; 50208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner llvm::StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); 50308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (Invalid) 50408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return StrTokSpellingLoc; 50508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 50608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const char *StrData = Buffer.data()+LocInfo.second; 50708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 50808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a langops struct and enable trigraphs. This is sufficient for 50908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // relexing tokens. 51008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner LangOptions LangOpts; 51108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner LangOpts.Trigraphs = true; 51208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 51308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Create a lexer starting at the beginning of this token. 51408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Lexer TheLexer(StrTokSpellingLoc, Features, Buffer.begin(), StrData, 51508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Buffer.end()); 51608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner Token TheTok; 51708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner TheLexer.LexFromRawLexer(TheTok); 51808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 51908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Use the StringLiteralParser to compute the length of the string in bytes. 52008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner StringLiteralParser SLP(&TheTok, 1, SM, Features, Target); 52108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned TokNumBytes = SLP.GetStringLength(); 52208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 52308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // If the byte is in this token, return the location of the byte. 52408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner if (ByteNo < TokNumBytes || 52508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner (ByteNo == TokNumBytes && TokNo == getNumConcatenated())) { 52608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); 52708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 52808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Now that we know the offset of the token in the spelling, use the 52908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // preprocessor to get the offset in the original source. 53008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); 53108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 53208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 53308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner // Move to the next string token. 53408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ++TokNo; 53508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner ByteNo -= TokNumBytes; 53608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner } 53708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner} 53808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 53908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 54008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) { 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: assert(0 && "Unknown unary operator"); 5462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: return "++"; 5472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: return "--"; 5482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: return "++"; 5492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: return "--"; 5502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return "&"; 5512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return "*"; 5522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return "+"; 5532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return "-"; 5542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return "~"; 5552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return "!"; 5562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: return "__real"; 5572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: return "__imag"; 5582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: return "__extension__"; 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallUnaryOperatorKind 563bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 564bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 565bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: assert(false && "No unary operator for overloaded function"); 5662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc; 5672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; 5682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return UO_AddrOf; 5692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return UO_Deref; 5702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return UO_Plus; 5712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return UO_Minus; 5722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Tilde: return UO_Not; 5732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Exclaim: return UO_LNot; 574bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 575bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 576bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 577bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 578bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 5792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: case UO_PreInc: return OO_PlusPlus; 5802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: case UO_PreDec: return OO_MinusMinus; 5812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_AddrOf: return OO_Amp; 5822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: return OO_Star; 5832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Plus: return OO_Plus; 5842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Minus: return OO_Minus; 5852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Not: return OO_Tilde; 5862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_LNot: return OO_Exclaim; 587bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 588bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 589bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 590bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 591bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 5935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 596668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, 597f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall unsigned numargs, QualType t, ExprValueKind VK, 598f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation rparenloc) 599f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(SC, t, VK, OK_Ordinary, 600898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), 601d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), 602898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 6031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 604668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek SubExprs = new (C) Stmt*[numargs+1]; 605b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 606b4609806e9232593ece09ce08b630836e825865cDouglas Gregor for (unsigned i = 0; i != numargs; ++i) 607b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[i+ARGS_START] = args[i]; 608668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 609b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 610b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 611e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 612668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 613f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation rparenloc) 614f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CallExprClass, t, VK, OK_Ordinary, 615898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), 616d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), 617898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 618668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 619668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek SubExprs = new (C) Stmt*[numargs+1]; 62077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numargs; ++i) 62277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[i+ARGS_START] = args[i]; 623668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6271eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 6291f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor SubExprs = new (C) Stmt*[1]; 6301f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 6311f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 632d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() { 633a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu Expr *CEE = getCallee()->IgnoreParenCasts(); 634200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl // If we're calling a dereference, look at the pointer instead. 635200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) { 636200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (BO->isPtrMemOp()) 637200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = BO->getRHS()->IgnoreParenCasts(); 638200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) { 639200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl if (UO->getOpcode() == UO_Deref) 640200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl CEE = UO->getSubExpr()->IgnoreParenCasts(); 641200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl } 6426346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 643d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return DRE->getDecl(); 644cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) 645cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes return ME->getMemberDecl(); 646a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 647a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 648a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 649a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 650d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() { 651caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); 652d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes} 653d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 654d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 655d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 656d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 6578189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 658d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 659d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 661d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 662d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 663d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 664d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 665d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 666d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 667d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 66868a049cab6015a7437bec5661601b7d37d23c70cDaniel Dunbar Stmt **NewSubExprs = new (C) Stmt*[NumArgs+1]; 669d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 670d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i) 671d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 672d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 673d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i) 674d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67688c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 677d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 678d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 679d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 680d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 681cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 682cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 6833c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregorunsigned CallExpr::isBuiltinCall(ASTContext &Context) const { 684c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 6851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // function. As a result, we try and obtain the DeclRefExpr from the 686c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 687c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 688c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 689cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 691c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 692c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 693cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 695bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 696bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 697cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 6981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6994fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 7004fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 7014fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 7027814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor return FDecl->getBuiltinID(); 703cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 704bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 7056dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 7066dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 7076217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 7086dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 7096217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 7106dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 7115291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor else if (const MemberPointerType *MPT 7125291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor = CalleeType->getAs<MemberPointerType>()) 7135291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor CalleeType = MPT->getPointeeType(); 7145291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 715183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *FnType = CalleeType->getAs<FunctionType>(); 7166dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 7176dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 718cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 719c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, 7208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, 721c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TypeSourceInfo *tsi, 722c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 7238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 7248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 7258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 726c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt sizeof(OffsetOfNode) * numComps + 7278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 7288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 7298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps, 7308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor exprsPtr, numExprs, RParenLoc); 7318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 7328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 7338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C, 7348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned numComps, unsigned numExprs) { 7358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void *Mem = C.Allocate(sizeof(OffsetOfExpr) + 7368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(OffsetOfNode) * numComps + 7378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor sizeof(Expr*) * numExprs); 7388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return new (Mem) OffsetOfExpr(numComps, numExprs); 7398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 7408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 741c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type, 7428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 743c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 7448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 7458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) 746f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, 747f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent=*/false, 7488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /*ValueDependent=*/tsi->getType()->isDependentType() || 7498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor hasAnyTypeDependentArguments(exprsPtr, numExprs) || 7508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor hasAnyValueDependentArguments(exprsPtr, numExprs)), 751c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), 752c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NumComps(numComps), NumExprs(numExprs) 7538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{ 7548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numComps; ++i) { 7558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setComponent(i, compsPtr[i]); 7568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 757c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for(unsigned i = 0; i < numExprs; ++i) { 7598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor setIndexExpr(i, exprsPtr[i]); 7608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 7618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 7628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 7638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const { 7648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field || getKind() == Identifier); 7658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (getKind() == Field) 7668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getField()->getIdentifier(); 767c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); 7698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 7708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 7711eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *qual, 77383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor SourceRange qualrange, 774f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 775161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair founddecl, 7762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo nameinfo, 777d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 778f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, 779f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind vk, 780f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind ok) { 78183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 7826bb8017bb9e828d118e15e59d71c66bba323c364John McCall 783161755a09898c95d21bfff33707da9ca41cd53c5John McCall bool hasQualOrFound = (qual != 0 || 784161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getDecl() != memberdecl || 785161755a09898c95d21bfff33707da9ca41cd53c5John McCall founddecl.getAccess() != memberdecl->getAccess()); 7866bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) 7876bb8017bb9e828d118e15e59d71c66bba323c364John McCall Size += sizeof(MemberNameQualifier); 7881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 789d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 790d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Size += ExplicitTemplateArgumentList::sizeFor(*targs); 7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7923248854a5d16e1de17c58e05f726bdef9f042df2Chris Lattner void *Mem = C.Allocate(Size, llvm::alignOf<MemberExpr>()); 793f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, 794f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ty, vk, ok); 7956bb8017bb9e828d118e15e59d71c66bba323c364John McCall 7966bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (hasQualOrFound) { 7976bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (qual && qual->isDependent()) { 7986bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setValueDependent(true); 7996bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->setTypeDependent(true); 8006bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 8016bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasQualifierOrFoundDecl = true; 8026bb8017bb9e828d118e15e59d71c66bba323c364John McCall 8036bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *NQ = E->getMemberQualifier(); 8046bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->NNS = qual; 8056bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->Range = qualrange; 8066bb8017bb9e828d118e15e59d71c66bba323c364John McCall NQ->FoundDecl = founddecl; 8076bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 8086bb8017bb9e828d118e15e59d71c66bba323c364John McCall 8096bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (targs) { 8106bb8017bb9e828d118e15e59d71c66bba323c364John McCall E->HasExplicitTemplateArgumentList = true; 811096832c5ed5b9106fa177ebc148489760c3bc496John McCall E->getExplicitTemplateArgs().initializeFrom(*targs); 8126bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 8136bb8017bb9e828d118e15e59d71c66bba323c364John McCall 8146bb8017bb9e828d118e15e59d71c66bba323c364John McCall return E; 81583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 81683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 817f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 818f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 819daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 820daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "Dependent"; 8212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BitCast: 822f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 8232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_LValueBitCast: 824e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor return "LValueBitCast"; 8252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NoOp: 826f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 8272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerived: 82811de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson return "BaseToDerived"; 8292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBase: 830f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 8312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UncheckedDerivedToBase: 83223cba801e11b03929c44f8cf54578305963a3476John McCall return "UncheckedDerivedToBase"; 8332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_Dynamic: 834f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 8352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToUnion: 836f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 8372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ArrayToPointerDecay: 838f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 8392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FunctionToPointerDecay: 840f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 8412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_NullToMemberPointer: 842f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 843404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 844404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall return "NullToPointer"; 8452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_BaseToDerivedMemberPointer: 846f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 8472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_DerivedToBaseMemberPointer: 8481a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson return "DerivedToBaseMemberPointer"; 8492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_UserDefinedConversion: 850f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 8512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ConstructorConversion: 852f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 8532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToPointer: 8547f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "IntegralToPointer"; 8552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_PointerToIntegral: 8567f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "PointerToIntegral"; 857daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 858daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "PointerToBoolean"; 8592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ToVoid: 860ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson return "ToVoid"; 8612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_VectorSplat: 86216a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson return "VectorSplat"; 8632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralCast: 86482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralCast"; 865daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 866daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "IntegralToBoolean"; 8672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_IntegralToFloating: 86882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralToFloating"; 8692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingToIntegral: 87082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "FloatingToIntegral"; 8712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_FloatingCast: 872c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer return "FloatingCast"; 873daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 874daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return "FloatingToBoolean"; 8752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_MemberPointerToBoolean: 876bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson return "MemberPointerToBoolean"; 8772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_AnyPointerToObjCPointerCast: 8784cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian return "AnyPointerToObjCPointerCast"; 8792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_AnyPointerToBlockPointerCast: 8803b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian return "AnyPointerToBlockPointerCast"; 8812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case CK_ObjCObjectLValueCast: 882569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return "ObjCObjectLValueCast"; 8832bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 8842bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingRealToComplex"; 885f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 886f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToReal"; 887f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToBoolean: 888f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToBoolean"; 8892bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 8902bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "FloatingComplexCast"; 891f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 892f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "FloatingComplexToIntegralComplex"; 8932bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 8942bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralRealToComplex"; 895f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 896f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToReal"; 897f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToBoolean: 898f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToBoolean"; 8992bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 9002bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall return "IntegralComplexCast"; 901f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 902f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall return "IntegralComplexToFloatingComplex"; 903f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 9041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9052bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall llvm_unreachable("Unhandled cast kind!"); 906f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return 0; 907f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 908f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 9096eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() { 9106eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *SubExpr = 0; 9116eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor CastExpr *E = this; 9126eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor do { 9136eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = E->getSubExpr(); 914c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 9156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Skip any temporary bindings; they're implicit. 9166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) 9176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = Binder->getSubExpr(); 918c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 9196eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Conversions by constructor and conversion functions have a 9206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // subexpression describing the call; strip it off. 9212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (E->getCastKind() == CK_ConstructorConversion) 9226eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); 9232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall else if (E->getCastKind() == CK_UserDefinedConversion) 9246eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); 925c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 9266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // If the subexpression we're left with is an implicit cast, look 9276eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // through that, too. 928c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); 929c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 9306eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return SubExpr; 9316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 9326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 933f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCXXBaseSpecifier **CastExpr::path_buffer() { 934f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall switch (getStmtClass()) { 935f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define ABSTRACT_STMT(x) 936f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define CASTEXPR(Type, Base) \ 937f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall case Stmt::Type##Class: \ 938f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1); 939f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define STMT(Type, Base) 940f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#include "clang/AST/StmtNodes.inc" 941f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall default: 942f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall llvm_unreachable("non-cast expressions not possible here"); 943f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return 0; 944f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 945f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 946f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 947f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallvoid CastExpr::setCastPath(const CXXCastPath &Path) { 948f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(Path.size() == path_size()); 949f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*)); 950f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 951f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 952f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T, 953f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 954f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 9555baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) { 956f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 957f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 958f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 959f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr *E = 9605baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); 961f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 962f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 963f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 964f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 965f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C, 966f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize) { 967f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 968f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 969f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); 970f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 971f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 972f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 973f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T, 974f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 975f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 976f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, 977f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation L, SourceLocation R) { 978f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize = (BasePath ? BasePath->size() : 0); 979f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 980f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 981f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CStyleCastExpr *E = 982f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); 983f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall if (PathSize) E->setCastPath(*BasePath); 984f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return E; 985f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 986f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 987f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) { 988f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void *Buffer = 989f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*)); 990f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); 991f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall} 992f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) { 9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 9972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemD: return ".*"; 9982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_PtrMemI: return "->*"; 9992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Mul: return "*"; 10002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Div: return "/"; 10012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Rem: return "%"; 10022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Add: return "+"; 10032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Sub: return "-"; 10042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shl: return "<<"; 10052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Shr: return ">>"; 10062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LT: return "<"; 10072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GT: return ">"; 10082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LE: return "<="; 10092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_GE: return ">="; 10102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_EQ: return "=="; 10112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_NE: return "!="; 10122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_And: return "&"; 10132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Xor: return "^"; 10142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Or: return "|"; 10152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: return "&&"; 10162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: return "||"; 10172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Assign: return "="; 10182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_MulAssign: return "*="; 10192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_DivAssign: return "/="; 10202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_RemAssign: return "%="; 10212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AddAssign: return "+="; 10222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_SubAssign: return "-="; 10232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShlAssign: return "<<="; 10242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_ShrAssign: return ">>="; 10252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_AndAssign: return "&="; 10262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_XorAssign: return "^="; 10272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_OrAssign: return "|="; 10282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: return ","; 10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1030baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 1031baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor return ""; 10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallBinaryOperatorKind 1035063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 1036063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 1037b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner default: assert(false && "Not an overloadable binary operator"); 10382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Plus: return BO_Add; 10392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Minus: return BO_Sub; 10402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Star: return BO_Mul; 10412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Slash: return BO_Div; 10422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Percent: return BO_Rem; 10432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Caret: return BO_Xor; 10442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Amp: return BO_And; 10452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Pipe: return BO_Or; 10462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Equal: return BO_Assign; 10472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Less: return BO_LT; 10482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Greater: return BO_GT; 10492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PlusEqual: return BO_AddAssign; 10502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_MinusEqual: return BO_SubAssign; 10512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_StarEqual: return BO_MulAssign; 10522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_SlashEqual: return BO_DivAssign; 10532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PercentEqual: return BO_RemAssign; 10542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_CaretEqual: return BO_XorAssign; 10552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpEqual: return BO_AndAssign; 10562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipeEqual: return BO_OrAssign; 10572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLess: return BO_Shl; 10582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreater: return BO_Shr; 10592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessLessEqual: return BO_ShlAssign; 10602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterGreaterEqual: return BO_ShrAssign; 10612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_EqualEqual: return BO_EQ; 10622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ExclaimEqual: return BO_NE; 10632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_LessEqual: return BO_LE; 10642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_GreaterEqual: return BO_GE; 10652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_AmpAmp: return BO_LAnd; 10662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_PipePipe: return BO_LOr; 10672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_Comma: return BO_Comma; 10682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case OO_ArrowStar: return BO_PtrMemI; 1069063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 1070063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1071063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1072063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 1073063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 1074063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 1075063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 1076063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 1077063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 1078063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 1079063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 1080063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 1081063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 1082063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 1083063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 1084063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 1085063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 1086063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 1087063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 1088063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 1089063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 1090063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 1091063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 1092063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 1093063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 1094063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 1095063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 1096709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc, 1097418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner Expr **initExprs, unsigned numInits, 10984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc) 1099f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false), 1100709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs(C, numInits), 11011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0), 1102c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt UnionFieldInit(0), HadArrayRangeDesignator(false) 1103c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt{ 1104ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek for (unsigned I = 0; I != numInits; ++I) { 1105ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isTypeDependent()) 11068e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = true; 1107ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (initExprs[I]->isValueDependent()) 11088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = true; 110973460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor } 1110c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1111709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits); 111266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1114709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) { 1115ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (NumInits > InitExprs.size()) 1116709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.reserve(C, NumInits); 1117fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 1118fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 1119709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) { 1120709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.resize(C, NumInits, 0); 11214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 11224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1123709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) { 1124ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek if (Init >= InitExprs.size()) { 1125709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0); 1126ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek InitExprs.back() = expr; 1127ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return 0; 11284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 11291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 11314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 11324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 11334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 11344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1135c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted KremenekSourceRange InitListExpr::getSourceRange() const { 1136c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (SyntacticForm) 1137c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SyntacticForm->getSourceRange(); 1138c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek SourceLocation Beg = LBraceLoc, End = RBraceLoc; 1139c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Beg.isInvalid()) { 1140c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer. 1141c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_iterator I = InitExprs.begin(), 1142c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.end(); 1143c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1144c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1145c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek Beg = S->getLocStart(); 1146c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1147c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1148c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1149c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1150c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (End.isInvalid()) { 1151c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek // Find the first non-null initializer from the end. 1152c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), 1153c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek E = InitExprs.rend(); 1154c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek I != E; ++I) { 1155c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek if (Stmt *S = *I) { 1156c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek End = S->getSourceRange().getEnd(); 1157c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek break; 1158c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1159c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1160c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek } 1161c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek return SourceRange(Beg, End); 1162c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek} 1163c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 1164bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 11654eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 11664eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const { 11676217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<BlockPointerType>()-> 1168183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall getPointeeType()->getAs<FunctionType>(); 11694eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 11704eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 11711eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const { 11721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getCaretLocation(); 117356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const { 11757297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 11767297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 11771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() { 11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getBody(); 11797297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 118056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 118156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1186026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 1187026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 1188026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 1189026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 1190026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattnerbool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 1191df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const { 1192ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 1193ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 1194ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 1195ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 11990faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 12000faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1201026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 1202026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1203026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 1205026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 1206df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump isUnusedResultAWarning(Loc, R1, R2, Ctx); 12075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 12091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 1211026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner default: break; 12122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostInc: 12132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PostDec: 12142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreInc: 12152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_PreDec: // ++/-- 1216026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 12172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Deref: 12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Dereferencing a volatile pointer is a side-effect. 1219df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1220026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1221026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 12222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Real: 12232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Imag: 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 1225df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) 1226df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump .isVolatileQualified()) 1227026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1228026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 12292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case UO_Extension: 1230df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1232026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 1233026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 1234026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1236e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 1237026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 1238c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek switch (BO->getOpcode()) { 1239c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek default: 1240c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek break; 124125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider the RHS of comma for side effects. LHS was checked by 124225973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Sema::CheckCommaOperands. 12432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_Comma: 1244c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // ((foo = <blah>), 0) is an idiom for hiding the result (and 1245c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek // lvalue-ness) of an assignment written in a macro. 1246c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IntegerLiteral *IE = 1247c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) 1248c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek if (IE->getValue() == 0) 1249c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek return false; 125025973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 125125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis // Consider '||', '&&' to have side effects if the LHS or RHS does. 12522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LAnd: 12532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall case BO_LOr: 125425973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis if (!BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) || 125525973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis !BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) 125625973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis return false; 125725973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis break; 1258bf0ee354163f87623a4b60412544243911332343John McCall } 1259026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 1260026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1261026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 1262026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 1263026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 1264026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1265e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 1266eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 1267c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor case VAArgExprClass: 1268026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1270ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 1271026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // The condition must be evaluated, but if either the LHS or RHS is a 1272026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // warning, warn about them. 1273ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Exp->getLHS() && 1275df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) 1276026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1277df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1278ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 1279ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 1281026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the base pointer or element is to a volatile pointer/field, accessing 1282026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 1283df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1284026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1285026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 1286026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 1287026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 1288026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the base pointer or element is to a volatile pointer/field, accessing 1292026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 1293df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 1294026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1295026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 1296026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 1297026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 1298026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1299211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 1301852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXOperatorCallExprClass: 1302852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXMemberCallExprClass: { 1303026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 1304026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 1305d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes if (const Decl *FD = CE->getCalleeDecl()) { 1306026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 1307026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 1308bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // 1309bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // Note: If new cases are added here, DiagnoseUnusedExprResult should be 1310bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // updated to match for QoI. 1311bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (FD->getAttr<WarnUnusedResultAttr>() || 1312bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 1313bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner Loc = CE->getCallee()->getLocStart(); 1314bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R1 = CE->getCallee()->getSourceRange(); 1315bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner 1316bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 1317bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 1318bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 1319bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return true; 1320bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1321026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 1322026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1323026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 132458beed91d468863b8c85bce43425422703838d27Anders Carlsson 132558beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXTemporaryObjectExprClass: 132658beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXConstructExprClass: 132758beed91d468863b8c85bce43425422703838d27Anders Carlsson return false; 132858beed91d468863b8c85bce43425422703838d27Anders Carlsson 1329f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian case ObjCMessageExprClass: { 1330f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); 1331f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian const ObjCMethodDecl *MD = ME->getMethodDecl(); 1332f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 1333f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian Loc = getExprLoc(); 1334f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian return true; 1335f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 1336026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 1337f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian } 13381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133909105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian case ObjCImplicitSetterGetterRefExprClass: { // Dot syntax for message send. 1340a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#if 0 13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCImplicitSetterGetterRefExpr *Ref = 134209105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian cast<ObjCImplicitSetterGetterRefExpr>(this); 1343a50089ec68a583d13718107c1b0c898f0903709eChris Lattner // FIXME: We really want the location of the '.' here. 1344154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian Loc = Ref->getLocation(); 1345154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian R1 = SourceRange(Ref->getLocation(), Ref->getLocation()); 1346154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian if (Ref->getBase()) 1347154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian R2 = Ref->getBase()->getSourceRange(); 13485e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner#else 13495e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 13505e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 1351a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#endif 1352a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 1353a50089ec68a583d13718107c1b0c898f0903709eChris Lattner } 1354611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 1355611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 1356611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 1357611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 1358611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 1359611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 1360611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 1361d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (!CS->body_empty()) { 1362611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 1363df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1364d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) 1365d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) 1366d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); 1367d2827af6f96d441d72315dbe6d8505c3be0f2aa6Argyrios Kyrtzidis } 13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13690faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 13700faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 1371026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 1372026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 1373026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 1374611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 13756eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor case CStyleCastExprClass: 1376fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // If this is an explicit cast to void, allow it. People do this when they 1377fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // think they know what they're doing :). 1378026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (getType()->isVoidType()) 1379fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner return false; 1380026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); 1381026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); 1382026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 138358beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXFunctionalCastExprClass: { 13840faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall if (getType()->isVoidType()) 13850faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall return false; 138658beed91d468863b8c85bce43425422703838d27Anders Carlsson const CastExpr *CE = cast<CastExpr>(this); 1387c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 138858beed91d468863b8c85bce43425422703838d27Anders Carlsson // If this is a cast to void or a constructor conversion, check the operand. 138958beed91d468863b8c85bce43425422703838d27Anders Carlsson // Otherwise, the result of the cast is unused. 13902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (CE->getCastKind() == CK_ToVoid || 13912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall CE->getCastKind() == CK_ConstructorConversion) 1392df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CastExpr>(this)->getSubExpr() 1393df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 1394026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); 1395026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); 1396026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 139758beed91d468863b8c85bce43425422703838d27Anders Carlsson } 13981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13994be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman case ImplicitCastExprClass: 14004be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman // Check the operand, since implicit casts are inserted by Sema 1401df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<ImplicitCastExpr>(this) 1402df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 14034be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 140404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 1405df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXDefaultArgExpr>(this) 1406df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 14074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 14094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 14104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 14114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 1412026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 14132d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 1414df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXBindTemporaryExpr>(this) 1415df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 14166b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson case CXXExprWithTemporariesClass: 1417df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXExprWithTemporaries>(this) 1418df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 14194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 14205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 14215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 142244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 14237f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise. 1424102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 142544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian switch (getStmtClass()) { 142644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 142744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 142844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 142944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 1430207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 1431102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 143244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ParenExprClass: 1433102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 143444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 1435102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 143606b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 1437102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 1438a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { 143944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const Decl *D = cast<DeclRefExpr>(this)->getDecl(); 1440102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 1441102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 1442102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 1443102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 144459a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // dereferencing to a pointer is always a gc'able candidate, 144559a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // unless it is __weak. 14467e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar return T->isPointerType() && 14470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); 1448102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 144944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 145044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 145183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 145244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const MemberExpr *M = cast<MemberExpr>(this); 1453102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 145444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 145544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 1456102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx); 145744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 145844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 1459369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 146011ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidisbool Expr::isBoundMemberFunction(ASTContext &Ctx) const { 146111ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis if (isTypeDependent()) 146211ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis return false; 14637eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; 146411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis} 146511ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 1466369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult MergeCanThrow(Expr::CanThrowResult CT1, 1467369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr::CanThrowResult CT2) { 1468369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // CanThrowResult constants are ordered so that the maximum is the correct 1469369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // merge result. 1470369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT1 > CT2 ? CT1 : CT2; 1471369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1472369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1473369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanSubExprsThrow(ASTContext &C, const Expr *CE) { 1474369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr *E = const_cast<Expr*>(CE); 1475369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr::CanThrowResult R = Expr::CT_Cannot; 1476369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl for (Expr::child_iterator I = E->child_begin(), IE = E->child_end(); 1477369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl I != IE && R != Expr::CT_Can; ++I) { 1478369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl R = MergeCanThrow(R, cast<Expr>(*I)->CanThrow(C)); 1479369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1480369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return R; 1481369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1482369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1483369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanCalleeThrow(const Decl *D, 1484369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl bool NullThrows = true) { 1485369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!D) 1486369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return NullThrows ? Expr::CT_Can : Expr::CT_Cannot; 1487369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1488369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // See if we can get a function type from the decl somehow. 1489369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const ValueDecl *VD = dyn_cast<ValueDecl>(D); 1490369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!VD) // If we have no clue what we're calling, assume the worst. 1491369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Can; 1492369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 14935221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl // As an extension, we assume that __attribute__((nothrow)) functions don't 14945221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl // throw. 14955221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl if (isa<FunctionDecl>(D) && D->hasAttr<NoThrowAttr>()) 14965221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl return Expr::CT_Cannot; 14975221d8f2da008689f7ff9476e6522bb2b63ec1a3Sebastian Redl 1498369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl QualType T = VD->getType(); 1499369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const FunctionProtoType *FT; 1500369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if ((FT = T->getAs<FunctionProtoType>())) { 1501369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } else if (const PointerType *PT = T->getAs<PointerType>()) 1502369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = PT->getPointeeType()->getAs<FunctionProtoType>(); 1503369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 1504369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = RT->getPointeeType()->getAs<FunctionProtoType>(); 1505369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl else if (const MemberPointerType *MT = T->getAs<MemberPointerType>()) 1506369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = MT->getPointeeType()->getAs<FunctionProtoType>(); 1507369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl else if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) 1508369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl FT = BT->getPointeeType()->getAs<FunctionProtoType>(); 1509369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1510369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!FT) 1511369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Can; 1512369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1513369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return FT->hasEmptyExceptionSpec() ? Expr::CT_Cannot : Expr::CT_Can; 1514369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1515369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1516369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanDynamicCastThrow(const CXXDynamicCastExpr *DC) { 1517369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (DC->isTypeDependent()) 1518369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Dependent; 1519369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1520295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl if (!DC->getTypeAsWritten()->isReferenceType()) 1521295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl return Expr::CT_Cannot; 1522295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl 1523369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return DC->getCastKind() == clang::CK_Dynamic? Expr::CT_Can : Expr::CT_Cannot; 1524369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1525369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1526369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanTypeidThrow(ASTContext &C, 1527369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const CXXTypeidExpr *DC) { 1528369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (DC->isTypeOperand()) 1529369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1530369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1531369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl Expr *Op = DC->getExprOperand(); 1532369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (Op->isTypeDependent()) 1533369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Dependent; 1534369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1535369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl const RecordType *RT = Op->getType()->getAs<RecordType>(); 1536369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!RT) 1537369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1538369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1539369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (!cast<CXXRecordDecl>(RT->getDecl())->isPolymorphic()) 1540369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1541369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1542369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (Op->Classify(C).isPRValue()) 1543369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Cannot; 1544369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1545369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return Expr::CT_Can; 1546369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1547369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1548369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian RedlExpr::CanThrowResult Expr::CanThrow(ASTContext &C) const { 1549369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // C++ [expr.unary.noexcept]p3: 1550369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // [Can throw] if in a potentially-evaluated context the expression would 1551369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // contain: 1552369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl switch (getStmtClass()) { 1553369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXThrowExprClass: 1554369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated throw-expression 1555369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Can; 1556369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1557369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDynamicCastExprClass: { 1558369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated dynamic_cast expression dynamic_cast<T>(v), 1559369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // where T is a reference type, that requires a run-time check 1560369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = CanDynamicCastThrow(cast<CXXDynamicCastExpr>(this)); 1561369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1562369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1563369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1564369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1565369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1566369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXTypeidExprClass: 1567369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated typeid expression applied to a glvalue 1568369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // expression whose type is a polymorphic class type 1569369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CanTypeidThrow(C, cast<CXXTypeidExpr>(this)); 1570369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1571369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // - a potentially evaluated call to a function, member function, function 1572369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // pointer, or member function pointer that does not have a non-throwing 1573369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // exception-specification 1574369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CallExprClass: 1575369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXOperatorCallExprClass: 1576369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXMemberCallExprClass: { 1577369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = CanCalleeThrow(cast<CallExpr>(this)->getCalleeDecl()); 1578369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1579369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1580369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1581369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1582369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1583295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl case CXXConstructExprClass: 1584295995c9c3196416372c9cd35d9cedb6da37bd3dSebastian Redl case CXXTemporaryObjectExprClass: { 1585369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = CanCalleeThrow( 1586369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl cast<CXXConstructExpr>(this)->getConstructor()); 1587369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1588369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1589369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1590369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1591369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1592369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXNewExprClass: { 1593369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = MergeCanThrow( 1594369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanCalleeThrow(cast<CXXNewExpr>(this)->getOperatorNew()), 1595369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanCalleeThrow(cast<CXXNewExpr>(this)->getConstructor(), 1596369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /*NullThrows*/false)); 1597369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1598369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 1599369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1600369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1601369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1602369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDeleteExprClass: { 1603369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = CanCalleeThrow( 1604369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl cast<CXXDeleteExpr>(this)->getOperatorDelete()); 1605369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (CT == CT_Can) 1606369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT; 16070b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl const Expr *Arg = cast<CXXDeleteExpr>(this)->getArgument(); 16080b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl // Unwrap exactly one implicit cast, which converts all pointers to void*. 16090b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (const ImplicitCastExpr *Cast = dyn_cast<ImplicitCastExpr>(Arg)) 16100b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl Arg = Cast->getSubExpr(); 16110b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (const PointerType *PT = Arg->getType()->getAs<PointerType>()) { 16120b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) { 16130b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl CanThrowResult CT2 = CanCalleeThrow( 16140b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl cast<CXXRecordDecl>(RT->getDecl())->getDestructor()); 16150b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (CT2 == CT_Can) 16160b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl return CT2; 16170b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl CT = MergeCanThrow(CT, CT2); 16180b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl } 16190b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl } 16200b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 16210b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl } 16220b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl 16230b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl case CXXBindTemporaryExprClass: { 16240b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl // The bound temporary has to be destroyed again, which might throw. 16250b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl CanThrowResult CT = CanCalleeThrow( 16260b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl cast<CXXBindTemporaryExpr>(this)->getTemporary()->getDestructor()); 16270b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl if (CT == CT_Can) 16280b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl return CT; 1629369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1630369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1631369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1632369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // ObjC message sends are like function calls, but never have exception 1633369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // specs. 1634369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCMessageExprClass: 1635369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCPropertyRefExprClass: 1636369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCImplicitSetterGetterRefExprClass: 1637369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Can; 1638369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1639369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Many other things have subexpressions, so we have to test those. 1640369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Some are simple: 1641369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ParenExprClass: 1642369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case MemberExprClass: 1643369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXReinterpretCastExprClass: 1644369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXConstCastExprClass: 1645369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ConditionalOperatorClass: 1646369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CompoundLiteralExprClass: 1647369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ExtVectorElementExprClass: 1648369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case InitListExprClass: 1649369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case DesignatedInitExprClass: 1650369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ParenListExprClass: 1651369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case VAArgExprClass: 1652369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDefaultArgExprClass: 16530b34cf7399e61ef33dc5a3af405351822eeb5f3eSebastian Redl case CXXExprWithTemporariesClass: 1654369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCIvarRefExprClass: 1655369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ObjCIsaExprClass: 1656369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ShuffleVectorExprClass: 1657369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CanSubExprsThrow(C, this); 1658369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1659369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Some might be dependent for other reasons. 1660369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case UnaryOperatorClass: 1661369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ArraySubscriptExprClass: 1662369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ImplicitCastExprClass: 1663369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CStyleCastExprClass: 1664369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXStaticCastExprClass: 1665369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXFunctionalCastExprClass: 1666369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case BinaryOperatorClass: 1667369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CompoundAssignOperatorClass: { 1668369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CT = isTypeDependent() ? CT_Dependent : CT_Cannot; 1669369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return MergeCanThrow(CT, CanSubExprsThrow(C, this)); 1670369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1671369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1672369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // FIXME: We should handle StmtExpr, but that opens a MASSIVE can of worms. 1673369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case StmtExprClass: 1674369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Can; 1675369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1676369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case ChooseExprClass: 1677369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl if (isTypeDependent() || isValueDependent()) 1678369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Dependent; 1679369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return cast<ChooseExpr>(this)->getChosenSubExpr(C)->CanThrow(C); 1680369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1681369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // Some expressions are always dependent. 1682369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case DependentScopeDeclRefExprClass: 1683369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXUnresolvedConstructExprClass: 1684369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl case CXXDependentScopeMemberExprClass: 1685369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Dependent; 1686369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 1687369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl default: 1688369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // All other expressions don't have subexpressions, or else they are 1689369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl // unevaluated. 1690369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl return CT_Cannot; 1691369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl } 1692369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl} 1693369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 16944e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 16954e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 1696b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara while (true) { 1697b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 1698b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1699b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1700b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1701b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 1702b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 1703b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1704b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1705b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1706b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1707b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 1708b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 17094e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 17104e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 171156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 171256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 171356f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 171456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 171556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 1716b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr* P = dyn_cast<ParenExpr>(E)) { 171756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 1718b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1719b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1720b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (CastExpr *P = dyn_cast<CastExpr>(E)) { 172156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 1722b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1723b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1724b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 1725b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 1726b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1727b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1728b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1729b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1730b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 173156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 173256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 173356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 17342fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() { 17352fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *E = this; 17362fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall while (true) { 1737b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 17382fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 1739b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1740b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1741b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) { 17422fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall E = P->getSubExpr(); 1743b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1744b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1745b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 1746b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 1747b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1748b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1749b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1750b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1751b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara return E; 17522fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall } 17532fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall} 17542fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 1755ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 1756ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 1757ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 1758ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 1759ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 1760ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 1761ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 1762ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 1763ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1764ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1766ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 1767ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 17682ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor // ptr<->int casts of the same width. We also ignore all identity casts. 1769ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 17701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1771ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 1772ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1773ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1774ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 17751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1776b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if ((E->getType()->isPointerType() || 17779d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor E->getType()->isIntegralType(Ctx)) && 1778b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara (SE->getType()->isPointerType() || 17799d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor SE->getType()->isIntegralType(Ctx)) && 1780ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 1781ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1782ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1783ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1784ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 17851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1786b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) { 1787b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara if (P->getOpcode() == UO_Extension) { 1788b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara E = P->getSubExpr(); 1789b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara continue; 1790b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1791b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara } 1792b9eb35ced8369c8c8479efc17712faaf34e16c56Abramo Bagnara 1793ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 1794ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1795ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 1796ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 17976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const { 17986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *E = this; 17996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) 18006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor E = ICE->getSubExprAsWritten(); 1801c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 18026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return isa<CXXDefaultArgExpr>(E); 18036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 1804ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 18052f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding 18062f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions. 1807f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlssonstatic const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { 18082f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 18092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 18102f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 18112f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 18122f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 18132f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 18142f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 18152f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) 18162f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = BE->getSubExpr(); 18172f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 18182f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 18192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (ICE->getCastKind() == CK_NoOp) 18202f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor E = ICE->getSubExpr(); 18212f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor else 18222f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor break; 18232f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 1824f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson 1825f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson return E->IgnoreParens(); 18262f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 18272f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 1828558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// isTemporaryObject - Determines if this expression produces a 1829558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall/// temporary of the given class type. 1830558d2abc7f9fd6801cc7677200992313ae90b5d8John McCallbool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { 1831558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) 1832558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 18332f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 1834f8b3015060096a946d91578d0f3b65d3097a4ebbAnders Carlsson const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); 18352f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 183658277b57f9492d0234748be89bcad48b322c5cf7John McCall // Temporaries are by definition pr-values of class type. 1837db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian if (!E->Classify(C).isPRValue()) { 1838db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian // In this context, property reference is a message call and is pr-value. 1839db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian if (!isa<ObjCPropertyRefExpr>(E) && 1840db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian !isa<ObjCImplicitSetterGetterRefExpr>(E)) 1841db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian return false; 1842db148be93c9af45da1f3aa9302c577618a56e6eaFariborz Jahanian } 18432f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 184419e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // Black-list a few cases which yield pr-values of class type that don't 184519e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // refer to temporaries of that type: 184619e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 184719e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - implicit derived-to-base conversions 1848558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall if (isa<ImplicitCastExpr>(E)) { 1849558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall switch (cast<ImplicitCastExpr>(E)->getCastKind()) { 1850558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_DerivedToBase: 1851558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall case CK_UncheckedDerivedToBase: 1852558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return false; 1853558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall default: 1854558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall break; 1855558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 18562f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor } 18572f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 185819e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall // - member expressions (all) 185919e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall if (isa<MemberExpr>(E)) 186019e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall return false; 186119e60ad937af50843a653fa19c8be6a83a64f24fJohn McCall 1862558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall return true; 18632f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor} 18642f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 1865898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 1866898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 1867898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) { 1868898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 1869898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 1870898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 1871898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1872898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1873898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1874898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1875898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyValueDependentArguments - Determines if any of the expressions 1876898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is value-dependent. 1877898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) { 1878898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 1879898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isValueDependent()) 1880898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 1881898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1882898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1883898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1884898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 18854204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const { 1886c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 1887c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 1888c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 1889c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 1890c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 1891c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 18924204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // If we ever capture reference-binding directly in the AST, we can 18934204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // kill the second parameter. 18944204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 18954204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (IsForRef) { 18964204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall EvalResult Result; 18974204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects; 18984204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall } 18991f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 1900e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 1901c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 1902e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 190314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 1904eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 1905e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 1906b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXTemporaryObjectExprClass: 1907b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXConstructExprClass: { 1908b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); 19094204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 19104204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // Only if it's 19114204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // 1) an application of the trivial default constructor or 1912b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall if (!CE->getConstructor()->isTrivial()) return false; 19134204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!CE->getNumArgs()) return true; 19144204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall 19154204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // 2) an elidable trivial copy construction of an operand which is 19164204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // itself a constant initializer. Note that we consider the 19174204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall // operand on its own, *not* as a reference binding. 19184204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return CE->isElidable() && 19194204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall CE->getArg(0)->isConstantInitializer(Ctx, false); 1920b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall } 192159b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 19221f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 19231f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 19241f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 192559b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 19264204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->isConstantInitializer(Ctx, false); 192759b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 1928e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 19291f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 19301f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 19311f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 1932e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 1933e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 1934e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 19354204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall if (!Exp->getInit(i)->isConstantInitializer(Ctx, false)) 1936e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 1937e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 1938c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 1939e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 19403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 19413498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 19423ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case ParenExprClass: 19434204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<ParenExpr>(this)->getSubExpr() 19444204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, IsForRef); 19455cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara case ChooseExprClass: 19465cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx) 19475cadfab3f2e7660453211eb0e00314bd40d93014Abramo Bagnara ->isConstantInitializer(Ctx, IsForRef); 1948c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 1949c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 19502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == UO_Extension) 19514204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return Exp->getSubExpr()->isConstantInitializer(Ctx, false); 1952c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 1953c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 19543ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case BinaryOperatorClass: { 19553ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // Special case &&foo - &&bar. It would be nice to generalize this somehow 19563ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // but this handles the common case. 19573ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner const BinaryOperator *Exp = cast<BinaryOperator>(this); 19582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall if (Exp->getOpcode() == BO_Sub && 19593ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) && 19603ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx))) 19613ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner return true; 19623ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner break; 19633ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner } 19644204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall case CXXFunctionalCastExprClass: 1965b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall case CXXStaticCastExprClass: 196681045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 1967c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case CStyleCastExprClass: 1968c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // Handle casts with a destination that's a struct or union; this 1969c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // deals with both the gcc no-op struct cast extension and the 1970c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // cast-to-union extension. 1971c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman if (getType()->isRecordType()) 19724204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<CastExpr>(this)->getSubExpr() 19734204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, false); 1974c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1975430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // Integer->integer casts can be handled here, which is important for 1976430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // things like (int)(&&x-&&y). Scary but true. 1977430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner if (getType()->isIntegerType() && 1978430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType()) 19794204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall return cast<CastExpr>(this)->getSubExpr() 19804204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall ->isConstantInitializer(Ctx, false); 1981c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1982c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 1983e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 1984c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 198538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 198638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 19875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 19885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// integer constant expression with the value zero, or if this is one that is 19895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// cast to void*. 1990ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregorbool Expr::isNullPointerConstant(ASTContext &Ctx, 1991ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NullPointerConstantValueDependence NPC) const { 1992ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor if (isValueDependent()) { 1993ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor switch (NPC) { 1994ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_NeverValueDependent: 1995ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor assert(false && "Unexpected value dependent expression!"); 1996ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor // If the unthinkable happens, fall through to the safest alternative. 1997c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1998ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNull: 19999d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor return isTypeDependent() || getType()->isIntegralType(Ctx); 2000c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2001ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNotNull: 2002ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return false; 2003ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2004ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 2005f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar 20060777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 20070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 20086215dee86c0e715b9f2b0d401ab2a5fcf629f1afSebastian Redl if (!Ctx.getLangOptions().CPlusPlus) { 20090777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 20106217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 20110777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 20120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Pointee.hasQualifiers() && 20130777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 20140777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 2015ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 20160777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 20175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2018aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 2019aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 2020ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 2021aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 2022aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 2023aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 2024ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 20251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (const CXXDefaultArgExpr *DefaultArg 20268123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 202704421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 2028ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); 20292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 20302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 20312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return true; 2032aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 20332d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 20346e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // C++0x nullptr_t is always a null pointer constant. 20356e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 20366e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return true; 20376e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 2038ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const RecordType *UT = getType()->getAsUnionType()) 2039ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) 2040ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ 2041ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian const Expr *InitExpr = CLE->getInitializer(); 2042ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) 2043ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); 2044ff3a078d2a67db9ae6ff4cc0f799a209f85a4e91Fariborz Jahanian } 2045aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 2046c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (!getType()->isIntegerType() || 204756fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType())) 2048aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff return false; 20491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 20515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // test for the value 0. 205209de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman llvm::APSInt Result; 205309de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman return isIntegerConstantExpr(Result, Ctx) && Result == 0; 20545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 205531a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 205633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 20576f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 205833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 2059de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 20605baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall if (ICE->getValueKind() != VK_RValue && 20612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall ICE->getCastKind() == CK_NoOp) 2062de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor E = ICE->getSubExpr()->IgnoreParens(); 2063de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor else 2064de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor break; 2065de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor } 2066de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor 206727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 206886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 206933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 207033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 207133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 20720f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) 20730f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) 20740f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis if (Field->isBitField()) 20750f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis return Field; 20760f279e756e3df69f9e071c572805e5d3e89123a2Argyrios Kyrtzidis 207733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) 207833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 207933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 208033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 208133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 208227c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 208327c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 2084093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const { 2085093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson const Expr *E = this->IgnoreParens(); 2086c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2087093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { 20885baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall if (ICE->getValueKind() != VK_RValue && 20892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall ICE->getCastKind() == CK_NoOp) 2090093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson E = ICE->getSubExpr()->IgnoreParens(); 2091093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson else 2092093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson break; 2093093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson } 2094c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2095093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) 2096093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return ASE->getBase()->getType()->isVectorType(); 2097093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2098093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson if (isa<ExtVectorElementExpr>(E)) 2099093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return true; 2100093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 2101093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson return false; 2102093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson} 2103093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson 21042140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 21052140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 21062140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 21072140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 21082140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 21092140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 2110213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 2111183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const VectorType *VT = getType()->getAs<VectorType>()) 21128a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 21138a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 21144d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 21154d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 21168a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 2117213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 2118a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // FIXME: Refactor this code to an accessor on the AST node which returns the 2119a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // "type" of component access, and share with code below and in Sema. 212001eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar llvm::StringRef Comp = Accessor->getName(); 2121190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 2122190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 2123150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") 2124190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 21251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2126190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 2127150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 2128150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar Comp = Comp.substr(1); 21291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2130150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar for (unsigned i = 0, e = Comp.size(); i != e; ++i) 2131150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp.substr(i + 1).find(Comp[i]) != llvm::StringRef::npos) 2132fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 2133150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar 2134fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 2135fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 2136b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 21378a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 21383b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 21393b8d116703db8018f855cbb4733ace426422623bNate Begeman llvm::SmallVectorImpl<unsigned> &Elts) const { 21404b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar llvm::StringRef Comp = Accessor->getName(); 21414b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 21424b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Comp = Comp.substr(1); 21431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21444b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isHi = Comp == "hi"; 21454b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isLo = Comp == "lo"; 21464b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isEven = Comp == "even"; 21474b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isOdd = Comp == "odd"; 21481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21498a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 21508a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 21511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21528a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 21538a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 21548a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 21558a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 21568a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 21578a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 21588a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 21598a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 21608a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 21614b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Index = ExtVectorType::getAccessorIdx(Comp[i]); 2162b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 21633b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 2164b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 21658a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 21668a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 216704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2168f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 216904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 217004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 217104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 217204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 2173c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 217404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 217504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 217604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 2177f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, 2178f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent=*/false, /*ValueDependent=*/false), 217904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs(NumArgs), Kind(IsInstanceSuper? SuperInstance : SuperClass), 218004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor HasMethod(Method != 0), SuperLoc(SuperLoc), 218104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 218204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2183c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt LBracLoc(LBracLoc), RBracLoc(RBracLoc) 2184c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{ 218504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(SuperType.getAsOpaquePtr()); 218604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (NumArgs) 218704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); 218804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 218904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 219004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2191f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 219204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 219304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 2194c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 219504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 219604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 219704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 2198f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, T->isDependentType(), 2199c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (T->isDependentType() || 220004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor hasAnyValueDependentArguments(Args, NumArgs))), 220104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs(NumArgs), Kind(Class), HasMethod(Method != 0), 220204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 220304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2204c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt LBracLoc(LBracLoc), RBracLoc(RBracLoc) 220504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 220604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 220704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (NumArgs) 220804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); 220904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 221004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 221104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T, 2212f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 221304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 221404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 2215c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 221604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 221704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 221804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) 2219f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ObjCMessageExprClass, T, VK, OK_Ordinary, Receiver->isTypeDependent(), 2220c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (Receiver->isTypeDependent() || 222104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor hasAnyValueDependentArguments(Args, NumArgs))), 222204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs(NumArgs), Kind(Instance), HasMethod(Method != 0), 222304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method 222404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor : Sel.getAsOpaquePtr())), 2225c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt LBracLoc(LBracLoc), RBracLoc(RBracLoc) 222604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{ 222704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor setReceiverPointer(Receiver); 222804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (NumArgs) 222904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor memcpy(getArgs(), Args, NumArgs * sizeof(Expr *)); 223004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 223104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 223204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2233f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 223404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 223504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation SuperLoc, 223604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor bool IsInstanceSuper, 223704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor QualType SuperType, 2238c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 223904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 224004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 224104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 2242c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 224304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 224404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 2245f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, SuperLoc, IsInstanceSuper, 2246c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SuperType, Sel, Method, Args, NumArgs, 224704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor RBracLoc); 224804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 224904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 225004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2251f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 225204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 225304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor TypeSourceInfo *Receiver, 2254c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 225504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 225604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 225704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 2258c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 225904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 226004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 2261f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, Method, Args, 226204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs, RBracLoc); 226304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 226404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 226504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T, 2266f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 226704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation LBracLoc, 226804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr *Receiver, 2269c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Selector Sel, 227004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ObjCMethodDecl *Method, 227104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor Expr **Args, unsigned NumArgs, 227204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor SourceLocation RBracLoc) { 2273c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 227404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 227504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 2276f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return new (Mem) ObjCMessageExpr(T, VK, LBracLoc, Receiver, Sel, Method, Args, 227704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs, RBracLoc); 227804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 227904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 2280c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context, 228104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor unsigned NumArgs) { 2282c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) + 228304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor NumArgs * sizeof(Expr *); 228404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment); 228504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs); 228604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 2287c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 228804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const { 228904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (HasMethod) 229004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod) 229104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor ->getSelector(); 2292c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Selector(SelectorOrMethod); 229304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor} 229404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor 229504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { 229604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor switch (getReceiverKind()) { 229704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Instance: 229804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 229904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>()) 230004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 230104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 23024df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 230304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case Class: 2304c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *Ty 2305c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall = getClassReceiver()->getAs<ObjCObjectType>()) 2306c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return Ty->getInterface(); 230704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 23084df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 230904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperInstance: 231004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Ptr 231104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getSuperType()->getAs<ObjCObjectPointerType>()) 231204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Ptr->getInterfaceDecl(); 231304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 2314c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor 231504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor case SuperClass: 231604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (const ObjCObjectPointerType *Iface 231704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor = getSuperType()->getAs<ObjCObjectPointerType>()) 231804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return Iface->getInterfaceDecl(); 231904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor break; 232004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor } 23210389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 232204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return 0; 2323eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek} 23240389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 232527437caadea35f84d550cd29f024fcf3ea240eecChris Lattnerbool ChooseExpr::isConditionTrue(ASTContext &C) const { 23269a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getCond()->EvaluateAsInt(C) != 0; 232727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 232827437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 2329888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 2330888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 2331888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 2332888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 2333888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 233494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 233594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 23361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 2337888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 233877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 233905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 234005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 234105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 234205c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() { 234305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 234405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 234505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 234605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 234705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 234805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 234905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2350c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty, 2351319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesignators, 2352ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 23531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation EqualOrColonLoc, 2354ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 23551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **IndexExprs, 23569ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned NumIndexExprs, 23579ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 23581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(DesignatedInitExprClass, Ty, 2359f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Init->getValueKind(), Init->getObjectKind(), 23609ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Init->isTypeDependent(), Init->isValueDependent()), 23611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 23621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { 2363319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor this->Designators = new (C) Designator[NumDesignators]; 23649ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 23659ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 23669ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor child_iterator Child = child_begin(); 23679ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 23689ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 23699ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 23709ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 23719ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 23729ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 2373ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 23749ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 23759ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 23769ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 23779ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 23788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = ExprBits.ValueDependent || 23799ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Index->isTypeDependent() || Index->isValueDependent(); 23809ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 23819ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 23829ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 23839ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 23849ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 23859ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 23869ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 23878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = ExprBits.ValueDependent || 23889ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Start->isTypeDependent() || Start->isValueDependent() || 23899ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor End->isTypeDependent() || End->isValueDependent(); 23909ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 23919ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 23929ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 23939ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 23949ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 23959ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 23969ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 23979ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); 2398ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 2399ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 240005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 24011eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 240205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 240305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 240405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 240505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 2406c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 2407c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff sizeof(Stmt *) * (NumIndexExprs + 1), 8); 2408319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators, 24099ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 24109ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor IndexExprs, NumIndexExprs, Init); 241105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 241205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 24131eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 2414d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 2415d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 2416d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 2417d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 2418d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 2419d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2420319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C, 2421319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor const Designator *Desigs, 2422d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 2423319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor Designators = new (C) Designator[NumDesigs]; 2424d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 2425d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 2426d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 2427d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 2428d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 242905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const { 243005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 2431d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 2432d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 243305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 2434eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 243505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 243605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 243705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 243805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 2439d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 2440d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 244105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); 244205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 244305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 244405c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) { 244505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 244605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 244705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 244805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 244905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 245005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 245105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 245205c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { 24531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 245405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 245505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 245605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 245705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 245805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 245905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 246005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 246105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { 24621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 246305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 246405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 246505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 246605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 246705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 246805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 246905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2470ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 2471ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 2472319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx, 24731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Designator *First, 2474ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 2475ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 2476ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 2477ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 2478ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 2479ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 2480ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 2481ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 2482ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 2483ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 2484ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 2485ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 2486ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 24871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator *NewDesignators 2488319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; 2489ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 2490ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 2491ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 2492ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 2493ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 2494ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 2495ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 2496ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 24971eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 24982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Expr **exprs, unsigned nexprs, 24992ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation rparenloc) 2500f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall: Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, 25012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman hasAnyTypeDependentArguments(exprs, nexprs), 25021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump hasAnyValueDependentArguments(exprs, nexprs)), 25032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { 25041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25052ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs = new (C) Stmt*[nexprs]; 25062ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman for (unsigned i = 0; i != nexprs; ++i) 25072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 25082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 25092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 251005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 2511ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 2512ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 2513ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 2514ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 2515ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 2516ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 2517ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 2518ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 2519ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 2520ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 2521ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 2522ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 2523ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 252477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 252577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 252677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 252777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// DeclRefExpr 25289ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); } 25299ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); } 253077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 25317779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff// ObjCIvarRefExpr 25325549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; } 25335549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; } 25347779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff 2535e3e9add4fd788927df6f545570e7838db59c01d7Steve Naroff// ObjCPropertyRefExpr 25368ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz JahanianStmt::child_iterator ObjCPropertyRefExpr::child_begin() 25378ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian{ 25388ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian if (BaseExprOrSuperType.is<Stmt*>()) { 25398ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian // Hack alert! 25408ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian return reinterpret_cast<Stmt**> (&BaseExprOrSuperType); 25418ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian } 25428ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian return child_iterator(); 25438ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian} 25448ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 25458ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz JahanianStmt::child_iterator ObjCPropertyRefExpr::child_end() 25468ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian{ return BaseExprOrSuperType.is<Stmt*>() ? 25478ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian reinterpret_cast<Stmt**> (&BaseExprOrSuperType)+1 : 25488ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian child_iterator(); 25498ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian} 2550ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff 255109105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian// ObjCImplicitSetterGetterRefExpr 25521eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_begin() { 25538ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian // If this is accessing a class member or super, skip that entry. 25548ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian // Technically, 2nd condition is sufficient. But I want to be verbose 25558ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian if (isSuperReceiver() || !Base) 25568ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian return child_iterator(); 25578ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian return &Base; 2558154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian} 25591eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_end() { 25608ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian if (isSuperReceiver() || !Base) 25618ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian return child_iterator(); 25621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return &Base+1; 2563154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian} 25645daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian 2565f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff// ObjCIsaExpr 2566f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; } 2567f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; } 2568f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 2569d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner// PredefinedExpr 2570d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); } 2571d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); } 257277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 257377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// IntegerLiteral 25749ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); } 25759ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); } 257677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 257777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CharacterLiteral 2578d603eaa682cecac2c10771a700cb83aa301653b4Chris LattnerStmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();} 25799ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); } 258077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 258177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// FloatingLiteral 25829ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); } 25839ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); } 258477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 25855d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner// ImaginaryLiteral 25865549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; } 25875549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; } 25885d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 258977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// StringLiteral 25909ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_begin() { return child_iterator(); } 25919ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_end() { return child_iterator(); } 259277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 259377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ParenExpr 25945549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_begin() { return &Val; } 25955549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_end() { return &Val+1; } 259677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 259777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// UnaryOperator 25985549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_begin() { return &Val; } 25995549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_end() { return &Val+1; } 260077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 26018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor// OffsetOfExpr 26028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorStmt::child_iterator OffsetOfExpr::child_begin() { 26038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Stmt **> (reinterpret_cast<OffsetOfNode *> (this + 1) 26048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor + NumComps); 26058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 26068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorStmt::child_iterator OffsetOfExpr::child_end() { 26078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return child_iterator(&*child_begin() + NumExprs); 26088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 26098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 26100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl// SizeOfAlignOfExpr 26111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator SizeOfAlignOfExpr::child_begin() { 26120518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 26130518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 26140518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 26150518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 26160518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (VariableArrayType* T = dyn_cast<VariableArrayType>( 26170518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 26180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(T); 26190518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(); 26200518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 2621d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return child_iterator(&Argument.Ex); 26229ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 26230518999d3adcc289997bd974dce90cc97f5c1c44Sebastian RedlStmt::child_iterator SizeOfAlignOfExpr::child_end() { 26240518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) 26250518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(); 2626d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return child_iterator(&Argument.Ex + 1); 26279ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 262877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 262977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ArraySubscriptExpr 26301237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_begin() { 26315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 263277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 26331237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_end() { 26345549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 263577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 263677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 263777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CallExpr 26381237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_begin() { 26395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 264077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 26411237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_end() { 26425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+NumArgs+ARGS_START; 264377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 26441237c673c07f9d827129ba02720108816abde562Ted Kremenek 26451237c673c07f9d827129ba02720108816abde562Ted Kremenek// MemberExpr 26465549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_begin() { return &Base; } 26475549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_end() { return &Base+1; } 26481237c673c07f9d827129ba02720108816abde562Ted Kremenek 2649213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman// ExtVectorElementExpr 26505549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; } 26515549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; } 26521237c673c07f9d827129ba02720108816abde562Ted Kremenek 26531237c673c07f9d827129ba02720108816abde562Ted Kremenek// CompoundLiteralExpr 26545549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; } 26555549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; } 26561237c673c07f9d827129ba02720108816abde562Ted Kremenek 26571237c673c07f9d827129ba02720108816abde562Ted Kremenek// CastExpr 26585549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_begin() { return &Op; } 26595549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_end() { return &Op+1; } 26601237c673c07f9d827129ba02720108816abde562Ted Kremenek 26611237c673c07f9d827129ba02720108816abde562Ted Kremenek// BinaryOperator 26621237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_begin() { 26635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 26641237c673c07f9d827129ba02720108816abde562Ted Kremenek} 26651237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_end() { 26665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 26671237c673c07f9d827129ba02720108816abde562Ted Kremenek} 26681237c673c07f9d827129ba02720108816abde562Ted Kremenek 26691237c673c07f9d827129ba02720108816abde562Ted Kremenek// ConditionalOperator 26701237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_begin() { 26715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 26721237c673c07f9d827129ba02720108816abde562Ted Kremenek} 26731237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_end() { 26745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 26751237c673c07f9d827129ba02720108816abde562Ted Kremenek} 26761237c673c07f9d827129ba02720108816abde562Ted Kremenek 26771237c673c07f9d827129ba02720108816abde562Ted Kremenek// AddrLabelExpr 26789ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); } 26799ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); } 26801237c673c07f9d827129ba02720108816abde562Ted Kremenek 26811237c673c07f9d827129ba02720108816abde562Ted Kremenek// StmtExpr 26825549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_begin() { return &SubStmt; } 26835549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; } 26841237c673c07f9d827129ba02720108816abde562Ted Kremenek 26851237c673c07f9d827129ba02720108816abde562Ted Kremenek// TypesCompatibleExpr 26869ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_begin() { 26879ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 26889ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 26899ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek 26909ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_end() { 26919ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 26929ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 26931237c673c07f9d827129ba02720108816abde562Ted Kremenek 26941237c673c07f9d827129ba02720108816abde562Ted Kremenek// ChooseExpr 26955549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; } 26965549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; } 26972d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 26982d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor// GNUNullExpr 26992d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); } 27002d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); } 27011237c673c07f9d827129ba02720108816abde562Ted Kremenek 2702d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman// ShuffleVectorExpr 2703d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_begin() { 27045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 2705d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman} 2706d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_end() { 27075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+NumExprs; 2708d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman} 2709d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 27107c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson// VAArgExpr 27115549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_begin() { return &Val; } 27125549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_end() { return &Val+1; } 27137c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 271466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson// InitListExpr 2715ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed KremenekStmt::child_iterator InitListExpr::child_begin() { 2716ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return InitExprs.size() ? &InitExprs[0] : 0; 2717ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek} 2718ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed KremenekStmt::child_iterator InitListExpr::child_end() { 2719ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0; 2720ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek} 272166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 27223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// DesignatedInitExpr 272305c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_begin() { 272405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 272505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 272605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 272705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 272805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_end() { 272905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return child_iterator(&*child_begin() + NumSubExprs); 273005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 273105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 27323498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// ImplicitValueInitExpr 27331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_begin() { 27341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return child_iterator(); 27353498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor} 27363498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 27371eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_end() { 27381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return child_iterator(); 27393498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor} 27403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 27412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman// ParenListExpr 27422ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_begin() { 27432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return &Exprs[0]; 27442ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 27452ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_end() { 27462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return &Exprs[0]+NumExprs; 27472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 27482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 27491237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCStringLiteral 27501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCStringLiteral::child_begin() { 2751c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner return &String; 27529ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 27539ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_end() { 2754c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner return &String+1; 27559ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 27561237c673c07f9d827129ba02720108816abde562Ted Kremenek 27571237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCEncodeExpr 27589ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); } 27599ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); } 27601237c673c07f9d827129ba02720108816abde562Ted Kremenek 2761b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian// ObjCSelectorExpr 27621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCSelectorExpr::child_begin() { 27639ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 27649ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 27659ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_end() { 27669ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 27679ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 2768b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 2769390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian// ObjCProtocolExpr 27709ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_begin() { 27719ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 27729ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 27739ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_end() { 27749ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 27759ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 2776390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 2777563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 27781eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCMessageExpr::child_begin() { 277904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor if (getReceiverKind() == Instance) 278004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return reinterpret_cast<Stmt **>(this + 1); 278104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getArgs(); 2782563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2783563477da25f824e37c535131695dc4dc9b68c465Steve NaroffStmt::child_iterator ObjCMessageExpr::child_end() { 278404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor return getArgs() + getNumArgs(); 2785563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2786563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 27874eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks 278856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_begin() { return child_iterator(); } 278956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_end() { return child_iterator(); } 27904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 27919da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();} 27929da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); } 27937cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 27947cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall// OpaqueValueExpr 27957cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallSourceRange OpaqueValueExpr::getSourceRange() const { return SourceRange(); } 27967cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallStmt::child_iterator OpaqueValueExpr::child_begin() { return child_iterator(); } 27977cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallStmt::child_iterator OpaqueValueExpr::child_end() { return child_iterator(); } 27987cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 2799