]> granicus.if.org Git - clang/commitdiff
New declarations/defs for Objc2's foreach-statement. This is work in progress.
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 2 Jan 2008 22:54:34 +0000 (22:54 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 2 Jan 2008 22:54:34 +0000 (22:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45511 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 0d1ec030b10f3f8de9a9bf6737cb077290c82124..95d077c2a496aad7afd5eb08a291ca34d87c964a 100644 (file)
@@ -183,6 +183,14 @@ Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; }
 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(); }
index fc28d06e6ecad6ebfde4c30196e346423e212316..099dd286eaf4050954a39bd51cdca5aba591b8ef 100644 (file)
@@ -296,6 +296,25 @@ void StmtPrinter::VisitForStmt(ForStmt *Node) {
   }
 }
 
+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";
 }
index d6f9dca49a840ec30f22c27a3af882cc9f04bd9e..53dabbd018a50c47bd60449004ad040de2ec39ed 100644 (file)
@@ -94,6 +94,9 @@ Stmt* Stmt::Create(Deserializer& D) {
 
     case ForStmtClass:
       return ForStmt::CreateImpl(D);
+      
+    case ObjcForCollectionStmtClass:
+      return ObjcForCollectionStmt::CreateImpl(D);
     
     case GotoStmtClass:
       return GotoStmt::CreateImpl(D);
@@ -560,6 +563,21 @@ ForStmt* ForStmt::CreateImpl(Deserializer& D) {
   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);
index 19bbfea62421d9f4bc48c0e940643c46fac933c3..e661e8775b2c47d8fa97e80f119683a3fd3d6fdb 100644 (file)
@@ -491,6 +491,16 @@ bool Parser::isObjCPropertyAttribute() {
   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.
index 04cfea6f07a0f1196e80ed56f7dd86b72f017628..4bcbfc7c21dc547d5513d07374ff25674d9c0b15 100644 (file)
@@ -254,6 +254,7 @@ void Parser::Initialize() {
     ObjcPropertyAttrs[objc_copy] = &PP.getIdentifierTable().get("copy");
     ObjcPropertyAttrs[objc_nonatomic] = 
                                   &PP.getIdentifierTable().get("nonatomic");
+    ObjCForCollectionInKW = &PP.getIdentifierTable().get("in");
   }
 }
 
index 0eff0a7a6b1760c9efea80915b1ff3cf517e7dba..58d61f61ccb31ed8189c0376d7990df431a56607 100644 (file)
@@ -573,6 +573,51 @@ public:
   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 {
index 27a5d1ea0fe7485aab4240dbfb3a44dc89f5820d..387ff651e1689691f07a024e88cf75d5c0bf64a5 100644 (file)
@@ -49,8 +49,10 @@ STMT(19, ObjcAtTryStmt        , Stmt)
 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.
index 20a836c7de9b564dd17e280e71102e34e102e7e6..40531b68b48f60db84b49c1f6ce33e891346815b 100644 (file)
@@ -292,6 +292,9 @@ private:
   };
   IdentifierInfo *ObjcPropertyAttrs[objc_NumAttrs];
   bool isObjCPropertyAttribute();
+  
+  IdentifierInfo *ObjCForCollectionInKW;
+  bool isObjCForCollectionInKW();
 
   TypeTy *ParseObjCTypeName(ObjcDeclSpec &DS);
   void ParseObjCMethodRequirement();