Author: ddunbar Date: Tue Nov 10 16:09:38 2009 New Revision: 86728 URL: http://llvm.org/viewvc/llvm-project?rev=86728&view=rev Log: Decouple more of clang-cc by moving ImplicitP[CT]H options into PreprocessorOptions.
Global variables used as [in] [out] parameters considered harmful. Modified: cfe/trunk/include/clang/Frontend/PreprocessorOptions.h cfe/trunk/tools/clang-cc/clang-cc.cpp Modified: cfe/trunk/include/clang/Frontend/PreprocessorOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PreprocessorOptions.h?rev=86728&r1=86727&r2=86728&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/PreprocessorOptions.h (original) +++ cfe/trunk/include/clang/Frontend/PreprocessorOptions.h Tue Nov 10 16:09:38 2009 @@ -28,6 +28,13 @@ unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler /// and target specific predefines. + /// The implicit PCH included at the start of the translation unit, or empty. + std::string ImplicitPCHInclude; + + /// The implicit PTH input included at the start of the translation unit, or + /// empty. + std::string ImplicitPTHInclude; + public: PreprocessorOptions() : UsePredefines(true) {} @@ -36,6 +43,24 @@ 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; + } + void addMacroDef(const std::string &Name) { Macros.push_back(std::make_pair(Name, false)); } Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86728&r1=86727&r2=86728&view=diff ============================================================================== --- cfe/trunk/tools/clang-cc/clang-cc.cpp (original) +++ cfe/trunk/tools/clang-cc/clang-cc.cpp Tue Nov 10 16:09:38 2009 @@ -1090,6 +1090,9 @@ } static void InitializePreprocessorOptions(PreprocessorOptions &InitOpts) { + InitOpts.setImplicitPCHInclude(ImplicitIncludePCH); + InitOpts.setImplicitPTHInclude(ImplicitIncludePTH); + // Use predefines? InitOpts.setUsePredefines(!UndefMacros); @@ -1143,7 +1146,7 @@ std::string OriginalFile = PCHReader::getOriginalSourceFile(*Ptr); if (!OriginalFile.empty()) { InitOpts.addInclude(OriginalFile, false); - ImplicitIncludePCH.clear(); + InitOpts.setImplicitPCHInclude(""); } } } @@ -1159,15 +1162,16 @@ const PreprocessorOptions &PPOpts, TargetInfo &Target, SourceManager &SourceMgr, HeaderSearch &HeaderInfo) { PTHManager *PTHMgr = 0; - if (!TokenCache.empty() && !ImplicitIncludePTH.empty()) { + if (!TokenCache.empty() && !PPOpts.getImplicitPTHInclude().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; + if (!TokenCache.empty() || !PPOpts.getImplicitPTHInclude().empty()) { + const std::string& x = TokenCache.empty() ? + PPOpts.getImplicitPTHInclude() : TokenCache; PTHMgr = PTHManager::Create(x, &Diags, TokenCache.empty() ? Diagnostic::Error : Diagnostic::Warning); @@ -1736,7 +1740,9 @@ llvm::OwningPtr<PCHReader> Reader; llvm::OwningPtr<ExternalASTSource> Source; - if (!ImplicitIncludePCH.empty()) { + const std::string &ImplicitPCHInclude = + CompOpts.getPreprocessorOpts().getImplicitPCHInclude(); + if (!ImplicitPCHInclude.empty()) { // If the user specified -isysroot, it will be used for relocatable PCH // files. const char *isysrootPCH = 0; @@ -1747,7 +1753,7 @@ // The user has asked us to include a precompiled header. Load // the precompiled header into the AST context. - switch (Reader->ReadPCH(ImplicitIncludePCH)) { + switch (Reader->ReadPCH(ImplicitPCHInclude)) { case PCHReader::Success: { // Set the predefines buffer as suggested by the PCH // reader. Typically, the predefines buffer will be empty. @@ -2206,7 +2212,7 @@ PhonyDependencyTarget); } - if (ImplicitIncludePCH.empty()) { + if (CompOpts.getPreprocessorOpts().getImplicitPCHInclude().empty()) { if (InitializeSourceManager(*PP.get(), InFile)) continue; _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits