From: Daniel Dunbar Date: Wed, 4 Nov 2009 23:56:25 +0000 (+0000) Subject: Kill PreprocessorFactory, which was both morally repugnant and totally unused. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90b1827c1c1cf075266b96b416eefcf37924333b;p=clang Kill PreprocessorFactory, which was both morally repugnant and totally unused. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86076 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/ASTConsumers.h b/include/clang/Frontend/ASTConsumers.h index f59a0a7d48..742813c669 100644 --- a/include/clang/Frontend/ASTConsumers.h +++ b/include/clang/Frontend/ASTConsumers.h @@ -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) diff --git a/include/clang/Frontend/AnalysisConsumer.h b/include/clang/Frontend/AnalysisConsumer.h index 0e4b09bd2a..3c676ce1de 100644 --- a/include/clang/Frontend/AnalysisConsumer.h +++ b/include/clang/Frontend/AnalysisConsumer.h @@ -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); diff --git a/include/clang/Frontend/PathDiagnosticClients.h b/include/clang/Frontend/PathDiagnosticClients.h index 8cb6898d75..06ce0bed71 100644 --- a/include/clang/Frontend/PathDiagnosticClients.h +++ b/include/clang/Frontend/PathDiagnosticClients.h @@ -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* 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 diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index 9cbcf8e3e9..3c67028654 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -30,7 +30,6 @@ class Diagnostic; class ASTConsumer; class IdentifierTable; class SourceManager; -class PreprocessorFactory; class LangOptions; class Decl; class Stmt; diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 35960ff328..3a401c999d 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -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 { diff --git a/include/clang/Rewrite/HTMLRewrite.h b/include/clang/Rewrite/HTMLRewrite.h index f77e0c61c5..8069356d99 100644 --- a/include/clang/Rewrite/HTMLRewrite.h +++ b/include/clang/Rewrite/HTMLRewrite.h @@ -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 diff --git a/lib/Frontend/AnalysisConsumer.cpp b/lib/Frontend/AnalysisConsumer.cpp index 049f3bd3ea..714ede4a6d 100644 --- a/lib/Frontend/AnalysisConsumer.cpp +++ b/lib/Frontend/AnalysisConsumer.cpp @@ -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 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 C(new AnalysisConsumer(diags, pp, ppf, + llvm::OwningPtr C(new AnalysisConsumer(diags, pp, lopts, OutDir, Opts)); diff --git a/lib/Frontend/HTMLDiagnostics.cpp b/lib/Frontend/HTMLDiagnostics.cpp index 9d6f96c69f..648ecac3bf 100644 --- a/lib/Frontend/HTMLDiagnostics.cpp +++ b/lib/Frontend/HTMLDiagnostics.cpp @@ -77,7 +77,6 @@ HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp, PathDiagnosticClient* clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP, - PreprocessorFactory*, llvm::SmallVectorImpl* 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. diff --git a/lib/Frontend/HTMLPrint.cpp b/lib/Frontend/HTMLPrint.cpp index 8d93d70e83..75e6184572 100644 --- a/lib/Frontend/HTMLPrint.cpp +++ b/lib/Frontend/HTMLPrint.cpp @@ -13,13 +13,14 @@ #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. diff --git a/lib/Frontend/PlistDiagnostics.cpp b/lib/Frontend/PlistDiagnostics.cpp index a83dca0a5f..a10ecd4a20 100644 --- a/lib/Frontend/PlistDiagnostics.cpp +++ b/lib/Frontend/PlistDiagnostics.cpp @@ -29,7 +29,6 @@ typedef llvm::DenseMap 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); } diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 7f3afc6076..b175a49856 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -43,8 +43,6 @@ using namespace clang; //===----------------------------------------------------------------------===// -PreprocessorFactory::~PreprocessorFactory() {} - Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts, TargetInfo &target, SourceManager &SM, HeaderSearch &Headers, diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 7326890ded..445bf30a1f 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -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 PP(PPF.CreatePreprocessor()); - HighlightMacros(R, FID, *PP); -} diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 2c0c7021d5..af34f4c791 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -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 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 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 &Features, llvm::LLVMContext& Context) { llvm::OwningPtr 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 PP(PPFactory.CreatePreprocessor()); + llvm::OwningPtr 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);