]> granicus.if.org Git - clang/commitdiff
PCH support for GNU statement expressions
authorDouglas Gregor <dgregor@apple.com>
Fri, 17 Apr 2009 19:05:30 +0000 (19:05 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 17 Apr 2009 19:05:30 +0000 (19:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69370 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8059ad2f2e042822bf8a443fba638f49a60723b4..ccfc9c71e05b1b33893ea29769e4f9609d058b60 100644 (file)
@@ -1641,15 +1641,21 @@ public:
            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; 
index 93b78f100e559b910544826aaae5dd2632eb46e1..04849ddba1fddb6a403f3b56831c2680d3232c21 100644 (file)
@@ -456,9 +456,10 @@ namespace clang {
       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.
index 8928b063cf23652c80d9babd9c689f0053c18346..e474dc7a70daeff60933e203047a5883ab0b0ce1 100644 (file)
@@ -289,6 +289,7 @@ namespace {
     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 @@ unsigned PCHStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
   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 @@ Stmt *PCHReader::ReadStmt() {
       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;
index 4bbaaa0c760596b8240c473ef57cde917c895694..14e979f2bc7f4cfc8641bfe424a527cf3a52bbc6 100644 (file)
@@ -491,6 +491,7 @@ namespace {
     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 @@ void PCHStmtWriter::VisitAddrLabelExpr(AddrLabelExpr *E) {
   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);
index fc6cfc29a20bf2672439c8bc673115a672b6d877..c8fbc83a0fa1346e17654de48e58435744d63e8c 100644 (file)
@@ -10,3 +10,5 @@ int g1(int x) { return f1(x); }
 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); }
index 10842e8b295d1607be2f7970f1089f1653b82289..367a2837cfd33d096f979aaaed8215f00f1259e2 100644 (file)
@@ -86,3 +86,8 @@ int computed_goto(int x) {
   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);
+}