2006-10-25 12:09:21 +08:00
|
|
|
//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-10-25 12:09:21 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Stmt class and statement subclasses.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-02 01:12:56 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/ASTDiagnostic.h"
|
2006-12-05 02:06:35 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2008-05-30 05:12:08 +08:00
|
|
|
#include "clang/AST/ExprObjC.h"
|
2012-12-02 01:12:56 +08:00
|
|
|
#include "clang/AST/Stmt.h"
|
2009-04-26 09:32:48 +08:00
|
|
|
#include "clang/AST/StmtCXX.h"
|
|
|
|
#include "clang/AST/StmtObjC.h"
|
2013-07-19 11:13:43 +08:00
|
|
|
#include "clang/AST/StmtOpenMP.h"
|
2008-12-23 03:15:10 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2013-02-09 06:30:41 +08:00
|
|
|
#include "clang/Basic/CharInfo.h"
|
2010-04-24 00:29:58 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2012-12-02 01:12:56 +08:00
|
|
|
#include "clang/Lex/Token.h"
|
2012-08-25 01:05:45 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2011-07-04 14:13:27 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-10-25 12:09:21 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2007-05-24 05:48:04 +08:00
|
|
|
static struct StmtClassNameTable {
|
2007-08-25 09:42:24 +08:00
|
|
|
const char *Name;
|
|
|
|
unsigned Counter;
|
|
|
|
unsigned Size;
|
2010-05-05 23:24:00 +08:00
|
|
|
} StmtClassInfo[Stmt::lastStmtConstant+1];
|
2007-08-25 09:42:24 +08:00
|
|
|
|
|
|
|
static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
|
|
|
|
static bool Initialized = false;
|
|
|
|
if (Initialized)
|
|
|
|
return StmtClassInfo[E];
|
|
|
|
|
|
|
|
// Intialize the table on the first use.
|
|
|
|
Initialized = true;
|
2010-05-18 14:22:21 +08:00
|
|
|
#define ABSTRACT_STMT(STMT)
|
2008-11-14 20:46:07 +08:00
|
|
|
#define STMT(CLASS, PARENT) \
|
|
|
|
StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
|
|
|
|
StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
|
2010-05-05 23:24:00 +08:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
2008-08-06 07:15:29 +08:00
|
|
|
|
2007-08-25 09:42:24 +08:00
|
|
|
return StmtClassInfo[E];
|
|
|
|
}
|
|
|
|
|
2013-08-18 18:09:15 +08:00
|
|
|
void *Stmt::operator new(size_t bytes, const ASTContext& C,
|
2013-08-19 01:45:38 +08:00
|
|
|
unsigned alignment) {
|
2012-12-01 23:09:41 +08:00
|
|
|
return ::operator new(bytes, C, alignment);
|
|
|
|
}
|
|
|
|
|
2007-03-24 06:27:02 +08:00
|
|
|
const char *Stmt::getStmtClassName() const {
|
2010-10-26 16:39:16 +08:00
|
|
|
return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
|
2007-03-24 06:27:02 +08:00
|
|
|
}
|
2007-05-24 05:48:04 +08:00
|
|
|
|
|
|
|
void Stmt::PrintStats() {
|
2007-08-25 09:42:24 +08:00
|
|
|
// Ensure the table is primed.
|
|
|
|
getStmtInfoTableEntry(Stmt::NullStmtClass);
|
2008-08-06 07:15:29 +08:00
|
|
|
|
2007-05-24 05:48:04 +08:00
|
|
|
unsigned sum = 0;
|
2011-07-04 14:13:27 +08:00
|
|
|
llvm::errs() << "\n*** Stmt/Expr Stats:\n";
|
2010-05-05 23:24:00 +08:00
|
|
|
for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
|
2007-08-25 09:42:24 +08:00
|
|
|
if (StmtClassInfo[i].Name == 0) continue;
|
|
|
|
sum += StmtClassInfo[i].Counter;
|
2007-05-24 05:48:04 +08:00
|
|
|
}
|
2011-07-04 14:13:27 +08:00
|
|
|
llvm::errs() << " " << sum << " stmts/exprs total.\n";
|
2007-05-24 05:48:04 +08:00
|
|
|
sum = 0;
|
2010-05-05 23:24:00 +08:00
|
|
|
for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
|
2007-08-25 09:42:24 +08:00
|
|
|
if (StmtClassInfo[i].Name == 0) continue;
|
2009-05-26 22:40:08 +08:00
|
|
|
if (StmtClassInfo[i].Counter == 0) continue;
|
2011-07-04 14:13:27 +08:00
|
|
|
llvm::errs() << " " << StmtClassInfo[i].Counter << " "
|
|
|
|
<< StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size
|
|
|
|
<< " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size
|
|
|
|
<< " bytes)\n";
|
2007-08-25 09:42:24 +08:00
|
|
|
sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
|
2007-05-24 05:48:04 +08:00
|
|
|
}
|
2011-07-04 14:13:27 +08:00
|
|
|
|
|
|
|
llvm::errs() << "Total bytes = " << sum << "\n";
|
2007-05-24 05:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Stmt::addStmtClass(StmtClass s) {
|
2007-08-25 09:42:24 +08:00
|
|
|
++getStmtInfoTableEntry(s).Counter;
|
2007-05-24 05:48:04 +08:00
|
|
|
}
|
|
|
|
|
2012-03-06 05:42:49 +08:00
|
|
|
bool Stmt::StatisticsEnabled = false;
|
|
|
|
void Stmt::EnableStatistics() {
|
|
|
|
StatisticsEnabled = true;
|
2007-05-24 05:48:04 +08:00
|
|
|
}
|
|
|
|
|
2011-07-07 14:58:02 +08:00
|
|
|
Stmt *Stmt::IgnoreImplicit() {
|
|
|
|
Stmt *s = this;
|
|
|
|
|
|
|
|
if (ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(s))
|
|
|
|
s = ewc->getSubExpr();
|
|
|
|
|
|
|
|
while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(s))
|
|
|
|
s = ice->getSubExpr();
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2011-09-10 08:02:34 +08:00
|
|
|
/// \brief Strip off all label-like statements.
|
|
|
|
///
|
2012-04-14 08:33:13 +08:00
|
|
|
/// This will strip off label statements, case statements, attributed
|
|
|
|
/// statements and default statements recursively.
|
2011-09-10 08:02:34 +08:00
|
|
|
const Stmt *Stmt::stripLabelLikeStatements() const {
|
|
|
|
const Stmt *S = this;
|
|
|
|
while (true) {
|
|
|
|
if (const LabelStmt *LS = dyn_cast<LabelStmt>(S))
|
|
|
|
S = LS->getSubStmt();
|
|
|
|
else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S))
|
|
|
|
S = SC->getSubStmt();
|
2012-04-14 08:33:13 +08:00
|
|
|
else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S))
|
|
|
|
S = AS->getSubStmt();
|
2011-09-10 08:02:34 +08:00
|
|
|
else
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-09 16:16:59 +08:00
|
|
|
namespace {
|
|
|
|
struct good {};
|
|
|
|
struct bad {};
|
2011-02-09 16:31:17 +08:00
|
|
|
|
|
|
|
// These silly little functions have to be static inline to suppress
|
|
|
|
// unused warnings, and they have to be defined to suppress other
|
|
|
|
// warnings.
|
2011-02-09 16:42:57 +08:00
|
|
|
static inline good is_good(good) { return good(); }
|
2011-02-09 16:16:59 +08:00
|
|
|
|
|
|
|
typedef Stmt::child_range children_t();
|
2011-02-09 16:42:57 +08:00
|
|
|
template <class T> good implements_children(children_t T::*) {
|
|
|
|
return good();
|
|
|
|
}
|
2013-09-11 06:57:15 +08:00
|
|
|
LLVM_ATTRIBUTE_UNUSED
|
2011-02-09 16:42:57 +08:00
|
|
|
static inline bad implements_children(children_t Stmt::*) {
|
|
|
|
return bad();
|
|
|
|
}
|
2011-02-09 16:16:59 +08:00
|
|
|
|
2012-12-25 22:51:39 +08:00
|
|
|
typedef SourceLocation getLocStart_t() const;
|
|
|
|
template <class T> good implements_getLocStart(getLocStart_t T::*) {
|
2011-02-09 16:42:57 +08:00
|
|
|
return good();
|
|
|
|
}
|
2013-09-11 06:57:15 +08:00
|
|
|
LLVM_ATTRIBUTE_UNUSED
|
2012-12-25 22:51:39 +08:00
|
|
|
static inline bad implements_getLocStart(getLocStart_t Stmt::*) {
|
|
|
|
return bad();
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef SourceLocation getLocEnd_t() const;
|
|
|
|
template <class T> good implements_getLocEnd(getLocEnd_t T::*) {
|
|
|
|
return good();
|
|
|
|
}
|
2013-09-11 06:57:15 +08:00
|
|
|
LLVM_ATTRIBUTE_UNUSED
|
2012-12-25 22:51:39 +08:00
|
|
|
static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) {
|
2011-02-09 16:42:57 +08:00
|
|
|
return bad();
|
|
|
|
}
|
2011-02-09 16:16:59 +08:00
|
|
|
|
|
|
|
#define ASSERT_IMPLEMENTS_children(type) \
|
2013-09-11 06:57:15 +08:00
|
|
|
(void) is_good(implements_children(&type::children))
|
2012-12-25 22:51:39 +08:00
|
|
|
#define ASSERT_IMPLEMENTS_getLocStart(type) \
|
2013-09-11 06:57:15 +08:00
|
|
|
(void) is_good(implements_getLocStart(&type::getLocStart))
|
2012-12-25 22:51:39 +08:00
|
|
|
#define ASSERT_IMPLEMENTS_getLocEnd(type) \
|
2013-09-11 06:57:15 +08:00
|
|
|
(void) is_good(implements_getLocEnd(&type::getLocEnd))
|
2011-02-09 16:16:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Check whether the various Stmt classes implement their member
|
|
|
|
/// functions.
|
2013-09-11 06:57:15 +08:00
|
|
|
LLVM_ATTRIBUTE_UNUSED
|
2011-02-09 16:16:59 +08:00
|
|
|
static inline void check_implementations() {
|
|
|
|
#define ABSTRACT_STMT(type)
|
|
|
|
#define STMT(type, base) \
|
|
|
|
ASSERT_IMPLEMENTS_children(type); \
|
2012-12-25 22:51:39 +08:00
|
|
|
ASSERT_IMPLEMENTS_getLocStart(type); \
|
|
|
|
ASSERT_IMPLEMENTS_getLocEnd(type);
|
2011-02-09 16:16:59 +08:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt::child_range Stmt::children() {
|
|
|
|
switch (getStmtClass()) {
|
|
|
|
case Stmt::NoStmtClass: llvm_unreachable("statement without class");
|
|
|
|
#define ABSTRACT_STMT(type)
|
|
|
|
#define STMT(type, base) \
|
|
|
|
case Stmt::type##Class: \
|
|
|
|
return static_cast<type*>(this)->children();
|
|
|
|
#include "clang/AST/StmtNodes.inc"
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown statement kind!");
|
|
|
|
}
|
|
|
|
|
2012-03-09 23:39:19 +08:00
|
|
|
// Amusing macro metaprogramming hack: check whether a class provides
|
2012-12-25 22:51:39 +08:00
|
|
|
// a more specific implementation of getSourceRange.
|
2012-03-09 23:39:19 +08:00
|
|
|
//
|
|
|
|
// See also Expr.cpp:getExprLoc().
|
|
|
|
namespace {
|
|
|
|
/// This implementation is used when a class provides a custom
|
2012-12-25 22:51:39 +08:00
|
|
|
/// implementation of getSourceRange.
|
2012-03-09 23:39:19 +08:00
|
|
|
template <class S, class T>
|
2012-12-25 22:51:39 +08:00
|
|
|
SourceRange getSourceRangeImpl(const Stmt *stmt,
|
|
|
|
SourceRange (T::*v)() const) {
|
|
|
|
return static_cast<const S*>(stmt)->getSourceRange();
|
2012-03-09 23:39:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// This implementation is used when a class doesn't provide a custom
|
2012-12-25 22:51:39 +08:00
|
|
|
/// implementation of getSourceRange. Overload resolution should pick it over
|
2012-03-09 23:39:19 +08:00
|
|
|
/// the implementation above because it's more specialized according to
|
|
|
|
/// function template partial ordering.
|
|
|
|
template <class S>
|
2012-12-25 22:51:39 +08:00
|
|
|
SourceRange getSourceRangeImpl(const Stmt *stmt,
|
|
|
|
SourceRange (Stmt::*v)() const) {
|
|
|
|
return SourceRange(static_cast<const S*>(stmt)->getLocStart(),
|
|
|
|
static_cast<const S*>(stmt)->getLocEnd());
|
2012-03-09 23:39:19 +08:00
|
|
|
}
|
2012-12-25 22:51:39 +08:00
|
|
|
}
|
2012-03-09 23:39:19 +08:00
|
|
|
|
2012-12-25 22:51:39 +08:00
|
|
|
SourceRange Stmt::getSourceRange() const {
|
|
|
|
switch (getStmtClass()) {
|
|
|
|
case Stmt::NoStmtClass: llvm_unreachable("statement without class");
|
|
|
|
#define ABSTRACT_STMT(type)
|
|
|
|
#define STMT(type, base) \
|
|
|
|
case Stmt::type##Class: \
|
|
|
|
return getSourceRangeImpl<type>(this, &type::getSourceRange);
|
|
|
|
#include "clang/AST/StmtNodes.inc"
|
2012-03-09 23:39:19 +08:00
|
|
|
}
|
2012-12-25 22:51:39 +08:00
|
|
|
llvm_unreachable("unknown statement kind!");
|
2012-03-09 23:39:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation Stmt::getLocStart() const {
|
2012-12-25 22:51:39 +08:00
|
|
|
// llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n";
|
2012-03-09 23:39:19 +08:00
|
|
|
switch (getStmtClass()) {
|
|
|
|
case Stmt::NoStmtClass: llvm_unreachable("statement without class");
|
|
|
|
#define ABSTRACT_STMT(type)
|
|
|
|
#define STMT(type, base) \
|
|
|
|
case Stmt::type##Class: \
|
2012-12-25 22:51:39 +08:00
|
|
|
return static_cast<const type*>(this)->getLocStart();
|
2012-03-09 23:39:19 +08:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown statement kind");
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation Stmt::getLocEnd() const {
|
|
|
|
switch (getStmtClass()) {
|
|
|
|
case Stmt::NoStmtClass: llvm_unreachable("statement without class");
|
|
|
|
#define ABSTRACT_STMT(type)
|
|
|
|
#define STMT(type, base) \
|
|
|
|
case Stmt::type##Class: \
|
2012-12-25 22:51:39 +08:00
|
|
|
return static_cast<const type*>(this)->getLocEnd();
|
2012-03-09 23:39:19 +08:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown statement kind");
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
|
2012-07-05 01:03:41 +08:00
|
|
|
SourceLocation LB, SourceLocation RB)
|
|
|
|
: Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) {
|
2012-12-30 04:03:39 +08:00
|
|
|
CompoundStmtBits.NumStmts = Stmts.size();
|
|
|
|
assert(CompoundStmtBits.NumStmts == Stmts.size() &&
|
2012-07-05 01:03:41 +08:00
|
|
|
"NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
|
|
|
|
|
2012-12-30 04:03:39 +08:00
|
|
|
if (Stmts.size() == 0) {
|
2012-07-05 01:03:41 +08:00
|
|
|
Body = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-30 04:03:39 +08:00
|
|
|
Body = new (C) Stmt*[Stmts.size()];
|
|
|
|
std::copy(Stmts.begin(), Stmts.end(), Body);
|
2012-07-05 01:03:41 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 14:02:26 +08:00
|
|
|
void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts,
|
|
|
|
unsigned NumStmts) {
|
2009-04-17 08:04:06 +08:00
|
|
|
if (this->Body)
|
|
|
|
C.Deallocate(Body);
|
2010-10-26 16:39:16 +08:00
|
|
|
this->CompoundStmtBits.NumStmts = NumStmts;
|
2009-04-17 08:04:06 +08:00
|
|
|
|
|
|
|
Body = new (C) Stmt*[NumStmts];
|
|
|
|
memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts);
|
|
|
|
}
|
2007-05-24 05:48:04 +08:00
|
|
|
|
2007-05-28 14:56:27 +08:00
|
|
|
const char *LabelStmt::getName() const {
|
2011-02-17 15:39:24 +08:00
|
|
|
return getDecl()->getIdentifier()->getNameStart();
|
2007-05-28 14:56:27 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc,
|
2012-07-09 18:04:07 +08:00
|
|
|
ArrayRef<const Attr*> Attrs,
|
|
|
|
Stmt *SubStmt) {
|
|
|
|
void *Mem = C.Allocate(sizeof(AttributedStmt) +
|
|
|
|
sizeof(Attr*) * (Attrs.size() - 1),
|
|
|
|
llvm::alignOf<AttributedStmt>());
|
|
|
|
return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C,
|
|
|
|
unsigned NumAttrs) {
|
2012-07-09 18:04:07 +08:00
|
|
|
assert(NumAttrs > 0 && "NumAttrs should be greater than zero");
|
|
|
|
void *Mem = C.Allocate(sizeof(AttributedStmt) +
|
|
|
|
sizeof(Attr*) * (NumAttrs - 1),
|
|
|
|
llvm::alignOf<AttributedStmt>());
|
|
|
|
return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
|
|
|
|
}
|
|
|
|
|
2013-08-22 14:02:26 +08:00
|
|
|
std::string AsmStmt::generateAsmString(const ASTContext &C) const {
|
2012-08-29 02:21:14 +08:00
|
|
|
if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
|
|
|
|
return gccAsmStmt->generateAsmString(C);
|
|
|
|
if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
|
|
|
|
return msAsmStmt->generateAsmString(C);
|
2012-08-29 01:43:23 +08:00
|
|
|
llvm_unreachable("unknown asm statement kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef AsmStmt::getOutputConstraint(unsigned i) const {
|
2012-08-29 02:21:14 +08:00
|
|
|
if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
|
|
|
|
return gccAsmStmt->getOutputConstraint(i);
|
|
|
|
if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
|
|
|
|
return msAsmStmt->getOutputConstraint(i);
|
2012-08-29 01:43:23 +08:00
|
|
|
llvm_unreachable("unknown asm statement kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
const Expr *AsmStmt::getOutputExpr(unsigned i) const {
|
2012-08-29 02:21:14 +08:00
|
|
|
if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
|
|
|
|
return gccAsmStmt->getOutputExpr(i);
|
|
|
|
if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
|
|
|
|
return msAsmStmt->getOutputExpr(i);
|
2012-08-29 01:43:23 +08:00
|
|
|
llvm_unreachable("unknown asm statement kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef AsmStmt::getInputConstraint(unsigned i) const {
|
2012-08-29 02:21:14 +08:00
|
|
|
if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
|
|
|
|
return gccAsmStmt->getInputConstraint(i);
|
|
|
|
if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
|
|
|
|
return msAsmStmt->getInputConstraint(i);
|
2012-08-29 01:43:23 +08:00
|
|
|
llvm_unreachable("unknown asm statement kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
const Expr *AsmStmt::getInputExpr(unsigned i) const {
|
2012-08-29 02:21:14 +08:00
|
|
|
if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
|
|
|
|
return gccAsmStmt->getInputExpr(i);
|
|
|
|
if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
|
|
|
|
return msAsmStmt->getInputExpr(i);
|
2012-08-29 01:43:23 +08:00
|
|
|
llvm_unreachable("unknown asm statement kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef AsmStmt::getClobber(unsigned i) const {
|
2012-08-29 02:21:14 +08:00
|
|
|
if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
|
|
|
|
return gccAsmStmt->getClobber(i);
|
|
|
|
if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
|
|
|
|
return msAsmStmt->getClobber(i);
|
2012-08-29 01:43:23 +08:00
|
|
|
llvm_unreachable("unknown asm statement kind!");
|
|
|
|
}
|
|
|
|
|
2012-08-28 08:24:05 +08:00
|
|
|
/// getNumPlusOperands - Return the number of output operands that have a "+"
|
|
|
|
/// constraint.
|
|
|
|
unsigned AsmStmt::getNumPlusOperands() const {
|
|
|
|
unsigned Res = 0;
|
|
|
|
for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
|
|
|
|
if (isOutputPlusConstraint(i))
|
|
|
|
++Res;
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2012-08-28 07:47:56 +08:00
|
|
|
StringRef GCCAsmStmt::getClobber(unsigned i) const {
|
|
|
|
return getClobberStringLiteral(i)->getString();
|
|
|
|
}
|
|
|
|
|
2012-08-25 08:11:56 +08:00
|
|
|
Expr *GCCAsmStmt::getOutputExpr(unsigned i) {
|
2008-10-28 02:40:21 +08:00
|
|
|
return cast<Expr>(Exprs[i]);
|
|
|
|
}
|
2009-03-10 12:59:06 +08:00
|
|
|
|
|
|
|
/// getOutputConstraint - Return the constraint string for the specified
|
|
|
|
/// output operand. All output constraints are known to be non-empty (either
|
|
|
|
/// '=' or '+').
|
2012-08-25 08:11:56 +08:00
|
|
|
StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const {
|
2010-01-31 04:38:10 +08:00
|
|
|
return getOutputConstraintLiteral(i)->getString();
|
2008-10-28 02:40:21 +08:00
|
|
|
}
|
2009-03-10 12:59:06 +08:00
|
|
|
|
2012-08-25 08:11:56 +08:00
|
|
|
Expr *GCCAsmStmt::getInputExpr(unsigned i) {
|
2008-10-28 02:40:21 +08:00
|
|
|
return cast<Expr>(Exprs[i + NumOutputs]);
|
|
|
|
}
|
2012-08-25 08:11:56 +08:00
|
|
|
void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) {
|
2011-02-22 06:09:29 +08:00
|
|
|
Exprs[i + NumOutputs] = E;
|
|
|
|
}
|
|
|
|
|
2009-03-10 12:59:06 +08:00
|
|
|
/// getInputConstraint - Return the specified input constraint. Unlike output
|
|
|
|
/// constraints, these can be empty.
|
2012-08-25 08:11:56 +08:00
|
|
|
StringRef GCCAsmStmt::getInputConstraint(unsigned i) const {
|
2010-01-31 04:38:10 +08:00
|
|
|
return getInputConstraintLiteral(i)->getString();
|
2008-10-28 02:40:21 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 14:02:26 +08:00
|
|
|
void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
|
|
|
|
IdentifierInfo **Names,
|
|
|
|
StringLiteral **Constraints,
|
|
|
|
Stmt **Exprs,
|
|
|
|
unsigned NumOutputs,
|
|
|
|
unsigned NumInputs,
|
|
|
|
StringLiteral **Clobbers,
|
|
|
|
unsigned NumClobbers) {
|
2009-04-18 04:57:14 +08:00
|
|
|
this->NumOutputs = NumOutputs;
|
|
|
|
this->NumInputs = NumInputs;
|
2010-01-31 07:19:41 +08:00
|
|
|
this->NumClobbers = NumClobbers;
|
|
|
|
|
|
|
|
unsigned NumExprs = NumOutputs + NumInputs;
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2010-01-31 07:19:41 +08:00
|
|
|
C.Deallocate(this->Names);
|
|
|
|
this->Names = new (C) IdentifierInfo*[NumExprs];
|
|
|
|
std::copy(Names, Names + NumExprs, this->Names);
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2010-01-31 07:19:41 +08:00
|
|
|
C.Deallocate(this->Exprs);
|
|
|
|
this->Exprs = new (C) Stmt*[NumExprs];
|
|
|
|
std::copy(Exprs, Exprs + NumExprs, this->Exprs);
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2010-01-31 07:19:41 +08:00
|
|
|
C.Deallocate(this->Constraints);
|
|
|
|
this->Constraints = new (C) StringLiteral*[NumExprs];
|
|
|
|
std::copy(Constraints, Constraints + NumExprs, this->Constraints);
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2010-01-31 07:19:41 +08:00
|
|
|
C.Deallocate(this->Clobbers);
|
|
|
|
this->Clobbers = new (C) StringLiteral*[NumClobbers];
|
|
|
|
std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
|
2009-04-18 04:57:14 +08:00
|
|
|
}
|
|
|
|
|
2009-03-10 14:33:24 +08:00
|
|
|
/// getNamedOperand - Given a symbolic operand reference like %[foo],
|
|
|
|
/// translate this into a numeric value needed to reference the same operand.
|
|
|
|
/// This returns -1 if the operand name is invalid.
|
2012-08-25 08:11:56 +08:00
|
|
|
int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const {
|
2009-03-10 14:33:24 +08:00
|
|
|
unsigned NumPlusOperands = 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-10 14:33:24 +08:00
|
|
|
// Check if this is an output operand.
|
|
|
|
for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
|
|
|
|
if (getOutputName(i) == SymbolicName)
|
|
|
|
return i;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-10 14:33:24 +08:00
|
|
|
for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
|
|
|
|
if (getInputName(i) == SymbolicName)
|
|
|
|
return getNumOutputs() + NumPlusOperands + i;
|
|
|
|
|
|
|
|
// Not found.
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
|
|
|
|
/// it into pieces. If the asm string is erroneous, emit errors and return
|
|
|
|
/// true, otherwise return false.
|
2012-08-25 08:11:56 +08:00
|
|
|
unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
|
2013-08-22 14:02:26 +08:00
|
|
|
const ASTContext &C, unsigned &DiagOffs) const {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Str = getAsmString()->getString();
|
2010-08-17 20:54:38 +08:00
|
|
|
const char *StrStart = Str.begin();
|
|
|
|
const char *StrEnd = Str.end();
|
2009-03-11 07:51:40 +08:00
|
|
|
const char *CurPtr = StrStart;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
// "Simple" inline asms have no constraints or operands, just convert the asm
|
|
|
|
// string to escape $'s.
|
|
|
|
if (isSimple()) {
|
|
|
|
std::string Result;
|
2009-03-11 07:51:40 +08:00
|
|
|
for (; CurPtr != StrEnd; ++CurPtr) {
|
|
|
|
switch (*CurPtr) {
|
2009-03-11 07:21:44 +08:00
|
|
|
case '$':
|
|
|
|
Result += "$$";
|
|
|
|
break;
|
|
|
|
default:
|
2009-03-11 07:51:40 +08:00
|
|
|
Result += *CurPtr;
|
2009-03-11 07:21:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Pieces.push_back(AsmStringPiece(Result));
|
2009-03-11 07:51:40 +08:00
|
|
|
return 0;
|
2009-03-11 07:21:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CurStringPiece - The current string that we are building up as we scan the
|
|
|
|
// asm string.
|
|
|
|
std::string CurStringPiece;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-09-02 08:18:52 +08:00
|
|
|
bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
while (1) {
|
|
|
|
// Done with the string?
|
2009-03-11 07:51:40 +08:00
|
|
|
if (CurPtr == StrEnd) {
|
2009-03-11 07:21:44 +08:00
|
|
|
if (!CurStringPiece.empty())
|
|
|
|
Pieces.push_back(AsmStringPiece(CurStringPiece));
|
2009-03-11 07:51:40 +08:00
|
|
|
return 0;
|
2009-03-11 07:21:44 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 07:51:40 +08:00
|
|
|
char CurChar = *CurPtr++;
|
2010-04-06 02:44:00 +08:00
|
|
|
switch (CurChar) {
|
|
|
|
case '$': CurStringPiece += "$$"; continue;
|
2010-04-24 00:29:58 +08:00
|
|
|
case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
|
|
|
|
case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
|
|
|
|
case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
|
2010-04-06 02:44:00 +08:00
|
|
|
case '%':
|
|
|
|
break;
|
|
|
|
default:
|
2009-03-11 07:21:44 +08:00
|
|
|
CurStringPiece += CurChar;
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
// Escaped "%" character in asm string.
|
2009-03-11 08:06:36 +08:00
|
|
|
if (CurPtr == StrEnd) {
|
|
|
|
// % at end of string is invalid (no escape).
|
|
|
|
DiagOffs = CurPtr-StrStart-1;
|
|
|
|
return diag::err_asm_invalid_escape;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 07:51:40 +08:00
|
|
|
char EscapedChar = *CurPtr++;
|
2009-03-11 07:21:44 +08:00
|
|
|
if (EscapedChar == '%') { // %% -> %
|
|
|
|
// Escaped percentage sign.
|
|
|
|
CurStringPiece += '%';
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
if (EscapedChar == '=') { // %= -> Generate an unique ID.
|
|
|
|
CurStringPiece += "${:uid}";
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
// Otherwise, we have an operand. If we have accumulated a string so far,
|
|
|
|
// add it to the Pieces list.
|
|
|
|
if (!CurStringPiece.empty()) {
|
|
|
|
Pieces.push_back(AsmStringPiece(CurStringPiece));
|
|
|
|
CurStringPiece.clear();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
// Handle %x4 and %x[foo] by capturing x as the modifier character.
|
|
|
|
char Modifier = '\0';
|
2013-02-09 06:30:41 +08:00
|
|
|
if (isLetter(EscapedChar)) {
|
2011-07-05 19:13:37 +08:00
|
|
|
if (CurPtr == StrEnd) { // Premature end.
|
|
|
|
DiagOffs = CurPtr-StrStart-1;
|
|
|
|
return diag::err_asm_invalid_escape;
|
|
|
|
}
|
2009-03-11 07:21:44 +08:00
|
|
|
Modifier = EscapedChar;
|
2009-03-11 07:51:40 +08:00
|
|
|
EscapedChar = *CurPtr++;
|
2009-03-11 07:21:44 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-02-09 06:30:41 +08:00
|
|
|
if (isDigit(EscapedChar)) {
|
2009-03-11 07:21:44 +08:00
|
|
|
// %n - Assembler operand n
|
2009-03-12 06:52:17 +08:00
|
|
|
unsigned N = 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-12 06:52:17 +08:00
|
|
|
--CurPtr;
|
2013-02-09 06:30:41 +08:00
|
|
|
while (CurPtr != StrEnd && isDigit(*CurPtr))
|
2009-03-12 07:09:16 +08:00
|
|
|
N = N*10 + ((*CurPtr++)-'0');
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 08:23:13 +08:00
|
|
|
unsigned NumOperands =
|
|
|
|
getNumOutputs() + getNumPlusOperands() + getNumInputs();
|
|
|
|
if (N >= NumOperands) {
|
|
|
|
DiagOffs = CurPtr-StrStart-1;
|
|
|
|
return diag::err_asm_invalid_operand_number;
|
|
|
|
}
|
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
Pieces.push_back(AsmStringPiece(N, Modifier));
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
// Handle %[foo], a symbolic operand reference.
|
|
|
|
if (EscapedChar == '[') {
|
2009-03-11 08:06:36 +08:00
|
|
|
DiagOffs = CurPtr-StrStart-1;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 08:06:36 +08:00
|
|
|
// Find the ']'.
|
2009-03-11 07:51:40 +08:00
|
|
|
const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
|
2009-03-11 08:06:36 +08:00
|
|
|
if (NameEnd == 0)
|
|
|
|
return diag::err_asm_unterminated_symbolic_operand_name;
|
|
|
|
if (NameEnd == CurPtr)
|
|
|
|
return diag::err_asm_empty_symbolic_operand_name;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
int N = getNamedOperand(SymbolicName);
|
2009-03-11 08:06:36 +08:00
|
|
|
if (N == -1) {
|
|
|
|
// Verify that an operand with that name exists.
|
|
|
|
DiagOffs = CurPtr-StrStart;
|
|
|
|
return diag::err_asm_unknown_symbolic_operand_name;
|
|
|
|
}
|
2009-03-11 07:21:44 +08:00
|
|
|
Pieces.push_back(AsmStringPiece(N, Modifier));
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 08:06:36 +08:00
|
|
|
CurPtr = NameEnd+1;
|
2009-03-11 07:21:44 +08:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-11 07:57:07 +08:00
|
|
|
DiagOffs = CurPtr-StrStart-1;
|
2009-03-11 07:51:40 +08:00
|
|
|
return diag::err_asm_invalid_escape;
|
2009-03-11 07:21:44 +08:00
|
|
|
}
|
|
|
|
}
|
2012-08-28 04:23:31 +08:00
|
|
|
|
|
|
|
/// Assemble final IR asm string (GCC-style).
|
2013-08-22 14:02:26 +08:00
|
|
|
std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const {
|
2012-08-25 01:05:45 +08:00
|
|
|
// Analyze the asm string to decompose it into its pieces. We know that Sema
|
|
|
|
// has already done this, so it is guaranteed to be successful.
|
2012-08-25 08:11:56 +08:00
|
|
|
SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces;
|
2012-08-25 01:05:45 +08:00
|
|
|
unsigned DiagOffs;
|
|
|
|
AnalyzeAsmString(Pieces, C, DiagOffs);
|
|
|
|
|
|
|
|
std::string AsmString;
|
|
|
|
for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
|
|
|
|
if (Pieces[i].isString())
|
|
|
|
AsmString += Pieces[i].getString();
|
|
|
|
else if (Pieces[i].getModifier() == '\0')
|
|
|
|
AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo());
|
|
|
|
else
|
|
|
|
AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' +
|
|
|
|
Pieces[i].getModifier() + '}';
|
|
|
|
}
|
|
|
|
return AsmString;
|
|
|
|
}
|
2009-03-11 07:21:44 +08:00
|
|
|
|
2012-08-28 04:23:31 +08:00
|
|
|
/// Assemble final IR asm string (MS-style).
|
2013-08-22 14:02:26 +08:00
|
|
|
std::string MSAsmStmt::generateAsmString(const ASTContext &C) const {
|
2012-08-28 04:23:31 +08:00
|
|
|
// FIXME: This needs to be translated into the IR string representation.
|
2012-08-29 04:33:49 +08:00
|
|
|
return AsmStr;
|
2012-08-28 04:23:31 +08:00
|
|
|
}
|
|
|
|
|
2012-08-24 08:07:09 +08:00
|
|
|
Expr *MSAsmStmt::getOutputExpr(unsigned i) {
|
|
|
|
return cast<Expr>(Exprs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *MSAsmStmt::getInputExpr(unsigned i) {
|
|
|
|
return cast<Expr>(Exprs[i + NumOutputs]);
|
|
|
|
}
|
|
|
|
void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
|
|
|
|
Exprs[i + NumOutputs] = E;
|
|
|
|
}
|
|
|
|
|
2010-02-03 10:09:59 +08:00
|
|
|
QualType CXXCatchStmt::getCaughtType() const {
|
|
|
|
if (ExceptionDecl)
|
|
|
|
return ExceptionDecl->getType();
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
2008-01-30 13:01:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Constructors
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc,
|
|
|
|
bool issimple, bool isvolatile, unsigned numoutputs,
|
|
|
|
unsigned numinputs, IdentifierInfo **names,
|
|
|
|
StringLiteral **constraints, Expr **exprs,
|
|
|
|
StringLiteral *asmstr, unsigned numclobbers,
|
|
|
|
StringLiteral **clobbers, SourceLocation rparenloc)
|
2012-08-28 03:38:01 +08:00
|
|
|
: AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
|
|
|
|
numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) {
|
2010-01-31 07:19:41 +08:00
|
|
|
|
2012-08-08 07:12:23 +08:00
|
|
|
unsigned NumExprs = NumOutputs + NumInputs;
|
|
|
|
|
2010-01-31 07:19:41 +08:00
|
|
|
Names = new (C) IdentifierInfo*[NumExprs];
|
|
|
|
std::copy(names, names + NumExprs, Names);
|
|
|
|
|
|
|
|
Exprs = new (C) Stmt*[NumExprs];
|
|
|
|
std::copy(exprs, exprs + NumExprs, Exprs);
|
|
|
|
|
|
|
|
Constraints = new (C) StringLiteral*[NumExprs];
|
|
|
|
std::copy(constraints, constraints + NumExprs, Constraints);
|
2008-08-06 07:15:29 +08:00
|
|
|
|
2010-01-31 07:19:41 +08:00
|
|
|
Clobbers = new (C) StringLiteral*[NumClobbers];
|
|
|
|
std::copy(clobbers, clobbers + NumClobbers, Clobbers);
|
2007-11-22 09:36:19 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
|
2012-08-16 08:06:53 +08:00
|
|
|
SourceLocation lbraceloc, bool issimple, bool isvolatile,
|
2012-10-17 05:55:39 +08:00
|
|
|
ArrayRef<Token> asmtoks, unsigned numoutputs,
|
2013-05-03 08:10:13 +08:00
|
|
|
unsigned numinputs,
|
2012-10-17 05:55:39 +08:00
|
|
|
ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs,
|
|
|
|
StringRef asmstr, ArrayRef<StringRef> clobbers,
|
|
|
|
SourceLocation endloc)
|
|
|
|
: AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
|
|
|
|
numinputs, clobbers.size()), LBraceLoc(lbraceloc),
|
2013-05-03 08:10:13 +08:00
|
|
|
EndLoc(endloc), NumAsmToks(asmtoks.size()) {
|
2012-08-16 08:06:53 +08:00
|
|
|
|
2013-05-03 08:10:13 +08:00
|
|
|
initialize(C, asmstr, asmtoks, constraints, exprs, clobbers);
|
|
|
|
}
|
2012-08-16 08:06:53 +08:00
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
|
2013-05-03 08:10:13 +08:00
|
|
|
size_t size = str.size();
|
|
|
|
char *buffer = new (C) char[size];
|
|
|
|
memcpy(buffer, str.data(), size);
|
|
|
|
return StringRef(buffer, size);
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,
|
2013-05-03 08:10:13 +08:00
|
|
|
ArrayRef<Token> asmtoks,
|
|
|
|
ArrayRef<StringRef> constraints,
|
|
|
|
ArrayRef<Expr*> exprs,
|
|
|
|
ArrayRef<StringRef> clobbers) {
|
|
|
|
assert(NumAsmToks == asmtoks.size());
|
|
|
|
assert(NumClobbers == clobbers.size());
|
|
|
|
|
|
|
|
unsigned NumExprs = exprs.size();
|
|
|
|
assert(NumExprs == NumOutputs + NumInputs);
|
|
|
|
assert(NumExprs == constraints.size());
|
|
|
|
|
|
|
|
AsmStr = copyIntoContext(C, asmstr);
|
2012-08-07 08:29:06 +08:00
|
|
|
|
2012-08-24 08:07:09 +08:00
|
|
|
Exprs = new (C) Stmt*[NumExprs];
|
2012-10-17 05:55:39 +08:00
|
|
|
for (unsigned i = 0, e = NumExprs; i != e; ++i)
|
|
|
|
Exprs[i] = exprs[i];
|
2012-08-24 08:07:09 +08:00
|
|
|
|
2012-08-07 08:29:06 +08:00
|
|
|
AsmToks = new (C) Token[NumAsmToks];
|
|
|
|
for (unsigned i = 0, e = NumAsmToks; i != e; ++i)
|
|
|
|
AsmToks[i] = asmtoks[i];
|
2012-08-09 03:48:07 +08:00
|
|
|
|
2012-08-29 04:28:20 +08:00
|
|
|
Constraints = new (C) StringRef[NumExprs];
|
|
|
|
for (unsigned i = 0, e = NumExprs; i != e; ++i) {
|
2013-05-03 08:10:13 +08:00
|
|
|
Constraints[i] = copyIntoContext(C, constraints[i]);
|
2012-08-29 04:28:20 +08:00
|
|
|
}
|
|
|
|
|
2012-08-11 05:36:25 +08:00
|
|
|
Clobbers = new (C) StringRef[NumClobbers];
|
2012-08-11 05:06:19 +08:00
|
|
|
for (unsigned i = 0, e = NumClobbers; i != e; ++i) {
|
|
|
|
// FIXME: Avoid the allocation/copy if at all possible.
|
2013-05-03 08:10:13 +08:00
|
|
|
Clobbers[i] = copyIntoContext(C, clobbers[i]);
|
2012-08-11 05:06:19 +08:00
|
|
|
}
|
2012-06-12 04:47:18 +08:00
|
|
|
}
|
|
|
|
|
2008-01-30 13:01:46 +08:00
|
|
|
ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
|
|
|
|
Stmt *Body, SourceLocation FCL,
|
2008-08-06 07:15:29 +08:00
|
|
|
SourceLocation RPL)
|
2008-01-30 13:01:46 +08:00
|
|
|
: Stmt(ObjCForCollectionStmtClass) {
|
|
|
|
SubExprs[ELEM] = Elem;
|
2013-09-03 22:41:16 +08:00
|
|
|
SubExprs[COLLECTION] = Collect;
|
2008-01-30 13:01:46 +08:00
|
|
|
SubExprs[BODY] = Body;
|
|
|
|
ForLoc = FCL;
|
|
|
|
RParenLoc = RPL;
|
|
|
|
}
|
|
|
|
|
2010-04-24 06:50:49 +08:00
|
|
|
ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
|
|
|
|
Stmt **CatchStmts, unsigned NumCatchStmts,
|
|
|
|
Stmt *atFinallyStmt)
|
|
|
|
: Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
|
|
|
|
NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != 0)
|
|
|
|
{
|
|
|
|
Stmt **Stmts = getStmts();
|
|
|
|
Stmts[0] = atTryStmt;
|
|
|
|
for (unsigned I = 0; I != NumCatchStmts; ++I)
|
|
|
|
Stmts[I + 1] = CatchStmts[I];
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2010-04-24 06:50:49 +08:00
|
|
|
if (HasFinally)
|
|
|
|
Stmts[NumCatchStmts + 1] = atFinallyStmt;
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context,
|
2012-08-08 07:12:23 +08:00
|
|
|
SourceLocation atTryLoc,
|
2010-04-24 06:50:49 +08:00
|
|
|
Stmt *atTryStmt,
|
2012-08-08 07:12:23 +08:00
|
|
|
Stmt **CatchStmts,
|
2010-04-24 06:50:49 +08:00
|
|
|
unsigned NumCatchStmts,
|
|
|
|
Stmt *atFinallyStmt) {
|
2012-08-08 07:12:23 +08:00
|
|
|
unsigned Size = sizeof(ObjCAtTryStmt) +
|
2010-04-24 06:50:49 +08:00
|
|
|
(1 + NumCatchStmts + (atFinallyStmt != 0)) * sizeof(Stmt *);
|
2010-10-30 13:14:06 +08:00
|
|
|
void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
|
2010-04-24 06:50:49 +08:00
|
|
|
return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
|
|
|
|
atFinallyStmt);
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
|
|
|
|
unsigned NumCatchStmts,
|
|
|
|
bool HasFinally) {
|
2012-08-08 07:12:23 +08:00
|
|
|
unsigned Size = sizeof(ObjCAtTryStmt) +
|
2010-04-24 06:50:49 +08:00
|
|
|
(1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
|
2010-10-30 13:14:06 +08:00
|
|
|
void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
|
2012-08-08 07:12:23 +08:00
|
|
|
return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
|
2010-04-24 06:50:49 +08:00
|
|
|
}
|
|
|
|
|
2012-12-25 22:51:39 +08:00
|
|
|
SourceLocation ObjCAtTryStmt::getLocEnd() const {
|
2010-04-24 06:50:49 +08:00
|
|
|
if (HasFinally)
|
2012-12-25 22:51:39 +08:00
|
|
|
return getFinallyStmt()->getLocEnd();
|
|
|
|
if (NumCatchStmts)
|
|
|
|
return getCatchStmt(NumCatchStmts - 1)->getLocEnd();
|
|
|
|
return getTryBody()->getLocEnd();
|
2008-01-30 13:01:46 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc,
|
2012-12-30 04:13:03 +08:00
|
|
|
Stmt *tryBlock, ArrayRef<Stmt*> handlers) {
|
2010-02-03 11:56:39 +08:00
|
|
|
std::size_t Size = sizeof(CXXTryStmt);
|
2012-12-30 04:13:03 +08:00
|
|
|
Size += ((handlers.size() + 1) * sizeof(Stmt));
|
2010-02-03 11:56:39 +08:00
|
|
|
|
2010-10-30 13:14:06 +08:00
|
|
|
void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
|
2012-12-30 04:13:03 +08:00
|
|
|
return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
|
2010-02-03 11:56:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
|
2010-07-23 00:03:56 +08:00
|
|
|
unsigned numHandlers) {
|
|
|
|
std::size_t Size = sizeof(CXXTryStmt);
|
|
|
|
Size += ((numHandlers + 1) * sizeof(Stmt));
|
|
|
|
|
2010-10-30 13:14:06 +08:00
|
|
|
void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
|
2010-07-23 00:03:56 +08:00
|
|
|
return new (Mem) CXXTryStmt(Empty, numHandlers);
|
|
|
|
}
|
|
|
|
|
2010-02-03 11:56:39 +08:00
|
|
|
CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
|
2012-12-30 04:13:03 +08:00
|
|
|
ArrayRef<Stmt*> handlers)
|
|
|
|
: Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
|
2010-02-03 11:56:39 +08:00
|
|
|
Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
|
2010-02-03 10:09:59 +08:00
|
|
|
Stmts[0] = tryBlock;
|
2012-12-30 04:13:03 +08:00
|
|
|
std::copy(handlers.begin(), handlers.end(), Stmts + 1);
|
2010-02-03 10:09:59 +08:00
|
|
|
}
|
|
|
|
|
2011-04-15 06:09:26 +08:00
|
|
|
CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt,
|
|
|
|
Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
|
|
|
|
Stmt *Body, SourceLocation FL,
|
|
|
|
SourceLocation CL, SourceLocation RPL)
|
|
|
|
: Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) {
|
|
|
|
SubExprs[RANGE] = Range;
|
|
|
|
SubExprs[BEGINEND] = BeginEndStmt;
|
2013-09-03 22:41:16 +08:00
|
|
|
SubExprs[COND] = Cond;
|
|
|
|
SubExprs[INC] = Inc;
|
2011-04-15 06:09:26 +08:00
|
|
|
SubExprs[LOOPVAR] = LoopVar;
|
|
|
|
SubExprs[BODY] = Body;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *CXXForRangeStmt::getRangeInit() {
|
|
|
|
DeclStmt *RangeStmt = getRangeStmt();
|
|
|
|
VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
|
|
|
|
assert(RangeDecl &&& "for-range should have a single var decl");
|
|
|
|
return RangeDecl->getInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Expr *CXXForRangeStmt::getRangeInit() const {
|
|
|
|
return const_cast<CXXForRangeStmt*>(this)->getRangeInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *CXXForRangeStmt::getLoopVariable() {
|
|
|
|
Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
|
|
|
|
assert(LV && "No loop variable in CXXForRangeStmt");
|
|
|
|
return cast<VarDecl>(LV);
|
|
|
|
}
|
|
|
|
|
|
|
|
const VarDecl *CXXForRangeStmt::getLoopVariable() const {
|
|
|
|
return const_cast<CXXForRangeStmt*>(this)->getLoopVariable();
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
|
2010-11-20 10:04:01 +08:00
|
|
|
Stmt *then, SourceLocation EL, Stmt *elsev)
|
|
|
|
: Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
|
2010-06-22 07:44:13 +08:00
|
|
|
{
|
|
|
|
setConditionVariable(C, var);
|
2013-09-03 22:41:16 +08:00
|
|
|
SubExprs[COND] = cond;
|
2010-06-22 07:44:13 +08:00
|
|
|
SubExprs[THEN] = then;
|
2012-08-08 07:12:23 +08:00
|
|
|
SubExprs[ELSE] = elsev;
|
2010-06-22 07:44:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *IfStmt::getConditionVariable() const {
|
|
|
|
if (!SubExprs[VAR])
|
|
|
|
return 0;
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2010-06-22 07:44:13 +08:00
|
|
|
DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
|
|
|
|
return cast<VarDecl>(DS->getSingleDecl());
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
|
2010-06-22 07:44:13 +08:00
|
|
|
if (!V) {
|
|
|
|
SubExprs[VAR] = 0;
|
|
|
|
return;
|
|
|
|
}
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2012-03-10 02:35:03 +08:00
|
|
|
SourceRange VarRange = V->getSourceRange();
|
|
|
|
SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
|
|
|
|
VarRange.getEnd());
|
2010-06-22 07:44:13 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
|
2012-08-08 07:12:23 +08:00
|
|
|
Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
|
2010-06-22 07:44:13 +08:00
|
|
|
SourceLocation RP)
|
2012-08-08 07:12:23 +08:00
|
|
|
: Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
|
2010-06-22 07:44:13 +08:00
|
|
|
{
|
|
|
|
SubExprs[INIT] = Init;
|
|
|
|
setConditionVariable(C, condVar);
|
2013-09-03 22:41:16 +08:00
|
|
|
SubExprs[COND] = Cond;
|
|
|
|
SubExprs[INC] = Inc;
|
2010-06-22 07:44:13 +08:00
|
|
|
SubExprs[BODY] = Body;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *ForStmt::getConditionVariable() const {
|
|
|
|
if (!SubExprs[CONDVAR])
|
|
|
|
return 0;
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2010-06-22 07:44:13 +08:00
|
|
|
DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
|
|
|
|
return cast<VarDecl>(DS->getSingleDecl());
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
|
2010-06-22 07:44:13 +08:00
|
|
|
if (!V) {
|
|
|
|
SubExprs[CONDVAR] = 0;
|
|
|
|
return;
|
|
|
|
}
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2012-03-10 02:35:03 +08:00
|
|
|
SourceRange VarRange = V->getSourceRange();
|
|
|
|
SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
|
|
|
|
VarRange.getEnd());
|
2010-06-22 07:44:13 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond)
|
2012-08-08 07:12:23 +08:00
|
|
|
: Stmt(SwitchStmtClass), FirstCase(0), AllEnumCasesCovered(0)
|
2010-06-22 07:44:13 +08:00
|
|
|
{
|
|
|
|
setConditionVariable(C, Var);
|
2013-09-03 22:41:16 +08:00
|
|
|
SubExprs[COND] = cond;
|
2010-06-22 07:44:13 +08:00
|
|
|
SubExprs[BODY] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *SwitchStmt::getConditionVariable() const {
|
|
|
|
if (!SubExprs[VAR])
|
|
|
|
return 0;
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2010-06-22 07:44:13 +08:00
|
|
|
DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
|
|
|
|
return cast<VarDecl>(DS->getSingleDecl());
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
|
2010-06-22 07:44:13 +08:00
|
|
|
if (!V) {
|
|
|
|
SubExprs[VAR] = 0;
|
|
|
|
return;
|
|
|
|
}
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2012-03-10 02:35:03 +08:00
|
|
|
SourceRange VarRange = V->getSourceRange();
|
|
|
|
SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
|
|
|
|
VarRange.getEnd());
|
2010-06-22 07:44:13 +08:00
|
|
|
}
|
|
|
|
|
2011-02-09 16:16:59 +08:00
|
|
|
Stmt *SwitchCase::getSubStmt() {
|
2011-02-28 08:18:06 +08:00
|
|
|
if (isa<CaseStmt>(this))
|
|
|
|
return cast<CaseStmt>(this)->getSubStmt();
|
2011-02-09 16:16:59 +08:00
|
|
|
return cast<DefaultStmt>(this)->getSubStmt();
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
|
2010-06-22 07:44:13 +08:00
|
|
|
SourceLocation WL)
|
2011-02-28 08:18:06 +08:00
|
|
|
: Stmt(WhileStmtClass) {
|
2010-06-22 07:44:13 +08:00
|
|
|
setConditionVariable(C, Var);
|
2013-09-03 22:41:16 +08:00
|
|
|
SubExprs[COND] = cond;
|
2010-06-22 07:44:13 +08:00
|
|
|
SubExprs[BODY] = body;
|
|
|
|
WhileLoc = WL;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *WhileStmt::getConditionVariable() const {
|
|
|
|
if (!SubExprs[VAR])
|
|
|
|
return 0;
|
2012-08-08 07:12:23 +08:00
|
|
|
|
2010-06-22 07:44:13 +08:00
|
|
|
DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
|
|
|
|
return cast<VarDecl>(DS->getSingleDecl());
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
|
2010-06-22 07:44:13 +08:00
|
|
|
if (!V) {
|
|
|
|
SubExprs[VAR] = 0;
|
|
|
|
return;
|
|
|
|
}
|
2012-03-10 02:35:03 +08:00
|
|
|
|
|
|
|
SourceRange VarRange = V->getSourceRange();
|
|
|
|
SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
|
|
|
|
VarRange.getEnd());
|
2010-06-22 07:44:13 +08:00
|
|
|
}
|
|
|
|
|
2007-08-25 05:09:09 +08:00
|
|
|
// IndirectGotoStmt
|
2011-02-17 15:39:24 +08:00
|
|
|
LabelDecl *IndirectGotoStmt::getConstantTarget() {
|
2010-10-28 16:53:48 +08:00
|
|
|
if (AddrLabelExpr *E =
|
|
|
|
dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
|
|
|
|
return E->getLabel();
|
|
|
|
return 0;
|
|
|
|
}
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// ReturnStmt
|
2008-06-17 11:11:08 +08:00
|
|
|
const Expr* ReturnStmt::getRetValue() const {
|
|
|
|
return cast_or_null<Expr>(RetExpr);
|
|
|
|
}
|
|
|
|
Expr* ReturnStmt::getRetValue() {
|
|
|
|
return cast_or_null<Expr>(RetExpr);
|
2007-08-25 05:09:09 +08:00
|
|
|
}
|
2011-04-28 09:08:34 +08:00
|
|
|
|
|
|
|
SEHTryStmt::SEHTryStmt(bool IsCXXTry,
|
|
|
|
SourceLocation TryLoc,
|
|
|
|
Stmt *TryBlock,
|
|
|
|
Stmt *Handler)
|
|
|
|
: Stmt(SEHTryStmtClass),
|
|
|
|
IsCXXTry(IsCXXTry),
|
|
|
|
TryLoc(TryLoc)
|
|
|
|
{
|
|
|
|
Children[TRY] = TryBlock;
|
|
|
|
Children[HANDLER] = Handler;
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
|
|
|
|
SourceLocation TryLoc, Stmt *TryBlock,
|
2011-04-28 09:08:34 +08:00
|
|
|
Stmt *Handler) {
|
|
|
|
return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
SEHExceptStmt* SEHTryStmt::getExceptHandler() const {
|
|
|
|
return dyn_cast<SEHExceptStmt>(getHandler());
|
|
|
|
}
|
|
|
|
|
|
|
|
SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const {
|
|
|
|
return dyn_cast<SEHFinallyStmt>(getHandler());
|
|
|
|
}
|
|
|
|
|
|
|
|
SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
|
|
|
|
Expr *FilterExpr,
|
|
|
|
Stmt *Block)
|
|
|
|
: Stmt(SEHExceptStmtClass),
|
|
|
|
Loc(Loc)
|
|
|
|
{
|
2013-09-03 22:41:16 +08:00
|
|
|
Children[FILTER_EXPR] = FilterExpr;
|
2011-04-28 09:08:34 +08:00
|
|
|
Children[BLOCK] = Block;
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc,
|
|
|
|
Expr *FilterExpr, Stmt *Block) {
|
2011-04-28 09:08:34 +08:00
|
|
|
return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
|
|
|
|
}
|
|
|
|
|
|
|
|
SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc,
|
|
|
|
Stmt *Block)
|
|
|
|
: Stmt(SEHFinallyStmtClass),
|
|
|
|
Loc(Loc),
|
|
|
|
Block(Block)
|
|
|
|
{}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc,
|
2011-04-28 09:08:34 +08:00
|
|
|
Stmt *Block) {
|
|
|
|
return new(C)SEHFinallyStmt(Loc,Block);
|
|
|
|
}
|
2013-04-17 02:53:08 +08:00
|
|
|
|
|
|
|
CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const {
|
|
|
|
unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
|
|
|
|
|
|
|
|
// Offset of the first Capture object.
|
|
|
|
unsigned FirstCaptureOffset =
|
|
|
|
llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
|
|
|
|
|
|
|
|
return reinterpret_cast<Capture *>(
|
|
|
|
reinterpret_cast<char *>(const_cast<CapturedStmt *>(this))
|
|
|
|
+ FirstCaptureOffset);
|
|
|
|
}
|
|
|
|
|
2013-05-04 11:59:06 +08:00
|
|
|
CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind,
|
|
|
|
ArrayRef<Capture> Captures,
|
2013-04-17 02:53:08 +08:00
|
|
|
ArrayRef<Expr *> CaptureInits,
|
2013-04-17 03:37:38 +08:00
|
|
|
CapturedDecl *CD,
|
2013-04-17 02:53:08 +08:00
|
|
|
RecordDecl *RD)
|
|
|
|
: Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
|
2013-05-04 11:59:06 +08:00
|
|
|
CapDeclAndKind(CD, Kind), TheRecordDecl(RD) {
|
2013-04-17 02:53:08 +08:00
|
|
|
assert( S && "null captured statement");
|
2013-04-17 03:37:38 +08:00
|
|
|
assert(CD && "null captured declaration for captured statement");
|
2013-04-17 02:53:08 +08:00
|
|
|
assert(RD && "null record declaration for captured statement");
|
|
|
|
|
|
|
|
// Copy initialization expressions.
|
|
|
|
Stmt **Stored = getStoredStmts();
|
|
|
|
for (unsigned I = 0, N = NumCaptures; I != N; ++I)
|
|
|
|
*Stored++ = CaptureInits[I];
|
|
|
|
|
|
|
|
// Copy the statement being captured.
|
|
|
|
*Stored = S;
|
|
|
|
|
|
|
|
// Copy all Capture objects.
|
|
|
|
Capture *Buffer = getStoredCaptures();
|
|
|
|
std::copy(Captures.begin(), Captures.end(), Buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
|
|
|
|
: Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
|
2013-05-04 11:59:06 +08:00
|
|
|
CapDeclAndKind(0, CR_Default), TheRecordDecl(0) {
|
2013-04-17 02:53:08 +08:00
|
|
|
getStoredStmts()[NumCaptures] = 0;
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S,
|
2013-05-04 11:59:06 +08:00
|
|
|
CapturedRegionKind Kind,
|
2013-04-17 02:53:08 +08:00
|
|
|
ArrayRef<Capture> Captures,
|
|
|
|
ArrayRef<Expr *> CaptureInits,
|
2013-04-17 03:37:38 +08:00
|
|
|
CapturedDecl *CD,
|
2013-04-17 02:53:08 +08:00
|
|
|
RecordDecl *RD) {
|
|
|
|
// The layout is
|
|
|
|
//
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
// | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture |
|
|
|
|
// ----------------^-------------------^----------------------
|
|
|
|
// getStoredStmts() getStoredCaptures()
|
|
|
|
//
|
|
|
|
// where S is the statement being captured.
|
|
|
|
//
|
|
|
|
assert(CaptureInits.size() == Captures.size() && "wrong number of arguments");
|
|
|
|
|
|
|
|
unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1);
|
|
|
|
if (!Captures.empty()) {
|
|
|
|
// Realign for the following Capture array.
|
|
|
|
Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
|
|
|
|
Size += sizeof(Capture) * Captures.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Mem = Context.Allocate(Size);
|
2013-05-04 11:59:06 +08:00
|
|
|
return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
|
2013-04-17 02:53:08 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context,
|
2013-04-17 02:53:08 +08:00
|
|
|
unsigned NumCaptures) {
|
|
|
|
unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
|
|
|
|
if (NumCaptures > 0) {
|
|
|
|
// Realign for the following Capture array.
|
|
|
|
Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
|
|
|
|
Size += sizeof(Capture) * NumCaptures;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Mem = Context.Allocate(Size);
|
|
|
|
return new (Mem) CapturedStmt(EmptyShell(), NumCaptures);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt::child_range CapturedStmt::children() {
|
2013-04-17 03:37:38 +08:00
|
|
|
// Children are captured field initilizers.
|
|
|
|
return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
|
2013-04-17 02:53:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
|
2013-05-04 03:20:19 +08:00
|
|
|
for (const_capture_iterator I = capture_begin(),
|
|
|
|
E = capture_end(); I != E; ++I) {
|
2013-05-16 14:20:58 +08:00
|
|
|
if (!I->capturesVariable())
|
2013-04-17 02:53:08 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// This does not handle variable redeclarations. This should be
|
|
|
|
// extended to capture variables with redeclarations, for example
|
|
|
|
// a thread-private variable in OpenMP.
|
|
|
|
if (I->getCapturedVar() == Var)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-19 11:13:43 +08:00
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
StmtRange OMPClause::children() {
|
|
|
|
switch(getClauseKind()) {
|
|
|
|
default : break;
|
|
|
|
#define OPENMP_CLAUSE(Name, Class) \
|
|
|
|
case OMPC_ ## Name : return static_cast<Class *>(this)->children();
|
|
|
|
#include "clang/Basic/OpenMPKinds.def"
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown OMPClause");
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
OMPPrivateClause *OMPPrivateClause::Create(const ASTContext &C,
|
2013-07-19 11:13:43 +08:00
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
ArrayRef<Expr *> VL) {
|
|
|
|
void *Mem = C.Allocate(sizeof(OMPPrivateClause) + sizeof(Expr *) * VL.size(),
|
|
|
|
llvm::alignOf<OMPPrivateClause>());
|
|
|
|
OMPPrivateClause *Clause = new (Mem) OMPPrivateClause(StartLoc, LParenLoc,
|
|
|
|
EndLoc, VL.size());
|
|
|
|
Clause->setVarRefs(VL);
|
|
|
|
return Clause;
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
|
2013-07-19 11:13:43 +08:00
|
|
|
unsigned N) {
|
|
|
|
void *Mem = C.Allocate(sizeof(OMPPrivateClause) + sizeof(Expr *) * N,
|
|
|
|
llvm::alignOf<OMPPrivateClause>());
|
|
|
|
return new (Mem) OMPPrivateClause(N);
|
|
|
|
}
|
|
|
|
|
2013-10-01 13:32:34 +08:00
|
|
|
OMPFirstprivateClause *OMPFirstprivateClause::Create(const ASTContext &C,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
ArrayRef<Expr *> VL) {
|
|
|
|
void *Mem = C.Allocate(sizeof(OMPFirstprivateClause) +
|
|
|
|
sizeof(Expr *) * VL.size(),
|
|
|
|
llvm::alignOf<OMPFirstprivateClause>());
|
|
|
|
OMPFirstprivateClause *Clause = new (Mem) OMPFirstprivateClause(StartLoc,
|
|
|
|
LParenLoc,
|
|
|
|
EndLoc,
|
|
|
|
VL.size());
|
|
|
|
Clause->setVarRefs(VL);
|
|
|
|
return Clause;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
|
|
|
|
unsigned N) {
|
|
|
|
void *Mem = C.Allocate(sizeof(OMPFirstprivateClause) + sizeof(Expr *) * N,
|
|
|
|
llvm::alignOf<OMPFirstprivateClause>());
|
|
|
|
return new (Mem) OMPFirstprivateClause(N);
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
ArrayRef<Expr *> VL) {
|
|
|
|
void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * VL.size(),
|
|
|
|
llvm::alignOf<OMPSharedClause>());
|
|
|
|
OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc,
|
|
|
|
EndLoc, VL.size());
|
|
|
|
Clause->setVarRefs(VL);
|
|
|
|
return Clause;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C,
|
|
|
|
unsigned N) {
|
|
|
|
void *Mem = C.Allocate(sizeof(OMPSharedClause) + sizeof(Expr *) * N,
|
|
|
|
llvm::alignOf<OMPSharedClause>());
|
|
|
|
return new (Mem) OMPSharedClause(N);
|
|
|
|
}
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) {
|
|
|
|
assert(Clauses.size() == this->Clauses.size() &&
|
|
|
|
"Number of clauses is not the same as the preallocated buffer");
|
|
|
|
std::copy(Clauses.begin(), Clauses.end(), this->Clauses.begin());
|
|
|
|
}
|
|
|
|
|
2013-08-21 12:01:01 +08:00
|
|
|
OMPParallelDirective *OMPParallelDirective::Create(
|
2013-08-22 13:28:54 +08:00
|
|
|
const ASTContext &C,
|
2013-08-21 12:01:01 +08:00
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AssociatedStmt) {
|
2013-07-19 11:13:43 +08:00
|
|
|
void *Mem = C.Allocate(sizeof(OMPParallelDirective) +
|
|
|
|
sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *),
|
|
|
|
llvm::alignOf<OMPParallelDirective>());
|
|
|
|
OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc,
|
|
|
|
Clauses.size());
|
|
|
|
Dir->setClauses(Clauses);
|
|
|
|
Dir->setAssociatedStmt(AssociatedStmt);
|
|
|
|
return Dir;
|
|
|
|
}
|
|
|
|
|
2013-08-22 13:28:54 +08:00
|
|
|
OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C,
|
2013-07-19 11:13:43 +08:00
|
|
|
unsigned N,
|
|
|
|
EmptyShell) {
|
|
|
|
void *Mem = C.Allocate(sizeof(OMPParallelDirective) +
|
|
|
|
sizeof(OMPClause *) * N + sizeof(Stmt *),
|
|
|
|
llvm::alignOf<OMPParallelDirective>());
|
|
|
|
return new (Mem) OMPParallelDirective(N);
|
|
|
|
}
|