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(); }
}
}
+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";
}
case ForStmtClass:
return ForStmt::CreateImpl(D);
+
+ case ObjcForCollectionStmtClass:
+ return ObjcForCollectionStmt::CreateImpl(D);
case GotoStmtClass:
return GotoStmt::CreateImpl(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);
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.
ObjcPropertyAttrs[objc_copy] = &PP.getIdentifierTable().get("copy");
ObjcPropertyAttrs[objc_nonatomic] =
&PP.getIdentifierTable().get("nonatomic");
+ ObjCForCollectionInKW = &PP.getIdentifierTable().get("in");
}
}
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 {
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.
};
IdentifierInfo *ObjcPropertyAttrs[objc_NumAttrs];
bool isObjCPropertyAttribute();
+
+ IdentifierInfo *ObjCForCollectionInKW;
+ bool isObjCForCollectionInKW();
TypeTy *ParseObjCTypeName(ObjcDeclSpec &DS);
void ParseObjCMethodRequirement();