[cfe-commits] r41636 - in /cfe/trunk: AST/Expr.cpp AST/StmtPrinter.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/AST/StmtNodes.def
Anders Carlsson
andersca at mac.com
Thu Aug 30 21:56:17 PDT 2007
Author: andersca
Date: Thu Aug 30 23:56:16 2007
New Revision: 41636
URL: http://llvm.org/viewvc/llvm-project?rev=41636&view=rev
Log:
Add InitListExpr class.
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/AST/StmtPrinter.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/StmtNodes.def
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=41636&r1=41635&r2=41636&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Thu Aug 30 23:56:16 2007
@@ -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; }
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=41636&r1=41635&r2=41636&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Thu Aug 30 23:56:16 2007
@@ -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) {
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=41636&r1=41635&r2=41636&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Thu Aug 30 23:56:16 2007
@@ -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.
}
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=41636&r1=41635&r2=41636&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Aug 30 23:56:16 2007
@@ -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 {
Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=41636&r1=41635&r2=41636&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Thu Aug 30 23:56:16 2007
@@ -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)
More information about the cfe-commits
mailing list