[cfe-commits] r70143 - in /cfe/trunk: include/clang/AST/StmtObjC.h include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp

steve naroff snaroff at apple.com
Sun Apr 26 19:31:14 PDT 2009


On Apr 26, 2009, at 4:38 PM, Douglas Gregor wrote:

>
> On Apr 26, 2009, at 11:52 AM, Steve Naroff wrote:
>
>> Author: snaroff
>> Date: Sun Apr 26 13:52:16 2009
>> New Revision: 70143
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=70143&view=rev
>> Log:
>> Add PCH read/write support for ObjC statements.
>
> Looks like we're still failing a lot of the Objective-C tests using  
> pch-test.pl. Is that expected?
>

Yes. This commit fixed all the problems with -emit-pch.

All the remaining problems have to do with -include-pch. I believe  
there is one problem causing most of the grief.

I will dig into this first thing tomorrow morning.

snaroff

> 	- Doug
>
>> Modified:
>>   cfe/trunk/include/clang/AST/StmtObjC.h
>>   cfe/trunk/include/clang/Frontend/PCHBitCodes.h
>>   cfe/trunk/lib/Frontend/PCHReader.cpp
>>   cfe/trunk/lib/Frontend/PCHWriter.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/StmtObjC.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtObjC.h?rev=70143&r1=70142&r2=70143&view=diff
>>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/include/clang/AST/StmtObjC.h (original)
>> +++ cfe/trunk/include/clang/AST/StmtObjC.h Sun Apr 26 13:52:16 2009
>> @@ -29,6 +29,8 @@
>> public:
>>  ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, Stmt *Body,
>>                        SourceLocation FCL, SourceLocation RPL);
>> +  explicit ObjCForCollectionStmt(EmptyShell Empty) :
>> +    Stmt(ObjCForCollectionStmtClass, Empty) { }
>>
>>  Stmt *getElement() { return SubExprs[ELEM]; }
>>  Expr *getCollection() {
>> @@ -42,7 +44,16 @@
>>  }
>>  const Stmt *getBody() const { return SubExprs[BODY]; }
>>
>> +  void setElement(Stmt *S) { SubExprs[ELEM] = S; }
>> +  void setCollection(Expr *E) {
>> +    SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(E);
>> +  }
>> +  void setBody(Stmt *S) { SubExprs[BODY] = S; }
>> +
>> +  SourceLocation getForLoc() const { return ForLoc; }
>> +  void setForLoc(SourceLocation Loc) { ForLoc = Loc; }
>>  SourceLocation getRParenLoc() const { return RParenLoc; }
>> +  void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
>>
>>  virtual SourceRange getSourceRange() const {
>>    return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
>> @@ -73,26 +84,34 @@
>>  ObjCAtCatchStmt(SourceLocation atCatchLoc, SourceLocation rparenloc,
>>                  ParmVarDecl *catchVarDecl,
>>                  Stmt *atCatchStmt, Stmt *atCatchList);
>> +
>> +  explicit ObjCAtCatchStmt(EmptyShell Empty) :
>> +    Stmt(ObjCAtCatchStmtClass, Empty) { }
>>
>>  const Stmt *getCatchBody() const { return SubExprs[BODY]; }
>>  Stmt *getCatchBody() { return SubExprs[BODY]; }
>> -
>> +  void setCatchBody(Stmt *S) { SubExprs[BODY] = S; }
>> +
>>  const ObjCAtCatchStmt *getNextCatchStmt() const {
>>    return static_cast<const ObjCAtCatchStmt*>(SubExprs[NEXT_CATCH]);
>>  }
>>  ObjCAtCatchStmt *getNextCatchStmt() {
>>    return static_cast<ObjCAtCatchStmt*>(SubExprs[NEXT_CATCH]);
>>  }
>> -
>> +  void setNextCatchStmt(Stmt *S) { SubExprs[NEXT_CATCH] = S; }
>> +
>>  const ParmVarDecl *getCatchParamDecl() const {
>>    return ExceptionDecl;
>>  }
>>  ParmVarDecl *getCatchParamDecl() {
>>    return ExceptionDecl;
>>  }
>> +  void setCatchParamDecl(ParmVarDecl *D) { ExceptionDecl = D; }
>>
>>  SourceLocation getAtCatchLoc() const { return AtCatchLoc; }
>> +  void setAtCatchLoc(SourceLocation Loc) { AtCatchLoc = Loc; }
>>  SourceLocation getRParenLoc() const { return RParenLoc; }
>> +  void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
>>
>>  virtual SourceRange getSourceRange() const {
>>    return SourceRange(AtCatchLoc, SubExprs[BODY]->getLocEnd());
>> @@ -117,15 +136,20 @@
>>  ObjCAtFinallyStmt(SourceLocation atFinallyLoc, Stmt *atFinallyStmt)
>>  : Stmt(ObjCAtFinallyStmtClass),
>>    AtFinallyStmt(atFinallyStmt), AtFinallyLoc(atFinallyLoc) {}
>> +
>> +  explicit ObjCAtFinallyStmt(EmptyShell Empty) :
>> +    Stmt(ObjCAtFinallyStmtClass, Empty) { }
>>
>>  const Stmt *getFinallyBody() const { return AtFinallyStmt; }
>>  Stmt *getFinallyBody() { return AtFinallyStmt; }
>> -
>> +  void setFinallyBody(Stmt *S) { AtFinallyStmt = S; }
>> +
>>  virtual SourceRange getSourceRange() const {
>>    return SourceRange(AtFinallyLoc, AtFinallyStmt->getLocEnd());
>>  }
>>
>>  SourceLocation getAtFinallyLoc() const { return AtFinallyLoc; }
>> +  void setAtFinallyLoc(SourceLocation Loc) { AtFinallyLoc = Loc; }
>>
>>  static bool classof(const Stmt *T) {
>>    return T->getStmtClass() == ObjCAtFinallyStmtClass;
>> @@ -154,22 +178,32 @@
>>      SubStmts[FINALLY] = atFinallyStmt;
>>      AtTryLoc = atTryLoc;
>>    }
>> +  explicit ObjCAtTryStmt(EmptyShell Empty) :
>> +    Stmt(ObjCAtTryStmtClass, Empty) { }
>>
>>  SourceLocation getAtTryLoc() const { return AtTryLoc; }
>> +  void setAtTryLoc(SourceLocation Loc) { AtTryLoc = Loc; }
>> +
>>  const Stmt *getTryBody() const { return SubStmts[TRY]; }
>>  Stmt *getTryBody() { return SubStmts[TRY]; }
>> +  void setTryBody(Stmt *S) { SubStmts[TRY] = S; }
>> +
>>  const ObjCAtCatchStmt *getCatchStmts() const {
>>    return dyn_cast_or_null<ObjCAtCatchStmt>(SubStmts[CATCH]);
>>  }
>>  ObjCAtCatchStmt *getCatchStmts() {
>>    return dyn_cast_or_null<ObjCAtCatchStmt>(SubStmts[CATCH]);
>>  }
>> +  void setCatchStmts(Stmt *S) { SubStmts[CATCH] = S; }
>> +
>>  const ObjCAtFinallyStmt *getFinallyStmt() const {
>>    return dyn_cast_or_null<ObjCAtFinallyStmt>(SubStmts[FINALLY]);
>>  }
>>  ObjCAtFinallyStmt *getFinallyStmt() {
>>    return dyn_cast_or_null<ObjCAtFinallyStmt>(SubStmts[FINALLY]);
>>  }
>> +  void setFinallyStmt(Stmt *S) { SubStmts[FINALLY] = S; }
>> +
>>  virtual SourceRange getSourceRange() const {
>>    return SourceRange(AtTryLoc, SubStmts[TRY]->getLocEnd());
>>  }
>> @@ -202,8 +236,11 @@
>>    SubStmts[SYNC_BODY] = synchBody;
>>    AtSynchronizedLoc = atSynchronizedLoc;
>>  }
>> +  explicit ObjCAtSynchronizedStmt(EmptyShell Empty) :
>> +    Stmt(ObjCAtSynchronizedStmtClass, Empty) { }
>>
>>  SourceLocation getAtSynchronizedLoc() const { return  
>> AtSynchronizedLoc; }
>> +  void setAtSynchronizedLoc(SourceLocation Loc)  
>> { AtSynchronizedLoc = Loc; }
>>
>>  const CompoundStmt *getSynchBody() const {
>>    return reinterpret_cast<CompoundStmt*>(SubStmts[SYNC_BODY]);
>> @@ -211,6 +248,7 @@
>>  CompoundStmt *getSynchBody() {
>>    return reinterpret_cast<CompoundStmt*>(SubStmts[SYNC_BODY]);
>>  }
>> +  void setSynchBody(Stmt *S) { SubStmts[SYNC_BODY] = S; }
>>
>>  const Expr *getSynchExpr() const {
>>    return reinterpret_cast<Expr*>(SubStmts[SYNC_EXPR]);
>> @@ -218,6 +256,7 @@
>>  Expr *getSynchExpr() {
>>    return reinterpret_cast<Expr*>(SubStmts[SYNC_EXPR]);
>>  }
>> +  void setSynchExpr(Stmt *S) { SubStmts[SYNC_EXPR] = S; }
>>
>>  virtual SourceRange getSourceRange() const {
>>    return SourceRange(AtSynchronizedLoc, getSynchBody()- 
>> >getLocEnd());
>> @@ -241,9 +280,15 @@
>>  : Stmt(ObjCAtThrowStmtClass), Throw(throwExpr) {
>>    AtThrowLoc = atThrowLoc;
>>  }
>> +  explicit ObjCAtThrowStmt(EmptyShell Empty) :
>> +    Stmt(ObjCAtThrowStmtClass, Empty) { }
>>
>>  const Expr *getThrowExpr() const { return  
>> reinterpret_cast<Expr*>(Throw); }
>>  Expr *getThrowExpr() { return reinterpret_cast<Expr*>(Throw); }
>> +  void setThrowExpr(Stmt *S) { Throw = S; }
>> +
>> +  SourceLocation getThrowLoc() { return AtThrowLoc; }
>> +  void setThrowLoc(SourceLocation Loc) { AtThrowLoc = Loc; }
>>
>>  virtual SourceRange getSourceRange() const {
>>    if (Throw)
>>
>> Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=70143&r1=70142&r2=70143&view=diff
>>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
>> +++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Sun Apr 26  
>> 13:52:16 2009
>> @@ -570,7 +570,20 @@
>>      /// \brief An ObjCMessageExpr record.
>>      EXPR_OBJC_MESSAGE_EXPR,
>>      /// \brief An ObjCSuperExpr record.
>> -      EXPR_OBJC_SUPER_EXPR
>> +      EXPR_OBJC_SUPER_EXPR,
>> +
>> +      /// \brief An ObjCForCollectionStmt record.
>> +      STMT_OBJC_FOR_COLLECTION,
>> +      /// \brief An ObjCAtCatchStmt record.
>> +      STMT_OBJC_CATCH,
>> +      /// \brief An ObjCAtFinallyStmt record.
>> +      STMT_OBJC_FINALLY,
>> +      /// \brief An ObjCAtTryStmt record.
>> +      STMT_OBJC_AT_TRY,
>> +      /// \brief An ObjCAtSynchronizedStmt record.
>> +      STMT_OBJC_AT_SYNCHRONIZED,
>> +      /// \brief An ObjCAtThrowStmt record.
>> +      STMT_OBJC_AT_THROW
>>    };
>>
>>    /// \brief The kinds of designators that can occur in a
>>
>> Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=70143&r1=70142&r2=70143&view=diff
>>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
>> +++ cfe/trunk/lib/Frontend/PCHReader.cpp Sun Apr 26 13:52:16 2009
>> @@ -502,6 +502,13 @@
>>    unsigned VisitObjCKVCRefExpr(ObjCKVCRefExpr *E);
>>    unsigned VisitObjCMessageExpr(ObjCMessageExpr *E);
>>    unsigned VisitObjCSuperExpr(ObjCSuperExpr *E);
>> +
>> +    unsigned VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
>> +    unsigned VisitObjCCatchStmt(ObjCAtCatchStmt *);
>> +    unsigned VisitObjCFinallyStmt(ObjCAtFinallyStmt *);
>> +    unsigned VisitObjCAtTryStmt(ObjCAtTryStmt *);
>> +    unsigned VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
>> +    unsigned VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
>>  };
>> }
>>
>> @@ -1140,6 +1147,57 @@
>>  return 0;
>> }
>>
>> +unsigned  
>> PCHStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
>> +  VisitStmt(S);
>> +  S->setElement(cast_or_null<Stmt>(StmtStack[StmtStack.size() -  
>> 3]));
>> +  S->setCollection(cast_or_null<Expr>(StmtStack[StmtStack.size() -  
>> 2]));
>> +  S->setBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() - 1]));
>> +  S->setForLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>> +  S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx+ 
>> +]));
>> +  return 3;
>> +}
>> +
>> +unsigned PCHStmtReader::VisitObjCCatchStmt(ObjCAtCatchStmt *S) {
>> +  VisitStmt(S);
>> +  S->setCatchBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() -  
>> 2]));
>> +  S- 
>> >setNextCatchStmt(cast_or_null<Stmt>(StmtStack[StmtStack.size() -  
>> 1]));
>> +  S- 
>> > 
>> setCatchParamDecl 
>> (cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
>> +  S->setAtCatchLoc(SourceLocation::getFromRawEncoding(Record[Idx+ 
>> +]));
>> +  S->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx+ 
>> +]));
>> +  return 2;
>> +}
>> +
>> +unsigned PCHStmtReader::VisitObjCFinallyStmt(ObjCAtFinallyStmt *S) {
>> +  VisitStmt(S);
>> +  S->setFinallyBody(StmtStack.back());
>> +  S->setAtFinallyLoc(SourceLocation::getFromRawEncoding(Record[Idx+ 
>> +]));
>> +  return 1;
>> +}
>> +
>> +unsigned PCHStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
>> +  VisitStmt(S);
>> +  S->setTryBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() -  
>> 3]));
>> +  S->setCatchStmts(cast_or_null<Stmt>(StmtStack[StmtStack.size() -  
>> 2]));
>> +  S->setFinallyStmt(cast_or_null<Stmt>(StmtStack[StmtStack.size()  
>> - 1]));
>> +  S->setAtTryLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>> +  return 3;
>> +}
>> +
>> +unsigned  
>> PCHStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt  
>> *S) {
>> +  VisitStmt(S);
>> +  S->setSynchExpr(cast_or_null<Stmt>(StmtStack[StmtStack.size() -  
>> 2]));
>> +  S->setSynchBody(cast_or_null<Stmt>(StmtStack[StmtStack.size() -  
>> 1]));
>> +  S- 
>> >setAtSynchronizedLoc(SourceLocation::getFromRawEncoding(Record[Idx+ 
>> +]));
>> +  return 2;
>> +}
>> +
>> +unsigned PCHStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
>> +  VisitStmt(S);
>> +  S->setThrowExpr(StmtStack.back());
>> +  S->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
>> +  return 1;
>> +}
>> +
>> // 
>> = 
>> = 
>> = 
>> ----------------------------------------------------------------------= 
>> ==//
>> // PCH reader implementation
>> // 
>> = 
>> = 
>> = 
>> ----------------------------------------------------------------------= 
>> ==//
>> @@ -3371,6 +3429,24 @@
>>    case pch::EXPR_OBJC_SUPER_EXPR:
>>      S = new (Context) ObjCSuperExpr(Empty);
>>      break;
>> +    case pch::STMT_OBJC_FOR_COLLECTION:
>> +      S = new (Context) ObjCForCollectionStmt(Empty);
>> +      break;
>> +    case pch::STMT_OBJC_CATCH:
>> +      S = new (Context) ObjCAtCatchStmt(Empty);
>> +      break;
>> +    case pch::STMT_OBJC_FINALLY:
>> +      S = new (Context) ObjCAtFinallyStmt(Empty);
>> +      break;
>> +    case pch::STMT_OBJC_AT_TRY:
>> +      S = new (Context) ObjCAtTryStmt(Empty);
>> +      break;
>> +    case pch::STMT_OBJC_AT_SYNCHRONIZED:
>> +      S = new (Context) ObjCAtSynchronizedStmt(Empty);
>> +      break;
>> +    case pch::STMT_OBJC_AT_THROW:
>> +      S = new (Context) ObjCAtThrowStmt(Empty);
>> +      break;
>>    }
>>
>>    // We hit a STMT_STOP, so we're done with this expression.
>>
>> Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=70143&r1=70142&r2=70143&view=diff
>>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
>> +++ cfe/trunk/lib/Frontend/PCHWriter.cpp Sun Apr 26 13:52:16 2009
>> @@ -667,7 +667,7 @@
>>    void VisitBlockExpr(BlockExpr *E);
>>    void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
>>
>> -    // Objective-C
>> +    // Objective-C Expressions
>>    void VisitObjCStringLiteral(ObjCStringLiteral *E);
>>    void VisitObjCEncodeExpr(ObjCEncodeExpr *E);
>>    void VisitObjCSelectorExpr(ObjCSelectorExpr *E);
>> @@ -677,6 +677,14 @@
>>    void VisitObjCKVCRefExpr(ObjCKVCRefExpr *E);
>>    void VisitObjCMessageExpr(ObjCMessageExpr *E);
>>    void VisitObjCSuperExpr(ObjCSuperExpr *E);
>> +
>> +    // Objective-C Statements
>> +    void VisitObjCForCollectionStmt(ObjCForCollectionStmt *);
>> +    void VisitObjCCatchStmt(ObjCAtCatchStmt *);
>> +    void VisitObjCFinallyStmt(ObjCAtFinallyStmt *);
>> +    void VisitObjCAtTryStmt(ObjCAtTryStmt *);
>> +    void VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *);
>> +    void VisitObjCAtThrowStmt(ObjCAtThrowStmt *);
>>  };
>> }
>>
>> @@ -1259,6 +1267,51 @@
>>  Code = pch::EXPR_OBJC_SUPER_EXPR;
>> }
>>
>> +void  
>> PCHStmtWriter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
>> +  VisitStmt(S);
>> +  Writer.WriteSubStmt(S->getElement());
>> +  Writer.WriteSubStmt(S->getCollection());
>> +  Writer.WriteSubStmt(S->getBody());
>> +  Writer.AddSourceLocation(S->getForLoc(), Record);
>> +  Writer.AddSourceLocation(S->getRParenLoc(), Record);
>> +  Code = pch::STMT_OBJC_FOR_COLLECTION;
>> +}
>> +
>> +void PCHStmtWriter::VisitObjCCatchStmt(ObjCAtCatchStmt *S) {
>> +  Writer.WriteSubStmt(S->getCatchBody());
>> +  Writer.WriteSubStmt(S->getNextCatchStmt());
>> +  Writer.AddDeclRef(S->getCatchParamDecl(), Record);
>> +  Writer.AddSourceLocation(S->getAtCatchLoc(), Record);
>> +  Writer.AddSourceLocation(S->getRParenLoc(), Record);
>> +  Code = pch::STMT_OBJC_CATCH;
>> +}
>> +
>> +void PCHStmtWriter::VisitObjCFinallyStmt(ObjCAtFinallyStmt *S) {
>> +  Writer.WriteSubStmt(S->getFinallyBody());
>> +  Writer.AddSourceLocation(S->getAtFinallyLoc(), Record);
>> +  Code = pch::STMT_OBJC_FINALLY;
>> +}
>> +
>> +void PCHStmtWriter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
>> +  Writer.WriteSubStmt(S->getTryBody());
>> +  Writer.WriteSubStmt(S->getCatchStmts());
>> +  Writer.WriteSubStmt(S->getFinallyStmt());
>> +  Writer.AddSourceLocation(S->getAtTryLoc(), Record);
>> +  Code = pch::STMT_OBJC_AT_TRY;
>> +}
>> +
>> +void  
>> PCHStmtWriter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt  
>> *S) {
>> +  Writer.WriteSubStmt(S->getSynchExpr());
>> +  Writer.WriteSubStmt(S->getSynchBody());
>> +  Writer.AddSourceLocation(S->getAtSynchronizedLoc(), Record);
>> +  Code = pch::STMT_OBJC_AT_SYNCHRONIZED;
>> +}
>> +
>> +void PCHStmtWriter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
>> +  Writer.WriteSubStmt(S->getThrowExpr());
>> +  Writer.AddSourceLocation(S->getThrowLoc(), Record);
>> +  Code = pch::STMT_OBJC_AT_THROW;
>> +}
>>
>> // 
>> = 
>> = 
>> = 
>> ----------------------------------------------------------------------= 
>> ==//
>> // PCHWriter Implementation
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list