From: Chris Lattner Date: Mon, 17 Dec 2007 06:44:29 +0000 (+0000) Subject: teach RemoveDuplicates about header maps. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b94c707350ee2099996a80c8d97f28b61ff98c7b;p=clang teach RemoveDuplicates about header maps. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45090 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 4f6ea926d2..5e102b9edf 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -676,15 +676,30 @@ static void AddPath(const std::string &Path, IncludeDirGroup Group, /// search list, remove the later (dead) ones. static void RemoveDuplicates(std::vector &SearchList) { llvm::SmallPtrSet SeenDirs; + llvm::SmallPtrSet SeenHeaderMaps; for (unsigned i = 0; i != SearchList.size(); ++i) { - // If this isn't the first time we've seen this dir, remove it. - if (!SeenDirs.insert(SearchList[i].getDir())) { + if (SearchList[i].isNormalDir()) { + // If this isn't the first time we've seen this dir, remove it. + if (SeenDirs.insert(SearchList[i].getDir())) + continue; + + if (Verbose) + fprintf(stderr, "ignoring duplicate directory \"%s\"\n", + SearchList[i].getDir()->getName()); + } else { + assert(SearchList[i].isHeaderMap() && "Not a headermap or normal dir?"); + // If this isn't the first time we've seen this headermap, remove it. + if (SeenHeaderMaps.insert(SearchList[i].getHeaderMap())) + continue; + if (Verbose) fprintf(stderr, "ignoring duplicate directory \"%s\"\n", SearchList[i].getDir()->getName()); - SearchList.erase(SearchList.begin()+i); - --i; } + + // This is reached if the current entry is a duplicate. + SearchList.erase(SearchList.begin()+i); + --i; } } diff --git a/include/clang/Lex/DirectoryLookup.h b/include/clang/Lex/DirectoryLookup.h index 817c1597bc..b57ebf013e 100644 --- a/include/clang/Lex/DirectoryLookup.h +++ b/include/clang/Lex/DirectoryLookup.h @@ -53,16 +53,16 @@ private: /// bool Framework : 1; - /// isHeaderMap - True if the HeaderMap field is valid, false if the Dir field + /// IsHeaderMap - True if the HeaderMap field is valid, false if the Dir field /// is valid. - bool isHeaderMap : 1; + bool IsHeaderMap : 1; public: /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of /// 'dir'. DirectoryLookup(const DirectoryEntry *dir, DirType DT, bool isUser, bool isFramework) : DirCharacteristic(DT), UserSupplied(isUser), - Framework(isFramework), isHeaderMap(false) { + Framework(isFramework), IsHeaderMap(false) { u.Dir = dir; } @@ -70,17 +70,23 @@ public: /// 'map'. DirectoryLookup(const HeaderMap *map, DirType DT, bool isUser, bool isFWork) : DirCharacteristic(DT), UserSupplied(isUser), Framework(isFWork), - isHeaderMap(true) { + IsHeaderMap(true) { u.Map = map; } /// getDir - Return the directory that this entry refers to. /// - const DirectoryEntry *getDir() const { return !isHeaderMap ? u.Dir : 0; } + const DirectoryEntry *getDir() const { return !IsHeaderMap ? u.Dir : 0; } /// getHeaderMap - Return the directory that this entry refers to. /// - const HeaderMap *getHeaderMap() const { return isHeaderMap ? u.Map : 0; } + const HeaderMap *getHeaderMap() const { return IsHeaderMap ? u.Map : 0; } + + /// isNormalDir - Return true if this is a normal directory, not a header map. + bool isNormalDir() const { return !IsHeaderMap; } + + /// isHeaderMap - Return true if this is a header map, not a normal directory. + bool isHeaderMap() const { return IsHeaderMap; } /// DirCharacteristic - The type of directory this is, one of the DirType enum /// values.