]> granicus.if.org Git - clang/commitdiff
PCH support for declaration statements, and a test for PredefinedExpr
authorDouglas Gregor <dgregor@apple.com>
Fri, 17 Apr 2009 16:55:36 +0000 (16:55 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 17 Apr 2009 16:55:36 +0000 (16:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69356 91177308-0d34-0410-b5e6-96231b3b80d8

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

index fbb5552ca75f99b7b4786f9bf45f09cf2544b41f..d0531f95a5b8898f65ba8bb7edbfb9411761a073 100644 (file)
@@ -244,6 +244,9 @@ public:
            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 @@ public:
   
   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);
   }
index 7c316c691c1637d5fbb12ffc4db4de442e5b7a88..f5b023430a34693d783a6fdacccee2e9bd3bc5ab 100644 (file)
@@ -399,6 +399,8 @@ namespace clang {
       STMT_BREAK,
       /// \brief A ReturnStmt record.
       STMT_RETURN,
+      /// \brief A DeclStmt record.
+      STMT_DECL,
       /// \brief A PredefinedExpr record.
       EXPR_PREDEFINED,
       /// \brief A DeclRefExpr record.
index 0dcdf8d3fd8df3e6452c9b589d5551e2ca6066e9..50378966e1614c58a420f583e4dc93772faea4f1 100644 (file)
@@ -257,6 +257,7 @@ namespace {
     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 @@ unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) {
   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 @@ Stmt *PCHReader::ReadStmt() {
       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;
       
index 91490549eaba38cf864e90e742a218c3608a6a66..4b4e89716616d5c40baf852d03b03cc0dac9d916 100644 (file)
@@ -459,6 +459,7 @@ namespace {
     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 @@ void PCHStmtWriter::VisitReturnStmt(ReturnStmt *S) {
   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);
index e9d03e877496fab933f5d32af8e0511307246a0a..a2278bf16c0cbd28b0921e3ccb1dc68f7ba42576 100644 (file)
@@ -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(); }
index 7290d2efcb083fe4e27cb11c8e14244b354fd10d..685811ad080f6c8d5f420f4753eacd66eab7044a 100644 (file)
@@ -39,10 +39,12 @@ void f0(int x) {
     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 @@ int f1(int x) {
 
   return x*2;
 }
+
+const char* what_is_my_name(void) { return __func__; }