Add InitListExpr class.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41636 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Expr.cpp b/AST/Expr.cpp
index 3aed116..d664c46 100644
--- a/AST/Expr.cpp
+++ b/AST/Expr.cpp
@@ -194,6 +194,18 @@
}
}
+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 @@
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; }
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp
index a771b4c..6903080 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -550,6 +550,15 @@
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) {
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index a32e607..3b65ab2 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -640,12 +640,16 @@
}
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.
}
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 375252c..44b97a9 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -967,6 +967,43 @@
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 {
diff --git a/include/clang/AST/StmtNodes.def b/include/clang/AST/StmtNodes.def
index bc02277..54be80e 100644
--- a/include/clang/AST/StmtNodes.def
+++ b/include/clang/AST/StmtNodes.def
@@ -65,6 +65,7 @@
STMT(49, ImplicitCastExpr , Expr)
STMT(50, CompoundLiteralExpr , Expr)
STMT(51, OCUVectorElementExpr , Expr)
+STMT(52, InitListExpr , Expr)
// GNU Extensions.
STMT(55, AddrLabelExpr , Expr)