]> granicus.if.org Git - clang/commitdiff
Add InitListExpr class.
authorAnders Carlsson <andersca@mac.com>
Fri, 31 Aug 2007 04:56:16 +0000 (04:56 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 31 Aug 2007 04:56:16 +0000 (04:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41636 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
AST/StmtPrinter.cpp
Sema/SemaExpr.cpp
include/clang/AST/Expr.h
include/clang/AST/StmtNodes.def

index 3aed116c763399bf081fa0513474fe0c1dcbf0e8..d664c46081ea883610ae8a3892a3c85bd4d12fc8 100644 (file)
@@ -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; }
index a771b4ce1a72120c0b7261bbe707e8708684ccc5..69030804225dbeb8d8346445e4fda146f7cc725f 100644 (file)
@@ -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) {
index a32e607aa4103550bb9df6354f95f193ded69ad9..3b65ab2bc1ded1ad0007aebfd69e39ba5d82c18e 100644 (file)
@@ -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.
 }
 
index 375252c6c9ac1dde6c1c0caec488e640c9209db9..44b97a942fe80ac3a03a255c8c1d35db61e5cb4f 100644 (file)
@@ -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 {
index bc022775a02ebb78149e2af05ba9a2341779ff83..54be80e040343bca5e8c93e2fb033cf2a0fbe204 100644 (file)
@@ -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)