Expr.cpp revision 9996a7f06a3c5b4554692e7177930cf4e8ef09af
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();
5626346f963145ed18b6edf50a78753b47db505e912Chris Lattner  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
563d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return DRE->getDecl();
564cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes  if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
565cb1c77f90d4e747b83a0d0cc125dc01567378f82Nuno Lopes    return ME->getMemberDecl();
566a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
567a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  return 0;
568a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu}
569a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
570d20254f2875d0004c57ee766f258dbcee29f4841Nuno LopesFunctionDecl *CallExpr::getDirectCallee() {
571caabf9bf331156e96dacb072385901fdfa057ec1Chris Lattner  return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
572d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes}
573d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes
574d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call.
575d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set
576d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null.
5778189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) {
578d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // No change, just return.
579d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs == getNumArgs()) return;
5801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
581d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // If shrinking # arguments, just delete the extras and forgot them.
582d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs < getNumArgs()) {
583d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    this->NumArgs = NumArgs;
584d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    return;
585d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  }
586d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
587d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Otherwise, we are growing the # arguments.  New an bigger argument array.
58868a049cab6015a7437bec5661601b7d37d23c70cDaniel Dunbar  Stmt **NewSubExprs = new (C) Stmt*[NumArgs+1];
589d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Copy over args.
590d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i)
591d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = SubExprs[i];
592d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Null out new args.
593d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
594d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = 0;
5951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59688c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor  if (SubExprs) C.Deallocate(SubExprs);
597d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SubExprs = NewSubExprs;
598d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  this->NumArgs = NumArgs;
599d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner}
600d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
601cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
602cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0.
6033c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregorunsigned CallExpr::isBuiltinCall(ASTContext &Context) const {
604c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // All simple function calls (e.g. func()) are implicitly cast to pointer to
6051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // function. As a result, we try and obtain the DeclRefExpr from the
606c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // ImplicitCastExpr.
607c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
608c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
609cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
611c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
612c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!DRE)
613cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
615bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
616bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  if (!FDecl)
617cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
6181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6194fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor  if (!FDecl->getIdentifier())
6204fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor    return 0;
6214fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor
6227814e6d6645d587891293d59ecf6576defcfac92Douglas Gregor  return FDecl->getBuiltinID();
623cb888967400a03504c88acedd5248d6778a82f46Chris Lattner}
624bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson
6256dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const {
6266dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  QualType CalleeType = getCallee()->getType();
6276217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>())
6286dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson    CalleeType = FnTypePtr->getPointeeType();
6296217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>())
6306dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson    CalleeType = BPT->getPointeeType();
6315291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  else if (const MemberPointerType *MPT
6325291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor                                      = CalleeType->getAs<MemberPointerType>())
6335291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor    CalleeType = MPT->getPointeeType();
6345291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
635183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  const FunctionType *FnType = CalleeType->getAs<FunctionType>();
6366dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  return FnType->getResultType();
6376dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson}
638cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
639c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type,
6408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   SourceLocation OperatorLoc,
641c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                   TypeSourceInfo *tsi,
642c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                   OffsetOfNode* compsPtr, unsigned numComps,
6438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   Expr** exprsPtr, unsigned numExprs,
6448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   SourceLocation RParenLoc) {
6458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void *Mem = C.Allocate(sizeof(OffsetOfExpr) +
646c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                         sizeof(OffsetOfNode) * numComps +
6478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                         sizeof(Expr*) * numExprs);
6488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
6498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, compsPtr, numComps,
6508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                exprsPtr, numExprs, RParenLoc);
6518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
6528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
6538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorOffsetOfExpr *OffsetOfExpr::CreateEmpty(ASTContext &C,
6548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                        unsigned numComps, unsigned numExprs) {
6558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void *Mem = C.Allocate(sizeof(OffsetOfExpr) +
6568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                         sizeof(OffsetOfNode) * numComps +
6578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                         sizeof(Expr*) * numExprs);
6588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return new (Mem) OffsetOfExpr(numComps, numExprs);
6598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
6608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
661c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntOffsetOfExpr::OffsetOfExpr(ASTContext &C, QualType type,
6628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                           SourceLocation OperatorLoc, TypeSourceInfo *tsi,
663c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                           OffsetOfNode* compsPtr, unsigned numComps,
6648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                           Expr** exprsPtr, unsigned numExprs,
6658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                           SourceLocation RParenLoc)
666c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  : Expr(OffsetOfExprClass, type, /*TypeDependent=*/false,
6678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor         /*ValueDependent=*/tsi->getType()->isDependentType() ||
6688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor         hasAnyTypeDependentArguments(exprsPtr, numExprs) ||
6698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor         hasAnyValueDependentArguments(exprsPtr, numExprs)),
670c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi),
671c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    NumComps(numComps), NumExprs(numExprs)
6728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor{
6738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for(unsigned i = 0; i < numComps; ++i) {
6748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    setComponent(i, compsPtr[i]);
6758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
676c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  for(unsigned i = 0; i < numExprs; ++i) {
6788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    setIndexExpr(i, exprsPtr[i]);
6798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
6808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
6818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
6828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorIdentifierInfo *OffsetOfExpr::OffsetOfNode::getFieldName() const {
6838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  assert(getKind() == Field || getKind() == Identifier);
6848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  if (getKind() == Field)
6858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return getField()->getIdentifier();
686c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask);
6888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
6898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
6901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow,
6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               NestedNameSpecifier *qual,
69283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                               SourceRange qualrange,
693f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman                               ValueDecl *memberdecl,
694161755a09898c95d21bfff33707da9ca41cd53c5John McCall                               DeclAccessPair founddecl,
6952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                               DeclarationNameInfo nameinfo,
696d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                               const TemplateArgumentListInfo *targs,
697c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                               QualType ty) {
69883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  std::size_t Size = sizeof(MemberExpr);
6996bb8017bb9e828d118e15e59d71c66bba323c364John McCall
700161755a09898c95d21bfff33707da9ca41cd53c5John McCall  bool hasQualOrFound = (qual != 0 ||
701161755a09898c95d21bfff33707da9ca41cd53c5John McCall                         founddecl.getDecl() != memberdecl ||
702161755a09898c95d21bfff33707da9ca41cd53c5John McCall                         founddecl.getAccess() != memberdecl->getAccess());
7036bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (hasQualOrFound)
7046bb8017bb9e828d118e15e59d71c66bba323c364John McCall    Size += sizeof(MemberNameQualifier);
7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
706d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  if (targs)
707d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    Size += ExplicitTemplateArgumentList::sizeFor(*targs);
7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
70983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  void *Mem = C.Allocate(Size, llvm::alignof<MemberExpr>());
7102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  MemberExpr *E = new (Mem) MemberExpr(base, isarrow, memberdecl, nameinfo, ty);
7116bb8017bb9e828d118e15e59d71c66bba323c364John McCall
7126bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (hasQualOrFound) {
7136bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (qual && qual->isDependent()) {
7146bb8017bb9e828d118e15e59d71c66bba323c364John McCall      E->setValueDependent(true);
7156bb8017bb9e828d118e15e59d71c66bba323c364John McCall      E->setTypeDependent(true);
7166bb8017bb9e828d118e15e59d71c66bba323c364John McCall    }
7176bb8017bb9e828d118e15e59d71c66bba323c364John McCall    E->HasQualifierOrFoundDecl = true;
7186bb8017bb9e828d118e15e59d71c66bba323c364John McCall
7196bb8017bb9e828d118e15e59d71c66bba323c364John McCall    MemberNameQualifier *NQ = E->getMemberQualifier();
7206bb8017bb9e828d118e15e59d71c66bba323c364John McCall    NQ->NNS = qual;
7216bb8017bb9e828d118e15e59d71c66bba323c364John McCall    NQ->Range = qualrange;
7226bb8017bb9e828d118e15e59d71c66bba323c364John McCall    NQ->FoundDecl = founddecl;
7236bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
7246bb8017bb9e828d118e15e59d71c66bba323c364John McCall
7256bb8017bb9e828d118e15e59d71c66bba323c364John McCall  if (targs) {
7266bb8017bb9e828d118e15e59d71c66bba323c364John McCall    E->HasExplicitTemplateArgumentList = true;
727096832c5ed5b9106fa177ebc148489760c3bc496John McCall    E->getExplicitTemplateArgs().initializeFrom(*targs);
7286bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
7296bb8017bb9e828d118e15e59d71c66bba323c364John McCall
7306bb8017bb9e828d118e15e59d71c66bba323c364John McCall  return E;
73183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor}
73283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
733f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const {
734f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  switch (getCastKind()) {
7352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_Unknown:
736f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "Unknown";
7372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_BitCast:
738f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "BitCast";
7392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_LValueBitCast:
740e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor    return "LValueBitCast";
7412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_NoOp:
742f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "NoOp";
7432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_BaseToDerived:
74411de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson    return "BaseToDerived";
7452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_DerivedToBase:
746f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "DerivedToBase";
7472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_UncheckedDerivedToBase:
74823cba801e11b03929c44f8cf54578305963a3476John McCall    return "UncheckedDerivedToBase";
7492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_Dynamic:
750f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "Dynamic";
7512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ToUnion:
752f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "ToUnion";
7532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ArrayToPointerDecay:
754f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "ArrayToPointerDecay";
7552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_FunctionToPointerDecay:
756f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "FunctionToPointerDecay";
7572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_NullToMemberPointer:
758f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "NullToMemberPointer";
7592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_BaseToDerivedMemberPointer:
760f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "BaseToDerivedMemberPointer";
7612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_DerivedToBaseMemberPointer:
7621a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    return "DerivedToBaseMemberPointer";
7632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_UserDefinedConversion:
764f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "UserDefinedConversion";
7652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ConstructorConversion:
766f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson    return "ConstructorConversion";
7672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_IntegralToPointer:
7687f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    return "IntegralToPointer";
7692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_PointerToIntegral:
7707f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    return "PointerToIntegral";
7712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ToVoid:
772ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson    return "ToVoid";
7732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_VectorSplat:
77416a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson    return "VectorSplat";
7752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_IntegralCast:
77682debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    return "IntegralCast";
7772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_IntegralToFloating:
77882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    return "IntegralToFloating";
7792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_FloatingToIntegral:
78082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    return "FloatingToIntegral";
7812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_FloatingCast:
782c6b29163557d02da5d2a4a06f986f0480291f51fBenjamin Kramer    return "FloatingCast";
7832de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_MemberPointerToBoolean:
784bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson    return "MemberPointerToBoolean";
7852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_AnyPointerToObjCPointerCast:
7864cbf9d43cc47bb7a070c5c5026521d7d6a8f73c7Fariborz Jahanian    return "AnyPointerToObjCPointerCast";
7872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_AnyPointerToBlockPointerCast:
7883b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    return "AnyPointerToBlockPointerCast";
7892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case CK_ObjCObjectLValueCast:
790569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    return "ObjCObjectLValueCast";
791f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  }
7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
793f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  assert(0 && "Unhandled cast kind!");
794f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  return 0;
795f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson}
796f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
7976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas GregorExpr *CastExpr::getSubExprAsWritten() {
7986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  Expr *SubExpr = 0;
7996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  CastExpr *E = this;
8006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  do {
8016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    SubExpr = E->getSubExpr();
802c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // Skip any temporary bindings; they're implicit.
8046eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(SubExpr))
8056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      SubExpr = Binder->getSubExpr();
806c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8076eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // Conversions by constructor and conversion functions have a
8086eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // subexpression describing the call; strip it off.
8092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (E->getCastKind() == CK_ConstructorConversion)
8106eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      SubExpr = cast<CXXConstructExpr>(SubExpr)->getArg(0);
8112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    else if (E->getCastKind() == CK_UserDefinedConversion)
8126eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor      SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument();
813c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8146eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // If the subexpression we're left with is an implicit cast, look
8156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    // through that, too.
816c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr)));
817c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
8186eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return SubExpr;
8196eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor}
8206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
821f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCXXBaseSpecifier **CastExpr::path_buffer() {
822f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  switch (getStmtClass()) {
823f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define ABSTRACT_STMT(x)
824f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define CASTEXPR(Type, Base) \
825f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  case Stmt::Type##Class: \
826f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return reinterpret_cast<CXXBaseSpecifier**>(static_cast<Type*>(this)+1);
827f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#define STMT(Type, Base)
828f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall#include "clang/AST/StmtNodes.inc"
829f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  default:
830f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    llvm_unreachable("non-cast expressions not possible here");
831f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return 0;
832f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  }
833f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
834f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
835f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallvoid CastExpr::setCastPath(const CXXCastPath &Path) {
836f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  assert(Path.size() == path_size());
837f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  memcpy(path_buffer(), Path.data(), Path.size() * sizeof(CXXBaseSpecifier*));
838f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
839f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
840f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::Create(ASTContext &C, QualType T,
841f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                           CastKind Kind, Expr *Operand,
842f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                           const CXXCastPath *BasePath,
8435baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                                           ExprValueKind VK) {
844f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  unsigned PathSize = (BasePath ? BasePath->size() : 0);
845f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void *Buffer =
846f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
847f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  ImplicitCastExpr *E =
8485baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK);
849f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  if (PathSize) E->setCastPath(*BasePath);
850f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  return E;
851f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
852f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
853f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallImplicitCastExpr *ImplicitCastExpr::CreateEmpty(ASTContext &C,
854f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                                unsigned PathSize) {
855f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void *Buffer =
856f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    C.Allocate(sizeof(ImplicitCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
857f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize);
858f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
859f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
860f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
861f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::Create(ASTContext &C, QualType T,
862f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       CastKind K, Expr *Op,
863f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       const CXXCastPath *BasePath,
864f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       TypeSourceInfo *WrittenTy,
865f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation L, SourceLocation R) {
866f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  unsigned PathSize = (BasePath ? BasePath->size() : 0);
867f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void *Buffer =
868f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
869f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CStyleCastExpr *E =
870f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    new (Buffer) CStyleCastExpr(T, K, Op, PathSize, WrittenTy, L, R);
871f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  if (PathSize) E->setCastPath(*BasePath);
872f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  return E;
873f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
874f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
875f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallCStyleCastExpr *CStyleCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
876f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void *Buffer =
877f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    C.Allocate(sizeof(CStyleCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
878f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize);
879f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall}
880f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=".
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) {
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
8852de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_PtrMemD:   return ".*";
8862de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_PtrMemI:   return "->*";
8872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Mul:       return "*";
8882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Div:       return "/";
8892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Rem:       return "%";
8902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Add:       return "+";
8912de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Sub:       return "-";
8922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Shl:       return "<<";
8932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Shr:       return ">>";
8942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_LT:        return "<";
8952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_GT:        return ">";
8962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_LE:        return "<=";
8972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_GE:        return ">=";
8982de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_EQ:        return "==";
8992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_NE:        return "!=";
9002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_And:       return "&";
9012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Xor:       return "^";
9022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Or:        return "|";
9032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_LAnd:      return "&&";
9042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_LOr:       return "||";
9052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Assign:    return "=";
9062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_MulAssign: return "*=";
9072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_DivAssign: return "/=";
9082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_RemAssign: return "%=";
9092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_AddAssign: return "+=";
9102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_SubAssign: return "-=";
9112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_ShlAssign: return "<<=";
9122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_ShrAssign: return ">>=";
9132de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_AndAssign: return "&=";
9142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_XorAssign: return "^=";
9152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_OrAssign:  return "|=";
9162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case BO_Comma:     return ",";
9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
918baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor
919baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor  return "";
9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallBinaryOperatorKind
923063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) {
924063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  switch (OO) {
925b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner  default: assert(false && "Not an overloadable binary operator");
9262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Plus: return BO_Add;
9272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Minus: return BO_Sub;
9282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Star: return BO_Mul;
9292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Slash: return BO_Div;
9302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Percent: return BO_Rem;
9312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Caret: return BO_Xor;
9322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Amp: return BO_And;
9332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Pipe: return BO_Or;
9342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Equal: return BO_Assign;
9352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Less: return BO_LT;
9362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Greater: return BO_GT;
9372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_PlusEqual: return BO_AddAssign;
9382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_MinusEqual: return BO_SubAssign;
9392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_StarEqual: return BO_MulAssign;
9402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_SlashEqual: return BO_DivAssign;
9412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_PercentEqual: return BO_RemAssign;
9422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_CaretEqual: return BO_XorAssign;
9432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_AmpEqual: return BO_AndAssign;
9442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_PipeEqual: return BO_OrAssign;
9452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_LessLess: return BO_Shl;
9462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_GreaterGreater: return BO_Shr;
9472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_LessLessEqual: return BO_ShlAssign;
9482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_GreaterGreaterEqual: return BO_ShrAssign;
9492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_EqualEqual: return BO_EQ;
9502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_ExclaimEqual: return BO_NE;
9512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_LessEqual: return BO_LE;
9522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_GreaterEqual: return BO_GE;
9532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_AmpAmp: return BO_LAnd;
9542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_PipePipe: return BO_LOr;
9552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_Comma: return BO_Comma;
9562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  case OO_ArrowStar: return BO_PtrMemI;
957063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  }
958063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor}
959063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
960063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) {
961063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static const OverloadedOperatorKind OverOps[] = {
962063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    /* .* Cannot be overloaded */OO_None, OO_ArrowStar,
963063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Star, OO_Slash, OO_Percent,
964063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Plus, OO_Minus,
965063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_LessLess, OO_GreaterGreater,
966063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual,
967063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_EqualEqual, OO_ExclaimEqual,
968063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Amp,
969063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Caret,
970063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Pipe,
971063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_AmpAmp,
972063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_PipePipe,
973063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Equal, OO_StarEqual,
974063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_SlashEqual, OO_PercentEqual,
975063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_PlusEqual, OO_MinusEqual,
976063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_LessLessEqual, OO_GreaterGreaterEqual,
977063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_AmpEqual, OO_CaretEqual,
978063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_PipeEqual,
979063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    OO_Comma
980063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  };
981063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return OverOps[Opc];
982063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor}
983063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
984709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekInitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc,
985418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner                           Expr **initExprs, unsigned numInits,
9864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor                           SourceLocation rbraceloc)
98773460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor  : Expr(InitListExprClass, QualType(), false, false),
988709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    InitExprs(C, numInits),
9891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0),
990c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    UnionFieldInit(0), HadArrayRangeDesignator(false)
991c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt{
992ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  for (unsigned I = 0; I != numInits; ++I) {
993ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    if (initExprs[I]->isTypeDependent())
99473460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor      TypeDependent = true;
995ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    if (initExprs[I]->isValueDependent())
99673460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor      ValueDependent = true;
99773460a32bc5299a5927d23d2e464d72af796eabfDouglas Gregor  }
998c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
999709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits);
100066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1002709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) {
1003ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  if (NumInits > InitExprs.size())
1004709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    InitExprs.reserve(C, NumInits);
1005fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor}
1006fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor
1007709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenekvoid InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) {
1008709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitExprs.resize(C, NumInits, 0);
10094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor}
10104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
1011709210feee317b8d6690dd1d15c2b74cfe55e261Ted KremenekExpr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) {
1012ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  if (Init >= InitExprs.size()) {
1013709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0);
1014ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    InitExprs.back() = expr;
1015ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    return 0;
10164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *Result = cast_or_null<Expr>(InitExprs[Init]);
10194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitExprs[Init] = expr;
10204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  return Result;
10214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor}
10224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
1023bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block.
10244eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff///
10254eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const {
10266217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  return getType()->getAs<BlockPointerType>()->
1027183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall                    getPointeeType()->getAs<FunctionType>();
10284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}
10294eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
10301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpSourceLocation BlockExpr::getCaretLocation() const {
10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return TheBlock->getCaretLocation();
103256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff}
10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst Stmt *BlockExpr::getBody() const {
10347297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor  return TheBlock->getBody();
10357297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor}
10361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt *BlockExpr::getBody() {
10371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return TheBlock->getBody();
10387297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor}
103956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
104056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines
10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1045026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should
1046026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused.  If so, fill in Loc and Ranges
1047026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the
1048026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning.
1049026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattnerbool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
1050df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump                                  SourceRange &R2, ASTContext &Ctx) const {
1051ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson  // Don't warn if the expr is type dependent. The type could end up
1052ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson  // instantiating to void.
1053ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson  if (isTypeDependent())
1054ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson    return false;
10551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
10580faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall    if (getType()->isVoidType())
10590faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall      return false;
1060026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = getExprLoc();
1061026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = getSourceRange();
1062026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass:
1064026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return cast<ParenExpr>(this)->getSubExpr()->
1065df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      isUnusedResultAWarning(Loc, R1, R2, Ctx);
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UnaryOperatorClass: {
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const UnaryOperator *UO = cast<UnaryOperator>(this);
10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (UO->getOpcode()) {
1070026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    default: break;
10712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_PostInc:
10722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_PostDec:
10732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_PreInc:
10742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_PreDec:                 // ++/--
1075026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;  // Not a warning.
10762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Deref:
10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // Dereferencing a volatile pointer is a side-effect.
1078df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      if (Ctx.getCanonicalType(getType()).isVolatileQualified())
1079026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner        return false;
1080026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      break;
10812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Real:
10822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Imag:
10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // accessing a piece of a volatile complex is a side-effect.
1084df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      if (Ctx.getCanonicalType(UO->getSubExpr()->getType())
1085df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump          .isVolatileQualified())
1086026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner        return false;
1087026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      break;
10882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case UO_Extension:
1089df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1091026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = UO->getOperatorLoc();
1092026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = UO->getSubExpr()->getSourceRange();
1093026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1095e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  case BinaryOperatorClass: {
1096026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    const BinaryOperator *BO = cast<BinaryOperator>(this);
1097c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek    switch (BO->getOpcode()) {
1098c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek      default:
1099c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek        break;
110025973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis      // Consider the RHS of comma for side effects. LHS was checked by
110125973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis      // Sema::CheckCommaOperands.
11022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      case BO_Comma:
1103c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek        // ((foo = <blah>), 0) is an idiom for hiding the result (and
1104c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek        // lvalue-ness) of an assignment written in a macro.
1105c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek        if (IntegerLiteral *IE =
1106c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek              dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens()))
1107c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek          if (IE->getValue() == 0)
1108c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5Ted Kremenek            return false;
110925973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis        return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
111025973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis      // Consider '||', '&&' to have side effects if the LHS or RHS does.
11112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      case BO_LAnd:
11122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      case BO_LOr:
111325973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis        if (!BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) ||
111425973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis            !BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx))
111525973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis          return false;
111625973455aed1cdc9c40b208c792b5db4f8f1297dArgyrios Kyrtzidis        break;
1117bf0ee354163f87623a4b60412544243911332343John McCall    }
1118026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (BO->isAssignmentOp())
1119026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;
1120026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = BO->getOperatorLoc();
1121026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = BO->getLHS()->getSourceRange();
1122026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R2 = BO->getRHS()->getSourceRange();
1123026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
1124e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  }
1125eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner  case CompoundAssignOperatorClass:
1126c6dfe194f623b02c123759f235b504d4850fc178Douglas Gregor  case VAArgExprClass:
1127026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1129ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  case ConditionalOperatorClass: {
1130026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // The condition must be evaluated, but if either the LHS or RHS is a
1131026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // warning, warn about them.
1132ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
11331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (Exp->getLHS() &&
1134df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump        Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx))
1135026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return true;
1136df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
1137ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  }
1138ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian
11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case MemberExprClass:
1140026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // If the base pointer or element is to a volatile pointer/field, accessing
1141026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // it is a side effect.
1142df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    if (Ctx.getCanonicalType(getType()).isVolatileQualified())
1143026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;
1144026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<MemberExpr>(this)->getMemberLoc();
1145026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = SourceRange(Loc, Loc);
1146026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R2 = cast<MemberExpr>(this)->getBase()->getSourceRange();
1147026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
11481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ArraySubscriptExprClass:
11505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // If the base pointer or element is to a volatile pointer/field, accessing
1151026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // it is a side effect.
1152df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    if (Ctx.getCanonicalType(getType()).isVolatileQualified())
1153026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      return false;
1154026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc();
1155026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange();
1156026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange();
1157026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
1158211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman
11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case CallExprClass:
1160852871abbff45f1c1d3787755a27fce08365b166Eli Friedman  case CXXOperatorCallExprClass:
1161852871abbff45f1c1d3787755a27fce08365b166Eli Friedman  case CXXMemberCallExprClass: {
1162026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    // If this is a direct call, get the callee.
1163026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    const CallExpr *CE = cast<CallExpr>(this);
1164d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    if (const Decl *FD = CE->getCalleeDecl()) {
1165026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      // If the callee has attribute pure, const, or warn_unused_result, warn
1166026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      // about it. void foo() { strlen("bar"); } should warn.
1167bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      //
1168bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      // Note: If new cases are added here, DiagnoseUnusedExprResult should be
1169bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      // updated to match for QoI.
1170bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      if (FD->getAttr<WarnUnusedResultAttr>() ||
1171bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner          FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) {
1172bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        Loc = CE->getCallee()->getLocStart();
1173bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        R1 = CE->getCallee()->getSourceRange();
1174bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner
1175bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        if (unsigned NumArgs = CE->getNumArgs())
1176bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner          R2 = SourceRange(CE->getArg(0)->getLocStart(),
1177bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner                           CE->getArg(NumArgs-1)->getLocEnd());
1178bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner        return true;
1179bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner      }
1180026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    }
1181026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
1182026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  }
118358beed91d468863b8c85bce43425422703838d27Anders Carlsson
118458beed91d468863b8c85bce43425422703838d27Anders Carlsson  case CXXTemporaryObjectExprClass:
118558beed91d468863b8c85bce43425422703838d27Anders Carlsson  case CXXConstructExprClass:
118658beed91d468863b8c85bce43425422703838d27Anders Carlsson    return false;
118758beed91d468863b8c85bce43425422703838d27Anders Carlsson
1188f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian  case ObjCMessageExprClass: {
1189f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian    const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this);
1190f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian    const ObjCMethodDecl *MD = ME->getMethodDecl();
1191f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian    if (MD && MD->getAttr<WarnUnusedResultAttr>()) {
1192f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian      Loc = getExprLoc();
1193f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian      return true;
1194f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian    }
1195026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
1196f031774aa2638b4d3f487e7e44180c1f89b867efFariborz Jahanian  }
11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
119809105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian  case ObjCImplicitSetterGetterRefExprClass: {   // Dot syntax for message send.
1199a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#if 0
12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    const ObjCImplicitSetterGetterRefExpr *Ref =
120109105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian      cast<ObjCImplicitSetterGetterRefExpr>(this);
1202a50089ec68a583d13718107c1b0c898f0903709eChris Lattner    // FIXME: We really want the location of the '.' here.
1203154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian    Loc = Ref->getLocation();
1204154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian    R1 = SourceRange(Ref->getLocation(), Ref->getLocation());
1205154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian    if (Ref->getBase())
1206154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian      R2 = Ref->getBase()->getSourceRange();
12075e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner#else
12085e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner    Loc = getExprLoc();
12095e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner    R1 = getSourceRange();
1210a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#endif
1211a50089ec68a583d13718107c1b0c898f0903709eChris Lattner    return true;
1212a50089ec68a583d13718107c1b0c898f0903709eChris Lattner  }
1213611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner  case StmtExprClass: {
1214611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // Statement exprs don't logically have side effects themselves, but are
1215611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // sometimes used in macros in ways that give them a type that is unused.
1216611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // For example ({ blah; foo(); }) will end up with a type if foo has a type.
1217611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // however, if the result of the stmt expr is dead, we don't want to emit a
1218611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // warning.
1219611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
1220611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    if (!CS->body_empty())
1221611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner      if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
1222df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump        return E->isUnusedResultAWarning(Loc, R1, R2, Ctx);
12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12240faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall    if (getType()->isVoidType())
12250faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall      return false;
1226026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<StmtExpr>(this)->getLParenLoc();
1227026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = getSourceRange();
1228026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
1229611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner  }
12306eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  case CStyleCastExprClass:
1231fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner    // If this is an explicit cast to void, allow it.  People do this when they
1232fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner    // think they know what they're doing :).
1233026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (getType()->isVoidType())
1234fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner      return false;
1235026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<CStyleCastExpr>(this)->getLParenLoc();
1236026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange();
1237026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
123858beed91d468863b8c85bce43425422703838d27Anders Carlsson  case CXXFunctionalCastExprClass: {
12390faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall    if (getType()->isVoidType())
12400faede6f31b07bcec7b776f2b420c3ea9bb3e58cJohn McCall      return false;
124158beed91d468863b8c85bce43425422703838d27Anders Carlsson    const CastExpr *CE = cast<CastExpr>(this);
1242c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
124358beed91d468863b8c85bce43425422703838d27Anders Carlsson    // If this is a cast to void or a constructor conversion, check the operand.
124458beed91d468863b8c85bce43425422703838d27Anders Carlsson    // Otherwise, the result of the cast is unused.
12452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (CE->getCastKind() == CK_ToVoid ||
12462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall        CE->getCastKind() == CK_ConstructorConversion)
1247df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump      return (cast<CastExpr>(this)->getSubExpr()
1248df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump              ->isUnusedResultAWarning(Loc, R1, R2, Ctx));
1249026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc();
1250026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange();
1251026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return true;
125258beed91d468863b8c85bce43425422703838d27Anders Carlsson  }
12531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12544be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman  case ImplicitCastExprClass:
12554be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman    // Check the operand, since implicit casts are inserted by Sema
1256df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<ImplicitCastExpr>(this)
1257df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
12584be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman
125904421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
1260df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<CXXDefaultArgExpr>(this)
1261df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
12624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  case CXXNewExprClass:
12644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    // FIXME: In theory, there might be new expressions that don't have side
12654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    // effects (e.g. a placement new with an uninitialized POD).
12664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  case CXXDeleteExprClass:
1267026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return false;
12682d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson  case CXXBindTemporaryExprClass:
1269df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<CXXBindTemporaryExpr>(this)
1270df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
12716b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson  case CXXExprWithTemporariesClass:
1272df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    return (cast<CXXExprWithTemporaries>(this)
1273df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump            ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
12744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
127744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able.
12787f4f86a2167abc116275e49c81350fc3225485e5Fariborz Jahanian/// returns true, if it is; false otherwise.
1279102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const {
128044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  switch (getStmtClass()) {
128144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  default:
128244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return false;
128344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ObjCIvarRefExprClass:
128444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return true;
1285207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian  case Expr::UnaryOperatorClass:
1286102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
128744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ParenExprClass:
1288102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
128944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ImplicitCastExprClass:
1290102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
129106b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian  case CStyleCastExprClass:
1292102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx);
1293a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  case DeclRefExprClass: {
129444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    const Decl *D = cast<DeclRefExpr>(this)->getDecl();
1295102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1296102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian      if (VD->hasGlobalStorage())
1297102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian        return true;
1298102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian      QualType T = VD->getType();
129959a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian      // dereferencing to a  pointer is always a gc'able candidate,
130059a53fa3f8ea73bae52ea36d0038f76e9f10729cFariborz Jahanian      // unless it is __weak.
13017e88a60d38b36695520e4f8d9279766ef111a662Daniel Dunbar      return T->isPointerType() &&
13020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall             (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak);
1303102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    }
130444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return false;
130544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  }
130683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  case MemberExprClass: {
130744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    const MemberExpr *M = cast<MemberExpr>(this);
1308102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return M->getBase()->isOBJCGCCandidate(Ctx);
130944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  }
131044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  case ArraySubscriptExprClass:
1311102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx);
131244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  }
131344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian}
13144e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() {
13154e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  Expr* E = this;
13164e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  while (ParenExpr* P = dyn_cast<ParenExpr>(E))
13174e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    E = P->getSubExpr();
13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13194e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  return E;
13204e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek}
13214e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
132256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
132356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand.
132456f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() {
132556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *E = this;
132656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  while (true) {
132756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    if (ParenExpr *P = dyn_cast<ParenExpr>(E))
132856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
132956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else if (CastExpr *P = dyn_cast<CastExpr>(E))
133056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
133156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else
133256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      return E;
133356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
133456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner}
133556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
13362fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCallExpr *Expr::IgnoreParenImpCasts() {
13372fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  Expr *E = this;
13382fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  while (true) {
13392fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall    if (ParenExpr *P = dyn_cast<ParenExpr>(E))
13402fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall      E = P->getSubExpr();
13412fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall    else if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E))
13422fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall      E = P->getSubExpr();
13432fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall    else
13442fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall      return E;
13452fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  }
13462fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall}
13472fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall
1348ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
1349ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size).  Strip off any
1350ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand.
1351ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) {
1352ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *E = this;
1353ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  while (true) {
1354ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    if (ParenExpr *P = dyn_cast<ParenExpr>(E)) {
1355ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      E = P->getSubExpr();
1356ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      continue;
1357ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    }
13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1359ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    if (CastExpr *P = dyn_cast<CastExpr>(E)) {
1360ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      // We ignore integer <-> casts that are of the same width, ptr<->ptr and
13612ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor      // ptr<->int casts of the same width.  We also ignore all identity casts.
1362ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      Expr *SE = P->getSubExpr();
13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1364ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) {
1365ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        E = SE;
1366ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        continue;
1367ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      }
13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13699d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor      if ((E->getType()->isPointerType() ||
13709d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor           E->getType()->isIntegralType(Ctx)) &&
13719d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor          (SE->getType()->isPointerType() ||
13729d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor           SE->getType()->isIntegralType(Ctx)) &&
1373ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner          Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) {
1374ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        E = SE;
1375ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner        continue;
1376ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner      }
1377ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    }
13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1379ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return E;
1380ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
1381ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner}
1382ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
13836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregorbool Expr::isDefaultArgument() const {
13846eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  const Expr *E = this;
13856eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
13866eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    E = ICE->getSubExprAsWritten();
1387c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  return isa<CXXDefaultArgExpr>(E);
13896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor}
1390ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
13912f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// \brief Skip over any no-op casts and any temporary-binding
13922f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor/// expressions.
13932f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregorstatic const Expr *skipTemporaryBindingsAndNoOpCasts(const Expr *E) {
13942f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
13952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (ICE->getCastKind() == CK_NoOp)
13962f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      E = ICE->getSubExpr();
13972f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    else
13982f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      break;
13992f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  }
14002f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14012f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E))
14022f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    E = BE->getSubExpr();
14032f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14042f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
14052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (ICE->getCastKind() == CK_NoOp)
14062f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      E = ICE->getSubExpr();
14072f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    else
14082f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      break;
14092f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  }
1410c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
14112f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  return E;
14122f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor}
14132f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14142f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregorconst Expr *Expr::getTemporaryObject() const {
14152f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  const Expr *E = skipTemporaryBindingsAndNoOpCasts(this);
14162f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14172f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  // A cast can produce a temporary object. The object's construction
14182f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  // is represented as a CXXConstructExpr.
14192f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  if (const CastExpr *Cast = dyn_cast<CastExpr>(E)) {
14202f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // Only user-defined and constructor conversions can produce
14212f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // temporary objects.
14222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Cast->getCastKind() != CK_ConstructorConversion &&
14232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall        Cast->getCastKind() != CK_UserDefinedConversion)
14242f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      return 0;
14252f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14262f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // Strip off temporary bindings and no-op casts.
14272f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    const Expr *Sub = skipTemporaryBindingsAndNoOpCasts(Cast->getSubExpr());
14282f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14292f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // If this is a constructor conversion, see if we have an object
14302f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // construction.
14312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Cast->getCastKind() == CK_ConstructorConversion)
14322f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      return dyn_cast<CXXConstructExpr>(Sub);
14332f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14342f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // If this is a user-defined conversion, see if we have a call to
14352f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // a function that itself returns a temporary object.
14362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Cast->getCastKind() == CK_UserDefinedConversion)
14372f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      if (const CallExpr *CE = dyn_cast<CallExpr>(Sub))
14382f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor        if (CE->getCallReturnType()->isRecordType())
14392f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor          return CE;
14402f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14412f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    return 0;
14422f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  }
14432f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14442f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  // A call returning a class type returns a temporary.
14452f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
14462f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    if (CE->getCallReturnType()->isRecordType())
14472f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      return CE;
14482f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14492f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    return 0;
14502f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  }
14512f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
14522f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  // Explicit temporary object constructors create temporaries.
14532f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  return dyn_cast<CXXTemporaryObjectExpr>(E);
14542f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor}
14552f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
1456898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions
1457898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent.
1458898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) {
1459898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  for (unsigned I = 0; I < NumExprs; ++I)
1460898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    if (Exprs[I]->isTypeDependent())
1461898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      return true;
1462898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1463898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  return false;
1464898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
1465898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1466898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyValueDependentArguments - Determines if any of the expressions
1467898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is value-dependent.
1468898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) {
1469898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  for (unsigned I = 0; I < NumExprs; ++I)
1470898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    if (Exprs[I]->isValueDependent())
1471898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      return true;
1472898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1473898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  return false;
1474898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
1475898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
14764204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCallbool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef) const {
1477c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // This function is attempting whether an expression is an initializer
1478c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // which can be evaluated at compile-time.  isEvaluatable handles most
1479c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // of the cases, but it can't deal with some initializer-specific
1480c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // expressions, and it can't deal with aggregates; we deal with those here,
1481c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  // and fall back to isEvaluatable for the other cases.
1482c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman
14834204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  // If we ever capture reference-binding directly in the AST, we can
14844204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  // kill the second parameter.
14854204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall
14864204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  if (IsForRef) {
14874204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    EvalResult Result;
14884204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    return EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects;
14894204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  }
14901f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman
1491e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  switch (getStmtClass()) {
1492c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  default: break;
1493e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  case StringLiteralClass:
149414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  case ObjCStringLiteralClass:
1495eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  case ObjCEncodeExprClass:
1496e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    return true;
1497b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall  case CXXTemporaryObjectExprClass:
1498b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall  case CXXConstructExprClass: {
1499b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall    const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);
15004204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall
15014204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    // Only if it's
15024204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    // 1) an application of the trivial default constructor or
1503b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall    if (!CE->getConstructor()->isTrivial()) return false;
15044204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    if (!CE->getNumArgs()) return true;
15054204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall
15064204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    // 2) an elidable trivial copy construction of an operand which is
15074204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    //    itself a constant initializer.  Note that we consider the
15084204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    //    operand on its own, *not* as a reference binding.
15094204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    return CE->isElidable() &&
15104204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall           CE->getArg(0)->isConstantInitializer(Ctx, false);
1511b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall  }
151259b5da6d853b4368b984700315adf7b37de05764Nate Begeman  case CompoundLiteralExprClass: {
15131f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // This handles gcc's extension that allows global initializers like
15141f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // "struct x {int x;} x = (struct x) {};".
15151f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // FIXME: This accepts other cases it shouldn't!
151659b5da6d853b4368b984700315adf7b37de05764Nate Begeman    const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer();
15174204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    return Exp->isConstantInitializer(Ctx, false);
151859b5da6d853b4368b984700315adf7b37de05764Nate Begeman  }
1519e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  case InitListExprClass: {
15201f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // FIXME: This doesn't deal with fields with reference types correctly.
15211f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // FIXME: This incorrectly allows pointers cast to integers to be assigned
15221f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman    // to bitfields.
1523e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    const InitListExpr *Exp = cast<InitListExpr>(this);
1524e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    unsigned numInits = Exp->getNumInits();
1525e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    for (unsigned i = 0; i < numInits; i++) {
15264204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      if (!Exp->getInit(i)->isConstantInitializer(Ctx, false))
1527e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson        return false;
1528e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson    }
1529c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    return true;
1530e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  }
15313498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  case ImplicitValueInitExprClass:
15323498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return true;
15333ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner  case ParenExprClass:
15344204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall    return cast<ParenExpr>(this)->getSubExpr()
15354204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      ->isConstantInitializer(Ctx, IsForRef);
1536c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  case UnaryOperatorClass: {
1537c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    const UnaryOperator* Exp = cast<UnaryOperator>(this);
15382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Exp->getOpcode() == UO_Extension)
15394204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      return Exp->getSubExpr()->isConstantInitializer(Ctx, false);
1540c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    break;
1541c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  }
15423ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner  case BinaryOperatorClass: {
15433ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    // Special case &&foo - &&bar.  It would be nice to generalize this somehow
15443ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    // but this handles the common case.
15453ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    const BinaryOperator *Exp = cast<BinaryOperator>(this);
15462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (Exp->getOpcode() == BO_Sub &&
15473ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner        isa<AddrLabelExpr>(Exp->getLHS()->IgnoreParenNoopCasts(Ctx)) &&
15483ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner        isa<AddrLabelExpr>(Exp->getRHS()->IgnoreParenNoopCasts(Ctx)))
15493ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner      return true;
15503ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner    break;
15513ae9f48ae0d07a5aa352bf03c944f557a5ac4c95Chris Lattner  }
15524204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  case CXXFunctionalCastExprClass:
1553b4b9b15c597a923a03ad0a33cdc49b67e5cc4450John McCall  case CXXStaticCastExprClass:
155481045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner  case ImplicitCastExprClass:
1555c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  case CStyleCastExprClass:
1556c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    // Handle casts with a destination that's a struct or union; this
1557c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    // deals with both the gcc no-op struct cast extension and the
1558c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    // cast-to-union extension.
1559c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    if (getType()->isRecordType())
15604204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      return cast<CastExpr>(this)->getSubExpr()
15614204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall        ->isConstantInitializer(Ctx, false);
1562c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1563430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner    // Integer->integer casts can be handled here, which is important for
1564430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner    // things like (int)(&&x-&&y).  Scary but true.
1565430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner    if (getType()->isIntegerType() &&
1566430656e1c392dcd9f17fe91a495421d69fca1bc8Chris Lattner        cast<CastExpr>(this)->getSubExpr()->getType()->isIntegerType())
15674204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall      return cast<CastExpr>(this)->getSubExpr()
15684204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall        ->isConstantInitializer(Ctx, false);
1569c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1570c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman    break;
1571e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson  }
1572c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman  return isEvaluatable(Ctx);
157338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff}
157438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
15755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// integer constant expression with the value zero, or if this is one that is
15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// cast to void*.
1578ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregorbool Expr::isNullPointerConstant(ASTContext &Ctx,
1579ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor                                 NullPointerConstantValueDependence NPC) const {
1580ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  if (isValueDependent()) {
1581ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    switch (NPC) {
1582ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    case NPC_NeverValueDependent:
1583ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      assert(false && "Unexpected value dependent expression!");
1584ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      // If the unthinkable happens, fall through to the safest alternative.
1585c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1586ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    case NPC_ValueDependentIsNull:
15879d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor      return isTypeDependent() || getType()->isIntegralType(Ctx);
1588c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1589ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    case NPC_ValueDependentIsNotNull:
1590ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor      return false;
1591ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    }
1592ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  }
1593f515b2268f829adfbfdb751f54d102b53ed0285cDaniel Dunbar
15940777972d38a3125efed962b045704c30ae6965cfSebastian Redl  // Strip off a cast to void*, if it exists. Except in C++.
15950835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
15966215dee86c0e715b9f2b0d401ab2a5fcf629f1afSebastian Redl    if (!Ctx.getLangOptions().CPlusPlus) {
15970777972d38a3125efed962b045704c30ae6965cfSebastian Redl      // Check that it is a cast to void*.
15986217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek      if (const PointerType *PT = CE->getType()->getAs<PointerType>()) {
15990777972d38a3125efed962b045704c30ae6965cfSebastian Redl        QualType Pointee = PT->getPointeeType();
16000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        if (!Pointee.hasQualifiers() &&
16010777972d38a3125efed962b045704c30ae6965cfSebastian Redl            Pointee->isVoidType() &&                              // to void*
16020777972d38a3125efed962b045704c30ae6965cfSebastian Redl            CE->getSubExpr()->getType()->isIntegerType())         // from int.
1603ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor          return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
16040777972d38a3125efed962b045704c30ae6965cfSebastian Redl      }
16055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1606aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
1607aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Ignore the ImplicitCastExpr type entirely.
1608ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
1609aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
1610aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Accept ((void*)0) as a null pointer constant, as many other
1611aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // implementations do.
1612ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  } else if (const CXXDefaultArgExpr *DefaultArg
16148123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner               = dyn_cast<CXXDefaultArgExpr>(this)) {
161504421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    // See through default argument expressions
1616ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC);
16172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  } else if (isa<GNUNullExpr>(this)) {
16182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    // The GNU __null extension is always a null pointer constant.
16192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return true;
1620aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff  }
16212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
16226e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  // C++0x nullptr_t is always a null pointer constant.
16236e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  if (getType()->isNullPtrType())
16246e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return true;
16256e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
1626aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  // This expression must be an integer type.
1627c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  if (!getType()->isIntegerType() ||
162856fc0d18caf9c829647a5e3ce35197f0d7e0feeeFariborz Jahanian      (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType()))
1629aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    return false;
16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // If we have an integer constant expression, we need to *evaluate* it and
16325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // test for the value 0.
163309de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman  llvm::APSInt Result;
163409de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman  return isIntegerConstantExpr(Result, Ctx) && Result == 0;
16355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
163631a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff
163733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() {
16386f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor  Expr *E = this->IgnoreParens();
163933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
1640de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
16415baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    if (ICE->getValueKind() != VK_RValue &&
16422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall        ICE->getCastKind() == CK_NoOp)
1643de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor      E = ICE->getSubExpr()->IgnoreParens();
1644de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor    else
1645de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor      break;
1646de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor  }
1647de4b1d86bf48bc2a84bddf6b188f6da53eaea845Douglas Gregor
164827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E))
164986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl()))
165033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor      if (Field->isBitField())
165133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor        return Field;
165233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
165333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E))
165433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor    if (BinOp->isAssignmentOp() && BinOp->getLHS())
165533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor      return BinOp->getLHS()->getBitField();
165633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
165733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  return 0;
165827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor}
165927c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor
1660093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlssonbool Expr::refersToVectorElement() const {
1661093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  const Expr *E = this->IgnoreParens();
1662c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1663093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
16645baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    if (ICE->getValueKind() != VK_RValue &&
16652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall        ICE->getCastKind() == CK_NoOp)
1666093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson      E = ICE->getSubExpr()->IgnoreParens();
1667093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson    else
1668093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson      break;
1669093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  }
1670c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1671093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E))
1672093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson    return ASE->getBase()->getType()->isVectorType();
1673093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson
1674093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  if (isa<ExtVectorElementExpr>(E))
1675093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson    return true;
1676093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson
1677093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  return false;
1678093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson}
1679093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson
16802140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector,
16812140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector.
16822140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const {
16832140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  return getBase()->getType()->isPointerType();
16842140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner}
16852140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner
1686213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const {
1687183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const VectorType *VT = getType()->getAs<VectorType>())
16888a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    return VT->getNumElements();
16898a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  return 1;
16904d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner}
16914d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner
16928a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated.
1693213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const {
1694a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar  // FIXME: Refactor this code to an accessor on the AST node which returns the
1695a2b34eb7d19d1d199a244da20afe12353e3593acDaniel Dunbar  // "type" of component access, and share with code below and in Sema.
169601eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar  llvm::StringRef Comp = Accessor->getName();
1697190d6a25393995b42e32086949a68285ee423fb9Nate Begeman
1698190d6a25393995b42e32086949a68285ee423fb9Nate Begeman  // Halving swizzles do not contain duplicate elements.
1699150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar  if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd")
1700190d6a25393995b42e32086949a68285ee423fb9Nate Begeman    return false;
17011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1702190d6a25393995b42e32086949a68285ee423fb9Nate Begeman  // Advance past s-char prefix on hex swizzles.
1703150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar  if (Comp[0] == 's' || Comp[0] == 'S')
1704150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar    Comp = Comp.substr(1);
17051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1706150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar  for (unsigned i = 0, e = Comp.size(); i != e; ++i)
1707150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar    if (Comp.substr(i + 1).find(Comp[i]) != llvm::StringRef::npos)
1708fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff        return true;
1709150274299b0bc2efda45783f99bef3f9f6e807acDaniel Dunbar
1710fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  return false;
1711fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff}
1712b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
17138a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
17143b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess(
17153b8d116703db8018f855cbb4733ace426422623bNate Begeman                                  llvm::SmallVectorImpl<unsigned> &Elts) const {
17164b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  llvm::StringRef Comp = Accessor->getName();
17174b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  if (Comp[0] == 's' || Comp[0] == 'S')
17184b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar    Comp = Comp.substr(1);
17191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17204b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isHi =   Comp == "hi";
17214b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isLo =   Comp == "lo";
17224b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isEven = Comp == "even";
17234b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar  bool isOdd  = Comp == "odd";
17241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17258a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
17268a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    uint64_t Index;
17271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17288a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    if (isHi)
17298a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = e + i;
17308a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isLo)
17318a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = i;
17328a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isEven)
17338a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i;
17348a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isOdd)
17358a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i + 1;
17368a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else
17374b55b24410a2739c589c4b9e84a364161c9a17e5Daniel Dunbar      Index = ExtVectorType::getAccessorIdx(Comp[i]);
1738b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
17393b8d116703db8018f855cbb4733ace426422623bNate Begeman    Elts.push_back(Index);
1740b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
17418a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman}
17428a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
174304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T,
174404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation LBracLoc,
174504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation SuperLoc,
174604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 bool IsInstanceSuper,
174704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 QualType SuperType,
1748c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                 Selector Sel,
174904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 ObjCMethodDecl *Method,
175004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 Expr **Args, unsigned NumArgs,
175104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation RBracLoc)
175204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  : Expr(ObjCMessageExprClass, T, /*TypeDependent=*/false,
175392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor         /*ValueDependent=*/false),
175404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs(NumArgs), Kind(IsInstanceSuper? SuperInstance : SuperClass),
175504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    HasMethod(Method != 0), SuperLoc(SuperLoc),
175604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
175704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                                       : Sel.getAsOpaquePtr())),
1758c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    LBracLoc(LBracLoc), RBracLoc(RBracLoc)
1759c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor{
176004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  setReceiverPointer(SuperType.getAsOpaquePtr());
176104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (NumArgs)
176204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
176304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
176404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
176504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T,
176604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation LBracLoc,
176704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 TypeSourceInfo *Receiver,
1768c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                 Selector Sel,
176904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 ObjCMethodDecl *Method,
177004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 Expr **Args, unsigned NumArgs,
177104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation RBracLoc)
177204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  : Expr(ObjCMessageExprClass, T, T->isDependentType(),
1773c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt         (T->isDependentType() ||
177404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor          hasAnyValueDependentArguments(Args, NumArgs))),
177504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs(NumArgs), Kind(Class), HasMethod(Method != 0),
177604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
177704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                                       : Sel.getAsOpaquePtr())),
1778c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    LBracLoc(LBracLoc), RBracLoc(RBracLoc)
177904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{
178004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  setReceiverPointer(Receiver);
178104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (NumArgs)
178204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
178304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
178404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
178504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr::ObjCMessageExpr(QualType T,
178604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation LBracLoc,
178704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 Expr *Receiver,
1788c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                 Selector Sel,
178904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 ObjCMethodDecl *Method,
179004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 Expr **Args, unsigned NumArgs,
179104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                 SourceLocation RBracLoc)
179292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor  : Expr(ObjCMessageExprClass, T, Receiver->isTypeDependent(),
1793c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt         (Receiver->isTypeDependent() ||
179404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor          hasAnyValueDependentArguments(Args, NumArgs))),
179504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs(NumArgs), Kind(Instance), HasMethod(Method != 0),
179604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    SelectorOrMethod(reinterpret_cast<uintptr_t>(Method? Method
179704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                                       : Sel.getAsOpaquePtr())),
1798c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    LBracLoc(LBracLoc), RBracLoc(RBracLoc)
179904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor{
180004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  setReceiverPointer(Receiver);
180104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (NumArgs)
180204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    memcpy(getArgs(), Args, NumArgs * sizeof(Expr *));
180304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
180404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
180504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
180604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation LBracLoc,
180704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation SuperLoc,
180804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         bool IsInstanceSuper,
180904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         QualType SuperType,
1810c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                         Selector Sel,
181104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         ObjCMethodDecl *Method,
181204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         Expr **Args, unsigned NumArgs,
181304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation RBracLoc) {
1814c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
181504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs * sizeof(Expr *);
181604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
181704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return new (Mem) ObjCMessageExpr(T, LBracLoc, SuperLoc, IsInstanceSuper,
1818c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                   SuperType, Sel, Method, Args, NumArgs,
181904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                   RBracLoc);
182004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
182104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
182204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
182304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation LBracLoc,
182404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         TypeSourceInfo *Receiver,
1825c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                         Selector Sel,
182604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         ObjCMethodDecl *Method,
182704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         Expr **Args, unsigned NumArgs,
182804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation RBracLoc) {
1829c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
183004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs * sizeof(Expr *);
183104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
1832c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return new (Mem) ObjCMessageExpr(T, LBracLoc, Receiver, Sel, Method, Args,
183304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                   NumArgs, RBracLoc);
183404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
183504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
183604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCMessageExpr *ObjCMessageExpr::Create(ASTContext &Context, QualType T,
183704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation LBracLoc,
183804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         Expr *Receiver,
1839c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                         Selector Sel,
184004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         ObjCMethodDecl *Method,
184104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         Expr **Args, unsigned NumArgs,
184204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                         SourceLocation RBracLoc) {
1843c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
184404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs * sizeof(Expr *);
184504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
1846c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return new (Mem) ObjCMessageExpr(T, LBracLoc, Receiver, Sel, Method, Args,
184704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                   NumArgs, RBracLoc);
184804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
184904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
1850c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntObjCMessageExpr *ObjCMessageExpr::CreateEmpty(ASTContext &Context,
185104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                              unsigned NumArgs) {
1852c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
185304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    NumArgs * sizeof(Expr *);
185404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  void *Mem = Context.Allocate(Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
185504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return new (Mem) ObjCMessageExpr(EmptyShell(), NumArgs);
185604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
1857c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
185804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorSelector ObjCMessageExpr::getSelector() const {
185904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (HasMethod)
186004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod)
186104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                                                               ->getSelector();
1862c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  return Selector(SelectorOrMethod);
186304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor}
186404badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor
186504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas GregorObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const {
186604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  switch (getReceiverKind()) {
186704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case Instance:
186804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    if (const ObjCObjectPointerType *Ptr
186904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor          = getInstanceReceiver()->getType()->getAs<ObjCObjectPointerType>())
187004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor      return Ptr->getInterfaceDecl();
187104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
18724df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek
187304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case Class:
1874c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const ObjCObjectType *Ty
1875c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          = getClassReceiver()->getAs<ObjCObjectType>())
1876c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return Ty->getInterface();
187704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
18784df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek
187904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case SuperInstance:
188004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    if (const ObjCObjectPointerType *Ptr
188104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor          = getSuperType()->getAs<ObjCObjectPointerType>())
188204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor      return Ptr->getInterfaceDecl();
188304badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
1884c2350e553b853ad00914faf23fa731e5fc4a8a5cDouglas Gregor
188504badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  case SuperClass:
188604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    if (const ObjCObjectPointerType *Iface
188704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor                       = getSuperType()->getAs<ObjCObjectPointerType>())
188804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor      return Iface->getInterfaceDecl();
188904badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    break;
189004badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  }
18910389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner
189204badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return 0;
1893eb3b324800598cc3d5385fbad95ae5cff2c79113Ted Kremenek}
18940389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner
189527437caadea35f84d550cd29f024fcf3ea240eecChris Lattnerbool ChooseExpr::isConditionTrue(ASTContext &C) const {
18969a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman  return getCond()->EvaluateAsInt(C) != 0;
189727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner}
189827437caadea35f84d550cd29f024fcf3ea240eecChris Lattner
1899888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs,
1900888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman                                 unsigned NumExprs) {
1901888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  if (SubExprs) C.Deallocate(SubExprs);
1902888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
1903888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  SubExprs = new (C) Stmt* [NumExprs];
190494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  this->NumExprs = NumExprs;
190594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs);
19061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
1907888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
190877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
190905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//  DesignatedInitExpr
191005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===//
191105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
191205c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() {
191305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  assert(Kind == FieldDesignator && "Only valid on a field designator");
191405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  if (Field.NameOrField & 0x01)
191505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01);
191605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  else
191705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return getField()->getIdentifier();
191805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
191905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
1920c302113179a1c2b1254224ea9b6f5316ceeb375cSean HuntDesignatedInitExpr::DesignatedInitExpr(ASTContext &C, QualType Ty,
1921319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                                       unsigned NumDesignators,
1922ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                                       const Designator *Designators,
19231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                       SourceLocation EqualOrColonLoc,
1924ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                                       bool GNUSyntax,
19251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                       Expr **IndexExprs,
19269ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                       unsigned NumIndexExprs,
19279ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                       Expr *Init)
19281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Expr(DesignatedInitExprClass, Ty,
19299ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor         Init->isTypeDependent(), Init->isValueDependent()),
19301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
19311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) {
1932319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  this->Designators = new (C) Designator[NumDesignators];
19339ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
19349ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // Record the initializer itself.
19359ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  child_iterator Child = child_begin();
19369ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  *Child++ = Init;
19379ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
19389ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // Copy the designators and their subexpressions, computing
19399ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // value-dependence along the way.
19409ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  unsigned IndexIdx = 0;
19419ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  for (unsigned I = 0; I != NumDesignators; ++I) {
1942ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    this->Designators[I] = Designators[I];
19439ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
19449ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    if (this->Designators[I].isArrayDesignator()) {
19459ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Compute type- and value-dependence.
19469ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      Expr *Index = IndexExprs[IndexIdx];
19471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ValueDependent = ValueDependent ||
19489ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor        Index->isTypeDependent() || Index->isValueDependent();
19499ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
19509ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Copy the index expressions into permanent storage.
19519ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      *Child++ = IndexExprs[IndexIdx++];
19529ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    } else if (this->Designators[I].isArrayRangeDesignator()) {
19539ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Compute type- and value-dependence.
19549ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      Expr *Start = IndexExprs[IndexIdx];
19559ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      Expr *End = IndexExprs[IndexIdx + 1];
19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ValueDependent = ValueDependent ||
19579ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor        Start->isTypeDependent() || Start->isValueDependent() ||
19589ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor        End->isTypeDependent() || End->isValueDependent();
19599ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
19609ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      // Copy the start/end expressions into permanent storage.
19619ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      *Child++ = IndexExprs[IndexIdx++];
19629ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor      *Child++ = IndexExprs[IndexIdx++];
19639ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    }
19649ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  }
19659ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
19669ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions");
1967ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor}
1968ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
196905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr *
19701eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr::Create(ASTContext &C, Designator *Designators,
197105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           unsigned NumDesignators,
197205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           Expr **IndexExprs, unsigned NumIndexExprs,
197305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           SourceLocation ColonOrEqualLoc,
197405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                           bool UsesColonSyntax, Expr *Init) {
1975c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff  void *Mem = C.Allocate(sizeof(DesignatedInitExpr) +
1976c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff                         sizeof(Stmt *) * (NumIndexExprs + 1), 8);
1977319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  return new (Mem) DesignatedInitExpr(C, C.VoidTy, NumDesignators, Designators,
19789ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                      ColonOrEqualLoc, UsesColonSyntax,
19799ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                                      IndexExprs, NumIndexExprs, Init);
198005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
198105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
19821eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C,
1983d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor                                                    unsigned NumIndexExprs) {
1984d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void *Mem = C.Allocate(sizeof(DesignatedInitExpr) +
1985d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor                         sizeof(Stmt *) * (NumIndexExprs + 1), 8);
1986d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  return new (Mem) DesignatedInitExpr(NumIndexExprs + 1);
1987d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor}
1988d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
1989319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::setDesignators(ASTContext &C,
1990319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                                        const Designator *Desigs,
1991d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor                                        unsigned NumDesigs) {
1992319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  Designators = new (C) Designator[NumDesigs];
1993d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  NumDesignators = NumDesigs;
1994d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  for (unsigned I = 0; I != NumDesigs; ++I)
1995d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Designators[I] = Desigs[I];
1996d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor}
1997d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
199805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const {
199905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation StartLoc;
2000d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner  Designator &First =
2001d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner    *const_cast<DesignatedInitExpr*>(this)->designators_begin();
200205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  if (First.isFieldDesignator()) {
2003eeae8f072748affce25ab4064982626361293390Douglas Gregor    if (GNUSyntax)
200405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc);
200505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    else
200605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc);
200705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  } else
2008d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner    StartLoc =
2009d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner      SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc);
201005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return SourceRange(StartLoc, getInit()->getSourceRange().getEnd());
201105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
201205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
201305c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) {
201405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  assert(D.Kind == Designator::ArrayDesignator && "Requires array designator");
201505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
201605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
201705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
201805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
201905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
202005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
202105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) {
20221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  assert(D.Kind == Designator::ArrayRangeDesignator &&
202305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor         "Requires array range designator");
202405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
202505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
202605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
202705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
202805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
202905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
203005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) {
20311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  assert(D.Kind == Designator::ArrayRangeDesignator &&
203205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor         "Requires array range designator");
203305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
203405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
203505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
203605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2));
203705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
203805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2039ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series
2040ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last).
2041319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(ASTContext &C, unsigned Idx,
20421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                          const Designator *First,
2043ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                                          const Designator *Last) {
2044ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  unsigned NumNewDesignators = Last - First;
2045ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  if (NumNewDesignators == 0) {
2046ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    std::copy_backward(Designators + Idx + 1,
2047ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                       Designators + NumDesignators,
2048ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                       Designators + Idx);
2049ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    --NumNewDesignators;
2050ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return;
2051ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  } else if (NumNewDesignators == 1) {
2052ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designators[Idx] = *First;
2053ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return;
2054ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
2055ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
20561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Designator *NewDesignators
2057319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor    = new (C) Designator[NumDesignators - 1 + NumNewDesignators];
2058ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  std::copy(Designators, Designators + Idx, NewDesignators);
2059ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  std::copy(First, Last, NewDesignators + Idx);
2060ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  std::copy(Designators + Idx + 1, Designators + NumDesignators,
2061ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor            NewDesignators + Idx + NumNewDesignators);
2062ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designators = NewDesignators;
2063ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  NumDesignators = NumDesignators - 1 + NumNewDesignators;
2064ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor}
2065ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
20661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc,
20672ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                             Expr **exprs, unsigned nexprs,
20682ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                             SourceLocation rparenloc)
20692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman: Expr(ParenListExprClass, QualType(),
20702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman       hasAnyTypeDependentArguments(exprs, nexprs),
20711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump       hasAnyValueDependentArguments(exprs, nexprs)),
20722ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) {
20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Exprs = new (C) Stmt*[nexprs];
20752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  for (unsigned i = 0; i != nexprs; ++i)
20762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    Exprs[i] = exprs[i];
20772ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
20782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
207905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===//
2080ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//  ExprIterator.
2081ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
2082ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
2083ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); }
2084ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); }
2085ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); }
2086ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const {
2087ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek  return cast<Expr>(I[idx]);
2088ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek}
2089ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); }
2090ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); }
2091ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek
2092ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===//
209377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//  Child Iterators for iterating over subexpressions/substatements
209477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
209577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
209677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// DeclRefExpr
20979ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
20989ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
209977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
21007779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff// ObjCIvarRefExpr
21015549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; }
21025549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; }
21037779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff
2104e3e9add4fd788927df6f545570e7838db59c01d7Steve Naroff// ObjCPropertyRefExpr
21055549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; }
21065549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; }
2107ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff
210809105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian// ObjCImplicitSetterGetterRefExpr
21091eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_begin() {
21102fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  // If this is accessing a class member, skip that entry.
21112fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  if (Base) return &Base;
21122fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  return &Base+1;
2113154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian}
21141eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_end() {
21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return &Base+1;
2116154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian}
21175daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian
2118cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor// ObjCSuperExpr
2119cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); }
2120cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); }
2121cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor
2122f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff// ObjCIsaExpr
2123f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; }
2124f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; }
2125f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff
2126d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner// PredefinedExpr
2127d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); }
2128d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); }
212977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
213077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// IntegerLiteral
21319ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); }
21329ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); }
213377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
213477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CharacterLiteral
2135d603eaa682cecac2c10771a700cb83aa301653b4Chris LattnerStmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();}
21369ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); }
213777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
213877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// FloatingLiteral
21399ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); }
21409ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); }
214177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
21425d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner// ImaginaryLiteral
21435549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; }
21445549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; }
21455d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
214677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// StringLiteral
21479ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_begin() { return child_iterator(); }
21489ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_end() { return child_iterator(); }
214977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
215077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ParenExpr
21515549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_begin() { return &Val; }
21525549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_end() { return &Val+1; }
215377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
215477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// UnaryOperator
21555549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_begin() { return &Val; }
21565549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_end() { return &Val+1; }
215777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
21588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor// OffsetOfExpr
21598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorStmt::child_iterator OffsetOfExpr::child_begin() {
21608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return reinterpret_cast<Stmt **> (reinterpret_cast<OffsetOfNode *> (this + 1)
21618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                      + NumComps);
21628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
21638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorStmt::child_iterator OffsetOfExpr::child_end() {
21648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  return child_iterator(&*child_begin() + NumExprs);
21658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}
21668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
21670518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl// SizeOfAlignOfExpr
21681eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator SizeOfAlignOfExpr::child_begin() {
21690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // If this is of a type and the type is a VLA type (and not a typedef), the
21700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // size expression of the VLA needs to be treated as an executable expression.
21710518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  // Why isn't this weirdness documented better in StmtIterator?
21720518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  if (isArgumentType()) {
21730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    if (VariableArrayType* T = dyn_cast<VariableArrayType>(
21740518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                                   getArgumentType().getTypePtr()))
21750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl      return child_iterator(T);
21760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return child_iterator();
21770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
2178d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  return child_iterator(&Argument.Ex);
21799ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
21800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian RedlStmt::child_iterator SizeOfAlignOfExpr::child_end() {
21810518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  if (isArgumentType())
21820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return child_iterator();
2183d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  return child_iterator(&Argument.Ex + 1);
21849ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
218577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
218677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ArraySubscriptExpr
21871237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_begin() {
21885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
218977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
21901237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_end() {
21915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
219277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
219377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
219477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CallExpr
21951237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_begin() {
21965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
219777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
21981237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_end() {
21995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+NumArgs+ARGS_START;
220077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
22011237c673c07f9d827129ba02720108816abde562Ted Kremenek
22021237c673c07f9d827129ba02720108816abde562Ted Kremenek// MemberExpr
22035549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_begin() { return &Base; }
22045549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_end() { return &Base+1; }
22051237c673c07f9d827129ba02720108816abde562Ted Kremenek
2206213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman// ExtVectorElementExpr
22075549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; }
22085549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; }
22091237c673c07f9d827129ba02720108816abde562Ted Kremenek
22101237c673c07f9d827129ba02720108816abde562Ted Kremenek// CompoundLiteralExpr
22115549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; }
22125549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; }
22131237c673c07f9d827129ba02720108816abde562Ted Kremenek
22141237c673c07f9d827129ba02720108816abde562Ted Kremenek// CastExpr
22155549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_begin() { return &Op; }
22165549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_end() { return &Op+1; }
22171237c673c07f9d827129ba02720108816abde562Ted Kremenek
22181237c673c07f9d827129ba02720108816abde562Ted Kremenek// BinaryOperator
22191237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_begin() {
22205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
22211237c673c07f9d827129ba02720108816abde562Ted Kremenek}
22221237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_end() {
22235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
22241237c673c07f9d827129ba02720108816abde562Ted Kremenek}
22251237c673c07f9d827129ba02720108816abde562Ted Kremenek
22261237c673c07f9d827129ba02720108816abde562Ted Kremenek// ConditionalOperator
22271237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_begin() {
22285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
22291237c673c07f9d827129ba02720108816abde562Ted Kremenek}
22301237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_end() {
22315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
22321237c673c07f9d827129ba02720108816abde562Ted Kremenek}
22331237c673c07f9d827129ba02720108816abde562Ted Kremenek
22341237c673c07f9d827129ba02720108816abde562Ted Kremenek// AddrLabelExpr
22359ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); }
22369ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); }
22371237c673c07f9d827129ba02720108816abde562Ted Kremenek
22381237c673c07f9d827129ba02720108816abde562Ted Kremenek// StmtExpr
22395549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_begin() { return &SubStmt; }
22405549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; }
22411237c673c07f9d827129ba02720108816abde562Ted Kremenek
22421237c673c07f9d827129ba02720108816abde562Ted Kremenek// TypesCompatibleExpr
22439ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_begin() {
22449ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
22459ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
22469ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek
22479ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_end() {
22489ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
22499ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
22501237c673c07f9d827129ba02720108816abde562Ted Kremenek
22511237c673c07f9d827129ba02720108816abde562Ted Kremenek// ChooseExpr
22525549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; }
22535549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; }
22542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
22552d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor// GNUNullExpr
22562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); }
22572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); }
22581237c673c07f9d827129ba02720108816abde562Ted Kremenek
2259d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman// ShuffleVectorExpr
2260d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_begin() {
22615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
2262d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
2263d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_end() {
22645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+NumExprs;
2265d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
2266d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
22677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson// VAArgExpr
22685549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_begin() { return &Val; }
22695549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_end() { return &Val+1; }
22707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
227166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson// InitListExpr
2272ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed KremenekStmt::child_iterator InitListExpr::child_begin() {
2273ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  return InitExprs.size() ? &InitExprs[0] : 0;
2274ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek}
2275ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed KremenekStmt::child_iterator InitListExpr::child_end() {
2276ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0;
2277ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek}
227866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
22793498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// DesignatedInitExpr
228005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_begin() {
228105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  char* Ptr = static_cast<char*>(static_cast<void *>(this));
228205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Ptr += sizeof(DesignatedInitExpr);
228305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
228405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
228505c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_end() {
228605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return child_iterator(&*child_begin() + NumSubExprs);
228705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
228805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
22893498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// ImplicitValueInitExpr
22901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_begin() {
22911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return child_iterator();
22923498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}
22933498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
22941eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ImplicitValueInitExpr::child_end() {
22951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return child_iterator();
22963498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}
22973498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
22982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman// ParenListExpr
22992ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_begin() {
23002ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  return &Exprs[0];
23012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
23022ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_end() {
23032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  return &Exprs[0]+NumExprs;
23042ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}
23052ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
23061237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCStringLiteral
23071eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCStringLiteral::child_begin() {
2308c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner  return &String;
23099ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
23109ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_end() {
2311c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner  return &String+1;
23129ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
23131237c673c07f9d827129ba02720108816abde562Ted Kremenek
23141237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCEncodeExpr
23159ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); }
23169ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); }
23171237c673c07f9d827129ba02720108816abde562Ted Kremenek
2318b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian// ObjCSelectorExpr
23191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCSelectorExpr::child_begin() {
23209ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
23219ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
23229ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_end() {
23239ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
23249ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
2325b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
2326390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian// ObjCProtocolExpr
23279ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_begin() {
23289ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
23299ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
23309ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_end() {
23319ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
23329ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
2333390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian
2334563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr
23351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpStmt::child_iterator ObjCMessageExpr::child_begin() {
233604badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  if (getReceiverKind() == Instance)
233704badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor    return reinterpret_cast<Stmt **>(this + 1);
233804badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return getArgs();
2339563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
2340563477da25f824e37c535131695dc4dc9b68c465Steve NaroffStmt::child_iterator ObjCMessageExpr::child_end() {
234104badcf84c8d504d8491c7c7e29b58f52cb16640Douglas Gregor  return getArgs() + getNumArgs();
2342563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
2343563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
23444eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks
234556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_begin() { return child_iterator(); }
234656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_end() { return child_iterator(); }
23474eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
23489da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();}
23499da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); }
2350