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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Stmt.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"
|
2009-04-26 09:32:48 +08:00
|
|
|
#include "clang/AST/StmtCXX.h"
|
|
|
|
#include "clang/AST/StmtObjC.h"
|
2008-12-23 03:15:10 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2009-02-06 09:42:09 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2009-03-11 07:51:40 +08:00
|
|
|
#include "clang/AST/ASTDiagnostic.h"
|
2009-08-24 21:25:12 +08:00
|
|
|
#include <cstdio>
|
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;
|
2007-08-25 09:55:00 +08:00
|
|
|
} StmtClassInfo[Stmt::lastExprConstant+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-02-03 08:55:45 +08:00
|
|
|
#define ABSTRACT_EXPR(CLASS, PARENT)
|
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);
|
2007-03-24 06:27:02 +08:00
|
|
|
#include "clang/AST/StmtNodes.def"
|
2008-08-06 07:15:29 +08:00
|
|
|
|
2007-08-25 09:42:24 +08:00
|
|
|
return StmtClassInfo[E];
|
|
|
|
}
|
|
|
|
|
2007-03-24 06:27:02 +08:00
|
|
|
const char *Stmt::getStmtClassName() const {
|
2009-08-08 09:41:12 +08:00
|
|
|
return getStmtInfoTableEntry((StmtClass)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;
|
|
|
|
fprintf(stderr, "*** Stmt/Expr Stats:\n");
|
2007-08-25 09:55:00 +08:00
|
|
|
for (int i = 0; i != Stmt::lastExprConstant+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
|
|
|
}
|
|
|
|
fprintf(stderr, " %d stmts/exprs total.\n", sum);
|
|
|
|
sum = 0;
|
2007-08-25 09:55:00 +08:00
|
|
|
for (int i = 0; i != Stmt::lastExprConstant+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;
|
2008-08-06 07:15:29 +08:00
|
|
|
fprintf(stderr, " %d %s, %d each (%d bytes)\n",
|
2007-08-25 09:42:24 +08:00
|
|
|
StmtClassInfo[i].Counter, StmtClassInfo[i].Name,
|
|
|
|
StmtClassInfo[i].Size,
|
|
|
|
StmtClassInfo[i].Counter*StmtClassInfo[i].Size);
|
|
|
|
sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
|
2007-05-24 05:48:04 +08:00
|
|
|
}
|
|
|
|
fprintf(stderr, "Total bytes = %d\n", sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stmt::addStmtClass(StmtClass s) {
|
2007-08-25 09:42:24 +08:00
|
|
|
++getStmtInfoTableEntry(s).Counter;
|
2007-05-24 05:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool StatSwitch = false;
|
|
|
|
|
2009-11-29 22:54:35 +08:00
|
|
|
bool Stmt::CollectingStats(bool Enable) {
|
|
|
|
if (Enable) StatSwitch = true;
|
2007-08-25 09:42:24 +08:00
|
|
|
return StatSwitch;
|
2007-05-24 05:48:04 +08:00
|
|
|
}
|
|
|
|
|
2009-04-17 08:04:06 +08:00
|
|
|
void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) {
|
|
|
|
if (this->Body)
|
|
|
|
C.Deallocate(Body);
|
|
|
|
this->NumStmts = NumStmts;
|
|
|
|
|
|
|
|
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 {
|
2009-10-19 04:26:12 +08:00
|
|
|
return getID()->getNameStart();
|
2007-05-28 14:56:27 +08:00
|
|
|
}
|
|
|
|
|
2007-09-01 07:49:30 +08:00
|
|
|
// This is defined here to avoid polluting Stmt.h with importing Expr.h
|
2008-08-06 07:15:29 +08:00
|
|
|
SourceRange ReturnStmt::getSourceRange() const {
|
2007-09-01 07:49:30 +08:00
|
|
|
if (RetExpr)
|
|
|
|
return SourceRange(RetLoc, RetExpr->getLocEnd());
|
|
|
|
else
|
|
|
|
return SourceRange(RetLoc);
|
|
|
|
}
|
|
|
|
|
2007-10-02 00:34:52 +08:00
|
|
|
bool Stmt::hasImplicitControlFlow() const {
|
|
|
|
switch (sClass) {
|
|
|
|
default:
|
|
|
|
return false;
|
2008-08-06 07:15:29 +08:00
|
|
|
|
2007-10-02 00:34:52 +08:00
|
|
|
case CallExprClass:
|
|
|
|
case ConditionalOperatorClass:
|
|
|
|
case ChooseExprClass:
|
|
|
|
case StmtExprClass:
|
|
|
|
case DeclStmtClass:
|
2008-08-06 07:15:29 +08:00
|
|
|
return true;
|
|
|
|
|
2007-10-02 00:34:52 +08:00
|
|
|
case Stmt::BinaryOperatorClass: {
|
|
|
|
const BinaryOperator* B = cast<BinaryOperator>(this);
|
|
|
|
if (B->isLogicalOp() || B->getOpcode() == BinaryOperator::Comma)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-10 12:59:06 +08:00
|
|
|
Expr *AsmStmt::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 '+').
|
2010-01-31 04:38:10 +08:00
|
|
|
llvm::StringRef AsmStmt::getOutputConstraint(unsigned i) const {
|
|
|
|
return getOutputConstraintLiteral(i)->getString();
|
2008-10-28 02:40:21 +08:00
|
|
|
}
|
2009-03-10 12:59:06 +08:00
|
|
|
|
2009-03-11 08:23:13 +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;
|
|
|
|
}
|
|
|
|
|
2009-03-10 12:59:06 +08:00
|
|
|
Expr *AsmStmt::getInputExpr(unsigned i) {
|
2008-10-28 02:40:21 +08:00
|
|
|
return cast<Expr>(Exprs[i + NumOutputs]);
|
|
|
|
}
|
2009-03-10 12:59:06 +08:00
|
|
|
|
|
|
|
/// getInputConstraint - Return the specified input constraint. Unlike output
|
|
|
|
/// constraints, these can be empty.
|
2010-01-31 04:38:10 +08:00
|
|
|
llvm::StringRef AsmStmt::getInputConstraint(unsigned i) const {
|
|
|
|
return getInputConstraintLiteral(i)->getString();
|
2008-10-28 02:40:21 +08:00
|
|
|
}
|
|
|
|
|
2009-03-10 14:33:24 +08:00
|
|
|
|
2010-01-31 04:38:10 +08:00
|
|
|
void AsmStmt::setOutputsAndInputsAndClobbers(ASTContext &C,
|
2010-01-31 06:25:16 +08:00
|
|
|
IdentifierInfo **Names,
|
2010-01-31 03:34:25 +08:00
|
|
|
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;
|
|
|
|
|
|
|
|
C.Deallocate(this->Names);
|
|
|
|
this->Names = new (C) IdentifierInfo*[NumExprs];
|
|
|
|
std::copy(Names, Names + NumExprs, this->Names);
|
|
|
|
|
|
|
|
C.Deallocate(this->Exprs);
|
|
|
|
this->Exprs = new (C) Stmt*[NumExprs];
|
|
|
|
std::copy(Exprs, Exprs + NumExprs, this->Exprs);
|
|
|
|
|
|
|
|
C.Deallocate(this->Constraints);
|
|
|
|
this->Constraints = new (C) StringLiteral*[NumExprs];
|
|
|
|
std::copy(Constraints, Constraints + NumExprs, this->Constraints);
|
2010-01-31 03:34:25 +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.
|
2010-01-31 04:38:10 +08:00
|
|
|
int AsmStmt::getNamedOperand(llvm::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.
|
2009-03-11 07:41:04 +08:00
|
|
|
unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&Pieces,
|
|
|
|
ASTContext &C, unsigned &DiagOffs) const {
|
2009-03-11 07:21:44 +08:00
|
|
|
const char *StrStart = getAsmString()->getStrData();
|
|
|
|
const char *StrEnd = StrStart + getAsmString()->getByteLength();
|
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
|
|
|
|
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++;
|
2009-03-11 07:21:44 +08:00
|
|
|
if (CurChar == '$') {
|
|
|
|
CurStringPiece += "$$";
|
|
|
|
continue;
|
|
|
|
} else if (CurChar != '%') {
|
|
|
|
CurStringPiece += CurChar;
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +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';
|
|
|
|
if (isalpha(EscapedChar)) {
|
|
|
|
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
|
|
|
|
2009-03-11 07:21:44 +08:00
|
|
|
if (isdigit(EscapedChar)) {
|
|
|
|
// %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;
|
|
|
|
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
|
|
|
|
2010-01-31 04:48:08 +08:00
|
|
|
llvm::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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-31 07:19:41 +08:00
|
|
|
AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
|
|
|
|
bool isvolatile, bool msasm,
|
|
|
|
unsigned numoutputs, unsigned numinputs,
|
2010-01-31 06:25:16 +08:00
|
|
|
IdentifierInfo **names, StringLiteral **constraints,
|
2008-01-30 13:01:46 +08:00
|
|
|
Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
|
|
|
|
StringLiteral **clobbers, SourceLocation rparenloc)
|
2007-11-22 09:36:19 +08:00
|
|
|
: Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
|
2010-01-05 06:37:17 +08:00
|
|
|
, IsSimple(issimple), IsVolatile(isvolatile), MSAsm(msasm)
|
2010-01-31 07:19:41 +08:00
|
|
|
, NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) {
|
|
|
|
|
|
|
|
unsigned NumExprs = NumOutputs +NumInputs;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect);
|
|
|
|
SubExprs[BODY] = Body;
|
|
|
|
ForLoc = FCL;
|
|
|
|
RParenLoc = RPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-06 07:15:29 +08:00
|
|
|
ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc,
|
|
|
|
SourceLocation rparenloc,
|
2009-03-04 03:52:17 +08:00
|
|
|
ParmVarDecl *catchVarDecl, Stmt *atCatchStmt,
|
2008-01-30 13:01:46 +08:00
|
|
|
Stmt *atCatchList)
|
|
|
|
: Stmt(ObjCAtCatchStmtClass) {
|
2009-03-04 03:52:17 +08:00
|
|
|
ExceptionDecl = catchVarDecl;
|
2008-01-30 13:01:46 +08:00
|
|
|
SubExprs[BODY] = atCatchStmt;
|
2008-05-25 12:34:57 +08:00
|
|
|
SubExprs[NEXT_CATCH] = NULL;
|
2009-03-01 12:28:32 +08:00
|
|
|
// FIXME: O(N^2) in number of catch blocks.
|
2008-05-25 12:34:57 +08:00
|
|
|
if (atCatchList) {
|
2008-02-02 05:28:59 +08:00
|
|
|
ObjCAtCatchStmt *AtCatchList = static_cast<ObjCAtCatchStmt*>(atCatchList);
|
|
|
|
|
2008-08-06 07:15:29 +08:00
|
|
|
while (ObjCAtCatchStmt* NextCatch = AtCatchList->getNextCatchStmt())
|
2008-02-02 05:28:59 +08:00
|
|
|
AtCatchList = NextCatch;
|
2008-08-06 07:15:29 +08:00
|
|
|
|
2008-02-02 05:28:59 +08:00
|
|
|
AtCatchList->SubExprs[NEXT_CATCH] = this;
|
2008-01-30 13:01:46 +08:00
|
|
|
}
|
|
|
|
AtCatchLoc = atCatchLoc;
|
|
|
|
RParenLoc = rparenloc;
|
|
|
|
}
|
|
|
|
|
2010-02-03 11:56:39 +08:00
|
|
|
CXXTryStmt *CXXTryStmt::Create(ASTContext &C, SourceLocation tryLoc,
|
|
|
|
Stmt *tryBlock, Stmt **handlers,
|
|
|
|
unsigned numHandlers) {
|
|
|
|
std::size_t Size = sizeof(CXXTryStmt);
|
|
|
|
Size += ((numHandlers + 1) * sizeof(Stmt));
|
|
|
|
|
|
|
|
void *Mem = C.Allocate(Size, llvm::alignof<CXXTryStmt>());
|
|
|
|
return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers, numHandlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
|
2010-02-03 10:09:59 +08:00
|
|
|
Stmt **handlers, unsigned numHandlers)
|
|
|
|
: Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(numHandlers) {
|
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;
|
|
|
|
std::copy(handlers, handlers + NumHandlers, Stmts + 1);
|
|
|
|
}
|
|
|
|
|
2007-08-25 05:09:09 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-12-24 09:48:39 +08:00
|
|
|
// AST Destruction.
|
2007-08-25 05:09:09 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-12-24 09:48:39 +08:00
|
|
|
void Stmt::DestroyChildren(ASTContext &C) {
|
|
|
|
for (child_iterator I = child_begin(), E = child_end(); I !=E; )
|
|
|
|
if (Stmt* Child = *I++) Child->Destroy(C);
|
2008-08-06 04:46:55 +08:00
|
|
|
}
|
|
|
|
|
2009-12-24 09:48:39 +08:00
|
|
|
static void BranchDestroy(ASTContext &C, Stmt *S, Stmt **SubExprs,
|
|
|
|
unsigned NumExprs) {
|
|
|
|
// We do not use child_iterator here because that will include
|
|
|
|
// the expressions referenced by the condition variable.
|
|
|
|
for (Stmt **I = SubExprs, **E = SubExprs + NumExprs; I != E; ++I)
|
|
|
|
if (Stmt *Child = *I) Child->Destroy(C);
|
|
|
|
|
|
|
|
S->~Stmt();
|
|
|
|
C.Deallocate((void *) S);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stmt::DoDestroy(ASTContext &C) {
|
|
|
|
DestroyChildren(C);
|
|
|
|
this->~Stmt();
|
|
|
|
C.Deallocate((void *)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXXCatchStmt::DoDestroy(ASTContext& C) {
|
|
|
|
if (ExceptionDecl)
|
|
|
|
ExceptionDecl->Destroy(C);
|
|
|
|
Stmt::DoDestroy(C);
|
2008-10-07 04:54:44 +08:00
|
|
|
}
|
|
|
|
|
2009-12-23 16:56:00 +08:00
|
|
|
void DeclStmt::DoDestroy(ASTContext &C) {
|
|
|
|
// Don't use StmtIterator to iterate over the Decls, as that can recurse
|
|
|
|
// into VLA size expressions (which are owned by the VLA). Further, Decls
|
|
|
|
// are owned by the DeclContext, and will be destroyed with them.
|
|
|
|
if (DG.isDeclGroup())
|
|
|
|
DG.getDeclGroup().Destroy(C);
|
|
|
|
}
|
|
|
|
|
2009-12-24 09:48:39 +08:00
|
|
|
void IfStmt::DoDestroy(ASTContext &C) {
|
|
|
|
BranchDestroy(C, this, SubExprs, END_EXPR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForStmt::DoDestroy(ASTContext &C) {
|
|
|
|
BranchDestroy(C, this, SubExprs, END_EXPR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchStmt::DoDestroy(ASTContext &C) {
|
|
|
|
// Destroy the SwitchCase statements in this switch. In the normal
|
|
|
|
// case, this loop will merely decrement the reference counts from
|
|
|
|
// the Retain() calls in addSwitchCase();
|
|
|
|
SwitchCase *SC = FirstCase;
|
|
|
|
while (SC) {
|
|
|
|
SwitchCase *Next = SC->getNextSwitchCase();
|
|
|
|
SC->Destroy(C);
|
|
|
|
SC = Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
BranchDestroy(C, this, SubExprs, END_EXPR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WhileStmt::DoDestroy(ASTContext &C) {
|
|
|
|
BranchDestroy(C, this, SubExprs, END_EXPR);
|
|
|
|
}
|
|
|
|
|
2010-01-31 07:19:41 +08:00
|
|
|
void AsmStmt::DoDestroy(ASTContext &C) {
|
|
|
|
DestroyChildren(C);
|
|
|
|
|
|
|
|
C.Deallocate(Names);
|
|
|
|
C.Deallocate(Constraints);
|
|
|
|
C.Deallocate(Exprs);
|
|
|
|
C.Deallocate(Clobbers);
|
|
|
|
|
2010-01-31 17:01:55 +08:00
|
|
|
this->~AsmStmt();
|
2010-01-31 07:19:41 +08:00
|
|
|
C.Deallocate((void *)this);
|
|
|
|
}
|
|
|
|
|
2009-12-24 09:48:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Child Iterators for iterating over subexpressions/substatements
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// DeclStmt
|
|
|
|
Stmt::child_iterator DeclStmt::child_begin() {
|
|
|
|
return StmtIterator(DG.begin(), DG.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt::child_iterator DeclStmt::child_end() {
|
|
|
|
return StmtIterator(DG.end(), DG.end());
|
|
|
|
}
|
|
|
|
|
2007-08-25 05:09:09 +08:00
|
|
|
// NullStmt
|
2007-10-19 07:28:49 +08:00
|
|
|
Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
|
|
|
|
Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// CompoundStmt
|
|
|
|
Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; }
|
2009-02-07 09:47:29 +08:00
|
|
|
Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+NumStmts; }
|
2007-08-25 05:09:09 +08:00
|
|
|
|
2007-08-31 00:50:46 +08:00
|
|
|
// CaseStmt
|
|
|
|
Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; }
|
|
|
|
Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; }
|
|
|
|
|
|
|
|
// DefaultStmt
|
|
|
|
Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; }
|
|
|
|
Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; }
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// LabelStmt
|
|
|
|
Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; }
|
2007-08-30 08:53:54 +08:00
|
|
|
Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; }
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// IfStmt
|
2009-12-24 07:38:34 +08:00
|
|
|
Stmt::child_iterator IfStmt::child_begin() {
|
|
|
|
return child_iterator(Var, &SubExprs[0]);
|
|
|
|
}
|
|
|
|
Stmt::child_iterator IfStmt::child_end() {
|
|
|
|
return child_iterator(0, &SubExprs[0]+END_EXPR);
|
|
|
|
}
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// SwitchStmt
|
2009-12-24 08:39:05 +08:00
|
|
|
Stmt::child_iterator SwitchStmt::child_begin() {
|
|
|
|
return child_iterator(Var, &SubExprs[0]);
|
|
|
|
}
|
|
|
|
Stmt::child_iterator SwitchStmt::child_end() {
|
|
|
|
return child_iterator(0, &SubExprs[0]+END_EXPR);
|
|
|
|
}
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// WhileStmt
|
2009-12-24 08:54:19 +08:00
|
|
|
Stmt::child_iterator WhileStmt::child_begin() {
|
|
|
|
return child_iterator(Var, &SubExprs[0]);
|
|
|
|
}
|
|
|
|
Stmt::child_iterator WhileStmt::child_end() {
|
|
|
|
return child_iterator(0, &SubExprs[0]+END_EXPR);
|
|
|
|
}
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// DoStmt
|
|
|
|
Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; }
|
|
|
|
Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; }
|
|
|
|
|
|
|
|
// ForStmt
|
2009-12-24 09:48:39 +08:00
|
|
|
Stmt::child_iterator ForStmt::child_begin() {
|
|
|
|
return child_iterator(CondVar, &SubExprs[0]);
|
|
|
|
}
|
|
|
|
Stmt::child_iterator ForStmt::child_end() {
|
2009-12-24 09:59:46 +08:00
|
|
|
return child_iterator(0, &SubExprs[0]+END_EXPR);
|
2009-12-24 09:48:39 +08:00
|
|
|
}
|
2007-08-25 05:09:09 +08:00
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
// ObjCForCollectionStmt
|
2008-08-06 07:15:29 +08:00
|
|
|
Stmt::child_iterator ObjCForCollectionStmt::child_begin() {
|
|
|
|
return &SubExprs[0];
|
2008-01-03 06:54:34 +08:00
|
|
|
}
|
2008-08-06 07:15:29 +08:00
|
|
|
Stmt::child_iterator ObjCForCollectionStmt::child_end() {
|
|
|
|
return &SubExprs[0]+END_EXPR;
|
2008-01-03 06:54:34 +08:00
|
|
|
}
|
|
|
|
|
2007-08-25 05:09:09 +08:00
|
|
|
// GotoStmt
|
2007-10-19 07:28:49 +08:00
|
|
|
Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); }
|
|
|
|
Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); }
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// IndirectGotoStmt
|
2008-06-17 11:11:08 +08:00
|
|
|
Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); }
|
|
|
|
const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); }
|
2007-08-25 05:09:09 +08:00
|
|
|
|
2008-06-17 11:11:08 +08:00
|
|
|
Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; }
|
|
|
|
Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; }
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// ContinueStmt
|
2007-10-19 07:28:49 +08:00
|
|
|
Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); }
|
|
|
|
Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); }
|
2007-08-25 05:09:09 +08:00
|
|
|
|
|
|
|
// BreakStmt
|
2007-10-19 07:28:49 +08:00
|
|
|
Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); }
|
|
|
|
Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); }
|
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
|
|
|
}
|
|
|
|
|
2008-06-17 11:11:08 +08:00
|
|
|
Stmt::child_iterator ReturnStmt::child_begin() {
|
|
|
|
return &RetExpr;
|
|
|
|
}
|
|
|
|
Stmt::child_iterator ReturnStmt::child_end() {
|
|
|
|
return RetExpr ? &RetExpr+1 : &RetExpr;
|
2007-08-28 04:58:16 +08:00
|
|
|
}
|
2007-08-25 05:09:09 +08:00
|
|
|
|
2007-10-29 12:04:16 +08:00
|
|
|
// AsmStmt
|
2009-09-09 23:08:12 +08:00
|
|
|
Stmt::child_iterator AsmStmt::child_begin() {
|
2010-01-31 07:19:41 +08:00
|
|
|
return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0];
|
2008-10-28 02:40:21 +08:00
|
|
|
}
|
|
|
|
Stmt::child_iterator AsmStmt::child_end() {
|
2010-01-31 07:19:41 +08:00
|
|
|
return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0] + NumOutputs + NumInputs;
|
2008-10-28 02:40:21 +08:00
|
|
|
}
|
2007-10-29 12:04:16 +08:00
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
// ObjCAtCatchStmt
|
|
|
|
Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &SubExprs[0]; }
|
2008-08-06 07:15:29 +08:00
|
|
|
Stmt::child_iterator ObjCAtCatchStmt::child_end() {
|
|
|
|
return &SubExprs[0]+END_EXPR;
|
2007-11-02 07:59:59 +08:00
|
|
|
}
|
2007-11-02 05:12:44 +08:00
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
// ObjCAtFinallyStmt
|
|
|
|
Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; }
|
|
|
|
Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; }
|
2007-11-02 05:12:44 +08:00
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
// ObjCAtTryStmt
|
|
|
|
Stmt::child_iterator ObjCAtTryStmt::child_begin() { return &SubStmts[0]; }
|
2008-08-06 07:15:29 +08:00
|
|
|
Stmt::child_iterator ObjCAtTryStmt::child_end() {
|
|
|
|
return &SubStmts[0]+END_EXPR;
|
2007-11-02 07:59:59 +08:00
|
|
|
}
|
2007-11-02 05:12:44 +08:00
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
// ObjCAtThrowStmt
|
|
|
|
Stmt::child_iterator ObjCAtThrowStmt::child_begin() {
|
2007-11-07 10:00:49 +08:00
|
|
|
return &Throw;
|
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
Stmt::child_iterator ObjCAtThrowStmt::child_end() {
|
2007-11-07 10:00:49 +08:00
|
|
|
return &Throw+1;
|
|
|
|
}
|
2008-01-30 03:14:59 +08:00
|
|
|
|
|
|
|
// ObjCAtSynchronizedStmt
|
|
|
|
Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() {
|
2008-01-30 06:59:37 +08:00
|
|
|
return &SubStmts[0];
|
2008-01-30 03:14:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() {
|
2008-01-30 06:59:37 +08:00
|
|
|
return &SubStmts[0]+END_EXPR;
|
2008-01-30 03:14:59 +08:00
|
|
|
}
|
|
|
|
|
2008-12-23 03:15:10 +08:00
|
|
|
// CXXCatchStmt
|
|
|
|
Stmt::child_iterator CXXCatchStmt::child_begin() {
|
|
|
|
return &HandlerBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt::child_iterator CXXCatchStmt::child_end() {
|
|
|
|
return &HandlerBlock + 1;
|
|
|
|
}
|
|
|
|
|
2008-12-23 05:35:02 +08:00
|
|
|
// CXXTryStmt
|
2010-02-03 11:56:39 +08:00
|
|
|
Stmt::child_iterator CXXTryStmt::child_begin() {
|
|
|
|
return reinterpret_cast<Stmt **>(this + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt::child_iterator CXXTryStmt::child_end() {
|
|
|
|
return reinterpret_cast<Stmt **>(this + 1) + NumHandlers + 1;
|
|
|
|
}
|