[cfe-commits] r69356 - in /cfe/trunk: include/clang/AST/Stmt.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 09:55:37 PDT 2009


Author: dgregor
Date: Fri Apr 17 11:55:36 2009
New Revision: 69356

URL: http://llvm.org/viewvc/llvm-project?rev=69356&view=rev
Log:
PCH support for declaration statements, and a test for PredefinedExpr

Modified:
    cfe/trunk/include/clang/AST/Stmt.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/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=69356&r1=69355&r2=69356&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Apr 17 11:55:36 2009
@@ -244,6 +244,9 @@
            SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
                                     StartLoc(startLoc), EndLoc(endLoc) {}
   
+  /// \brief Build an empty declaration statement.
+  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
+
   virtual void Destroy(ASTContext& Ctx);
 
   /// isSingleDecl - This method returns true if this DeclStmt refers
@@ -257,10 +260,13 @@
   
   const DeclGroupRef getDeclGroup() const { return DG; }
   DeclGroupRef getDeclGroup() { return DG; }
+  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
 
   SourceLocation getStartLoc() const { return StartLoc; }
+  void setStartLoc(SourceLocation L) { StartLoc = L; }
   SourceLocation getEndLoc() const { return EndLoc; }
-  
+  void setEndLoc(SourceLocation L) { EndLoc = L; }
+
   SourceRange getSourceRange() const {
     return SourceRange(StartLoc, EndLoc);
   }

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

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Fri Apr 17 11:55:36 2009
@@ -399,6 +399,8 @@
       STMT_BREAK,
       /// \brief A ReturnStmt record.
       STMT_RETURN,
+      /// \brief A DeclStmt record.
+      STMT_DECL,
       /// \brief A PredefinedExpr record.
       EXPR_PREDEFINED,
       /// \brief A DeclRefExpr record.

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Apr 17 11:55:36 2009
@@ -257,6 +257,7 @@
     unsigned VisitContinueStmt(ContinueStmt *S);
     unsigned VisitBreakStmt(BreakStmt *S);
     unsigned VisitReturnStmt(ReturnStmt *S);
+    unsigned VisitDeclStmt(DeclStmt *S);
     unsigned VisitExpr(Expr *E);
     unsigned VisitPredefinedExpr(PredefinedExpr *E);
     unsigned VisitDeclRefExpr(DeclRefExpr *E);
@@ -406,6 +407,25 @@
   return 1;
 }
 
+unsigned PCHStmtReader::VisitDeclStmt(DeclStmt *S) {
+  VisitStmt(S);
+  S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+
+  if (Idx + 1 == Record.size()) {
+    // Single declaration
+    S->setDeclGroup(DeclGroupRef(Reader.GetDecl(Record[Idx++])));
+  } else {
+    llvm::SmallVector<Decl *, 16> Decls;
+    Decls.reserve(Record.size() - Idx);
+    for (unsigned N = Record.size(); Idx != N; ++Idx)
+      Decls.push_back(Reader.GetDecl(Record[Idx]));
+    S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(),
+                                                   &Decls[0], Decls.size())));
+  }
+  return 0;
+}
+
 unsigned PCHStmtReader::VisitExpr(Expr *E) {
   VisitStmt(E);
   E->setType(Reader.GetType(Record[Idx++]));
@@ -2184,8 +2204,11 @@
       S = new (Context) ReturnStmt(Empty);
       break;
 
+    case pch::STMT_DECL:
+      S = new (Context) DeclStmt(Empty);
+      break;
+
     case pch::EXPR_PREDEFINED:
-      // FIXME: untested (until we can serialize function bodies).
       S = new (Context) PredefinedExpr(Empty);
       break;
       

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Apr 17 11:55:36 2009
@@ -459,6 +459,7 @@
     void VisitContinueStmt(ContinueStmt *S);
     void VisitBreakStmt(BreakStmt *S);
     void VisitReturnStmt(ReturnStmt *S);
+    void VisitDeclStmt(DeclStmt *S);
     void VisitExpr(Expr *E);
     void VisitPredefinedExpr(PredefinedExpr *E);
     void VisitDeclRefExpr(DeclRefExpr *E);
@@ -600,6 +601,16 @@
   Code = pch::STMT_RETURN;
 }
 
+void PCHStmtWriter::VisitDeclStmt(DeclStmt *S) {
+  VisitStmt(S);
+  Writer.AddSourceLocation(S->getStartLoc(), Record);
+  Writer.AddSourceLocation(S->getEndLoc(), Record);
+  DeclGroupRef DG = S->getDeclGroup();
+  for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
+    Writer.AddDeclRef(*D, Record);
+  Code = pch::STMT_DECL;
+}
+
 void PCHStmtWriter::VisitExpr(Expr *E) {
   VisitStmt(E);
   Writer.AddTypeRef(E->getType(), Record);

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

==============================================================================
--- cfe/trunk/test/PCH/stmts.c (original)
+++ cfe/trunk/test/PCH/stmts.c Fri Apr 17 11:55:36 2009
@@ -7,3 +7,4 @@
 
 void g0(void) { f0(5); }
 int g1(int x) { return f1(x); }
+const char* query_name(void) { return what_is_my_name(); }

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

==============================================================================
--- cfe/trunk/test/PCH/stmts.h (original)
+++ cfe/trunk/test/PCH/stmts.h Fri Apr 17 11:55:36 2009
@@ -39,10 +39,12 @@
     x++;
   } while (x < 10);
 
-  for (; x < 20; ++x) {
-    if (x == 12)
+  for (int y = x; y < 20; ++y) {
+    if (x + y == 12)
       return;
   }
+
+  int z = x, *y, j = 5;
 }
 
 int f1(int x) {
@@ -56,3 +58,5 @@
 
   return x*2;
 }
+
+const char* what_is_my_name(void) { return __func__; }





More information about the cfe-commits mailing list