Expr.cpp revision 4be1f47de20525ad90f02ba8682a7e2cbd3205d1
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
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h"
152eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner#include "clang/AST/ASTContext.h"
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/StmtVisitor.h"
17c7229c338c21ef26b01ef3ecf9eec4fd373fa9ecChris Lattner#include "clang/Basic/IdentifierTable.h"
18da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h"
198a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman#include "llvm/Constants.h"
208a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman#include "llvm/DerivedTypes.h"
215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang;
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerStringLiteral::StringLiteral(const char *strData, unsigned byteLength,
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool Wide, QualType t, SourceLocation firstLoc,
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             SourceLocation lastLoc) :
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr(StringLiteralClass, t) {
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // OPTIMIZE: could allocate this appended to the StringLiteral.
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  char *AStrData = new char[byteLength];
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  memcpy(AStrData, strData, byteLength);
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  StrData = AStrData;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ByteLength = byteLength;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IsWide = Wide;
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  firstTokLoc = firstLoc;
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  lastTokLoc = lastLoc;
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerStringLiteral::~StringLiteral() {
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  delete[] StrData;
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool UnaryOperator::isPostfix(Opcode Op) {
465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostInc:
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostDec:
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return true;
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++".
575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) {
585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default: assert(0 && "Unknown unary operator");
605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostInc: return "++";
615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostDec: return "--";
625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PreInc:  return "++";
635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PreDec:  return "--";
645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AddrOf:  return "&";
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Deref:   return "*";
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Plus:    return "+";
675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Minus:   return "-";
685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Not:     return "~";
695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LNot:    return "!";
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Real:    return "__real";
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Imag:    return "__imag";
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case SizeOf:  return "sizeof";
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AlignOf: return "alignof";
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Extension: return "__extension__";
7573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  case OffsetOf: return "__builtin_offsetof";
765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
83e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerCallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                   SourceLocation rparenloc)
8677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  : Expr(CallExprClass, t), NumArgs(numargs) {
8777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  SubExprs = new Expr*[numargs+1];
8877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  SubExprs[FN] = fn;
895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  for (unsigned i = 0; i != numargs; ++i)
9077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    SubExprs[i+ARGS_START] = args[i];
915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RParenLoc = rparenloc;
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
94d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call.
95d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set
96d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null.
97d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattnervoid CallExpr::setNumArgs(unsigned NumArgs) {
98d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // No change, just return.
99d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs == getNumArgs()) return;
100d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
101d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // If shrinking # arguments, just delete the extras and forgot them.
102d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs < getNumArgs()) {
103d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i)
104d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner      delete getArg(i);
105d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    this->NumArgs = NumArgs;
106d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    return;
107d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  }
108d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
109d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Otherwise, we are growing the # arguments.  New an bigger argument array.
110d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  Expr **NewSubExprs = new Expr*[NumArgs+1];
111d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Copy over args.
112d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i)
113d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = SubExprs[i];
114d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Null out new args.
115d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
116d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = 0;
117d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
118d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  delete[] SubExprs;
119d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SubExprs = NewSubExprs;
120d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  this->NumArgs = NumArgs;
121d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner}
122d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
123c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroffbool CallExpr::isBuiltinConstantExpr() const {
124c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // All simple function calls (e.g. func()) are implicitly cast to pointer to
125c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // function. As a result, we try and obtain the DeclRefExpr from the
126c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // ImplicitCastExpr.
127c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
128c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
129c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff    return false;
130c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff
131c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
132c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!DRE)
133c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff    return false;
134c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff
135bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
136bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  if (!FDecl)
137bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson    return false;
138bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson
139bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  unsigned builtinID = FDecl->getIdentifier()->getBuiltinID();
140bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  if (!builtinID)
141bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson    return false;
142bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson
143bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  // We have a builtin that is a constant expression
144861dc46e3c53d64d8685fd9a0f95faac710b61c6Eli Friedman  return builtinID == Builtin::BI__builtin___CFStringMakeConstantString ||
145861dc46e3c53d64d8685fd9a0f95faac710b61c6Eli Friedman         builtinID == Builtin::BI__builtin_classify_type;
146c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff}
147d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
14813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool CallExpr::isBuiltinClassifyType(llvm::APSInt &Result) const {
14913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  // The following enum mimics gcc's internal "typeclass.h" file.
15013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  enum gcc_type_class {
15113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    no_type_class = -1,
15213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    void_type_class, integer_type_class, char_type_class,
15313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    enumeral_type_class, boolean_type_class,
15413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    pointer_type_class, reference_type_class, offset_type_class,
15513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    real_type_class, complex_type_class,
15613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    function_type_class, method_type_class,
15713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    record_type_class, union_type_class,
15813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    array_type_class, string_type_class,
15913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    lang_type_class
16013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  };
16113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  Result.setIsSigned(true);
16213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff
16313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  // All simple function calls (e.g. func()) are implicitly cast to pointer to
16413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  // function. As a result, we try and obtain the DeclRefExpr from the
16513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  // ImplicitCastExpr.
16613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
16713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
16813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    return false;
16913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
17013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  if (!DRE)
17113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    return false;
17213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff
17313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  // We have a DeclRefExpr.
17413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  if (strcmp(DRE->getDecl()->getName(), "__builtin_classify_type") == 0) {
17513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    // If no argument was supplied, default to "no_type_class". This isn't
17613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    // ideal, however it's what gcc does.
17713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    Result = static_cast<uint64_t>(no_type_class);
17813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    if (NumArgs >= 1) {
17913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      QualType argType = getArg(0)->getType();
18013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff
18113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      if (argType->isVoidType())
18213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = void_type_class;
18313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isEnumeralType())
18413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = enumeral_type_class;
18513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isBooleanType())
18613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = boolean_type_class;
18713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isCharType())
18813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = string_type_class; // gcc doesn't appear to use char_type_class
18913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isIntegerType())
19013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = integer_type_class;
19113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isPointerType())
19213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = pointer_type_class;
19313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isReferenceType())
19413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = reference_type_class;
19513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isRealType())
19613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = real_type_class;
19713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isComplexType())
19813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = complex_type_class;
19913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isFunctionType())
20013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = function_type_class;
20113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isStructureType())
20213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = record_type_class;
20313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isUnionType())
20413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = union_type_class;
20513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isArrayType())
20613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = array_type_class;
20713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else if (argType->isUnionType())
20813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff        Result = union_type_class;
20913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      else  // FIXME: offset_type_class, method_type_class, & lang_type_class?
2103ef5bc03d0bfc05fd76fc83beeb1b7ddbbb463daChris Lattner        assert(0 && "CallExpr::isBuiltinClassifyType(): unimplemented type");
21113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    }
21213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    return true;
21313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  }
21413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  return false;
21513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff}
21613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff
2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=".
2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) {
2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default: assert(0 && "Unknown binary operator");
2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Mul:       return "*";
2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Div:       return "/";
2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Rem:       return "%";
2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Add:       return "+";
2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Sub:       return "-";
2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Shl:       return "<<";
2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Shr:       return ">>";
2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LT:        return "<";
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case GT:        return ">";
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LE:        return "<=";
2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case GE:        return ">=";
2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case EQ:        return "==";
2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case NE:        return "!=";
2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case And:       return "&";
2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Xor:       return "^";
2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Or:        return "|";
2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LAnd:      return "&&";
2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LOr:       return "||";
2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Assign:    return "=";
2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case MulAssign: return "*=";
2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DivAssign: return "/=";
2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case RemAssign: return "%=";
2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AddAssign: return "+=";
2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case SubAssign: return "-=";
2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ShlAssign: return "<<=";
2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ShrAssign: return ">>=";
2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AndAssign: return "&=";
2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case XorAssign: return "^=";
2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case OrAssign:  return "|=";
2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Comma:     return ",";
2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonInitListExpr::InitListExpr(SourceLocation lbraceloc,
25666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson                           Expr **initexprs, unsigned numinits,
25766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson                           SourceLocation rbraceloc)
258c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  : Expr(InitListExprClass, QualType()),
259c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    LBraceLoc(lbraceloc), RBraceLoc(rbraceloc)
26066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson{
26166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  for (unsigned i = 0; i != numinits; i++)
262c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    InitExprs.push_back(initexprs[i]);
26366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines
2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// hasLocalSideEffect - Return true if this immediate expression has side
2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// effects, not counting any sub-expressions.
2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Expr::hasLocalSideEffect() const {
2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass:
2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return cast<ParenExpr>(this)->getSubExpr()->hasLocalSideEffect();
2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UnaryOperatorClass: {
2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const UnaryOperator *UO = cast<UnaryOperator>(this);
2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (UO->getOpcode()) {
2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    default: return false;
2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PostInc:
2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PostDec:
2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PreInc:
2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PreDec:
2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return true;                     // ++/--
2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Deref:
2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // Dereferencing a volatile pointer is a side-effect.
2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return getType().isVolatileQualified();
2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Real:
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Imag:
2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // accessing a piece of a volatile complex is a side-effect.
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return UO->getSubExpr()->getType().isVolatileQualified();
2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Extension:
2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return UO->getSubExpr()->hasLocalSideEffect();
2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
300e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  case BinaryOperatorClass: {
301e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner    const BinaryOperator *BinOp = cast<BinaryOperator>(this);
302e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner    // Consider comma to have side effects if the LHS and RHS both do.
303e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner    if (BinOp->getOpcode() == BinaryOperator::Comma)
304e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner      return BinOp->getLHS()->hasLocalSideEffect() &&
305e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner             BinOp->getRHS()->hasLocalSideEffect();
306e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner
307e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner    return BinOp->isAssignmentOp();
308e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  }
309eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner  case CompoundAssignOperatorClass:
3101f683e9cf2e855b32d3fb4b142aa121cd3cf1088Chris Lattner    return true;
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
312ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  case ConditionalOperatorClass: {
313ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
314ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian    return Exp->getCond()->hasLocalSideEffect()
315ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian           || (Exp->getLHS() && Exp->getLHS()->hasLocalSideEffect())
316ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian           || (Exp->getRHS() && Exp->getRHS()->hasLocalSideEffect());
317ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  }
318ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case MemberExprClass:
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ArraySubscriptExprClass:
3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // If the base pointer or element is to a volatile pointer/field, accessing
3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // if is a side effect.
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getType().isVolatileQualified();
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case CallExprClass:
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // TODO: check attributes for pure/const.   "void foo() { strlen("bar"); }"
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // should warn.
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return true;
329a9c01021724b9b546d282b8609cbe559734812ecChris Lattner  case ObjCMessageExprClass:
330a9c01021724b9b546d282b8609cbe559734812ecChris Lattner    return true;
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case CastExprClass:
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // If this is a cast to void, check the operand.  Otherwise, the result of
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // the cast is unused.
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (getType()->isVoidType())
3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return cast<CastExpr>(this)->getSubExpr()->hasLocalSideEffect();
3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
33804421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner
3394be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman  case ImplicitCastExprClass:
3404be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman    // Check the operand, since implicit casts are inserted by Sema
3414be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman    return cast<ImplicitCastExpr>(this)->getSubExpr()->hasLocalSideEffect();
3424be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman
34304421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
34404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return cast<CXXDefaultArgExpr>(this)->getExpr()->hasLocalSideEffect();
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// incomplete type other than void. Nonarray expressions that can be lvalues:
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - name, where name must be a variable
3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - e[i]
3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - (e), where e must be an lvalue
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - e.name, where e must be an lvalue
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - e->name
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - *e, the type of e cannot be a function type
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - string-constant
3577da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner///  - (__real__ e) and (__imag__ e) where e is an lvalue  [GNU extension]
35808ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling///  - reference type [C++ [expr]]
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
360ca51c97fbb10b9d48e1857e01c532493f87cd5f0Bill WendlingExpr::isLvalueResult Expr::isLvalue() const {
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // first, check the type (C99 6.3.2.1)
362cb4f9a6d0be445d84af35ba81323be6127816f9eChris Lattner  if (TR->isFunctionType()) // from isObjectType()
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return LV_NotObjectType;
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
365acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff  // Allow qualified void which is an incomplete type other than void (yuck).
366f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  if (TR->isVoidType() && !TR.getCanonicalType().getCVRQualifiers())
367acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff    return LV_IncompleteVoidType;
368acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff
369cb4f9a6d0be445d84af35ba81323be6127816f9eChris Lattner  if (TR->isReferenceType()) // C++ [expr]
37008ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling    return LV_Valid;
37108ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // the type looks fine, now check the expression
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case StringLiteralClass: // C99 6.5.1p4
3757323a6297edad643c202594dcf3d9a174de96ca6Anders Carlsson    return LV_Valid;
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2))))
3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // For vectors, make sure base is an lvalue (i.e. not a function call).
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType())
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue();
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return LV_Valid;
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclRefExprClass: // C99 6.5.1p2
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isa<VarDecl>(cast<DeclRefExpr>(this)->getDecl()))
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return LV_Valid;
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
385fdd75663fffeb2058a7847975e50837e61200593Anton Korobeynikov  case MemberExprClass: { // C99 6.5.2.3p4
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const MemberExpr *m = cast<MemberExpr>(this);
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return m->isArrow() ? LV_Valid : m->getBase()->isLvalue();
388fdd75663fffeb2058a7847975e50837e61200593Anton Korobeynikov  }
3897da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner  case UnaryOperatorClass:
3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
3917da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner      return LV_Valid; // C99 6.5.3p4
3927da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner
3937da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner    if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
3947da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner        cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag)
3957da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner      return cast<UnaryOperator>(this)->getSubExpr()->isLvalue();  // GNU.
3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass: // C99 6.5.1p5
3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return cast<ParenExpr>(this)->getSubExpr()->isLvalue();
399e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff  case CompoundLiteralExprClass: // C99 6.5.2.5p5
400e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff    return LV_Valid;
401213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  case ExtVectorElementExprClass:
402213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman    if (cast<ExtVectorElementExpr>(this)->containsDuplicateElements())
403fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff      return LV_DuplicateVectorComponents;
404fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    return LV_Valid;
405027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff  case ObjCIvarRefExprClass: // ObjC instance variables are lvalues.
406027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff    return LV_Valid;
407fa28b30d5a1e93e5263be33e343532b900d2c643Chris Lattner  case PreDefinedExprClass:
408fa28b30d5a1e93e5263be33e343532b900d2c643Chris Lattner    return LV_Valid;
40904421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
41004421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue();
4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return LV_InvalidExpression;
4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// does not have an incomplete type, does not have a const-qualified type, and
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// if it is a structure or union, does not have any member (including,
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// recursively, any member or element of all contained aggregates or unions)
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with a const-qualified type.
422ca51c97fbb10b9d48e1857e01c532493f87cd5f0Bill WendlingExpr::isModifiableLvalueResult Expr::isModifiableLvalue() const {
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  isLvalueResult lvalResult = isLvalue();
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (lvalResult) {
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_Valid: break;
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_NotObjectType: return MLV_NotObjectType;
4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_IncompleteVoidType: return MLV_IncompleteVoidType;
429fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents;
4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_InvalidExpression: return MLV_InvalidExpression;
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TR.isConstQualified())
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return MLV_ConstQualified;
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TR->isArrayType())
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return MLV_ArrayType;
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (TR->isIncompleteType())
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return MLV_IncompleteType;
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const RecordType *r = dyn_cast<RecordType>(TR.getCanonicalType())) {
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (r->hasConstFields())
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return MLV_ConstQualified;
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return MLV_Valid;
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4462e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek/// hasGlobalStorage - Return true if this expression has static storage
4474cc627111453b75519d5130b57e06256da7b00e8Chris Lattner/// duration.  This means that the address of this expression is a link-time
4484cc627111453b75519d5130b57e06256da7b00e8Chris Lattner/// constant.
4492e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenekbool Expr::hasGlobalStorage() const {
4501d09ecca892185ba067e47ba879f424de59950efChris Lattner  switch (getStmtClass()) {
4511d09ecca892185ba067e47ba879f424de59950efChris Lattner  default:
4521d09ecca892185ba067e47ba879f424de59950efChris Lattner    return false;
4534cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  case ParenExprClass:
4542e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek    return cast<ParenExpr>(this)->getSubExpr()->hasGlobalStorage();
4554cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  case ImplicitCastExprClass:
4562e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek    return cast<ImplicitCastExpr>(this)->getSubExpr()->hasGlobalStorage();
457e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  case CompoundLiteralExprClass:
458e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff    return cast<CompoundLiteralExpr>(this)->isFileScope();
4591d09ecca892185ba067e47ba879f424de59950efChris Lattner  case DeclRefExprClass: {
4601d09ecca892185ba067e47ba879f424de59950efChris Lattner    const Decl *D = cast<DeclRefExpr>(this)->getDecl();
4611d09ecca892185ba067e47ba879f424de59950efChris Lattner    if (const VarDecl *VD = dyn_cast<VarDecl>(D))
4622e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek      return VD->hasGlobalStorage();
46363f067f5a75ae97b53dc7a6a6530e2c72c8bb7f8Seo Sanghyeon    if (isa<FunctionDecl>(D))
46463f067f5a75ae97b53dc7a6a6530e2c72c8bb7f8Seo Sanghyeon      return true;
4651d09ecca892185ba067e47ba879f424de59950efChris Lattner    return false;
4661d09ecca892185ba067e47ba879f424de59950efChris Lattner  }
467fb7080663a0f0abd687a6f58ac917d9a76318b73Chris Lattner  case MemberExprClass: {
4681d09ecca892185ba067e47ba879f424de59950efChris Lattner    const MemberExpr *M = cast<MemberExpr>(this);
4692e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek    return !M->isArrow() && M->getBase()->hasGlobalStorage();
470fb7080663a0f0abd687a6f58ac917d9a76318b73Chris Lattner  }
4714cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  case ArraySubscriptExprClass:
4722e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek    return cast<ArraySubscriptExpr>(this)->getBase()->hasGlobalStorage();
473fa28b30d5a1e93e5263be33e343532b900d2c643Chris Lattner  case PreDefinedExprClass:
474fa28b30d5a1e93e5263be33e343532b900d2c643Chris Lattner    return true;
47504421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
47604421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return cast<CXXDefaultArgExpr>(this)->getExpr()->hasGlobalStorage();
4771d09ecca892185ba067e47ba879f424de59950efChris Lattner  }
4781d09ecca892185ba067e47ba879f424de59950efChris Lattner}
4791d09ecca892185ba067e47ba879f424de59950efChris Lattner
4804e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() {
4814e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  Expr* E = this;
4824e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  while (ParenExpr* P = dyn_cast<ParenExpr>(E))
4834e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    E = P->getSubExpr();
4844e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
4854e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  return E;
4864e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek}
4874e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
48856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
48956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand.
49056f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() {
49156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *E = this;
49256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  while (true) {
49356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    if (ParenExpr *P = dyn_cast<ParenExpr>(E))
49456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
49556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else if (CastExpr *P = dyn_cast<CastExpr>(E))
49656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
49756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E))
49856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
49956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else
50056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      return E;
50156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
50256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner}
50356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
50456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
50538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroffbool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
50638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  switch (getStmtClass()) {
50738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  default:
50838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (Loc) *Loc = getLocStart();
50938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    return false;
51038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case ParenExprClass:
51138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    return cast<ParenExpr>(this)->getSubExpr()->isConstantExpr(Ctx, Loc);
51238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case StringLiteralClass:
5135d37e32a5bfefacdd7b4d0664199d72c703d489dSteve Naroff  case ObjCStringLiteralClass:
51438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case FloatingLiteralClass:
51538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case IntegerLiteralClass:
51638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case CharacterLiteralClass:
51738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case ImaginaryLiteralClass:
5181a86b33c1870fee08d281c9f07ac1280195a7faeAnders Carlsson  case TypesCompatibleExprClass:
5191a86b33c1870fee08d281c9f07ac1280195a7faeAnders Carlsson  case CXXBoolLiteralExprClass:
5202777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
52138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case CallExprClass: {
52238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const CallExpr *CE = cast<CallExpr>(this);
523c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff    if (CE->isBuiltinConstantExpr())
524c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff      return true;
52538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (Loc) *Loc = getLocStart();
52638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    return false;
52738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
5284ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner  case DeclRefExprClass: {
5294ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner    const Decl *D = cast<DeclRefExpr>(this)->getDecl();
5304ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner    // Accept address of function.
5314ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner    if (isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D))
5322777e494c96bee69141a10a0174d5da16e7b927bChris Lattner      return true;
53338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (Loc) *Loc = getLocStart();
5341d09ecca892185ba067e47ba879f424de59950efChris Lattner    if (isa<VarDecl>(D))
5351d09ecca892185ba067e47ba879f424de59950efChris Lattner      return TR->isArrayType();
53638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    return false;
5374ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner  }
538b8f13a8baff3df080fe024fec47746e9a79fe649Steve Naroff  case CompoundLiteralExprClass:
539b8f13a8baff3df080fe024fec47746e9a79fe649Steve Naroff    if (Loc) *Loc = getLocStart();
540b8f13a8baff3df080fe024fec47746e9a79fe649Steve Naroff    // Allow "(int []){2,4}", since the array will be converted to a pointer.
541d47d4f518e43eaa716e2d18359bd725a03b87f58Nate Begeman    // Allow "(vector type){2,4}" since the elements are all constant.
542d47d4f518e43eaa716e2d18359bd725a03b87f58Nate Begeman    return TR->isArrayType() || TR->isVectorType();
54338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case UnaryOperatorClass: {
54438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const UnaryOperator *Exp = cast<UnaryOperator>(this);
54538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
5461d09ecca892185ba067e47ba879f424de59950efChris Lattner    // C99 6.6p9
547239c15e5b07a6cc84278ede87edf638922767520Chris Lattner    if (Exp->getOpcode() == UnaryOperator::AddrOf) {
5482e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek      if (!Exp->getSubExpr()->hasGlobalStorage()) {
549239c15e5b07a6cc84278ede87edf638922767520Chris Lattner        if (Loc) *Loc = getLocStart();
550239c15e5b07a6cc84278ede87edf638922767520Chris Lattner        return false;
551239c15e5b07a6cc84278ede87edf638922767520Chris Lattner      }
552239c15e5b07a6cc84278ede87edf638922767520Chris Lattner      return true;
553239c15e5b07a6cc84278ede87edf638922767520Chris Lattner    }
5541d09ecca892185ba067e47ba879f424de59950efChris Lattner
55538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // Get the operand value.  If this is sizeof/alignof, do not evalute the
55638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // operand.  This affects C99 6.6p3.
557d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    if (!Exp->isSizeOfAlignOfOp() &&
558d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff        Exp->getOpcode() != UnaryOperator::OffsetOf &&
55938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff        !Exp->getSubExpr()->isConstantExpr(Ctx, Loc))
56038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
56138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
56238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    switch (Exp->getOpcode()) {
56338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
56438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // See C99 6.6p3.
56538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    default:
56638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      if (Loc) *Loc = Exp->getOperatorLoc();
56738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
56838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::Extension:
56938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return true;  // FIXME: this is wrong.
57038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::SizeOf:
57138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::AlignOf:
572d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    case UnaryOperator::OffsetOf:
57338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
5743c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman      if (!Exp->getSubExpr()->getType()->isConstantSizeType()) {
57565383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner        if (Loc) *Loc = Exp->getOperatorLoc();
57638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff        return false;
57765383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner      }
5782777e494c96bee69141a10a0174d5da16e7b927bChris Lattner      return true;
57938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::LNot:
58038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::Plus:
58138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::Minus:
58238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::Not:
5832777e494c96bee69141a10a0174d5da16e7b927bChris Lattner      return true;
58438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    }
58538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
58638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case SizeOfAlignOfTypeExprClass: {
58738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
58838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // alignof always evaluates to a constant.
589a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    if (Exp->isSizeOf() && !Exp->getArgumentType()->isVoidType() &&
590a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner        !Exp->getArgumentType()->isConstantSizeType()) {
59165383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner      if (Loc) *Loc = Exp->getOperatorLoc();
59238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
59365383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner    }
5942777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
59538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
59638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case BinaryOperatorClass: {
59738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const BinaryOperator *Exp = cast<BinaryOperator>(this);
59838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
59938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // The LHS of a constant expr is always evaluated and needed.
60038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (!Exp->getLHS()->isConstantExpr(Ctx, Loc))
60138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
60238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
60338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (!Exp->getRHS()->isConstantExpr(Ctx, Loc))
60438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
6052777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
60638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
60738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case ImplicitCastExprClass:
60838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case CastExprClass: {
60938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const Expr *SubExpr;
61038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    SourceLocation CastLoc;
61138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (const CastExpr *C = dyn_cast<CastExpr>(this)) {
61238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      SubExpr = C->getSubExpr();
61338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      CastLoc = C->getLParenLoc();
61438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    } else {
61538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr();
61638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      CastLoc = getLocStart();
61738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    }
61838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (!SubExpr->isConstantExpr(Ctx, Loc)) {
61938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      if (Loc) *Loc = SubExpr->getLocStart();
62038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
62138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    }
6222777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
62338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
62438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case ConditionalOperatorClass: {
62538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
6262777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    if (!Exp->getCond()->isConstantExpr(Ctx, Loc) ||
6273907323dd6665c0c4e383435cb145233f4533406Anders Carlsson        // Handle the GNU extension for missing LHS.
6283907323dd6665c0c4e383435cb145233f4533406Anders Carlsson        !(Exp->getLHS() && Exp->getLHS()->isConstantExpr(Ctx, Loc)) ||
6292777e494c96bee69141a10a0174d5da16e7b927bChris Lattner        !Exp->getRHS()->isConstantExpr(Ctx, Loc))
63038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
6312777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
63238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
633d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff  case InitListExprClass: {
634d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    const InitListExpr *Exp = cast<InitListExpr>(this);
635d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    unsigned numInits = Exp->getNumInits();
636d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    for (unsigned i = 0; i < numInits; i++) {
637d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff      if (!Exp->getInit(i)->isConstantExpr(Ctx, Loc)) {
638d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff        if (Loc) *Loc = Exp->getInit(i)->getLocStart();
639d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff        return false;
640d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff      }
641d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    }
642d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    return true;
643d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff  }
64404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
64504421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return cast<CXXDefaultArgExpr>(this)->getExpr()->isConstantExpr(Ctx, Loc);
64638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
64738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff}
64838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIntegerConstantExpr - this recursive routine will test if an expression is
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// an integer constant expression. Note: With the introduction of VLA's in
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// C99 the result of the sizeof operator is no longer always a constant
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expression. The generalization of the wording to include any subexpression
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// that is not evaluated (C99 6.6p3) means that nonconstant subexpressions
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// can appear as operands to other operators (e.g. &&, ||, ?:). For instance,
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// "0 || f()" can be treated as a constant expression. In C90 this expression,
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// occurring in a context requiring a constant, would have been a constraint
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// violation. FIXME: This routine currently implements C90 semantics.
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// To properly implement C99 semantics this routine will need to evaluate
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions involving operators previously mentioned.
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero,
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comma, etc
6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FIXME: This should ext-warn on overflow during evaluation!  ISO C does not
665ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner/// permit this.  This includes things like (int)1e1000
666ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner///
667ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// FIXME: Handle offsetof.  Two things to do:  Handle GCC's __builtin_offsetof
668ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// to support gcc 4.0+  and handle the idiom GCC recognizes with a null pointer
669ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// cast+dereference.
670590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattnerbool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
671590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                                 SourceLocation *Loc, bool isEvaluated) const {
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Loc) *Loc = getLocStart();
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass:
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return cast<ParenExpr>(this)->getSubExpr()->
678590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                     isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case IntegerLiteralClass:
6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Result = cast<IntegerLiteral>(this)->getValue();
6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
6822eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner  case CharacterLiteralClass: {
6832eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner    const CharacterLiteral *CL = cast<CharacterLiteral>(this);
68498be4943e8dc4f3905629a7102668960873cf863Chris Lattner    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
6852eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner    Result = CL->getValue();
686f0fbcb356bc4eb5f6467dc4fc4bc447e9a630102Chris Lattner    Result.setIsUnsigned(!getType()->isSignedIntegerType());
6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
6882eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner  }
6897b658aa315784fa489a32daeacfe400512ce468dSteve Naroff  case TypesCompatibleExprClass: {
6907b658aa315784fa489a32daeacfe400512ce468dSteve Naroff    const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this);
69198be4943e8dc4f3905629a7102668960873cf863Chris Lattner    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
692ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff    Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2());
693389cecc83f33e93c8ba6bf2e8269b8690404416fSteve Naroff    break;
6947b658aa315784fa489a32daeacfe400512ce468dSteve Naroff  }
69513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  case CallExprClass: {
69613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    const CallExpr *CE = cast<CallExpr>(this);
69798be4943e8dc4f3905629a7102668960873cf863Chris Lattner    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
69813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    if (CE->isBuiltinClassifyType(Result))
69913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff      break;
70013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    if (Loc) *Loc = getLocStart();
70113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    return false;
70213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  }
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclRefExprClass:
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (const EnumConstantDecl *D =
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer          dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) {
7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = D->getInitVal();
7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Loc) *Loc = getLocStart();
7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UnaryOperatorClass: {
7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const UnaryOperator *Exp = cast<UnaryOperator>(this);
7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Get the operand value.  If this is sizeof/alignof, do not evalute the
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // operand.  This affects C99 6.6p3.
7165a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    if (!Exp->isSizeOfAlignOfOp() && !Exp->isOffsetOfOp() &&
717602dafdea34b78c7bc1f4601f94062afa4139e76Chris Lattner        !Exp->getSubExpr()->isIntegerConstantExpr(Result, Ctx, Loc,isEvaluated))
7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (Exp->getOpcode()) {
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // See C99 6.6p3.
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    default:
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (Loc) *Loc = Exp->getOperatorLoc();
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Extension:
72776e773a443be9f006610f46529e07d4c8d857680Chris Lattner      return true;  // FIXME: this is wrong.
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::SizeOf:
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::AlignOf:
730a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      // Return the result in the right width.
73198be4943e8dc4f3905629a7102668960873cf863Chris Lattner      Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
732a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
733a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
734a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      if (Exp->getSubExpr()->getType()->isVoidType()) {
735a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner        Result = 1;
736a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner        break;
737a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      }
738a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
7403c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman      if (!Exp->getSubExpr()->getType()->isConstantSizeType()) {
74165383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner        if (Loc) *Loc = Exp->getOperatorLoc();
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
74365383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner      }
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
74576e773a443be9f006610f46529e07d4c8d857680Chris Lattner      // Get information about the size or align.
746efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner      if (Exp->getSubExpr()->getType()->isFunctionType()) {
747efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner        // GCC extension: sizeof(function) = 1.
748efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner        Result = Exp->getOpcode() == UnaryOperator::AlignOf ? 4 : 1;
749da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner      } else {
75098be4943e8dc4f3905629a7102668960873cf863Chris Lattner        unsigned CharSize = Ctx.Target.getCharWidth();
75164a31ef8d46fcdf2bca38098e3206a45052b515dAnders Carlsson        if (Exp->getOpcode() == UnaryOperator::AlignOf)
75298be4943e8dc4f3905629a7102668960873cf863Chris Lattner          Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType()) / CharSize;
75364a31ef8d46fcdf2bca38098e3206a45052b515dAnders Carlsson        else
75498be4943e8dc4f3905629a7102668960873cf863Chris Lattner          Result = Ctx.getTypeSize(Exp->getSubExpr()->getType()) / CharSize;
755da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner      }
7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::LNot: {
758bf7553889594886213e05cd3f94a6d6f7747bf7bChris Lattner      bool Val = Result == 0;
75998be4943e8dc4f3905629a7102668960873cf863Chris Lattner      Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = Val;
7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Plus:
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Minus:
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = -Result;
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Not:
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = ~Result;
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7715a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    case UnaryOperator::OffsetOf:
7725a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson      Result = Exp->evaluateOffsetOf(Ctx);
7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case SizeOfAlignOfTypeExprClass: {
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
778a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
779a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    // Return the result in the right width.
78098be4943e8dc4f3905629a7102668960873cf863Chris Lattner    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
781a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
782a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
783a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    if (Exp->getArgumentType()->isVoidType()) {
784a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      Result = 1;
785a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      break;
786a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    }
787a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
788a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    // alignof always evaluates to a constant, sizeof does if arg is not VLA.
7893c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman    if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType()) {
79065383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner      if (Loc) *Loc = Exp->getOperatorLoc();
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
79265383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner    }
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
79476e773a443be9f006610f46529e07d4c8d857680Chris Lattner    // Get information about the size or align.
795efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner    if (Exp->getArgumentType()->isFunctionType()) {
796efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner      // GCC extension: sizeof(function) = 1.
797efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner      Result = Exp->isSizeOf() ? 1 : 4;
7986a24acbb3dbb3bea9426716bee6ad6023ad15f3fAnders Carlsson    } else {
79998be4943e8dc4f3905629a7102668960873cf863Chris Lattner      unsigned CharSize = Ctx.Target.getCharWidth();
8006a24acbb3dbb3bea9426716bee6ad6023ad15f3fAnders Carlsson      if (Exp->isSizeOf())
80198be4943e8dc4f3905629a7102668960873cf863Chris Lattner        Result = Ctx.getTypeSize(Exp->getArgumentType()) / CharSize;
8026a24acbb3dbb3bea9426716bee6ad6023ad15f3fAnders Carlsson      else
80398be4943e8dc4f3905629a7102668960873cf863Chris Lattner        Result = Ctx.getTypeAlign(Exp->getArgumentType()) / CharSize;
804060e470e53b73167114284eb0b8c3e25bb3dad99Ted Kremenek    }
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case BinaryOperatorClass: {
8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const BinaryOperator *Exp = cast<BinaryOperator>(this);
8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // The LHS of a constant expr is always evaluated and needed.
811590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    if (!Exp->getLHS()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    llvm::APSInt RHS(Result);
8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // The short-circuiting &&/|| operators don't necessarily evaluate their
8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // RHS.  Make sure to pass isEvaluated down correctly.
8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Exp->isLogicalOp()) {
8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      bool RHSEval;
8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (Exp->getOpcode() == BinaryOperator::LAnd)
8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        RHSEval = Result != 0;
8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      else {
8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        assert(Exp->getOpcode() == BinaryOperator::LOr &&"Unexpected logical");
8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        RHSEval = Result == 0;
8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      }
8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
827590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner      if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc,
8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                                isEvaluated & RHSEval))
8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    } else {
831590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner      if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, isEvaluated))
8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (Exp->getOpcode()) {
8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    default:
8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (Loc) *Loc = getLocStart();
8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Mul:
8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result *= RHS;
8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Div:
8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (RHS == 0) {
8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (!isEvaluated) break;
8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (Loc) *Loc = getLocStart();
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      }
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result /= RHS;
8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Rem:
8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (RHS == 0) {
8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (!isEvaluated) break;
8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (Loc) *Loc = getLocStart();
8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      }
8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result %= RHS;
8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Add: Result += RHS; break;
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Sub: Result -= RHS; break;
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Shl:
861701e5eb608d7b0b94279b6be86bf90f8dea68e9eChris Lattner      Result <<=
862701e5eb608d7b0b94279b6be86bf90f8dea68e9eChris Lattner        static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1));
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Shr:
865701e5eb608d7b0b94279b6be86bf90f8dea68e9eChris Lattner      Result >>=
866701e5eb608d7b0b94279b6be86bf90f8dea68e9eChris Lattner        static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1));
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::LT:  Result = Result < RHS; break;
8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::GT:  Result = Result > RHS; break;
8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::LE:  Result = Result <= RHS; break;
8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::GE:  Result = Result >= RHS; break;
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::EQ:  Result = Result == RHS; break;
8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::NE:  Result = Result != RHS; break;
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::And: Result &= RHS; break;
8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Xor: Result ^= RHS; break;
8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Or:  Result |= RHS; break;
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::LAnd:
8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = Result != 0 && RHS != 0;
8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::LOr:
8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = Result != 0 || RHS != 0;
8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Comma:
8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // C99 6.6p3: "shall not contain assignment, ..., or comma operators,
8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // *except* when they are contained within a subexpression that is not
8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // evaluated".  Note that Assignment can never happen due to constraints
8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // on the LHS subexpr, so we don't need to check it here.
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (isEvaluated) {
8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (Loc) *Loc = getLocStart();
8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      }
8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // The result of the constant expr is the RHS.
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = RHS;
8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return true;
8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!");
9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
90226dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner  case ImplicitCastExprClass:
9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case CastExprClass: {
90426dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    const Expr *SubExpr;
90526dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    SourceLocation CastLoc;
90626dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    if (const CastExpr *C = dyn_cast<CastExpr>(this)) {
90726dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      SubExpr = C->getSubExpr();
90826dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      CastLoc = C->getLParenLoc();
90926dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    } else {
91026dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr();
91126dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      CastLoc = getLocStart();
91226dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    }
91326dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner
9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // C99 6.6p6: shall only convert arithmetic types to integer types.
91526dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    if (!SubExpr->getType()->isArithmeticType() ||
91626dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner        !getType()->isIntegerType()) {
91726dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      if (Loc) *Loc = SubExpr->getLocStart();
9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
920987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner
92198be4943e8dc4f3905629a7102668960873cf863Chris Lattner    uint32_t DestWidth = static_cast<uint32_t>(Ctx.getTypeSize(getType()));
922987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner
9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Handle simple integer->integer casts.
92426dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    if (SubExpr->getType()->isIntegerType()) {
92526dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      if (!SubExpr->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
92726dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner
92826dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      // Figure out if this is a truncate, extend or noop cast.
92926dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      // If the input is signed, do a sign extend, noop, or truncate.
930c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      if (getType()->isBooleanType()) {
931c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner        // Conversion to bool compares against zero.
932c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner        Result = Result != 0;
933c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner        Result.zextOrTrunc(DestWidth);
934c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      } else if (SubExpr->getType()->isSignedIntegerType())
93526dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner        Result.sextOrTrunc(DestWidth);
93626dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      else  // If the input is unsigned, do a zero extend, noop, or truncate.
93726dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner        Result.zextOrTrunc(DestWidth);
9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Allow floating constants that are the immediate operands of casts or that
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // are parenthesized.
94326dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    const Expr *Operand = SubExpr;
9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    while (const ParenExpr *PE = dyn_cast<ParenExpr>(Operand))
9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Operand = PE->getSubExpr();
946987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner
947987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    // If this isn't a floating literal, we can't handle it.
948987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(Operand);
949987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    if (!FL) {
950987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner      if (Loc) *Loc = Operand->getLocStart();
951987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner      return false;
952987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    }
953c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner
954c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner    // If the destination is boolean, compare against zero.
955c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner    if (getType()->isBooleanType()) {
956c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      Result = !FL->getValue().isZero();
957c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      Result.zextOrTrunc(DestWidth);
958c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      break;
959c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner    }
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
961987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    // Determine whether we are converting to unsigned or signed.
962987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    bool DestSigned = getType()->isSignedIntegerType();
963ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner
964ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner    // TODO: Warn on overflow, but probably not here: isIntegerConstantExpr can
965ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner    // be called multiple times per AST.
966987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    uint64_t Space[4];
967ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner    (void)FL->getValue().convertToInteger(Space, DestWidth, DestSigned,
968ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner                                          llvm::APFloat::rmTowardZero);
969987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    Result = llvm::APInt(DestWidth, 4, Space);
970987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    break;
9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ConditionalOperatorClass: {
9735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
9745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
975590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    if (!Exp->getCond()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const Expr *TrueExp  = Exp->getLHS();
9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const Expr *FalseExp = Exp->getRHS();
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Result == 0) std::swap(TrueExp, FalseExp);
9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Evaluate the false one first, discard the result.
9833907323dd6665c0c4e383435cb145233f4533406Anders Carlsson    if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false))
9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Evalute the true one, capture the result.
9863907323dd6665c0c4e383435cb145233f4533406Anders Carlsson    if (TrueExp &&
9873907323dd6665c0c4e383435cb145233f4533406Anders Carlsson        !TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
99104421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
99204421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return cast<CXXDefaultArgExpr>(this)
99304421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner             ->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Cases that are valid constant exprs fall through to here.
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Result.setIsUnsigned(getType()->isUnsignedIntegerType());
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return true;
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// integer constant expression with the value zero, or if this is one that is
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// cast to void*.
1004590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattnerbool Expr::isNullPointerConstant(ASTContext &Ctx) const {
1005aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  // Strip off a cast to void*, if it exists.
1006aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  if (const CastExpr *CE = dyn_cast<CastExpr>(this)) {
1007aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Check that it is a cast to void*.
10084b3f9b367c16e494c181d6f03d53497ae1275fbeEli Friedman    if (const PointerType *PT = CE->getType()->getAsPointerType()) {
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      QualType Pointee = PT->getPointeeType();
1010f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner      if (Pointee.getCVRQualifiers() == 0 &&
1011f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner          Pointee->isVoidType() &&                                 // to void*
1012aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff          CE->getSubExpr()->getType()->isIntegerType())            // from int.
1013aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff        return CE->getSubExpr()->isNullPointerConstant(Ctx);
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1015aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
1016aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Ignore the ImplicitCastExpr type entirely.
1017aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    return ICE->getSubExpr()->isNullPointerConstant(Ctx);
1018aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
1019aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Accept ((void*)0) as a null pointer constant, as many other
1020aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // implementations do.
1021aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    return PE->getSubExpr()->isNullPointerConstant(Ctx);
10228123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner  } else if (const CXXDefaultArgExpr *DefaultArg
10238123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner               = dyn_cast<CXXDefaultArgExpr>(this)) {
102404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    // See through default argument expressions
102504421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return DefaultArg->getExpr()->isNullPointerConstant(Ctx);
1026aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff  }
1027aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff
1028aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  // This expression must be an integer type.
1029aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  if (!getType()->isIntegerType())
1030aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    return false;
1031aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff
10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // If we have an integer constant expression, we need to *evaluate* it and
10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // test for the value 0.
10345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APSInt Val(32);
1035aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  return isIntegerConstantExpr(Val, Ctx, 0, true) && Val == 0;
10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
103731a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff
1038213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const {
10398a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  if (const VectorType *VT = getType()->getAsVectorType())
10408a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    return VT->getNumElements();
10418a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  return 1;
10424d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner}
10434d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner
10448a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated.
1045213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const {
1046fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  const char *compStr = Accessor.getName();
1047fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  unsigned length = strlen(compStr);
1048fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff
1049fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  for (unsigned i = 0; i < length-1; i++) {
1050fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    const char *s = compStr+i;
1051fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    for (const char c = *s++; *s; s++)
1052fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff      if (c == *s)
1053fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff        return true;
1054fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  }
1055fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  return false;
1056fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff}
1057b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
10588a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
10593b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess(
10603b8d116703db8018f855cbb4733ace426422623bNate Begeman                                  llvm::SmallVectorImpl<unsigned> &Elts) const {
1061b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  const char *compStr = Accessor.getName();
10628a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
10638a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  bool isHi =   !strcmp(compStr, "hi");
10648a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  bool isLo =   !strcmp(compStr, "lo");
10658a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  bool isEven = !strcmp(compStr, "e");
10668a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  bool isOdd  = !strcmp(compStr, "o");
10678a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
10688a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
10698a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    uint64_t Index;
10708a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
10718a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    if (isHi)
10728a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = e + i;
10738a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isLo)
10748a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = i;
10758a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isEven)
10768a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i;
10778a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isOdd)
10788a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i + 1;
10798a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else
10808a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = ExtVectorType::getAccessorIdx(compStr[i]);
1081b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
10823b8d116703db8018f855cbb4733ace426422623bNate Begeman    Elts.push_back(Index);
1083b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
10848a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman}
10858a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
10868a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begemanunsigned
10878a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate BegemanExtVectorElementExpr::getAccessedFieldNo(unsigned Idx,
10888a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman                                         const llvm::Constant *Elts) {
10898a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  if (isa<llvm::ConstantAggregateZero>(Elts))
10908a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    return 0;
10918a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
10928a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  return cast<llvm::ConstantInt>(Elts->getOperand(Idx))->getZExtValue();
1093b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner}
1094b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
109568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// constructor for instance messages.
1096bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
1097a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                QualType retType, ObjCMethodDecl *mproto,
1098db611d556f71f98b66b69514d45958d76e5727abSteve Naroff                SourceLocation LBrac, SourceLocation RBrac,
109949f109c786f99eb7468dac3976db083a65493444Steve Naroff                Expr **ArgExprs, unsigned nargs)
1100db611d556f71f98b66b69514d45958d76e5727abSteve Naroff  : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
1101ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek    MethodProto(mproto) {
110249f109c786f99eb7468dac3976db083a65493444Steve Naroff  NumArgs = nargs;
110349f109c786f99eb7468dac3976db083a65493444Steve Naroff  SubExprs = new Expr*[NumArgs+1];
110468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  SubExprs[RECEIVER] = receiver;
110549f109c786f99eb7468dac3976db083a65493444Steve Naroff  if (NumArgs) {
110649f109c786f99eb7468dac3976db083a65493444Steve Naroff    for (unsigned i = 0; i != NumArgs; ++i)
110768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
110868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  }
1109563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  LBracloc = LBrac;
1110563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  RBracloc = RBrac;
1111563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
1112563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
111368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// constructor for class messages.
111468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// FIXME: clsName should be typed to ObjCInterfaceType
1115bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
1116a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                QualType retType, ObjCMethodDecl *mproto,
1117db611d556f71f98b66b69514d45958d76e5727abSteve Naroff                SourceLocation LBrac, SourceLocation RBrac,
111849f109c786f99eb7468dac3976db083a65493444Steve Naroff                Expr **ArgExprs, unsigned nargs)
1119db611d556f71f98b66b69514d45958d76e5727abSteve Naroff  : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
1120ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek    MethodProto(mproto) {
112149f109c786f99eb7468dac3976db083a65493444Steve Naroff  NumArgs = nargs;
112249f109c786f99eb7468dac3976db083a65493444Steve Naroff  SubExprs = new Expr*[NumArgs+1];
1123ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek  SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | 0x1);
112449f109c786f99eb7468dac3976db083a65493444Steve Naroff  if (NumArgs) {
112549f109c786f99eb7468dac3976db083a65493444Steve Naroff    for (unsigned i = 0; i != NumArgs; ++i)
112668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
112768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  }
1128563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  LBracloc = LBrac;
1129563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  RBracloc = RBrac;
1130563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
1131563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
113227437caadea35f84d550cd29f024fcf3ea240eecChris Lattnerbool ChooseExpr::isConditionTrue(ASTContext &C) const {
113327437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  llvm::APSInt CondVal(32);
113427437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  bool IsConst = getCond()->isIntegerConstantExpr(CondVal, C);
113527437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst;
113627437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  return CondVal != 0;
113727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner}
113827437caadea35f84d550cd29f024fcf3ea240eecChris Lattner
11395a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlssonstatic int64_t evaluateOffsetOf(ASTContext& C, const Expr *E)
11405a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson{
11415a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
11425a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    QualType Ty = ME->getBase()->getType();
11435a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
11445a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    RecordDecl *RD = Ty->getAsRecordType()->getDecl();
114598be4943e8dc4f3905629a7102668960873cf863Chris Lattner    const ASTRecordLayout &RL = C.getASTRecordLayout(RD);
11465a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    FieldDecl *FD = ME->getMemberDecl();
11475a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
11485a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    // FIXME: This is linear time.
11495a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    unsigned i = 0, e = 0;
11505a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    for (i = 0, e = RD->getNumMembers(); i != e; i++) {
11515a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson      if (RD->getMember(i) == FD)
11525a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson        break;
11535a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    }
11545a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
11555a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    return RL.getFieldOffset(i) + evaluateOffsetOf(C, ME->getBase());
11565a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  } else if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
11575a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    const Expr *Base = ASE->getBase();
11585a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    llvm::APSInt Idx(32);
11595a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    bool ICE = ASE->getIdx()->isIntegerConstantExpr(Idx, C);
11605a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    assert(ICE && "Array index is not a constant integer!");
11615a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
116298be4943e8dc4f3905629a7102668960873cf863Chris Lattner    int64_t size = C.getTypeSize(ASE->getType());
11635a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    size *= Idx.getSExtValue();
11645a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
11655a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    return size + evaluateOffsetOf(C, Base);
11665a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  } else if (isa<CompoundLiteralExpr>(E))
11675a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    return 0;
11685a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
11695a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  assert(0 && "Unknown offsetof subexpression!");
11705a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  return 0;
11715a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson}
11725a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
11735a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlssonint64_t UnaryOperator::evaluateOffsetOf(ASTContext& C) const
11745a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson{
11755a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  assert(Opc == OffsetOf && "Unary operator not offsetof!");
11765a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
117798be4943e8dc4f3905629a7102668960873cf863Chris Lattner  unsigned CharSize = C.Target.getCharWidth();
11785a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  return ::evaluateOffsetOf(C, Val) / CharSize;
11795a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson}
11805a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
118177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
118277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//  Child Iterators for iterating over subexpressions/substatements
118377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
118477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
118577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// DeclRefExpr
11869ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
11879ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
118877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
11897779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff// ObjCIvarRefExpr
119092261971835f822e6bcee7baadf2c34b482dfe96Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_begin() {
119192261971835f822e6bcee7baadf2c34b482dfe96Ted Kremenek  return reinterpret_cast<Stmt**>(&Base);
119292261971835f822e6bcee7baadf2c34b482dfe96Ted Kremenek}
119392261971835f822e6bcee7baadf2c34b482dfe96Ted Kremenek
119492261971835f822e6bcee7baadf2c34b482dfe96Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_end() {
119592261971835f822e6bcee7baadf2c34b482dfe96Ted Kremenek  return reinterpret_cast<Stmt**>(&Base)+1;
119692261971835f822e6bcee7baadf2c34b482dfe96Ted Kremenek}
11977779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff
119877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// PreDefinedExpr
11999ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator PreDefinedExpr::child_begin() { return child_iterator(); }
12009ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator PreDefinedExpr::child_end() { return child_iterator(); }
120177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
120277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// IntegerLiteral
12039ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); }
12049ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); }
120577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
120677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CharacterLiteral
12079ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_begin() { return child_iterator(); }
12089ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); }
120977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
121077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// FloatingLiteral
12119ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); }
12129ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); }
121377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
12145d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner// ImaginaryLiteral
12155d66145eed1c319df5a69977cb8ff74f597ea544Chris LattnerStmt::child_iterator ImaginaryLiteral::child_begin() {
12165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&Val);
12175d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}
12185d66145eed1c319df5a69977cb8ff74f597ea544Chris LattnerStmt::child_iterator ImaginaryLiteral::child_end() {
12195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&Val)+1;
12205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}
12215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
122277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// StringLiteral
12239ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_begin() { return child_iterator(); }
12249ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_end() { return child_iterator(); }
122577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
122677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ParenExpr
122777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted KremenekStmt::child_iterator ParenExpr::child_begin() {
122877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  return reinterpret_cast<Stmt**>(&Val);
122977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
123077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted KremenekStmt::child_iterator ParenExpr::child_end() {
12315d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&Val)+1;
123277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
123377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
123477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// UnaryOperator
123577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted KremenekStmt::child_iterator UnaryOperator::child_begin() {
1236f816f77480e70caadfdbd741cf17d84a6be30b71Ted Kremenek  return reinterpret_cast<Stmt**>(&Val);
123777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
123877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted KremenekStmt::child_iterator UnaryOperator::child_end() {
1239f816f77480e70caadfdbd741cf17d84a6be30b71Ted Kremenek  return reinterpret_cast<Stmt**>(&Val+1);
124077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
124177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
124277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// SizeOfAlignOfTypeExpr
12439ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() {
1244699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek  // If the type is a VLA type (and not a typedef), the size expression of the
1245699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek  // VLA needs to be treated as an executable expression.
1246699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek  if (VariableArrayType* T = dyn_cast<VariableArrayType>(Ty.getTypePtr()))
1247699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek    return child_iterator(T);
1248699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek  else
1249699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek    return child_iterator();
12509ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
12519ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator SizeOfAlignOfTypeExpr::child_end() {
1252699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek  return child_iterator();
12539ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
125477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
125577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ArraySubscriptExpr
12561237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_begin() {
125777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  return reinterpret_cast<Stmt**>(&SubExprs);
125877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
12591237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_end() {
12605d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
126177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
126277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
126377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CallExpr
12641237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_begin() {
126542a297700e0bb916762e7af780e026010357b4f9Ted Kremenek  return reinterpret_cast<Stmt**>(&SubExprs[0]);
126677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
12671237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_end() {
126842a297700e0bb916762e7af780e026010357b4f9Ted Kremenek  return reinterpret_cast<Stmt**>(&SubExprs[NumArgs+ARGS_START]);
126977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
12701237c673c07f9d827129ba02720108816abde562Ted Kremenek
12711237c673c07f9d827129ba02720108816abde562Ted Kremenek// MemberExpr
12721237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator MemberExpr::child_begin() {
12731237c673c07f9d827129ba02720108816abde562Ted Kremenek  return reinterpret_cast<Stmt**>(&Base);
12741237c673c07f9d827129ba02720108816abde562Ted Kremenek}
12751237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator MemberExpr::child_end() {
12765d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&Base)+1;
12771237c673c07f9d827129ba02720108816abde562Ted Kremenek}
12781237c673c07f9d827129ba02720108816abde562Ted Kremenek
1279213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman// ExtVectorElementExpr
1280213541a68a3e137d11d2cefb612c6cdb410d7e8eNate BegemanStmt::child_iterator ExtVectorElementExpr::child_begin() {
12811237c673c07f9d827129ba02720108816abde562Ted Kremenek  return reinterpret_cast<Stmt**>(&Base);
12821237c673c07f9d827129ba02720108816abde562Ted Kremenek}
1283213541a68a3e137d11d2cefb612c6cdb410d7e8eNate BegemanStmt::child_iterator ExtVectorElementExpr::child_end() {
12845d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&Base)+1;
12851237c673c07f9d827129ba02720108816abde562Ted Kremenek}
12861237c673c07f9d827129ba02720108816abde562Ted Kremenek
12871237c673c07f9d827129ba02720108816abde562Ted Kremenek// CompoundLiteralExpr
12881237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_begin() {
12891237c673c07f9d827129ba02720108816abde562Ted Kremenek  return reinterpret_cast<Stmt**>(&Init);
12901237c673c07f9d827129ba02720108816abde562Ted Kremenek}
12911237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_end() {
12925d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&Init)+1;
12931237c673c07f9d827129ba02720108816abde562Ted Kremenek}
12941237c673c07f9d827129ba02720108816abde562Ted Kremenek
12951237c673c07f9d827129ba02720108816abde562Ted Kremenek// ImplicitCastExpr
12961237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ImplicitCastExpr::child_begin() {
12971237c673c07f9d827129ba02720108816abde562Ted Kremenek  return reinterpret_cast<Stmt**>(&Op);
12981237c673c07f9d827129ba02720108816abde562Ted Kremenek}
12991237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ImplicitCastExpr::child_end() {
13005d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&Op)+1;
13011237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13021237c673c07f9d827129ba02720108816abde562Ted Kremenek
13031237c673c07f9d827129ba02720108816abde562Ted Kremenek// CastExpr
13041237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CastExpr::child_begin() {
13051237c673c07f9d827129ba02720108816abde562Ted Kremenek  return reinterpret_cast<Stmt**>(&Op);
13061237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13071237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CastExpr::child_end() {
13085d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&Op)+1;
13091237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13101237c673c07f9d827129ba02720108816abde562Ted Kremenek
13111237c673c07f9d827129ba02720108816abde562Ted Kremenek// BinaryOperator
13121237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_begin() {
13131237c673c07f9d827129ba02720108816abde562Ted Kremenek  return reinterpret_cast<Stmt**>(&SubExprs);
13141237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13151237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_end() {
13165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
13171237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13181237c673c07f9d827129ba02720108816abde562Ted Kremenek
13191237c673c07f9d827129ba02720108816abde562Ted Kremenek// ConditionalOperator
13201237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_begin() {
13211237c673c07f9d827129ba02720108816abde562Ted Kremenek  return reinterpret_cast<Stmt**>(&SubExprs);
13221237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13231237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_end() {
13245d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
13251237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13261237c673c07f9d827129ba02720108816abde562Ted Kremenek
13271237c673c07f9d827129ba02720108816abde562Ted Kremenek// AddrLabelExpr
13289ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); }
13299ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); }
13301237c673c07f9d827129ba02720108816abde562Ted Kremenek
13311237c673c07f9d827129ba02720108816abde562Ted Kremenek// StmtExpr
13321237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator StmtExpr::child_begin() {
13331237c673c07f9d827129ba02720108816abde562Ted Kremenek  return reinterpret_cast<Stmt**>(&SubStmt);
13341237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13351237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator StmtExpr::child_end() {
13365d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&SubStmt)+1;
13371237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13381237c673c07f9d827129ba02720108816abde562Ted Kremenek
13391237c673c07f9d827129ba02720108816abde562Ted Kremenek// TypesCompatibleExpr
13409ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_begin() {
13419ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13429ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
13439ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek
13449ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_end() {
13459ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13469ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
13471237c673c07f9d827129ba02720108816abde562Ted Kremenek
13481237c673c07f9d827129ba02720108816abde562Ted Kremenek// ChooseExpr
13491237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ChooseExpr::child_begin() {
13501237c673c07f9d827129ba02720108816abde562Ted Kremenek  return reinterpret_cast<Stmt**>(&SubExprs);
13511237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13521237c673c07f9d827129ba02720108816abde562Ted Kremenek
13531237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ChooseExpr::child_end() {
13545d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
13551237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13561237c673c07f9d827129ba02720108816abde562Ted Kremenek
1357e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman// OverloadExpr
1358e2ce1d9440186cf3332368291cd884a6e3ae8946Nate BegemanStmt::child_iterator OverloadExpr::child_begin() {
1359e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman  return reinterpret_cast<Stmt**>(&SubExprs[0]);
1360e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman}
1361e2ce1d9440186cf3332368291cd884a6e3ae8946Nate BegemanStmt::child_iterator OverloadExpr::child_end() {
136267295d05c50ab0b5d1b0f9ef82a906701c348715Nate Begeman  return reinterpret_cast<Stmt**>(&SubExprs[NumExprs]);
1363e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman}
1364e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman
1365d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman// ShuffleVectorExpr
1366d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_begin() {
1367d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  return reinterpret_cast<Stmt**>(&SubExprs[0]);
1368d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
1369d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_end() {
1370d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  return reinterpret_cast<Stmt**>(&SubExprs[NumExprs]);
1371d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
1372d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
13737c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson// VAArgExpr
13747c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders CarlssonStmt::child_iterator VAArgExpr::child_begin() {
13757c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  return reinterpret_cast<Stmt**>(&Val);
13767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}
13777c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
13787c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders CarlssonStmt::child_iterator VAArgExpr::child_end() {
13797c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  return reinterpret_cast<Stmt**>(&Val)+1;
13807c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}
13817c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
138266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson// InitListExpr
138366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_begin() {
13841a42a2550a2db937ab3df863b771f13be34b66d6Steve Naroff  return reinterpret_cast<Stmt**>(InitExprs.size() ?
13851a42a2550a2db937ab3df863b771f13be34b66d6Steve Naroff                                  &InitExprs[0] : 0);
138666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
138766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_end() {
13881a42a2550a2db937ab3df863b771f13be34b66d6Steve Naroff  return reinterpret_cast<Stmt**>(InitExprs.size() ?
13891a42a2550a2db937ab3df863b771f13be34b66d6Steve Naroff                                  &InitExprs[0] + InitExprs.size() : 0);
139066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
139166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
13921237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCStringLiteral
13939ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_begin() {
13949ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13959ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
13969ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_end() {
13979ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13989ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
13991237c673c07f9d827129ba02720108816abde562Ted Kremenek
14001237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCEncodeExpr
14019ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); }
14029ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); }
14031237c673c07f9d827129ba02720108816abde562Ted Kremenek
1404b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian// ObjCSelectorExpr
14059ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_begin() {
14069ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
14079ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
14089ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_end() {
14099ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
14109ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
1411b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
1412390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian// ObjCProtocolExpr
14139ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_begin() {
14149ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
14159ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
14169ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_end() {
14179ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
14189ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
1419390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian
1420563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr
1421ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted KremenekStmt::child_iterator ObjCMessageExpr::child_begin() {
1422ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek  return reinterpret_cast<Stmt**>(&SubExprs[ getReceiver() ? 0 : ARGS_START ]);
1423563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
1424563477da25f824e37c535131695dc4dc9b68c465Steve NaroffStmt::child_iterator ObjCMessageExpr::child_end() {
142568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  return reinterpret_cast<Stmt**>(&SubExprs[getNumArgs()+ARGS_START]);
1426563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
1427563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
1428