143c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner//===--- StmtCXX.h - Classes for representing C++ statements ----*- C++ -*-===//
243c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner//
343c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner//                     The LLVM Compiler Infrastructure
443c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner//
543c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner// This file is distributed under the University of Illinois Open Source
643c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner// License. See LICENSE.TXT for details.
743c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner//
843c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner//===----------------------------------------------------------------------===//
943c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner//
1043c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner// This file defines the C++ statement AST node classes.
1143c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner//
1243c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner//===----------------------------------------------------------------------===//
1343c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
1443c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner#ifndef LLVM_CLANG_AST_STMTCXX_H
1543c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner#define LLVM_CLANG_AST_STMTCXX_H
1643c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
179946fc735d7285f2195f89635370f534afd9877eDmitri Gribenko#include "clang/AST/DeclarationName.h"
189946fc735d7285f2195f89635370f534afd9877eDmitri Gribenko#include "clang/AST/Expr.h"
199946fc735d7285f2195f89635370f534afd9877eDmitri Gribenko#include "clang/AST/NestedNameSpecifier.h"
2043c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner#include "clang/AST/Stmt.h"
21aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
2243c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
2343c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattnernamespace clang {
2443c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
25d308e6201afd3a8a198c52ba034d35ed19d4bafeDouglas Gregorclass VarDecl;
26d308e6201afd3a8a198c52ba034d35ed19d4bafeDouglas Gregor
2743c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner/// CXXCatchStmt - This represents a C++ catch block.
2843c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner///
2943c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattnerclass CXXCatchStmt : public Stmt {
3043c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  SourceLocation CatchLoc;
3143c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  /// The exception-declaration of the type.
32d308e6201afd3a8a198c52ba034d35ed19d4bafeDouglas Gregor  VarDecl *ExceptionDecl;
3343c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  /// The handler block.
3443c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  Stmt *HandlerBlock;
3543c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
3643c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattnerpublic:
37d308e6201afd3a8a198c52ba034d35ed19d4bafeDouglas Gregor  CXXCatchStmt(SourceLocation catchLoc, VarDecl *exDecl, Stmt *handlerBlock)
3843c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  : Stmt(CXXCatchStmtClass), CatchLoc(catchLoc), ExceptionDecl(exDecl),
3943c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner    HandlerBlock(handlerBlock) {}
4043c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
417cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis  CXXCatchStmt(EmptyShell Empty)
426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  : Stmt(CXXCatchStmtClass), ExceptionDecl(nullptr), HandlerBlock(nullptr) {}
437cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis
4465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return CatchLoc; }
4565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
4665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return HandlerBlock->getLocEnd();
4743c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  }
4843c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
49d308e6201afd3a8a198c52ba034d35ed19d4bafeDouglas Gregor  SourceLocation getCatchLoc() const { return CatchLoc; }
502bf701ee4babb5c4a9ea99ca4675c5ef040bd402Mike Stump  VarDecl *getExceptionDecl() const { return ExceptionDecl; }
516515afe50c8d69dbb029b85f879cb2e083854b6cMike Stump  QualType getCaughtType() const;
526515afe50c8d69dbb029b85f879cb2e083854b6cMike Stump  Stmt *getHandlerBlock() const { return HandlerBlock; }
5343c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
5443c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  static bool classof(const Stmt *T) {
5543c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner    return T->getStmtClass() == CXXCatchStmtClass;
5643c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  }
5743c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
5863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&HandlerBlock, &HandlerBlock+1); }
597cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis
6060adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
6143c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner};
6243c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
6343c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner/// CXXTryStmt - A C++ try block, including all handlers.
6443c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner///
6543c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattnerclass CXXTryStmt : public Stmt {
6643c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  SourceLocation TryLoc;
67b0e4cb6a88a4b4bd2ecdcc622e852fa3e20290c9Sam Weinig  unsigned NumHandlers;
68b0e4cb6a88a4b4bd2ecdcc622e852fa3e20290c9Sam Weinig
6907cf58c96dc599d1c25dae4efd9445b6f5d3596cNico Weber  CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, ArrayRef<Stmt*> handlers);
7043c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
717cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis  CXXTryStmt(EmptyShell Empty, unsigned numHandlers)
727cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis    : Stmt(CXXTryStmtClass), NumHandlers(numHandlers) { }
737cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis
747cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis  Stmt const * const *getStmts() const {
757cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis    return reinterpret_cast<Stmt const * const*>(this + 1);
767cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis  }
777cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis  Stmt **getStmts() {
787cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis    return reinterpret_cast<Stmt **>(this + 1);
797cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis  }
807cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis
8143c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattnerpublic:
820b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  static CXXTryStmt *Create(const ASTContext &C, SourceLocation tryLoc,
8307cf58c96dc599d1c25dae4efd9445b6f5d3596cNico Weber                            Stmt *tryBlock, ArrayRef<Stmt*> handlers);
8443c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
850b861560d9b4b0eb2b36d0f32cc7819efe9ee5f2Craig Topper  static CXXTryStmt *Create(const ASTContext &C, EmptyShell Empty,
867cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis                            unsigned numHandlers);
877cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis
8865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
8965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
9043c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
91d308e6201afd3a8a198c52ba034d35ed19d4bafeDouglas Gregor  SourceLocation getTryLoc() const { return TryLoc; }
92a1a396df16c02b22983b5c9592022fd9237d4866Sam Weinig  SourceLocation getEndLoc() const {
937cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis    return getStmts()[NumHandlers]->getLocEnd();
94a1a396df16c02b22983b5c9592022fd9237d4866Sam Weinig  }
95d308e6201afd3a8a198c52ba034d35ed19d4bafeDouglas Gregor
96a1a396df16c02b22983b5c9592022fd9237d4866Sam Weinig  CompoundStmt *getTryBlock() {
97cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(getStmts()[0]);
98a1a396df16c02b22983b5c9592022fd9237d4866Sam Weinig  }
9943c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  const CompoundStmt *getTryBlock() const {
100cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CompoundStmt>(getStmts()[0]);
10143c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  }
10243c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
103b0e4cb6a88a4b4bd2ecdcc622e852fa3e20290c9Sam Weinig  unsigned getNumHandlers() const { return NumHandlers; }
10443c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  CXXCatchStmt *getHandler(unsigned i) {
105cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CXXCatchStmt>(getStmts()[i + 1]);
10643c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  }
10743c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  const CXXCatchStmt *getHandler(unsigned i) const {
108cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    return cast<CXXCatchStmt>(getStmts()[i + 1]);
10943c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  }
11043c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
11143c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  static bool classof(const Stmt *T) {
11243c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner    return T->getStmtClass() == CXXTryStmtClass;
11343c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner  }
11443c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
11563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
11663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(getStmts(), getStmts() + getNumHandlers() + 1);
11763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
1187cb45e37b6f924d9ddbc53ac023bbaadb4ca3534Argyrios Kyrtzidis
11960adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
12043c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner};
12143c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
122ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for
123ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// statement, represented as 'for (range-declarator : range-expression)'.
124ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith///
125ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// This is stored in a partially-desugared form to allow full semantic
126ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// analysis of the constituent components. The original syntactic components
127ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// can be extracted using getLoopVariable and getRangeInit.
128ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithclass CXXForRangeStmt : public Stmt {
129ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  enum { RANGE, BEGINEND, COND, INC, LOOPVAR, BODY, END };
130ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // SubExprs[RANGE] is an expression or declstmt.
131ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // SubExprs[COND] and SubExprs[INC] are expressions.
132ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  Stmt *SubExprs[END];
133ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  SourceLocation ForLoc;
134ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  SourceLocation ColonLoc;
135ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  SourceLocation RParenLoc;
136ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithpublic:
137ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEnd,
138ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                  Expr *Cond, Expr *Inc, DeclStmt *LoopVar, Stmt *Body,
139ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                  SourceLocation FL, SourceLocation CL, SourceLocation RPL);
140ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  CXXForRangeStmt(EmptyShell Empty) : Stmt(CXXForRangeStmtClass, Empty) { }
141ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
142ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
143ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  VarDecl *getLoopVariable();
144ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  Expr *getRangeInit();
145ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
146ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  const VarDecl *getLoopVariable() const;
147ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  const Expr *getRangeInit() const;
148ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
149ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
150ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  DeclStmt *getRangeStmt() { return cast<DeclStmt>(SubExprs[RANGE]); }
151ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  DeclStmt *getBeginEndStmt() {
152ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return cast_or_null<DeclStmt>(SubExprs[BEGINEND]);
153ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
154ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  Expr *getCond() { return cast_or_null<Expr>(SubExprs[COND]); }
155ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  Expr *getInc() { return cast_or_null<Expr>(SubExprs[INC]); }
156ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  DeclStmt *getLoopVarStmt() { return cast<DeclStmt>(SubExprs[LOOPVAR]); }
157ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  Stmt *getBody() { return SubExprs[BODY]; }
158ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
159ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  const DeclStmt *getRangeStmt() const {
160ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return cast<DeclStmt>(SubExprs[RANGE]);
161ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
162ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  const DeclStmt *getBeginEndStmt() const {
163ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return cast_or_null<DeclStmt>(SubExprs[BEGINEND]);
164ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
165ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  const Expr *getCond() const {
166ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return cast_or_null<Expr>(SubExprs[COND]);
167ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
168ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  const Expr *getInc() const {
169ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return cast_or_null<Expr>(SubExprs[INC]);
170ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
171ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  const DeclStmt *getLoopVarStmt() const {
172ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return cast<DeclStmt>(SubExprs[LOOPVAR]);
173ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
174ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  const Stmt *getBody() const { return SubExprs[BODY]; }
175ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
176ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setRangeInit(Expr *E) { SubExprs[RANGE] = reinterpret_cast<Stmt*>(E); }
177ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setRangeStmt(Stmt *S) { SubExprs[RANGE] = S; }
178ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setBeginEndStmt(Stmt *S) { SubExprs[BEGINEND] = S; }
179ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
180ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
181ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setLoopVarStmt(Stmt *S) { SubExprs[LOOPVAR] = S; }
182ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setBody(Stmt *S) { SubExprs[BODY] = S; }
183ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
184ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
185ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  SourceLocation getForLoc() const { return ForLoc; }
186ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setForLoc(SourceLocation Loc) { ForLoc = Loc; }
187ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  SourceLocation getColonLoc() const { return ColonLoc; }
188ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
189ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  SourceLocation getRParenLoc() const { return RParenLoc; }
190ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
191ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
19265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
19365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
19465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExprs[BODY]->getLocEnd();
195ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
19665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
197ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  static bool classof(const Stmt *T) {
198ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return T->getStmtClass() == CXXForRangeStmtClass;
199ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
200ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
201ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  // Iterators
202ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  child_range children() {
203ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    return child_range(&SubExprs[0], &SubExprs[END]);
204ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  }
205ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith};
206ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
207ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// \brief Representation of a Microsoft __if_exists or __if_not_exists
208ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// statement with a dependent name.
209ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor///
210ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// The __if_exists statement can be used to include a sequence of statements
211ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// in the program only when a particular dependent name does not exist. For
212ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// example:
213ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor///
214ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// \code
215ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// template<typename T>
216ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// void call_foo(T &t) {
217ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor///   __if_exists (T::foo) {
218ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie///     t.foo(); // okay: only called when T::foo exists.
219ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor///   }
220ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// }
221ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// \endcode
222ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor///
223ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// Similarly, the __if_not_exists statement can be used to include the
224ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// statements when a particular name does not exist.
225ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor///
226ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// Note that this statement only captures __if_exists and __if_not_exists
227ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// statements whose name is dependent. All non-dependent cases are handled
228ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// directly in the parser, so that they don't introduce a new scope. Clang
229ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// introduces scopes in the dependent case to keep names inside the compound
230ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// statement from leaking out into the surround statements, which would
231ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// compromise the template instantiation model. This behavior differs from
232ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// Visual C++ (which never introduces a scope), but is a fairly reasonable
233ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor/// approximation of the VC++ behavior.
234ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregorclass MSDependentExistsStmt : public Stmt {
235ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  SourceLocation KeywordLoc;
236ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  bool IsIfExists;
237ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
238ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  DeclarationNameInfo NameInfo;
239ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  Stmt *SubStmt;
240ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
241ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  friend class ASTReader;
242ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  friend class ASTStmtReader;
243ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
244ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregorpublic:
245ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  MSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists,
246ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                        NestedNameSpecifierLoc QualifierLoc,
247ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                        DeclarationNameInfo NameInfo,
248ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor                        CompoundStmt *SubStmt)
249ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  : Stmt(MSDependentExistsStmtClass),
250ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    KeywordLoc(KeywordLoc), IsIfExists(IsIfExists),
251ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    QualifierLoc(QualifierLoc), NameInfo(NameInfo),
252ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    SubStmt(reinterpret_cast<Stmt *>(SubStmt)) { }
253ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
254ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the location of the __if_exists or __if_not_exists
255ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// keyword.
256ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  SourceLocation getKeywordLoc() const { return KeywordLoc; }
257ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
258ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// \brief Determine whether this is an __if_exists statement.
259ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  bool isIfExists() const { return IsIfExists; }
260ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor
261ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// \brief Determine whether this is an __if_exists statement.
262ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  bool isIfNotExists() const { return !IsIfExists; }
263ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
264ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies this name, if
265ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// any.
266ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
267ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
268ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// \brief Retrieve the name of the entity we're testing for, along with
269ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// location information
270ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  DeclarationNameInfo getNameInfo() const { return NameInfo; }
271ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
272ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// \brief Retrieve the compound statement that will be included in the
273ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  /// program only if the existence of the symbol matches the initial keyword.
274ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CompoundStmt *getSubStmt() const {
275ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return reinterpret_cast<CompoundStmt *>(SubStmt);
276ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  }
277ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
27865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
27965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
280ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
281ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  child_range children() {
282ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    return child_range(&SubStmt, &SubStmt+1);
283ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  }
284ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
285ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  static bool classof(const Stmt *T) {
286ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor    return T->getStmtClass() == MSDependentExistsStmtClass;
287ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor  }
288ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor};
28943c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner
290db2eb5abf4c082d1f0c5c45e39d8cd0300f81e38Douglas Gregor}  // end namespace clang
291f540305c5d834ad9412b41805b81a74249b7c5afDouglas Gregor
29243c98041f7746f8d9445bdea873d86eca966b2b8Chris Lattner#endif
293