From: Fariborz Jahanian Date: Tue, 29 Jan 2008 19:14:59 +0000 (+0000) Subject: AST for @synchronized. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fa3ee8e6776634caf064ba5928ca7699d317a280;p=clang AST for @synchronized. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46524 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp index 8d4f6133ef..0f4936b1bb 100644 --- a/AST/Stmt.cpp +++ b/AST/Stmt.cpp @@ -249,3 +249,13 @@ Stmt::child_iterator ObjCAtThrowStmt::child_begin() { Stmt::child_iterator ObjCAtThrowStmt::child_end() { return &Throw+1; } + +// ObjCAtSynchronizedStmt +Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() { + return &SynchBody; +} + +Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() { + return &SynchBody+1; +} + diff --git a/AST/StmtSerialization.cpp b/AST/StmtSerialization.cpp index 545813cfba..8394dc6ea0 100644 --- a/AST/StmtSerialization.cpp +++ b/AST/StmtSerialization.cpp @@ -893,6 +893,20 @@ ObjCAtThrowStmt* ObjCAtThrowStmt::CreateImpl(Deserializer& D) { Stmt* Throw = D.ReadOwnedPtr(); return new ObjCAtThrowStmt(L,Throw); } + +void ObjCAtSynchronizedStmt::EmitImpl(Serializer& S) const { + S.Emit(AtSynchronizedLoc); + S.EmitOwnedPtr(SynchExpr); + S.EmitOwnedPtr(SynchBody); +} + +ObjCAtSynchronizedStmt* ObjCAtSynchronizedStmt::CreateImpl(Deserializer& D) { + SourceLocation L = SourceLocation::ReadVal(D); + Expr *syncExpr = D.ReadOwnedPtr(); + Stmt *synchBody = D.ReadOwnedPtr(); + ObjCAtSynchronizedStmt* stmt = new ObjCAtSynchronizedStmt(L,syncExpr,synchBody); + return stmt; +} void ObjCAtTryStmt::EmitImpl(Serializer& S) const { S.Emit(AtTryLoc); diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 87e5c183fc..41cab3bf77 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -1113,7 +1113,27 @@ Parser::StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { /// @synchronized '(' expression ')' /// Parser::StmtResult Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { - return 0; + ExprResult Res; + ConsumeToken(); // consume synchronized + if (Tok.isNot(tok::l_paren)) { + Diag (Tok, diag::err_expected_lparen_after, "@synchronized"); + return true; + } + ConsumeParen(); // '(' + Res = ParseExpression(); + if (Res.isInvalid) { + SkipUntil(tok::semi); + return true; + } + if (Tok.isNot(tok::r_paren)) { + Diag (Tok, diag::err_expected_rparen); + return true; + } + ConsumeParen(); // ')' + StmtResult SynchBody = ParseCompoundStatementBody(); + if (SynchBody.isInvalid) + SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); + return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.Val, SynchBody.Val); } /// objc-try-catch-statement: diff --git a/Sema/Sema.h b/Sema/Sema.h index c402baef94..a35af4341f 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -378,6 +378,9 @@ public: virtual StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, StmtTy *Throw); + virtual StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, + ExprTy *SynchExpr, + StmtTy *SynchBody); //===--------------------------------------------------------------------===// // Expression Parsing Callbacks: SemaExpr.cpp. diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp index b8483866f5..e702ce802a 100644 --- a/Sema/SemaStmt.cpp +++ b/Sema/SemaStmt.cpp @@ -809,5 +809,12 @@ Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, StmtTy *Throw) { return TS; } +Action::StmtResult +Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprTy *SynchExpr, + StmtTy *SynchBody) { + ObjCAtSynchronizedStmt *SS = new ObjCAtSynchronizedStmt(AtLoc, + static_cast(SynchExpr), static_cast(SynchBody)); + return SS; +} diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 94ae9c88c4..17757fb52d 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -992,6 +992,9 @@ public: } static bool classof(const ObjCAtSynchronizedStmt *) { return true; } + virtual child_iterator child_begin(); + virtual child_iterator child_end(); + virtual void EmitImpl(llvm::Serializer& S) const; static ObjCAtSynchronizedStmt* CreateImpl(llvm::Deserializer& D); }; diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index d948b94b86..ce4781b91a 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -335,6 +335,12 @@ public: return 0; } + virtual StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, + ExprTy *SynchExpr, + StmtTy *SynchBody) { + return 0; + } + //===--------------------------------------------------------------------===// // Expression Parsing Callbacks. //===--------------------------------------------------------------------===//