Expr.cpp revision cb1c77f90d4e747b83a0d0cc125dc01567378f82
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.cpp - Expression AST Node Implementation --------------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements the Expr class and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar#include "clang/AST/Expr.h" 150979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor#include "clang/AST/ExprCXX.h" 16a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/APValue.h" 172eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner#include "clang/AST/ASTContext.h" 18a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/DeclObjC.h" 1998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor#include "clang/AST/DeclCXX.h" 20aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 2119cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h" 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/StmtVisitor.h" 231b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 24da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h" 25cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor#include "llvm/Support/ErrorHandling.h" 263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson#include "llvm/Support/raw_ostream.h" 27ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm> 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::initializeFrom( 35d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Info) { 36d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall LAngleLoc = Info.getLAngleLoc(); 37d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall RAngleLoc = Info.getRAngleLoc(); 38d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NumTemplateArgs = Info.size(); 39d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 40d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); 41d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall for (unsigned i = 0; i != NumTemplateArgs; ++i) 42d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); 43d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 44d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 45d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::copyInto( 46d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo &Info) const { 47d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.setLAngleLoc(LAngleLoc); 48d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.setRAngleLoc(RAngleLoc); 49d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall for (unsigned I = 0; I != NumTemplateArgs; ++I) 50d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Info.addArgument(getTemplateArgs()[I]); 51d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 52d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 53d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallstd::size_t ExplicitTemplateArgumentList::sizeFor( 54d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Info) { 55d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return sizeof(ExplicitTemplateArgumentList) + 56d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall sizeof(TemplateArgumentLoc) * Info.size(); 57d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 58d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 590da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregorvoid DeclRefExpr::computeDependence() { 600da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TypeDependent = false; 610da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = false; 620da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 630da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor NamedDecl *D = getDecl(); 640da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 650da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) C++ [temp.dep.expr]p3: 660da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An id-expression is type-dependent if it contains: 670da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 680da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // and 690da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // 700da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) C++ [temp.dep.constexpr]p2: 710da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // An identifier is value-dependent if it is: 720da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 730da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - an identifier that was declared with dependent type 740da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a name declared with a dependent type, 750da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor if (getType()->isDependentType()) { 760da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TypeDependent = true; 770da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = true; 780da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 790da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a conversion-function-id that specifies a dependent type 800da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor else if (D->getDeclName().getNameKind() 810da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor == DeclarationName::CXXConversionFunctionName && 820da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor D->getDeclName().getCXXNameType()->isDependentType()) { 830da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TypeDependent = true; 840da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = true; 850da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 860da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a template-id that is dependent, 870da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor else if (hasExplicitTemplateArgumentList() && 880da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TemplateSpecializationType::anyDependentTemplateArguments( 890da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor getTemplateArgs(), 900da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor getNumTemplateArgs())) { 910da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TypeDependent = true; 920da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = true; 930da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 940da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - the name of a non-type template parameter, 950da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor else if (isa<NonTypeTemplateParmDecl>(D)) 960da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = true; 970da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (VD) - a constant with integral or enumeration type and is 980da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // initialized with an expression that is value-dependent. 990da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor else if (VarDecl *Var = dyn_cast<VarDecl>(D)) { 1000da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor if (Var->getType()->isIntegralType() && 1010da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor Var->getType().getCVRQualifiers() == Qualifiers::Const && 1020da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor Var->getInit() && 1030da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor Var->getInit()->isValueDependent()) 1040da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor ValueDependent = true; 1050da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 1060da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (TD) - a nested-name-specifier or a qualified-id that names a 1070da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // member of an unknown specialization. 1080da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor // (handled by DependentScopeDeclRefExpr) 1090da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor} 1100da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor 111a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, 112a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 113dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, SourceLocation NameLoc, 114d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs, 1150da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T) 1160da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor : Expr(DeclRefExprClass, T, false, false), 117a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor DecoratedD(D, 118a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor (Qualifier? HasQualifierFlag : 0) | 119d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)), 120a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Loc(NameLoc) { 121a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (Qualifier) { 122a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NameQualifier *NQ = getNameQualifier(); 123a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NQ->NNS = Qualifier; 124a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NQ->Range = QualifierRange; 125a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 126a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 127d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 128d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs); 129a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 1300da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 131a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 132a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 133a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context, 134a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier, 135a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange QualifierRange, 136dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 137a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 1380da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor QualType T, 1390da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs) { 140a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor std::size_t Size = sizeof(DeclRefExpr); 141a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (Qualifier != 0) 142a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Size += sizeof(NameQualifier); 143a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 144d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (TemplateArgs) 145d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs); 146a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 147a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>()); 148a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameLoc, 1490da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor TemplateArgs, T); 150a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 151a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 152a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorSourceRange DeclRefExpr::getSourceRange() const { 153a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor // FIXME: Does not handle multi-token names well, e.g., operator[]. 154a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceRange R(Loc); 155a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 156a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (hasQualifier()) 157a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setBegin(getQualifierRange().getBegin()); 158a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (hasExplicitTemplateArgumentList()) 159a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor R.setEnd(getRAngleLoc()); 160a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return R; 161a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor} 162a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 1633a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined 1643a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead. 1653a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlssonstd::string PredefinedExpr::ComputeName(ASTContext &Context, IdentType IT, 1663a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const Decl *CurrentDecl) { 1673a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { 1683a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (IT != PrettyFunction) 1693a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return FD->getNameAsString(); 1703a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 1713a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 1723a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 1733a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 1743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 1753a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (MD->isVirtual()) 1763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << "virtual "; 1773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 1783a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 1793a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson PrintingPolicy Policy(Context.getLangOptions()); 1803a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Policy.SuppressTagKind = true; 1813a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 1823a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Proto = FD->getQualifiedNameAsString(Policy); 1833a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 184183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *AFT = FD->getType()->getAs<FunctionType>(); 1853a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson const FunctionProtoType *FT = 0; 1863a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->hasWrittenPrototype()) 1873a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FT = dyn_cast<FunctionProtoType>(AFT); 1883a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 1893a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += "("; 1903a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT) { 1913a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_string_ostream POut(Proto); 1923a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { 1933a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (i) POut << ", "; 1943a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson std::string Param; 1953a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy); 1963a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << Param; 1973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 1983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 1993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FT->isVariadic()) { 2003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (FD->getNumParams()) POut << ", "; 2013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson POut << "..."; 2023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2033a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Proto += ")"; 2053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2063a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)) 2073a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig AFT->getResultType().getAsStringInternal(Proto, Policy); 2083a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2093a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << Proto; 2103a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2113a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 2123a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 2133a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2143a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { 2153a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::SmallString<256> Name; 2163a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson llvm::raw_svector_ostream Out(Name); 2173a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << (MD->isInstanceMethod() ? '-' : '+'); 2183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '['; 2193a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getClassInterface()->getNameAsString(); 2203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (const ObjCCategoryImplDecl *CID = 2213a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) { 2223a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << '('; 2233a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << CID->getNameAsString(); 2243a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ')'; 2253a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ' '; 2273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << MD->getSelector().getAsString(); 2283a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out << ']'; 2293a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 2303a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson Out.flush(); 2313a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return Name.str().str(); 2323a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2333a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) { 2343a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. 2353a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return "top level"; 2363a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson } 2373a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson return ""; 2383a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson} 2393a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 240da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 241da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 242da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 243da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 244da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 245ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 246ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 247ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 248da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 249da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 250da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 2512085fd6cd22ec5c268175251db10d7c60caf7aaaChris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData, 2522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, 2532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner QualType Ty, 2541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const SourceLocation *Loc, 255a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 2562085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 2572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 2582085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 2592085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 2602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner llvm::alignof<StringLiteral>()); 2612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 2621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 2642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner char *AStrData = new (C, 1) char[ByteLength]; 2652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(AStrData, StrData, ByteLength); 2662085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->StrData = AStrData; 2672085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->ByteLength = ByteLength; 2682085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->IsWide = Wide; 2692085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 2702085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 272726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 2732085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 2742085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 275726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 276726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 277673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 278673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 279673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 280673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor llvm::alignof<StringLiteral>()); 281673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 282673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->StrData = 0; 283673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->ByteLength = 0; 284673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 285673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 286673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 287673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 28842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid StringLiteral::DoDestroy(ASTContext &C) { 2898189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek C.Deallocate(const_cast<char*>(StrData)); 29042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor Expr::DoDestroy(C); 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 293b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbarvoid StringLiteral::setString(ASTContext &C, llvm::StringRef Str) { 294673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor if (StrData) 295673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor C.Deallocate(const_cast<char*>(StrData)); 296673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 297b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar char *AStrData = new (C, 1) char[Str.size()]; 298b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar memcpy(AStrData, Str.data(), Str.size()); 299673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StrData = AStrData; 300b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar ByteLength = Str.size(); 301673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 302673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) { 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: assert(0 && "Unknown unary operator"); 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PostInc: return "++"; 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PostDec: return "--"; 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PreInc: return "++"; 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PreDec: return "--"; 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case AddrOf: return "&"; 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Deref: return "*"; 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Plus: return "+"; 3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Minus: return "-"; 3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Not: return "~"; 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LNot: return "!"; 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Real: return "__real"; 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Imag: return "__imag"; 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Extension: return "__extension__"; 32173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner case OffsetOf: return "__builtin_offsetof"; 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3251eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpUnaryOperator::Opcode 326bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 327bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 328bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: assert(false && "No unary operator for overloaded function"); 329b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_PlusPlus: return Postfix ? PostInc : PreInc; 330b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_MinusMinus: return Postfix ? PostDec : PreDec; 331b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Amp: return AddrOf; 332b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Star: return Deref; 333b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Plus: return Plus; 334b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Minus: return Minus; 335b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Tilde: return Not; 336b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Exclaim: return LNot; 337bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 338bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 339bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 340bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 341bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 342bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case PostInc: case PreInc: return OO_PlusPlus; 343bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case PostDec: case PreDec: return OO_MinusMinus; 344bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case AddrOf: return OO_Amp; 345bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Deref: return OO_Star; 346bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Plus: return OO_Plus; 347bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Minus: return OO_Minus; 348bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Not: return OO_Tilde; 349bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case LNot: return OO_Exclaim; 350bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 351bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 352bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 353bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 354bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 359668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, 3608189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek unsigned numargs, QualType t, SourceLocation rparenloc) 3611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, t, 362898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), 363d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), 364898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 366668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek SubExprs = new (C) Stmt*[numargs+1]; 367b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 368b4609806e9232593ece09ce08b630836e825865cDouglas Gregor for (unsigned i = 0; i != numargs; ++i) 369b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[i+ARGS_START] = args[i]; 370668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 371b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 372b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 373e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 374668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 375668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc) 376898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(CallExprClass, t, 377898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), 378d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), 379898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 380668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 381668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek SubExprs = new (C) Stmt*[numargs+1]; 38277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numargs; ++i) 38477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[i+ARGS_START] = args[i]; 385668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3891eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 3911f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor SubExprs = new (C) Stmt*[1]; 3921f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 3931f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 39442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid CallExpr::DoDestroy(ASTContext& C) { 395668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek DestroyChildren(C); 396668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek if (SubExprs) C.Deallocate(SubExprs); 397668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek this->~CallExpr(); 398668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek C.Deallocate(this); 399668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek} 400668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 401d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() { 402a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu Expr *CEE = getCallee()->IgnoreParenCasts(); 4036346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 404d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return DRE->getDecl(); 405cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE)) 406cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes return ME->getMemberDecl(); 407a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 408a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 409a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 410a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 411d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() { 412caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); 413d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes} 414d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 415d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 416d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 417d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 4188189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 419d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 420d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 4211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 422d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 423d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 424d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i) 4258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek getArg(i)->Destroy(C); 426d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 427d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 428d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 429d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 430d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 43168a049cab6015a7437bec5661601b7d37d23c70cDaniel Dunbar Stmt **NewSubExprs = new (C) Stmt*[NumArgs+1]; 432d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 433d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i) 434d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 435d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 436d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i) 437d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43988c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 440d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 441d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 442d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 443d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 444cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 445cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 4463c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregorunsigned CallExpr::isBuiltinCall(ASTContext &Context) const { 447c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // function. As a result, we try and obtain the DeclRefExpr from the 449c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 450c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 451c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 452cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 454c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 455c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 456cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 458bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 459bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 460cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 4611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4624fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 4634fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 4644fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 4657814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor return FDecl->getBuiltinID(); 466cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 467bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 4686dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 4696dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 4706217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 4716dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 4726217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 4736dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 4741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 475183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *FnType = CalleeType->getAs<FunctionType>(); 4766dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 4776dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 478cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 4791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr::MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual, 480f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman SourceRange qualrange, ValueDecl *memberdecl, 481d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall SourceLocation l, const TemplateArgumentListInfo *targs, 482d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall QualType ty) 4831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(MemberExprClass, ty, 48483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor base->isTypeDependent() || (qual && qual->isDependent()), 48583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor base->isValueDependent() || (qual && qual->isDependent())), 48683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow), 487d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall HasQualifier(qual != 0), HasExplicitTemplateArgumentList(targs) { 48883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor // Initialize the qualifier, if any. 48983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (HasQualifier) { 49083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NameQualifier *NQ = getMemberQualifier(); 49183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NQ->NNS = qual; 49283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NQ->Range = qualrange; 49383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 4941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 495c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor // Initialize the explicit template argument list, if any. 496d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 497d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall getExplicitTemplateArgumentList()->initializeFrom(*targs); 49883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 49983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 5001eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 5011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *qual, 50283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor SourceRange qualrange, 503f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *memberdecl, 5041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation l, 505d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 506c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor QualType ty) { 50783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 50883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (qual != 0) 50983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor Size += sizeof(NameQualifier); 5101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 511d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall if (targs) 512d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall Size += ExplicitTemplateArgumentList::sizeFor(*targs); 5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor void *Mem = C.Allocate(Size, llvm::alignof<MemberExpr>()); 515c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return new (Mem) MemberExpr(base, isarrow, qual, qualrange, memberdecl, l, 516d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall targs, ty); 51783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 51883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 519f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 520f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 521f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_Unknown: 522f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Unknown"; 523f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_BitCast: 524f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 525f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_NoOp: 526f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 52711de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson case CastExpr::CK_BaseToDerived: 52811de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson return "BaseToDerived"; 529f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_DerivedToBase: 530f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 531f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_Dynamic: 532f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 533f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_ToUnion: 534f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 535f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_ArrayToPointerDecay: 536f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 537f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_FunctionToPointerDecay: 538f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 539f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_NullToMemberPointer: 540f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 541f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_BaseToDerivedMemberPointer: 542f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 5431a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson case CastExpr::CK_DerivedToBaseMemberPointer: 5441a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson return "DerivedToBaseMemberPointer"; 545f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_UserDefinedConversion: 546f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 547f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_ConstructorConversion: 548f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 5497f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson case CastExpr::CK_IntegralToPointer: 5507f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "IntegralToPointer"; 5517f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson case CastExpr::CK_PointerToIntegral: 5527f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson return "PointerToIntegral"; 553ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson case CastExpr::CK_ToVoid: 554ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson return "ToVoid"; 55516a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson case CastExpr::CK_VectorSplat: 55616a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson return "VectorSplat"; 55782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson case CastExpr::CK_IntegralCast: 55882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralCast"; 55982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson case CastExpr::CK_IntegralToFloating: 56082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "IntegralToFloating"; 56182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson case CastExpr::CK_FloatingToIntegral: 56282debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson return "FloatingToIntegral"; 563c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer case CastExpr::CK_FloatingCast: 564c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer return "FloatingCast"; 565bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson case CastExpr::CK_MemberPointerToBoolean: 566bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson return "MemberPointerToBoolean"; 5674cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian case CastExpr::CK_AnyPointerToObjCPointerCast: 5684cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian return "AnyPointerToObjCPointerCast"; 5693b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian case CastExpr::CK_AnyPointerToBlockPointerCast: 5703b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian return "AnyPointerToBlockPointerCast"; 571f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 5721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 573f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson assert(0 && "Unhandled cast kind!"); 574f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return 0; 575f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 576f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 5776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() { 5786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *SubExpr = 0; 5796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor CastExpr *E = this; 5806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor do { 5816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = E->getSubExpr(); 5826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 5836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Skip any temporary bindings; they're implicit. 5846eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr)) 5856eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = Binder->getSubExpr(); 5866eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 5876eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // Conversions by constructor and conversion functions have a 5886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // subexpression describing the call; strip it off. 5896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor if (E->getCastKind() == CastExpr::CK_ConstructorConversion) 5906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0); 5916eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor else if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) 5926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); 5936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 5946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // If the subexpression we're left with is an implicit cast, look 5956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor // through that, too. 5966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); 5976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 5986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return SubExpr; 5996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 6006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) { 6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 605baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor case PtrMemD: return ".*"; 606baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor case PtrMemI: return "->*"; 6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Mul: return "*"; 6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Div: return "/"; 6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Rem: return "%"; 6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Add: return "+"; 6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Sub: return "-"; 6125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Shl: return "<<"; 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Shr: return ">>"; 6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LT: return "<"; 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case GT: return ">"; 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LE: return "<="; 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case GE: return ">="; 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case EQ: return "=="; 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case NE: return "!="; 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case And: return "&"; 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Xor: return "^"; 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Or: return "|"; 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LAnd: return "&&"; 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LOr: return "||"; 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Assign: return "="; 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MulAssign: return "*="; 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DivAssign: return "/="; 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case RemAssign: return "%="; 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case AddAssign: return "+="; 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SubAssign: return "-="; 6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ShlAssign: return "<<="; 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ShrAssign: return ">>="; 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case AndAssign: return "&="; 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case XorAssign: return "^="; 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case OrAssign: return "|="; 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Comma: return ","; 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 638baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 639baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor return ""; 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6421eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpBinaryOperator::Opcode 643063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 644063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 645b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner default: assert(false && "Not an overloadable binary operator"); 646063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Plus: return Add; 647063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Minus: return Sub; 648063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Star: return Mul; 649063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Slash: return Div; 650063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Percent: return Rem; 651063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Caret: return Xor; 652063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Amp: return And; 653063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Pipe: return Or; 654063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Equal: return Assign; 655063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Less: return LT; 656063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Greater: return GT; 657063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PlusEqual: return AddAssign; 658063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_MinusEqual: return SubAssign; 659063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_StarEqual: return MulAssign; 660063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_SlashEqual: return DivAssign; 661063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PercentEqual: return RemAssign; 662063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_CaretEqual: return XorAssign; 663063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_AmpEqual: return AndAssign; 664063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PipeEqual: return OrAssign; 665063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_LessLess: return Shl; 666063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_GreaterGreater: return Shr; 667063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_LessLessEqual: return ShlAssign; 668063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_GreaterGreaterEqual: return ShrAssign; 669063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_EqualEqual: return EQ; 670063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_ExclaimEqual: return NE; 671063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_LessEqual: return LE; 672063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_GreaterEqual: return GE; 673063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_AmpAmp: return LAnd; 674063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PipePipe: return LOr; 675063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Comma: return Comma; 676063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_ArrowStar: return PtrMemI; 677063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 678063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 679063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 680063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 681063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 682063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 683063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 684063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 685063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 686063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 687063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 688063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 689063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 690063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 691063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 692063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 693063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 694063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 695063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 696063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 697063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 698063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 699063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 700063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 701063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 702063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 703063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 7041eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpInitListExpr::InitListExpr(SourceLocation lbraceloc, 705418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner Expr **initExprs, unsigned numInits, 7064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc) 70773460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor : Expr(InitListExprClass, QualType(), false, false), 7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0), 70973460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor UnionFieldInit(0), HadArrayRangeDesignator(false) 71073460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor{ 71173460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor for (unsigned I = 0; I != numInits; ++I) { 71273460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor if (initExprs[I]->isTypeDependent()) 71373460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor TypeDependent = true; 71473460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor if (initExprs[I]->isValueDependent()) 71573460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor ValueDependent = true; 71673460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor } 71773460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor 718418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner InitExprs.insert(InitExprs.end(), initExprs, initExprs+numInits); 71966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 721fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregorvoid InitListExpr::reserveInits(unsigned NumInits) { 722fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor if (NumInits > InitExprs.size()) 723fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor InitExprs.reserve(NumInits); 724fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 725fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 7264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorvoid InitListExpr::resizeInits(ASTContext &Context, unsigned NumInits) { 727d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner for (unsigned Idx = NumInits, LastIdx = InitExprs.size(); 728f592c929bd1f083abcc8199b24bb825fdd28df1cDaniel Dunbar Idx < LastIdx; ++Idx) 729068636800594844c53fba0bc871c579745757d0eDouglas Gregor InitExprs[Idx]->Destroy(Context); 7304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs.resize(NumInits, 0); 7314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 7324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 7334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas GregorExpr *InitListExpr::updateInit(unsigned Init, Expr *expr) { 7344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Init >= InitExprs.size()) { 7354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs.insert(InitExprs.end(), Init - InitExprs.size() + 1, 0); 7364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs.back() = expr; 7374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return 0; 7384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 7391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 7414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 7424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 7434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 7444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 745bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 7464eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 7474eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const { 7486217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<BlockPointerType>()-> 749183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall getPointeeType()->getAs<FunctionType>(); 7504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 7514eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 7521eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const { 7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getCaretLocation(); 75456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 7551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const { 7567297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 7577297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 7581eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() { 7591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return TheBlock->getBody(); 7607297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 76156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 76256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 767026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 768026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 769026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 770026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 771026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattnerbool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 772df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const { 773ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 774ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 775ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 776ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 7771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 780026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 781026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 782026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 784026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 785df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump isUnusedResultAWarning(Loc, R1, R2, Ctx); 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 7881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 790026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner default: break; 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::PostInc: 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::PostDec: 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::PreInc: 794026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner case UnaryOperator::PreDec: // ++/-- 795026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Deref: 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Dereferencing a volatile pointer is a side-effect. 798df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 799026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 800026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Real: 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Imag: 8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 804df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) 805df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump .isVolatileQualified()) 806026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 807026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Extension: 809df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 811026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 812026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 813026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 815e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 816026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 817026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // Consider comma to have side effects if the LHS or RHS does. 818026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->getOpcode() == BinaryOperator::Comma) 819df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) || 820df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 822026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 823026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 824026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 825026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 826026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 827026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 828e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 829eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 830026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 832ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 833026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // The condition must be evaluated, but if either the LHS or RHS is a 834026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // warning, warn about them. 835ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 8361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (Exp->getLHS() && 837df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx)) 838026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 839df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx); 840ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 841ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 843026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the base pointer or element is to a volatile pointer/field, accessing 844026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 845df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 846026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 847026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 848026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 849026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 850026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the base pointer or element is to a volatile pointer/field, accessing 854026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 855df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump if (Ctx.getCanonicalType(getType()).isVolatileQualified()) 856026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 857026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 858026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 859026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 860026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 861211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 863852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXOperatorCallExprClass: 864852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXMemberCallExprClass: { 865026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 866026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 867d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes if (const Decl *FD = CE->getCalleeDecl()) { 868026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 869026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 870bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // 871bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // Note: If new cases are added here, DiagnoseUnusedExprResult should be 872bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner // updated to match for QoI. 873bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (FD->getAttr<WarnUnusedResultAttr>() || 874bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 875bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner Loc = CE->getCallee()->getLocStart(); 876bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R1 = CE->getCallee()->getSourceRange(); 877bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner 878bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 879bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 880bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 881bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return true; 882bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 883026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 884026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 885026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 88658beed91d468863b8c85bce43425422703838d27Anders Carlsson 88758beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXTemporaryObjectExprClass: 88858beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXConstructExprClass: 88958beed91d468863b8c85bce43425422703838d27Anders Carlsson return false; 89058beed91d468863b8c85bce43425422703838d27Anders Carlsson 891a9c01021724b9b546d282b8609cbe559734812ecChris Lattner case ObjCMessageExprClass: 892026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 8931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89409105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian case ObjCImplicitSetterGetterRefExprClass: { // Dot syntax for message send. 895a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#if 0 8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCImplicitSetterGetterRefExpr *Ref = 89709105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian cast<ObjCImplicitSetterGetterRefExpr>(this); 898a50089ec68a583d13718107c1b0c898f0903709eChris Lattner // FIXME: We really want the location of the '.' here. 899154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian Loc = Ref->getLocation(); 900154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian R1 = SourceRange(Ref->getLocation(), Ref->getLocation()); 901154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian if (Ref->getBase()) 902154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian R2 = Ref->getBase()->getSourceRange(); 9035e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner#else 9045e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 9055e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 906a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#endif 907a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 908a50089ec68a583d13718107c1b0c898f0903709eChris Lattner } 909611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 910611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 911611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 912611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 913611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 914611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 915611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 916611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (!CS->body_empty()) 917611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 918df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); 9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 920026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 921026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 922026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 923611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 9246eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor case CStyleCastExprClass: 925fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // If this is an explicit cast to void, allow it. People do this when they 926fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // think they know what they're doing :). 927026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (getType()->isVoidType()) 928fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner return false; 929026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); 930026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); 931026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 93258beed91d468863b8c85bce43425422703838d27Anders Carlsson case CXXFunctionalCastExprClass: { 93358beed91d468863b8c85bce43425422703838d27Anders Carlsson const CastExpr *CE = cast<CastExpr>(this); 93458beed91d468863b8c85bce43425422703838d27Anders Carlsson 93558beed91d468863b8c85bce43425422703838d27Anders Carlsson // If this is a cast to void or a constructor conversion, check the operand. 93658beed91d468863b8c85bce43425422703838d27Anders Carlsson // Otherwise, the result of the cast is unused. 93758beed91d468863b8c85bce43425422703838d27Anders Carlsson if (CE->getCastKind() == CastExpr::CK_ToVoid || 93858beed91d468863b8c85bce43425422703838d27Anders Carlsson CE->getCastKind() == CastExpr::CK_ConstructorConversion) 939df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CastExpr>(this)->getSubExpr() 940df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 941026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); 942026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); 943026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 94458beed91d468863b8c85bce43425422703838d27Anders Carlsson } 9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9464be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman case ImplicitCastExprClass: 9474be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman // Check the operand, since implicit casts are inserted by Sema 948df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<ImplicitCastExpr>(this) 949df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 9504be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 95104421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 952df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXDefaultArgExpr>(this) 953df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 9544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 9554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 9564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 9574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 9584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 959026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 9602d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 961df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXBindTemporaryExpr>(this) 962df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 9636b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson case CXXExprWithTemporariesClass: 964df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump return (cast<CXXExprWithTemporaries>(this) 965df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx)); 9664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 969ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor/// DeclCanBeLvalue - Determine whether the given declaration can be 970ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor/// an lvalue. This is a helper routine for isLvalue. 971ba7e210a999275695f58be03ef402758cfec3635Douglas Gregorstatic bool DeclCanBeLvalue(const NamedDecl *Decl, ASTContext &Ctx) { 97272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor // C++ [temp.param]p6: 97372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor // A non-type non-reference template-parameter is not an lvalue. 9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const NonTypeTemplateParmDecl *NTTParm 97572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor = dyn_cast<NonTypeTemplateParmDecl>(Decl)) 97672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return NTTParm->getType()->isReferenceType(); 97772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 97844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return isa<VarDecl>(Decl) || isa<FieldDecl>(Decl) || 979ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor // C++ 3.10p2: An lvalue refers to an object or function. 980ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor (Ctx.getLangOptions().CPlusPlus && 98151fa86f738a9768fac4e1cad7bdde53774b5b322John McCall (isa<FunctionDecl>(Decl) || isa<FunctionTemplateDecl>(Decl))); 982ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor} 983ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor 9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an 9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// incomplete type other than void. Nonarray expressions that can be lvalues: 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - name, where name must be a variable 9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - e[i] 9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - (e), where e must be an lvalue 9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - e.name, where e must be an lvalue 9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - e->name 9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - *e, the type of e cannot be a function type 9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - string-constant 9937da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner/// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension] 99408ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling/// - reference type [C++ [expr]] 9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 99628be73f74c9e241a23ea24fe5756623de6bf1084Chris LattnerExpr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const { 99753202857c60214d80950a975e6e52aebf30bd16aEli Friedman assert(!TR->isReferenceType() && "Expressions can't have reference type."); 99853202857c60214d80950a975e6e52aebf30bd16aEli Friedman 99953202857c60214d80950a975e6e52aebf30bd16aEli Friedman isLvalueResult Res = isLvalueInternal(Ctx); 100053202857c60214d80950a975e6e52aebf30bd16aEli Friedman if (Res != LV_Valid || Ctx.getLangOptions().CPlusPlus) 100153202857c60214d80950a975e6e52aebf30bd16aEli Friedman return Res; 100253202857c60214d80950a975e6e52aebf30bd16aEli Friedman 100398cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor // first, check the type (C99 6.3.2.1). Expressions with function 100498cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor // type in C are not lvalues, but they can be lvalues in C++. 100583314aa1cf61ed2458a8a20c83b2d4708192d5dcDouglas Gregor if (TR->isFunctionType() || TR == Ctx.OverloadTy) 10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return LV_NotObjectType; 10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1008acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff // Allow qualified void which is an incomplete type other than void (yuck). 10090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (TR->isVoidType() && !Ctx.getCanonicalType(TR).hasQualifiers()) 1010acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff return LV_IncompleteVoidType; 1011acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff 101253202857c60214d80950a975e6e52aebf30bd16aEli Friedman return LV_Valid; 101353202857c60214d80950a975e6e52aebf30bd16aEli Friedman} 101408ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling 101553202857c60214d80950a975e6e52aebf30bd16aEli Friedman// Check whether the expression can be sanely treated like an l-value 101653202857c60214d80950a975e6e52aebf30bd16aEli FriedmanExpr::isLvalueResult Expr::isLvalueInternal(ASTContext &Ctx) const { 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 1018820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian case ObjCIsaExprClass: 1019eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case StringLiteralClass: // C99 6.5.1p4 1020eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: // @encode behaves like its string in every way. 10217323a6297edad643c202594dcf3d9a174de96ca6Anders Carlsson return LV_Valid; 10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2)))) 10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // For vectors, make sure base is an lvalue (i.e. not a function call). 10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType()) 102528be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(Ctx); 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return LV_Valid; 1027a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { // C99 6.5.1p2 1028ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor const NamedDecl *RefdDecl = cast<DeclRefExpr>(this)->getDecl(); 1029ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor if (DeclCanBeLvalue(RefdDecl, Ctx)) 10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return LV_Valid; 10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 10324111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner } 1033dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff case BlockDeclRefExprClass: { 1034dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this); 10354f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff if (isa<VarDecl>(BDR->getDecl())) 1036dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff return LV_Valid; 1037dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff break; 1038dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff } 103983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const MemberExpr *m = cast<MemberExpr>(this); 104186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (Ctx.getLangOptions().CPlusPlus) { // C++ [expr.ref]p4: 104286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *Member = m->getMemberDecl(); 104386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // C++ [expr.ref]p4: 104486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // If E2 is declared to have type "reference to T", then E1.E2 104586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // is an lvalue. 104686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (ValueDecl *Value = dyn_cast<ValueDecl>(Member)) 104786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (Value->getType()->isReferenceType()) 104886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return LV_Valid; 104986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 105086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- If E2 is a static data member [...] then E1.E2 is an lvalue. 10512d2e9cfdc1dbb6e4a22f8c0b1abcd30437e3795dDouglas Gregor if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord()) 105286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return LV_Valid; 105386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 105486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- If E2 is a non-static data member [...]. If E1 is an 105586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // lvalue, then E1.E2 is an lvalue. 10562514a309204341798f96912ce7a90841bea59727Fariborz Jahanian if (isa<FieldDecl>(Member)) { 10572514a309204341798f96912ce7a90841bea59727Fariborz Jahanian if (m->isArrow()) 10582514a309204341798f96912ce7a90841bea59727Fariborz Jahanian return LV_Valid; 10592514a309204341798f96912ce7a90841bea59727Fariborz Jahanian Expr *BaseExp = m->getBase(); 10602514a309204341798f96912ce7a90841bea59727Fariborz Jahanian return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ? 10612514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx); 10622514a309204341798f96912ce7a90841bea59727Fariborz Jahanian } 106386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 106486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- If it refers to a static member function [...], then 106586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // E1.E2 is an lvalue. 106686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- Otherwise, if E1.E2 refers to a non-static member 106786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // function [...], then E1.E2 is not an lvalue. 106886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member)) 106986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return Method->isStatic()? LV_Valid : LV_MemberFunction; 107086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 107186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- If E2 is a member enumerator [...], the expression E1.E2 107286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // is not an lvalue. 107386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (isa<EnumConstantDecl>(Member)) 107486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return LV_InvalidExpression; 107586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 107686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // Not an lvalue. 107786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return LV_InvalidExpression; 10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 10792514a309204341798f96912ce7a90841bea59727Fariborz Jahanian 108086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // C99 6.5.2.3p4 10812514a309204341798f96912ce7a90841bea59727Fariborz Jahanian if (m->isArrow()) 10822514a309204341798f96912ce7a90841bea59727Fariborz Jahanian return LV_Valid; 10832514a309204341798f96912ce7a90841bea59727Fariborz Jahanian Expr *BaseExp = m->getBase(); 10842514a309204341798f96912ce7a90841bea59727Fariborz Jahanian return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ? 10852514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx); 1086fdd75663fffeb2058a7847975e50837e61200593Anton Korobeynikov } 10877da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner case UnaryOperatorClass: 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref) 10897da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner return LV_Valid; // C99 6.5.3p4 10907da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner 10917da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real || 1092baf0d6678418e0dd9309438c3e50274253cfc7b2Chris Lattner cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag || 1093baf0d6678418e0dd9309438c3e50274253cfc7b2Chris Lattner cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension) 109428be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(Ctx); // GNU. 109574253736184c0717a0649922551bf9d8b6815651Douglas Gregor 109674253736184c0717a0649922551bf9d8b6815651Douglas Gregor if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.pre.incr]p1 109774253736184c0717a0649922551bf9d8b6815651Douglas Gregor (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreInc || 109874253736184c0717a0649922551bf9d8b6815651Douglas Gregor cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreDec)) 109974253736184c0717a0649922551bf9d8b6815651Douglas Gregor return LV_Valid; 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 1101eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor case ImplicitCastExprClass: 11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return cast<ImplicitCastExpr>(this)->isLvalueCast()? LV_Valid 1103eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor : LV_InvalidExpression; 11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: // C99 6.5.1p5 110528be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner return cast<ParenExpr>(this)->getSubExpr()->isLvalue(Ctx); 1106eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor case BinaryOperatorClass: 1107eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor case CompoundAssignOperatorClass: { 1108eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor const BinaryOperator *BinOp = cast<BinaryOperator>(this); 1109337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 1110337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.comma]p1 1111337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor BinOp->getOpcode() == BinaryOperator::Comma) 1112337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor return BinOp->getRHS()->isLvalue(Ctx); 1113337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 1114224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl // C++ [expr.mptr.oper]p6 111527d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian // The result of a .* expression is an lvalue only if its first operand is 111627d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian // an lvalue and its second operand is a pointer to data member. 111727d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian if (BinOp->getOpcode() == BinaryOperator::PtrMemD && 1118224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl !BinOp->getType()->isFunctionType()) 1119224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl return BinOp->getLHS()->isLvalue(Ctx); 1120224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl 112127d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian // The result of an ->* expression is an lvalue only if its second operand 112227d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian // is a pointer to data member. 112327d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian if (BinOp->getOpcode() == BinaryOperator::PtrMemI && 112427d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian !BinOp->getType()->isFunctionType()) { 112527d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian QualType Ty = BinOp->getRHS()->getType(); 112627d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian if (Ty->isMemberPointerType() && !Ty->isMemberFunctionPointerType()) 112727d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian return LV_Valid; 112827d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian } 112927d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian 1130bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor if (!BinOp->isAssignmentOp()) 1131eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor return LV_InvalidExpression; 1132eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 1133bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor if (Ctx.getLangOptions().CPlusPlus) 11341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // C++ [expr.ass]p1: 1135bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor // The result of an assignment operation [...] is an lvalue. 1136bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor return LV_Valid; 1137bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor 1138bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor 1139bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor // C99 6.5.16: 1140bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor // An assignment expression [...] is not an lvalue. 1141bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor return LV_InvalidExpression; 1142eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor } 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case CallExprClass: 114488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor case CXXOperatorCallExprClass: 114588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor case CXXMemberCallExprClass: { 11467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // C++0x [expr.call]p10 11479d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // A function call is an lvalue if and only if the result type 11487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // is an lvalue reference. 11496dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType ReturnType = cast<CallExpr>(this)->getCallReturnType(); 11506dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson if (ReturnType->isLValueReferenceType()) 11516dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return LV_Valid; 11527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 11539d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor break; 11549d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 1155e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff case CompoundLiteralExprClass: // C99 6.5.2.5p5 1156e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff return LV_Valid; 1157670a62cd1d51042ea076cda5e93f26a1d8327fb3Chris Lattner case ChooseExprClass: 1158670a62cd1d51042ea076cda5e93f26a1d8327fb3Chris Lattner // __builtin_choose_expr is an lvalue if the selected operand is. 11597976932a1c256d447316ffac58e9821417725e34Eli Friedman return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx)->isLvalue(Ctx); 1160213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman case ExtVectorElementExprClass: 1161213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (cast<ExtVectorElementExpr>(this)->containsDuplicateElements()) 1162fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return LV_DuplicateVectorComponents; 1163fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return LV_Valid; 1164027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff case ObjCIvarRefExprClass: // ObjC instance variables are lvalues. 1165027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff return LV_Valid; 1166799a6a6850af625946bb8d88ca960bb6604e3858Steve Naroff case ObjCPropertyRefExprClass: // FIXME: check if read-only property. 1167799a6a6850af625946bb8d88ca960bb6604e3858Steve Naroff return LV_Valid; 116809105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian case ObjCImplicitSetterGetterRefExprClass: // FIXME: check if read-only property. 1169670a62cd1d51042ea076cda5e93f26a1d8327fb3Chris Lattner return LV_Valid; 1170d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner case PredefinedExprClass: 1171796da18402f286b897782a298ae3b20c459c102eDouglas Gregor return LV_Valid; 1172ba13543329afac4a0d01304ec2ec4924d99306a6John McCall case UnresolvedLookupExprClass: 1173ba13543329afac4a0d01304ec2ec4924d99306a6John McCall return LV_Valid; 117404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 117528be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue(Ctx); 11766eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor case CStyleCastExprClass: 11779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXFunctionalCastExprClass: 11789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXStaticCastExprClass: 11799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXDynamicCastExprClass: 11809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXReinterpretCastExprClass: 11819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXConstCastExprClass: 11829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // The result of an explicit cast is an lvalue if the type we are 11837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // casting to is an lvalue reference type. See C++ [expr.cast]p1, 11849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // C++ [expr.static.cast]p2, C++ [expr.dynamic.cast]p2, 11859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // C++ [expr.reinterpret.cast]p1, C++ [expr.const.cast]p1. 11867c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (cast<ExplicitCastExpr>(this)->getTypeAsWritten()-> 11877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl isLValueReferenceType()) 11889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return LV_Valid; 11899d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor break; 1190c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl case CXXTypeidExprClass: 1191c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2.8p1: The result of a typeid expression is an lvalue of ... 1192c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl return LV_Valid; 11936f68027af2b6ce294a2706f23a1d3cb7ca1b8d37Anders Carlsson case CXXBindTemporaryExprClass: 11946f68027af2b6ce294a2706f23a1d3cb7ca1b8d37Anders Carlsson return cast<CXXBindTemporaryExpr>(this)->getSubExpr()-> 11956f68027af2b6ce294a2706f23a1d3cb7ca1b8d37Anders Carlsson isLvalueInternal(Ctx); 119676458501a8963fa11b91c9337a487de6871169b4Sebastian Redl case ConditionalOperatorClass: { 119776458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // Complicated handling is only for C++. 119876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl if (!Ctx.getLangOptions().CPlusPlus) 119976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl return LV_InvalidExpression; 120076458501a8963fa11b91c9337a487de6871169b4Sebastian Redl 120176458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // Sema should have taken care to ensure that a CXXTemporaryObjectExpr is 120276458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // everywhere there's an object converted to an rvalue. Also, any other 120376458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // casts should be wrapped by ImplicitCastExprs. There's just the special 120476458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // case involving throws to work out. 120576458501a8963fa11b91c9337a487de6871169b4Sebastian Redl const ConditionalOperator *Cond = cast<ConditionalOperator>(this); 1206d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor Expr *True = Cond->getTrueExpr(); 1207d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor Expr *False = Cond->getFalseExpr(); 120876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // C++0x 5.16p2 120976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // If either the second or the third operand has type (cv) void, [...] 121076458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // the result [...] is an rvalue. 1211d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor if (True->getType()->isVoidType() || False->getType()->isVoidType()) 121276458501a8963fa11b91c9337a487de6871169b4Sebastian Redl return LV_InvalidExpression; 121376458501a8963fa11b91c9337a487de6871169b4Sebastian Redl 121476458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // Both sides must be lvalues for the result to be an lvalue. 1215d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor if (True->isLvalue(Ctx) != LV_Valid || False->isLvalue(Ctx) != LV_Valid) 121676458501a8963fa11b91c9337a487de6871169b4Sebastian Redl return LV_InvalidExpression; 121776458501a8963fa11b91c9337a487de6871169b4Sebastian Redl 121876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // That's it. 121976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl return LV_Valid; 122076458501a8963fa11b91c9337a487de6871169b4Sebastian Redl } 122176458501a8963fa11b91c9337a487de6871169b4Sebastian Redl 12222d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor case Expr::CXXExprWithTemporariesClass: 12232d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor return cast<CXXExprWithTemporaries>(this)->getSubExpr()->isLvalue(Ctx); 12242d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor 12252d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor case Expr::ObjCMessageExprClass: 12262d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor if (const ObjCMethodDecl *Method 12272d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor = cast<ObjCMessageExpr>(this)->getMethodDecl()) 12282d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor if (Method->getResultType()->isLValueReferenceType()) 12292d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor return LV_Valid; 12302d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor break; 12312d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor 12325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return LV_InvalidExpression; 12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// does not have an incomplete type, does not have a const-qualified type, and 12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// if it is a structure or union, does not have any member (including, 12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// recursively, any member or element of all contained aggregates or unions) 12425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with a const-qualified type. 12431eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpExpr::isModifiableLvalueResult 124444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel DunbarExpr::isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc) const { 124528be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult lvalResult = isLvalue(Ctx); 12461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (lvalResult) { 12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case LV_Valid: 1249ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor // C++ 3.10p11: Functions cannot be modified, but pointers to 1250ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor // functions can be modifiable. 1251ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor if (Ctx.getLangOptions().CPlusPlus && TR->isFunctionType()) 1252ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor return MLV_NotObjectType; 1253ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor break; 1254ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor 12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LV_NotObjectType: return MLV_NotObjectType; 12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LV_IncompleteVoidType: return MLV_IncompleteVoidType; 1257fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents; 1258ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner case LV_InvalidExpression: 1259ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner // If the top level is a C-style cast, and the subexpression is a valid 1260ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner // lvalue, then this is probably a use of the old-school "cast as lvalue" 1261ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner // GCC extension. We don't support it, but we want to produce good 1262ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner // diagnostics when it happens so that the user knows why. 126344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(IgnoreParens())) { 126444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid) { 126544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar if (Loc) 126644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar *Loc = CE->getLParenLoc(); 1267ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner return MLV_LValueCast; 126844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar } 126944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar } 1270ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner return MLV_InvalidExpression; 127186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor case LV_MemberFunction: return MLV_MemberFunction; 12722514a309204341798f96912ce7a90841bea59727Fariborz Jahanian case LV_SubObjCPropertySetting: return MLV_SubObjCPropertySetting; 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 127404831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman 127504831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman // The following is illegal: 127604831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman // void takeclosure(void (^C)(void)); 127704831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman // void func() { int x = 1; takeclosure(^{ x = 7; }); } 127804831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman // 1279c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian if (const BlockDeclRefExpr *BDR = dyn_cast<BlockDeclRefExpr>(this)) { 128004831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl())) 128104831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman return MLV_NotBlockQualified; 128204831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman } 12837e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar 1284c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian // Assigning to an 'implicit' property? 12857e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar if (const ObjCImplicitSetterGetterRefExpr* Expr = 1286c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian dyn_cast<ObjCImplicitSetterGetterRefExpr>(this)) { 1287c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian if (Expr->getSetterMethod() == 0) 1288c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian return MLV_NoSetterProperty; 1289c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian } 12907e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar 1291c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType CT = Ctx.getCanonicalType(getType()); 12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1293c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (CT.isConstQualified()) 12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return MLV_ConstQualified; 1295c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (CT->isArrayType()) 12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return MLV_ArrayType; 1297c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (CT->isIncompleteType()) 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return MLV_IncompleteType; 12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13006217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *r = CT->getAs<RecordType>()) { 13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (r->hasConstFields()) 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return MLV_ConstQualified; 13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return MLV_Valid; 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 130844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 13097f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise. 1310102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 131144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian switch (getStmtClass()) { 131244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 131344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 131444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 131544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 1316207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 1317102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 131844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ParenExprClass: 1319102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 132044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 1321102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 132206b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 1323102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 1324a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor case DeclRefExprClass: { 132544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const Decl *D = cast<DeclRefExpr>(this)->getDecl(); 1326102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 1327102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 1328102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 1329102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 133059a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // dereferencing to a pointer is always a gc'able candidate, 133159a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian // unless it is __weak. 13327e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar return T->isPointerType() && 13330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); 1334102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 133544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 133644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 133783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 133844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const MemberExpr *M = cast<MemberExpr>(this); 1339102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 134044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 134144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 1342102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx); 134344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 134444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 13454e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 13464e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 13474e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek while (ParenExpr* P = dyn_cast<ParenExpr>(E)) 13484e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek E = P->getSubExpr(); 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13504e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return E; 13514e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 13524e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 135356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 135456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 135556f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 135656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 135756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 135856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) 135956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 136056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner else if (CastExpr *P = dyn_cast<CastExpr>(E)) 136156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 136256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner else 136356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return E; 136456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 136556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 136656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 1367ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 1368ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 1369ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 1370ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 1371ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 1372ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 1373ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 1374ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 1375ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1376ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 13771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1378ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 1379ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 1380ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // ptr<->int casts of the same width. We also ignore all identify casts. 1381ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1383ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 1384ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1385ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1386ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 13871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1388ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if ((E->getType()->isPointerType() || E->getType()->isIntegralType()) && 1389ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner (SE->getType()->isPointerType() || SE->getType()->isIntegralType()) && 1390ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 1391ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1392ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1393ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1394ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 13951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1396ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 1397ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1398ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 1399ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 14006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const { 14016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *E = this; 14026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) 14036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor E = ICE->getSubExprAsWritten(); 14046eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor 14056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return isa<CXXDefaultArgExpr>(E); 14066eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor} 1407ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 1408898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 1409898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 1410898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) { 1411898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 1412898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 1413898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 1414898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1415898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1416898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1417898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1418898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyValueDependentArguments - Determines if any of the expressions 1419898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is value-dependent. 1420898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) { 1421898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 1422898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isValueDependent()) 1423898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 1424898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1425898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1426898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1427898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1428c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedmanbool Expr::isConstantInitializer(ASTContext &Ctx) const { 1429c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 1430c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 1431c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 1432c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 1433c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 1434c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 14351f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This function assumes the variable being assigned to 14361f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // isn't a reference type! 14371f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 1438e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 1439c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 1440e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 144114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 1442eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 1443e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 144459b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 14451f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 14461f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 14471f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 144859b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 1449c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman return Exp->isConstantInitializer(Ctx); 145059b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 1451e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 14521f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 14531f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 14541f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 1455e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 1456e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 1457e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (!Exp->getInit(i)->isConstantInitializer(Ctx)) 1459e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 1460e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 1461c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 1462e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 14633498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 14643498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 14653ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case ParenExprClass: 1466c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return cast<ParenExpr>(this)->getSubExpr()->isConstantInitializer(Ctx); 1467c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 1468c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 1469c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman if (Exp->getOpcode() == UnaryOperator::Extension) 1470c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return Exp->getSubExpr()->isConstantInitializer(Ctx); 1471c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 1472c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 14733ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner case BinaryOperatorClass: { 14743ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // Special case &&foo - &&bar. It would be nice to generalize this somehow 14753ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner // but this handles the common case. 14763ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner const BinaryOperator *Exp = cast<BinaryOperator>(this); 14773ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner if (Exp->getOpcode() == BinaryOperator::Sub && 14783ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) && 14793ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx))) 14803ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner return true; 14813ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner break; 14823ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner } 148381045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 1484c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case CStyleCastExprClass: 1485c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // Handle casts with a destination that's a struct or union; this 1486c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // deals with both the gcc no-op struct cast extension and the 1487c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // cast-to-union extension. 1488c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman if (getType()->isRecordType()) 1489c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return cast<CastExpr>(this)->getSubExpr()->isConstantInitializer(Ctx); 1490430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner 1491430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // Integer->integer casts can be handled here, which is important for 1492430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner // things like (int)(&&x-&&y). Scary but true. 1493430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner if (getType()->isIntegerType() && 1494430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType()) 1495430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner return cast<CastExpr>(this)->getSubExpr()->isConstantInitializer(Ctx); 1496430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner 1497c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 1498e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 1499c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 150038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 150138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 15025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIntegerConstantExpr - this recursive routine will test if an expression is 1503e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman/// an integer constant expression. 15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero, 15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comma, etc 15075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 1508ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// FIXME: Handle offsetof. Two things to do: Handle GCC's __builtin_offsetof 1509ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// to support gcc 4.0+ and handle the idiom GCC recognizes with a null pointer 1510ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// cast+dereference. 15112d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar 1512e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// CheckICE - This function does the fundamental ICE checking: the returned 1513e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// ICEDiag contains a Val of 0, 1, or 2, and a possibly null SourceLocation. 1514e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// Note that to reduce code duplication, this helper does no evaluation 15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// itself; the caller checks whether the expression is evaluatable, and 1516e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// in the rare cases where CheckICE actually cares about the evaluated 15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// value, it calls into Evalute. 1518e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 1519e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// Meanings of Val: 1520e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 0: This expression is an ICE if it can be evaluated by Evaluate. 1521e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 1: This expression is not an ICE, but if it isn't evaluated, it's 1522e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// a legal subexpression for an ICE. This return value is used to handle 1523e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// the comma operator in C99 mode. 1524e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 2: This expression is not an ICE, and is not a legal subexpression for one. 1525e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 1526e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedmanstruct ICEDiag { 1527e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman unsigned Val; 1528e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman SourceLocation Loc; 1529e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 1530e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman public: 1531e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag(unsigned v, SourceLocation l) : Val(v), Loc(l) {} 1532e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag() : Val(0) {} 1533e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman}; 1534e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 1535e28d7195aad595154130ac8d03cc6c6513ece1bfEli FriedmanICEDiag NoDiag() { return ICEDiag(); } 1536e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 153760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedmanstatic ICEDiag CheckEvalInICE(const Expr* E, ASTContext &Ctx) { 153860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman Expr::EvalResult EVResult; 153960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (!E->Evaluate(EVResult, Ctx) || EVResult.HasSideEffects || 154060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman !EVResult.Val.isInt()) { 154160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(2, E->getLocStart()); 154260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 154360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return NoDiag(); 154460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman} 154560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman 1546e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedmanstatic ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { 1547c3082413e4207173b32c118e922d63149df6261fAnders Carlsson assert(!E->isValueDependent() && "Should not see value dependent exprs!"); 1548e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (!E->getType()->isIntegralType()) { 1549e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 1550a6afa768aa7bd3102a2807aa720917e4a1771e4eEli Friedman } 1551e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 1552e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman switch (E->getStmtClass()) { 1553f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor#define STMT(Node, Base) case Expr::Node##Class: 1554f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor#define EXPR(Node, Base) 1555f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor#include "clang/AST/StmtNodes.def" 1556f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::PredefinedExprClass: 1557f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::FloatingLiteralClass: 1558f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ImaginaryLiteralClass: 1559f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::StringLiteralClass: 1560f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ArraySubscriptExprClass: 1561f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::MemberExprClass: 1562f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CompoundAssignOperatorClass: 1563f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CompoundLiteralExprClass: 1564f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ExtVectorElementExprClass: 1565f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::InitListExprClass: 1566f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::DesignatedInitExprClass: 1567f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ImplicitValueInitExprClass: 1568f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ParenListExprClass: 1569f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::VAArgExprClass: 1570f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::AddrLabelExprClass: 1571f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::StmtExprClass: 1572f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXMemberCallExprClass: 1573f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXDynamicCastExprClass: 1574f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXTypeidExprClass: 1575f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXNullPtrLiteralExprClass: 1576f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXThisExprClass: 1577f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXThrowExprClass: 1578f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXNewExprClass: 1579f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXDeleteExprClass: 1580f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXPseudoDestructorExprClass: 1581ba13543329afac4a0d01304ec2ec4924d99306a6John McCall case Expr::UnresolvedLookupExprClass: 1582865d447ac6a4721ab58e898d014a21f2eff74b06John McCall case Expr::DependentScopeDeclRefExprClass: 1583f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXConstructExprClass: 1584f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXBindTemporaryExprClass: 1585f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXExprWithTemporariesClass: 1586f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXTemporaryObjectExprClass: 1587f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXUnresolvedConstructExprClass: 1588865d447ac6a4721ab58e898d014a21f2eff74b06John McCall case Expr::CXXDependentScopeMemberExprClass: 1589129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall case Expr::UnresolvedMemberExprClass: 1590f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCStringLiteralClass: 1591f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCEncodeExprClass: 1592f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCMessageExprClass: 1593f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCSelectorExprClass: 1594f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCProtocolExprClass: 1595f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCIvarRefExprClass: 1596f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCPropertyRefExprClass: 1597f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCImplicitSetterGetterRefExprClass: 1598f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCSuperExprClass: 1599f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ObjCIsaExprClass: 1600f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ShuffleVectorExprClass: 1601f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::BlockExprClass: 1602f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::BlockDeclRefExprClass: 1603f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::NoStmtClass: 1604f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ExprClass: 1605e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 16067e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar 1607043cad21b78c6b02597cdc7b6ead32388e27ebc7Douglas Gregor case Expr::GNUNullExprClass: 1608043cad21b78c6b02597cdc7b6ead32388e27ebc7Douglas Gregor // GCC considers the GNU __null value to be an integral constant expression. 1609043cad21b78c6b02597cdc7b6ead32388e27ebc7Douglas Gregor return NoDiag(); 16107e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar 1611e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::ParenExprClass: 1612e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CheckICE(cast<ParenExpr>(E)->getSubExpr(), Ctx); 1613e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::IntegerLiteralClass: 1614e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CharacterLiteralClass: 1615e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CXXBoolLiteralExprClass: 1616e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CXXZeroInitValueExprClass: 1617e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::TypesCompatibleExprClass: 1618e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::UnaryTypeTraitExprClass: 1619e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case Expr::CallExprClass: 1621e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CXXOperatorCallExprClass: { 1622e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const CallExpr *CE = cast<CallExpr>(E); 162360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (CE->isBuiltinCall(Ctx)) 162460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return CheckEvalInICE(E, Ctx); 1625e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 162613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff } 1627e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::DeclRefExprClass: 1628e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (isa<EnumConstantDecl>(cast<DeclRefExpr>(E)->getDecl())) 1629e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 16304a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl if (Ctx.getLangOptions().CPlusPlus && 16310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall E->getType().getCVRQualifiers() == Qualifiers::Const) { 16324a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl // C++ 7.1.5.1p2 16334a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl // A variable of non-volatile const-qualified integral or enumeration 16344a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl // type initialized by an ICE can be used in ICEs. 16354a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl if (const VarDecl *Dcl = 1636e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman dyn_cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl())) { 1637cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor Qualifiers Quals = Ctx.getCanonicalType(Dcl->getType()).getQualifiers(); 1638cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor if (Quals.hasVolatile() || !Quals.hasConst()) 1639cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation()); 1640cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor 1641cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // Look for the definition of this variable, which will actually have 1642cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // an initializer. 1643cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor const VarDecl *Def = 0; 1644cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor const Expr *Init = Dcl->getDefinition(Def); 1645cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor if (Init) { 1646cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor if (Def->isInitKnownICE()) { 1647cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // We have already checked whether this subexpression is an 1648cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // integral constant expression. 1649cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor if (Def->isInitICE()) 1650cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor return NoDiag(); 1651cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor else 1652cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation()); 1653cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor } 165478d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor 1655cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // C++ [class.static.data]p4: 1656cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // If a static data member is of const integral or const 1657cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // enumeration type, its declaration in the class definition can 1658cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // specify a constant-initializer which shall be an integral 1659cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // constant expression (5.19). In that case, the member can appear 1660cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor // in integral constant expressions. 1661cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor if (Def->isOutOfLine()) { 1662c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman Dcl->setInitKnownICE(false); 1663cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation()); 1664cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor } 1665c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman 1666c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman if (Dcl->isCheckingICE()) { 1667c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation()); 1668c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman } 1669c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman 1670c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman Dcl->setCheckingICE(); 167178d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor ICEDiag Result = CheckICE(Init, Ctx); 167278d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor // Cache the result of the ICE test. 1673c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman Dcl->setInitKnownICE(Result.Val == 0); 167478d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor return Result; 167578d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor } 16764a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl } 16774a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl } 1678e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 1679e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::UnaryOperatorClass: { 1680e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const UnaryOperator *Exp = cast<UnaryOperator>(E); 16815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Exp->getOpcode()) { 1682f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case UnaryOperator::PostInc: 1683f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case UnaryOperator::PostDec: 1684f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case UnaryOperator::PreInc: 1685f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case UnaryOperator::PreDec: 1686f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case UnaryOperator::AddrOf: 1687f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case UnaryOperator::Deref: 1688e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 16897e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar 16905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Extension: 1691e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case UnaryOperator::LNot: 16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Plus: 16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Minus: 16945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Not: 169560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman case UnaryOperator::Real: 169660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman case UnaryOperator::Imag: 1697e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CheckICE(Exp->getSubExpr(), Ctx); 16985a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson case UnaryOperator::OffsetOf: 169960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // Note that per C99, offsetof must be an ICE. And AFAIK, using 170060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // Evaluate matches the proposed gcc behavior for cases like 170160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // "offsetof(struct s{int x[4];}, x[!.0])". This doesn't affect 170260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // compliance: we should warn earlier for offsetof expressions with 170360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // array subscripts that aren't ICEs, and if the array subscripts 170460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // are ICEs, the value of the offsetof must be an integer constant. 170560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return CheckEvalInICE(E, Ctx); 17065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1708e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::SizeOfAlignOfExprClass: { 1709e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const SizeOfAlignOfExpr *Exp = cast<SizeOfAlignOfExpr>(E); 1710e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (Exp->isSizeOf() && Exp->getTypeOfArgument()->isVariableArrayType()) 1711e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 1712e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 17135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1714e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::BinaryOperatorClass: { 1715e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const BinaryOperator *Exp = cast<BinaryOperator>(E); 17165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Exp->getOpcode()) { 1717f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::PtrMemD: 1718f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::PtrMemI: 1719f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::Assign: 1720f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::MulAssign: 1721f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::DivAssign: 1722f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::RemAssign: 1723f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::AddAssign: 1724f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::SubAssign: 1725f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::ShlAssign: 1726f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::ShrAssign: 1727f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::AndAssign: 1728f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::XorAssign: 1729f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case BinaryOperator::OrAssign: 1730e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 17317e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar 17325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Mul: 17335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Div: 17345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Rem: 1735e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Add: 1736e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Sub: 17375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Shl: 17385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Shr: 1739e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::LT: 1740e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::GT: 1741e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::LE: 1742e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::GE: 1743e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::EQ: 1744e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::NE: 1745e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::And: 1746e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Xor: 1747e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Or: 1748e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Comma: { 1749e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag LHSResult = CheckICE(Exp->getLHS(), Ctx); 1750e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag RHSResult = CheckICE(Exp->getRHS(), Ctx); 175160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (Exp->getOpcode() == BinaryOperator::Div || 175260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman Exp->getOpcode() == BinaryOperator::Rem) { 175360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // Evaluate gives an error for undefined Div/Rem, so make sure 175460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // we don't evaluate one. 175560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (LHSResult.Val != 2 && RHSResult.Val != 2) { 175660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman llvm::APSInt REval = Exp->getRHS()->EvaluateAsInt(Ctx); 175760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (REval == 0) 175860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(1, E->getLocStart()); 175960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (REval.isSigned() && REval.isAllOnesValue()) { 176060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman llvm::APSInt LEval = Exp->getLHS()->EvaluateAsInt(Ctx); 176160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (LEval.isMinSignedValue()) 176260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(1, E->getLocStart()); 176360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 176460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 176560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 176660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (Exp->getOpcode() == BinaryOperator::Comma) { 176760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (Ctx.getLangOptions().C99) { 176860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // C99 6.6p3 introduces a strange edge case: comma can be in an ICE 176960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // if it isn't evaluated. 177060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (LHSResult.Val == 0 && RHSResult.Val == 0) 177160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(1, E->getLocStart()); 177260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } else { 177360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // In both C89 and C++, commas in ICEs are illegal. 177460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(2, E->getLocStart()); 177560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 1776b11e77836dd0867955c5abf32baf1c3e6c7f81e1Eli Friedman } 1777e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (LHSResult.Val >= RHSResult.Val) 1778e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return LHSResult; 1779e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return RHSResult; 17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1781e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::LAnd: 1782e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::LOr: { 1783e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag LHSResult = CheckICE(Exp->getLHS(), Ctx); 1784e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag RHSResult = CheckICE(Exp->getRHS(), Ctx); 1785e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (LHSResult.Val == 0 && RHSResult.Val == 1) { 1786e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // Rare case where the RHS has a comma "side-effect"; we need 1787e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // to actually check the condition to see whether the side 1788e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // with the comma is evaluated. 1789e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if ((Exp->getOpcode() == BinaryOperator::LAnd) != 179060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman (Exp->getLHS()->EvaluateAsInt(Ctx) == 0)) 1791e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return RHSResult; 1792e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 1793a135975d4257ccc83f13b607b29d882bb00c80b6Daniel Dunbar } 179460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman 1795e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (LHSResult.Val >= RHSResult.Val) 1796e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return LHSResult; 1797e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return RHSResult; 17985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1799987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner } 18005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1801f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CastExprClass: 1802e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::ImplicitCastExprClass: 1803f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::ExplicitCastExprClass: 1804e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CStyleCastExprClass: 180559600d80b7e34e819cd25dd67f661aa1f3d9099dDouglas Gregor case Expr::CXXFunctionalCastExprClass: 1806f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor case Expr::CXXNamedCastExprClass: 180759600d80b7e34e819cd25dd67f661aa1f3d9099dDouglas Gregor case Expr::CXXStaticCastExprClass: 180859600d80b7e34e819cd25dd67f661aa1f3d9099dDouglas Gregor case Expr::CXXReinterpretCastExprClass: 180959600d80b7e34e819cd25dd67f661aa1f3d9099dDouglas Gregor case Expr::CXXConstCastExprClass: { 1810e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr(); 1811e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (SubExpr->getType()->isIntegralType()) 1812e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CheckICE(SubExpr, Ctx); 1813e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (isa<FloatingLiteral>(SubExpr->IgnoreParens())) 1814e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 1815e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 1816e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman } 1817e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::ConditionalOperatorClass: { 1818e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const ConditionalOperator *Exp = cast<ConditionalOperator>(E); 18191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the condition (ignoring parens) is a __builtin_constant_p call, 182028daa53db73341b7ee7f269924ccfca1c6d179acChris Lattner // then only the true side is actually considered in an integer constant 182142b83dde7c700b34f9435ad746984169888ae705Chris Lattner // expression, and it is fully evaluated. This is an important GNU 182242b83dde7c700b34f9435ad746984169888ae705Chris Lattner // extension. See GCC PR38377 for discussion. 1823e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (const CallExpr *CallCE = dyn_cast<CallExpr>(Exp->getCond()->IgnoreParenCasts())) 18243c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor if (CallCE->isBuiltinCall(Ctx) == Builtin::BI__builtin_constant_p) { 1825e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman Expr::EvalResult EVResult; 1826e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (!E->Evaluate(EVResult, Ctx) || EVResult.HasSideEffects || 1827e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman !EVResult.Val.isInt()) { 182860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(2, E->getLocStart()); 1829e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman } 1830e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 183142b83dde7c700b34f9435ad746984169888ae705Chris Lattner } 1832e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag CondResult = CheckICE(Exp->getCond(), Ctx); 1833e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag TrueResult = CheckICE(Exp->getTrueExpr(), Ctx); 1834e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag FalseResult = CheckICE(Exp->getFalseExpr(), Ctx); 1835e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (CondResult.Val == 2) 1836e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CondResult; 1837e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (TrueResult.Val == 2) 1838e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return TrueResult; 1839e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (FalseResult.Val == 2) 1840e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return FalseResult; 1841e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (CondResult.Val == 1) 1842e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CondResult; 1843e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (TrueResult.Val == 0 && FalseResult.Val == 0) 1844e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 1845e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // Rare case where the diagnostics depend on which side is evaluated 1846e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // Note that if we get here, CondResult is 0, and at least one of 1847e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // TrueResult and FalseResult is non-zero. 184860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (Exp->getCond()->EvaluateAsInt(Ctx) == 0) { 1849e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return FalseResult; 1850e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman } 1851e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return TrueResult; 18525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1853e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CXXDefaultArgExprClass: 1854e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CheckICE(cast<CXXDefaultArgExpr>(E)->getExpr(), Ctx); 185560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman case Expr::ChooseExprClass: { 18567976932a1c256d447316ffac58e9821417725e34Eli Friedman return CheckICE(cast<ChooseExpr>(E)->getChosenSubExpr(Ctx), Ctx); 185760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 18585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18597e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar 1860f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor // Silence a GCC warning 1861f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor return ICEDiag(2, E->getLocStart()); 1862e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman} 18635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1864e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedmanbool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 1865e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman SourceLocation *Loc, bool isEvaluated) const { 1866e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag d = CheckICE(this, Ctx); 1867e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (d.Val != 0) { 1868e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (Loc) *Loc = d.Loc; 1869e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return false; 1870e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman } 1871e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman EvalResult EvalResult; 187260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (!Evaluate(EvalResult, Ctx)) 18739f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("ICE cannot be evaluated!"); 187460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman assert(!EvalResult.HasSideEffects && "ICE with side effects!"); 187560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman assert(EvalResult.Val.isInt() && "ICE that isn't integer!"); 1876e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman Result = EvalResult.Val.getInt(); 18775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 18815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// integer constant expression with the value zero, or if this is one that is 18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// cast to void*. 1883ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregorbool Expr::isNullPointerConstant(ASTContext &Ctx, 1884ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NullPointerConstantValueDependence NPC) const { 1885ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor if (isValueDependent()) { 1886ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor switch (NPC) { 1887ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_NeverValueDependent: 1888ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor assert(false && "Unexpected value dependent expression!"); 1889ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor // If the unthinkable happens, fall through to the safest alternative. 1890ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 1891ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNull: 1892ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return isTypeDependent() || getType()->isIntegralType(); 1893ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor 1894ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor case NPC_ValueDependentIsNotNull: 1895ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return false; 1896ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 1897ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor } 1898f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar 18990777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 19000835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 19016215dee86c0e715b9f2b0d401ab2a5fcf629f1afSebastian Redl if (!Ctx.getLangOptions().CPlusPlus) { 19020777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 19036217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 19040777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 19050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Pointee.hasQualifiers() && 19060777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 19070777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 1908ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 19090777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 19105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1911aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 1912aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 1913ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 1914aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 1915aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 1916aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 1917ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); 19181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (const CXXDefaultArgExpr *DefaultArg 19198123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 192004421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 1921ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); 19222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 19232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 19242d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return true; 1925aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 19262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 19276e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // C++0x nullptr_t is always a null pointer constant. 19286e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 19296e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return true; 19306e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 1931aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 193256fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian if (!getType()->isIntegerType() || 193356fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType())) 1934aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff return false; 19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 19375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // test for the value 0. 193809de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman llvm::APSInt Result; 193909de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman return isIntegerConstantExpr(Result, Ctx) && Result == 0; 19405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 194131a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 194233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 19436f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 194433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 194527c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 194686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 194733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 194833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 194933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 195033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) 195133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 195233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 195333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 195433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 195527c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 195627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 19572140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 19582140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 19592140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 19602140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 19612140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 19622140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 1963213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 1964183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const VectorType *VT = getType()->getAs<VectorType>()) 19658a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 19668a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 19674d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 19684d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 19698a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 1970213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 1971a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // FIXME: Refactor this code to an accessor on the AST node which returns the 1972a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar // "type" of component access, and share with code below and in Sema. 197301eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar llvm::StringRef Comp = Accessor->getName(); 1974190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 1975190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 1976150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd") 1977190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 19781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1979190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 1980150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 1981150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar Comp = Comp.substr(1); 19821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1983150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar for (unsigned i = 0, e = Comp.size(); i != e; ++i) 1984150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar if (Comp.substr(i + 1).find(Comp[i]) != llvm::StringRef::npos) 1985fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 1986150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar 1987fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 1988fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 1989b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 19908a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 19913b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 19923b8d116703db8018f855cbb4733ace426422623bNate Begeman llvm::SmallVectorImpl<unsigned> &Elts) const { 19934b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar llvm::StringRef Comp = Accessor->getName(); 19944b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar if (Comp[0] == 's' || Comp[0] == 'S') 19954b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Comp = Comp.substr(1); 19961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19974b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isHi = Comp == "hi"; 19984b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isLo = Comp == "lo"; 19994b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isEven = Comp == "even"; 20004b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar bool isOdd = Comp == "odd"; 20011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20028a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 20038a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 20041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20058a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 20068a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 20078a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 20088a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 20098a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 20108a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 20118a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 20128a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 20138a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 20144b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar Index = ExtVectorType::getAccessorIdx(Comp[i]); 2015b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 20163b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 2017b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 20188a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 20198a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 202068d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// constructor for instance messages. 2021bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo, 2022a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek QualType retType, ObjCMethodDecl *mproto, 2023db611d556f71f98b66b69514d45958d76e5727abSteve Naroff SourceLocation LBrac, SourceLocation RBrac, 202449f109c786f99eb7468dac3976db083a65493444Steve Naroff Expr **ArgExprs, unsigned nargs) 20251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(ObjCMessageExprClass, retType), SelName(selInfo), 2026ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek MethodProto(mproto) { 202749f109c786f99eb7468dac3976db083a65493444Steve Naroff NumArgs = nargs; 20285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek SubExprs = new Stmt*[NumArgs+1]; 202968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff SubExprs[RECEIVER] = receiver; 203049f109c786f99eb7468dac3976db083a65493444Steve Naroff if (NumArgs) { 203149f109c786f99eb7468dac3976db083a65493444Steve Naroff for (unsigned i = 0; i != NumArgs; ++i) 203268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); 203368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff } 2034563477da25f824e37c535131695dc4dc9b68c465Steve Naroff LBracloc = LBrac; 2035563477da25f824e37c535131695dc4dc9b68c465Steve Naroff RBracloc = RBrac; 2036563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2037563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 20381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// constructor for class messages. 203968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// FIXME: clsName should be typed to ObjCInterfaceType 2040bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo, 2041a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek QualType retType, ObjCMethodDecl *mproto, 2042db611d556f71f98b66b69514d45958d76e5727abSteve Naroff SourceLocation LBrac, SourceLocation RBrac, 204349f109c786f99eb7468dac3976db083a65493444Steve Naroff Expr **ArgExprs, unsigned nargs) 20441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(ObjCMessageExprClass, retType), SelName(selInfo), 2045ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek MethodProto(mproto) { 204649f109c786f99eb7468dac3976db083a65493444Steve Naroff NumArgs = nargs; 20475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek SubExprs = new Stmt*[NumArgs+1]; 20484df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown); 204949f109c786f99eb7468dac3976db083a65493444Steve Naroff if (NumArgs) { 205049f109c786f99eb7468dac3976db083a65493444Steve Naroff for (unsigned i = 0; i != NumArgs; ++i) 205168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); 205268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff } 2053563477da25f824e37c535131695dc4dc9b68c465Steve Naroff LBracloc = LBrac; 2054563477da25f824e37c535131695dc4dc9b68c465Steve Naroff RBracloc = RBrac; 2055563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2056563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 20571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// constructor for class messages. 20584df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekObjCMessageExpr::ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo, 20594df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek QualType retType, ObjCMethodDecl *mproto, 20604df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SourceLocation LBrac, SourceLocation RBrac, 20614df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek Expr **ArgExprs, unsigned nargs) 20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump: Expr(ObjCMessageExprClass, retType), SelName(selInfo), 20634df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekMethodProto(mproto) { 20644df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek NumArgs = nargs; 20654df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SubExprs = new Stmt*[NumArgs+1]; 20664df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown); 20674df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek if (NumArgs) { 20684df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek for (unsigned i = 0; i != NumArgs; ++i) 20694df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); 20704df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek } 20714df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek LBracloc = LBrac; 20724df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek RBracloc = RBrac; 20734df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek} 20744df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 20754df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekObjCMessageExpr::ClassInfo ObjCMessageExpr::getClassInfo() const { 20764df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek uintptr_t x = (uintptr_t) SubExprs[RECEIVER]; 20774df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek switch (x & Flags) { 20784df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek default: 20794df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek assert(false && "Invalid ObjCMessageExpr."); 20804df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek case IsInstMeth: 20814df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek return ClassInfo(0, 0); 20824df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek case IsClsMethDeclUnknown: 20834df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek return ClassInfo(0, (IdentifierInfo*) (x & ~Flags)); 20844df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek case IsClsMethDeclKnown: { 20854df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek ObjCInterfaceDecl* D = (ObjCInterfaceDecl*) (x & ~Flags); 20864df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek return ClassInfo(D, D->getIdentifier()); 20874df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek } 20884df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek } 20894df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek} 20904df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 20910389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattnervoid ObjCMessageExpr::setClassInfo(const ObjCMessageExpr::ClassInfo &CI) { 20920389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner if (CI.first == 0 && CI.second == 0) 20930389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner SubExprs[RECEIVER] = (Expr*)((uintptr_t)0 | IsInstMeth); 20940389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner else if (CI.first == 0) 20950389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.second | IsClsMethDeclUnknown); 20960389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner else 20970389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.first | IsClsMethDeclKnown); 20980389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner} 20990389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 21000389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 210127437caadea35f84d550cd29f024fcf3ea240eecChris Lattnerbool ChooseExpr::isConditionTrue(ASTContext &C) const { 21029a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getCond()->EvaluateAsInt(C) != 0; 210327437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 210427437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 2105888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 2106888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 2107888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 2108888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 2109888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 211094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 211194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 21121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 2113888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 2114888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::DoDestroy(ASTContext& C) { 2115888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman DestroyChildren(C); 2116888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 2117888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman this->~ShuffleVectorExpr(); 2118888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman C.Deallocate(this); 211994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor} 212094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 212142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid SizeOfAlignOfExpr::DoDestroy(ASTContext& C) { 21220518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Override default behavior of traversing children. If this has a type 21230518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // operand and the type is a variable-length array, the child iteration 21240518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // will iterate over the size expression. However, this expression belongs 21250518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // to the type, not to this, so we don't want to delete it. 21260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // We still want to delete this expression. 21278189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek if (isArgumentType()) { 21288189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek this->~SizeOfAlignOfExpr(); 21298189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek C.Deallocate(this); 21308189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 21310518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl else 213242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor Expr::DoDestroy(C); 21339048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar} 21349048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar 213577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 213605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 213705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 213805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 213905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() { 214005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 214105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 214205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 214305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 214405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 214505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 214605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 21471eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::DesignatedInitExpr(QualType Ty, unsigned NumDesignators, 2148ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 21491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation EqualOrColonLoc, 2150ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 21511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **IndexExprs, 21529ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned NumIndexExprs, 21539ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 21541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Expr(DesignatedInitExprClass, Ty, 21559ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Init->isTypeDependent(), Init->isValueDependent()), 21561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 21571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { 2158ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators = new Designator[NumDesignators]; 21599ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 21609ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 21619ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor child_iterator Child = child_begin(); 21629ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 21639ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 21649ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 21659ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 21669ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 21679ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 2168ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 21699ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 21709ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 21719ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 21729ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 21731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDependent = ValueDependent || 21749ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Index->isTypeDependent() || Index->isValueDependent(); 21759ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 21769ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 21779ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 21789ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 21799ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 21809ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 21819ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 21821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ValueDependent = ValueDependent || 21839ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Start->isTypeDependent() || Start->isValueDependent() || 21849ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor End->isTypeDependent() || End->isValueDependent(); 21859ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 21869ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 21879ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 21889ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 21899ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 21909ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 21919ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 21929ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); 2193ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 2194ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 219505c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 21961eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 219705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 219805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 219905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 220005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 2201c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 2202c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff sizeof(Stmt *) * (NumIndexExprs + 1), 8); 22039ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor return new (Mem) DesignatedInitExpr(C.VoidTy, NumDesignators, Designators, 22049ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 22059ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor IndexExprs, NumIndexExprs, Init); 220605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 220705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 22081eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 2209d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 2210d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 2211d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 2212d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 2213d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 2214d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 22151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DesignatedInitExpr::setDesignators(const Designator *Desigs, 2216d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 2217d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor if (Designators) 2218d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor delete [] Designators; 2219d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 2220d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators = new Designator[NumDesigs]; 2221d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 2222d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 2223d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 2224d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 2225d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 222605c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const { 222705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 2228d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 2229d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 223005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 2231eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 223205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 223305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 223405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 223505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 2236d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 2237d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 223805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); 223905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 224005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 224105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) { 224205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 224305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 224405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 224505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 224605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 224705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 224805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 224905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { 22501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 225105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 225205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 225305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 225405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 225505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 225605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 225705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 225805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { 22591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(D.Kind == Designator::ArrayRangeDesignator && 226005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 226105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 226205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 226305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 226405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 226505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 226605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 2267ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 2268ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 22691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DesignatedInitExpr::ExpandDesignator(unsigned Idx, 22701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Designator *First, 2271ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 2272ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 2273ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 2274ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 2275ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 2276ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 2277ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 2278ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 2279ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 2280ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 2281ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 2282ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 2283ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 22841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator *NewDesignators 2285ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor = new Designator[NumDesignators - 1 + NumNewDesignators]; 2286ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 2287ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 2288ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 2289ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 2290ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor delete [] Designators; 2291ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 2292ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 2293ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 2294ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 229542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid DesignatedInitExpr::DoDestroy(ASTContext &C) { 2296ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor delete [] Designators; 229742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor Expr::DoDestroy(C); 2298ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 2299ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 23001eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 23012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Expr **exprs, unsigned nexprs, 23022ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation rparenloc) 23032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman: Expr(ParenListExprClass, QualType(), 23042ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman hasAnyTypeDependentArguments(exprs, nexprs), 23051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump hasAnyValueDependentArguments(exprs, nexprs)), 23062ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { 23071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs = new (C) Stmt*[nexprs]; 23092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman for (unsigned i = 0; i != nexprs; ++i) 23102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 23112ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 23122ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 23132ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanvoid ParenListExpr::DoDestroy(ASTContext& C) { 23142ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman DestroyChildren(C); 23152ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman if (Exprs) C.Deallocate(Exprs); 23162ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman this->~ParenListExpr(); 23172ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman C.Deallocate(this); 23182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 23192ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 232005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 2321ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 2322ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 2323ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 2324ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 2325ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 2326ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 2327ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 2328ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 2329ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 2330ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 2331ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 2332ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 2333ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 233477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 233577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 233677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 233777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// DeclRefExpr 23389ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); } 23399ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); } 234077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 23417779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff// ObjCIvarRefExpr 23425549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; } 23435549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; } 23447779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff 2345e3e9add4fd788927df6f545570e7838db59c01d7Steve Naroff// ObjCPropertyRefExpr 23465549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; } 23475549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; } 2348ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff 234909105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian// ObjCImplicitSetterGetterRefExpr 23501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_begin() { 23511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return &Base; 2352154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian} 23531eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_end() { 23541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return &Base+1; 2355154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian} 23565daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian 2357cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor// ObjCSuperExpr 2358cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); } 2359cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); } 2360cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor 2361f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff// ObjCIsaExpr 2362f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; } 2363f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; } 2364f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 2365d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner// PredefinedExpr 2366d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); } 2367d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); } 236877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 236977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// IntegerLiteral 23709ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); } 23719ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); } 237277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 237377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CharacterLiteral 2374d603eaa682cecac2c10771a700cb83aa301653b4Chris LattnerStmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();} 23759ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); } 237677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 237777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// FloatingLiteral 23789ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); } 23799ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); } 238077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 23815d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner// ImaginaryLiteral 23825549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; } 23835549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; } 23845d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 238577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// StringLiteral 23869ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_begin() { return child_iterator(); } 23879ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_end() { return child_iterator(); } 238877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 238977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ParenExpr 23905549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_begin() { return &Val; } 23915549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_end() { return &Val+1; } 239277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 239377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// UnaryOperator 23945549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_begin() { return &Val; } 23955549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_end() { return &Val+1; } 239677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 23970518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl// SizeOfAlignOfExpr 23981eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator SizeOfAlignOfExpr::child_begin() { 23990518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 24000518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 24010518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 24020518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 24030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (VariableArrayType* T = dyn_cast<VariableArrayType>( 24040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 24050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(T); 24060518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(); 24070518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 2408d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return child_iterator(&Argument.Ex); 24099ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 24100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian RedlStmt::child_iterator SizeOfAlignOfExpr::child_end() { 24110518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) 24120518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(); 2413d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return child_iterator(&Argument.Ex + 1); 24149ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 241577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 241677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ArraySubscriptExpr 24171237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_begin() { 24185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 241977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 24201237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_end() { 24215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 242277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 242377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 242477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CallExpr 24251237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_begin() { 24265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 242777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 24281237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_end() { 24295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+NumArgs+ARGS_START; 243077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 24311237c673c07f9d827129ba02720108816abde562Ted Kremenek 24321237c673c07f9d827129ba02720108816abde562Ted Kremenek// MemberExpr 24335549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_begin() { return &Base; } 24345549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_end() { return &Base+1; } 24351237c673c07f9d827129ba02720108816abde562Ted Kremenek 2436213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman// ExtVectorElementExpr 24375549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; } 24385549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; } 24391237c673c07f9d827129ba02720108816abde562Ted Kremenek 24401237c673c07f9d827129ba02720108816abde562Ted Kremenek// CompoundLiteralExpr 24415549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; } 24425549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; } 24431237c673c07f9d827129ba02720108816abde562Ted Kremenek 24441237c673c07f9d827129ba02720108816abde562Ted Kremenek// CastExpr 24455549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_begin() { return &Op; } 24465549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_end() { return &Op+1; } 24471237c673c07f9d827129ba02720108816abde562Ted Kremenek 24481237c673c07f9d827129ba02720108816abde562Ted Kremenek// BinaryOperator 24491237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_begin() { 24505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 24511237c673c07f9d827129ba02720108816abde562Ted Kremenek} 24521237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_end() { 24535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 24541237c673c07f9d827129ba02720108816abde562Ted Kremenek} 24551237c673c07f9d827129ba02720108816abde562Ted Kremenek 24561237c673c07f9d827129ba02720108816abde562Ted Kremenek// ConditionalOperator 24571237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_begin() { 24585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 24591237c673c07f9d827129ba02720108816abde562Ted Kremenek} 24601237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_end() { 24615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 24621237c673c07f9d827129ba02720108816abde562Ted Kremenek} 24631237c673c07f9d827129ba02720108816abde562Ted Kremenek 24641237c673c07f9d827129ba02720108816abde562Ted Kremenek// AddrLabelExpr 24659ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); } 24669ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); } 24671237c673c07f9d827129ba02720108816abde562Ted Kremenek 24681237c673c07f9d827129ba02720108816abde562Ted Kremenek// StmtExpr 24695549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_begin() { return &SubStmt; } 24705549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; } 24711237c673c07f9d827129ba02720108816abde562Ted Kremenek 24721237c673c07f9d827129ba02720108816abde562Ted Kremenek// TypesCompatibleExpr 24739ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_begin() { 24749ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 24759ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 24769ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek 24779ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_end() { 24789ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 24799ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 24801237c673c07f9d827129ba02720108816abde562Ted Kremenek 24811237c673c07f9d827129ba02720108816abde562Ted Kremenek// ChooseExpr 24825549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; } 24835549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; } 24842d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 24852d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor// GNUNullExpr 24862d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); } 24872d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); } 24881237c673c07f9d827129ba02720108816abde562Ted Kremenek 2489d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman// ShuffleVectorExpr 2490d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_begin() { 24915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 2492d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman} 2493d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_end() { 24945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+NumExprs; 2495d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman} 2496d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 24977c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson// VAArgExpr 24985549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_begin() { return &Val; } 24995549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_end() { return &Val+1; } 25007c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 250166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson// InitListExpr 250266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_begin() { 25035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return InitExprs.size() ? &InitExprs[0] : 0; 250466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 250566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_end() { 25065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0; 250766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 250866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 25093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// DesignatedInitExpr 251005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_begin() { 251105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 251205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 251305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 251405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 251505c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_end() { 251605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return child_iterator(&*child_begin() + NumSubExprs); 251705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 251805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 25193498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// ImplicitValueInitExpr 25201eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_begin() { 25211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return child_iterator(); 25223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor} 25233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 25241eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_end() { 25251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return child_iterator(); 25263498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor} 25273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 25282ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman// ParenListExpr 25292ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_begin() { 25302ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return &Exprs[0]; 25312ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 25322ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_end() { 25332ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return &Exprs[0]+NumExprs; 25342ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 25352ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 25361237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCStringLiteral 25371eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCStringLiteral::child_begin() { 2538c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner return &String; 25399ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 25409ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_end() { 2541c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner return &String+1; 25429ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 25431237c673c07f9d827129ba02720108816abde562Ted Kremenek 25441237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCEncodeExpr 25459ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); } 25469ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); } 25471237c673c07f9d827129ba02720108816abde562Ted Kremenek 2548b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian// ObjCSelectorExpr 25491eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCSelectorExpr::child_begin() { 25509ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 25519ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 25529ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_end() { 25539ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 25549ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 2555b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 2556390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian// ObjCProtocolExpr 25579ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_begin() { 25589ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 25599ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 25609ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_end() { 25619ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 25629ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 2563390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 2564563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 25651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCMessageExpr::child_begin() { 25665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return getReceiver() ? &SubExprs[0] : &SubExprs[0] + ARGS_START; 2567563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2568563477da25f824e37c535131695dc4dc9b68c465Steve NaroffStmt::child_iterator ObjCMessageExpr::child_end() { 25695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+ARGS_START+getNumArgs(); 2570563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2571563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 25724eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks 257356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_begin() { return child_iterator(); } 257456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_end() { return child_iterator(); } 25754eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 25769da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();} 25779da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); } 2578