diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-11-11 05:33:31 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-11 05:33:31 +0000 |
commit | d8daaa7450535e101d3155fb939b0914278987c4 (patch) | |
tree | d0b127d11867f9972cb68afc9dd7c434ddfb51e5 | |
parent | 7b5a1210d93ca62ecd61800f245c87259b1f8f79 (diff) |
clang-cc: Simplify this code, now that predefines handling is uniform in the
PCH/-E and PCH/not--E cases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86808 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | tools/clang-cc/clang-cc.cpp | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index a13d1a4da4..8bf02f748f 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -1114,39 +1114,27 @@ static void InitializePreprocessorOptions(PreprocessorOptions &InitOpts) { // We want to add these paths to the predefines buffer in order, make a // temporary vector to sort by their occurrence. llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths; + std::string OriginalFile; // For use by -implicit-include-pch. if (!ImplicitIncludePTH.empty()) OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(), &ImplicitIncludePTH)); - if (!ImplicitIncludePCH.empty()) + if (!ImplicitIncludePCH.empty()) { + OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH); + // FIXME: Don't fail like this. + if (OriginalFile.empty()) + exit(1); OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(), - &ImplicitIncludePCH)); + &OriginalFile)); + } for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i) OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i), &ImplicitIncludes[i])); llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end()); // Now that they are ordered by position, add to the predefines buffer. - for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i) { - std::string *Ptr = OrderedPaths[i].second; - if (!ImplicitIncludes.empty() && - Ptr >= &ImplicitIncludes[0] && - Ptr <= &ImplicitIncludes[ImplicitIncludes.size()-1]) { - InitOpts.addInclude(*Ptr); - } else if (Ptr == &ImplicitIncludePTH) { - InitOpts.addInclude(*Ptr); - } else { - // We end up here when we're producing preprocessed output and - // we loaded a PCH file. In this case, just include the header - // file that was used to build the precompiled header. - assert(Ptr == &ImplicitIncludePCH); - std::string OriginalFile = PCHReader::getOriginalSourceFile(*Ptr); - // FIXME: Don't fail like this. - if (OriginalFile.empty()) - exit(1); - InitOpts.addInclude(OriginalFile); - } - } + for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i) + InitOpts.addInclude(*OrderedPaths[i].second); } } |