[cfe-commits] r69370 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/stmts.c test/PCH/stmts.h

Douglas Gregor dgregor at apple.com
Fri Apr 17 12:05:31 PDT 2009


Author: dgregor
Date: Fri Apr 17 14:05:30 2009
New Revision: 69370

URL: http://llvm.org/viewvc/llvm-project?rev=69370&view=rev
Log:
PCH support for GNU statement expressions

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/test/PCH/stmts.c
    cfe/trunk/test/PCH/stmts.h

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Apr 17 14:05:30 2009
@@ -1641,15 +1641,21 @@
            SourceLocation lp, SourceLocation rp) :
     Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
   
+  /// \brief Build an empty statement expression.
+  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
+
   CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
   const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
-  
+  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
+
   virtual SourceRange getSourceRange() const {
     return SourceRange(LParenLoc, RParenLoc);
   }
   
   SourceLocation getLParenLoc() const { return LParenLoc; }
+  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
   SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
   
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == StmtExprClass; 

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69370&r1=69369&r2=69370&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Fri Apr 17 14:05:30 2009
@@ -456,9 +456,10 @@
       EXPR_IMPLICIT_VALUE_INIT,
       /// \brief A VAArgExpr record.
       EXPR_VA_ARG,
-      // An AddrLabelExpr record.
+      /// \brief An AddrLabelExpr record.
       EXPR_ADDR_LABEL,
-      // FIXME: StmtExpr
+      /// \brief A StmtExpr record.
+      EXPR_STMT,
       /// \brief A TypesCompatibleExpr record.
       EXPR_TYPES_COMPATIBLE,
       /// \brief A ChooseExpr record.

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69370&r1=69369&r2=69370&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Apr 17 14:05:30 2009
@@ -289,6 +289,7 @@
     unsigned VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
     unsigned VisitVAArgExpr(VAArgExpr *E);
     unsigned VisitAddrLabelExpr(AddrLabelExpr *E);
+    unsigned VisitStmtExpr(StmtExpr *E);
     unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
     unsigned VisitChooseExpr(ChooseExpr *E);
     unsigned VisitGNUNullExpr(GNUNullExpr *E);
@@ -749,6 +750,14 @@
   return 0;
 }
 
+unsigned PCHStmtReader::VisitStmtExpr(StmtExpr *E) {
+  VisitExpr(E);
+  E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setSubStmt(cast_or_null<CompoundStmt>(StmtStack.back()));
+  return 1;
+}
+
 unsigned PCHStmtReader::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
   VisitExpr(E);
   E->setArgType1(Reader.GetType(Record[Idx++]));
@@ -2359,6 +2368,10 @@
       S = new (Context) AddrLabelExpr(Empty);
       break;
 
+    case pch::EXPR_STMT:
+      S = new (Context) StmtExpr(Empty);
+      break;
+
     case pch::EXPR_TYPES_COMPATIBLE:
       S = new (Context) TypesCompatibleExpr(Empty);
       break;

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69370&r1=69369&r2=69370&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Apr 17 14:05:30 2009
@@ -491,6 +491,7 @@
     void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
     void VisitVAArgExpr(VAArgExpr *E);
     void VisitAddrLabelExpr(AddrLabelExpr *E);
+    void VisitStmtExpr(StmtExpr *E);
     void VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
     void VisitChooseExpr(ChooseExpr *E);
     void VisitGNUNullExpr(GNUNullExpr *E);
@@ -896,6 +897,14 @@
   Code = pch::EXPR_ADDR_LABEL;
 }
 
+void PCHStmtWriter::VisitStmtExpr(StmtExpr *E) {
+  VisitExpr(E);
+  Writer.WriteSubStmt(E->getSubStmt());
+  Writer.AddSourceLocation(E->getLParenLoc(), Record);
+  Writer.AddSourceLocation(E->getRParenLoc(), Record);
+  Code = pch::EXPR_STMT;
+}
+
 void PCHStmtWriter::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
   VisitExpr(E);
   Writer.AddTypeRef(E->getArgType1(), Record);

Modified: cfe/trunk/test/PCH/stmts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/stmts.c?rev=69370&r1=69369&r2=69370&view=diff

==============================================================================
--- cfe/trunk/test/PCH/stmts.c (original)
+++ cfe/trunk/test/PCH/stmts.c Fri Apr 17 14:05:30 2009
@@ -10,3 +10,5 @@
 const char* query_name(void) { return what_is_my_name(); }
 
 int use_computed_goto(int x) { return computed_goto(x); }
+
+int get_weird_max(int x, int y) { return weird_max(x, y); }

Modified: cfe/trunk/test/PCH/stmts.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/stmts.h?rev=69370&r1=69369&r2=69370&view=diff

==============================================================================
--- cfe/trunk/test/PCH/stmts.h (original)
+++ cfe/trunk/test/PCH/stmts.h Fri Apr 17 14:05:30 2009
@@ -86,3 +86,8 @@
   done:
   return 5;
 }
+
+#define maxint(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
+int weird_max(int x, int y) {
+  return maxint(++x, --y);
+}





More information about the cfe-commits mailing list