Expr.cpp revision de4b1d86bf48bc2a84bddf6b188f6da53eaea845
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() &&
101501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor        Var->getType().getCVRQualifiers() == Qualifiers::Const) {
102501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor      const VarDecl *Def = 0;
103501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor      if (const Expr *Init = Var->getDefinition(Def))
104501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor        if (Init->isValueDependent())
105501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor          ValueDependent = true;
106501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor    }
1070da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
1080da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //  (TD)  - a nested-name-specifier or a qualified-id that names a
1090da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //          member of an unknown specialization.
1100da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //        (handled by DependentScopeDeclRefExpr)
1110da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor}
1120da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor
113a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier,
114a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                         SourceRange QualifierRange,
115dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall                         ValueDecl *D, SourceLocation NameLoc,
116d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                         const TemplateArgumentListInfo *TemplateArgs,
1170da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                         QualType T)
1180da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  : Expr(DeclRefExprClass, T, false, false),
119a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    DecoratedD(D,
120a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor               (Qualifier? HasQualifierFlag : 0) |
121d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall               (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)),
122a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    Loc(NameLoc) {
123a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (Qualifier) {
124a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NameQualifier *NQ = getNameQualifier();
125a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NQ->NNS = Qualifier;
126a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NQ->Range = QualifierRange;
127a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
128a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
129d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  if (TemplateArgs)
130d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs);
131a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
1320da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  computeDependence();
133a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}
134a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
135a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
136a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                                 NestedNameSpecifier *Qualifier,
137a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                                 SourceRange QualifierRange,
138dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall                                 ValueDecl *D,
139a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                                 SourceLocation NameLoc,
1400da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                                 QualType T,
1410da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                                 const TemplateArgumentListInfo *TemplateArgs) {
142a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  std::size_t Size = sizeof(DeclRefExpr);
143a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (Qualifier != 0)
144a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    Size += sizeof(NameQualifier);
145a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
146d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  if (TemplateArgs)
147d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
148a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
149a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>());
150a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameLoc,
1510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                               TemplateArgs, T);
152a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}
153a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
154a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorSourceRange DeclRefExpr::getSourceRange() const {
155a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // FIXME: Does not handle multi-token names well, e.g., operator[].
156a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceRange R(Loc);
157a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
158a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (hasQualifier())
159a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    R.setBegin(getQualifierRange().getBegin());
160a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (hasExplicitTemplateArgumentList())
161a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    R.setEnd(getRAngleLoc());
162a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  return R;
163a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}
164a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
1653a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined
1663a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead.
1673a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlssonstd::string PredefinedExpr::ComputeName(ASTContext &Context, IdentType IT,
1683a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson                                        const Decl *CurrentDecl) {
1693a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) {
1703a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    if (IT != PrettyFunction)
1713a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      return FD->getNameAsString();
1723a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
1733a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    llvm::SmallString<256> Name;
1743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    llvm::raw_svector_ostream Out(Name);
1753a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
1763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
1773a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      if (MD->isVirtual())
1783a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        Out << "virtual ";
1794eadcc569223135e13353c9381b448986e3f7053Sam Weinig      if (MD->isStatic())
1804eadcc569223135e13353c9381b448986e3f7053Sam Weinig        Out << "static ";
1813a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    }
1823a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
1833a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    PrintingPolicy Policy(Context.getLangOptions());
1843a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Policy.SuppressTagKind = true;
1853a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
1863a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    std::string Proto = FD->getQualifiedNameAsString(Policy);
1873a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
188183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    const FunctionType *AFT = FD->getType()->getAs<FunctionType>();
1893a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    const FunctionProtoType *FT = 0;
1903a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    if (FD->hasWrittenPrototype())
1913a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      FT = dyn_cast<FunctionProtoType>(AFT);
1923a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
1933a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Proto += "(";
1943a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    if (FT) {
1953a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      llvm::raw_string_ostream POut(Proto);
1963a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) {
1973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        if (i) POut << ", ";
1983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        std::string Param;
1993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy);
2003a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        POut << Param;
2013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      }
2023a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
2033a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      if (FT->isVariadic()) {
2043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        if (FD->getNumParams()) POut << ", ";
2053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        POut << "...";
2063a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      }
2073a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    }
2083a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Proto += ")";
2093a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
2104eadcc569223135e13353c9381b448986e3f7053Sam Weinig    if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
2114eadcc569223135e13353c9381b448986e3f7053Sam Weinig      Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers());
2124eadcc569223135e13353c9381b448986e3f7053Sam Weinig      if (ThisQuals.hasConst())
2134eadcc569223135e13353c9381b448986e3f7053Sam Weinig        Proto += " const";
2144eadcc569223135e13353c9381b448986e3f7053Sam Weinig      if (ThisQuals.hasVolatile())
2154eadcc569223135e13353c9381b448986e3f7053Sam Weinig        Proto += " volatile";
2164eadcc569223135e13353c9381b448986e3f7053Sam Weinig    }
2174eadcc569223135e13353c9381b448986e3f7053Sam Weinig
2183a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig    if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD))
2193a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig      AFT->getResultType().getAsStringInternal(Proto, Policy);
2203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
2213a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out << Proto;
2223a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
2233a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out.flush();
2243a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    return Name.str().str();
2253a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  }
2263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) {
2273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    llvm::SmallString<256> Name;
2283a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    llvm::raw_svector_ostream Out(Name);
2293a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out << (MD->isInstanceMethod() ? '-' : '+');
2303a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out << '[';
2313a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out << MD->getClassInterface()->getNameAsString();
2323a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    if (const ObjCCategoryImplDecl *CID =
2333a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) {
2343a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      Out << '(';
2353a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      Out <<  CID->getNameAsString();
2363a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      Out <<  ')';
2373a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    }
2383a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out <<  ' ';
2393a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out << MD->getSelector().getAsString();
2403a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out <<  ']';
2413a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
2423a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out.flush();
2433a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    return Name.str().str();
2443a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  }
2453a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) {
2463a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string.
2473a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    return "top level";
2483a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  }
2493a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  return "";
2503a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson}
2513a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
252da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate
253da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double.  Note that this may cause loss of precision, but is useful for
254da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc.
255da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const {
256da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  llvm::APFloat V = getValue();
257ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen  bool ignored;
258ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen  V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven,
259ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen            &ignored);
260da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  return V.convertToDouble();
261da8249e57f3badecf925571881fe57243935c6c1Chris Lattner}
262da8249e57f3badecf925571881fe57243935c6c1Chris Lattner
2632085fd6cd22ec5c268175251db10d7c60caf7aaaChris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData,
2642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                                     unsigned ByteLength, bool Wide,
2652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                                     QualType Ty,
2661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                     const SourceLocation *Loc,
267a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                                     unsigned NumStrs) {
2682085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  // Allocate enough space for the StringLiteral plus an array of locations for
2692085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  // any concatenated string tokens.
2702085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  void *Mem = C.Allocate(sizeof(StringLiteral)+
2712085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                         sizeof(SourceLocation)*(NumStrs-1),
2722085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                         llvm::alignof<StringLiteral>());
2732085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  StringLiteral *SL = new (Mem) StringLiteral(Ty);
2741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // OPTIMIZE: could allocate this appended to the StringLiteral.
2762085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  char *AStrData = new (C, 1) char[ByteLength];
2772085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  memcpy(AStrData, StrData, ByteLength);
2782085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->StrData = AStrData;
2792085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->ByteLength = ByteLength;
2802085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->IsWide = Wide;
2812085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->TokLocs[0] = Loc[0];
2822085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->NumConcatenated = NumStrs;
2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
284726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  if (NumStrs != 1)
2852085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1));
2862085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  return SL;
287726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner}
288726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner
289673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) {
290673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void *Mem = C.Allocate(sizeof(StringLiteral)+
291673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor                         sizeof(SourceLocation)*(NumStrs-1),
292673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor                         llvm::alignof<StringLiteral>());
293673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  StringLiteral *SL = new (Mem) StringLiteral(QualType());
294673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  SL->StrData = 0;
295673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  SL->ByteLength = 0;
296673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  SL->NumConcatenated = NumStrs;
297673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  return SL;
298673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor}
299673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
30042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid StringLiteral::DoDestroy(ASTContext &C) {
3018189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  C.Deallocate(const_cast<char*>(StrData));
30242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  Expr::DoDestroy(C);
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
305b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbarvoid StringLiteral::setString(ASTContext &C, llvm::StringRef Str) {
306673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  if (StrData)
307673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    C.Deallocate(const_cast<char*>(StrData));
308673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
309b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  char *AStrData = new (C, 1) char[Str.size()];
310b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  memcpy(AStrData, Str.data(), Str.size());
311673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  StrData = AStrData;
312b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  ByteLength = Str.size();
313673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor}
314673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++".
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) {
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default: assert(0 && "Unknown unary operator");
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostInc: return "++";
3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostDec: return "--";
3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PreInc:  return "++";
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PreDec:  return "--";
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AddrOf:  return "&";
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Deref:   return "*";
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Plus:    return "+";
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Minus:   return "-";
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Not:     return "~";
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LNot:    return "!";
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Real:    return "__real";
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Imag:    return "__imag";
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Extension: return "__extension__";
33373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  case OffsetOf: return "__builtin_offsetof";
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3371eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpUnaryOperator::Opcode
338bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) {
339bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  switch (OO) {
340bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  default: assert(false && "No unary operator for overloaded function");
341b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  case OO_PlusPlus:   return Postfix ? PostInc : PreInc;
342b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  case OO_MinusMinus: return Postfix ? PostDec : PreDec;
343b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  case OO_Amp:        return AddrOf;
344b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  case OO_Star:       return Deref;
345b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  case OO_Plus:       return Plus;
346b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  case OO_Minus:      return Minus;
347b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  case OO_Tilde:      return Not;
348b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  case OO_Exclaim:    return LNot;
349bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  }
350bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor}
351bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
352bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) {
353bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  switch (Opc) {
354bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  case PostInc: case PreInc: return OO_PlusPlus;
355bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  case PostDec: case PreDec: return OO_MinusMinus;
356bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  case AddrOf: return OO_Amp;
357bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  case Deref: return OO_Star;
358bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  case Plus: return OO_Plus;
359bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  case Minus: return OO_Minus;
360bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  case Not: return OO_Tilde;
361bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  case LNot: return OO_Exclaim;
362bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  default: return OO_None;
363bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  }
364bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor}
365bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
366bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
371668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args,
3728189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek                   unsigned numargs, QualType t, SourceLocation rparenloc)
3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Expr(SC, t,
374898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs),
375d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner         fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)),
376898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    NumArgs(numargs) {
3771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
378668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  SubExprs = new (C) Stmt*[numargs+1];
379b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  SubExprs[FN] = fn;
380b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  for (unsigned i = 0; i != numargs; ++i)
381b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    SubExprs[i+ARGS_START] = args[i];
382668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
383b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  RParenLoc = rparenloc;
384b4609806e9232593ece09ce08b630836e825865cDouglas Gregor}
385e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman
386668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs,
387668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek                   QualType t, SourceLocation rparenloc)
388898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  : Expr(CallExprClass, t,
389898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs),
390d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner         fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)),
391898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    NumArgs(numargs) {
392668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
393668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  SubExprs = new (C) Stmt*[numargs+1];
39477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  SubExprs[FN] = fn;
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  for (unsigned i = 0; i != numargs; ++i)
39677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    SubExprs[i+ARGS_START] = args[i];
397668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RParenLoc = rparenloc;
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4011eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty)
4021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Expr(SC, Empty), SubExprs(0), NumArgs(0) {
4031f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  SubExprs = new (C) Stmt*[1];
4041f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor}
4051f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
40642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid CallExpr::DoDestroy(ASTContext& C) {
407668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  DestroyChildren(C);
408668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  if (SubExprs) C.Deallocate(SubExprs);
409668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  this->~CallExpr();
410668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  C.Deallocate(this);
411668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek}
412668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
413d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() {
414a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  Expr *CEE = getCallee()->IgnoreParenCasts();
4156346f963145ed18b6edf50a78753b47db505e912Chris Lattner  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
416d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return DRE->getDecl();
417cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes  if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
418cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes    return ME->getMemberDecl();
419a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
420a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  return 0;
421a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu}
422a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
423d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() {
424caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner  return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
425d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes}
426d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes
427d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call.
428d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set
429d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null.
4308189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) {
431d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // No change, just return.
432d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs == getNumArgs()) return;
4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
434d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // If shrinking # arguments, just delete the extras and forgot them.
435d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs < getNumArgs()) {
436d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i)
4378189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek      getArg(i)->Destroy(C);
438d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    this->NumArgs = NumArgs;
439d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    return;
440d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  }
441d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
442d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Otherwise, we are growing the # arguments.  New an bigger argument array.
44368a049cab6015a7437bec5661601b7d37d23c70cDaniel Dunbar  Stmt **NewSubExprs = new (C) Stmt*[NumArgs+1];
444d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Copy over args.
445d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i)
446d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = SubExprs[i];
447d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Null out new args.
448d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
449d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = 0;
4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45188c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor  if (SubExprs) C.Deallocate(SubExprs);
452d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SubExprs = NewSubExprs;
453d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  this->NumArgs = NumArgs;
454d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner}
455d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
456cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
457cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0.
4583c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregorunsigned CallExpr::isBuiltinCall(ASTContext &Context) const {
459c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // All simple function calls (e.g. func()) are implicitly cast to pointer to
4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // function. As a result, we try and obtain the DeclRefExpr from the
461c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // ImplicitCastExpr.
462c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
463c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
464cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
466c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
467c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!DRE)
468cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
470bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
471bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  if (!FDecl)
472cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
4731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4744fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor  if (!FDecl->getIdentifier())
4754fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor    return 0;
4764fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor
4777814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor  return FDecl->getBuiltinID();
478cb888967400a03504c88acedd5248d6778a82f46Chris Lattner}
479bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson
4806dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const {
4816dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  QualType CalleeType = getCallee()->getType();
4826217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>())
4836dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson    CalleeType = FnTypePtr->getPointeeType();
4846217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>())
4856dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson    CalleeType = BPT->getPointeeType();
4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
487183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  const FunctionType *FnType = CalleeType->getAs<FunctionType>();
4886dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  return FnType->getResultType();
4896dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson}
490cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
4911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr::MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual,
492f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman                       SourceRange qualrange, ValueDecl *memberdecl,
493d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                       SourceLocation l, const TemplateArgumentListInfo *targs,
494d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                       QualType ty)
4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Expr(MemberExprClass, ty,
49683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor         base->isTypeDependent() || (qual && qual->isDependent()),
49783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor         base->isValueDependent() || (qual && qual->isDependent())),
49883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow),
499d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    HasQualifier(qual != 0), HasExplicitTemplateArgumentList(targs) {
50083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  // Initialize the qualifier, if any.
50183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (HasQualifier) {
50283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    NameQualifier *NQ = getMemberQualifier();
50383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    NQ->NNS = qual;
50483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    NQ->Range = qualrange;
50583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
507c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  // Initialize the explicit template argument list, if any.
508d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  if (targs)
509d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    getExplicitTemplateArgumentList()->initializeFrom(*targs);
51083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor}
51183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
5121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow,
5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               NestedNameSpecifier *qual,
51483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                               SourceRange qualrange,
515f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman                               ValueDecl *memberdecl,
5161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               SourceLocation l,
517d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                               const TemplateArgumentListInfo *targs,
518c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                               QualType ty) {
51983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  std::size_t Size = sizeof(MemberExpr);
52083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  if (qual != 0)
52183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    Size += sizeof(NameQualifier);
5221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
523d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  if (targs)
524d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    Size += ExplicitTemplateArgumentList::sizeFor(*targs);
5251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  void *Mem = C.Allocate(Size, llvm::alignof<MemberExpr>());
527c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  return new (Mem) MemberExpr(base, isarrow, qual, qualrange, memberdecl, l,
528d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                              targs, ty);
52983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor}
53083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
531f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const {
532f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  switch (getCastKind()) {
533f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_Unknown:
534f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "Unknown";
535f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_BitCast:
536f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "BitCast";
537f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_NoOp:
538f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "NoOp";
53911de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson  case CastExpr::CK_BaseToDerived:
54011de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson    return "BaseToDerived";
541f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_DerivedToBase:
542f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "DerivedToBase";
543f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_Dynamic:
544f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "Dynamic";
545f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_ToUnion:
546f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "ToUnion";
547f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_ArrayToPointerDecay:
548f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "ArrayToPointerDecay";
549f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_FunctionToPointerDecay:
550f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "FunctionToPointerDecay";
551f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_NullToMemberPointer:
552f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "NullToMemberPointer";
553f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_BaseToDerivedMemberPointer:
554f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "BaseToDerivedMemberPointer";
5551a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson  case CastExpr::CK_DerivedToBaseMemberPointer:
5561a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    return "DerivedToBaseMemberPointer";
557f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_UserDefinedConversion:
558f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "UserDefinedConversion";
559f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  case CastExpr::CK_ConstructorConversion:
560f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "ConstructorConversion";
5617f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson  case CastExpr::CK_IntegralToPointer:
5627f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    return "IntegralToPointer";
5637f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson  case CastExpr::CK_PointerToIntegral:
5647f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    return "PointerToIntegral";
565ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson  case CastExpr::CK_ToVoid:
566ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson    return "ToVoid";
56716a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson  case CastExpr::CK_VectorSplat:
56816a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson    return "VectorSplat";
56982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson  case CastExpr::CK_IntegralCast:
57082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    return "IntegralCast";
57182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson  case CastExpr::CK_IntegralToFloating:
57282debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    return "IntegralToFloating";
57382debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson  case CastExpr::CK_FloatingToIntegral:
57482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    return "FloatingToIntegral";
575c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer  case CastExpr::CK_FloatingCast:
576c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer    return "FloatingCast";
577bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson  case CastExpr::CK_MemberPointerToBoolean:
578bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson    return "MemberPointerToBoolean";
5794cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian  case CastExpr::CK_AnyPointerToObjCPointerCast:
5804cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian    return "AnyPointerToObjCPointerCast";
5813b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian  case CastExpr::CK_AnyPointerToBlockPointerCast:
5823b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    return "AnyPointerToBlockPointerCast";
583f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  }
5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
585f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  assert(0 && "Unhandled cast kind!");
586f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  return 0;
587f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson}
588f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
5896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() {
5906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  Expr *SubExpr = 0;
5916eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  CastExpr *E = this;
5926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  do {
5936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    SubExpr = E->getSubExpr();
5946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
5956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // Skip any temporary bindings; they're implicit.
5966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr))
5976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      SubExpr = Binder->getSubExpr();
5986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
5996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // Conversions by constructor and conversion functions have a
6006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // subexpression describing the call; strip it off.
6016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    if (E->getCastKind() == CastExpr::CK_ConstructorConversion)
6026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0);
6036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    else if (E->getCastKind() == CastExpr::CK_UserDefinedConversion)
6046eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument();
6056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
6066eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // If the subexpression we're left with is an implicit cast, look
6076eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // through that, too.
6086eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr)));
6096eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
6106eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return SubExpr;
6116eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor}
6126eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=".
6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) {
6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
617baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor  case PtrMemD:   return ".*";
618baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor  case PtrMemI:   return "->*";
6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Mul:       return "*";
6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Div:       return "/";
6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Rem:       return "%";
6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Add:       return "+";
6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Sub:       return "-";
6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Shl:       return "<<";
6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Shr:       return ">>";
6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LT:        return "<";
6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case GT:        return ">";
6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LE:        return "<=";
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case GE:        return ">=";
6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case EQ:        return "==";
6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case NE:        return "!=";
6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case And:       return "&";
6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Xor:       return "^";
6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Or:        return "|";
6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LAnd:      return "&&";
6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LOr:       return "||";
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Assign:    return "=";
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case MulAssign: return "*=";
6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DivAssign: return "/=";
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case RemAssign: return "%=";
6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AddAssign: return "+=";
6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case SubAssign: return "-=";
6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ShlAssign: return "<<=";
6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ShrAssign: return ">>=";
6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AndAssign: return "&=";
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case XorAssign: return "^=";
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case OrAssign:  return "|=";
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Comma:     return ",";
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
650baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor
651baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor  return "";
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6541eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpBinaryOperator::Opcode
655063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) {
656063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  switch (OO) {
657b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  default: assert(false && "Not an overloadable binary operator");
658063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Plus: return Add;
659063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Minus: return Sub;
660063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Star: return Mul;
661063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Slash: return Div;
662063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Percent: return Rem;
663063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Caret: return Xor;
664063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Amp: return And;
665063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Pipe: return Or;
666063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Equal: return Assign;
667063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Less: return LT;
668063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Greater: return GT;
669063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_PlusEqual: return AddAssign;
670063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_MinusEqual: return SubAssign;
671063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_StarEqual: return MulAssign;
672063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_SlashEqual: return DivAssign;
673063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_PercentEqual: return RemAssign;
674063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_CaretEqual: return XorAssign;
675063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_AmpEqual: return AndAssign;
676063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_PipeEqual: return OrAssign;
677063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_LessLess: return Shl;
678063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_GreaterGreater: return Shr;
679063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_LessLessEqual: return ShlAssign;
680063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_GreaterGreaterEqual: return ShrAssign;
681063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_EqualEqual: return EQ;
682063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_ExclaimEqual: return NE;
683063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_LessEqual: return LE;
684063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_GreaterEqual: return GE;
685063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_AmpAmp: return LAnd;
686063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_PipePipe: return LOr;
687063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_Comma: return Comma;
688063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  case OO_ArrowStar: return PtrMemI;
689063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  }
690063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor}
691063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
692063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) {
693063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static const OverloadedOperatorKind OverOps[] = {
694063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    /* .* Cannot be overloaded */OO_None, OO_ArrowStar,
695063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Star, OO_Slash, OO_Percent,
696063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Plus, OO_Minus,
697063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_LessLess, OO_GreaterGreater,
698063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual,
699063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_EqualEqual, OO_ExclaimEqual,
700063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Amp,
701063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Caret,
702063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Pipe,
703063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_AmpAmp,
704063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_PipePipe,
705063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Equal, OO_StarEqual,
706063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_SlashEqual, OO_PercentEqual,
707063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_PlusEqual, OO_MinusEqual,
708063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_LessLessEqual, OO_GreaterGreaterEqual,
709063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_AmpEqual, OO_CaretEqual,
710063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_PipeEqual,
711063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Comma
712063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  };
713063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return OverOps[Opc];
714063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor}
715063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
7161eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpInitListExpr::InitListExpr(SourceLocation lbraceloc,
717418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner                           Expr **initExprs, unsigned numInits,
7184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor                           SourceLocation rbraceloc)
71973460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor  : Expr(InitListExprClass, QualType(), false, false),
7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0),
72173460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor    UnionFieldInit(0), HadArrayRangeDesignator(false)
72273460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor{
72373460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor  for (unsigned I = 0; I != numInits; ++I) {
72473460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor    if (initExprs[I]->isTypeDependent())
72573460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor      TypeDependent = true;
72673460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor    if (initExprs[I]->isValueDependent())
72773460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor      ValueDependent = true;
72873460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor  }
72973460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor
730418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner  InitExprs.insert(InitExprs.end(), initExprs, initExprs+numInits);
73166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
733fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregorvoid InitListExpr::reserveInits(unsigned NumInits) {
734fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  if (NumInits > InitExprs.size())
735fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor    InitExprs.reserve(NumInits);
736fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor}
737fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor
7384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorvoid InitListExpr::resizeInits(ASTContext &Context, unsigned NumInits) {
739d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner  for (unsigned Idx = NumInits, LastIdx = InitExprs.size();
740f592c929bd1f083abcc8199b24bb825fdd28df1cDaniel Dunbar       Idx < LastIdx; ++Idx)
741068636800594844c53fba0bc871c579745757d0eDouglas Gregor    InitExprs[Idx]->Destroy(Context);
7424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitExprs.resize(NumInits, 0);
7434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor}
7444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
7454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas GregorExpr *InitListExpr::updateInit(unsigned Init, Expr *expr) {
7464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  if (Init >= InitExprs.size()) {
7474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    InitExprs.insert(InitExprs.end(), Init - InitExprs.size() + 1, 0);
7484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    InitExprs.back() = expr;
7494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return 0;
7504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *Result = cast_or_null<Expr>(InitExprs[Init]);
7534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitExprs[Init] = expr;
7544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  return Result;
7554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor}
7564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
757bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block.
7584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff///
7594eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const {
7606217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  return getType()->getAs<BlockPointerType>()->
761183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall                    getPointeeType()->getAs<FunctionType>();
7624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}
7634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
7641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const {
7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return TheBlock->getCaretLocation();
76656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff}
7671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const {
7687297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  return TheBlock->getBody();
7697297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor}
7701eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() {
7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return TheBlock->getBody();
7727297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor}
77356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
77456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
779026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should
780026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused.  If so, fill in Loc and Ranges
781026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the
782026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning.
783026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattnerbool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
784df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump                                  SourceRange &R2, ASTContext &Ctx) const {
785ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson  // Don't warn if the expr is type dependent. The type could end up
786ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson  // instantiating to void.
787ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson  if (isTypeDependent())
788ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson    return false;
7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
792026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = getExprLoc();
793026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = getSourceRange();
794026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass:
796026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return cast<ParenExpr>(this)->getSubExpr()->
797df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      isUnusedResultAWarning(Loc, R1, R2, Ctx);
7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UnaryOperatorClass: {
7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const UnaryOperator *UO = cast<UnaryOperator>(this);
8001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (UO->getOpcode()) {
802026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    default: break;
8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PostInc:
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PostDec:
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PreInc:
806026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    case UnaryOperator::PreDec:                 // ++/--
807026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;  // Not a warning.
8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Deref:
8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // Dereferencing a volatile pointer is a side-effect.
810df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      if (Ctx.getCanonicalType(getType()).isVolatileQualified())
811026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner        return false;
812026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      break;
8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Real:
8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Imag:
8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // accessing a piece of a volatile complex is a side-effect.
816df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      if (Ctx.getCanonicalType(UO->getSubExpr()->getType())
817df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump          .isVolatileQualified())
818026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner        return false;
819026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      break;
8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Extension:
821df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
823026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = UO->getOperatorLoc();
824026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = UO->getSubExpr()->getSourceRange();
825026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
827e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  case BinaryOperatorClass: {
828026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    const BinaryOperator *BO = cast<BinaryOperator>(this);
829026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // Consider comma to have side effects if the LHS or RHS does.
830026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (BO->getOpcode() == BinaryOperator::Comma)
831df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      return (BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) ||
832df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump              BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
8331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
834026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (BO->isAssignmentOp())
835026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;
836026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = BO->getOperatorLoc();
837026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = BO->getLHS()->getSourceRange();
838026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R2 = BO->getRHS()->getSourceRange();
839026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
840e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  }
841eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner  case CompoundAssignOperatorClass:
842026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
844ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  case ConditionalOperatorClass: {
845026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // The condition must be evaluated, but if either the LHS or RHS is a
846026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // warning, warn about them.
847ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
8481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (Exp->getLHS() &&
849df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump        Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx))
850026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return true;
851df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
852ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  }
853ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian
8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case MemberExprClass:
855026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // If the base pointer or element is to a volatile pointer/field, accessing
856026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // it is a side effect.
857df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    if (Ctx.getCanonicalType(getType()).isVolatileQualified())
858026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;
859026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<MemberExpr>(this)->getMemberLoc();
860026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = SourceRange(Loc, Loc);
861026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R2 = cast<MemberExpr>(this)->getBase()->getSourceRange();
862026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
8631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ArraySubscriptExprClass:
8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // If the base pointer or element is to a volatile pointer/field, accessing
866026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // it is a side effect.
867df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    if (Ctx.getCanonicalType(getType()).isVolatileQualified())
868026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;
869026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc();
870026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange();
871026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange();
872026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
873211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case CallExprClass:
875852871abbff45f1c1d3787755a27fce08365b166Eli Friedman  case CXXOperatorCallExprClass:
876852871abbff45f1c1d3787755a27fce08365b166Eli Friedman  case CXXMemberCallExprClass: {
877026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // If this is a direct call, get the callee.
878026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    const CallExpr *CE = cast<CallExpr>(this);
879d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    if (const Decl *FD = CE->getCalleeDecl()) {
880026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      // If the callee has attribute pure, const, or warn_unused_result, warn
881026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      // about it. void foo() { strlen("bar"); } should warn.
882bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      //
883bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      // Note: If new cases are added here, DiagnoseUnusedExprResult should be
884bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      // updated to match for QoI.
885bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      if (FD->getAttr<WarnUnusedResultAttr>() ||
886bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner          FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) {
887bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        Loc = CE->getCallee()->getLocStart();
888bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        R1 = CE->getCallee()->getSourceRange();
889bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner
890bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        if (unsigned NumArgs = CE->getNumArgs())
891bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner          R2 = SourceRange(CE->getArg(0)->getLocStart(),
892bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner                           CE->getArg(NumArgs-1)->getLocEnd());
893bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        return true;
894bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      }
895026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    }
896026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
897026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  }
89858beed91d468863b8c85bce43425422703838d27Anders Carlsson
89958beed91d468863b8c85bce43425422703838d27Anders Carlsson  case CXXTemporaryObjectExprClass:
90058beed91d468863b8c85bce43425422703838d27Anders Carlsson  case CXXConstructExprClass:
90158beed91d468863b8c85bce43425422703838d27Anders Carlsson    return false;
90258beed91d468863b8c85bce43425422703838d27Anders Carlsson
903a9c01021724b9b546d282b8609cbe559734812ecChris Lattner  case ObjCMessageExprClass:
904026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
9051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
90609105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian  case ObjCImplicitSetterGetterRefExprClass: {   // Dot syntax for message send.
907a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#if 0
9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const ObjCImplicitSetterGetterRefExpr *Ref =
90909105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian      cast<ObjCImplicitSetterGetterRefExpr>(this);
910a50089ec68a583d13718107c1b0c898f0903709eChris Lattner    // FIXME: We really want the location of the '.' here.
911154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian    Loc = Ref->getLocation();
912154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian    R1 = SourceRange(Ref->getLocation(), Ref->getLocation());
913154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian    if (Ref->getBase())
914154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian      R2 = Ref->getBase()->getSourceRange();
9155e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner#else
9165e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner    Loc = getExprLoc();
9175e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner    R1 = getSourceRange();
918a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#endif
919a50089ec68a583d13718107c1b0c898f0903709eChris Lattner    return true;
920a50089ec68a583d13718107c1b0c898f0903709eChris Lattner  }
921611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner  case StmtExprClass: {
922611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // Statement exprs don't logically have side effects themselves, but are
923611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // sometimes used in macros in ways that give them a type that is unused.
924611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // For example ({ blah; foo(); }) will end up with a type if foo has a type.
925611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // however, if the result of the stmt expr is dead, we don't want to emit a
926611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // warning.
927611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
928611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    if (!CS->body_empty())
929611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner      if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
930df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump        return E->isUnusedResultAWarning(Loc, R1, R2, Ctx);
9311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
932026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<StmtExpr>(this)->getLParenLoc();
933026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = getSourceRange();
934026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
935611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner  }
9366eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  case CStyleCastExprClass:
937fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner    // If this is an explicit cast to void, allow it.  People do this when they
938fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner    // think they know what they're doing :).
939026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (getType()->isVoidType())
940fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner      return false;
941026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<CStyleCastExpr>(this)->getLParenLoc();
942026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange();
943026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
94458beed91d468863b8c85bce43425422703838d27Anders Carlsson  case CXXFunctionalCastExprClass: {
94558beed91d468863b8c85bce43425422703838d27Anders Carlsson    const CastExpr *CE = cast<CastExpr>(this);
94658beed91d468863b8c85bce43425422703838d27Anders Carlsson
94758beed91d468863b8c85bce43425422703838d27Anders Carlsson    // If this is a cast to void or a constructor conversion, check the operand.
94858beed91d468863b8c85bce43425422703838d27Anders Carlsson    // Otherwise, the result of the cast is unused.
94958beed91d468863b8c85bce43425422703838d27Anders Carlsson    if (CE->getCastKind() == CastExpr::CK_ToVoid ||
95058beed91d468863b8c85bce43425422703838d27Anders Carlsson        CE->getCastKind() == CastExpr::CK_ConstructorConversion)
951df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      return (cast<CastExpr>(this)->getSubExpr()
952df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump              ->isUnusedResultAWarning(Loc, R1, R2, Ctx));
953026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc();
954026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange();
955026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
95658beed91d468863b8c85bce43425422703838d27Anders Carlsson  }
9571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9584be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman  case ImplicitCastExprClass:
9594be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman    // Check the operand, since implicit casts are inserted by Sema
960df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<ImplicitCastExpr>(this)
961df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
9624be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman
96304421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
964df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<CXXDefaultArgExpr>(this)
965df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
9664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  case CXXNewExprClass:
9684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    // FIXME: In theory, there might be new expressions that don't have side
9694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    // effects (e.g. a placement new with an uninitialized POD).
9704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  case CXXDeleteExprClass:
971026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
9722d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson  case CXXBindTemporaryExprClass:
973df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<CXXBindTemporaryExpr>(this)
974df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
9756b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson  case CXXExprWithTemporariesClass:
976df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<CXXExprWithTemporaries>(this)
977df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
9784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
981ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor/// DeclCanBeLvalue - Determine whether the given declaration can be
982ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor/// an lvalue. This is a helper routine for isLvalue.
983ba7e210a999275695f58be03ef402758cfec3635Douglas Gregorstatic bool DeclCanBeLvalue(const NamedDecl *Decl, ASTContext &Ctx) {
98472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  // C++ [temp.param]p6:
98572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  //   A non-type non-reference template-parameter is not an lvalue.
9861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  if (const NonTypeTemplateParmDecl *NTTParm
98772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor        = dyn_cast<NonTypeTemplateParmDecl>(Decl))
98872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor    return NTTParm->getType()->isReferenceType();
98972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
99044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  return isa<VarDecl>(Decl) || isa<FieldDecl>(Decl) ||
991ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor    // C++ 3.10p2: An lvalue refers to an object or function.
992ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor    (Ctx.getLangOptions().CPlusPlus &&
99351fa86f738a9768fac4e1cad7bdde53774b5b322John McCall     (isa<FunctionDecl>(Decl) || isa<FunctionTemplateDecl>(Decl)));
994ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor}
995ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor
9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// incomplete type other than void. Nonarray expressions that can be lvalues:
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - name, where name must be a variable
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - e[i]
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - (e), where e must be an lvalue
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - e.name, where e must be an lvalue
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - e->name
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - *e, the type of e cannot be a function type
10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - string-constant
10057da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner///  - (__real__ e) and (__imag__ e) where e is an lvalue  [GNU extension]
100608ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling///  - reference type [C++ [expr]]
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
100828be73f74c9e241a23ea24fe5756623de6bf1084Chris LattnerExpr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const {
100953202857c60214d80950a975e6e52aebf30bd16aEli Friedman  assert(!TR->isReferenceType() && "Expressions can't have reference type.");
101053202857c60214d80950a975e6e52aebf30bd16aEli Friedman
101153202857c60214d80950a975e6e52aebf30bd16aEli Friedman  isLvalueResult Res = isLvalueInternal(Ctx);
101253202857c60214d80950a975e6e52aebf30bd16aEli Friedman  if (Res != LV_Valid || Ctx.getLangOptions().CPlusPlus)
101353202857c60214d80950a975e6e52aebf30bd16aEli Friedman    return Res;
101453202857c60214d80950a975e6e52aebf30bd16aEli Friedman
101598cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor  // first, check the type (C99 6.3.2.1). Expressions with function
101698cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor  // type in C are not lvalues, but they can be lvalues in C++.
101783314aa1cf61ed2458a8a20c83b2d4708192d5dcDouglas Gregor  if (TR->isFunctionType() || TR == Ctx.OverloadTy)
10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return LV_NotObjectType;
10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1020acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff  // Allow qualified void which is an incomplete type other than void (yuck).
10210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (TR->isVoidType() && !Ctx.getCanonicalType(TR).hasQualifiers())
1022acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff    return LV_IncompleteVoidType;
1023acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff
102453202857c60214d80950a975e6e52aebf30bd16aEli Friedman  return LV_Valid;
102553202857c60214d80950a975e6e52aebf30bd16aEli Friedman}
102608ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling
102753202857c60214d80950a975e6e52aebf30bd16aEli Friedman// Check whether the expression can be sanely treated like an l-value
102853202857c60214d80950a975e6e52aebf30bd16aEli FriedmanExpr::isLvalueResult Expr::isLvalueInternal(ASTContext &Ctx) const {
10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
1030820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian  case ObjCIsaExprClass:
1031eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  case StringLiteralClass:  // C99 6.5.1p4
1032eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  case ObjCEncodeExprClass: // @encode behaves like its string in every way.
10337323a6297edad643c202594dcf3d9a174de96ca6Anders Carlsson    return LV_Valid;
10345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2))))
10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // For vectors, make sure base is an lvalue (i.e. not a function call).
10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType())
103728be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner      return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(Ctx);
10385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return LV_Valid;
1039a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  case DeclRefExprClass: { // C99 6.5.1p2
1040ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor    const NamedDecl *RefdDecl = cast<DeclRefExpr>(this)->getDecl();
1041ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor    if (DeclCanBeLvalue(RefdDecl, Ctx))
10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return LV_Valid;
10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
10444111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  }
1045dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff  case BlockDeclRefExprClass: {
1046dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff    const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
10474f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    if (isa<VarDecl>(BDR->getDecl()))
1048dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff      return LV_Valid;
1049dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff    break;
1050dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff  }
105183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  case MemberExprClass: {
10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const MemberExpr *m = cast<MemberExpr>(this);
105386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    if (Ctx.getLangOptions().CPlusPlus) { // C++ [expr.ref]p4:
105486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      NamedDecl *Member = m->getMemberDecl();
105586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      // C++ [expr.ref]p4:
105686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //   If E2 is declared to have type "reference to T", then E1.E2
105786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //   is an lvalue.
105886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      if (ValueDecl *Value = dyn_cast<ValueDecl>(Member))
105986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor        if (Value->getType()->isReferenceType())
106086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor          return LV_Valid;
106186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor
106286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //   -- If E2 is a static data member [...] then E1.E2 is an lvalue.
10632d2e9cfdc1dbb6e4a22f8c0b1abcd30437e3795dDouglas Gregor      if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord())
106486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor        return LV_Valid;
106586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor
106686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //   -- If E2 is a non-static data member [...]. If E1 is an
106786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //      lvalue, then E1.E2 is an lvalue.
10682514a309204341798f96912ce7a90841bea59727Fariborz Jahanian      if (isa<FieldDecl>(Member)) {
10692514a309204341798f96912ce7a90841bea59727Fariborz Jahanian        if (m->isArrow())
10702514a309204341798f96912ce7a90841bea59727Fariborz Jahanian          return LV_Valid;
10712514a309204341798f96912ce7a90841bea59727Fariborz Jahanian        Expr *BaseExp = m->getBase();
10722514a309204341798f96912ce7a90841bea59727Fariborz Jahanian        return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ?
10732514a309204341798f96912ce7a90841bea59727Fariborz Jahanian                 LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx);
10742514a309204341798f96912ce7a90841bea59727Fariborz Jahanian      }
107586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor
107686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //   -- If it refers to a static member function [...], then
107786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //      E1.E2 is an lvalue.
107886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //   -- Otherwise, if E1.E2 refers to a non-static member
107986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //      function [...], then E1.E2 is not an lvalue.
108086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member))
108186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor        return Method->isStatic()? LV_Valid : LV_MemberFunction;
108286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor
108386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //   -- If E2 is a member enumerator [...], the expression E1.E2
108486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      //      is not an lvalue.
108586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      if (isa<EnumConstantDecl>(Member))
108686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor        return LV_InvalidExpression;
108786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor
108886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor        // Not an lvalue.
108986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor      return LV_InvalidExpression;
10901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
10912514a309204341798f96912ce7a90841bea59727Fariborz Jahanian
109286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    // C99 6.5.2.3p4
10932514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    if (m->isArrow())
10942514a309204341798f96912ce7a90841bea59727Fariborz Jahanian      return LV_Valid;
10952514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    Expr *BaseExp = m->getBase();
10962514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    return (BaseExp->getStmtClass() == ObjCPropertyRefExprClass) ?
10972514a309204341798f96912ce7a90841bea59727Fariborz Jahanian             LV_SubObjCPropertySetting : BaseExp->isLvalue(Ctx);
1098fdd75663fffeb2058a7847975e50837e61200593Anton Korobeynikov  }
10997da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner  case UnaryOperatorClass:
11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
11017da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner      return LV_Valid; // C99 6.5.3p4
11027da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner
11037da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner    if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
1104baf0d6678418e0dd9309438c3e50274253cfc7b2Chris Lattner        cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag ||
1105baf0d6678418e0dd9309438c3e50274253cfc7b2Chris Lattner        cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension)
110628be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner      return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(Ctx);  // GNU.
110774253736184c0717a0649922551bf9d8b6815651Douglas Gregor
110874253736184c0717a0649922551bf9d8b6815651Douglas Gregor    if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.pre.incr]p1
110974253736184c0717a0649922551bf9d8b6815651Douglas Gregor        (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreInc ||
111074253736184c0717a0649922551bf9d8b6815651Douglas Gregor         cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreDec))
111174253736184c0717a0649922551bf9d8b6815651Douglas Gregor      return LV_Valid;
11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
1113eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  case ImplicitCastExprClass:
11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return cast<ImplicitCastExpr>(this)->isLvalueCast()? LV_Valid
1115eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor                                                       : LV_InvalidExpression;
11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass: // C99 6.5.1p5
111728be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner    return cast<ParenExpr>(this)->getSubExpr()->isLvalue(Ctx);
1118eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  case BinaryOperatorClass:
1119eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  case CompoundAssignOperatorClass: {
1120eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor    const BinaryOperator *BinOp = cast<BinaryOperator>(this);
1121337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor
1122337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor    if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.comma]p1
1123337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor        BinOp->getOpcode() == BinaryOperator::Comma)
1124337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor      return BinOp->getRHS()->isLvalue(Ctx);
1125337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor
1126224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl    // C++ [expr.mptr.oper]p6
112727d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian    // The result of a .* expression is an lvalue only if its first operand is
112827d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian    // an lvalue and its second operand is a pointer to data member.
112927d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian    if (BinOp->getOpcode() == BinaryOperator::PtrMemD &&
1130224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl        !BinOp->getType()->isFunctionType())
1131224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl      return BinOp->getLHS()->isLvalue(Ctx);
1132224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl
113327d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian    // The result of an ->* expression is an lvalue only if its second operand
113427d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian    // is a pointer to data member.
113527d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian    if (BinOp->getOpcode() == BinaryOperator::PtrMemI &&
113627d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian        !BinOp->getType()->isFunctionType()) {
113727d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian      QualType Ty = BinOp->getRHS()->getType();
113827d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian      if (Ty->isMemberPointerType() && !Ty->isMemberFunctionPointerType())
113927d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian        return LV_Valid;
114027d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian    }
114127d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian
1142bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor    if (!BinOp->isAssignmentOp())
1143eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor      return LV_InvalidExpression;
1144eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
1145bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor    if (Ctx.getLangOptions().CPlusPlus)
11461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      // C++ [expr.ass]p1:
1147bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor      //   The result of an assignment operation [...] is an lvalue.
1148bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor      return LV_Valid;
1149bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor
1150bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor
1151bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor    // C99 6.5.16:
1152bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor    //   An assignment expression [...] is not an lvalue.
1153bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor    return LV_InvalidExpression;
1154eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  }
11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  case CallExprClass:
115688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  case CXXOperatorCallExprClass:
115788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  case CXXMemberCallExprClass: {
11587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    // C++0x [expr.call]p10
11599d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    //   A function call is an lvalue if and only if the result type
11607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    //   is an lvalue reference.
11616dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson    QualType ReturnType = cast<CallExpr>(this)->getCallReturnType();
11626dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson    if (ReturnType->isLValueReferenceType())
11636dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson      return LV_Valid;
11647c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
11659d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    break;
11669d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  }
1167e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff  case CompoundLiteralExprClass: // C99 6.5.2.5p5
1168e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff    return LV_Valid;
1169670a62cd1d51042ea076cda5e93f26a1d8327fb3Chris Lattner  case ChooseExprClass:
1170670a62cd1d51042ea076cda5e93f26a1d8327fb3Chris Lattner    // __builtin_choose_expr is an lvalue if the selected operand is.
11717976932a1c256d447316ffac58e9821417725e34Eli Friedman    return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx)->isLvalue(Ctx);
1172213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  case ExtVectorElementExprClass:
1173213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman    if (cast<ExtVectorElementExpr>(this)->containsDuplicateElements())
1174fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff      return LV_DuplicateVectorComponents;
1175fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    return LV_Valid;
1176027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff  case ObjCIvarRefExprClass: // ObjC instance variables are lvalues.
1177027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff    return LV_Valid;
1178799a6a6850af625946bb8d88ca960bb6604e3858Steve Naroff  case ObjCPropertyRefExprClass: // FIXME: check if read-only property.
1179799a6a6850af625946bb8d88ca960bb6604e3858Steve Naroff    return LV_Valid;
118009105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian  case ObjCImplicitSetterGetterRefExprClass: // FIXME: check if read-only property.
1181670a62cd1d51042ea076cda5e93f26a1d8327fb3Chris Lattner    return LV_Valid;
1182d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  case PredefinedExprClass:
1183796da18402f286b897782a298ae3b20c459c102eDouglas Gregor    return LV_Valid;
1184ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  case UnresolvedLookupExprClass:
1185ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    return LV_Valid;
118604421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
118728be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner    return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue(Ctx);
11886eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  case CStyleCastExprClass:
11899d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  case CXXFunctionalCastExprClass:
11909d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  case CXXStaticCastExprClass:
11919d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  case CXXDynamicCastExprClass:
11929d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  case CXXReinterpretCastExprClass:
11939d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  case CXXConstCastExprClass:
11949d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // The result of an explicit cast is an lvalue if the type we are
11957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    // casting to is an lvalue reference type. See C++ [expr.cast]p1,
11969d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // C++ [expr.static.cast]p2, C++ [expr.dynamic.cast]p2,
11979d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // C++ [expr.reinterpret.cast]p1, C++ [expr.const.cast]p1.
11987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    if (cast<ExplicitCastExpr>(this)->getTypeAsWritten()->
11997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl          isLValueReferenceType())
12009d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor      return LV_Valid;
12019d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    break;
1202c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  case CXXTypeidExprClass:
1203c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    // C++ 5.2.8p1: The result of a typeid expression is an lvalue of ...
1204c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    return LV_Valid;
12056f68027af2b6ce294a2706f23a1d3cb7ca1b8d37Anders Carlsson  case CXXBindTemporaryExprClass:
12066f68027af2b6ce294a2706f23a1d3cb7ca1b8d37Anders Carlsson    return cast<CXXBindTemporaryExpr>(this)->getSubExpr()->
12076f68027af2b6ce294a2706f23a1d3cb7ca1b8d37Anders Carlsson      isLvalueInternal(Ctx);
1208eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  case CXXBindReferenceExprClass:
1209eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson    // Something that's bound to a reference is always an lvalue.
1210eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson    return LV_Valid;
121176458501a8963fa11b91c9337a487de6871169b4Sebastian Redl  case ConditionalOperatorClass: {
121276458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    // Complicated handling is only for C++.
121376458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    if (!Ctx.getLangOptions().CPlusPlus)
121476458501a8963fa11b91c9337a487de6871169b4Sebastian Redl      return LV_InvalidExpression;
121576458501a8963fa11b91c9337a487de6871169b4Sebastian Redl
121676458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    // Sema should have taken care to ensure that a CXXTemporaryObjectExpr is
121776458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    // everywhere there's an object converted to an rvalue. Also, any other
121876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    // casts should be wrapped by ImplicitCastExprs. There's just the special
121976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    // case involving throws to work out.
122076458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    const ConditionalOperator *Cond = cast<ConditionalOperator>(this);
1221d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor    Expr *True = Cond->getTrueExpr();
1222d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor    Expr *False = Cond->getFalseExpr();
122376458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    // C++0x 5.16p2
122476458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    //   If either the second or the third operand has type (cv) void, [...]
122576458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    //   the result [...] is an rvalue.
1226d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor    if (True->getType()->isVoidType() || False->getType()->isVoidType())
122776458501a8963fa11b91c9337a487de6871169b4Sebastian Redl      return LV_InvalidExpression;
122876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl
122976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    // Both sides must be lvalues for the result to be an lvalue.
1230d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor    if (True->isLvalue(Ctx) != LV_Valid || False->isLvalue(Ctx) != LV_Valid)
123176458501a8963fa11b91c9337a487de6871169b4Sebastian Redl      return LV_InvalidExpression;
123276458501a8963fa11b91c9337a487de6871169b4Sebastian Redl
123376458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    // That's it.
123476458501a8963fa11b91c9337a487de6871169b4Sebastian Redl    return LV_Valid;
123576458501a8963fa11b91c9337a487de6871169b4Sebastian Redl  }
123676458501a8963fa11b91c9337a487de6871169b4Sebastian Redl
12372d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor  case Expr::CXXExprWithTemporariesClass:
12382d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor    return cast<CXXExprWithTemporaries>(this)->getSubExpr()->isLvalue(Ctx);
12392d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor
12402d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor  case Expr::ObjCMessageExprClass:
12412d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor    if (const ObjCMethodDecl *Method
12422d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor          = cast<ObjCMessageExpr>(this)->getMethodDecl())
12432d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor      if (Method->getResultType()->isLValueReferenceType())
12442d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor        return LV_Valid;
12452d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor    break;
12462d48e7811216b2a2d15dcf7e4be8f73ad48cc60aDouglas Gregor
12475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return LV_InvalidExpression;
12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// does not have an incomplete type, does not have a const-qualified type, and
12551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// if it is a structure or union, does not have any member (including,
12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// recursively, any member or element of all contained aggregates or unions)
12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with a const-qualified type.
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpExpr::isModifiableLvalueResult
125944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel DunbarExpr::isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc) const {
126028be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  isLvalueResult lvalResult = isLvalue(Ctx);
12611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (lvalResult) {
12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  case LV_Valid:
1264ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor    // C++ 3.10p11: Functions cannot be modified, but pointers to
1265ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor    // functions can be modifiable.
1266ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor    if (Ctx.getLangOptions().CPlusPlus && TR->isFunctionType())
1267ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor      return MLV_NotObjectType;
1268ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor    break;
1269ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor
12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_NotObjectType: return MLV_NotObjectType;
12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_IncompleteVoidType: return MLV_IncompleteVoidType;
1272fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents;
1273ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner  case LV_InvalidExpression:
1274ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    // If the top level is a C-style cast, and the subexpression is a valid
1275ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    // lvalue, then this is probably a use of the old-school "cast as lvalue"
1276ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    // GCC extension.  We don't support it, but we want to produce good
1277ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    // diagnostics when it happens so that the user knows why.
127844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar    if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(IgnoreParens())) {
127944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar      if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid) {
128044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar        if (Loc)
128144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar          *Loc = CE->getLParenLoc();
1282ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner        return MLV_LValueCast;
128344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar      }
128444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar    }
1285ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    return MLV_InvalidExpression;
128686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  case LV_MemberFunction: return MLV_MemberFunction;
12872514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    case LV_SubObjCPropertySetting: return MLV_SubObjCPropertySetting;
12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
128904831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman
129004831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman  // The following is illegal:
129104831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman  //   void takeclosure(void (^C)(void));
129204831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman  //   void func() { int x = 1; takeclosure(^{ x = 7; }); }
129304831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman  //
1294c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian  if (const BlockDeclRefExpr *BDR = dyn_cast<BlockDeclRefExpr>(this)) {
129504831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman    if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
129604831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman      return MLV_NotBlockQualified;
129704831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman  }
12987e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar
1299c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian  // Assigning to an 'implicit' property?
13007e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar  if (const ObjCImplicitSetterGetterRefExpr* Expr =
1301c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian        dyn_cast<ObjCImplicitSetterGetterRefExpr>(this)) {
1302c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian    if (Expr->getSetterMethod() == 0)
1303c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian      return MLV_NoSetterProperty;
1304c3f48cd3f08c384de50a3eeceaa79f4800a35f19Fariborz Jahanian  }
13057e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar
1306c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  QualType CT = Ctx.getCanonicalType(getType());
13071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1308c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (CT.isConstQualified())
13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return MLV_ConstQualified;
1310c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (CT->isArrayType())
13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return MLV_ArrayType;
1312c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (CT->isIncompleteType())
13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return MLV_IncompleteType;
13141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13156217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const RecordType *r = CT->getAs<RecordType>()) {
13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (r->hasConstFields())
13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return MLV_ConstQualified;
13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return MLV_Valid;
13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
13225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
132344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able.
13247f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise.
1325102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const {
132644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  switch (getStmtClass()) {
132744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  default:
132844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return false;
132944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ObjCIvarRefExprClass:
133044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return true;
1331207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian  case Expr::UnaryOperatorClass:
1332102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
133344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ParenExprClass:
1334102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
133544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ImplicitCastExprClass:
1336102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
133706b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian  case CStyleCastExprClass:
1338102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
1339a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  case DeclRefExprClass: {
134044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    const Decl *D = cast<DeclRefExpr>(this)->getDecl();
1341102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1342102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian      if (VD->hasGlobalStorage())
1343102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian        return true;
1344102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian      QualType T = VD->getType();
134559a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian      // dereferencing to a  pointer is always a gc'able candidate,
134659a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian      // unless it is __weak.
13477e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar      return T->isPointerType() &&
13480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall             (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak);
1349102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    }
135044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return false;
135144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  }
135283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  case MemberExprClass: {
135344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    const MemberExpr *M = cast<MemberExpr>(this);
1354102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return M->getBase()->isOBJCGCCandidate(Ctx);
135544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  }
135644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ArraySubscriptExprClass:
1357102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx);
135844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  }
135944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian}
13604e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() {
13614e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  Expr* E = this;
13624e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  while (ParenExpr* P = dyn_cast<ParenExpr>(E))
13634e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    E = P->getSubExpr();
13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13654e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  return E;
13664e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek}
13674e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
136856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
136956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand.
137056f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() {
137156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *E = this;
137256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  while (true) {
137356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    if (ParenExpr *P = dyn_cast<ParenExpr>(E))
137456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
137556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else if (CastExpr *P = dyn_cast<CastExpr>(E))
137656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
137756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else
137856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      return E;
137956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
138056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner}
138156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
1382ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
1383ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size).  Strip off any
1384ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand.
1385ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) {
1386ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *E = this;
1387ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  while (true) {
1388ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    if (ParenExpr *P = dyn_cast<ParenExpr>(E)) {
1389ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      E = P->getSubExpr();
1390ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      continue;
1391ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    }
13921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1393ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    if (CastExpr *P = dyn_cast<CastExpr>(E)) {
1394ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      // We ignore integer <-> casts that are of the same width, ptr<->ptr and
1395ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      // ptr<->int casts of the same width.  We also ignore all identify casts.
1396ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      Expr *SE = P->getSubExpr();
13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1398ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) {
1399ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        E = SE;
1400ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        continue;
1401ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      }
14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1403ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      if ((E->getType()->isPointerType() || E->getType()->isIntegralType()) &&
1404ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner          (SE->getType()->isPointerType() || SE->getType()->isIntegralType()) &&
1405ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner          Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) {
1406ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        E = SE;
1407ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        continue;
1408ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      }
1409ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    }
14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1411ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return E;
1412ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
1413ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner}
1414ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
14156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const {
14166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  const Expr *E = this;
14176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
14186eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    E = ICE->getSubExprAsWritten();
14196eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
14206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return isa<CXXDefaultArgExpr>(E);
14216eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor}
1422ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
1423898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions
1424898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent.
1425898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) {
1426898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  for (unsigned I = 0; I < NumExprs; ++I)
1427898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    if (Exprs[I]->isTypeDependent())
1428898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      return true;
1429898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1430898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  return false;
1431898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
1432898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1433898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyValueDependentArguments - Determines if any of the expressions
1434898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is value-dependent.
1435898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) {
1436898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  for (unsigned I = 0; I < NumExprs; ++I)
1437898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    if (Exprs[I]->isValueDependent())
1438898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      return true;
1439898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1440898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  return false;
1441898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
1442898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1443c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedmanbool Expr::isConstantInitializer(ASTContext &Ctx) const {
1444c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // This function is attempting whether an expression is an initializer
1445c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // which can be evaluated at compile-time.  isEvaluatable handles most
1446c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // of the cases, but it can't deal with some initializer-specific
1447c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // expressions, and it can't deal with aggregates; we deal with those here,
1448c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // and fall back to isEvaluatable for the other cases.
1449c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman
14501f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman  // FIXME: This function assumes the variable being assigned to
14511f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman  // isn't a reference type!
14521f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman
1453e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  switch (getStmtClass()) {
1454c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  default: break;
1455e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  case StringLiteralClass:
145614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  case ObjCStringLiteralClass:
1457eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  case ObjCEncodeExprClass:
1458e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    return true;
145959b5da6d853b4368b984700315adf7b37de05764Nate Begeman  case CompoundLiteralExprClass: {
14601f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // This handles gcc's extension that allows global initializers like
14611f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // "struct x {int x;} x = (struct x) {};".
14621f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // FIXME: This accepts other cases it shouldn't!
146359b5da6d853b4368b984700315adf7b37de05764Nate Begeman    const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer();
1464c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman    return Exp->isConstantInitializer(Ctx);
146559b5da6d853b4368b984700315adf7b37de05764Nate Begeman  }
1466e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  case InitListExprClass: {
14671f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // FIXME: This doesn't deal with fields with reference types correctly.
14681f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // FIXME: This incorrectly allows pointers cast to integers to be assigned
14691f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // to bitfields.
1470e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    const InitListExpr *Exp = cast<InitListExpr>(this);
1471e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    unsigned numInits = Exp->getNumInits();
1472e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    for (unsigned i = 0; i < numInits; i++) {
14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      if (!Exp->getInit(i)->isConstantInitializer(Ctx))
1474e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson        return false;
1475e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    }
1476c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    return true;
1477e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  }
14783498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  case ImplicitValueInitExprClass:
14793498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return true;
14803ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner  case ParenExprClass:
1481c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    return cast<ParenExpr>(this)->getSubExpr()->isConstantInitializer(Ctx);
1482c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  case UnaryOperatorClass: {
1483c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    const UnaryOperator* Exp = cast<UnaryOperator>(this);
1484c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    if (Exp->getOpcode() == UnaryOperator::Extension)
1485c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman      return Exp->getSubExpr()->isConstantInitializer(Ctx);
1486c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    break;
1487c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  }
14883ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner  case BinaryOperatorClass: {
14893ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    // Special case &&foo - &&bar.  It would be nice to generalize this somehow
14903ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    // but this handles the common case.
14913ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    const BinaryOperator *Exp = cast<BinaryOperator>(this);
14923ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    if (Exp->getOpcode() == BinaryOperator::Sub &&
14933ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner        isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) &&
14943ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner        isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx)))
14953ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner      return true;
14963ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    break;
14973ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner  }
149881045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner  case ImplicitCastExprClass:
1499c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  case CStyleCastExprClass:
1500c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    // Handle casts with a destination that's a struct or union; this
1501c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    // deals with both the gcc no-op struct cast extension and the
1502c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    // cast-to-union extension.
1503c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    if (getType()->isRecordType())
1504c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman      return cast<CastExpr>(this)->getSubExpr()->isConstantInitializer(Ctx);
1505430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner
1506430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner    // Integer->integer casts can be handled here, which is important for
1507430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner    // things like (int)(&&x-&&y).  Scary but true.
1508430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner    if (getType()->isIntegerType() &&
1509430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner        cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType())
1510430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner      return cast<CastExpr>(this)->getSubExpr()->isConstantInitializer(Ctx);
1511430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner
1512c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    break;
1513e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  }
1514c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  return isEvaluatable(Ctx);
151538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff}
151638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
15175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIntegerConstantExpr - this recursive routine will test if an expression is
1518e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman/// an integer constant expression.
15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero,
15215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comma, etc
15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1523ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// FIXME: Handle offsetof.  Two things to do:  Handle GCC's __builtin_offsetof
1524ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// to support gcc 4.0+  and handle the idiom GCC recognizes with a null pointer
1525ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// cast+dereference.
15262d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar
1527e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// CheckICE - This function does the fundamental ICE checking: the returned
1528e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// ICEDiag contains a Val of 0, 1, or 2, and a possibly null SourceLocation.
1529e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// Note that to reduce code duplication, this helper does no evaluation
15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// itself; the caller checks whether the expression is evaluatable, and
1531e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// in the rare cases where CheckICE actually cares about the evaluated
15321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// value, it calls into Evalute.
1533e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman//
1534e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// Meanings of Val:
1535e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 0: This expression is an ICE if it can be evaluated by Evaluate.
1536e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 1: This expression is not an ICE, but if it isn't evaluated, it's
1537e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman//    a legal subexpression for an ICE. This return value is used to handle
1538e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman//    the comma operator in C99 mode.
1539e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 2: This expression is not an ICE, and is not a legal subexpression for one.
1540e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman
1541e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedmanstruct ICEDiag {
1542e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  unsigned Val;
1543e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  SourceLocation Loc;
1544e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman
1545e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  public:
1546e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  ICEDiag(unsigned v, SourceLocation l) : Val(v), Loc(l) {}
1547e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  ICEDiag() : Val(0) {}
1548e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman};
1549e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman
1550e28d7195aad595154130ac8d03cc6c6513ece1bfEli FriedmanICEDiag NoDiag() { return ICEDiag(); }
1551e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman
155260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedmanstatic ICEDiag CheckEvalInICE(const Expr* E, ASTContext &Ctx) {
155360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman  Expr::EvalResult EVResult;
155460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman  if (!E->Evaluate(EVResult, Ctx) || EVResult.HasSideEffects ||
155560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      !EVResult.Val.isInt()) {
155660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman    return ICEDiag(2, E->getLocStart());
155760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman  }
155860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman  return NoDiag();
155960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman}
156060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman
1561e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedmanstatic ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
1562c3082413e4207173b32c118e922d63149df6261fAnders Carlsson  assert(!E->isValueDependent() && "Should not see value dependent exprs!");
1563e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  if (!E->getType()->isIntegralType()) {
1564e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return ICEDiag(2, E->getLocStart());
1565a6afa768aa7bd3102a2807aa720917e4a1771e4eEli Friedman  }
1566e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman
1567e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  switch (E->getStmtClass()) {
1568f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor#define STMT(Node, Base) case Expr::Node##Class:
1569f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor#define EXPR(Node, Base)
1570f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor#include "clang/AST/StmtNodes.def"
1571f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::PredefinedExprClass:
1572f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::FloatingLiteralClass:
1573f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ImaginaryLiteralClass:
1574f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::StringLiteralClass:
1575f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ArraySubscriptExprClass:
1576f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::MemberExprClass:
1577f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CompoundAssignOperatorClass:
1578f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CompoundLiteralExprClass:
1579f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ExtVectorElementExprClass:
1580f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::InitListExprClass:
1581f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::DesignatedInitExprClass:
1582f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ImplicitValueInitExprClass:
1583f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ParenListExprClass:
1584f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::VAArgExprClass:
1585f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::AddrLabelExprClass:
1586f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::StmtExprClass:
1587f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXMemberCallExprClass:
1588f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXDynamicCastExprClass:
1589f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXTypeidExprClass:
1590f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXNullPtrLiteralExprClass:
1591f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXThisExprClass:
1592f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXThrowExprClass:
1593f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXNewExprClass:
1594f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXDeleteExprClass:
1595f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXPseudoDestructorExprClass:
1596ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  case Expr::UnresolvedLookupExprClass:
1597865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  case Expr::DependentScopeDeclRefExprClass:
1598f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXConstructExprClass:
1599f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXBindTemporaryExprClass:
1600eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  case Expr::CXXBindReferenceExprClass:
1601f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXExprWithTemporariesClass:
1602f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXTemporaryObjectExprClass:
1603f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXUnresolvedConstructExprClass:
1604865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  case Expr::CXXDependentScopeMemberExprClass:
1605129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  case Expr::UnresolvedMemberExprClass:
1606f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCStringLiteralClass:
1607f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCEncodeExprClass:
1608f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCMessageExprClass:
1609f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCSelectorExprClass:
1610f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCProtocolExprClass:
1611f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCIvarRefExprClass:
1612f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCPropertyRefExprClass:
1613f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCImplicitSetterGetterRefExprClass:
1614f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCSuperExprClass:
1615f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ObjCIsaExprClass:
1616f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ShuffleVectorExprClass:
1617f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::BlockExprClass:
1618f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::BlockDeclRefExprClass:
1619f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::NoStmtClass:
1620f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ExprClass:
1621e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return ICEDiag(2, E->getLocStart());
16227e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar
1623043cad21b78c6b02597cdc7b6ead32388e27ebc7Douglas Gregor  case Expr::GNUNullExprClass:
1624043cad21b78c6b02597cdc7b6ead32388e27ebc7Douglas Gregor    // GCC considers the GNU __null value to be an integral constant expression.
1625043cad21b78c6b02597cdc7b6ead32388e27ebc7Douglas Gregor    return NoDiag();
16267e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar
1627e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::ParenExprClass:
1628e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return CheckICE(cast<ParenExpr>(E)->getSubExpr(), Ctx);
1629e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::IntegerLiteralClass:
1630e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::CharacterLiteralClass:
1631e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::CXXBoolLiteralExprClass:
1632e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::CXXZeroInitValueExprClass:
1633e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::TypesCompatibleExprClass:
1634e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::UnaryTypeTraitExprClass:
1635e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return NoDiag();
16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  case Expr::CallExprClass:
1637e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::CXXOperatorCallExprClass: {
1638e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    const CallExpr *CE = cast<CallExpr>(E);
163960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman    if (CE->isBuiltinCall(Ctx))
164060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      return CheckEvalInICE(E, Ctx);
1641e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return ICEDiag(2, E->getLocStart());
164213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  }
1643e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::DeclRefExprClass:
1644e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (isa<EnumConstantDecl>(cast<DeclRefExpr>(E)->getDecl()))
1645e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return NoDiag();
16464a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl    if (Ctx.getLangOptions().CPlusPlus &&
16470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        E->getType().getCVRQualifiers() == Qualifiers::Const) {
16484a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl      // C++ 7.1.5.1p2
16494a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl      //   A variable of non-volatile const-qualified integral or enumeration
16504a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl      //   type initialized by an ICE can be used in ICEs.
16514a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl      if (const VarDecl *Dcl =
1652e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman              dyn_cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl())) {
1653cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor        Qualifiers Quals = Ctx.getCanonicalType(Dcl->getType()).getQualifiers();
1654cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor        if (Quals.hasVolatile() || !Quals.hasConst())
1655cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation());
1656cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor
1657cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor        // Look for the definition of this variable, which will actually have
1658cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor        // an initializer.
1659cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor        const VarDecl *Def = 0;
1660cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor        const Expr *Init = Dcl->getDefinition(Def);
1661cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor        if (Init) {
1662cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          if (Def->isInitKnownICE()) {
1663cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor            // We have already checked whether this subexpression is an
1664cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor            // integral constant expression.
1665cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor            if (Def->isInitICE())
1666cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor              return NoDiag();
1667cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor            else
1668cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor              return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation());
1669cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          }
167078d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor
1671cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          // C++ [class.static.data]p4:
1672cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          //   If a static data member is of const integral or const
1673cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          //   enumeration type, its declaration in the class definition can
1674cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          //   specify a constant-initializer which shall be an integral
1675cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          //   constant expression (5.19). In that case, the member can appear
1676cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          //   in integral constant expressions.
1677cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          if (Def->isOutOfLine()) {
1678c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman            Dcl->setInitKnownICE(false);
1679cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor            return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation());
1680cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor          }
1681c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman
1682c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman          if (Dcl->isCheckingICE()) {
1683c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman            return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation());
1684c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman          }
1685c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman
1686c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman          Dcl->setCheckingICE();
168778d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor          ICEDiag Result = CheckICE(Init, Ctx);
168878d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor          // Cache the result of the ICE test.
1689c013118155077cf8bdaef743c5dbce760114eed3Eli Friedman          Dcl->setInitKnownICE(Result.Val == 0);
169078d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor          return Result;
169178d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor        }
16924a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl      }
16934a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl    }
1694e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return ICEDiag(2, E->getLocStart());
1695e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::UnaryOperatorClass: {
1696e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    const UnaryOperator *Exp = cast<UnaryOperator>(E);
16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (Exp->getOpcode()) {
1698f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case UnaryOperator::PostInc:
1699f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case UnaryOperator::PostDec:
1700f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case UnaryOperator::PreInc:
1701f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case UnaryOperator::PreDec:
1702f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case UnaryOperator::AddrOf:
1703f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case UnaryOperator::Deref:
1704e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return ICEDiag(2, E->getLocStart());
17057e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar
17065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Extension:
1707e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case UnaryOperator::LNot:
17085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Plus:
17095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Minus:
17105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Not:
171160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman    case UnaryOperator::Real:
171260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman    case UnaryOperator::Imag:
1713e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return CheckICE(Exp->getSubExpr(), Ctx);
17145a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    case UnaryOperator::OffsetOf:
171560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      // Note that per C99, offsetof must be an ICE. And AFAIK, using
171660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      // Evaluate matches the proposed gcc behavior for cases like
171760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      // "offsetof(struct s{int x[4];}, x[!.0])".  This doesn't affect
171860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      // compliance: we should warn earlier for offsetof expressions with
171960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      // array subscripts that aren't ICEs, and if the array subscripts
172060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      // are ICEs, the value of the offsetof must be an integer constant.
172160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      return CheckEvalInICE(E, Ctx);
17225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
17235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1724e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::SizeOfAlignOfExprClass: {
1725e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    const SizeOfAlignOfExpr *Exp = cast<SizeOfAlignOfExpr>(E);
1726e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (Exp->isSizeOf() && Exp->getTypeOfArgument()->isVariableArrayType())
1727e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return ICEDiag(2, E->getLocStart());
1728e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return NoDiag();
17295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1730e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::BinaryOperatorClass: {
1731e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    const BinaryOperator *Exp = cast<BinaryOperator>(E);
17325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (Exp->getOpcode()) {
1733f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::PtrMemD:
1734f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::PtrMemI:
1735f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::Assign:
1736f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::MulAssign:
1737f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::DivAssign:
1738f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::RemAssign:
1739f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::AddAssign:
1740f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::SubAssign:
1741f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::ShlAssign:
1742f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::ShrAssign:
1743f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::AndAssign:
1744f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::XorAssign:
1745f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor    case BinaryOperator::OrAssign:
1746e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return ICEDiag(2, E->getLocStart());
17477e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar
17485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Mul:
17495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Div:
17505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Rem:
1751e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::Add:
1752e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::Sub:
17535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Shl:
17545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Shr:
1755e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::LT:
1756e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::GT:
1757e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::LE:
1758e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::GE:
1759e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::EQ:
1760e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::NE:
1761e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::And:
1762e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::Xor:
1763e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::Or:
1764e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::Comma: {
1765e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      ICEDiag LHSResult = CheckICE(Exp->getLHS(), Ctx);
1766e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      ICEDiag RHSResult = CheckICE(Exp->getRHS(), Ctx);
176760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      if (Exp->getOpcode() == BinaryOperator::Div ||
176860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          Exp->getOpcode() == BinaryOperator::Rem) {
176960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman        // Evaluate gives an error for undefined Div/Rem, so make sure
177060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman        // we don't evaluate one.
177160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman        if (LHSResult.Val != 2 && RHSResult.Val != 2) {
177260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          llvm::APSInt REval = Exp->getRHS()->EvaluateAsInt(Ctx);
177360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          if (REval == 0)
177460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman            return ICEDiag(1, E->getLocStart());
177560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          if (REval.isSigned() && REval.isAllOnesValue()) {
177660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman            llvm::APSInt LEval = Exp->getLHS()->EvaluateAsInt(Ctx);
177760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman            if (LEval.isMinSignedValue())
177860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman              return ICEDiag(1, E->getLocStart());
177960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          }
178060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman        }
178160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      }
178260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman      if (Exp->getOpcode() == BinaryOperator::Comma) {
178360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman        if (Ctx.getLangOptions().C99) {
178460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          // C99 6.6p3 introduces a strange edge case: comma can be in an ICE
178560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          // if it isn't evaluated.
178660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          if (LHSResult.Val == 0 && RHSResult.Val == 0)
178760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman            return ICEDiag(1, E->getLocStart());
178860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman        } else {
178960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          // In both C89 and C++, commas in ICEs are illegal.
179060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          return ICEDiag(2, E->getLocStart());
179160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman        }
1792b11e77836dd0867955c5abf32baf1c3e6c7f81e1Eli Friedman      }
1793e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      if (LHSResult.Val >= RHSResult.Val)
1794e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        return LHSResult;
1795e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return RHSResult;
17965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1797e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::LAnd:
1798e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    case BinaryOperator::LOr: {
1799e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      ICEDiag LHSResult = CheckICE(Exp->getLHS(), Ctx);
1800e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      ICEDiag RHSResult = CheckICE(Exp->getRHS(), Ctx);
1801e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      if (LHSResult.Val == 0 && RHSResult.Val == 1) {
1802e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        // Rare case where the RHS has a comma "side-effect"; we need
1803e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        // to actually check the condition to see whether the side
1804e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        // with the comma is evaluated.
1805e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        if ((Exp->getOpcode() == BinaryOperator::LAnd) !=
180660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman            (Exp->getLHS()->EvaluateAsInt(Ctx) == 0))
1807e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman          return RHSResult;
1808e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        return NoDiag();
1809a135975d4257ccc83f13b607b29d882bb00c80b6Daniel Dunbar      }
181060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman
1811e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      if (LHSResult.Val >= RHSResult.Val)
1812e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        return LHSResult;
1813e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return RHSResult;
18145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1815987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    }
18165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1817f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CastExprClass:
1818e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::ImplicitCastExprClass:
1819f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::ExplicitCastExprClass:
1820e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::CStyleCastExprClass:
182159600d80b7e34e819cd25dd67f661aa1f3d9099dDouglas Gregor  case Expr::CXXFunctionalCastExprClass:
1822f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  case Expr::CXXNamedCastExprClass:
182359600d80b7e34e819cd25dd67f661aa1f3d9099dDouglas Gregor  case Expr::CXXStaticCastExprClass:
182459600d80b7e34e819cd25dd67f661aa1f3d9099dDouglas Gregor  case Expr::CXXReinterpretCastExprClass:
182559600d80b7e34e819cd25dd67f661aa1f3d9099dDouglas Gregor  case Expr::CXXConstCastExprClass: {
1826e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr();
1827e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (SubExpr->getType()->isIntegralType())
1828e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return CheckICE(SubExpr, Ctx);
1829e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (isa<FloatingLiteral>(SubExpr->IgnoreParens()))
1830e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return NoDiag();
1831e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return ICEDiag(2, E->getLocStart());
1832e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  }
1833e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::ConditionalOperatorClass: {
1834e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    const ConditionalOperator *Exp = cast<ConditionalOperator>(E);
18351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // If the condition (ignoring parens) is a __builtin_constant_p call,
183628daa53db73341b7ee7f269924ccfca1c6d179acChris Lattner    // then only the true side is actually considered in an integer constant
183742b83dde7c700b34f9435ad746984169888ae705Chris Lattner    // expression, and it is fully evaluated.  This is an important GNU
183842b83dde7c700b34f9435ad746984169888ae705Chris Lattner    // extension.  See GCC PR38377 for discussion.
1839e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (const CallExpr *CallCE = dyn_cast<CallExpr>(Exp->getCond()->IgnoreParenCasts()))
18403c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor      if (CallCE->isBuiltinCall(Ctx) == Builtin::BI__builtin_constant_p) {
1841e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        Expr::EvalResult EVResult;
1842e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        if (!E->Evaluate(EVResult, Ctx) || EVResult.HasSideEffects ||
1843e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman            !EVResult.Val.isInt()) {
184460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman          return ICEDiag(2, E->getLocStart());
1845e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        }
1846e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman        return NoDiag();
184742b83dde7c700b34f9435ad746984169888ae705Chris Lattner      }
1848e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    ICEDiag CondResult = CheckICE(Exp->getCond(), Ctx);
1849e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    ICEDiag TrueResult = CheckICE(Exp->getTrueExpr(), Ctx);
1850e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    ICEDiag FalseResult = CheckICE(Exp->getFalseExpr(), Ctx);
1851e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (CondResult.Val == 2)
1852e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return CondResult;
1853e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (TrueResult.Val == 2)
1854e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return TrueResult;
1855e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (FalseResult.Val == 2)
1856e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return FalseResult;
1857e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (CondResult.Val == 1)
1858e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return CondResult;
1859e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (TrueResult.Val == 0 && FalseResult.Val == 0)
1860e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return NoDiag();
1861e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    // Rare case where the diagnostics depend on which side is evaluated
1862e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    // Note that if we get here, CondResult is 0, and at least one of
1863e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    // TrueResult and FalseResult is non-zero.
186460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman    if (Exp->getCond()->EvaluateAsInt(Ctx) == 0) {
1865e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman      return FalseResult;
1866e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    }
1867e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return TrueResult;
18685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1869e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  case Expr::CXXDefaultArgExprClass:
1870e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return CheckICE(cast<CXXDefaultArgExpr>(E)->getExpr(), Ctx);
187160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman  case Expr::ChooseExprClass: {
18727976932a1c256d447316ffac58e9821417725e34Eli Friedman    return CheckICE(cast<ChooseExpr>(E)->getChosenSubExpr(Ctx), Ctx);
187360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman  }
18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
18757e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar
1876f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  // Silence a GCC warning
1877f299124fe491879fed48f611f6f299382d114dd4Douglas Gregor  return ICEDiag(2, E->getLocStart());
1878e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman}
18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1880e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedmanbool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
1881e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman                                 SourceLocation *Loc, bool isEvaluated) const {
1882e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  ICEDiag d = CheckICE(this, Ctx);
1883e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  if (d.Val != 0) {
1884e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    if (Loc) *Loc = d.Loc;
1885e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman    return false;
1886e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  }
1887e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  EvalResult EvalResult;
188860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman  if (!Evaluate(EvalResult, Ctx))
18899f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin    llvm_unreachable("ICE cannot be evaluated!");
189060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman  assert(!EvalResult.HasSideEffects && "ICE with side effects!");
189160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman  assert(EvalResult.Val.isInt() && "ICE that isn't integer!");
1892e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman  Result = EvalResult.Val.getInt();
18935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return true;
18945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
18955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
18975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// integer constant expression with the value zero, or if this is one that is
18985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// cast to void*.
1899ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregorbool Expr::isNullPointerConstant(ASTContext &Ctx,
1900ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor                                 NullPointerConstantValueDependence NPC) const {
1901ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  if (isValueDependent()) {
1902ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    switch (NPC) {
1903ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    case NPC_NeverValueDependent:
1904ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      assert(false && "Unexpected value dependent expression!");
1905ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      // If the unthinkable happens, fall through to the safest alternative.
1906ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor
1907ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    case NPC_ValueDependentIsNull:
1908ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      return isTypeDependent() || getType()->isIntegralType();
1909ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor
1910ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    case NPC_ValueDependentIsNotNull:
1911ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      return false;
1912ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    }
1913ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  }
1914f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar
19150777972d38a3125efed962b045704c30ae6965cfSebastian Redl  // Strip off a cast to void*, if it exists. Except in C++.
19160835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
19176215dee86c0e715b9f2b0d401ab2a5fcf629f1afSebastian Redl    if (!Ctx.getLangOptions().CPlusPlus) {
19180777972d38a3125efed962b045704c30ae6965cfSebastian Redl      // Check that it is a cast to void*.
19196217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek      if (const PointerType *PT = CE->getType()->getAs<PointerType>()) {
19200777972d38a3125efed962b045704c30ae6965cfSebastian Redl        QualType Pointee = PT->getPointeeType();
19210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        if (!Pointee.hasQualifiers() &&
19220777972d38a3125efed962b045704c30ae6965cfSebastian Redl            Pointee->isVoidType() &&                              // to void*
19230777972d38a3125efed962b045704c30ae6965cfSebastian Redl            CE->getSubExpr()->getType()->isIntegerType())         // from int.
1924ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor          return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
19250777972d38a3125efed962b045704c30ae6965cfSebastian Redl      }
19265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1927aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
1928aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Ignore the ImplicitCastExpr type entirely.
1929ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
1930aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
1931aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Accept ((void*)0) as a null pointer constant, as many other
1932aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // implementations do.
1933ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
19341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  } else if (const CXXDefaultArgExpr *DefaultArg
19358123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner               = dyn_cast<CXXDefaultArgExpr>(this)) {
193604421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    // See through default argument expressions
1937ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC);
19382d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  } else if (isa<GNUNullExpr>(this)) {
19392d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    // The GNU __null extension is always a null pointer constant.
19402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return true;
1941aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff  }
19422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
19436e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  // C++0x nullptr_t is always a null pointer constant.
19446e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  if (getType()->isNullPtrType())
19456e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return true;
19466e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
1947aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  // This expression must be an integer type.
194856fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian  if (!getType()->isIntegerType() ||
194956fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian      (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType()))
1950aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    return false;
19511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // If we have an integer constant expression, we need to *evaluate* it and
19535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // test for the value 0.
195409de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman  llvm::APSInt Result;
195509de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman  return isIntegerConstantExpr(Result, Ctx) && Result == 0;
19565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
195731a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff
195833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() {
19596f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor  Expr *E = this->IgnoreParens();
196033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
1961de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
1962de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor    if (ICE->isLvalueCast() && ICE->getCastKind() == CastExpr::CK_NoOp)
1963de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor      E = ICE->getSubExpr()->IgnoreParens();
1964de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor    else
1965de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor      break;
1966de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  }
1967de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor
196827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E))
196986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl()))
197033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor      if (Field->isBitField())
197133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor        return Field;
197233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
197333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E))
197433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor    if (BinOp->isAssignmentOp() && BinOp->getLHS())
197533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor      return BinOp->getLHS()->getBitField();
197633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
197733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  return 0;
197827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor}
197927c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor
19802140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector,
19812140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector.
19822140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const {
19832140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  return getBase()->getType()->isPointerType();
19842140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner}
19852140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner
1986213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const {
1987183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const VectorType *VT = getType()->getAs<VectorType>())
19888a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    return VT->getNumElements();
19898a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  return 1;
19904d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner}
19914d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner
19928a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated.
1993213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const {
1994a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar  // FIXME: Refactor this code to an accessor on the AST node which returns the
1995a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar  // "type" of component access, and share with code below and in Sema.
199601eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar  llvm::StringRef Comp = Accessor->getName();
1997190d6a25393995b42e32086949a68285ee423fb9Nate Begeman
1998190d6a25393995b42e32086949a68285ee423fb9Nate Begeman  // Halving swizzles do not contain duplicate elements.
1999150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar  if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd")
2000190d6a25393995b42e32086949a68285ee423fb9Nate Begeman    return false;
20011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2002190d6a25393995b42e32086949a68285ee423fb9Nate Begeman  // Advance past s-char prefix on hex swizzles.
2003150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar  if (Comp[0] == 's' || Comp[0] == 'S')
2004150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar    Comp = Comp.substr(1);
20051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2006150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar  for (unsigned i = 0, e = Comp.size(); i != e; ++i)
2007150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar    if (Comp.substr(i + 1).find(Comp[i]) != llvm::StringRef::npos)
2008fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff        return true;
2009150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar
2010fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  return false;
2011fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff}
2012b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
20138a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
20143b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess(
20153b8d116703db8018f855cbb4733ace426422623bNate Begeman                                  llvm::SmallVectorImpl<unsigned> &Elts) const {
20164b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  llvm::StringRef Comp = Accessor->getName();
20174b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  if (Comp[0] == 's' || Comp[0] == 'S')
20184b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar    Comp = Comp.substr(1);
20191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20204b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isHi =   Comp == "hi";
20214b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isLo =   Comp == "lo";
20224b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isEven = Comp == "even";
20234b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isOdd  = Comp == "odd";
20241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20258a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
20268a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    uint64_t Index;
20271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20288a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    if (isHi)
20298a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = e + i;
20308a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isLo)
20318a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = i;
20328a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isEven)
20338a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i;
20348a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isOdd)
20358a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i + 1;
20368a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else
20374b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar      Index = ExtVectorType::getAccessorIdx(Comp[i]);
2038b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
20393b8d116703db8018f855cbb4733ace426422623bNate Begeman    Elts.push_back(Index);
2040b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
20418a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman}
20428a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
204368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// constructor for instance messages.
2044bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
2045a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                QualType retType, ObjCMethodDecl *mproto,
2046db611d556f71f98b66b69514d45958d76e5727abSteve Naroff                SourceLocation LBrac, SourceLocation RBrac,
204749f109c786f99eb7468dac3976db083a65493444Steve Naroff                Expr **ArgExprs, unsigned nargs)
20482333f7727f97018d6742e1e0938133bcfad967abEli Friedman  : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
2049ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek    MethodProto(mproto) {
205049f109c786f99eb7468dac3976db083a65493444Steve Naroff  NumArgs = nargs;
20515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  SubExprs = new Stmt*[NumArgs+1];
205268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  SubExprs[RECEIVER] = receiver;
205349f109c786f99eb7468dac3976db083a65493444Steve Naroff  if (NumArgs) {
205449f109c786f99eb7468dac3976db083a65493444Steve Naroff    for (unsigned i = 0; i != NumArgs; ++i)
205568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
205668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  }
2057563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  LBracloc = LBrac;
2058563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  RBracloc = RBrac;
2059563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
2060563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
20611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// constructor for class messages.
206268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// FIXME: clsName should be typed to ObjCInterfaceType
2063bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
2064a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                QualType retType, ObjCMethodDecl *mproto,
2065db611d556f71f98b66b69514d45958d76e5727abSteve Naroff                SourceLocation LBrac, SourceLocation RBrac,
206649f109c786f99eb7468dac3976db083a65493444Steve Naroff                Expr **ArgExprs, unsigned nargs)
20672333f7727f97018d6742e1e0938133bcfad967abEli Friedman  : Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
2068ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek    MethodProto(mproto) {
206949f109c786f99eb7468dac3976db083a65493444Steve Naroff  NumArgs = nargs;
20705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  SubExprs = new Stmt*[NumArgs+1];
20714df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown);
207249f109c786f99eb7468dac3976db083a65493444Steve Naroff  if (NumArgs) {
207349f109c786f99eb7468dac3976db083a65493444Steve Naroff    for (unsigned i = 0; i != NumArgs; ++i)
207468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
207568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  }
2076563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  LBracloc = LBrac;
2077563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  RBracloc = RBrac;
2078563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
2079563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// constructor for class messages.
20814df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekObjCMessageExpr::ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo,
20824df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek                                 QualType retType, ObjCMethodDecl *mproto,
20834df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek                                 SourceLocation LBrac, SourceLocation RBrac,
20844df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek                                 Expr **ArgExprs, unsigned nargs)
20852333f7727f97018d6742e1e0938133bcfad967abEli Friedman: Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
20864df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekMethodProto(mproto) {
20874df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  NumArgs = nargs;
20884df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  SubExprs = new Stmt*[NumArgs+1];
20894df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown);
20904df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  if (NumArgs) {
20914df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    for (unsigned i = 0; i != NumArgs; ++i)
20924df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
20934df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  }
20944df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  LBracloc = LBrac;
20954df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  RBracloc = RBrac;
20964df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek}
20974df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek
20984df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekObjCMessageExpr::ClassInfo ObjCMessageExpr::getClassInfo() const {
20994df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  uintptr_t x = (uintptr_t) SubExprs[RECEIVER];
21004df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  switch (x & Flags) {
21014df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    default:
21024df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      assert(false && "Invalid ObjCMessageExpr.");
21034df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    case IsInstMeth:
21044df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      return ClassInfo(0, 0);
21054df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    case IsClsMethDeclUnknown:
21064df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      return ClassInfo(0, (IdentifierInfo*) (x & ~Flags));
21074df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    case IsClsMethDeclKnown: {
21084df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      ObjCInterfaceDecl* D = (ObjCInterfaceDecl*) (x & ~Flags);
21094df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      return ClassInfo(D, D->getIdentifier());
21104df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    }
21114df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  }
21124df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek}
21134df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek
21140389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattnervoid ObjCMessageExpr::setClassInfo(const ObjCMessageExpr::ClassInfo &CI) {
21150389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner  if (CI.first == 0 && CI.second == 0)
21160389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner    SubExprs[RECEIVER] = (Expr*)((uintptr_t)0 | IsInstMeth);
21170389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner  else if (CI.first == 0)
21180389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner    SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.second | IsClsMethDeclUnknown);
21190389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner  else
21200389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner    SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.first | IsClsMethDeclKnown);
21210389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner}
21220389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner
21230389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner
212427437caadea35f84d550cd29f024fcf3ea240eecChris Lattnerbool ChooseExpr::isConditionTrue(ASTContext &C) const {
21259a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman  return getCond()->EvaluateAsInt(C) != 0;
212627437caadea35f84d550cd29f024fcf3ea240eecChris Lattner}
212727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner
2128888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs,
2129888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman                                 unsigned NumExprs) {
2130888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  if (SubExprs) C.Deallocate(SubExprs);
2131888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
2132888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  SubExprs = new (C) Stmt* [NumExprs];
213394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  this->NumExprs = NumExprs;
213494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs);
21351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
2136888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
2137888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::DoDestroy(ASTContext& C) {
2138888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  DestroyChildren(C);
2139888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  if (SubExprs) C.Deallocate(SubExprs);
2140888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  this->~ShuffleVectorExpr();
2141888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  C.Deallocate(this);
214294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor}
214394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
214442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid SizeOfAlignOfExpr::DoDestroy(ASTContext& C) {
21450518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // Override default behavior of traversing children. If this has a type
21460518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // operand and the type is a variable-length array, the child iteration
21470518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // will iterate over the size expression. However, this expression belongs
21480518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // to the type, not to this, so we don't want to delete it.
21490518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // We still want to delete this expression.
21508189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  if (isArgumentType()) {
21518189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    this->~SizeOfAlignOfExpr();
21528189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek    C.Deallocate(this);
21538189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
21540518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  else
215542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor    Expr::DoDestroy(C);
21569048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar}
21579048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar
215877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
215905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//  DesignatedInitExpr
216005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===//
216105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
216205c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() {
216305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  assert(Kind == FieldDesignator && "Only valid on a field designator");
216405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  if (Field.NameOrField & 0x01)
216505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01);
216605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  else
216705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return getField()->getIdentifier();
216805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
216905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2170319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas GregorDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty,
2171319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                                       unsigned NumDesignators,
2172ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                                       const Designator *Designators,
21731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                       SourceLocation EqualOrColonLoc,
2174ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                                       bool GNUSyntax,
21751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                       Expr **IndexExprs,
21769ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                       unsigned NumIndexExprs,
21779ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                       Expr *Init)
21781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Expr(DesignatedInitExprClass, Ty,
21799ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor         Init->isTypeDependent(), Init->isValueDependent()),
21801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) {
2182319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  this->Designators = new (C) Designator[NumDesignators];
21839ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
21849ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // Record the initializer itself.
21859ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  child_iterator Child = child_begin();
21869ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  *Child++ = Init;
21879ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
21889ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // Copy the designators and their subexpressions, computing
21899ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // value-dependence along the way.
21909ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  unsigned IndexIdx = 0;
21919ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  for (unsigned I = 0; I != NumDesignators; ++I) {
2192ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    this->Designators[I] = Designators[I];
21939ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
21949ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    if (this->Designators[I].isArrayDesignator()) {
21959ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Compute type- and value-dependence.
21969ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      Expr *Index = IndexExprs[IndexIdx];
21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ValueDependent = ValueDependent ||
21989ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor        Index->isTypeDependent() || Index->isValueDependent();
21999ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
22009ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Copy the index expressions into permanent storage.
22019ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      *Child++ = IndexExprs[IndexIdx++];
22029ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    } else if (this->Designators[I].isArrayRangeDesignator()) {
22039ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Compute type- and value-dependence.
22049ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      Expr *Start = IndexExprs[IndexIdx];
22059ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      Expr *End = IndexExprs[IndexIdx + 1];
22061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ValueDependent = ValueDependent ||
22079ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor        Start->isTypeDependent() || Start->isValueDependent() ||
22089ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor        End->isTypeDependent() || End->isValueDependent();
22099ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
22109ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Copy the start/end expressions into permanent storage.
22119ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      *Child++ = IndexExprs[IndexIdx++];
22129ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      *Child++ = IndexExprs[IndexIdx++];
22139ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    }
22149ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  }
22159ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
22169ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions");
2217ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor}
2218ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
221905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr *
22201eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators,
222105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           unsigned NumDesignators,
222205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           Expr **IndexExprs, unsigned NumIndexExprs,
222305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           SourceLocation ColonOrEqualLoc,
222405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           bool UsesColonSyntax, Expr *Init) {
2225c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff  void *Mem = C.Allocate(sizeof(DesignatedInitExpr) +
2226c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff                         sizeof(Stmt *) * (NumIndexExprs + 1), 8);
2227319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators,
22289ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                      ColonOrEqualLoc, UsesColonSyntax,
22299ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                      IndexExprs, NumIndexExprs, Init);
223005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
223105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
22321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C,
2233d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor                                                    unsigned NumIndexExprs) {
2234d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void *Mem = C.Allocate(sizeof(DesignatedInitExpr) +
2235d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor                         sizeof(Stmt *) * (NumIndexExprs + 1), 8);
2236d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  return new (Mem) DesignatedInitExpr(NumIndexExprs + 1);
2237d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor}
2238d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2239319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C,
2240319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                                        const Designator *Desigs,
2241d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor                                        unsigned NumDesigs) {
2242319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  DestroyDesignators(C);
2243d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2244319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  Designators = new (C) Designator[NumDesigs];
2245d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  NumDesignators = NumDesigs;
2246d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  for (unsigned I = 0; I != NumDesigs; ++I)
2247d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Designators[I] = Desigs[I];
2248d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor}
2249d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
225005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const {
225105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation StartLoc;
2252d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner  Designator &First =
2253d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner    *const_cast<DesignatedInitExpr*>(this)->designators_begin();
225405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  if (First.isFieldDesignator()) {
2255eeae8f072748affce25ab4064982626361293390Douglas Gregor    if (GNUSyntax)
225605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc);
225705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    else
225805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc);
225905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  } else
2260d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner    StartLoc =
2261d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner      SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc);
226205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return SourceRange(StartLoc, getInit()->getSourceRange().getEnd());
226305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
226405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
226505c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) {
226605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  assert(D.Kind == Designator::ArrayDesignator && "Requires array designator");
226705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
226805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
226905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
227005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
227105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
227205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
227305c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) {
22741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  assert(D.Kind == Designator::ArrayRangeDesignator &&
227505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor         "Requires array range designator");
227605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
227705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
227805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
227905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
228005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
228105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
228205c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) {
22831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  assert(D.Kind == Designator::ArrayRangeDesignator &&
228405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor         "Requires array range designator");
228505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
228605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
228705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
228805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2));
228905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
229005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2291ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series
2292ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last).
2293319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx,
22941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                          const Designator *First,
2295ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                                          const Designator *Last) {
2296ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  unsigned NumNewDesignators = Last - First;
2297ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  if (NumNewDesignators == 0) {
2298ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    std::copy_backward(Designators + Idx + 1,
2299ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                       Designators + NumDesignators,
2300ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                       Designators + Idx);
2301ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    --NumNewDesignators;
2302ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return;
2303ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  } else if (NumNewDesignators == 1) {
2304ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designators[Idx] = *First;
2305ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return;
2306ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
2307ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
23081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Designator *NewDesignators
2309319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor    = new (C) Designator[NumDesignators - 1 + NumNewDesignators];
2310ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  std::copy(Designators, Designators + Idx, NewDesignators);
2311ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  std::copy(First, Last, NewDesignators + Idx);
2312ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  std::copy(Designators + Idx + 1, Designators + NumDesignators,
2313ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor            NewDesignators + Idx + NumNewDesignators);
2314319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  DestroyDesignators(C);
2315ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designators = NewDesignators;
2316ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  NumDesignators = NumDesignators - 1 + NumNewDesignators;
2317ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor}
2318ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
231942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid DesignatedInitExpr::DoDestroy(ASTContext &C) {
2320319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  DestroyDesignators(C);
232142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  Expr::DoDestroy(C);
2322ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor}
2323ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2324319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::DestroyDesignators(ASTContext &C) {
2325319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  for (unsigned I = 0; I != NumDesignators; ++I)
2326319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor    Designators[I].~Designator();
2327319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  C.Deallocate(Designators);
2328319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  Designators = 0;
2329319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor}
2330319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor
23311eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc,
23322ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                             Expr **exprs, unsigned nexprs,
23332ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                             SourceLocation rparenloc)
23342ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman: Expr(ParenListExprClass, QualType(),
23352ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman       hasAnyTypeDependentArguments(exprs, nexprs),
23361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump       hasAnyValueDependentArguments(exprs, nexprs)),
23372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) {
23381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Exprs = new (C) Stmt*[nexprs];
23402ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  for (unsigned i = 0; i != nexprs; ++i)
23412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    Exprs[i] = exprs[i];
23422ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
23432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
23442ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanvoid ParenListExpr::DoDestroy(ASTContext& C) {
23452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  DestroyChildren(C);
23462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  if (Exprs) C.Deallocate(Exprs);
23472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  this->~ParenListExpr();
23482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  C.Deallocate(this);
23492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
23502ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
235105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===//
2352ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//  ExprIterator.
2353ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
2354ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
2355ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); }
2356ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); }
2357ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); }
2358ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const {
2359ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  return cast<Expr>(I[idx]);
2360ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek}
2361ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); }
2362ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); }
2363ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
2364ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
236577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//  Child Iterators for iterating over subexpressions/substatements
236677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
236777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
236877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// DeclRefExpr
23699ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
23709ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
237177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
23727779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff// ObjCIvarRefExpr
23735549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; }
23745549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; }
23757779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff
2376e3e9add4fd788927df6f545570e7838db59c01d7Steve Naroff// ObjCPropertyRefExpr
23775549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; }
23785549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; }
2379ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff
238009105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian// ObjCImplicitSetterGetterRefExpr
23811eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_begin() {
23821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return &Base;
2383154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian}
23841eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_end() {
23851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return &Base+1;
2386154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian}
23875daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian
2388cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor// ObjCSuperExpr
2389cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); }
2390cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); }
2391cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor
2392f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff// ObjCIsaExpr
2393f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; }
2394f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; }
2395f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff
2396d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner// PredefinedExpr
2397d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); }
2398d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); }
239977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
240077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// IntegerLiteral
24019ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); }
24029ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); }
240377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
240477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CharacterLiteral
2405d603eaa682cecac2c10771a700cb83aa301653b4Chris LattnerStmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();}
24069ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); }
240777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
240877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// FloatingLiteral
24099ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); }
24109ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); }
241177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
24125d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner// ImaginaryLiteral
24135549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; }
24145549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; }
24155d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
241677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// StringLiteral
24179ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_begin() { return child_iterator(); }
24189ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_end() { return child_iterator(); }
241977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
242077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ParenExpr
24215549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_begin() { return &Val; }
24225549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_end() { return &Val+1; }
242377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
242477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// UnaryOperator
24255549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_begin() { return &Val; }
24265549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_end() { return &Val+1; }
242777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
24280518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl// SizeOfAlignOfExpr
24291eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator SizeOfAlignOfExpr::child_begin() {
24300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // If this is of a type and the type is a VLA type (and not a typedef), the
24310518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // size expression of the VLA needs to be treated as an executable expression.
24320518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // Why isn't this weirdness documented better in StmtIterator?
24330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  if (isArgumentType()) {
24340518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    if (VariableArrayType* T = dyn_cast<VariableArrayType>(
24350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                                   getArgumentType().getTypePtr()))
24360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl      return child_iterator(T);
24370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return child_iterator();
24380518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
2439d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  return child_iterator(&Argument.Ex);
24409ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
24410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian RedlStmt::child_iterator SizeOfAlignOfExpr::child_end() {
24420518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  if (isArgumentType())
24430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return child_iterator();
2444d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  return child_iterator(&Argument.Ex + 1);
24459ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
244677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
244777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ArraySubscriptExpr
24481237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_begin() {
24495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
245077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
24511237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_end() {
24525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
245377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
245477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
245577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CallExpr
24561237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_begin() {
24575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
245877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
24591237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_end() {
24605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+NumArgs+ARGS_START;
246177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
24621237c673c07f9d827129ba02720108816abde562Ted Kremenek
24631237c673c07f9d827129ba02720108816abde562Ted Kremenek// MemberExpr
24645549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_begin() { return &Base; }
24655549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_end() { return &Base+1; }
24661237c673c07f9d827129ba02720108816abde562Ted Kremenek
2467213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman// ExtVectorElementExpr
24685549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; }
24695549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; }
24701237c673c07f9d827129ba02720108816abde562Ted Kremenek
24711237c673c07f9d827129ba02720108816abde562Ted Kremenek// CompoundLiteralExpr
24725549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; }
24735549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; }
24741237c673c07f9d827129ba02720108816abde562Ted Kremenek
24751237c673c07f9d827129ba02720108816abde562Ted Kremenek// CastExpr
24765549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_begin() { return &Op; }
24775549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_end() { return &Op+1; }
24781237c673c07f9d827129ba02720108816abde562Ted Kremenek
24791237c673c07f9d827129ba02720108816abde562Ted Kremenek// BinaryOperator
24801237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_begin() {
24815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
24821237c673c07f9d827129ba02720108816abde562Ted Kremenek}
24831237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_end() {
24845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
24851237c673c07f9d827129ba02720108816abde562Ted Kremenek}
24861237c673c07f9d827129ba02720108816abde562Ted Kremenek
24871237c673c07f9d827129ba02720108816abde562Ted Kremenek// ConditionalOperator
24881237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_begin() {
24895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
24901237c673c07f9d827129ba02720108816abde562Ted Kremenek}
24911237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_end() {
24925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
24931237c673c07f9d827129ba02720108816abde562Ted Kremenek}
24941237c673c07f9d827129ba02720108816abde562Ted Kremenek
24951237c673c07f9d827129ba02720108816abde562Ted Kremenek// AddrLabelExpr
24969ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); }
24979ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); }
24981237c673c07f9d827129ba02720108816abde562Ted Kremenek
24991237c673c07f9d827129ba02720108816abde562Ted Kremenek// StmtExpr
25005549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_begin() { return &SubStmt; }
25015549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; }
25021237c673c07f9d827129ba02720108816abde562Ted Kremenek
25031237c673c07f9d827129ba02720108816abde562Ted Kremenek// TypesCompatibleExpr
25049ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_begin() {
25059ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25069ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25079ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek
25089ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_end() {
25099ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25109ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25111237c673c07f9d827129ba02720108816abde562Ted Kremenek
25121237c673c07f9d827129ba02720108816abde562Ted Kremenek// ChooseExpr
25135549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; }
25145549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; }
25152d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
25162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor// GNUNullExpr
25172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); }
25182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); }
25191237c673c07f9d827129ba02720108816abde562Ted Kremenek
2520d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman// ShuffleVectorExpr
2521d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_begin() {
25225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
2523d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
2524d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_end() {
25255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+NumExprs;
2526d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
2527d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
25287c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson// VAArgExpr
25295549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_begin() { return &Val; }
25305549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_end() { return &Val+1; }
25317c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
253266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson// InitListExpr
253366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_begin() {
25345549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return InitExprs.size() ? &InitExprs[0] : 0;
253566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
253666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_end() {
25375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0;
253866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
253966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
25403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// DesignatedInitExpr
254105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_begin() {
254205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
254305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
254405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
254505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
254605c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_end() {
254705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return child_iterator(&*child_begin() + NumSubExprs);
254805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
254905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
25503498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// ImplicitValueInitExpr
25511eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_begin() {
25521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return child_iterator();
25533498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}
25543498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
25551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_end() {
25561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return child_iterator();
25573498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}
25583498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
25592ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman// ParenListExpr
25602ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_begin() {
25612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  return &Exprs[0];
25622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
25632ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_end() {
25642ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  return &Exprs[0]+NumExprs;
25652ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
25662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
25671237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCStringLiteral
25681eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCStringLiteral::child_begin() {
2569c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner  return &String;
25709ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25719ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_end() {
2572c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner  return &String+1;
25739ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25741237c673c07f9d827129ba02720108816abde562Ted Kremenek
25751237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCEncodeExpr
25769ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); }
25779ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); }
25781237c673c07f9d827129ba02720108816abde562Ted Kremenek
2579b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian// ObjCSelectorExpr
25801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCSelectorExpr::child_begin() {
25819ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25829ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25839ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_end() {
25849ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25859ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
2586b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
2587390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian// ObjCProtocolExpr
25889ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_begin() {
25899ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25909ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25919ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_end() {
25929ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25939ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
2594390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian
2595563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr
25961eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCMessageExpr::child_begin() {
25975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return getReceiver() ? &SubExprs[0] : &SubExprs[0] + ARGS_START;
2598563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
2599563477da25f824e37c535131695dc4dc9b68c465Steve NaroffStmt::child_iterator ObjCMessageExpr::child_end() {
26005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+ARGS_START+getNumArgs();
2601563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
2602563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
26034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks
260456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_begin() { return child_iterator(); }
260556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_end() { return child_iterator(); }
26064eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
26079da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();}
26089da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); }
2609