mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 03:56:16 +08:00
Add InitListExpr class.
llvm-svn: 41636
This commit is contained in:
@@ -194,6 +194,18 @@ const char *BinaryOperator::getOpcodeStr(Opcode Op) {
|
||||
}
|
||||
}
|
||||
|
||||
InitListExpr::InitListExpr(SourceLocation lbraceloc,
|
||||
Expr **initexprs, unsigned numinits,
|
||||
SourceLocation rbraceloc)
|
||||
: Expr(InitListExprClass, QualType())
|
||||
, NumInits(numinits)
|
||||
, LBraceLoc(lbraceloc)
|
||||
, RBraceLoc(rbraceloc)
|
||||
{
|
||||
InitExprs = new Expr*[numinits];
|
||||
for (unsigned i = 0; i != numinits; i++)
|
||||
InitExprs[i] = initexprs[i];
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Generic Expression Routines
|
||||
@@ -871,6 +883,14 @@ Stmt::child_iterator ChooseExpr::child_end() {
|
||||
return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
|
||||
}
|
||||
|
||||
// InitListExpr
|
||||
Stmt::child_iterator InitListExpr::child_begin() {
|
||||
return reinterpret_cast<Stmt**>(&InitExprs[0]);
|
||||
}
|
||||
Stmt::child_iterator InitListExpr::child_end() {
|
||||
return reinterpret_cast<Stmt**>(&InitExprs[NumInits]);
|
||||
}
|
||||
|
||||
// ObjCStringLiteral
|
||||
Stmt::child_iterator ObjCStringLiteral::child_begin() { return NULL; }
|
||||
Stmt::child_iterator ObjCStringLiteral::child_end() { return NULL; }
|
||||
|
||||
@@ -550,6 +550,15 @@ void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
|
||||
OS << ")";
|
||||
}
|
||||
|
||||
void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
|
||||
OS << "{ ";
|
||||
for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
|
||||
if (i) OS << ", ";
|
||||
PrintExpr(Node->getInit(i));
|
||||
}
|
||||
OS << " }";
|
||||
}
|
||||
|
||||
// C++
|
||||
|
||||
void StmtPrinter::VisitCXXCastExpr(CXXCastExpr *Node) {
|
||||
|
||||
@@ -640,12 +640,16 @@ ParseCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
|
||||
}
|
||||
|
||||
Action::ExprResult Sema::
|
||||
ParseInitList(SourceLocation LParenLoc, ExprTy **InitList, unsigned NumInit,
|
||||
SourceLocation RParenLoc) {
|
||||
ParseInitList(SourceLocation LBraceLoc, ExprTy **initlist, unsigned NumInit,
|
||||
SourceLocation RBraceLoc) {
|
||||
// Expr **InitList = reinterpret_cast<Expr**>(initlist);
|
||||
|
||||
// FIXME: add semantic analysis (C99 6.7.8). This involves
|
||||
// knowledge of the object being intialized. As a result, the code for
|
||||
// doing the semantic analysis will likely be located elsewhere (i.e. in
|
||||
// consumers of InitListExpr (e.g. ParseDeclarator, ParseCompoundLiteral).
|
||||
|
||||
//return new InitListExpr(LBraceLoc, InitList, NumInit, RBraceLoc);
|
||||
return false; // FIXME instantiate an InitListExpr.
|
||||
}
|
||||
|
||||
|
||||
@@ -967,6 +967,43 @@ public:
|
||||
virtual child_iterator child_end();
|
||||
};
|
||||
|
||||
/// InitListExpr, used for struct and array initializers.
|
||||
class InitListExpr : public Expr {
|
||||
Expr **InitExprs;
|
||||
unsigned NumInits;
|
||||
SourceLocation LBraceLoc, RBraceLoc;
|
||||
public:
|
||||
InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
|
||||
SourceLocation rbraceloc);
|
||||
~InitListExpr() {
|
||||
delete [] InitExprs;
|
||||
}
|
||||
|
||||
unsigned getNumInits() const { return NumInits; }
|
||||
|
||||
const Expr* getInit(unsigned Init) const {
|
||||
assert(Init < NumInits && "Initializer access out of range!");
|
||||
return InitExprs[Init];
|
||||
}
|
||||
|
||||
Expr* getInit(unsigned Init) {
|
||||
assert(Init < NumInits && "Initializer access out of range!");
|
||||
return InitExprs[Init];
|
||||
}
|
||||
|
||||
virtual SourceRange getSourceRange() const {
|
||||
return SourceRange(LBraceLoc, RBraceLoc);
|
||||
}
|
||||
static bool classof(const Stmt *T) {
|
||||
return T->getStmtClass() == InitListExprClass;
|
||||
}
|
||||
static bool classof(const InitListExpr *) { return true; }
|
||||
|
||||
// Iterators
|
||||
virtual child_iterator child_begin();
|
||||
virtual child_iterator child_end();
|
||||
};
|
||||
|
||||
/// ObjCStringLiteral, used for Objective-C string literals
|
||||
/// i.e. @"foo".
|
||||
class ObjCStringLiteral : public Expr {
|
||||
|
||||
@@ -65,6 +65,7 @@ STMT(48, ConditionalOperator , Expr)
|
||||
STMT(49, ImplicitCastExpr , Expr)
|
||||
STMT(50, CompoundLiteralExpr , Expr)
|
||||
STMT(51, OCUVectorElementExpr , Expr)
|
||||
STMT(52, InitListExpr , Expr)
|
||||
|
||||
// GNU Extensions.
|
||||
STMT(55, AddrLabelExpr , Expr)
|
||||
|
||||
Reference in New Issue
Block a user