[cfe-commits] r39676 - in /cfe/cfe/trunk/Driver: ASTStreamers.cpp ASTStreamers.h clang.cpp

bwendlin at cs.uiuc.edu bwendlin at cs.uiuc.edu
Wed Jul 11 09:47:02 PDT 2007


Author: bwendlin
Date: Wed Jul 11 11:47:02 2007
New Revision: 39676

URL: http://llvm.org/viewvc/llvm-project?rev=39676&view=rev
Log:
Submitted by: Bill Wendling

- Separate out the AST streamers from the clang.cpp file into their very
  own special files.

Added:
    cfe/cfe/trunk/Driver/ASTStreamers.cpp   (with props)
    cfe/cfe/trunk/Driver/ASTStreamers.h   (with props)
Modified:
    cfe/cfe/trunk/Driver/clang.cpp

Added: cfe/cfe/trunk/Driver/ASTStreamers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/ASTStreamers.cpp?rev=39676&view=auto

==============================================================================
--- cfe/cfe/trunk/Driver/ASTStreamers.cpp (added)
+++ cfe/cfe/trunk/Driver/ASTStreamers.cpp Wed Jul 11 11:47:02 2007
@@ -0,0 +1,109 @@
+//===--- ASTStreamers.cpp - ASTStreamer Drivers ---------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Bill Wendling and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// ASTStreamer drivers.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ASTStreamers.h"
+#include "clang/AST/AST.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Sema/ASTStreamer.h"
+
+void clang::BuildASTs(Preprocessor &PP, unsigned MainFileID, bool Stats) {
+  // collect global stats on Decls/Stmts (until we have a module streamer)
+  if (Stats) {
+    Decl::CollectingStats(true);
+    Stmt::CollectingStats(true);
+  }
+
+  ASTContext Context(PP.getTargetInfo(), PP.getIdentifierTable());
+  ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
+
+  while (ASTStreamer_ReadTopLevelDecl(Streamer))
+    /* keep reading */;
+
+  if (Stats) {
+    fprintf(stderr, "\nSTATISTICS:\n");
+    ASTStreamer_PrintStats(Streamer);
+    Context.PrintStats();
+    Decl::PrintStats();
+    Stmt::PrintStats();
+  }
+  
+  ASTStreamer_Terminate(Streamer);
+}
+
+void clang::PrintFunctionDecl(FunctionDecl *FD) {
+  bool HasBody = FD->getBody();
+  
+  std::string Proto = FD->getName();
+  FunctionType *AFT = cast<FunctionType>(FD->getType());
+
+  if (FunctionTypeProto *FT = dyn_cast<FunctionTypeProto>(AFT)) {
+    Proto += "(";
+    for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) {
+      if (i) Proto += ", ";
+      std::string ParamStr;
+      if (HasBody) ParamStr = FD->getParamDecl(i)->getName();
+      
+      FT->getArgType(i).getAsStringInternal(ParamStr);
+      Proto += ParamStr;
+    }
+    
+    if (FT->isVariadic()) {
+      if (FD->getNumParams()) Proto += ", ";
+      Proto += "...";
+    }
+    Proto += ")";
+  } else {
+    assert(isa<FunctionTypeNoProto>(AFT));
+    Proto += "()";
+  }
+
+  AFT->getResultType().getAsStringInternal(Proto);
+  fprintf(stderr, "\n%s", Proto.c_str());
+  
+  if (FD->getBody()) {
+    fprintf(stderr, " ");
+    FD->getBody()->dump();
+    fprintf(stderr, "\n");
+  } else {
+    fprintf(stderr, ";\n");
+  }
+}
+
+void clang::PrintTypeDefDecl(TypedefDecl *TD) {
+  std::string S = TD->getName();
+  TD->getUnderlyingType().getAsStringInternal(S);
+  fprintf(stderr, "typedef %s;\n", S.c_str());
+}
+
+void clang::PrintASTs(Preprocessor &PP, unsigned MainFileID, bool Stats) {
+  ASTContext Context(PP.getTargetInfo(), PP.getIdentifierTable());
+  ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
+  
+  while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) {
+    if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+      PrintFunctionDecl(FD);
+    } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
+      PrintTypeDefDecl(TD);
+    } else {
+      fprintf(stderr, "Read top-level variable decl: '%s'\n", D->getName());
+    }
+  }
+  
+  if (Stats) {
+    fprintf(stderr, "\nSTATISTICS:\n");
+    ASTStreamer_PrintStats(Streamer);
+    Context.PrintStats();
+  }
+  
+  ASTStreamer_Terminate(Streamer);
+}

Propchange: cfe/cfe/trunk/Driver/ASTStreamers.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/Driver/ASTStreamers.cpp

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: cfe/cfe/trunk/Driver/ASTStreamers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/ASTStreamers.h?rev=39676&view=auto

==============================================================================
--- cfe/cfe/trunk/Driver/ASTStreamers.h (added)
+++ cfe/cfe/trunk/Driver/ASTStreamers.h Wed Jul 11 11:47:02 2007
@@ -0,0 +1,30 @@
+//===--- ASTStreamers.h - ASTStreamer Drivers -------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Bill Wendling and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// AST Streamers.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef DRIVER_ASTSTREAMERS_H_
+#define DRIVER_ASTSTREAMERS_H_
+
+namespace clang {
+
+class Preprocessor;
+class FunctionDecl;
+class TypedefDecl;
+
+void BuildASTs(Preprocessor &PP, unsigned MainFileID, bool Stats);
+void PrintASTs(Preprocessor &PP, unsigned MainFileID, bool Stats);
+void PrintFunctionDecl(FunctionDecl *FD);
+void PrintTypeDefDecl(TypedefDecl *TD);
+
+} // end clang namespace
+
+#endif

Propchange: cfe/cfe/trunk/Driver/ASTStreamers.h

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/Driver/ASTStreamers.h

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39676&r1=39675&r2=39676&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:47:02 2007
@@ -23,9 +23,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang.h"
+#include "ASTStreamers.h"
 #include "TextDiagnosticPrinter.h"
-#include "clang/Sema/ASTStreamer.h"
-#include "clang/AST/AST.h"
 #include "clang/Parse/Parser.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Basic/FileManager.h"
@@ -684,99 +683,6 @@
 }
 
 //===----------------------------------------------------------------------===//
-// ASTStreamer drivers
-//===----------------------------------------------------------------------===//
-
-static void BuildASTs(Preprocessor &PP, unsigned MainFileID) {
-  // collect global stats on Decls/Stmts (until we have a module streamer)
-  if (Stats) {
-    Decl::CollectingStats(true);
-    Stmt::CollectingStats(true);
-  }
-  ASTContext Context(PP.getTargetInfo(), PP.getIdentifierTable());
-  ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
-  while (ASTStreamer_ReadTopLevelDecl(Streamer))
-    /* keep reading */;
-
-  if (Stats) {
-    fprintf(stderr, "\nSTATISTICS:\n");
-    ASTStreamer_PrintStats(Streamer);
-    Context.PrintStats();
-    Decl::PrintStats();
-    Stmt::PrintStats();
-  }
-  
-  ASTStreamer_Terminate(Streamer);
-}
-
-static void PrintFunctionDecl(FunctionDecl *FD) {
-  bool HasBody = FD->getBody();
-  
-  std::string Proto = FD->getName();
-  FunctionType *AFT = cast<FunctionType>(FD->getType());
-  if (FunctionTypeProto *FT = dyn_cast<FunctionTypeProto>(AFT)) {
-    Proto += "(";
-    for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) {
-      if (i) Proto += ", ";
-      std::string ParamStr;
-      if (HasBody) ParamStr = FD->getParamDecl(i)->getName();
-      
-      FT->getArgType(i).getAsStringInternal(ParamStr);
-      Proto += ParamStr;
-    }
-    
-    if (FT->isVariadic()) {
-      if (FD->getNumParams()) Proto += ", ";
-      Proto += "...";
-    }
-    Proto += ")";
-  } else {
-    assert(isa<FunctionTypeNoProto>(AFT));
-    Proto += "()";
-  }
-  AFT->getResultType().getAsStringInternal(Proto);
-
-  fprintf(stderr, "\n%s", Proto.c_str());
-  
-  if (FD->getBody()) {
-    fprintf(stderr, " ");
-    FD->getBody()->dump();
-    fprintf(stderr, "\n");
-  } else {
-    fprintf(stderr, ";\n");
-  }
-}
-
-static void PrintTypeDefDecl(TypedefDecl *TD) {
-  std::string S = TD->getName();
-  TD->getUnderlyingType().getAsStringInternal(S);
-  fprintf(stderr, "typedef %s;\n", S.c_str());
-}
-
-static void PrintASTs(Preprocessor &PP, unsigned MainFileID) {
-  ASTContext Context(PP.getTargetInfo(), PP.getIdentifierTable());
-  ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
-  
-  while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) {
-    if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-      PrintFunctionDecl(FD);
-    } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
-      PrintTypeDefDecl(TD);
-    } else {
-      fprintf(stderr, "Read top-level variable decl: '%s'\n", D->getName());
-    }
-  }
-  
-  if (Stats) {
-    fprintf(stderr, "\nSTATISTICS:\n");
-    ASTStreamer_PrintStats(Streamer);
-    Context.PrintStats();
-  }
-  
-  ASTStreamer_Terminate(Streamer);
-}
-
-//===----------------------------------------------------------------------===//
 // Main driver
 //===----------------------------------------------------------------------===//
 
@@ -884,10 +790,10 @@
     break;
   case ParseSyntaxOnly:              // -fsyntax-only
   case ParseAST:
-    BuildASTs(PP, MainFileID);
+    BuildASTs(PP, MainFileID, Stats);
     break;
   case ParseASTPrint:
-    PrintASTs(PP, MainFileID);
+    PrintASTs(PP, MainFileID, Stats);
     break;
   case EmitLLVM:
     EmitLLVMFromASTs(PP, MainFileID, Stats);





More information about the cfe-commits mailing list