aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Frontend/PreprocessorOptions.h25
-rw-r--r--tools/clang-cc/clang-cc.cpp20
2 files changed, 38 insertions, 7 deletions
diff --git a/include/clang/Frontend/PreprocessorOptions.h b/include/clang/Frontend/PreprocessorOptions.h
index cae37e78f5..d2af829c6d 100644
--- a/include/clang/Frontend/PreprocessorOptions.h
+++ b/include/clang/Frontend/PreprocessorOptions.h
@@ -28,6 +28,13 @@ class PreprocessorOptions {
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 @@ public:
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));
}
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index f08c768be3..74a8363837 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -1090,6 +1090,9 @@ static void InitializeIncludePaths(HeaderSearchOptions &Opts,
}
static void InitializePreprocessorOptions(PreprocessorOptions &InitOpts) {
+ InitOpts.setImplicitPCHInclude(ImplicitIncludePCH);
+ InitOpts.setImplicitPTHInclude(ImplicitIncludePTH);
+
// Use predefines?
InitOpts.setUsePredefines(!UndefMacros);
@@ -1143,7 +1146,7 @@ static void InitializePreprocessorOptions(PreprocessorOptions &InitOpts) {
std::string OriginalFile = PCHReader::getOriginalSourceFile(*Ptr);
if (!OriginalFile.empty()) {
InitOpts.addInclude(OriginalFile, false);
- ImplicitIncludePCH.clear();
+ InitOpts.setImplicitPCHInclude("");
}
}
}
@@ -1159,15 +1162,16 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo,
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 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
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 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
// 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 @@ int main(int argc, char **argv) {
PhonyDependencyTarget);
}
- if (ImplicitIncludePCH.empty()) {
+ if (CompOpts.getPreprocessorOpts().getImplicitPCHInclude().empty()) {
if (InitializeSourceManager(*PP.get(), InFile))
continue;