[cfe-commits] r45511 - in /cfe/trunk: AST/Stmt.cpp AST/StmtPrinter.cpp AST/StmtSerialization.cpp Parse/ParseObjc.cpp Parse/Parser.cpp include/clang/AST/Stmt.h include/clang/AST/StmtNodes.def include/clang/Parse/Parser.h

Fariborz Jahanian fjahanian at apple.com
Wed Jan 2 14:54:34 PST 2008


Author: fjahanian
Date: Wed Jan  2 16:54:34 2008
New Revision: 45511

URL: http://llvm.org/viewvc/llvm-project?rev=45511&view=rev
Log:
New declarations/defs for Objc2's foreach-statement. This is work in progress.

Modified:
    cfe/trunk/AST/Stmt.cpp
    cfe/trunk/AST/StmtPrinter.cpp
    cfe/trunk/AST/StmtSerialization.cpp
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Parse/Parser.cpp
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/include/clang/AST/StmtNodes.def
    cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Stmt.cpp?rev=45511&r1=45510&r2=45511&view=diff

==============================================================================
--- cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/trunk/AST/Stmt.cpp Wed Jan  2 16:54:34 2008
@@ -183,6 +183,14 @@
 Stmt::child_iterator ForStmt::child_begin() { return &SubExprs[0]; }
 Stmt::child_iterator ForStmt::child_end() { return &SubExprs[0]+END_EXPR; }
 
+// ObjcForCollectionStmt
+Stmt::child_iterator ObjcForCollectionStmt::child_begin() { 
+  return &SubExprs[0]; 
+}
+Stmt::child_iterator ObjcForCollectionStmt::child_end() { 
+  return &SubExprs[0]+END_EXPR; 
+}
+
 // GotoStmt
 Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); }
 Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); }

Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=45511&r1=45510&r2=45511&view=diff

==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Wed Jan  2 16:54:34 2008
@@ -296,6 +296,25 @@
   }
 }
 
+void StmtPrinter::VisitObjcForCollectionStmt(ObjcForCollectionStmt *Node) {
+  Indent() << "for (";
+  if (DeclStmt *DS = dyn_cast<DeclStmt>(Node->getElement()))
+    PrintRawDecl(DS->getDecl());
+  else
+    PrintExpr(cast<Expr>(Node->getElement()));
+  OS << " in ";
+  PrintExpr(Node->getCollection());
+  OS << ") ";
+  
+  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
+    PrintRawCompoundStmt(CS);
+    OS << "\n";
+  } else {
+    OS << "\n";
+    PrintStmt(Node->getBody());
+  }
+}
+
 void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
   Indent() << "goto " << Node->getLabel()->getName() << ";\n";
 }

Modified: cfe/trunk/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtSerialization.cpp?rev=45511&r1=45510&r2=45511&view=diff

==============================================================================
--- cfe/trunk/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/AST/StmtSerialization.cpp Wed Jan  2 16:54:34 2008
@@ -94,6 +94,9 @@
 
     case ForStmtClass:
       return ForStmt::CreateImpl(D);
+      
+    case ObjcForCollectionStmtClass:
+      return ObjcForCollectionStmt::CreateImpl(D);
     
     case GotoStmtClass:
       return GotoStmt::CreateImpl(D);
@@ -560,6 +563,21 @@
   return new ForStmt(Init,Cond,Inc,Body,ForLoc);
 }
 
+void ObjcForCollectionStmt::EmitImpl(Serializer& S) const {
+  S.Emit(ForCollectionLoc);
+  S.EmitOwnedPtr(getElement());
+  S.EmitOwnedPtr(getCollection());
+  S.EmitOwnedPtr(getBody());
+}
+
+ObjcForCollectionStmt* ObjcForCollectionStmt::CreateImpl(Deserializer& D) {
+  SourceLocation ForCollectionLoc = SourceLocation::ReadVal(D);
+  Stmt* Element = D.ReadOwnedPtr<Stmt>();
+  Expr* Collection = D.ReadOwnedPtr<Expr>();
+  Stmt* Body = D.ReadOwnedPtr<Stmt>();
+  return new ObjcForCollectionStmt(Element,Collection,Body,ForCollectionLoc);
+}
+
 void GotoStmt::EmitImpl(Serializer& S) const {
   S.Emit(GotoLoc);
   S.Emit(LabelLoc);

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=45511&r1=45510&r2=45511&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Wed Jan  2 16:54:34 2008
@@ -491,6 +491,16 @@
   return false;
 } 
 
+///  objc-for-collection-in: 'in'
+///
+bool Parser::isObjCForCollectionInKW() {
+  if (Tok.is(tok::identifier)) {
+    const IdentifierInfo *II = Tok.getIdentifierInfo();
+    return II == ObjCForCollectionInKW;
+  }
+  return false;
+}
+
 /// ParseObjcTypeQualifierList - This routine parses the objective-c's type
 /// qualifier list and builds their bitmask representation in the input
 /// argument.

Modified: cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/Parser.cpp?rev=45511&r1=45510&r2=45511&view=diff

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Wed Jan  2 16:54:34 2008
@@ -254,6 +254,7 @@
     ObjcPropertyAttrs[objc_copy] = &PP.getIdentifierTable().get("copy");
     ObjcPropertyAttrs[objc_nonatomic] = 
                                   &PP.getIdentifierTable().get("nonatomic");
+    ObjCForCollectionInKW = &PP.getIdentifierTable().get("in");
   }
 }
 

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=45511&r1=45510&r2=45511&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed Jan  2 16:54:34 2008
@@ -573,6 +573,51 @@
   static ForStmt* CreateImpl(llvm::Deserializer& D);
 };
 
+/// ObjcForCollectionStmt - This represents Objective-c's collection statement;
+/// represented as 'for (element 'in' collection-expression)' stmt.
+///
+class ObjcForCollectionStmt : public Stmt {
+  enum { ELEM, COLLECTION, BODY, END_EXPR };
+  Stmt* SubExprs[END_EXPR]; // SubExprs[ELEM] is an expression or declstmt.
+  SourceLocation ForCollectionLoc;
+public:
+  ObjcForCollectionStmt(Stmt *Elem, Expr *Collect, Stmt *Body, 
+                        SourceLocation FCL) 
+  : Stmt(ObjcForCollectionStmtClass) {
+    SubExprs[ELEM] = Elem;
+    SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect);
+    SubExprs[BODY] = Body;
+    ForCollectionLoc = FCL;
+  }
+    
+  Stmt *getElement() { return SubExprs[ELEM]; }
+  Expr *getCollection() { 
+    return reinterpret_cast<Expr*>(SubExprs[COLLECTION]); 
+  }
+  Stmt *getBody() { return SubExprs[BODY]; }
+    
+  const Stmt *getElement() const { return SubExprs[ELEM]; }
+  const Expr *getCollection() const { 
+    return reinterpret_cast<Expr*>(SubExprs[COLLECTION]);
+  }
+  const Stmt *getBody() const { return SubExprs[BODY]; }
+    
+  virtual SourceRange getSourceRange() const { 
+    return SourceRange(ForCollectionLoc, SubExprs[BODY]->getLocEnd()); 
+  }
+  static bool classof(const Stmt *T) { 
+    return T->getStmtClass() == ObjcForCollectionStmtClass; 
+  }
+  static bool classof(const ObjcForCollectionStmt *) { return true; }
+    
+  // Iterators
+  virtual child_iterator child_begin();
+  virtual child_iterator child_end();
+    
+  virtual void EmitImpl(llvm::Serializer& S) const;
+  static ObjcForCollectionStmt* CreateImpl(llvm::Deserializer& D);
+};
+  
 /// GotoStmt - This represents a direct goto.
 ///
 class GotoStmt : public Stmt {

Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=45511&r1=45510&r2=45511&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Wed Jan  2 16:54:34 2008
@@ -49,8 +49,10 @@
 STMT(20, ObjcAtCatchStmt      , Stmt)
 STMT(21, ObjcAtFinallyStmt    , Stmt)
 STMT(22, ObjcAtThrowStmt      , Stmt)
+// Obj-C2 statements
+STMT(23, ObjcForCollectionStmt, Stmt)
 
-LAST_STMT(22)
+LAST_STMT(23)
 
 FIRST_EXPR(31)
 // Expressions.

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=45511&r1=45510&r2=45511&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Jan  2 16:54:34 2008
@@ -292,6 +292,9 @@
   };
   IdentifierInfo *ObjcPropertyAttrs[objc_NumAttrs];
   bool isObjCPropertyAttribute();
+  
+  IdentifierInfo *ObjCForCollectionInKW;
+  bool isObjCForCollectionInKW();
 
   TypeTy *ParseObjCTypeName(ObjcDeclSpec &DS);
   void ParseObjCMethodRequirement();





More information about the cfe-commits mailing list