| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #include "clang/Basic/FileManager.h" |
| 14 | #include "clang/Basic/LangOptions.h" |
| 15 | #include "clang/Config/config.h" |
| 16 | #include "clang/Frontend/FrontendDiagnostic.h" |
| 17 | #include "clang/Frontend/Utils.h" |
| 18 | #include "clang/Lex/HeaderMap.h" |
| 19 | #include "clang/Lex/HeaderSearch.h" |
| 20 | #include "clang/Lex/HeaderSearchOptions.h" |
| 21 | #include "llvm/ADT/SmallPtrSet.h" |
| 22 | #include "llvm/ADT/SmallString.h" |
| 23 | #include "llvm/ADT/SmallVector.h" |
| 24 | #include "llvm/ADT/StringExtras.h" |
| 25 | #include "llvm/ADT/Triple.h" |
| 26 | #include "llvm/ADT/Twine.h" |
| 27 | #include "llvm/Support/ErrorHandling.h" |
| 28 | #include "llvm/Support/Path.h" |
| 29 | #include "llvm/Support/raw_ostream.h" |
| 30 | |
| 31 | using namespace clang; |
| 32 | using namespace clang::frontend; |
| 33 | |
| 34 | namespace { |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | class { |
| 40 | std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > ; |
| 41 | typedef std::vector<std::pair<IncludeDirGroup, |
| 42 | DirectoryLookup> >::const_iterator ; |
| 43 | std::vector<std::pair<std::string, bool> > ; |
| 44 | HeaderSearch &; |
| 45 | bool ; |
| 46 | std::string ; |
| 47 | bool ; |
| 48 | |
| 49 | public: |
| 50 | |
| 51 | InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot) |
| 52 | : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot), |
| 53 | HasSysroot(!(sysroot.empty() || sysroot == "/")) { |
| 54 | } |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | bool AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework); |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | bool AddUnmappedPath(const Twine &Path, IncludeDirGroup Group, |
| 65 | bool isFramework); |
| 66 | |
| 67 | |
| 68 | |
| 69 | void (StringRef Prefix, bool ) { |
| 70 | SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | bool AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir, |
| 77 | StringRef Dir32, StringRef Dir64, |
| 78 | const llvm::Triple &triple); |
| 79 | |
| 80 | |
| 81 | |
| 82 | void AddMinGWCPlusPlusIncludePaths(StringRef Base, |
| 83 | StringRef Arch, |
| 84 | StringRef Version); |
| 85 | |
| 86 | |
| 87 | void AddDefaultCIncludePaths(const llvm::Triple &triple, |
| 88 | const HeaderSearchOptions &HSOpts); |
| 89 | |
| 90 | |
| 91 | |
| 92 | void AddDefaultCPlusPlusIncludePaths(const LangOptions &LangOpts, |
| 93 | const llvm::Triple &triple, |
| 94 | const HeaderSearchOptions &HSOpts); |
| 95 | |
| 96 | |
| 97 | |
| 98 | void AddDefaultIncludePaths(const LangOptions &Lang, |
| 99 | const llvm::Triple &triple, |
| 100 | const HeaderSearchOptions &HSOpts); |
| 101 | |
| 102 | |
| 103 | |
| 104 | void Realize(const LangOptions &Lang); |
| 105 | }; |
| 106 | |
| 107 | } |
| 108 | |
| 109 | static bool CanPrefixSysroot(StringRef Path) { |
| 110 | #if defined(_WIN32) |
| 111 | return !Path.empty() && llvm::sys::path::is_separator(Path[0]); |
| 112 | #else |
| 113 | return llvm::sys::path::is_absolute(Path); |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | bool InitHeaderSearch::(const Twine &Path, IncludeDirGroup Group, |
| 118 | bool isFramework) { |
| 119 | |
| 120 | |
| 121 | if (HasSysroot) { |
| 122 | SmallString<256> MappedPathStorage; |
| 123 | StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); |
| 124 | if (CanPrefixSysroot(MappedPathStr)) { |
| 125 | return AddUnmappedPath(IncludeSysroot + Path, Group, isFramework); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return AddUnmappedPath(Path, Group, isFramework); |
| 130 | } |
| 131 | |
| 132 | bool InitHeaderSearch::(const Twine &Path, IncludeDirGroup Group, |
| 133 | bool isFramework) { |
| 134 | (0) . __assert_fail ("!Path.isTriviallyEmpty() && \"can't handle empty path here\"", "/home/seafit/code_projects/clang_source/clang/lib/Frontend/InitHeaderSearch.cpp", 134, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); |
| 135 | |
| 136 | FileManager &FM = Headers.getFileMgr(); |
| 137 | SmallString<256> MappedPathStorage; |
| 138 | StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); |
| 139 | |
| 140 | |
| 141 | SrcMgr::CharacteristicKind Type; |
| 142 | if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) { |
| 143 | Type = SrcMgr::C_User; |
| 144 | } else if (Group == ExternCSystem) { |
| 145 | Type = SrcMgr::C_ExternCSystem; |
| 146 | } else { |
| 147 | Type = SrcMgr::C_System; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) { |
| 152 | IncludePath.push_back( |
| 153 | std::make_pair(Group, DirectoryLookup(DE, Type, isFramework))); |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | |
| 159 | if (!isFramework) { |
| 160 | if (const FileEntry *FE = FM.getFile(MappedPathStr)) { |
| 161 | if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { |
| 162 | |
| 163 | IncludePath.push_back( |
| 164 | std::make_pair(Group, |
| 165 | DirectoryLookup(HM, Type, Group == IndexHeaderMap))); |
| 166 | return true; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | if (Verbose) |
| 172 | llvm::errs() << "ignoring nonexistent directory \"" |
| 173 | << MappedPathStr << "\"\n"; |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | bool InitHeaderSearch::(StringRef Base, |
| 178 | StringRef ArchDir, |
| 179 | StringRef Dir32, |
| 180 | StringRef Dir64, |
| 181 | const llvm::Triple &triple) { |
| 182 | |
| 183 | bool IsBaseFound = AddPath(Base, CXXSystem, false); |
| 184 | |
| 185 | |
| 186 | llvm::Triple::ArchType arch = triple.getArch(); |
| 187 | bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; |
| 188 | if (is64bit) |
| 189 | AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false); |
| 190 | else |
| 191 | AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false); |
| 192 | |
| 193 | |
| 194 | AddPath(Base + "/backward", CXXSystem, false); |
| 195 | return IsBaseFound; |
| 196 | } |
| 197 | |
| 198 | void InitHeaderSearch::(StringRef Base, |
| 199 | StringRef Arch, |
| 200 | StringRef Version) { |
| 201 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", |
| 202 | CXXSystem, false); |
| 203 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, |
| 204 | CXXSystem, false); |
| 205 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", |
| 206 | CXXSystem, false); |
| 207 | } |
| 208 | |
| 209 | void InitHeaderSearch::(const llvm::Triple &triple, |
| 210 | const HeaderSearchOptions &HSOpts) { |
| 211 | llvm::Triple::OSType os = triple.getOS(); |
| 212 | |
| 213 | if (HSOpts.UseStandardSystemIncludes) { |
| 214 | switch (os) { |
| 215 | case llvm::Triple::CloudABI: |
| 216 | case llvm::Triple::FreeBSD: |
| 217 | case llvm::Triple::NetBSD: |
| 218 | case llvm::Triple::OpenBSD: |
| 219 | case llvm::Triple::NaCl: |
| 220 | case llvm::Triple::PS4: |
| 221 | case llvm::Triple::ELFIAMCU: |
| 222 | case llvm::Triple::Fuchsia: |
| 223 | break; |
| 224 | case llvm::Triple::Win32: |
| 225 | if (triple.getEnvironment() != llvm::Triple::Cygnus) |
| 226 | break; |
| 227 | LLVM_FALLTHROUGH; |
| 228 | default: |
| 229 | |
| 230 | AddPath("/usr/local/include", System, false); |
| 231 | break; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | |
| 236 | |
| 237 | if (HSOpts.UseBuiltinIncludes) { |
| 238 | |
| 239 | |
| 240 | SmallString<128> P = StringRef(HSOpts.ResourceDir); |
| 241 | llvm::sys::path::append(P, "include"); |
| 242 | AddUnmappedPath(P, ExternCSystem, false); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | |
| 247 | if (!HSOpts.UseStandardSystemIncludes) |
| 248 | return; |
| 249 | |
| 250 | |
| 251 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 252 | if (CIncludeDirs != "") { |
| 253 | SmallVector<StringRef, 5> dirs; |
| 254 | CIncludeDirs.split(dirs, ":"); |
| 255 | for (StringRef dir : dirs) |
| 256 | AddPath(dir, ExternCSystem, false); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | switch (os) { |
| 261 | case llvm::Triple::Linux: |
| 262 | case llvm::Triple::Hurd: |
| 263 | case llvm::Triple::Solaris: |
| 264 | llvm_unreachable("Include management is handled in the driver."); |
| 265 | |
| 266 | case llvm::Triple::CloudABI: { |
| 267 | |
| 268 | SmallString<128> P = StringRef(HSOpts.ResourceDir); |
| 269 | llvm::sys::path::append(P, "../../..", triple.str(), "include"); |
| 270 | AddPath(P, System, false); |
| 271 | break; |
| 272 | } |
| 273 | |
| 274 | case llvm::Triple::Haiku: |
| 275 | AddPath("/boot/system/non-packaged/develop/headers", System, false); |
| 276 | AddPath("/boot/system/develop/headers/os", System, false); |
| 277 | AddPath("/boot/system/develop/headers/os/app", System, false); |
| 278 | AddPath("/boot/system/develop/headers/os/arch", System, false); |
| 279 | AddPath("/boot/system/develop/headers/os/device", System, false); |
| 280 | AddPath("/boot/system/develop/headers/os/drivers", System, false); |
| 281 | AddPath("/boot/system/develop/headers/os/game", System, false); |
| 282 | AddPath("/boot/system/develop/headers/os/interface", System, false); |
| 283 | AddPath("/boot/system/develop/headers/os/kernel", System, false); |
| 284 | AddPath("/boot/system/develop/headers/os/locale", System, false); |
| 285 | AddPath("/boot/system/develop/headers/os/mail", System, false); |
| 286 | AddPath("/boot/system/develop/headers/os/media", System, false); |
| 287 | AddPath("/boot/system/develop/headers/os/midi", System, false); |
| 288 | AddPath("/boot/system/develop/headers/os/midi2", System, false); |
| 289 | AddPath("/boot/system/develop/headers/os/net", System, false); |
| 290 | AddPath("/boot/system/develop/headers/os/opengl", System, false); |
| 291 | AddPath("/boot/system/develop/headers/os/storage", System, false); |
| 292 | AddPath("/boot/system/develop/headers/os/support", System, false); |
| 293 | AddPath("/boot/system/develop/headers/os/translation", System, false); |
| 294 | AddPath("/boot/system/develop/headers/os/add-ons/graphics", System, false); |
| 295 | AddPath("/boot/system/develop/headers/os/add-ons/input_server", System, false); |
| 296 | AddPath("/boot/system/develop/headers/os/add-ons/mail_daemon", System, false); |
| 297 | AddPath("/boot/system/develop/headers/os/add-ons/registrar", System, false); |
| 298 | AddPath("/boot/system/develop/headers/os/add-ons/screen_saver", System, false); |
| 299 | AddPath("/boot/system/develop/headers/os/add-ons/tracker", System, false); |
| 300 | AddPath("/boot/system/develop/headers/os/be_apps/Deskbar", System, false); |
| 301 | AddPath("/boot/system/develop/headers/os/be_apps/NetPositive", System, false); |
| 302 | AddPath("/boot/system/develop/headers/os/be_apps/Tracker", System, false); |
| 303 | AddPath("/boot/system/develop/headers/3rdparty", System, false); |
| 304 | AddPath("/boot/system/develop/headers/bsd", System, false); |
| 305 | AddPath("/boot/system/develop/headers/glibc", System, false); |
| 306 | AddPath("/boot/system/develop/headers/posix", System, false); |
| 307 | AddPath("/boot/system/develop/headers", System, false); |
| 308 | break; |
| 309 | case llvm::Triple::RTEMS: |
| 310 | break; |
| 311 | case llvm::Triple::Win32: |
| 312 | switch (triple.getEnvironment()) { |
| 313 | default: llvm_unreachable("Include management is handled in the driver."); |
| 314 | case llvm::Triple::Cygnus: |
| 315 | AddPath("/usr/include/w32api", System, false); |
| 316 | break; |
| 317 | case llvm::Triple::GNU: |
| 318 | break; |
| 319 | } |
| 320 | break; |
| 321 | default: |
| 322 | break; |
| 323 | } |
| 324 | |
| 325 | switch (os) { |
| 326 | case llvm::Triple::CloudABI: |
| 327 | case llvm::Triple::RTEMS: |
| 328 | case llvm::Triple::NaCl: |
| 329 | case llvm::Triple::ELFIAMCU: |
| 330 | case llvm::Triple::Fuchsia: |
| 331 | break; |
| 332 | case llvm::Triple::PS4: { |
| 333 | |
| 334 | std::string BaseSDKPath = ""; |
| 335 | if (!HasSysroot) { |
| 336 | const char *envValue = getenv("SCE_ORBIS_SDK_DIR"); |
| 337 | if (envValue) |
| 338 | BaseSDKPath = envValue; |
| 339 | else { |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | SmallString<128> P = StringRef(HSOpts.ResourceDir); |
| 346 | llvm::sys::path::append(P, "../../.."); |
| 347 | BaseSDKPath = P.str(); |
| 348 | } |
| 349 | } |
| 350 | AddPath(BaseSDKPath + "/target/include", System, false); |
| 351 | if (triple.isPS4CPU()) |
| 352 | AddPath(BaseSDKPath + "/target/include_common", System, false); |
| 353 | LLVM_FALLTHROUGH; |
| 354 | } |
| 355 | default: |
| 356 | AddPath("/usr/include", ExternCSystem, false); |
| 357 | break; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | void InitHeaderSearch::( |
| 362 | const LangOptions &LangOpts, const llvm::Triple &triple, |
| 363 | const HeaderSearchOptions &HSOpts) { |
| 364 | llvm::Triple::OSType os = triple.getOS(); |
| 365 | |
| 366 | |
| 367 | if (triple.isOSDarwin()) { |
| 368 | bool IsBaseFound = true; |
| 369 | switch (triple.getArch()) { |
| 370 | default: break; |
| 371 | |
| 372 | case llvm::Triple::ppc: |
| 373 | case llvm::Triple::ppc64: |
| 374 | IsBaseFound = AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 375 | "powerpc-apple-darwin10", "", |
| 376 | "ppc64", triple); |
| 377 | IsBaseFound |= AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
| 378 | "powerpc-apple-darwin10", "", |
| 379 | "ppc64", triple); |
| 380 | break; |
| 381 | |
| 382 | case llvm::Triple::x86: |
| 383 | case llvm::Triple::x86_64: |
| 384 | IsBaseFound = AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 385 | "i686-apple-darwin10", "", |
| 386 | "x86_64", triple); |
| 387 | IsBaseFound |= AddGnuCPlusPlusIncludePaths( |
| 388 | "/usr/include/c++/4.0.0", "i686-apple-darwin8", "", "", triple); |
| 389 | break; |
| 390 | |
| 391 | case llvm::Triple::arm: |
| 392 | case llvm::Triple::thumb: |
| 393 | IsBaseFound = AddGnuCPlusPlusIncludePaths( |
| 394 | "/usr/include/c++/4.2.1", "arm-apple-darwin10", "v7", "", triple); |
| 395 | IsBaseFound |= AddGnuCPlusPlusIncludePaths( |
| 396 | "/usr/include/c++/4.2.1", "arm-apple-darwin10", "v6", "", triple); |
| 397 | break; |
| 398 | |
| 399 | case llvm::Triple::aarch64: |
| 400 | IsBaseFound = AddGnuCPlusPlusIncludePaths( |
| 401 | "/usr/include/c++/4.2.1", "arm64-apple-darwin10", "", "", triple); |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | if (!IsBaseFound && |
| 406 | !(LangOpts.CUDA || LangOpts.OpenCL || LangOpts.RenderScript)) { |
| 407 | Headers.getDiags().Report(SourceLocation(), |
| 408 | diag::warn_stdlibcxx_not_found); |
| 409 | } |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | switch (os) { |
| 414 | case llvm::Triple::Linux: |
| 415 | case llvm::Triple::Hurd: |
| 416 | case llvm::Triple::Solaris: |
| 417 | llvm_unreachable("Include management is handled in the driver."); |
| 418 | break; |
| 419 | case llvm::Triple::Win32: |
| 420 | switch (triple.getEnvironment()) { |
| 421 | default: llvm_unreachable("Include management is handled in the driver."); |
| 422 | case llvm::Triple::Cygnus: |
| 423 | |
| 424 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3"); |
| 425 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3"); |
| 426 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4"); |
| 427 | |
| 428 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); |
| 429 | break; |
| 430 | } |
| 431 | break; |
| 432 | case llvm::Triple::DragonFly: |
| 433 | AddPath("/usr/include/c++/5.0", CXXSystem, false); |
| 434 | break; |
| 435 | case llvm::Triple::Minix: |
| 436 | AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3", |
| 437 | "", "", "", triple); |
| 438 | break; |
| 439 | default: |
| 440 | break; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | void InitHeaderSearch::(const LangOptions &Lang, |
| 445 | const llvm::Triple &triple, |
| 446 | const HeaderSearchOptions &HSOpts) { |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | switch (triple.getOS()) { |
| 452 | default: |
| 453 | break; |
| 454 | |
| 455 | case llvm::Triple::Linux: |
| 456 | case llvm::Triple::Hurd: |
| 457 | case llvm::Triple::Solaris: |
| 458 | return; |
| 459 | |
| 460 | case llvm::Triple::Win32: |
| 461 | if (triple.getEnvironment() != llvm::Triple::Cygnus || |
| 462 | triple.isOSBinFormatMachO()) |
| 463 | return; |
| 464 | break; |
| 465 | } |
| 466 | |
| 467 | if (Lang.CPlusPlus && !Lang.AsmPreprocessor && |
| 468 | HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) { |
| 469 | if (HSOpts.UseLibcxx) { |
| 470 | AddPath("/usr/include/c++/v1", CXXSystem, false); |
| 471 | } else { |
| 472 | AddDefaultCPlusPlusIncludePaths(Lang, triple, HSOpts); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | AddDefaultCIncludePaths(triple, HSOpts); |
| 477 | |
| 478 | |
| 479 | if (HSOpts.UseStandardSystemIncludes) { |
| 480 | if (triple.isOSDarwin()) { |
| 481 | AddPath("/System/Library/Frameworks", System, true); |
| 482 | AddPath("/Library/Frameworks", System, true); |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, |
| 491 | unsigned First, bool Verbose) { |
| 492 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; |
| 493 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; |
| 494 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; |
| 495 | unsigned NonSystemRemoved = 0; |
| 496 | for (unsigned i = First; i != SearchList.size(); ++i) { |
| 497 | unsigned DirToRemove = i; |
| 498 | |
| 499 | const DirectoryLookup &CurEntry = SearchList[i]; |
| 500 | |
| 501 | if (CurEntry.isNormalDir()) { |
| 502 | |
| 503 | if (SeenDirs.insert(CurEntry.getDir()).second) |
| 504 | continue; |
| 505 | } else if (CurEntry.isFramework()) { |
| 506 | |
| 507 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()).second) |
| 508 | continue; |
| 509 | } else { |
| 510 | (0) . __assert_fail ("CurEntry.isHeaderMap() && \"Not a headermap or normal dir?\"", "/home/seafit/code_projects/clang_source/clang/lib/Frontend/InitHeaderSearch.cpp", 510, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 511 | |
| 512 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()).second) |
| 513 | continue; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { |
| 524 | |
| 525 | unsigned FirstDir; |
| 526 | for (FirstDir = First;; ++FirstDir) { |
| 527 | (0) . __assert_fail ("FirstDir != i && \"Didn't find dupe?\"", "/home/seafit/code_projects/clang_source/clang/lib/Frontend/InitHeaderSearch.cpp", 527, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FirstDir != i && "Didn't find dupe?"); |
| 528 | |
| 529 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; |
| 530 | |
| 531 | |
| 532 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) |
| 533 | continue; |
| 534 | |
| 535 | bool isSame; |
| 536 | if (CurEntry.isNormalDir()) |
| 537 | isSame = SearchEntry.getDir() == CurEntry.getDir(); |
| 538 | else if (CurEntry.isFramework()) |
| 539 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); |
| 540 | else { |
| 541 | (0) . __assert_fail ("CurEntry.isHeaderMap() && \"Not a headermap or normal dir?\"", "/home/seafit/code_projects/clang_source/clang/lib/Frontend/InitHeaderSearch.cpp", 541, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 542 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); |
| 543 | } |
| 544 | |
| 545 | if (isSame) |
| 546 | break; |
| 547 | } |
| 548 | |
| 549 | |
| 550 | |
| 551 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) |
| 552 | DirToRemove = FirstDir; |
| 553 | } |
| 554 | |
| 555 | if (Verbose) { |
| 556 | llvm::errs() << "ignoring duplicate directory \"" |
| 557 | << CurEntry.getName() << "\"\n"; |
| 558 | if (DirToRemove != i) |
| 559 | llvm::errs() << " as it is a non-system directory that duplicates " |
| 560 | << "a system directory\n"; |
| 561 | } |
| 562 | if (DirToRemove != i) |
| 563 | ++NonSystemRemoved; |
| 564 | |
| 565 | |
| 566 | |
| 567 | SearchList.erase(SearchList.begin()+DirToRemove); |
| 568 | --i; |
| 569 | } |
| 570 | return NonSystemRemoved; |
| 571 | } |
| 572 | |
| 573 | |
| 574 | void InitHeaderSearch::(const LangOptions &Lang) { |
| 575 | |
| 576 | std::vector<DirectoryLookup> SearchList; |
| 577 | SearchList.reserve(IncludePath.size()); |
| 578 | |
| 579 | |
| 580 | for (auto &Include : IncludePath) |
| 581 | if (Include.first == Quoted) |
| 582 | SearchList.push_back(Include.second); |
| 583 | |
| 584 | |
| 585 | RemoveDuplicates(SearchList, 0, Verbose); |
| 586 | unsigned NumQuoted = SearchList.size(); |
| 587 | |
| 588 | for (auto &Include : IncludePath) |
| 589 | if (Include.first == Angled || Include.first == IndexHeaderMap) |
| 590 | SearchList.push_back(Include.second); |
| 591 | |
| 592 | RemoveDuplicates(SearchList, NumQuoted, Verbose); |
| 593 | unsigned NumAngled = SearchList.size(); |
| 594 | |
| 595 | for (auto &Include : IncludePath) |
| 596 | if (Include.first == System || Include.first == ExternCSystem || |
| 597 | (!Lang.ObjC && !Lang.CPlusPlus && Include.first == CSystem) || |
| 598 | ( Lang.CPlusPlus && |
| 599 | Include.first == CXXSystem) || |
| 600 | (Lang.ObjC && !Lang.CPlusPlus && Include.first == ObjCSystem) || |
| 601 | (Lang.ObjC && Lang.CPlusPlus && Include.first == ObjCXXSystem)) |
| 602 | SearchList.push_back(Include.second); |
| 603 | |
| 604 | for (auto &Include : IncludePath) |
| 605 | if (Include.first == After) |
| 606 | SearchList.push_back(Include.second); |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose); |
| 612 | NumAngled -= NonSystemRemoved; |
| 613 | |
| 614 | bool DontSearchCurDir = false; |
| 615 | Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir); |
| 616 | |
| 617 | Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes); |
| 618 | |
| 619 | |
| 620 | if (Verbose) { |
| 621 | llvm::errs() << "#include \"...\" search starts here:\n"; |
| 622 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { |
| 623 | if (i == NumQuoted) |
| 624 | llvm::errs() << "#include <...> search starts here:\n"; |
| 625 | StringRef Name = SearchList[i].getName(); |
| 626 | const char *Suffix; |
| 627 | if (SearchList[i].isNormalDir()) |
| 628 | Suffix = ""; |
| 629 | else if (SearchList[i].isFramework()) |
| 630 | Suffix = " (framework directory)"; |
| 631 | else { |
| 632 | (0) . __assert_fail ("SearchList[i].isHeaderMap() && \"Unknown DirectoryLookup\"", "/home/seafit/code_projects/clang_source/clang/lib/Frontend/InitHeaderSearch.cpp", 632, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); |
| 633 | Suffix = " (headermap)"; |
| 634 | } |
| 635 | llvm::errs() << " " << Name << Suffix << "\n"; |
| 636 | } |
| 637 | llvm::errs() << "End of search list.\n"; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | void clang::(HeaderSearch &HS, |
| 642 | const HeaderSearchOptions &HSOpts, |
| 643 | const LangOptions &Lang, |
| 644 | const llvm::Triple &Triple) { |
| 645 | InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); |
| 646 | |
| 647 | |
| 648 | for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { |
| 649 | const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; |
| 650 | if (E.IgnoreSysRoot) { |
| 651 | Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework); |
| 652 | } else { |
| 653 | Init.AddPath(E.Path, E.Group, E.IsFramework); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | Init.AddDefaultIncludePaths(Lang, Triple, HSOpts); |
| 658 | |
| 659 | for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i) |
| 660 | Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix, |
| 661 | HSOpts.SystemHeaderPrefixes[i].IsSystemHeader); |
| 662 | |
| 663 | if (HSOpts.UseBuiltinIncludes) { |
| 664 | |
| 665 | SmallString<128> P = StringRef(HSOpts.ResourceDir); |
| 666 | llvm::sys::path::append(P, "include"); |
| 667 | if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P)) |
| 668 | HS.getModuleMap().setBuiltinIncludeDir(Dir); |
| 669 | } |
| 670 | |
| 671 | Init.Realize(Lang); |
| 672 | } |
| 673 | |