From 049d3a06ea9f8fc03582488a2b7f24512565a335 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 17 Nov 2009 05:52:41 +0000 Subject: [PATCH] Simplify PreprocessorOptions, it doesn't need abstracted field access. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89047 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/PreprocessorOptions.h | 50 +------------------- lib/Frontend/CompilerInstance.cpp | 4 +- lib/Frontend/FrontendAction.cpp | 4 +- lib/Frontend/InitPreprocessor.cpp | 26 +++++----- tools/clang-cc/Options.cpp | 14 +++--- 5 files changed, 24 insertions(+), 74 deletions(-) diff --git a/include/clang/Frontend/PreprocessorOptions.h b/include/clang/Frontend/PreprocessorOptions.h index 6ae6843ee6..f0c1d3c2c3 100644 --- a/include/clang/Frontend/PreprocessorOptions.h +++ b/include/clang/Frontend/PreprocessorOptions.h @@ -23,6 +23,7 @@ class LangOptions; /// PreprocessorOptions - This class is used for passing the various options /// used in preprocessor initialization to InitializePreprocessor(). class PreprocessorOptions { +public: std::vector > Macros; std::vector Includes; std::vector MacroIncludes; @@ -43,61 +44,12 @@ class PreprocessorOptions { public: PreprocessorOptions() : UsePredefines(true) {} - bool getUsePredefines() const { return UsePredefines; } - void setUsePredefines(bool Value) { - UsePredefines = Value; - } - - const std::string &getImplicitPCHInclude() const { - return ImplicitPCHInclude; - } - void setImplicitPCHInclude(llvm::StringRef Value) { - assert((Value.empty() || ImplicitPTHInclude.empty()) && - "Cannot both implicit PCH and PTH includes!"); - ImplicitPCHInclude = Value; - } - - const std::string &getImplicitPTHInclude() const { - return ImplicitPTHInclude; - } - void setImplicitPTHInclude(llvm::StringRef Value) { - assert((ImplicitPCHInclude.empty() || Value.empty()) && - "Cannot both implicit PCH and PTH includes!"); - ImplicitPTHInclude = Value; - } - - const std::string &getTokenCache() const { - return TokenCache; - } - void setTokenCache(llvm::StringRef Value) { - TokenCache = Value; - } - void addMacroDef(llvm::StringRef Name) { Macros.push_back(std::make_pair(Name, false)); } void addMacroUndef(llvm::StringRef Name) { Macros.push_back(std::make_pair(Name, true)); } - void addInclude(llvm::StringRef Name) { - Includes.push_back(Name); - } - void addMacroInclude(llvm::StringRef Name) { - MacroIncludes.push_back(Name); - } - - typedef std::vector >::const_iterator macro_iterator; - macro_iterator macro_begin() const { return Macros.begin(); } - macro_iterator macro_end() const { return Macros.end(); } - - typedef std::vector::const_iterator include_iterator; - include_iterator include_begin() const { return Includes.begin(); } - include_iterator include_end() const { return Includes.end(); } - - typedef std::vector::const_iterator imacro_iterator; - imacro_iterator imacro_begin() const { return MacroIncludes.begin(); } - imacro_iterator imacro_end() const { return MacroIncludes.end(); } }; } // end namespace clang diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 42352dfe51..0365761c84 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -167,8 +167,8 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags, FileManager &FileMgr) { // Create a PTH manager if we are using some form of a token cache. PTHManager *PTHMgr = 0; - if (!PPOpts.getTokenCache().empty()) - PTHMgr = PTHManager::Create(PPOpts.getTokenCache(), Diags); + if (!PPOpts.TokenCache.empty()) + PTHMgr = PTHManager::Create(PPOpts.TokenCache, Diags); // FIXME: Don't fail like this. if (Diags.hasErrorOccurred()) diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index 2629b446f0..ff63a0dab5 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -90,10 +90,10 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, goto failure; /// Use PCH? - if (!CI.getPreprocessorOpts().getImplicitPCHInclude().empty()) { + if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) { assert(hasPCHSupport() && "This action does not have PCH support!"); CI.createPCHExternalASTSource( - CI.getPreprocessorOpts().getImplicitPCHInclude()); + CI.getPreprocessorOpts().ImplicitPCHInclude); if (!CI.getASTContext().getExternalSource()) goto failure; } diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 9648620ea0..4ee286dd26 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -477,7 +477,7 @@ void clang::InitializePreprocessor(Preprocessor &PP, LineDirective, LineDirective+strlen(LineDirective)); // Install things like __POWERPC__, __GNUC__, etc into the macro table. - if (InitOpts.getUsePredefines()) + if (InitOpts.UsePredefines) InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(), PredefineBuffer); @@ -488,27 +488,25 @@ void clang::InitializePreprocessor(Preprocessor &PP, LineDirective, LineDirective+strlen(LineDirective)); // Process #define's and #undef's in the order they are given. - for (PreprocessorOptions::macro_iterator I = InitOpts.macro_begin(), - E = InitOpts.macro_end(); I != E; ++I) { - if (I->second) // isUndef - UndefineBuiltinMacro(PredefineBuffer, I->first.c_str()); + for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) { + if (InitOpts.Macros[i].second) // isUndef + UndefineBuiltinMacro(PredefineBuffer, InitOpts.Macros[i].first.c_str()); else - DefineBuiltinMacro(PredefineBuffer, I->first.c_str()); + DefineBuiltinMacro(PredefineBuffer, InitOpts.Macros[i].first.c_str()); } // If -imacros are specified, include them now. These are processed before // any -include directives. - for (PreprocessorOptions::imacro_iterator I = InitOpts.imacro_begin(), - E = InitOpts.imacro_end(); I != E; ++I) - AddImplicitIncludeMacros(PredefineBuffer, *I); + for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i) + AddImplicitIncludeMacros(PredefineBuffer, InitOpts.MacroIncludes[i]); // Process -include directives. - for (PreprocessorOptions::include_iterator I = InitOpts.include_begin(), - E = InitOpts.include_end(); I != E; ++I) { - if (*I == InitOpts.getImplicitPTHInclude()) - AddImplicitIncludePTH(PredefineBuffer, PP, *I); + for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) { + const std::string &Path = InitOpts.Includes[i]; + if (Path == InitOpts.ImplicitPTHInclude) + AddImplicitIncludePTH(PredefineBuffer, PP, Path); else - AddImplicitInclude(PredefineBuffer, *I); + AddImplicitInclude(PredefineBuffer, Path); } // Null terminate PredefinedBuffer and add it. diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index 56f77c62a7..2dc521986f 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -1008,8 +1008,8 @@ void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts, void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) { using namespace preprocessoroptions; - Opts.setImplicitPCHInclude(ImplicitIncludePCH); - Opts.setImplicitPTHInclude(ImplicitIncludePTH); + Opts.ImplicitPCHInclude = ImplicitIncludePCH; + Opts.ImplicitPTHInclude = ImplicitIncludePTH; // Select the token cache file, we don't support more than one currently so we // can't have both an implicit-pth and a token cache file. @@ -1020,12 +1020,12 @@ void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) { exit(1); } if (TokenCache.getPosition()) - Opts.setTokenCache(TokenCache); + Opts.TokenCache = TokenCache; else - Opts.setTokenCache(ImplicitIncludePTH); + Opts.TokenCache = ImplicitIncludePTH; // Use predefines? - Opts.setUsePredefines(!UndefMacros); + Opts.UsePredefines = !UndefMacros; // Add macros from the command line. unsigned d = 0, D = D_macros.size(); @@ -1040,7 +1040,7 @@ void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) { // If -imacros are specified, include them now. These are processed before // any -include directives. for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i) - Opts.addMacroInclude(ImplicitMacroIncludes[i]); + Opts.MacroIncludes.push_back(ImplicitMacroIncludes[i]); // Add the ordered list of -includes, sorting in the implicit include options // at the appropriate location. @@ -1064,7 +1064,7 @@ void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) { llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end()); for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i) - Opts.addInclude(*OrderedPaths[i].second); + Opts.Includes.push_back(*OrderedPaths[i].second); } void clang::InitializeLangOptions(LangOptions &Options, -- 2.50.1