Expr.cpp revision 369e51fa400aeb5835bb9af4634ea516c11429a7
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.cpp - Expression AST Node Implementation --------------------===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements the Expr class and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar#include "clang/AST/Expr.h"
150979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor#include "clang/AST/ExprCXX.h"
16a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/APValue.h"
172eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner#include "clang/AST/ASTContext.h"
18a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/DeclObjC.h"
1998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor#include "clang/AST/DeclCXX.h"
20aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h"
2119cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h"
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/StmtVisitor.h"
231b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h"
24da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h"
25cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor#include "llvm/Support/ErrorHandling.h"
263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson#include "llvm/Support/raw_ostream.h"
27ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm>
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang;
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
30bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattnervoid Expr::ANCHOR() {} // key function for Expr class.
31bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner
322b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// isKnownToHaveBooleanValue - Return true if this is an integer expression
332b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// that is known to return 0 or 1.  This happens for _Bool/bool expressions
342b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// but also int expressions which are produced by things like comparisons in
352b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner/// C.
362b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerbool Expr::isKnownToHaveBooleanValue() const {
372b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  // If this value has _Bool type, it is obvious 0/1.
382b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  if (getType()->isBooleanType()) return true;
39c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // If this is a non-scalar-integer type, we don't care enough to try.
402ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  if (!getType()->isIntegralOrEnumerationType()) return false;
41c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
422b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  if (const ParenExpr *PE = dyn_cast<ParenExpr>(this))
432b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    return PE->getSubExpr()->isKnownToHaveBooleanValue();
44c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
452b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(this)) {
462b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    switch (UO->getOpcode()) {
472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Plus:
482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Extension:
492b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner      return UO->getSubExpr()->isKnownToHaveBooleanValue();
502b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    default:
512b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner      return false;
522b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    }
532b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  }
54c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
556907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall  // Only look through implicit casts.  If the user writes
566907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall  // '(int) (a && b)' treat it as an arbitrary int.
576907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall  if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(this))
582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    return CE->getSubExpr()->isKnownToHaveBooleanValue();
59c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
602b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(this)) {
612b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    switch (BO->getOpcode()) {
622b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    default: return false;
632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_LT:   // Relational operators.
642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_GT:
652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_LE:
662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_GE:
672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_EQ:   // Equality operators.
682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_NE:
692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_LAnd: // AND operator.
702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_LOr:  // Logical OR operator.
712b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner      return true;
72c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_And:  // Bitwise AND operator.
742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_Xor:  // Bitwise XOR operator.
752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_Or:   // Bitwise OR operator.
762b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner      // Handle things like (x==2)|(y==12).
772b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner      return BO->getLHS()->isKnownToHaveBooleanValue() &&
782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner             BO->getRHS()->isKnownToHaveBooleanValue();
79c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_Comma:
812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case BO_Assign:
822b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner      return BO->getRHS()->isKnownToHaveBooleanValue();
832b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    }
842b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  }
85c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
862b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(this))
872b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    return CO->getTrueExpr()->isKnownToHaveBooleanValue() &&
882b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner           CO->getFalseExpr()->isKnownToHaveBooleanValue();
89c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
902b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  return false;
912b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner}
922b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
97d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::initializeFrom(
98d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                      const TemplateArgumentListInfo &Info) {
99d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  LAngleLoc = Info.getLAngleLoc();
100d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  RAngleLoc = Info.getRAngleLoc();
101d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  NumTemplateArgs = Info.size();
102d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
103d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  TemplateArgumentLoc *ArgBuffer = getTemplateArgs();
104d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  for (unsigned i = 0; i != NumTemplateArgs; ++i)
105d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
106d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall}
107d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
108d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallvoid ExplicitTemplateArgumentList::copyInto(
109d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                      TemplateArgumentListInfo &Info) const {
110d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  Info.setLAngleLoc(LAngleLoc);
111d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  Info.setRAngleLoc(RAngleLoc);
112d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  for (unsigned I = 0; I != NumTemplateArgs; ++I)
113d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    Info.addArgument(getTemplateArgs()[I]);
114d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall}
115d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1168dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidisstd::size_t ExplicitTemplateArgumentList::sizeFor(unsigned NumTemplateArgs) {
1178dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  return sizeof(ExplicitTemplateArgumentList) +
1188dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis         sizeof(TemplateArgumentLoc) * NumTemplateArgs;
1198dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis}
1208dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
121d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallstd::size_t ExplicitTemplateArgumentList::sizeFor(
122d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                      const TemplateArgumentListInfo &Info) {
1238dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  return sizeFor(Info.size());
124d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall}
125d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1260da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregorvoid DeclRefExpr::computeDependence() {
1270da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  TypeDependent = false;
1280da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  ValueDependent = false;
129c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1300da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  NamedDecl *D = getDecl();
1310da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor
1320da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  // (TD) C++ [temp.dep.expr]p3:
1330da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //   An id-expression is type-dependent if it contains:
1340da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //
135c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // and
1360da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //
1370da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  // (VD) C++ [temp.dep.constexpr]p2:
1380da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //  An identifier is value-dependent if it is:
1390da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor
1400da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //  (TD)  - an identifier that was declared with dependent type
1410da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //  (VD)  - a name declared with a dependent type,
1420da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  if (getType()->isDependentType()) {
1430da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    TypeDependent = true;
1440da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    ValueDependent = true;
1450da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
1460da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //  (TD)  - a conversion-function-id that specifies a dependent type
147c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  else if (D->getDeclName().getNameKind()
1480da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                               == DeclarationName::CXXConversionFunctionName &&
1490da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor           D->getDeclName().getCXXNameType()->isDependentType()) {
1500da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    TypeDependent = true;
1510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    ValueDependent = true;
1520da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
1530da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //  (TD)  - a template-id that is dependent,
154096832c5ed5b9106fa177ebc148489760c3bc496John McCall  else if (hasExplicitTemplateArgs() &&
1550da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor           TemplateSpecializationType::anyDependentTemplateArguments(
156c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                                       getTemplateArgs(),
1570da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                                                       getNumTemplateArgs())) {
1580da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    TypeDependent = true;
1590da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    ValueDependent = true;
1600da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
1610da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //  (VD)  - the name of a non-type template parameter,
1620da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  else if (isa<NonTypeTemplateParmDecl>(D))
1630da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    ValueDependent = true;
1640da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //  (VD) - a constant with integral or enumeration type and is
1650da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //         initialized with an expression that is value-dependent.
1660da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  else if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
1672ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor    if (Var->getType()->isIntegralOrEnumerationType() &&
168501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor        Var->getType().getCVRQualifiers() == Qualifiers::Const) {
16931310a21fb2a9f13950f864f681c86080b05d5b2Sebastian Redl      if (const Expr *Init = Var->getAnyInitializer())
170501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor        if (Init->isValueDependent())
171501edb6a54524555ad27fbf41a7920dc756b08c6Douglas Gregor          ValueDependent = true;
172bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    }
173bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    // (VD) - FIXME: Missing from the standard:
174bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    //      -  a member function or a static data member of the current
175bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    //         instantiation
176bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    else if (Var->isStaticDataMember() &&
1777ed5bd3e27a6f2b37ee0449aa818116cbd03306eDouglas Gregor             Var->getDeclContext()->isDependentContext())
178bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor      ValueDependent = true;
179bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor  }
180bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor  // (VD) - FIXME: Missing from the standard:
181bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor  //      -  a member function or a static data member of the current
182bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor  //         instantiation
183bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor  else if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext())
184bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    ValueDependent = true;
1850da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //  (TD)  - a nested-name-specifier or a qualified-id that names a
1860da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //          member of an unknown specialization.
1870da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  //        (handled by DependentScopeDeclRefExpr)
1880da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor}
1890da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor
190c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier,
191a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                         SourceRange QualifierRange,
192dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall                         ValueDecl *D, SourceLocation NameLoc,
193d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                         const TemplateArgumentListInfo *TemplateArgs,
1940da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                         QualType T)
1950da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  : Expr(DeclRefExprClass, T, false, false),
196a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    DecoratedD(D,
197a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor               (Qualifier? HasQualifierFlag : 0) |
198d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall               (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)),
199a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    Loc(NameLoc) {
200a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (Qualifier) {
201a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NameQualifier *NQ = getNameQualifier();
202a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NQ->NNS = Qualifier;
203a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NQ->Range = QualifierRange;
204a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
205c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
206d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  if (TemplateArgs)
207096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().initializeFrom(*TemplateArgs);
208a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
2090da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  computeDependence();
210a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}
211a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
2122577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier,
2132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                         SourceRange QualifierRange,
2142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                         ValueDecl *D, const DeclarationNameInfo &NameInfo,
2152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                         const TemplateArgumentListInfo *TemplateArgs,
2162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                         QualType T)
2172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  : Expr(DeclRefExprClass, T, false, false),
2182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    DecoratedD(D,
2192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara               (Qualifier? HasQualifierFlag : 0) |
2202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara               (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)),
2212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) {
2222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (Qualifier) {
2232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NameQualifier *NQ = getNameQualifier();
2242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NQ->NNS = Qualifier;
2252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NQ->Range = QualifierRange;
2262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
2272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
2282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  if (TemplateArgs)
229096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().initializeFrom(*TemplateArgs);
2302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
2312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  computeDependence();
2322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara}
2332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
234a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorDeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
235a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                                 NestedNameSpecifier *Qualifier,
236a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                                 SourceRange QualifierRange,
237dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall                                 ValueDecl *D,
238a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                                 SourceLocation NameLoc,
2390da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                                 QualType T,
2400da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                                 const TemplateArgumentListInfo *TemplateArgs) {
2412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return Create(Context, Qualifier, QualifierRange, D,
2422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                DeclarationNameInfo(D->getDeclName(), NameLoc),
2432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                T, TemplateArgs);
2442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara}
2452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
2462577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
2472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                 NestedNameSpecifier *Qualifier,
2482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                 SourceRange QualifierRange,
2492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                 ValueDecl *D,
2502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                 const DeclarationNameInfo &NameInfo,
2512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                 QualType T,
2522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                 const TemplateArgumentListInfo *TemplateArgs) {
253a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  std::size_t Size = sizeof(DeclRefExpr);
254a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (Qualifier != 0)
255a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    Size += sizeof(NameQualifier);
256c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
257d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  if (TemplateArgs)
258d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
259c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
260a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>());
2612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameInfo,
2620da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                               TemplateArgs, T);
263a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}
264a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
265663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios KyrtzidisDeclRefExpr *DeclRefExpr::CreateEmpty(ASTContext &Context, bool HasQualifier,
266663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis                                      unsigned NumTemplateArgs) {
267663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  std::size_t Size = sizeof(DeclRefExpr);
268663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  if (HasQualifier)
269663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis    Size += sizeof(NameQualifier);
270663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
271663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  if (NumTemplateArgs)
272663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis    Size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
273663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
274663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>());
275663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  return new (Mem) DeclRefExpr(EmptyShell());
276663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis}
277663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
278a2813cec2605ce7878d1b13471d685f689b251afDouglas GregorSourceRange DeclRefExpr::getSourceRange() const {
2792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceRange R = getNameInfo().getSourceRange();
280a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  if (hasQualifier())
281a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    R.setBegin(getQualifierRange().getBegin());
282096832c5ed5b9106fa177ebc148489760c3bc496John McCall  if (hasExplicitTemplateArgs())
283a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    R.setEnd(getRAngleLoc());
284a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  return R;
285a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}
286a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
2873a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// FIXME: Maybe this should use DeclPrinter with a special "print predefined
2883a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson// expr" policy instead.
289848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlssonstd::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) {
290848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson  ASTContext &Context = CurrentDecl->getASTContext();
291848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson
2923a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) {
293848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual)
2943a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      return FD->getNameAsString();
2953a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
2963a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    llvm::SmallString<256> Name;
2973a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    llvm::raw_svector_ostream Out(Name);
2983a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
2993a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
300848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson      if (MD->isVirtual() && IT != PrettyFunctionNoVirtual)
3013a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        Out << "virtual ";
3024eadcc569223135e13353c9381b448986e3f7053Sam Weinig      if (MD->isStatic())
3034eadcc569223135e13353c9381b448986e3f7053Sam Weinig        Out << "static ";
3043a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    }
3053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
3063a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    PrintingPolicy Policy(Context.getLangOptions());
3073a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
3083a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    std::string Proto = FD->getQualifiedNameAsString(Policy);
3093a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
310183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    const FunctionType *AFT = FD->getType()->getAs<FunctionType>();
3113a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    const FunctionProtoType *FT = 0;
3123a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    if (FD->hasWrittenPrototype())
3133a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      FT = dyn_cast<FunctionProtoType>(AFT);
3143a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
3153a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Proto += "(";
3163a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    if (FT) {
3173a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      llvm::raw_string_ostream POut(Proto);
3183a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) {
3193a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        if (i) POut << ", ";
3203a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        std::string Param;
3213a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        FD->getParamDecl(i)->getType().getAsStringInternal(Param, Policy);
3223a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        POut << Param;
3233a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      }
3243a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
3253a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      if (FT->isVariadic()) {
3263a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        if (FD->getNumParams()) POut << ", ";
3273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson        POut << "...";
3283a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson      }
3293a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    }
3303a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Proto += ")";
3313a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
3324eadcc569223135e13353c9381b448986e3f7053Sam Weinig    if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
3334eadcc569223135e13353c9381b448986e3f7053Sam Weinig      Qualifiers ThisQuals = Qualifiers::fromCVRMask(MD->getTypeQualifiers());
3344eadcc569223135e13353c9381b448986e3f7053Sam Weinig      if (ThisQuals.hasConst())
3354eadcc569223135e13353c9381b448986e3f7053Sam Weinig        Proto += " const";
3364eadcc569223135e13353c9381b448986e3f7053Sam Weinig      if (ThisQuals.hasVolatile())
3374eadcc569223135e13353c9381b448986e3f7053Sam Weinig        Proto += " volatile";
3384eadcc569223135e13353c9381b448986e3f7053Sam Weinig    }
3394eadcc569223135e13353c9381b448986e3f7053Sam Weinig
3403a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig    if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD))
3413a1ce1ed0f5686384e712837bad28c576622e442Sam Weinig      AFT->getResultType().getAsStringInternal(Proto, Policy);
3423a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
3433a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out << Proto;
3443a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
3453a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out.flush();
3463a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    return Name.str().str();
3473a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  }
3483a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) {
3493a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    llvm::SmallString<256> Name;
3503a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    llvm::raw_svector_ostream Out(Name);
3513a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out << (MD->isInstanceMethod() ? '-' : '+');
3523a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out << '[';
353b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek
354b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek    // For incorrect code, there might not be an ObjCInterfaceDecl.  Do
355b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek    // a null check to avoid a crash.
356b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek    if (const ObjCInterfaceDecl *ID = MD->getClassInterface())
357900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer      Out << ID;
358b03d33edaf24af2893a50caee4d2c99839242c44Ted Kremenek
3593a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    if (const ObjCCategoryImplDecl *CID =
360900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer        dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext()))
361900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer      Out << '(' << CID << ')';
362900fc6388e803868a34b9483510c345e9b49d7ebBenjamin Kramer
3633a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out <<  ' ';
3643a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out << MD->getSelector().getAsString();
3653a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out <<  ']';
3663a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
3673a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    Out.flush();
3683a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    return Name.str().str();
3693a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  }
3703a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  if (isa<TranslationUnitDecl>(CurrentDecl) && IT == PrettyFunction) {
3713a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string.
3723a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson    return "top level";
3733a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  }
3743a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  return "";
3753a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson}
3763a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
3779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisvoid APNumericStorage::setIntValue(ASTContext &C, const llvm::APInt &Val) {
3789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  if (hasAllocation())
3799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    C.Deallocate(pVal);
3809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
3819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  BitWidth = Val.getBitWidth();
3829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  unsigned NumWords = Val.getNumWords();
3839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  const uint64_t* Words = Val.getRawData();
3849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  if (NumWords > 1) {
3859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    pVal = new (C) uint64_t[NumWords];
3869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    std::copy(Words, Words + NumWords, pVal);
3879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  } else if (NumWords == 1)
3889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    VAL = Words[0];
3899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  else
3909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    VAL = 0;
3919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}
3929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
3939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral *
3949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, const llvm::APInt &V,
3959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                       QualType type, SourceLocation l) {
3969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  return new (C) IntegerLiteral(C, V, type, l);
3979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}
3989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
3999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral *
4009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisIntegerLiteral::Create(ASTContext &C, EmptyShell Empty) {
4019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  return new (C) IntegerLiteral(Empty);
4029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}
4039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
4049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral *
4059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, const llvm::APFloat &V,
4069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                        bool isexact, QualType Type, SourceLocation L) {
4079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  return new (C) FloatingLiteral(C, V, isexact, Type, L);
4089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}
4099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
4109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral *
4119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios KyrtzidisFloatingLiteral::Create(ASTContext &C, EmptyShell Empty) {
4129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  return new (C) FloatingLiteral(Empty);
4139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}
4149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
415da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate
416da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double.  Note that this may cause loss of precision, but is useful for
417da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc.
418da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const {
419da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  llvm::APFloat V = getValue();
420ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen  bool ignored;
421ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen  V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven,
422ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen            &ignored);
423da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  return V.convertToDouble();
424da8249e57f3badecf925571881fe57243935c6c1Chris Lattner}
425da8249e57f3badecf925571881fe57243935c6c1Chris Lattner
4262085fd6cd22ec5c268175251db10d7c60caf7aaaChris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData,
4272085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                                     unsigned ByteLength, bool Wide,
4282085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                                     QualType Ty,
4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                     const SourceLocation *Loc,
430a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                                     unsigned NumStrs) {
4312085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  // Allocate enough space for the StringLiteral plus an array of locations for
4322085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  // any concatenated string tokens.
4332085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  void *Mem = C.Allocate(sizeof(StringLiteral)+
4342085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                         sizeof(SourceLocation)*(NumStrs-1),
4352085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                         llvm::alignof<StringLiteral>());
4362085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  StringLiteral *SL = new (Mem) StringLiteral(Ty);
4371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // OPTIMIZE: could allocate this appended to the StringLiteral.
4392085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  char *AStrData = new (C, 1) char[ByteLength];
4402085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  memcpy(AStrData, StrData, ByteLength);
4412085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->StrData = AStrData;
4422085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->ByteLength = ByteLength;
4432085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->IsWide = Wide;
4442085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->TokLocs[0] = Loc[0];
4452085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  SL->NumConcatenated = NumStrs;
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
447726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  if (NumStrs != 1)
4482085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1));
4492085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  return SL;
450726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner}
451726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner
452673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) {
453673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void *Mem = C.Allocate(sizeof(StringLiteral)+
454673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor                         sizeof(SourceLocation)*(NumStrs-1),
455673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor                         llvm::alignof<StringLiteral>());
456673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  StringLiteral *SL = new (Mem) StringLiteral(QualType());
457673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  SL->StrData = 0;
458673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  SL->ByteLength = 0;
459673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  SL->NumConcatenated = NumStrs;
460673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  return SL;
461673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor}
462673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
463b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbarvoid StringLiteral::setString(ASTContext &C, llvm::StringRef Str) {
464b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  char *AStrData = new (C, 1) char[Str.size()];
465b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  memcpy(AStrData, Str.data(), Str.size());
466673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  StrData = AStrData;
467b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  ByteLength = Str.size();
468673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor}
469673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++".
4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) {
4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default: assert(0 && "Unknown unary operator");
4752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_PostInc: return "++";
4762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_PostDec: return "--";
4772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_PreInc:  return "++";
4782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_PreDec:  return "--";
4792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_AddrOf:  return "&";
4802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Deref:   return "*";
4812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Plus:    return "+";
4822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Minus:   return "-";
4832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Not:     return "~";
4842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_LNot:    return "!";
4852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Real:    return "__real";
4862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Imag:    return "__imag";
4872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Extension: return "__extension__";
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallUnaryOperatorKind
492bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) {
493bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  switch (OO) {
494bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  default: assert(false && "No unary operator for overloaded function");
4952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_PlusPlus:   return Postfix ? UO_PostInc : UO_PreInc;
4962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec;
4972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Amp:        return UO_AddrOf;
4982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Star:       return UO_Deref;
4992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Plus:       return UO_Plus;
5002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Minus:      return UO_Minus;
5012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Tilde:      return UO_Not;
5022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Exclaim:    return UO_LNot;
503bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  }
504bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor}
505bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
506bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) {
507bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  switch (Opc) {
5082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_PostInc: case UO_PreInc: return OO_PlusPlus;
5092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_PostDec: case UO_PreDec: return OO_MinusMinus;
5102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_AddrOf: return OO_Amp;
5112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Deref: return OO_Star;
5122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Plus: return OO_Plus;
5132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Minus: return OO_Minus;
5142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_Not: return OO_Tilde;
5152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case UO_LNot: return OO_Exclaim;
516bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  default: return OO_None;
517bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  }
518bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor}
519bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
520bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
525668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args,
5268189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek                   unsigned numargs, QualType t, SourceLocation rparenloc)
5271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Expr(SC, t,
528898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs),
529d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner         fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)),
530898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    NumArgs(numargs) {
5311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
532668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  SubExprs = new (C) Stmt*[numargs+1];
533b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  SubExprs[FN] = fn;
534b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  for (unsigned i = 0; i != numargs; ++i)
535b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    SubExprs[i+ARGS_START] = args[i];
536668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
537b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  RParenLoc = rparenloc;
538b4609806e9232593ece09ce08b630836e825865cDouglas Gregor}
539e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman
540668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs,
541668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek                   QualType t, SourceLocation rparenloc)
542898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  : Expr(CallExprClass, t,
543898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs),
544d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner         fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)),
545898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    NumArgs(numargs) {
546668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
547668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  SubExprs = new (C) Stmt*[numargs+1];
54877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  SubExprs[FN] = fn;
5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  for (unsigned i = 0; i != numargs; ++i)
55077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    SubExprs[i+ARGS_START] = args[i];
551668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RParenLoc = rparenloc;
5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty)
5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Expr(SC, Empty), SubExprs(0), NumArgs(0) {
5571f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  SubExprs = new (C) Stmt*[1];
5581f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor}
5591f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
560d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesDecl *CallExpr::getCalleeDecl() {
561a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  Expr *CEE = getCallee()->IgnoreParenCasts();
562200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl  // If we're calling a dereference, look at the pointer instead.
563200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl  if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) {
564200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl    if (BO->isPtrMemOp())
565200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl      CEE = BO->getRHS()->IgnoreParenCasts();
566200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl  } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) {
567200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl    if (UO->getOpcode() == UO_Deref)
568200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl      CEE = UO->getSubExpr()->IgnoreParenCasts();
569200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl  }
5706346f963145ed18b6edf50a78753b47db505e912Chris Lattner  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
571d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return DRE->getDecl();
572cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes  if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
573cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes    return ME->getMemberDecl();
574a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
575a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  return 0;
576a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu}
577a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
578d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() {
579caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner  return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
580d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes}
581d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes
582d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call.
583d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set
584d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null.
5858189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) {
586d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // No change, just return.
587d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs == getNumArgs()) return;
5881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
589d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // If shrinking # arguments, just delete the extras and forgot them.
590d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs < getNumArgs()) {
591d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    this->NumArgs = NumArgs;
592d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    return;
593d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  }
594d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
595d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Otherwise, we are growing the # arguments.  New an bigger argument array.
59668a049cab6015a7437bec5661601b7d37d23c70cDaniel Dunbar  Stmt **NewSubExprs = new (C) Stmt*[NumArgs+1];
597d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Copy over args.
598d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i)
599d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = SubExprs[i];
600d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Null out new args.
601d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
602d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = 0;
6031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60488c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor  if (SubExprs) C.Deallocate(SubExprs);
605d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SubExprs = NewSubExprs;
606d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  this->NumArgs = NumArgs;
607d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner}
608d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
609cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
610cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0.
6113c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregorunsigned CallExpr::isBuiltinCall(ASTContext &Context) const {
612c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // All simple function calls (e.g. func()) are implicitly cast to pointer to
6131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // function. As a result, we try and obtain the DeclRefExpr from the
614c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // ImplicitCastExpr.
615c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
616c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
617cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
6181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
619c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
620c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!DRE)
621cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
623bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
624bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  if (!FDecl)
625cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
6261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6274fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor  if (!FDecl->getIdentifier())
6284fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor    return 0;
6294fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor
6307814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor  return FDecl->getBuiltinID();
631cb888967400a03504c88acedd5248d6778a82f46Chris Lattner}
632bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson
6336dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const {
6346dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  QualType CalleeType = getCallee()->getType();
6356217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>())
6366dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson    CalleeType = FnTypePtr->getPointeeType();
6376217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>())
6386dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson    CalleeType = BPT->getPointeeType();
6395291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  else if (const MemberPointerType *MPT
6405291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor                                      = CalleeType->getAs<MemberPointerType>())
6415291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor    CalleeType = MPT->getPointeeType();
6425291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
643183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  const FunctionType *FnType = CalleeType->getAs<FunctionType>();
6446dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  return FnType->getResultType();
6456dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson}
646cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
647c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type,
6488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   SourceLocation OperatorLoc,
649c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                   TypeSourceInfo *tsi,
650c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                   OffsetOfNode* compsPtr, unsigned numComps,
6518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   Expr** exprsPtr, unsigned numExprs,
6528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   SourceLocation RParenLoc) {
6538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void *Mem = C.Allocate(sizeof(OffsetOfExpr) +
654c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                         sizeof(OffsetOfNode) * numComps +
6558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                         sizeof(Expr*) * numExprs);
6568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
6578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps,
6588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                exprsPtr, numExprs, RParenLoc);
6598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
6608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
6618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C,
6628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                        unsigned numComps, unsigned numExprs) {
6638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void *Mem = C.Allocate(sizeof(OffsetOfExpr) +
6648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                         sizeof(OffsetOfNode) * numComps +
6658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                         sizeof(Expr*) * numExprs);
6668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return new (Mem) OffsetOfExpr(numComps, numExprs);
6678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
6688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
669c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type,
6708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                           SourceLocation OperatorLoc, TypeSourceInfo *tsi,
671c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                           OffsetOfNode* compsPtr, unsigned numComps,
6728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                           Expr** exprsPtr, unsigned numExprs,
6738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                           SourceLocation RParenLoc)
674c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  : Expr(OffsetOfExprClass, type, /*TypeDependent=*/false,
6758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor         /*ValueDependent=*/tsi->getType()->isDependentType() ||
6768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor         hasAnyTypeDependentArguments(exprsPtr, numExprs) ||
6778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor         hasAnyValueDependentArguments(exprsPtr, numExprs)),
678c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi),
679c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    NumComps(numComps), NumExprs(numExprs)
6808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{
6818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for(unsigned i = 0; i < numComps; ++i) {
6828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    setComponent(i, compsPtr[i]);
6838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
684c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for(unsigned i = 0; i < numExprs; ++i) {
6868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    setIndexExpr(i, exprsPtr[i]);
6878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
6888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
6898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
6908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const {
6918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  assert(getKind() == Field || getKind() == Identifier);
6928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (getKind() == Field)
6938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return getField()->getIdentifier();
694c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask);
6968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
6978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
6981eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow,
6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               NestedNameSpecifier *qual,
70083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                               SourceRange qualrange,
701f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman                               ValueDecl *memberdecl,
702161755a09898c95d21bfff33707da9ca41cd53c5John McCall                               DeclAccessPair founddecl,
7032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                               DeclarationNameInfo nameinfo,
704d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                               const TemplateArgumentListInfo *targs,
705c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                               QualType ty) {
70683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  std::size_t Size = sizeof(MemberExpr);
7076bb8017bb9e828d118e15e59d71c66bba323c364John McCall
708161755a09898c95d21bfff33707da9ca41cd53c5John McCall  bool hasQualOrFound = (qual != 0 ||
709161755a09898c95d21bfff33707da9ca41cd53c5John McCall                         founddecl.getDecl() != memberdecl ||
710161755a09898c95d21bfff33707da9ca41cd53c5John McCall                         founddecl.getAccess() != memberdecl->getAccess());
7116bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (hasQualOrFound)
7126bb8017bb9e828d118e15e59d71c66bba323c364John McCall    Size += sizeof(MemberNameQualifier);
7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
714d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  if (targs)
715d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    Size += ExplicitTemplateArgumentList::sizeFor(*targs);
7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  void *Mem = C.Allocate(Size, llvm::alignof<MemberExpr>());
7182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, ty);
7196bb8017bb9e828d118e15e59d71c66bba323c364John McCall
7206bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (hasQualOrFound) {
7216bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (qual && qual->isDependent()) {
7226bb8017bb9e828d118e15e59d71c66bba323c364John McCall      E->setValueDependent(true);
7236bb8017bb9e828d118e15e59d71c66bba323c364John McCall      E->setTypeDependent(true);
7246bb8017bb9e828d118e15e59d71c66bba323c364John McCall    }
7256bb8017bb9e828d118e15e59d71c66bba323c364John McCall    E->HasQualifierOrFoundDecl = true;
7266bb8017bb9e828d118e15e59d71c66bba323c364John McCall
7276bb8017bb9e828d118e15e59d71c66bba323c364John McCall    MemberNameQualifier *NQ = E->getMemberQualifier();
7286bb8017bb9e828d118e15e59d71c66bba323c364John McCall    NQ->NNS = qual;
7296bb8017bb9e828d118e15e59d71c66bba323c364John McCall    NQ->Range = qualrange;
7306bb8017bb9e828d118e15e59d71c66bba323c364John McCall    NQ->FoundDecl = founddecl;
7316bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
7326bb8017bb9e828d118e15e59d71c66bba323c364John McCall
7336bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (targs) {
7346bb8017bb9e828d118e15e59d71c66bba323c364John McCall    E->HasExplicitTemplateArgumentList = true;
735096832c5ed5b9106fa177ebc148489760c3bc496John McCall    E->getExplicitTemplateArgs().initializeFrom(*targs);
7366bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
7376bb8017bb9e828d118e15e59d71c66bba323c364John McCall
7386bb8017bb9e828d118e15e59d71c66bba323c364John McCall  return E;
73983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor}
74083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
741f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const {
742f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  switch (getCastKind()) {
7432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_Unknown:
744f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "Unknown";
7452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_BitCast:
746f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "BitCast";
7472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_LValueBitCast:
748e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor    return "LValueBitCast";
7492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_NoOp:
750f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "NoOp";
7512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_BaseToDerived:
75211de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson    return "BaseToDerived";
7532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_DerivedToBase:
754f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "DerivedToBase";
7552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_UncheckedDerivedToBase:
75623cba801e11b03929c44f8cf54578305963a3476John McCall    return "UncheckedDerivedToBase";
7572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_Dynamic:
758f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "Dynamic";
7592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ToUnion:
760f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "ToUnion";
7612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ArrayToPointerDecay:
762f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "ArrayToPointerDecay";
7632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_FunctionToPointerDecay:
764f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "FunctionToPointerDecay";
7652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_NullToMemberPointer:
766f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "NullToMemberPointer";
7672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_BaseToDerivedMemberPointer:
768f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "BaseToDerivedMemberPointer";
7692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_DerivedToBaseMemberPointer:
7701a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    return "DerivedToBaseMemberPointer";
7712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_UserDefinedConversion:
772f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "UserDefinedConversion";
7732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ConstructorConversion:
774f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "ConstructorConversion";
7752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_IntegralToPointer:
7767f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    return "IntegralToPointer";
7772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_PointerToIntegral:
7787f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    return "PointerToIntegral";
7792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ToVoid:
780ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson    return "ToVoid";
7812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_VectorSplat:
78216a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson    return "VectorSplat";
7832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_IntegralCast:
78482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    return "IntegralCast";
7852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_IntegralToFloating:
78682debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    return "IntegralToFloating";
7872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_FloatingToIntegral:
78882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    return "FloatingToIntegral";
7892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_FloatingCast:
790c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer    return "FloatingCast";
7912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_MemberPointerToBoolean:
792bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson    return "MemberPointerToBoolean";
7932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_AnyPointerToObjCPointerCast:
7944cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian    return "AnyPointerToObjCPointerCast";
7952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_AnyPointerToBlockPointerCast:
7963b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    return "AnyPointerToBlockPointerCast";
7972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ObjCObjectLValueCast:
798569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    return "ObjCObjectLValueCast";
799f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  }
8001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
801f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  assert(0 && "Unhandled cast kind!");
802f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  return 0;
803f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson}
804f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
8056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() {
8066eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  Expr *SubExpr = 0;
8076eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  CastExpr *E = this;
8086eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  do {
8096eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    SubExpr = E->getSubExpr();
810c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8116eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // Skip any temporary bindings; they're implicit.
8126eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr))
8136eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      SubExpr = Binder->getSubExpr();
814c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // Conversions by constructor and conversion functions have a
8166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // subexpression describing the call; strip it off.
8172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (E->getCastKind() == CK_ConstructorConversion)
8186eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0);
8192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    else if (E->getCastKind() == CK_UserDefinedConversion)
8206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument();
821c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8226eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // If the subexpression we're left with is an implicit cast, look
8236eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // through that, too.
824c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr)));
825c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return SubExpr;
8276eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor}
8286eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
829f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCXXBaseSpecifier **CastExpr::path_buffer() {
830f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  switch (getStmtClass()) {
831f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define ABSTRACT_STMT(x)
832f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define CASTEXPR(Type, Base) \
833f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  case Stmt::Type##Class: \
834f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1);
835f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define STMT(Type, Base)
836f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#include "clang/AST/StmtNodes.inc"
837f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  default:
838f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    llvm_unreachable("non-cast expressions not possible here");
839f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return 0;
840f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  }
841f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
842f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
843f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallvoid CastExpr::setCastPath(const CXXCastPath &Path) {
844f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  assert(Path.size() == path_size());
845f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*));
846f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
847f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
848f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T,
849f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                           CastKind Kind, Expr *Operand,
850f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                           const CXXCastPath *BasePath,
8515baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                                           ExprValueKind VK) {
852f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  unsigned PathSize = (BasePath ? BasePath->size() : 0);
853f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void *Buffer =
854f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
855f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  ImplicitCastExpr *E =
8565baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK);
857f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  if (PathSize) E->setCastPath(*BasePath);
858f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  return E;
859f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
860f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
861f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C,
862f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                                unsigned PathSize) {
863f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void *Buffer =
864f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
865f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize);
866f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
867f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
868f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
869f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T,
870f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       CastKind K, Expr *Op,
871f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       const CXXCastPath *BasePath,
872f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       TypeSourceInfo *WrittenTy,
873f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation L, SourceLocation R) {
874f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  unsigned PathSize = (BasePath ? BasePath->size() : 0);
875f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void *Buffer =
876f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
877f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CStyleCastExpr *E =
878f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    new (Buffer) CStyleCastExpr(T, K, Op, PathSize, WrittenTy, L, R);
879f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  if (PathSize) E->setCastPath(*BasePath);
880f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  return E;
881f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
882f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
883f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
884f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void *Buffer =
885f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
886f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize);
887f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
888f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=".
8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) {
8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
8932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_PtrMemD:   return ".*";
8942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_PtrMemI:   return "->*";
8952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Mul:       return "*";
8962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Div:       return "/";
8972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Rem:       return "%";
8982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Add:       return "+";
8992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Sub:       return "-";
9002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Shl:       return "<<";
9012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Shr:       return ">>";
9022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_LT:        return "<";
9032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_GT:        return ">";
9042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_LE:        return "<=";
9052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_GE:        return ">=";
9062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_EQ:        return "==";
9072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_NE:        return "!=";
9082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_And:       return "&";
9092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Xor:       return "^";
9102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Or:        return "|";
9112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_LAnd:      return "&&";
9122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_LOr:       return "||";
9132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Assign:    return "=";
9142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_MulAssign: return "*=";
9152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_DivAssign: return "/=";
9162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_RemAssign: return "%=";
9172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_AddAssign: return "+=";
9182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_SubAssign: return "-=";
9192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_ShlAssign: return "<<=";
9202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_ShrAssign: return ">>=";
9212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_AndAssign: return "&=";
9222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_XorAssign: return "^=";
9232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_OrAssign:  return "|=";
9242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Comma:     return ",";
9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
926baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor
927baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor  return "";
9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallBinaryOperatorKind
931063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) {
932063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  switch (OO) {
933b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  default: assert(false && "Not an overloadable binary operator");
9342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Plus: return BO_Add;
9352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Minus: return BO_Sub;
9362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Star: return BO_Mul;
9372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Slash: return BO_Div;
9382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Percent: return BO_Rem;
9392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Caret: return BO_Xor;
9402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Amp: return BO_And;
9412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Pipe: return BO_Or;
9422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Equal: return BO_Assign;
9432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Less: return BO_LT;
9442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Greater: return BO_GT;
9452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_PlusEqual: return BO_AddAssign;
9462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_MinusEqual: return BO_SubAssign;
9472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_StarEqual: return BO_MulAssign;
9482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_SlashEqual: return BO_DivAssign;
9492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_PercentEqual: return BO_RemAssign;
9502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_CaretEqual: return BO_XorAssign;
9512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_AmpEqual: return BO_AndAssign;
9522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_PipeEqual: return BO_OrAssign;
9532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_LessLess: return BO_Shl;
9542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_GreaterGreater: return BO_Shr;
9552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_LessLessEqual: return BO_ShlAssign;
9562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_GreaterGreaterEqual: return BO_ShrAssign;
9572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_EqualEqual: return BO_EQ;
9582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_ExclaimEqual: return BO_NE;
9592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_LessEqual: return BO_LE;
9602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_GreaterEqual: return BO_GE;
9612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_AmpAmp: return BO_LAnd;
9622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_PipePipe: return BO_LOr;
9632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Comma: return BO_Comma;
9642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_ArrowStar: return BO_PtrMemI;
965063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  }
966063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor}
967063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
968063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) {
969063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static const OverloadedOperatorKind OverOps[] = {
970063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    /* .* Cannot be overloaded */OO_None, OO_ArrowStar,
971063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Star, OO_Slash, OO_Percent,
972063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Plus, OO_Minus,
973063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_LessLess, OO_GreaterGreater,
974063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual,
975063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_EqualEqual, OO_ExclaimEqual,
976063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Amp,
977063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Caret,
978063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Pipe,
979063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_AmpAmp,
980063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_PipePipe,
981063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Equal, OO_StarEqual,
982063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_SlashEqual, OO_PercentEqual,
983063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_PlusEqual, OO_MinusEqual,
984063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_LessLessEqual, OO_GreaterGreaterEqual,
985063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_AmpEqual, OO_CaretEqual,
986063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_PipeEqual,
987063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Comma
988063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  };
989063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return OverOps[Opc];
990063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor}
991063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
992709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc,
993418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner                           Expr **initExprs, unsigned numInits,
9944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor                           SourceLocation rbraceloc)
99573460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor  : Expr(InitListExprClass, QualType(), false, false),
996709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    InitExprs(C, numInits),
9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0),
998c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    UnionFieldInit(0), HadArrayRangeDesignator(false)
999c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt{
1000ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  for (unsigned I = 0; I != numInits; ++I) {
1001ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    if (initExprs[I]->isTypeDependent())
100273460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor      TypeDependent = true;
1003ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    if (initExprs[I]->isValueDependent())
100473460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor      ValueDependent = true;
100573460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor  }
1006c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1007709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits);
100866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1010709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) {
1011ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  if (NumInits > InitExprs.size())
1012709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    InitExprs.reserve(C, NumInits);
1013fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor}
1014fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor
1015709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) {
1016709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitExprs.resize(C, NumInits, 0);
10174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor}
10184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
1019709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) {
1020ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  if (Init >= InitExprs.size()) {
1021709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0);
1022ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    InitExprs.back() = expr;
1023ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    return 0;
10244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *Result = cast_or_null<Expr>(InitExprs[Init]);
10274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitExprs[Init] = expr;
10284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  return Result;
10294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor}
10304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
1031bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block.
10324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff///
10334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const {
10346217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  return getType()->getAs<BlockPointerType>()->
1035183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall                    getPointeeType()->getAs<FunctionType>();
10364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}
10374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
10381eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const {
10391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return TheBlock->getCaretLocation();
104056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff}
10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const {
10427297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  return TheBlock->getBody();
10437297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor}
10441eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() {
10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return TheBlock->getBody();
10467297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor}
104756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
104856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines
10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1053026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should
1054026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused.  If so, fill in Loc and Ranges
1055026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the
1056026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning.
1057026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattnerbool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
1058df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump                                  SourceRange &R2, ASTContext &Ctx) const {
1059ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson  // Don't warn if the expr is type dependent. The type could end up
1060ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson  // instantiating to void.
1061ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson  if (isTypeDependent())
1062ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson    return false;
10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
10660faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall    if (getType()->isVoidType())
10670faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall      return false;
1068026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = getExprLoc();
1069026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = getSourceRange();
1070026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass:
1072026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return cast<ParenExpr>(this)->getSubExpr()->
1073df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      isUnusedResultAWarning(Loc, R1, R2, Ctx);
10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UnaryOperatorClass: {
10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const UnaryOperator *UO = cast<UnaryOperator>(this);
10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (UO->getOpcode()) {
1078026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    default: break;
10792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_PostInc:
10802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_PostDec:
10812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_PreInc:
10822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_PreDec:                 // ++/--
1083026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;  // Not a warning.
10842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Deref:
10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // Dereferencing a volatile pointer is a side-effect.
1086df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      if (Ctx.getCanonicalType(getType()).isVolatileQualified())
1087026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner        return false;
1088026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      break;
10892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Real:
10902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Imag:
10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // accessing a piece of a volatile complex is a side-effect.
1092df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      if (Ctx.getCanonicalType(UO->getSubExpr()->getType())
1093df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump          .isVolatileQualified())
1094026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner        return false;
1095026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      break;
10962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Extension:
1097df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1099026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = UO->getOperatorLoc();
1100026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = UO->getSubExpr()->getSourceRange();
1101026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1103e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  case BinaryOperatorClass: {
1104026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    const BinaryOperator *BO = cast<BinaryOperator>(this);
1105c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek    switch (BO->getOpcode()) {
1106c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek      default:
1107c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek        break;
110825973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis      // Consider the RHS of comma for side effects. LHS was checked by
110925973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis      // Sema::CheckCommaOperands.
11102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      case BO_Comma:
1111c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek        // ((foo = <blah>), 0) is an idiom for hiding the result (and
1112c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek        // lvalue-ness) of an assignment written in a macro.
1113c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek        if (IntegerLiteral *IE =
1114c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek              dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens()))
1115c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek          if (IE->getValue() == 0)
1116c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek            return false;
111725973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis        return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
111825973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis      // Consider '||', '&&' to have side effects if the LHS or RHS does.
11192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      case BO_LAnd:
11202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      case BO_LOr:
112125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis        if (!BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) ||
112225973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis            !BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx))
112325973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis          return false;
112425973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis        break;
1125bf0ee354163f87623a4b60412544243911332343John McCall    }
1126026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (BO->isAssignmentOp())
1127026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;
1128026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = BO->getOperatorLoc();
1129026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = BO->getLHS()->getSourceRange();
1130026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R2 = BO->getRHS()->getSourceRange();
1131026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
1132e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  }
1133eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner  case CompoundAssignOperatorClass:
1134c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor  case VAArgExprClass:
1135026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1137ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  case ConditionalOperatorClass: {
1138026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // The condition must be evaluated, but if either the LHS or RHS is a
1139026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // warning, warn about them.
1140ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (Exp->getLHS() &&
1142df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump        Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx))
1143026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return true;
1144df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
1145ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  }
1146ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian
11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case MemberExprClass:
1148026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // If the base pointer or element is to a volatile pointer/field, accessing
1149026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // it is a side effect.
1150df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    if (Ctx.getCanonicalType(getType()).isVolatileQualified())
1151026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;
1152026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<MemberExpr>(this)->getMemberLoc();
1153026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = SourceRange(Loc, Loc);
1154026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R2 = cast<MemberExpr>(this)->getBase()->getSourceRange();
1155026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ArraySubscriptExprClass:
11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // If the base pointer or element is to a volatile pointer/field, accessing
1159026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // it is a side effect.
1160df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    if (Ctx.getCanonicalType(getType()).isVolatileQualified())
1161026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;
1162026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc();
1163026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange();
1164026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange();
1165026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
1166211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman
11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case CallExprClass:
1168852871abbff45f1c1d3787755a27fce08365b166Eli Friedman  case CXXOperatorCallExprClass:
1169852871abbff45f1c1d3787755a27fce08365b166Eli Friedman  case CXXMemberCallExprClass: {
1170026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // If this is a direct call, get the callee.
1171026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    const CallExpr *CE = cast<CallExpr>(this);
1172d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    if (const Decl *FD = CE->getCalleeDecl()) {
1173026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      // If the callee has attribute pure, const, or warn_unused_result, warn
1174026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      // about it. void foo() { strlen("bar"); } should warn.
1175bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      //
1176bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      // Note: If new cases are added here, DiagnoseUnusedExprResult should be
1177bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      // updated to match for QoI.
1178bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      if (FD->getAttr<WarnUnusedResultAttr>() ||
1179bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner          FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) {
1180bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        Loc = CE->getCallee()->getLocStart();
1181bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        R1 = CE->getCallee()->getSourceRange();
1182bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner
1183bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        if (unsigned NumArgs = CE->getNumArgs())
1184bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner          R2 = SourceRange(CE->getArg(0)->getLocStart(),
1185bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner                           CE->getArg(NumArgs-1)->getLocEnd());
1186bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        return true;
1187bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      }
1188026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    }
1189026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
1190026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  }
119158beed91d468863b8c85bce43425422703838d27Anders Carlsson
119258beed91d468863b8c85bce43425422703838d27Anders Carlsson  case CXXTemporaryObjectExprClass:
119358beed91d468863b8c85bce43425422703838d27Anders Carlsson  case CXXConstructExprClass:
119458beed91d468863b8c85bce43425422703838d27Anders Carlsson    return false;
119558beed91d468863b8c85bce43425422703838d27Anders Carlsson
1196f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian  case ObjCMessageExprClass: {
1197f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian    const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this);
1198f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian    const ObjCMethodDecl *MD = ME->getMethodDecl();
1199f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian    if (MD && MD->getAttr<WarnUnusedResultAttr>()) {
1200f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian      Loc = getExprLoc();
1201f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian      return true;
1202f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian    }
1203026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
1204f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian  }
12051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
120609105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian  case ObjCImplicitSetterGetterRefExprClass: {   // Dot syntax for message send.
1207a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#if 0
12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const ObjCImplicitSetterGetterRefExpr *Ref =
120909105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian      cast<ObjCImplicitSetterGetterRefExpr>(this);
1210a50089ec68a583d13718107c1b0c898f0903709eChris Lattner    // FIXME: We really want the location of the '.' here.
1211154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian    Loc = Ref->getLocation();
1212154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian    R1 = SourceRange(Ref->getLocation(), Ref->getLocation());
1213154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian    if (Ref->getBase())
1214154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian      R2 = Ref->getBase()->getSourceRange();
12155e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner#else
12165e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner    Loc = getExprLoc();
12175e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner    R1 = getSourceRange();
1218a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#endif
1219a50089ec68a583d13718107c1b0c898f0903709eChris Lattner    return true;
1220a50089ec68a583d13718107c1b0c898f0903709eChris Lattner  }
1221611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner  case StmtExprClass: {
1222611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // Statement exprs don't logically have side effects themselves, but are
1223611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // sometimes used in macros in ways that give them a type that is unused.
1224611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // For example ({ blah; foo(); }) will end up with a type if foo has a type.
1225611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // however, if the result of the stmt expr is dead, we don't want to emit a
1226611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // warning.
1227611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
1228611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    if (!CS->body_empty())
1229611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner      if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
1230df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump        return E->isUnusedResultAWarning(Loc, R1, R2, Ctx);
12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12320faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall    if (getType()->isVoidType())
12330faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall      return false;
1234026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<StmtExpr>(this)->getLParenLoc();
1235026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = getSourceRange();
1236026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
1237611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner  }
12386eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  case CStyleCastExprClass:
1239fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner    // If this is an explicit cast to void, allow it.  People do this when they
1240fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner    // think they know what they're doing :).
1241026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (getType()->isVoidType())
1242fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner      return false;
1243026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<CStyleCastExpr>(this)->getLParenLoc();
1244026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange();
1245026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
124658beed91d468863b8c85bce43425422703838d27Anders Carlsson  case CXXFunctionalCastExprClass: {
12470faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall    if (getType()->isVoidType())
12480faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall      return false;
124958beed91d468863b8c85bce43425422703838d27Anders Carlsson    const CastExpr *CE = cast<CastExpr>(this);
1250c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
125158beed91d468863b8c85bce43425422703838d27Anders Carlsson    // If this is a cast to void or a constructor conversion, check the operand.
125258beed91d468863b8c85bce43425422703838d27Anders Carlsson    // Otherwise, the result of the cast is unused.
12532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (CE->getCastKind() == CK_ToVoid ||
12542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall        CE->getCastKind() == CK_ConstructorConversion)
1255df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      return (cast<CastExpr>(this)->getSubExpr()
1256df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump              ->isUnusedResultAWarning(Loc, R1, R2, Ctx));
1257026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc();
1258026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange();
1259026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
126058beed91d468863b8c85bce43425422703838d27Anders Carlsson  }
12611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12624be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman  case ImplicitCastExprClass:
12634be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman    // Check the operand, since implicit casts are inserted by Sema
1264df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<ImplicitCastExpr>(this)
1265df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
12664be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman
126704421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
1268df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<CXXDefaultArgExpr>(this)
1269df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
12704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  case CXXNewExprClass:
12724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    // FIXME: In theory, there might be new expressions that don't have side
12734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    // effects (e.g. a placement new with an uninitialized POD).
12744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  case CXXDeleteExprClass:
1275026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
12762d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson  case CXXBindTemporaryExprClass:
1277df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<CXXBindTemporaryExpr>(this)
1278df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
12796b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson  case CXXExprWithTemporariesClass:
1280df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<CXXExprWithTemporaries>(this)
1281df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
12824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
128544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able.
12867f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise.
1287102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const {
128844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  switch (getStmtClass()) {
128944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  default:
129044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return false;
129144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ObjCIvarRefExprClass:
129244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return true;
1293207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian  case Expr::UnaryOperatorClass:
1294102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
129544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ParenExprClass:
1296102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
129744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ImplicitCastExprClass:
1298102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
129906b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian  case CStyleCastExprClass:
1300102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
1301a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  case DeclRefExprClass: {
130244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    const Decl *D = cast<DeclRefExpr>(this)->getDecl();
1303102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1304102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian      if (VD->hasGlobalStorage())
1305102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian        return true;
1306102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian      QualType T = VD->getType();
130759a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian      // dereferencing to a  pointer is always a gc'able candidate,
130859a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian      // unless it is __weak.
13097e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar      return T->isPointerType() &&
13100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall             (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak);
1311102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    }
131244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return false;
131344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  }
131483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  case MemberExprClass: {
131544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    const MemberExpr *M = cast<MemberExpr>(this);
1316102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return M->getBase()->isOBJCGCCandidate(Ctx);
131744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  }
131844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ArraySubscriptExprClass:
1319102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx);
132044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  }
132144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian}
1322369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1323369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult MergeCanThrow(Expr::CanThrowResult CT1,
1324369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl                                          Expr::CanThrowResult CT2) {
1325369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  // CanThrowResult constants are ordered so that the maximum is the correct
1326369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  // merge result.
1327369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  return CT1 > CT2 ? CT1 : CT2;
1328369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl}
1329369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1330369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanSubExprsThrow(ASTContext &C, const Expr *CE) {
1331369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  Expr *E = const_cast<Expr*>(CE);
1332369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  Expr::CanThrowResult R = Expr::CT_Cannot;
1333369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  for (Expr::child_iterator I = E->child_begin(), IE = E->child_end();
1334369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl       I != IE && R != Expr::CT_Can; ++I) {
1335369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    R = MergeCanThrow(R, cast<Expr>(*I)->CanThrow(C));
1336369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  }
1337369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  return R;
1338369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl}
1339369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1340369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanCalleeThrow(const Decl *D,
1341369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl                                           bool NullThrows = true) {
1342369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if (!D)
1343369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return NullThrows ? Expr::CT_Can : Expr::CT_Cannot;
1344369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1345369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  // See if we can get a function type from the decl somehow.
1346369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  const ValueDecl *VD = dyn_cast<ValueDecl>(D);
1347369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if (!VD) // If we have no clue what we're calling, assume the worst.
1348369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return Expr::CT_Can;
1349369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1350369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  QualType T = VD->getType();
1351369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  const FunctionProtoType *FT;
1352369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if ((FT = T->getAs<FunctionProtoType>())) {
1353369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  } else if (const PointerType *PT = T->getAs<PointerType>())
1354369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    FT = PT->getPointeeType()->getAs<FunctionProtoType>();
1355369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  else if (const ReferenceType *RT = T->getAs<ReferenceType>())
1356369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    FT = RT->getPointeeType()->getAs<FunctionProtoType>();
1357369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  else if (const MemberPointerType *MT = T->getAs<MemberPointerType>())
1358369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    FT = MT->getPointeeType()->getAs<FunctionProtoType>();
1359369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  else if (const BlockPointerType *BT = T->getAs<BlockPointerType>())
1360369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    FT = BT->getPointeeType()->getAs<FunctionProtoType>();
1361369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1362369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if (!FT)
1363369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return Expr::CT_Can;
1364369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1365369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  return FT->hasEmptyExceptionSpec() ? Expr::CT_Cannot : Expr::CT_Can;
1366369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl}
1367369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1368369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanDynamicCastThrow(const CXXDynamicCastExpr *DC) {
1369369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if (DC->isTypeDependent())
1370369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return Expr::CT_Dependent;
1371369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1372369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  return DC->getCastKind() == clang::CK_Dynamic? Expr::CT_Can : Expr::CT_Cannot;
1373369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl}
1374369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1375369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redlstatic Expr::CanThrowResult CanTypeidThrow(ASTContext &C,
1376369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl                                           const CXXTypeidExpr *DC) {
1377369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if (DC->isTypeOperand())
1378369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return Expr::CT_Cannot;
1379369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1380369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  Expr *Op = DC->getExprOperand();
1381369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if (Op->isTypeDependent())
1382369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return Expr::CT_Dependent;
1383369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1384369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  const RecordType *RT = Op->getType()->getAs<RecordType>();
1385369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if (!RT)
1386369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return Expr::CT_Cannot;
1387369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1388369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if (!cast<CXXRecordDecl>(RT->getDecl())->isPolymorphic())
1389369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return Expr::CT_Cannot;
1390369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1391369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  if (Op->Classify(C).isPRValue())
1392369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return Expr::CT_Cannot;
1393369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1394369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  return Expr::CT_Can;
1395369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl}
1396369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1397369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian RedlExpr::CanThrowResult Expr::CanThrow(ASTContext &C) const {
1398369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  // C++ [expr.unary.noexcept]p3:
1399369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  //   [Can throw] if in a potentially-evaluated context the expression would
1400369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  //   contain:
1401369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  switch (getStmtClass()) {
1402369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXThrowExprClass:
1403369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    //   - a potentially evaluated throw-expression
1404369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return CT_Can;
1405369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1406369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXDynamicCastExprClass: {
1407369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    //   - a potentially evaluated dynamic_cast expression dynamic_cast<T>(v),
1408369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    //     where T is a reference type, that requires a run-time check
1409369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    CanThrowResult CT = CanDynamicCastThrow(cast<CXXDynamicCastExpr>(this));
1410369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    if (CT == CT_Can)
1411369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl      return CT;
1412369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return MergeCanThrow(CT, CanSubExprsThrow(C, this));
1413369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  }
1414369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1415369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXTypeidExprClass:
1416369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    //   - a potentially evaluated typeid expression applied to a glvalue
1417369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    //     expression whose type is a polymorphic class type
1418369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return CanTypeidThrow(C, cast<CXXTypeidExpr>(this));
1419369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1420369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    //   - a potentially evaluated call to a function, member function, function
1421369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    //     pointer, or member function pointer that does not have a non-throwing
1422369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    //     exception-specification
1423369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CallExprClass:
1424369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXOperatorCallExprClass:
1425369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXMemberCallExprClass: {
1426369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    CanThrowResult CT = CanCalleeThrow(cast<CallExpr>(this)->getCalleeDecl());
1427369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    if (CT == CT_Can)
1428369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl      return CT;
1429369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return MergeCanThrow(CT, CanSubExprsThrow(C, this));
1430369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  }
1431369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1432369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXConstructExprClass: {
1433369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    CanThrowResult CT = CanCalleeThrow(
1434369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl        cast<CXXConstructExpr>(this)->getConstructor());
1435369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    if (CT == CT_Can)
1436369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl      return CT;
1437369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return MergeCanThrow(CT, CanSubExprsThrow(C, this));
1438369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  }
1439369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1440369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXNewExprClass: {
1441369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    CanThrowResult CT = MergeCanThrow(
1442369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl        CanCalleeThrow(cast<CXXNewExpr>(this)->getOperatorNew()),
1443369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl        CanCalleeThrow(cast<CXXNewExpr>(this)->getConstructor(),
1444369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl                       /*NullThrows*/false));
1445369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    if (CT == CT_Can)
1446369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl      return CT;
1447369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return MergeCanThrow(CT, CanSubExprsThrow(C, this));
1448369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  }
1449369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1450369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXDeleteExprClass: {
1451369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // FIXME: check if destructor might throw
1452369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    CanThrowResult CT = CanCalleeThrow(
1453369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl        cast<CXXDeleteExpr>(this)->getOperatorDelete());
1454369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    if (CT == CT_Can)
1455369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl      return CT;
1456369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return MergeCanThrow(CT, CanSubExprsThrow(C, this));
1457369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  }
1458369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1459369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // ObjC message sends are like function calls, but never have exception
1460369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // specs.
1461369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ObjCMessageExprClass:
1462369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ObjCPropertyRefExprClass:
1463369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ObjCImplicitSetterGetterRefExprClass:
1464369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return CT_Can;
1465369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1466369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // Many other things have subexpressions, so we have to test those.
1467369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // Some are simple:
1468369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ParenExprClass:
1469369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case MemberExprClass:
1470369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXReinterpretCastExprClass:
1471369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXConstCastExprClass:
1472369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ConditionalOperatorClass:
1473369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CompoundLiteralExprClass:
1474369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ExtVectorElementExprClass:
1475369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case InitListExprClass:
1476369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case DesignatedInitExprClass:
1477369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ParenListExprClass:
1478369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case VAArgExprClass:
1479369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXDefaultArgExprClass:
1480369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXBindTemporaryExprClass:
1481369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXExprWithTemporariesClass:
1482369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXTemporaryObjectExprClass:
1483369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ObjCIvarRefExprClass:
1484369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ObjCIsaExprClass:
1485369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ShuffleVectorExprClass:
1486369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return CanSubExprsThrow(C, this);
1487369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1488369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // Some might be dependent for other reasons.
1489369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case UnaryOperatorClass:
1490369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ArraySubscriptExprClass:
1491369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ImplicitCastExprClass:
1492369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CStyleCastExprClass:
1493369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXStaticCastExprClass:
1494369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXFunctionalCastExprClass:
1495369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case BinaryOperatorClass:
1496369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CompoundAssignOperatorClass: {
1497369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    CanThrowResult CT = isTypeDependent() ? CT_Dependent : CT_Cannot;
1498369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return MergeCanThrow(CT, CanSubExprsThrow(C, this));
1499369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  }
1500369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1501369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // FIXME: We should handle StmtExpr, but that opens a MASSIVE can of worms.
1502369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case StmtExprClass:
1503369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return CT_Can;
1504369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1505369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case ChooseExprClass:
1506369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    if (isTypeDependent() || isValueDependent())
1507369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl      return CT_Dependent;
1508369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return cast<ChooseExpr>(this)->getChosenSubExpr(C)->CanThrow(C);
1509369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1510369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // Some expressions are always dependent.
1511369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case DependentScopeDeclRefExprClass:
1512369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXUnresolvedConstructExprClass:
1513369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  case CXXDependentScopeMemberExprClass:
1514369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return CT_Dependent;
1515369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
1516369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  default:
1517369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // All other expressions don't have subexpressions, or else they are
1518369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    // unevaluated.
1519369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return CT_Cannot;
1520369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  }
1521369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl}
1522369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
15234e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() {
15244e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  Expr* E = this;
15254e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  while (ParenExpr* P = dyn_cast<ParenExpr>(E))
15264e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    E = P->getSubExpr();
15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15284e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  return E;
15294e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek}
15304e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
153156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
153256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand.
153356f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() {
153456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *E = this;
153556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  while (true) {
153656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    if (ParenExpr *P = dyn_cast<ParenExpr>(E))
153756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
153856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else if (CastExpr *P = dyn_cast<CastExpr>(E))
153956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
154056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else
154156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      return E;
154256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
154356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner}
154456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
15452fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() {
15462fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  Expr *E = this;
15472fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  while (true) {
15482fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall    if (ParenExpr *P = dyn_cast<ParenExpr>(E))
15492fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall      E = P->getSubExpr();
15502fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall    else if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E))
15512fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall      E = P->getSubExpr();
15522fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall    else
15532fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall      return E;
15542fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  }
15552fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall}
15562fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall
1557ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
1558ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size).  Strip off any
1559ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand.
1560ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) {
1561ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *E = this;
1562ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  while (true) {
1563ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    if (ParenExpr *P = dyn_cast<ParenExpr>(E)) {
1564ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      E = P->getSubExpr();
1565ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      continue;
1566ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    }
15671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1568ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    if (CastExpr *P = dyn_cast<CastExpr>(E)) {
1569ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      // We ignore integer <-> casts that are of the same width, ptr<->ptr and
15702ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor      // ptr<->int casts of the same width.  We also ignore all identity casts.
1571ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      Expr *SE = P->getSubExpr();
15721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1573ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) {
1574ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        E = SE;
1575ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        continue;
1576ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      }
15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15789d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor      if ((E->getType()->isPointerType() ||
15799d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor           E->getType()->isIntegralType(Ctx)) &&
15809d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor          (SE->getType()->isPointerType() ||
15819d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor           SE->getType()->isIntegralType(Ctx)) &&
1582ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner          Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) {
1583ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        E = SE;
1584ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        continue;
1585ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      }
1586ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    }
15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1588ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return E;
1589ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
1590ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner}
1591ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
15926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const {
15936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  const Expr *E = this;
15946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
15956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    E = ICE->getSubExprAsWritten();
1596c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
15976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return isa<CXXDefaultArgExpr>(E);
15986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor}
1599ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
16002f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding
16012f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions.
16022f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregorstatic const Expr *skipTemporaryBindingsAndNoOpCasts(const Expr *E) {
16032f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
16042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (ICE->getCastKind() == CK_NoOp)
16052f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      E = ICE->getSubExpr();
16062f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    else
16072f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      break;
16082f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  }
16092f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16102f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E))
16112f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    E = BE->getSubExpr();
16122f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16132f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
16142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (ICE->getCastKind() == CK_NoOp)
16152f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      E = ICE->getSubExpr();
16162f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    else
16172f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      break;
16182f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  }
1619c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
16202f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  return E;
16212f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor}
16222f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16232f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregorconst Expr *Expr::getTemporaryObject() const {
16242f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  const Expr *E = skipTemporaryBindingsAndNoOpCasts(this);
16252f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16262f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  // A cast can produce a temporary object. The object's construction
16272f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  // is represented as a CXXConstructExpr.
16282f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  if (const CastExpr *Cast = dyn_cast<CastExpr>(E)) {
16292f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // Only user-defined and constructor conversions can produce
16302f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // temporary objects.
16312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Cast->getCastKind() != CK_ConstructorConversion &&
16322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall        Cast->getCastKind() != CK_UserDefinedConversion)
16332f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      return 0;
16342f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16352f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // Strip off temporary bindings and no-op casts.
16362f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    const Expr *Sub = skipTemporaryBindingsAndNoOpCasts(Cast->getSubExpr());
16372f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16382f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // If this is a constructor conversion, see if we have an object
16392f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // construction.
16402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Cast->getCastKind() == CK_ConstructorConversion)
16412f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      return dyn_cast<CXXConstructExpr>(Sub);
16422f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16432f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // If this is a user-defined conversion, see if we have a call to
16442f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // a function that itself returns a temporary object.
16452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Cast->getCastKind() == CK_UserDefinedConversion)
16462f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      if (const CallExpr *CE = dyn_cast<CallExpr>(Sub))
16472f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor        if (CE->getCallReturnType()->isRecordType())
16482f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor          return CE;
16492f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16502f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    return 0;
16512f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  }
16522f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16532f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  // A call returning a class type returns a temporary.
16542f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
16552f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    if (CE->getCallReturnType()->isRecordType())
16562f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      return CE;
16572f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16582f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    return 0;
16592f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  }
16602f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
16612f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  // Explicit temporary object constructors create temporaries.
16622f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  return dyn_cast<CXXTemporaryObjectExpr>(E);
16632f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor}
16642f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
1665898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions
1666898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent.
1667898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) {
1668898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  for (unsigned I = 0; I < NumExprs; ++I)
1669898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    if (Exprs[I]->isTypeDependent())
1670898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      return true;
1671898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1672898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  return false;
1673898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
1674898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1675898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyValueDependentArguments - Determines if any of the expressions
1676898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is value-dependent.
1677898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) {
1678898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  for (unsigned I = 0; I < NumExprs; ++I)
1679898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    if (Exprs[I]->isValueDependent())
1680898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      return true;
1681898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1682898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  return false;
1683898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
1684898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
16854204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const {
1686c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // This function is attempting whether an expression is an initializer
1687c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // which can be evaluated at compile-time.  isEvaluatable handles most
1688c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // of the cases, but it can't deal with some initializer-specific
1689c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // expressions, and it can't deal with aggregates; we deal with those here,
1690c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // and fall back to isEvaluatable for the other cases.
1691c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman
16924204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  // If we ever capture reference-binding directly in the AST, we can
16934204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  // kill the second parameter.
16944204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall
16954204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  if (IsForRef) {
16964204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    EvalResult Result;
16974204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects;
16984204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  }
16991f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman
1700e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  switch (getStmtClass()) {
1701c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  default: break;
1702e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  case StringLiteralClass:
170314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  case ObjCStringLiteralClass:
1704eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  case ObjCEncodeExprClass:
1705e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    return true;
1706b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall  case CXXTemporaryObjectExprClass:
1707b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall  case CXXConstructExprClass: {
1708b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall    const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);
17094204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall
17104204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    // Only if it's
17114204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    // 1) an application of the trivial default constructor or
1712b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall    if (!CE->getConstructor()->isTrivial()) return false;
17134204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    if (!CE->getNumArgs()) return true;
17144204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall
17154204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    // 2) an elidable trivial copy construction of an operand which is
17164204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    //    itself a constant initializer.  Note that we consider the
17174204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    //    operand on its own, *not* as a reference binding.
17184204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    return CE->isElidable() &&
17194204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall           CE->getArg(0)->isConstantInitializer(Ctx, false);
1720b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall  }
172159b5da6d853b4368b984700315adf7b37de05764Nate Begeman  case CompoundLiteralExprClass: {
17221f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // This handles gcc's extension that allows global initializers like
17231f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // "struct x {int x;} x = (struct x) {};".
17241f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // FIXME: This accepts other cases it shouldn't!
172559b5da6d853b4368b984700315adf7b37de05764Nate Begeman    const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer();
17264204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    return Exp->isConstantInitializer(Ctx, false);
172759b5da6d853b4368b984700315adf7b37de05764Nate Begeman  }
1728e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  case InitListExprClass: {
17291f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // FIXME: This doesn't deal with fields with reference types correctly.
17301f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // FIXME: This incorrectly allows pointers cast to integers to be assigned
17311f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // to bitfields.
1732e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    const InitListExpr *Exp = cast<InitListExpr>(this);
1733e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    unsigned numInits = Exp->getNumInits();
1734e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    for (unsigned i = 0; i < numInits; i++) {
17354204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      if (!Exp->getInit(i)->isConstantInitializer(Ctx, false))
1736e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson        return false;
1737e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    }
1738c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    return true;
1739e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  }
17403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  case ImplicitValueInitExprClass:
17413498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return true;
17423ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner  case ParenExprClass:
17434204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    return cast<ParenExpr>(this)->getSubExpr()
17444204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      ->isConstantInitializer(Ctx, IsForRef);
1745c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  case UnaryOperatorClass: {
1746c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    const UnaryOperator* Exp = cast<UnaryOperator>(this);
17472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Exp->getOpcode() == UO_Extension)
17484204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      return Exp->getSubExpr()->isConstantInitializer(Ctx, false);
1749c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    break;
1750c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  }
17513ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner  case BinaryOperatorClass: {
17523ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    // Special case &&foo - &&bar.  It would be nice to generalize this somehow
17533ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    // but this handles the common case.
17543ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    const BinaryOperator *Exp = cast<BinaryOperator>(this);
17552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Exp->getOpcode() == BO_Sub &&
17563ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner        isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) &&
17573ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner        isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx)))
17583ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner      return true;
17593ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    break;
17603ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner  }
17614204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  case CXXFunctionalCastExprClass:
1762b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall  case CXXStaticCastExprClass:
176381045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner  case ImplicitCastExprClass:
1764c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  case CStyleCastExprClass:
1765c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    // Handle casts with a destination that's a struct or union; this
1766c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    // deals with both the gcc no-op struct cast extension and the
1767c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    // cast-to-union extension.
1768c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    if (getType()->isRecordType())
17694204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      return cast<CastExpr>(this)->getSubExpr()
17704204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall        ->isConstantInitializer(Ctx, false);
1771c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1772430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner    // Integer->integer casts can be handled here, which is important for
1773430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner    // things like (int)(&&x-&&y).  Scary but true.
1774430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner    if (getType()->isIntegerType() &&
1775430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner        cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType())
17764204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      return cast<CastExpr>(this)->getSubExpr()
17774204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall        ->isConstantInitializer(Ctx, false);
1778c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1779c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    break;
1780e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  }
1781c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  return isEvaluatable(Ctx);
178238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff}
178338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
17845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
17855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// integer constant expression with the value zero, or if this is one that is
17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// cast to void*.
1787ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregorbool Expr::isNullPointerConstant(ASTContext &Ctx,
1788ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor                                 NullPointerConstantValueDependence NPC) const {
1789ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  if (isValueDependent()) {
1790ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    switch (NPC) {
1791ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    case NPC_NeverValueDependent:
1792ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      assert(false && "Unexpected value dependent expression!");
1793ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      // If the unthinkable happens, fall through to the safest alternative.
1794c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1795ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    case NPC_ValueDependentIsNull:
17969d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor      return isTypeDependent() || getType()->isIntegralType(Ctx);
1797c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1798ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    case NPC_ValueDependentIsNotNull:
1799ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      return false;
1800ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    }
1801ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  }
1802f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar
18030777972d38a3125efed962b045704c30ae6965cfSebastian Redl  // Strip off a cast to void*, if it exists. Except in C++.
18040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
18056215dee86c0e715b9f2b0d401ab2a5fcf629f1afSebastian Redl    if (!Ctx.getLangOptions().CPlusPlus) {
18060777972d38a3125efed962b045704c30ae6965cfSebastian Redl      // Check that it is a cast to void*.
18076217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek      if (const PointerType *PT = CE->getType()->getAs<PointerType>()) {
18080777972d38a3125efed962b045704c30ae6965cfSebastian Redl        QualType Pointee = PT->getPointeeType();
18090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        if (!Pointee.hasQualifiers() &&
18100777972d38a3125efed962b045704c30ae6965cfSebastian Redl            Pointee->isVoidType() &&                              // to void*
18110777972d38a3125efed962b045704c30ae6965cfSebastian Redl            CE->getSubExpr()->getType()->isIntegerType())         // from int.
1812ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor          return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
18130777972d38a3125efed962b045704c30ae6965cfSebastian Redl      }
18145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1815aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
1816aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Ignore the ImplicitCastExpr type entirely.
1817ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
1818aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
1819aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Accept ((void*)0) as a null pointer constant, as many other
1820aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // implementations do.
1821ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  } else if (const CXXDefaultArgExpr *DefaultArg
18238123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner               = dyn_cast<CXXDefaultArgExpr>(this)) {
182404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    // See through default argument expressions
1825ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC);
18262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  } else if (isa<GNUNullExpr>(this)) {
18272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    // The GNU __null extension is always a null pointer constant.
18282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return true;
1829aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff  }
18302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
18316e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  // C++0x nullptr_t is always a null pointer constant.
18326e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  if (getType()->isNullPtrType())
18336e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return true;
18346e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
1835aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  // This expression must be an integer type.
1836c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (!getType()->isIntegerType() ||
183756fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian      (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType()))
1838aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    return false;
18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // If we have an integer constant expression, we need to *evaluate* it and
18415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // test for the value 0.
184209de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman  llvm::APSInt Result;
184309de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman  return isIntegerConstantExpr(Result, Ctx) && Result == 0;
18445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
184531a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff
184633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() {
18476f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor  Expr *E = this->IgnoreParens();
184833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
1849de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
18505baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    if (ICE->getValueKind() != VK_RValue &&
18512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall        ICE->getCastKind() == CK_NoOp)
1852de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor      E = ICE->getSubExpr()->IgnoreParens();
1853de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor    else
1854de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor      break;
1855de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  }
1856de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor
185727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E))
185886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl()))
185933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor      if (Field->isBitField())
186033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor        return Field;
186133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
186233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E))
186333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor    if (BinOp->isAssignmentOp() && BinOp->getLHS())
186433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor      return BinOp->getLHS()->getBitField();
186533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
186633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  return 0;
186727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor}
186827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor
1869093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const {
1870093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  const Expr *E = this->IgnoreParens();
1871c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1872093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
18735baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    if (ICE->getValueKind() != VK_RValue &&
18742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall        ICE->getCastKind() == CK_NoOp)
1875093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson      E = ICE->getSubExpr()->IgnoreParens();
1876093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson    else
1877093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson      break;
1878093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  }
1879c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1880093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E))
1881093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson    return ASE->getBase()->getType()->isVectorType();
1882093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson
1883093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  if (isa<ExtVectorElementExpr>(E))
1884093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson    return true;
1885093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson
1886093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  return false;
1887093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson}
1888093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson
18892140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector,
18902140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector.
18912140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const {
18922140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  return getBase()->getType()->isPointerType();
18932140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner}
18942140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner
1895213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const {
1896183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const VectorType *VT = getType()->getAs<VectorType>())
18978a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    return VT->getNumElements();
18988a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  return 1;
18994d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner}
19004d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner
19018a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated.
1902213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const {
1903a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar  // FIXME: Refactor this code to an accessor on the AST node which returns the
1904a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar  // "type" of component access, and share with code below and in Sema.
190501eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar  llvm::StringRef Comp = Accessor->getName();
1906190d6a25393995b42e32086949a68285ee423fb9Nate Begeman
1907190d6a25393995b42e32086949a68285ee423fb9Nate Begeman  // Halving swizzles do not contain duplicate elements.
1908150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar  if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd")
1909190d6a25393995b42e32086949a68285ee423fb9Nate Begeman    return false;
19101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1911190d6a25393995b42e32086949a68285ee423fb9Nate Begeman  // Advance past s-char prefix on hex swizzles.
1912150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar  if (Comp[0] == 's' || Comp[0] == 'S')
1913150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar    Comp = Comp.substr(1);
19141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1915150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar  for (unsigned i = 0, e = Comp.size(); i != e; ++i)
1916150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar    if (Comp.substr(i + 1).find(Comp[i]) != llvm::StringRef::npos)
1917fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff        return true;
1918150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar
1919fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  return false;
1920fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff}
1921b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
19228a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
19233b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess(
19243b8d116703db8018f855cbb4733ace426422623bNate Begeman                                  llvm::SmallVectorImpl<unsigned> &Elts) const {
19254b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  llvm::StringRef Comp = Accessor->getName();
19264b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  if (Comp[0] == 's' || Comp[0] == 'S')
19274b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar    Comp = Comp.substr(1);
19281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19294b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isHi =   Comp == "hi";
19304b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isLo =   Comp == "lo";
19314b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isEven = Comp == "even";
19324b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isOdd  = Comp == "odd";
19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19348a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
19358a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    uint64_t Index;
19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19378a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    if (isHi)
19388a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = e + i;
19398a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isLo)
19408a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = i;
19418a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isEven)
19428a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i;
19438a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isOdd)
19448a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i + 1;
19458a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else
19464b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar      Index = ExtVectorType::getAccessorIdx(Comp[i]);
1947b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
19483b8d116703db8018f855cbb4733ace426422623bNate Begeman    Elts.push_back(Index);
1949b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
19508a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman}
19518a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
195204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T,
195304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation LBracLoc,
195404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation SuperLoc,
195504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 bool IsInstanceSuper,
195604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 QualType SuperType,
1957c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                 Selector Sel,
195804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 ObjCMethodDecl *Method,
195904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 Expr **Args, unsigned NumArgs,
196004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation RBracLoc)
196104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  : Expr(ObjCMessageExprClass, T, /*TypeDependent=*/false,
196292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         /*ValueDependent=*/false),
196304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs(NumArgs), Kind(IsInstanceSuper? SuperInstance : SuperClass),
196404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    HasMethod(Method != 0), SuperLoc(SuperLoc),
196504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
196604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                                       : Sel.getAsOpaquePtr())),
1967c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    LBracLoc(LBracLoc), RBracLoc(RBracLoc)
1968c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{
196904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  setReceiverPointer(SuperType.getAsOpaquePtr());
197004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (NumArgs)
197104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
197204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
197304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
197404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T,
197504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation LBracLoc,
197604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 TypeSourceInfo *Receiver,
1977c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                 Selector Sel,
197804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 ObjCMethodDecl *Method,
197904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 Expr **Args, unsigned NumArgs,
198004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation RBracLoc)
198104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  : Expr(ObjCMessageExprClass, T, T->isDependentType(),
1982c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt         (T->isDependentType() ||
198304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor          hasAnyValueDependentArguments(Args, NumArgs))),
198404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs(NumArgs), Kind(Class), HasMethod(Method != 0),
198504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
198604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                                       : Sel.getAsOpaquePtr())),
1987c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    LBracLoc(LBracLoc), RBracLoc(RBracLoc)
198804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{
198904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  setReceiverPointer(Receiver);
199004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (NumArgs)
199104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
199204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
199304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
199404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T,
199504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation LBracLoc,
199604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 Expr *Receiver,
1997c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                 Selector Sel,
199804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 ObjCMethodDecl *Method,
199904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 Expr **Args, unsigned NumArgs,
200004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation RBracLoc)
200192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  : Expr(ObjCMessageExprClass, T, Receiver->isTypeDependent(),
2002c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt         (Receiver->isTypeDependent() ||
200304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor          hasAnyValueDependentArguments(Args, NumArgs))),
200404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs(NumArgs), Kind(Instance), HasMethod(Method != 0),
200504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
200604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                                       : Sel.getAsOpaquePtr())),
2007c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    LBracLoc(LBracLoc), RBracLoc(RBracLoc)
200804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{
200904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  setReceiverPointer(Receiver);
201004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (NumArgs)
201104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
201204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
201304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
201404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
201504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation LBracLoc,
201604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation SuperLoc,
201704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         bool IsInstanceSuper,
201804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         QualType SuperType,
2019c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                         Selector Sel,
202004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         ObjCMethodDecl *Method,
202104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         Expr **Args, unsigned NumArgs,
202204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation RBracLoc) {
2023c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
202404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs * sizeof(Expr *);
202504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
202604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return new (Mem) ObjCMessageExpr(T, LBracLoc, SuperLoc, IsInstanceSuper,
2027c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                   SuperType, Sel, Method, Args, NumArgs,
202804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                   RBracLoc);
202904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
203004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
203104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
203204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation LBracLoc,
203304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         TypeSourceInfo *Receiver,
2034c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                         Selector Sel,
203504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         ObjCMethodDecl *Method,
203604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         Expr **Args, unsigned NumArgs,
203704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation RBracLoc) {
2038c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
203904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs * sizeof(Expr *);
204004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
2041c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return new (Mem) ObjCMessageExpr(T, LBracLoc, Receiver, Sel, Method, Args,
204204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                   NumArgs, RBracLoc);
204304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
204404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
204504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
204604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation LBracLoc,
204704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         Expr *Receiver,
2048c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                         Selector Sel,
204904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         ObjCMethodDecl *Method,
205004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         Expr **Args, unsigned NumArgs,
205104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation RBracLoc) {
2052c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
205304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs * sizeof(Expr *);
205404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
2055c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return new (Mem) ObjCMessageExpr(T, LBracLoc, Receiver, Sel, Method, Args,
205604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                   NumArgs, RBracLoc);
205704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
205804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
2059c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context,
206004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                              unsigned NumArgs) {
2061c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
206204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs * sizeof(Expr *);
206304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
206404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs);
206504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
2066c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
206704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const {
206804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (HasMethod)
206904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod)
207004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                                               ->getSelector();
2071c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return Selector(SelectorOrMethod);
207204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
207304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
207404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const {
207504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  switch (getReceiverKind()) {
207604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case Instance:
207704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    if (const ObjCObjectPointerType *Ptr
207804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor          = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>())
207904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor      return Ptr->getInterfaceDecl();
208004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
20814df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek
208204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case Class:
2083c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const ObjCObjectType *Ty
2084c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          = getClassReceiver()->getAs<ObjCObjectType>())
2085c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return Ty->getInterface();
208604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
20874df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek
208804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case SuperInstance:
208904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    if (const ObjCObjectPointerType *Ptr
209004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor          = getSuperType()->getAs<ObjCObjectPointerType>())
209104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor      return Ptr->getInterfaceDecl();
209204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
2093c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor
209404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case SuperClass:
209504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    if (const ObjCObjectPointerType *Iface
209604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                       = getSuperType()->getAs<ObjCObjectPointerType>())
209704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor      return Iface->getInterfaceDecl();
209804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
209904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  }
21000389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner
210104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return 0;
2102eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek}
21030389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner
210427437caadea35f84d550cd29f024fcf3ea240eecChris Lattnerbool ChooseExpr::isConditionTrue(ASTContext &C) const {
21059a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman  return getCond()->EvaluateAsInt(C) != 0;
210627437caadea35f84d550cd29f024fcf3ea240eecChris Lattner}
210727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner
2108888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs,
2109888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman                                 unsigned NumExprs) {
2110888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  if (SubExprs) C.Deallocate(SubExprs);
2111888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
2112888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  SubExprs = new (C) Stmt* [NumExprs];
211394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  this->NumExprs = NumExprs;
211494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs);
21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
2116888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
211777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
211805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//  DesignatedInitExpr
211905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===//
212005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
212105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() {
212205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  assert(Kind == FieldDesignator && "Only valid on a field designator");
212305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  if (Field.NameOrField & 0x01)
212405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01);
212505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  else
212605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return getField()->getIdentifier();
212705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
212805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2129c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty,
2130319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                                       unsigned NumDesignators,
2131ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                                       const Designator *Designators,
21321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                       SourceLocation EqualOrColonLoc,
2133ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                                       bool GNUSyntax,
21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                       Expr **IndexExprs,
21359ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                       unsigned NumIndexExprs,
21369ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                       Expr *Init)
21371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Expr(DesignatedInitExprClass, Ty,
21389ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor         Init->isTypeDependent(), Init->isValueDependent()),
21391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
21401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) {
2141319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  this->Designators = new (C) Designator[NumDesignators];
21429ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
21439ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // Record the initializer itself.
21449ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  child_iterator Child = child_begin();
21459ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  *Child++ = Init;
21469ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
21479ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // Copy the designators and their subexpressions, computing
21489ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // value-dependence along the way.
21499ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  unsigned IndexIdx = 0;
21509ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  for (unsigned I = 0; I != NumDesignators; ++I) {
2151ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    this->Designators[I] = Designators[I];
21529ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
21539ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    if (this->Designators[I].isArrayDesignator()) {
21549ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Compute type- and value-dependence.
21559ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      Expr *Index = IndexExprs[IndexIdx];
21561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ValueDependent = ValueDependent ||
21579ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor        Index->isTypeDependent() || Index->isValueDependent();
21589ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
21599ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Copy the index expressions into permanent storage.
21609ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      *Child++ = IndexExprs[IndexIdx++];
21619ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    } else if (this->Designators[I].isArrayRangeDesignator()) {
21629ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Compute type- and value-dependence.
21639ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      Expr *Start = IndexExprs[IndexIdx];
21649ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      Expr *End = IndexExprs[IndexIdx + 1];
21651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ValueDependent = ValueDependent ||
21669ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor        Start->isTypeDependent() || Start->isValueDependent() ||
21679ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor        End->isTypeDependent() || End->isValueDependent();
21689ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
21699ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Copy the start/end expressions into permanent storage.
21709ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      *Child++ = IndexExprs[IndexIdx++];
21719ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      *Child++ = IndexExprs[IndexIdx++];
21729ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    }
21739ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  }
21749ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
21759ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions");
2176ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor}
2177ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
217805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr *
21791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators,
218005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           unsigned NumDesignators,
218105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           Expr **IndexExprs, unsigned NumIndexExprs,
218205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           SourceLocation ColonOrEqualLoc,
218305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           bool UsesColonSyntax, Expr *Init) {
2184c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff  void *Mem = C.Allocate(sizeof(DesignatedInitExpr) +
2185c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff                         sizeof(Stmt *) * (NumIndexExprs + 1), 8);
2186319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators,
21879ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                      ColonOrEqualLoc, UsesColonSyntax,
21889ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                      IndexExprs, NumIndexExprs, Init);
218905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
219005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
21911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C,
2192d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor                                                    unsigned NumIndexExprs) {
2193d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void *Mem = C.Allocate(sizeof(DesignatedInitExpr) +
2194d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor                         sizeof(Stmt *) * (NumIndexExprs + 1), 8);
2195d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  return new (Mem) DesignatedInitExpr(NumIndexExprs + 1);
2196d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor}
2197d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2198319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C,
2199319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                                        const Designator *Desigs,
2200d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor                                        unsigned NumDesigs) {
2201319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  Designators = new (C) Designator[NumDesigs];
2202d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  NumDesignators = NumDesigs;
2203d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  for (unsigned I = 0; I != NumDesigs; ++I)
2204d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Designators[I] = Desigs[I];
2205d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor}
2206d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
220705c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const {
220805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation StartLoc;
2209d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner  Designator &First =
2210d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner    *const_cast<DesignatedInitExpr*>(this)->designators_begin();
221105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  if (First.isFieldDesignator()) {
2212eeae8f072748affce25ab4064982626361293390Douglas Gregor    if (GNUSyntax)
221305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc);
221405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    else
221505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc);
221605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  } else
2217d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner    StartLoc =
2218d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner      SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc);
221905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return SourceRange(StartLoc, getInit()->getSourceRange().getEnd());
222005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
222105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
222205c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) {
222305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  assert(D.Kind == Designator::ArrayDesignator && "Requires array designator");
222405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
222505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
222605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
222705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
222805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
222905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
223005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) {
22311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  assert(D.Kind == Designator::ArrayRangeDesignator &&
223205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor         "Requires array range designator");
223305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
223405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
223505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
223605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
223705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
223805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
223905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) {
22401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  assert(D.Kind == Designator::ArrayRangeDesignator &&
224105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor         "Requires array range designator");
224205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
224305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
224405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
224505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2));
224605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
224705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2248ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series
2249ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last).
2250319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx,
22511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                          const Designator *First,
2252ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                                          const Designator *Last) {
2253ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  unsigned NumNewDesignators = Last - First;
2254ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  if (NumNewDesignators == 0) {
2255ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    std::copy_backward(Designators + Idx + 1,
2256ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                       Designators + NumDesignators,
2257ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                       Designators + Idx);
2258ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    --NumNewDesignators;
2259ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return;
2260ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  } else if (NumNewDesignators == 1) {
2261ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designators[Idx] = *First;
2262ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return;
2263ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
2264ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
22651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Designator *NewDesignators
2266319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor    = new (C) Designator[NumDesignators - 1 + NumNewDesignators];
2267ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  std::copy(Designators, Designators + Idx, NewDesignators);
2268ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  std::copy(First, Last, NewDesignators + Idx);
2269ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  std::copy(Designators + Idx + 1, Designators + NumDesignators,
2270ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor            NewDesignators + Idx + NumNewDesignators);
2271ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designators = NewDesignators;
2272ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  NumDesignators = NumDesignators - 1 + NumNewDesignators;
2273ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor}
2274ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
22751eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc,
22762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                             Expr **exprs, unsigned nexprs,
22772ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                             SourceLocation rparenloc)
22782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman: Expr(ParenListExprClass, QualType(),
22792ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman       hasAnyTypeDependentArguments(exprs, nexprs),
22801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump       hasAnyValueDependentArguments(exprs, nexprs)),
22812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) {
22821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Exprs = new (C) Stmt*[nexprs];
22842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  for (unsigned i = 0; i != nexprs; ++i)
22852ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    Exprs[i] = exprs[i];
22862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
22872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
228805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===//
2289ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//  ExprIterator.
2290ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
2291ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
2292ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); }
2293ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); }
2294ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); }
2295ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const {
2296ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  return cast<Expr>(I[idx]);
2297ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek}
2298ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); }
2299ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); }
2300ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
2301ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
230277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//  Child Iterators for iterating over subexpressions/substatements
230377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
230477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
230577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// DeclRefExpr
23069ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
23079ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
230877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
23097779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff// ObjCIvarRefExpr
23105549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; }
23115549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; }
23127779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff
2313e3e9add4fd788927df6f545570e7838db59c01d7Steve Naroff// ObjCPropertyRefExpr
23145549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; }
23155549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; }
2316ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff
231709105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian// ObjCImplicitSetterGetterRefExpr
23181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_begin() {
23192fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  // If this is accessing a class member, skip that entry.
23202fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  if (Base) return &Base;
23212fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  return &Base+1;
2322154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian}
23231eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_end() {
23241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return &Base+1;
2325154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian}
23265daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian
2327cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor// ObjCSuperExpr
2328cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); }
2329cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); }
2330cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor
2331f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff// ObjCIsaExpr
2332f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; }
2333f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; }
2334f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff
2335d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner// PredefinedExpr
2336d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); }
2337d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); }
233877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
233977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// IntegerLiteral
23409ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); }
23419ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); }
234277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
234377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CharacterLiteral
2344d603eaa682cecac2c10771a700cb83aa301653b4Chris LattnerStmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();}
23459ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); }
234677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
234777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// FloatingLiteral
23489ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); }
23499ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); }
235077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
23515d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner// ImaginaryLiteral
23525549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; }
23535549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; }
23545d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
235577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// StringLiteral
23569ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_begin() { return child_iterator(); }
23579ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_end() { return child_iterator(); }
235877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
235977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ParenExpr
23605549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_begin() { return &Val; }
23615549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_end() { return &Val+1; }
236277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
236377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// UnaryOperator
23645549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_begin() { return &Val; }
23655549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_end() { return &Val+1; }
236677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
23678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor// OffsetOfExpr
23688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorStmt::child_iterator OffsetOfExpr::child_begin() {
23698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return reinterpret_cast<Stmt **> (reinterpret_cast<OffsetOfNode *> (this + 1)
23708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                      + NumComps);
23718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
23728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorStmt::child_iterator OffsetOfExpr::child_end() {
23738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return child_iterator(&*child_begin() + NumExprs);
23748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
23758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
23760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl// SizeOfAlignOfExpr
23771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator SizeOfAlignOfExpr::child_begin() {
23780518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // If this is of a type and the type is a VLA type (and not a typedef), the
23790518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // size expression of the VLA needs to be treated as an executable expression.
23800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // Why isn't this weirdness documented better in StmtIterator?
23810518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  if (isArgumentType()) {
23820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    if (VariableArrayType* T = dyn_cast<VariableArrayType>(
23830518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                                   getArgumentType().getTypePtr()))
23840518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl      return child_iterator(T);
23850518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return child_iterator();
23860518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
2387d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  return child_iterator(&Argument.Ex);
23889ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
23890518999d3adcc289997bd974dce90cc97f5c1c44Sebastian RedlStmt::child_iterator SizeOfAlignOfExpr::child_end() {
23900518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  if (isArgumentType())
23910518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return child_iterator();
2392d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  return child_iterator(&Argument.Ex + 1);
23939ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
239477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
239577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ArraySubscriptExpr
23961237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_begin() {
23975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
239877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
23991237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_end() {
24005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
240177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
240277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
240377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CallExpr
24041237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_begin() {
24055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
240677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
24071237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_end() {
24085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+NumArgs+ARGS_START;
240977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
24101237c673c07f9d827129ba02720108816abde562Ted Kremenek
24111237c673c07f9d827129ba02720108816abde562Ted Kremenek// MemberExpr
24125549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_begin() { return &Base; }
24135549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_end() { return &Base+1; }
24141237c673c07f9d827129ba02720108816abde562Ted Kremenek
2415213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman// ExtVectorElementExpr
24165549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; }
24175549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; }
24181237c673c07f9d827129ba02720108816abde562Ted Kremenek
24191237c673c07f9d827129ba02720108816abde562Ted Kremenek// CompoundLiteralExpr
24205549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; }
24215549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; }
24221237c673c07f9d827129ba02720108816abde562Ted Kremenek
24231237c673c07f9d827129ba02720108816abde562Ted Kremenek// CastExpr
24245549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_begin() { return &Op; }
24255549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_end() { return &Op+1; }
24261237c673c07f9d827129ba02720108816abde562Ted Kremenek
24271237c673c07f9d827129ba02720108816abde562Ted Kremenek// BinaryOperator
24281237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_begin() {
24295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
24301237c673c07f9d827129ba02720108816abde562Ted Kremenek}
24311237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_end() {
24325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
24331237c673c07f9d827129ba02720108816abde562Ted Kremenek}
24341237c673c07f9d827129ba02720108816abde562Ted Kremenek
24351237c673c07f9d827129ba02720108816abde562Ted Kremenek// ConditionalOperator
24361237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_begin() {
24375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
24381237c673c07f9d827129ba02720108816abde562Ted Kremenek}
24391237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_end() {
24405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
24411237c673c07f9d827129ba02720108816abde562Ted Kremenek}
24421237c673c07f9d827129ba02720108816abde562Ted Kremenek
24431237c673c07f9d827129ba02720108816abde562Ted Kremenek// AddrLabelExpr
24449ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); }
24459ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); }
24461237c673c07f9d827129ba02720108816abde562Ted Kremenek
24471237c673c07f9d827129ba02720108816abde562Ted Kremenek// StmtExpr
24485549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_begin() { return &SubStmt; }
24495549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; }
24501237c673c07f9d827129ba02720108816abde562Ted Kremenek
24511237c673c07f9d827129ba02720108816abde562Ted Kremenek// TypesCompatibleExpr
24529ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_begin() {
24539ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
24549ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
24559ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek
24569ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_end() {
24579ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
24589ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
24591237c673c07f9d827129ba02720108816abde562Ted Kremenek
24601237c673c07f9d827129ba02720108816abde562Ted Kremenek// ChooseExpr
24615549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; }
24625549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; }
24632d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
24642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor// GNUNullExpr
24652d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); }
24662d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); }
24671237c673c07f9d827129ba02720108816abde562Ted Kremenek
2468d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman// ShuffleVectorExpr
2469d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_begin() {
24705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
2471d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
2472d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_end() {
24735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+NumExprs;
2474d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
2475d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
24767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson// VAArgExpr
24775549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_begin() { return &Val; }
24785549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_end() { return &Val+1; }
24797c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
248066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson// InitListExpr
2481ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed KremenekStmt::child_iterator InitListExpr::child_begin() {
2482ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  return InitExprs.size() ? &InitExprs[0] : 0;
2483ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek}
2484ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed KremenekStmt::child_iterator InitListExpr::child_end() {
2485ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0;
2486ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek}
248766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
24883498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// DesignatedInitExpr
248905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_begin() {
249005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
249105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
249205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
249305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
249405c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_end() {
249505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return child_iterator(&*child_begin() + NumSubExprs);
249605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
249705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
24983498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// ImplicitValueInitExpr
24991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_begin() {
25001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return child_iterator();
25013498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}
25023498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
25031eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_end() {
25041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return child_iterator();
25053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}
25063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
25072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman// ParenListExpr
25082ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_begin() {
25092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  return &Exprs[0];
25102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
25112ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_end() {
25122ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  return &Exprs[0]+NumExprs;
25132ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
25142ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
25151237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCStringLiteral
25161eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCStringLiteral::child_begin() {
2517c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner  return &String;
25189ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25199ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_end() {
2520c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner  return &String+1;
25219ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25221237c673c07f9d827129ba02720108816abde562Ted Kremenek
25231237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCEncodeExpr
25249ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); }
25259ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); }
25261237c673c07f9d827129ba02720108816abde562Ted Kremenek
2527b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian// ObjCSelectorExpr
25281eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCSelectorExpr::child_begin() {
25299ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25309ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25319ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_end() {
25329ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25339ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
2534b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
2535390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian// ObjCProtocolExpr
25369ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_begin() {
25379ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25389ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
25399ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_end() {
25409ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
25419ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
2542390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian
2543563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr
25441eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCMessageExpr::child_begin() {
254504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (getReceiverKind() == Instance)
254604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    return reinterpret_cast<Stmt **>(this + 1);
254704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return getArgs();
2548563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
2549563477da25f824e37c535131695dc4dc9b68c465Steve NaroffStmt::child_iterator ObjCMessageExpr::child_end() {
255004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return getArgs() + getNumArgs();
2551563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
2552563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
25534eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks
255456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_begin() { return child_iterator(); }
255556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_end() { return child_iterator(); }
25564eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
25579da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();}
25589da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); }
2559