Browse Source

Fixed the include path problem #321. (the test case for C++ may be necessary.)

pull/395/head
ebifrier 12 years ago committed by Joao Matos
parent
commit
08994b0408
  1. 33
      src/CppParser/AST.cpp

33
src/CppParser/AST.cpp

@ -9,6 +9,30 @@
#include <algorithm> #include <algorithm>
#include <string> #include <string>
#include <vector> #include <vector>
#include <llvm/Support/Path.h>
// copy from widenPath ('llvm/lib/Support/Windows/Path.inc')
static std::string normalizePath(const std::string & File) {
llvm::SmallString<2 * 128> Result;
for (llvm::sys::path::const_iterator I = llvm::sys::path::begin(File),
E = llvm::sys::path::end(File);
I != E; ++I) {
if (I->size() == 1 && *I == ".")
continue;
if (I->size() == 2 && *I == "..")
llvm::sys::path::remove_filename(Result);
else
llvm::sys::path::append(Result, *I);
}
#ifdef _WIN32
// Clean up the file path.
std::replace(Result.begin(), Result.end(), '/', '\\');
#endif
return Result.c_str();
}
template<typename T> template<typename T>
static std::vector<T> split(const T & str, const T & delimiters) { static std::vector<T> split(const T & str, const T & delimiters) {
@ -626,21 +650,18 @@ ASTContext::ASTContext() {}
TranslationUnit* ASTContext::FindOrCreateModule(std::string File) TranslationUnit* ASTContext::FindOrCreateModule(std::string File)
{ {
#ifdef _WIN32 auto normalizedFile = normalizePath(File);
// Clean up the file path.
std::replace(File.begin(), File.end(), '/', '\\');
#endif
auto existingUnit = std::find_if(TranslationUnits.begin(), auto existingUnit = std::find_if(TranslationUnits.begin(),
TranslationUnits.end(), [&](TranslationUnit* unit) { TranslationUnits.end(), [&](TranslationUnit* unit) {
return unit && unit->FileName == File; return unit && unit->FileName == normalizedFile;
}); });
if (existingUnit != TranslationUnits.end()) if (existingUnit != TranslationUnits.end())
return *existingUnit; return *existingUnit;
auto unit = new TranslationUnit(); auto unit = new TranslationUnit();
unit->FileName = File; unit->FileName = normalizedFile;
TranslationUnits.push_back(unit); TranslationUnits.push_back(unit);
return unit; return unit;

Loading…
Cancel
Save