]> granicus.if.org Git - clang/commitdiff
Kill PreprocessorFactory, which was both morally repugnant and totally unused.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 4 Nov 2009 23:56:25 +0000 (23:56 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 4 Nov 2009 23:56:25 +0000 (23:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86076 91177308-0d34-0410-b5e6-96231b3b80d8

13 files changed:
include/clang/Frontend/ASTConsumers.h
include/clang/Frontend/AnalysisConsumer.h
include/clang/Frontend/PathDiagnosticClients.h
include/clang/Frontend/Utils.h
include/clang/Lex/Preprocessor.h
include/clang/Rewrite/HTMLRewrite.h
lib/Frontend/AnalysisConsumer.cpp
lib/Frontend/HTMLDiagnostics.cpp
lib/Frontend/HTMLPrint.cpp
lib/Frontend/PlistDiagnostics.cpp
lib/Lex/Preprocessor.cpp
lib/Rewrite/HTMLRewrite.cpp
tools/clang-cc/clang-cc.cpp

index f59a0a7d481e6590f9fba4d9244c2587b9143fbc..742813c66907ac72079e8b70a3c20b4056112557 100644 (file)
@@ -28,7 +28,6 @@ class ASTConsumer;
 class Diagnostic;
 class FileManager;
 class Preprocessor;
-class PreprocessorFactory;
 class CompileOptions;
 class LangOptions;
 
@@ -86,10 +85,11 @@ ASTConsumer *CreateBackendConsumer(BackendAction Action,
                                    llvm::raw_ostream *OS,
                                    llvm::LLVMContext& C);
 
-// HTML printer: uses the rewriter to convert source code to HTML with
-// syntax highlighting suitable for viewing in a web-browser.
-ASTConsumer* CreateHTMLPrinter(llvm::raw_ostream *OS, Diagnostic &D,
-                               Preprocessor *PP, PreprocessorFactory *PPF);
+/// CreateHTMLPrinter - Create an AST consumer which rewrites source code to
+/// HTML with syntax highlighting suitable for viewing in a web-browser.
+ASTConsumer *CreateHTMLPrinter(llvm::raw_ostream *OS, Preprocessor &PP,
+                               bool SyntaxHighlight = true,
+                               bool HighlightMacros = true);
 
 // PCH generator: generates a precompiled header file; this file can be
 // used later with the PCHReader (clang-cc option -include-pch)
index 0e4b09bd2a124c98dc14e1b698200c03abed2b6e..3c676ce1de9b533a75ccd5f4e7b2057da8fbfa56 100644 (file)
@@ -19,7 +19,6 @@ namespace clang {
 class ASTConsumer;
 class Diagnostic;
 class Preprocessor;
-class PreprocessorFactory;
 class LangOptions;
 
 /// Analysis - Set of available source code analyses.
@@ -70,7 +69,6 @@ struct AnalyzerOptions {
 /// analysis passes.  (The set of analyses run is controlled by command-line
 /// options.)
 ASTConsumer* CreateAnalysisConsumer(Diagnostic &diags, Preprocessor *pp,
-                                    PreprocessorFactory *ppf,
                                     const LangOptions &lopts,
                                     const std::string &output,
                                     const AnalyzerOptions& Opts);
index 8cb6898d75984cf20d7d5b3838c9a53766a90a08..06ce0bed71d91495dd4fa67cd72bbe41ae17dba1 100644 (file)
@@ -22,7 +22,6 @@ namespace clang {
 
 class PathDiagnosticClient;
 class Preprocessor;
-class PreprocessorFactory;
 
 class PathDiagnosticClientFactory {
 public:
@@ -37,17 +36,14 @@ public:
 
 PathDiagnosticClient*
 CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP = 0,
-                           PreprocessorFactory* PPF = 0,
                            llvm::SmallVectorImpl<std::string>* FilesMade = 0);
 
 PathDiagnosticClientFactory*
 CreateHTMLDiagnosticClientFactory(const std::string& prefix,
-                                  Preprocessor* PP = 0,
-                                  PreprocessorFactory* PPF = 0);
+                                  Preprocessor* PP = 0);
 
 PathDiagnosticClient*
 CreatePlistDiagnosticClient(const std::string& prefix, Preprocessor* PP,
-                            PreprocessorFactory* PPF,
                             PathDiagnosticClientFactory *PF = 0);
 
 } // end clang namespace
index 9cbcf8e3e93e88687a41721dd8952bd182d4a1ac..3c670286545ba4a2c9edf96e9456faba3916ffa8 100644 (file)
@@ -30,7 +30,6 @@ class Diagnostic;
 class ASTConsumer;
 class IdentifierTable;
 class SourceManager;
-class PreprocessorFactory;
 class LangOptions;
 class Decl;
 class Stmt;
index 35960ff328a6d0930e973de2e4f49c8621869bcc..3a401c999db2f9695c82689c572198b963995f39 100644 (file)
@@ -831,14 +831,6 @@ public:
   void HandleComment(SourceRange Comment);
 };
 
-/// PreprocessorFactory - A generic factory interface for lazily creating
-///  Preprocessor objects on-demand when they are needed.
-class PreprocessorFactory {
-public:
-  virtual ~PreprocessorFactory();
-  virtual Preprocessor* CreatePreprocessor() = 0;
-};
-
 /// \brief Abstract base class that describes a handler that will receive
 /// source ranges for each of the comments encountered in the source file.
 class CommentHandler {
index f77e0c61c54ce4a3db39d885efbbae63f3ad4e10..8069356d99629cb1d30ac8a5a4823c3dac5f5fc3 100644 (file)
@@ -23,7 +23,6 @@ namespace clang {
 class Rewriter;
 class RewriteBuffer;
 class Preprocessor;
-class PreprocessorFactory;
 
 namespace html {
 
@@ -75,7 +74,7 @@ namespace html {
   /// macro expansions.  This won't be perfectly perfect, but it will be
   /// reasonably close.
   void HighlightMacros(Rewriter &R, FileID FID, Preprocessor &PP);
-  void HighlightMacros(Rewriter &R, FileID FID, PreprocessorFactory &PPF);
+
 } // end html namespace
 } // end clang namespace
 
index 049f3bd3ea1435ceb8b126759c045369a474af29..714ede4a6d66025f0663e610363be6ee779179fa 100644 (file)
@@ -52,12 +52,11 @@ namespace {
 //===----------------------------------------------------------------------===//
 
 static PathDiagnosticClient*
-CreatePlistHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP,
-                            PreprocessorFactory* PPF) {
+CreatePlistHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP) {
   llvm::sys::Path F(prefix);
   PathDiagnosticClientFactory *PF =
-    CreateHTMLDiagnosticClientFactory(F.getDirname(), PP, PPF);
-  return CreatePlistDiagnosticClient(prefix, PP, PPF, PF);
+    CreateHTMLDiagnosticClientFactory(F.getDirname(), PP);
+  return CreatePlistDiagnosticClient(prefix, PP, PF);
 }
 
 //===----------------------------------------------------------------------===//
@@ -78,7 +77,6 @@ namespace {
     Diagnostic &Diags;
     ASTContext* Ctx;
     Preprocessor* PP;
-    PreprocessorFactory* PPF;
     const std::string OutDir;
     AnalyzerOptions Opts;
 
@@ -92,13 +90,11 @@ namespace {
     llvm::OwningPtr<AnalysisManager> Mgr;
 
     AnalysisConsumer(Diagnostic &diags, Preprocessor* pp,
-                     PreprocessorFactory* ppf,
                      const LangOptions& lopts,
                      const std::string& outdir,
                      const AnalyzerOptions& opts)
-      : LOpts(lopts), Diags(diags),
-        Ctx(0), PP(pp), PPF(ppf),
-        OutDir(outdir), Opts(opts), PD(0) {
+      : LOpts(lopts), Diags(diags), Ctx(0), PP(pp), OutDir(outdir),
+        Opts(opts), PD(0) {
       DigestAnalyzerOptions();
     }
 
@@ -108,7 +104,7 @@ namespace {
         switch (Opts.AnalysisDiagOpt) {
         default:
 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN, AUTOCREATE) \
-          case PD_##NAME: PD = CREATEFN(OutDir, PP, PPF); break;
+          case PD_##NAME: PD = CREATEFN(OutDir, PP); break;
 #include "clang/Frontend/Analyses.def"
         }
       }
@@ -444,12 +440,11 @@ static void ActionInlineCall(AnalysisManager &mgr, Decl *D) {
 //===----------------------------------------------------------------------===//
 
 ASTConsumer* clang::CreateAnalysisConsumer(Diagnostic &diags, Preprocessor* pp,
-                                           PreprocessorFactory* ppf,
                                            const LangOptions& lopts,
                                            const std::string& OutDir,
                                            const AnalyzerOptions& Opts) {
 
-  llvm::OwningPtr<AnalysisConsumer> C(new AnalysisConsumer(diags, pp, ppf,
+  llvm::OwningPtr<AnalysisConsumer> C(new AnalysisConsumer(diags, pp,
                                                            lopts, OutDir,
                                                            Opts));
 
index 9d6f96c69f5d39cb47633cd90ae38dbbb2419627..648ecac3bf42a61a9ac10b9b8aeaf6afcc2d22dc 100644 (file)
@@ -77,7 +77,6 @@ HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
 
 PathDiagnosticClient*
 clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP,
-                                  PreprocessorFactory*,
                                   llvm::SmallVectorImpl<std::string>* FilesMade)
 {
   return new HTMLDiagnostics(prefix, PP, FilesMade);
@@ -111,8 +110,7 @@ public:
 
 PathDiagnosticClientFactory*
 clang::CreateHTMLDiagnosticClientFactory(const std::string& prefix,
-                                         Preprocessor* PP,
-                                         PreprocessorFactory*) {
+                                         Preprocessor* PP) {
   return new HTMLDiagnosticsFactory(prefix, PP);
 }
 
@@ -216,12 +214,6 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
   // for example.
 
   if (PP) html::SyntaxHighlight(R, FID, *PP);
-
-  // FIXME: We eventually want to use PPF to create a fresh Preprocessor,
-  //  once we have worked out the bugs.
-  //
-  // if (PPF) html::HighlightMacros(R, FID, *PPF);
-  //
   if (PP) html::HighlightMacros(R, FID, *PP);
 
   // Get the full directory name of the analyzed file.
index 8d93d70e83f4e43c8fc5ee93c133cd28e69ace0f..75e6184572e50286725833de6ad3585d8002ee7c 100644 (file)
 
 #include "clang/Frontend/ASTConsumers.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
-#include "clang/Rewrite/Rewriter.h"
-#include "clang/Rewrite/HTMLRewrite.h"
 #include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/FileManager.h"
-#include "clang/AST/ASTContext.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Rewrite/HTMLRewrite.h"
+#include "clang/Rewrite/Rewriter.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace clang;
@@ -32,13 +33,14 @@ namespace {
   class HTMLPrinter : public ASTConsumer {
     Rewriter R;
     llvm::raw_ostream *Out;
-    Diagnostic &Diags;
-    Preprocessor *PP;
-    PreprocessorFactory *PPF;
+    Preprocessor &PP;
+    bool SyntaxHighlight, HighlightMacros;
+
   public:
-    HTMLPrinter(llvm::raw_ostream *OS, Diagnostic &D, Preprocessor *pp,
-                PreprocessorFactory* ppf)
-      : Out(OS), Diags(D), PP(pp), PPF(ppf) {}
+    HTMLPrinter(llvm::raw_ostream *OS, Preprocessor &pp,
+                bool _SyntaxHighlight, bool _HighlightMacros)
+      : Out(OS), PP(pp), SyntaxHighlight(_SyntaxHighlight),
+        HighlightMacros(_HighlightMacros) {}
     virtual ~HTMLPrinter();
 
     void Initialize(ASTContext &context);
@@ -46,10 +48,10 @@ namespace {
 }
 
 ASTConsumer* clang::CreateHTMLPrinter(llvm::raw_ostream *OS,
-                                      Diagnostic &D, Preprocessor *PP,
-                                      PreprocessorFactory* PPF) {
-
-  return new HTMLPrinter(OS, D, PP, PPF);
+                                      Preprocessor &PP,
+                                      bool SyntaxHighlight,
+                                      bool HighlightMacros) {
+  return new HTMLPrinter(OS, PP, SyntaxHighlight, HighlightMacros);
 }
 
 void HTMLPrinter::Initialize(ASTContext &context) {
@@ -57,7 +59,7 @@ void HTMLPrinter::Initialize(ASTContext &context) {
 }
 
 HTMLPrinter::~HTMLPrinter() {
-  if (Diags.hasErrorOccurred())
+  if (PP.getDiagnostics().hasErrorOccurred())
     return;
 
   // Format the file.
@@ -79,8 +81,8 @@ HTMLPrinter::~HTMLPrinter() {
   // We might not have a preprocessor if we come from a deserialized AST file,
   // for example.
 
-  if (PP) html::SyntaxHighlight(R, FID, *PP);
-  if (PPF) html::HighlightMacros(R, FID, *PP);
+  if (SyntaxHighlight) html::SyntaxHighlight(R, FID, PP);
+  if (HighlightMacros) html::HighlightMacros(R, FID, PP);
   html::EscapeText(R, FID, false, true);
 
   // Emit the HTML.
index a83dca0a5ffa98c2793509e58980c2f4de6d6843..a10ecd4a206057dbd8bc6463605fcffb2d0f5816 100644 (file)
@@ -29,7 +29,6 @@ typedef llvm::DenseMap<FileID, unsigned> FIDMap;
 
 namespace clang {
   class Preprocessor;
-  class PreprocessorFactory;
 }
 
 namespace {
@@ -63,8 +62,7 @@ PlistDiagnostics::PlistDiagnostics(const std::string& output,
 }
 
 PathDiagnosticClient*
-clang::CreatePlistDiagnosticClient(const std::string& s,
-                                   Preprocessor *PP, PreprocessorFactory*,
+clang::CreatePlistDiagnosticClient(const std::string& s, Preprocessor *PP,
                                    PathDiagnosticClientFactory *PF) {
   return new PlistDiagnostics(s, PP->getLangOptions(), PF);
 }
index 7f3afc60764c205a84ab70cbe45e1a4343182b77..b175a49856dcbd0fae54442b47596f548b0d0a23 100644 (file)
@@ -43,8 +43,6 @@ using namespace clang;
 
 //===----------------------------------------------------------------------===//
 
-PreprocessorFactory::~PreprocessorFactory() {}
-
 Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts,
                            TargetInfo &target, SourceManager &SM,
                            HeaderSearch &Headers,
index 7326890ded76725576759621daf94cfdd7774f69..445bf30a1f98f67cbe170334c4ff67f571928862 100644 (file)
@@ -564,10 +564,3 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) {
   // Restore diagnostics object back to its own thing.
   PP.setDiagnostics(*OldDiags);
 }
-
-void html::HighlightMacros(Rewriter &R, FileID FID,
-                           PreprocessorFactory &PPF) {
-
-  llvm::OwningPtr<Preprocessor> PP(PPF.CreatePreprocessor());
-  HighlightMacros(R, FID, *PP);
-}
index 2c0c7021d597503872eb20e294d7840615828bb9..af34f4c7910ae67131e4fd4dd98c00d5ee3e3987 100644 (file)
@@ -1195,67 +1195,48 @@ void InitializePreprocessorInitOptions(PreprocessorInitOptions &InitOpts) {
 }
 
 //===----------------------------------------------------------------------===//
-// Driver PreprocessorFactory - For lazily generating preprocessors ...
+// Preprocessor construction
 //===----------------------------------------------------------------------===//
 
-namespace {
-class VISIBILITY_HIDDEN DriverPreprocessorFactory : public PreprocessorFactory {
-  Diagnostic        &Diags;
-  const LangOptions &LangInfo;
-  TargetInfo        &Target;
-  SourceManager     &SourceMgr;
-  HeaderSearch      &HeaderInfo;
-
-public:
-  DriverPreprocessorFactory(Diagnostic &diags, const LangOptions &opts,
-                            TargetInfo &target, SourceManager &SM,
-                            HeaderSearch &Headers)
-  : Diags(diags), LangInfo(opts), Target(target),
-    SourceMgr(SM), HeaderInfo(Headers) {}
-
-
-  virtual ~DriverPreprocessorFactory() {}
-
-  virtual Preprocessor* CreatePreprocessor() {
-    llvm::OwningPtr<PTHManager> PTHMgr;
+static Preprocessor *
+CreatePreprocessor(Diagnostic &Diags,const LangOptions &LangInfo,
+                   TargetInfo &Target, SourceManager &SourceMgr,
+                   HeaderSearch &HeaderInfo) {
+  PTHManager *PTHMgr = 0;
+  if (!TokenCache.empty() && !ImplicitIncludePTH.empty()) {
+    fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
+            "options\n");
+    exit(1);
+  }
 
-    if (!TokenCache.empty() && !ImplicitIncludePTH.empty()) {
-      fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
-                      "options\n");
-      exit(1);
-    }
+  // Use PTH?
+  if (!TokenCache.empty() || !ImplicitIncludePTH.empty()) {
+    const std::string& x = TokenCache.empty() ? ImplicitIncludePTH:TokenCache;
+    PTHMgr = PTHManager::Create(x, &Diags,
+                                TokenCache.empty() ? Diagnostic::Error
+                                : Diagnostic::Warning);
+  }
 
-    // Use PTH?
-    if (!TokenCache.empty() || !ImplicitIncludePTH.empty()) {
-      const std::string& x = TokenCache.empty() ? ImplicitIncludePTH:TokenCache;
-      PTHMgr.reset(PTHManager::Create(x, &Diags,
-                                      TokenCache.empty() ? Diagnostic::Error
-                                                        : Diagnostic::Warning));
-    }
+  if (Diags.hasErrorOccurred())
+    exit(1);
 
-    if (Diags.hasErrorOccurred())
-      exit(1);
+  // Create the Preprocessor.
+  Preprocessor *PP = new Preprocessor(Diags, LangInfo, Target,
+                                      SourceMgr, HeaderInfo, PTHMgr);
 
-    // Create the Preprocessor.
-    llvm::OwningPtr<Preprocessor> PP(new Preprocessor(Diags, LangInfo, Target,
-                                                      SourceMgr, HeaderInfo,
-                                                      PTHMgr.get()));
-
-    // Note that this is different then passing PTHMgr to Preprocessor's ctor.
-    // That argument is used as the IdentifierInfoLookup argument to
-    // IdentifierTable's ctor.
-    if (PTHMgr) {
-      PTHMgr->setPreprocessor(PP.get());
-      PP->setPTHManager(PTHMgr.take());
-    }
+  // Note that this is different then passing PTHMgr to Preprocessor's ctor.
+  // That argument is used as the IdentifierInfoLookup argument to
+  // IdentifierTable's ctor.
+  if (PTHMgr) {
+    PTHMgr->setPreprocessor(PP);
+    PP->setPTHManager(PTHMgr);
+  }
 
-    PreprocessorInitOptions InitOpts;
-    InitializePreprocessorInitOptions(InitOpts);
-    InitializePreprocessor(*PP, InitOpts);
+  PreprocessorInitOptions InitOpts;
+  InitializePreprocessorInitOptions(InitOpts);
+  InitializePreprocessor(*PP, InitOpts);
 
-    return PP.take();
-  }
-};
+  return PP;
 }
 
 //===----------------------------------------------------------------------===//
@@ -1723,8 +1704,8 @@ static ASTConsumer *CreateConsumerAction(Preprocessor &PP,
 
 /// ProcessInputFile - Process a single input file with the specified state.
 ///
-static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
-                             const std::string &InFile, ProgActions PA,
+static void ProcessInputFile(Preprocessor &PP, const std::string &InFile,
+                             ProgActions PA,
                              const llvm::StringMap<bool> &Features,
                              llvm::LLVMContext& Context) {
   llvm::OwningPtr<llvm::raw_ostream> OS;
@@ -1749,11 +1730,11 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
 
   case EmitHTML:
     OS.reset(ComputeOutFile(InFile, 0, true, OutPath));
-    Consumer.reset(CreateHTMLPrinter(OS.get(), PP.getDiagnostics(), &PP, &PPF));
+    Consumer.reset(CreateHTMLPrinter(OS.get(), PP));
     break;
 
   case RunAnalysis:
-    Consumer.reset(CreateAnalysisConsumer(PP.getDiagnostics(), &PP, &PPF,
+    Consumer.reset(CreateAnalysisConsumer(PP.getDiagnostics(), &PP,
                                           PP.getLangOptions(), OutputFile,
                                           ReadAnalyzerOptions()));
     break;
@@ -2284,10 +2265,9 @@ int main(int argc, char **argv) {
     InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo, Triple);
 
     // Set up the preprocessor with these options.
-    DriverPreprocessorFactory PPFactory(Diags, LangInfo, *Target,
-                                        *SourceMgr.get(), HeaderInfo);
-
-    llvm::OwningPtr<Preprocessor> PP(PPFactory.CreatePreprocessor());
+    llvm::OwningPtr<Preprocessor> PP(CreatePreprocessor(Diags, LangInfo,
+                                                        *Target, *SourceMgr,
+                                                        HeaderInfo));
     if (!PP)
       continue;
 
@@ -2324,7 +2304,7 @@ int main(int argc, char **argv) {
       ((PathDiagnosticClient*)DiagClient.get())->SetPreprocessor(PP.get());
 
     // Process the source file.
-    ProcessInputFile(*PP, PPFactory, InFile, ProgAction, Features, Context);
+    ProcessInputFile(*PP, InFile, ProgAction, Features, Context);
 
     HeaderInfo.ClearFileInfo();
     DiagClient->setLangOptions(0);