clang  3.9.0
StmtCXX.cpp
Go to the documentation of this file.
1 //===--- StmtCXX.cpp - Classes for representing C++ statements ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the subclesses of Stmt class declared in StmtCXX.h
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/StmtCXX.h"
15 
16 #include "clang/AST/ASTContext.h"
17 
18 using namespace clang;
19 
21  if (ExceptionDecl)
22  return ExceptionDecl->getType();
23  return QualType();
24 }
25 
27  Stmt *tryBlock, ArrayRef<Stmt *> handlers) {
28  std::size_t Size = sizeof(CXXTryStmt);
29  Size += ((handlers.size() + 1) * sizeof(Stmt *));
30 
31  void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
32  return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
33 }
34 
35 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
36  unsigned numHandlers) {
37  std::size_t Size = sizeof(CXXTryStmt);
38  Size += ((numHandlers + 1) * sizeof(Stmt *));
39 
40  void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
41  return new (Mem) CXXTryStmt(Empty, numHandlers);
42 }
43 
44 CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
45  ArrayRef<Stmt *> handlers)
46  : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
47  Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
48  Stmts[0] = tryBlock;
49  std::copy(handlers.begin(), handlers.end(), Stmts + 1);
50 }
51 
53  DeclStmt *BeginStmt, DeclStmt *EndStmt,
54  Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
55  Stmt *Body, SourceLocation FL,
57  SourceLocation RPL)
58  : Stmt(CXXForRangeStmtClass), ForLoc(FL), CoawaitLoc(CAL), ColonLoc(CL),
59  RParenLoc(RPL) {
60  SubExprs[RANGE] = Range;
61  SubExprs[BEGINSTMT] = BeginStmt;
62  SubExprs[ENDSTMT] = EndStmt;
63  SubExprs[COND] = Cond;
64  SubExprs[INC] = Inc;
65  SubExprs[LOOPVAR] = LoopVar;
66  SubExprs[BODY] = Body;
67 }
68 
70  DeclStmt *RangeStmt = getRangeStmt();
71  VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
72  assert(RangeDecl && "for-range should have a single var decl");
73  return RangeDecl->getInit();
74 }
75 
77  return const_cast<CXXForRangeStmt *>(this)->getRangeInit();
78 }
79 
81  Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
82  assert(LV && "No loop variable in CXXForRangeStmt");
83  return cast<VarDecl>(LV);
84 }
85 
87  return const_cast<CXXForRangeStmt *>(this)->getLoopVariable();
88 }
Defines the clang::ASTContext interface.
A (possibly-)qualified type.
Definition: Type.h:598
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c.h:53
const Expr * getInit() const
Definition: Decl.h:1139
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:768
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:92
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition: StmtCXX.cpp:26
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition: StmtCXX.h:128
QualType getType() const
Definition: Decl.h:599
Expr - This represents one expression.
Definition: Expr.h:105
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:65
Encodes a location in the source.
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:443
const Decl * getSingleDecl() const
Definition: Stmt.h:461
CXXForRangeStmt(DeclStmt *Range, DeclStmt *Begin, DeclStmt *End, Expr *Cond, Expr *Inc, DeclStmt *LoopVar, Stmt *Body, SourceLocation FL, SourceLocation CAL, SourceLocation CL, SourceLocation RPL)
Definition: StmtCXX.cpp:52
QualType getCaughtType() const
Definition: StmtCXX.cpp:20
DeclStmt * getRangeStmt()
Definition: StmtCXX.h:154
VarDecl * getLoopVariable()
Definition: StmtCXX.cpp:80
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:568
DeclStmt * getLoopVarStmt()
Definition: StmtCXX.h:161
SourceLocation ColonLoc
Location of ':'.
Definition: OpenMPClause.h:266