InitHeaderSearch.cpp revision 014f9720bc53cc748aa13b0773cd67428a9e6ae4
1//===--- InitHeaderSearch.cpp - Initialize header search paths ------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements the InitHeaderSearch class. 11// 12//===----------------------------------------------------------------------===// 13 14#ifdef HAVE_CLANG_CONFIG_H 15# include "clang/Config/config.h" 16#endif 17 18#include "clang/Frontend/Utils.h" 19#include "clang/Basic/FileManager.h" 20#include "clang/Basic/LangOptions.h" 21#include "clang/Frontend/HeaderSearchOptions.h" 22#include "clang/Lex/HeaderSearch.h" 23#include "llvm/ADT/SmallString.h" 24#include "llvm/ADT/SmallPtrSet.h" 25#include "llvm/ADT/SmallVector.h" 26#include "llvm/ADT/StringExtras.h" 27#include "llvm/ADT/Triple.h" 28#include "llvm/ADT/Twine.h" 29#include "llvm/Support/raw_ostream.h" 30#include "llvm/Support/Path.h" 31#include "llvm/Config/config.h" 32#ifdef _MSC_VER 33 #define WIN32_LEAN_AND_MEAN 1 34 #include <windows.h> 35#endif 36using namespace clang; 37using namespace clang::frontend; 38 39namespace { 40 41/// InitHeaderSearch - This class makes it easier to set the search paths of 42/// a HeaderSearch object. InitHeaderSearch stores several search path lists 43/// internally, which can be sent to a HeaderSearch object in one swoop. 44class InitHeaderSearch { 45 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath; 46 typedef std::vector<std::pair<IncludeDirGroup, 47 DirectoryLookup> >::const_iterator path_iterator; 48 HeaderSearch& Headers; 49 bool Verbose; 50 std::string IncludeSysroot; 51 bool IsNotEmptyOrRoot; 52 53public: 54 55 InitHeaderSearch(HeaderSearch &HS, bool verbose, llvm::StringRef sysroot) 56 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot), 57 IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) { 58 } 59 60 /// AddPath - Add the specified path to the specified group list. 61 void AddPath(const llvm::Twine &Path, IncludeDirGroup Group, 62 bool isCXXAware, bool isUserSupplied, 63 bool isFramework, bool IgnoreSysRoot = false); 64 65 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu 66 /// libstdc++. 67 void AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, 68 llvm::StringRef ArchDir, 69 llvm::StringRef Dir32, 70 llvm::StringRef Dir64, 71 const llvm::Triple &triple); 72 73 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW 74 /// libstdc++. 75 void AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, 76 llvm::StringRef Arch, 77 llvm::StringRef Version); 78 79 /// AddMinGW64CXXPaths - Add the necessary paths to support 80 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64. 81 void AddMinGW64CXXPaths(llvm::StringRef Base); 82 83 /// AddDelimitedPaths - Add a list of paths delimited by the system PATH 84 /// separator. The processing follows that of the CPATH variable for gcc. 85 void AddDelimitedPaths(llvm::StringRef String); 86 87 // AddDefaultCIncludePaths - Add paths that should always be searched. 88 void AddDefaultCIncludePaths(const llvm::Triple &triple, 89 const HeaderSearchOptions &HSOpts); 90 91 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when 92 // compiling c++. 93 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple); 94 95 /// AddDefaultSystemIncludePaths - Adds the default system include paths so 96 /// that e.g. stdio.h is found. 97 void AddDefaultSystemIncludePaths(const LangOptions &Lang, 98 const llvm::Triple &triple, 99 const HeaderSearchOptions &HSOpts); 100 101 /// Realize - Merges all search path lists into one list and send it to 102 /// HeaderSearch. 103 void Realize(const LangOptions &Lang); 104}; 105 106} 107 108void InitHeaderSearch::AddPath(const llvm::Twine &Path, 109 IncludeDirGroup Group, bool isCXXAware, 110 bool isUserSupplied, bool isFramework, 111 bool IgnoreSysRoot) { 112 assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); 113 FileManager &FM = Headers.getFileMgr(); 114 115 // Compute the actual path, taking into consideration -isysroot. 116 llvm::SmallString<256> MappedPathStorage; 117 llvm::StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); 118 119 // Handle isysroot. 120 if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot && 121 llvm::sys::path::is_absolute(MappedPathStr) && 122 IsNotEmptyOrRoot) { 123 MappedPathStorage.clear(); 124 MappedPathStr = 125 (IncludeSysroot + Path).toStringRef(MappedPathStorage); 126 } 127 128 // Compute the DirectoryLookup type. 129 SrcMgr::CharacteristicKind Type; 130 if (Group == Quoted || Group == Angled) 131 Type = SrcMgr::C_User; 132 else if (isCXXAware) 133 Type = SrcMgr::C_System; 134 else 135 Type = SrcMgr::C_ExternCSystem; 136 137 138 // If the directory exists, add it. 139 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) { 140 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type, 141 isUserSupplied, isFramework))); 142 return; 143 } 144 145 // Check to see if this is an apple-style headermap (which are not allowed to 146 // be frameworks). 147 if (!isFramework) { 148 if (const FileEntry *FE = FM.getFile(MappedPathStr)) { 149 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { 150 // It is a headermap, add it to the search path. 151 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type, 152 isUserSupplied))); 153 return; 154 } 155 } 156 } 157 158 if (Verbose) 159 llvm::errs() << "ignoring nonexistent directory \"" 160 << MappedPathStr << "\"\n"; 161} 162 163 164void InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) { 165 if (at.empty()) // Empty string should not add '.' path. 166 return; 167 168 llvm::StringRef::size_type delim; 169 while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) { 170 if (delim == 0) 171 AddPath(".", Angled, false, true, false); 172 else 173 AddPath(at.substr(0, delim), Angled, false, true, false); 174 at = at.substr(delim + 1); 175 } 176 177 if (at.empty()) 178 AddPath(".", Angled, false, true, false); 179 else 180 AddPath(at, Angled, false, true, false); 181} 182 183void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, 184 llvm::StringRef ArchDir, 185 llvm::StringRef Dir32, 186 llvm::StringRef Dir64, 187 const llvm::Triple &triple) { 188 // Add the base dir 189 AddPath(Base, CXXSystem, true, false, false); 190 191 // Add the multilib dirs 192 llvm::Triple::ArchType arch = triple.getArch(); 193 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; 194 if (is64bit) 195 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false); 196 else 197 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false); 198 199 // Add the backward dir 200 AddPath(Base + "/backward", CXXSystem, true, false, false); 201} 202 203void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, 204 llvm::StringRef Arch, 205 llvm::StringRef Version) { 206 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", 207 CXXSystem, true, false, false); 208 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, 209 CXXSystem, true, false, false); 210 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", 211 CXXSystem, true, false, false); 212} 213 214void InitHeaderSearch::AddMinGW64CXXPaths(llvm::StringRef Base) { 215 AddPath(Base, 216 CXXSystem, true, false, false); 217 AddPath(Base + "/x86_64-w64-mingw32", 218 CXXSystem, true, false, false); 219 AddPath(Base + "/backward", 220 CXXSystem, true, false, false); 221} 222 223 // FIXME: This probably should goto to some platform utils place. 224#ifdef _MSC_VER 225 226 // Read registry string. 227 // This also supports a means to look for high-versioned keys by use 228 // of a $VERSION placeholder in the key path. 229 // $VERSION in the key path is a placeholder for the version number, 230 // causing the highest value path to be searched for and used. 231 // I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION". 232 // There can be additional characters in the component. Only the numberic 233 // characters are compared. 234static bool getSystemRegistryString(const char *keyPath, const char *valueName, 235 char *value, size_t maxLength) { 236 HKEY hRootKey = NULL; 237 HKEY hKey = NULL; 238 const char* subKey = NULL; 239 DWORD valueType; 240 DWORD valueSize = maxLength - 1; 241 long lResult; 242 bool returnValue = false; 243 if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { 244 hRootKey = HKEY_CLASSES_ROOT; 245 subKey = keyPath + 18; 246 } 247 else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { 248 hRootKey = HKEY_USERS; 249 subKey = keyPath + 11; 250 } 251 else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { 252 hRootKey = HKEY_LOCAL_MACHINE; 253 subKey = keyPath + 19; 254 } 255 else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { 256 hRootKey = HKEY_CURRENT_USER; 257 subKey = keyPath + 18; 258 } 259 else 260 return(false); 261 const char *placeHolder = strstr(subKey, "$VERSION"); 262 char bestName[256]; 263 bestName[0] = '\0'; 264 // If we have a $VERSION placeholder, do the highest-version search. 265 if (placeHolder) { 266 const char *keyEnd = placeHolder - 1; 267 const char *nextKey = placeHolder; 268 // Find end of previous key. 269 while ((keyEnd > subKey) && (*keyEnd != '\\')) 270 keyEnd--; 271 // Find end of key containing $VERSION. 272 while (*nextKey && (*nextKey != '\\')) 273 nextKey++; 274 size_t partialKeyLength = keyEnd - subKey; 275 char partialKey[256]; 276 if (partialKeyLength > sizeof(partialKey)) 277 partialKeyLength = sizeof(partialKey); 278 strncpy(partialKey, subKey, partialKeyLength); 279 partialKey[partialKeyLength] = '\0'; 280 HKEY hTopKey = NULL; 281 lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey); 282 if (lResult == ERROR_SUCCESS) { 283 char keyName[256]; 284 int bestIndex = -1; 285 double bestValue = 0.0; 286 DWORD index, size = sizeof(keyName) - 1; 287 for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL, 288 NULL, NULL, NULL) == ERROR_SUCCESS; index++) { 289 const char *sp = keyName; 290 while (*sp && !isdigit(*sp)) 291 sp++; 292 if (!*sp) 293 continue; 294 const char *ep = sp + 1; 295 while (*ep && (isdigit(*ep) || (*ep == '.'))) 296 ep++; 297 char numBuf[32]; 298 strncpy(numBuf, sp, sizeof(numBuf) - 1); 299 numBuf[sizeof(numBuf) - 1] = '\0'; 300 double value = strtod(numBuf, NULL); 301 if (value > bestValue) { 302 bestIndex = (int)index; 303 bestValue = value; 304 strcpy(bestName, keyName); 305 } 306 size = sizeof(keyName) - 1; 307 } 308 // If we found the highest versioned key, open the key and get the value. 309 if (bestIndex != -1) { 310 // Append rest of key. 311 strncat(bestName, nextKey, sizeof(bestName) - 1); 312 bestName[sizeof(bestName) - 1] = '\0'; 313 // Open the chosen key path remainder. 314 lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey); 315 if (lResult == ERROR_SUCCESS) { 316 lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, 317 (LPBYTE)value, &valueSize); 318 if (lResult == ERROR_SUCCESS) 319 returnValue = true; 320 RegCloseKey(hKey); 321 } 322 } 323 RegCloseKey(hTopKey); 324 } 325 } 326 else { 327 lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); 328 if (lResult == ERROR_SUCCESS) { 329 lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, 330 (LPBYTE)value, &valueSize); 331 if (lResult == ERROR_SUCCESS) 332 returnValue = true; 333 RegCloseKey(hKey); 334 } 335 } 336 return(returnValue); 337} 338#else // _MSC_VER 339 // Read registry string. 340static bool getSystemRegistryString(const char*, const char*, char*, size_t) { 341 return(false); 342} 343#endif // _MSC_VER 344 345 // Get Visual Studio installation directory. 346static bool getVisualStudioDir(std::string &path) { 347 // First check the environment variables that vsvars32.bat sets. 348 const char* vcinstalldir = getenv("VCINSTALLDIR"); 349 if(vcinstalldir) { 350 char *p = const_cast<char *>(strstr(vcinstalldir, "\\VC")); 351 if (p) 352 *p = '\0'; 353 path = vcinstalldir; 354 return(true); 355 } 356 357 char vsIDEInstallDir[256]; 358 char vsExpressIDEInstallDir[256]; 359 // Then try the windows registry. 360 bool hasVCDir = getSystemRegistryString( 361 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION", 362 "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1); 363 bool hasVCExpressDir = getSystemRegistryString( 364 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\$VERSION", 365 "InstallDir", vsExpressIDEInstallDir, sizeof(vsExpressIDEInstallDir) - 1); 366 // If we have both vc80 and vc90, pick version we were compiled with. 367 if (hasVCDir && vsIDEInstallDir[0]) { 368 char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); 369 if (p) 370 *p = '\0'; 371 path = vsIDEInstallDir; 372 return(true); 373 } 374 else if (hasVCExpressDir && vsExpressIDEInstallDir[0]) { 375 char *p = (char*)strstr(vsExpressIDEInstallDir, "\\Common7\\IDE"); 376 if (p) 377 *p = '\0'; 378 path = vsExpressIDEInstallDir; 379 return(true); 380 } 381 else { 382 // Try the environment. 383 const char* vs100comntools = getenv("VS100COMNTOOLS"); 384 const char* vs90comntools = getenv("VS90COMNTOOLS"); 385 const char* vs80comntools = getenv("VS80COMNTOOLS"); 386 const char* vscomntools = NULL; 387 388 // Try to find the version that we were compiled with 389 if(false) {} 390 #if (_MSC_VER >= 1600) // VC100 391 else if(vs100comntools) { 392 vscomntools = vs100comntools; 393 } 394 #elif (_MSC_VER == 1500) // VC80 395 else if(vs90comntools) { 396 vscomntools = vs90comntools; 397 } 398 #elif (_MSC_VER == 1400) // VC80 399 else if(vs80comntools) { 400 vscomntools = vs80comntools; 401 } 402 #endif 403 // Otherwise find any version we can 404 else if (vs100comntools) 405 vscomntools = vs100comntools; 406 else if (vs90comntools) 407 vscomntools = vs90comntools; 408 else if (vs80comntools) 409 vscomntools = vs80comntools; 410 411 if (vscomntools && *vscomntools) { 412 char *p = const_cast<char *>(strstr(vscomntools, "\\Common7\\Tools")); 413 if (p) 414 *p = '\0'; 415 path = vscomntools; 416 return(true); 417 } 418 else 419 return(false); 420 } 421 return(false); 422} 423 424 // Get Windows SDK installation directory. 425static bool getWindowsSDKDir(std::string &path) { 426 char windowsSDKInstallDir[256]; 427 // Try the Windows registry. 428 bool hasSDKDir = getSystemRegistryString( 429 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION", 430 "InstallationFolder", windowsSDKInstallDir, sizeof(windowsSDKInstallDir) - 1); 431 // If we have both vc80 and vc90, pick version we were compiled with. 432 if (hasSDKDir && windowsSDKInstallDir[0]) { 433 path = windowsSDKInstallDir; 434 return(true); 435 } 436 return(false); 437} 438 439void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, 440 const HeaderSearchOptions &HSOpts) { 441 llvm::Triple::OSType os = triple.getOS(); 442 443 switch (os) { 444 case llvm::Triple::FreeBSD: 445 case llvm::Triple::NetBSD: 446 break; 447 default: 448 // FIXME: temporary hack: hard-coded paths. 449 AddPath("/usr/local/include", System, true, false, false); 450 break; 451 } 452 453 // Builtin includes use #include_next directives and should be positioned 454 // just prior C include dirs. 455 if (HSOpts.UseBuiltinIncludes) { 456 // Ignore the sys root, we *always* look for clang headers relative to 457 // supplied path. 458 llvm::sys::Path P(HSOpts.ResourceDir); 459 P.appendComponent("include"); 460 AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true); 461 } 462 463 // Add dirs specified via 'configure --with-c-include-dirs'. 464 llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS); 465 if (CIncludeDirs != "") { 466 llvm::SmallVector<llvm::StringRef, 5> dirs; 467 CIncludeDirs.split(dirs, ":"); 468 for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin(); 469 i != dirs.end(); 470 ++i) 471 AddPath(*i, System, false, false, false); 472 return; 473 } 474 475 switch (os) { 476 case llvm::Triple::Win32: { 477 std::string VSDir; 478 std::string WindowsSDKDir; 479 if (getVisualStudioDir(VSDir)) { 480 AddPath(VSDir + "\\VC\\include", System, false, false, false); 481 if (getWindowsSDKDir(WindowsSDKDir)) 482 AddPath(WindowsSDKDir + "\\include", System, false, false, false); 483 else 484 AddPath(VSDir + "\\VC\\PlatformSDK\\Include", 485 System, false, false, false); 486 } else { 487 // Default install paths. 488 AddPath("C:/Program Files/Microsoft Visual Studio 10.0/VC/include", 489 System, false, false, false); 490 AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include", 491 System, false, false, false); 492 AddPath( 493 "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", 494 System, false, false, false); 495 AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include", 496 System, false, false, false); 497 AddPath( 498 "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include", 499 System, false, false, false); 500 } 501 break; 502 } 503 case llvm::Triple::Haiku: 504 AddPath("/boot/common/include", System, true, false, false); 505 AddPath("/boot/develop/headers/os", System, true, false, false); 506 AddPath("/boot/develop/headers/os/app", System, true, false, false); 507 AddPath("/boot/develop/headers/os/arch", System, true, false, false); 508 AddPath("/boot/develop/headers/os/device", System, true, false, false); 509 AddPath("/boot/develop/headers/os/drivers", System, true, false, false); 510 AddPath("/boot/develop/headers/os/game", System, true, false, false); 511 AddPath("/boot/develop/headers/os/interface", System, true, false, false); 512 AddPath("/boot/develop/headers/os/kernel", System, true, false, false); 513 AddPath("/boot/develop/headers/os/locale", System, true, false, false); 514 AddPath("/boot/develop/headers/os/mail", System, true, false, false); 515 AddPath("/boot/develop/headers/os/media", System, true, false, false); 516 AddPath("/boot/develop/headers/os/midi", System, true, false, false); 517 AddPath("/boot/develop/headers/os/midi2", System, true, false, false); 518 AddPath("/boot/develop/headers/os/net", System, true, false, false); 519 AddPath("/boot/develop/headers/os/storage", System, true, false, false); 520 AddPath("/boot/develop/headers/os/support", System, true, false, false); 521 AddPath("/boot/develop/headers/os/translation", 522 System, true, false, false); 523 AddPath("/boot/develop/headers/os/add-ons/graphics", 524 System, true, false, false); 525 AddPath("/boot/develop/headers/os/add-ons/input_server", 526 System, true, false, false); 527 AddPath("/boot/develop/headers/os/add-ons/screen_saver", 528 System, true, false, false); 529 AddPath("/boot/develop/headers/os/add-ons/tracker", 530 System, true, false, false); 531 AddPath("/boot/develop/headers/os/be_apps/Deskbar", 532 System, true, false, false); 533 AddPath("/boot/develop/headers/os/be_apps/NetPositive", 534 System, true, false, false); 535 AddPath("/boot/develop/headers/os/be_apps/Tracker", 536 System, true, false, false); 537 AddPath("/boot/develop/headers/cpp", System, true, false, false); 538 AddPath("/boot/develop/headers/cpp/i586-pc-haiku", 539 System, true, false, false); 540 AddPath("/boot/develop/headers/3rdparty", System, true, false, false); 541 AddPath("/boot/develop/headers/bsd", System, true, false, false); 542 AddPath("/boot/develop/headers/glibc", System, true, false, false); 543 AddPath("/boot/develop/headers/posix", System, true, false, false); 544 AddPath("/boot/develop/headers", System, true, false, false); 545 break; 546 case llvm::Triple::Cygwin: 547 AddPath("/usr/include/w32api", System, true, false, false); 548 break; 549 case llvm::Triple::MinGW32: 550 // FIXME: We should be aware of i686-w64-mingw32. 551 if (triple.getArch() == llvm::Triple::x86_64) 552 AddPath("c:/mingw/x86_64-w64-mingw32/include", 553 System, true, false, false); 554 AddPath("/mingw/include", System, true, false, false); 555 AddPath("c:/mingw/include", System, true, false, false); 556 break; 557 default: 558 break; 559 } 560 561 AddPath("/usr/include", System, false, false, false); 562} 563 564void InitHeaderSearch:: 565AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) { 566 llvm::Triple::OSType os = triple.getOS(); 567 llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT); 568 if (CxxIncludeRoot != "") { 569 llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH); 570 if (CxxIncludeArch == "") 571 AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(), 572 CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, 573 triple); 574 else 575 AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH, 576 CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, 577 triple); 578 return; 579 } 580 // FIXME: temporary hack: hard-coded paths. 581 582 if (triple.isOSDarwin()) { 583 switch (triple.getArch()) { 584 default: break; 585 586 case llvm::Triple::ppc: 587 case llvm::Triple::ppc64: 588 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 589 "powerpc-apple-darwin10", "", "ppc64", 590 triple); 591 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", 592 "powerpc-apple-darwin10", "", "ppc64", 593 triple); 594 break; 595 596 case llvm::Triple::x86: 597 case llvm::Triple::x86_64: 598 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 599 "i686-apple-darwin10", "", "x86_64", triple); 600 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", 601 "i686-apple-darwin8", "", "", triple); 602 break; 603 604 case llvm::Triple::arm: 605 case llvm::Triple::thumb: 606 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 607 "arm-apple-darwin10", "v7", "", triple); 608 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 609 "arm-apple-darwin10", "v6", "", triple); 610 break; 611 } 612 return; 613 } 614 615 switch (os) { 616 case llvm::Triple::Cygwin: 617 // Cygwin-1.7 618 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4"); 619 // g++-4 / Cygwin-1.5 620 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); 621 // FIXME: Do we support g++-3.4.4? 622 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4"); 623 break; 624 case llvm::Triple::MinGW32: 625 // FIXME: We should be aware of i686-w64-mingw32. 626 if (triple.getArch() == llvm::Triple::x86_64) { 627 // mingw-w64-20110207 628 AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.3"); 629 // mingw-w64-20101129 630 AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.2"); 631 } 632 // Try gcc 4.5.2 (MSYS) 633 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); 634 // Try gcc 4.5.0 635 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0"); 636 // Try gcc 4.4.0 637 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); 638 // Try gcc 4.3.0 639 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); 640 break; 641 case llvm::Triple::DragonFly: 642 AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false); 643 break; 644 case llvm::Triple::Linux: 645 //===------------------------------------------------------------------===// 646 // Debian based distros. 647 // Note: these distros symlink /usr/include/c++/X.Y.Z -> X.Y 648 //===------------------------------------------------------------------===// 649 // Ubuntu 10.10 "Maverick Meerkat" -- gcc-4.4.5 650 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 651 "i686-linux-gnu", "", "64", triple); 652 // The rest of 10.10 is the same as previous versions. 653 654 // Ubuntu 10.04 LTS "Lucid Lynx" -- gcc-4.4.3 655 // Ubuntu 9.10 "Karmic Koala" -- gcc-4.4.1 656 // Debian 6.0 "squeeze" -- gcc-4.4.2 657 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 658 "x86_64-linux-gnu", "32", "", triple); 659 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 660 "i486-linux-gnu", "", "64", triple); 661 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 662 "arm-linux-gnueabi", "", "", triple); 663 // Ubuntu 9.04 "Jaunty Jackalope" -- gcc-4.3.3 664 // Ubuntu 8.10 "Intrepid Ibex" -- gcc-4.3.2 665 // Debian 5.0 "lenny" -- gcc-4.3.2 666 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 667 "x86_64-linux-gnu", "32", "", triple); 668 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 669 "i486-linux-gnu", "", "64", triple); 670 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 671 "arm-linux-gnueabi", "", "", triple); 672 // Ubuntu 8.04.4 LTS "Hardy Heron" -- gcc-4.2.4 673 // Ubuntu 8.04.[0-3] LTS "Hardy Heron" -- gcc-4.2.3 674 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", 675 "x86_64-linux-gnu", "32", "", triple); 676 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", 677 "i486-linux-gnu", "", "64", triple); 678 // Ubuntu 7.10 "Gutsy Gibbon" -- gcc-4.1.3 679 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1", 680 "x86_64-linux-gnu", "32", "", triple); 681 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1", 682 "i486-linux-gnu", "", "64", triple); 683 684 //===------------------------------------------------------------------===// 685 // Redhat based distros. 686 //===------------------------------------------------------------------===// 687 // Fedora 15 688 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0", 689 "x86_64-redhat-linux", "32", "", triple); 690 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0", 691 "i686-redhat-linux", "", "", triple); 692 // Fedora 14 693 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1", 694 "x86_64-redhat-linux", "32", "", triple); 695 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1", 696 "i686-redhat-linux", "", "", triple); 697 // Fedora 13 698 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4", 699 "x86_64-redhat-linux", "32", "", triple); 700 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4", 701 "i686-redhat-linux","", "", triple); 702 // Fedora 12 703 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", 704 "x86_64-redhat-linux", "32", "", triple); 705 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", 706 "i686-redhat-linux","", "", triple); 707 // Fedora 12 (pre-FEB-2010) 708 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", 709 "x86_64-redhat-linux", "32", "", triple); 710 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", 711 "i686-redhat-linux","", "", triple); 712 // Fedora 11 713 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", 714 "x86_64-redhat-linux", "32", "", triple); 715 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", 716 "i586-redhat-linux","", "", triple); 717 // Fedora 10 718 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", 719 "x86_64-redhat-linux", "32", "", triple); 720 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", 721 "i386-redhat-linux","", "", triple); 722 // Fedora 9 723 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", 724 "x86_64-redhat-linux", "32", "", triple); 725 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", 726 "i386-redhat-linux", "", "", triple); 727 // Fedora 8 728 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", 729 "x86_64-redhat-linux", "", "", triple); 730 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", 731 "i386-redhat-linux", "", "", triple); 732 733 //===------------------------------------------------------------------===// 734 735 // Exherbo (2010-01-25) 736 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", 737 "x86_64-pc-linux-gnu", "32", "", triple); 738 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", 739 "i686-pc-linux-gnu", "", "", triple); 740 741 // openSUSE 11.1 32 bit 742 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 743 "i586-suse-linux", "", "", triple); 744 // openSUSE 11.1 64 bit 745 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 746 "x86_64-suse-linux", "32", "", triple); 747 // openSUSE 11.2 748 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 749 "i586-suse-linux", "", "", triple); 750 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 751 "x86_64-suse-linux", "", "", triple); 752 753 // openSUSE 11.4 754 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5", 755 "i586-suse-linux", "", "", triple); 756 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5", 757 "x86_64-suse-linux", "", "", triple); 758 759 // Arch Linux 2008-06-24 760 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", 761 "i686-pc-linux-gnu", "", "", triple); 762 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", 763 "x86_64-unknown-linux-gnu", "", "", triple); 764 765 // Arch Linux gcc 4.6 766 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0", 767 "i686-pc-linux-gnu", "", "", triple); 768 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0", 769 "x86_64-unknown-linux-gnu", "", "", triple); 770 771 // Gentoo x86 gcc 4.5.2 772 AddGnuCPlusPlusIncludePaths( 773 "/usr/lib/gcc/i686-pc-linux-gnu/4.5.2/include/g++-v4", 774 "i686-pc-linux-gnu", "", "", triple); 775 // Gentoo x86 gcc 4.4.5 776 AddGnuCPlusPlusIncludePaths( 777 "/usr/lib/gcc/i686-pc-linux-gnu/4.4.5/include/g++-v4", 778 "i686-pc-linux-gnu", "", "", triple); 779 // Gentoo x86 gcc 4.4.4 780 AddGnuCPlusPlusIncludePaths( 781 "/usr/lib/gcc/i686-pc-linux-gnu/4.4.4/include/g++-v4", 782 "i686-pc-linux-gnu", "", "", triple); 783 // Gentoo x86 2010.0 stable 784 AddGnuCPlusPlusIncludePaths( 785 "/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/g++-v4", 786 "i686-pc-linux-gnu", "", "", triple); 787 // Gentoo x86 2009.1 stable 788 AddGnuCPlusPlusIncludePaths( 789 "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4", 790 "i686-pc-linux-gnu", "", "", triple); 791 // Gentoo x86 2009.0 stable 792 AddGnuCPlusPlusIncludePaths( 793 "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4", 794 "i686-pc-linux-gnu", "", "", triple); 795 // Gentoo x86 2008.0 stable 796 AddGnuCPlusPlusIncludePaths( 797 "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", 798 "i686-pc-linux-gnu", "", "", triple); 799 // Gentoo x86 llvm-gcc trunk 800 AddGnuCPlusPlusIncludePaths( 801 "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1", 802 "i686-pc-linux-gnu", "", "", triple); 803 804 // Gentoo amd64 gcc 4.5.2 805 AddGnuCPlusPlusIncludePaths( 806 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4", 807 "x86_64-pc-linux-gnu", "32", "", triple); 808 // Gentoo amd64 gcc 4.4.5 809 AddGnuCPlusPlusIncludePaths( 810 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include/g++-v4", 811 "x86_64-pc-linux-gnu", "32", "", triple); 812 // Gentoo amd64 gcc 4.4.4 813 AddGnuCPlusPlusIncludePaths( 814 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4", 815 "x86_64-pc-linux-gnu", "32", "", triple); 816 // Gentoo amd64 gcc 4.4.3 817 AddGnuCPlusPlusIncludePaths( 818 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4", 819 "x86_64-pc-linux-gnu", "32", "", triple); 820 // Gentoo amd64 gcc 4.3.2 821 AddGnuCPlusPlusIncludePaths( 822 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4", 823 "x86_64-pc-linux-gnu", "", "", triple); 824 // Gentoo amd64 stable 825 AddGnuCPlusPlusIncludePaths( 826 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", 827 "x86_64-pc-linux-gnu", "", "", triple); 828 829 // Gentoo amd64 llvm-gcc trunk 830 AddGnuCPlusPlusIncludePaths( 831 "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1", 832 "x86_64-pc-linux-gnu", "", "", triple); 833 834 break; 835 case llvm::Triple::FreeBSD: 836 // FreeBSD 8.0 837 // FreeBSD 7.3 838 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple); 839 break; 840 case llvm::Triple::NetBSD: 841 AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple); 842 break; 843 case llvm::Triple::OpenBSD: { 844 std::string t = triple.getTriple(); 845 if (t.substr(0, 6) == "x86_64") 846 t.replace(0, 6, "amd64"); 847 AddGnuCPlusPlusIncludePaths("/usr/include/g++", 848 t, "", "", triple); 849 break; 850 } 851 case llvm::Triple::Minix: 852 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3", 853 "", "", "", triple); 854 break; 855 case llvm::Triple::Solaris: 856 // Solaris - Fall though.. 857 case llvm::Triple::AuroraUX: 858 // AuroraUX 859 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", 860 "i386-pc-solaris2.11", "", "", triple); 861 break; 862 default: 863 break; 864 } 865} 866 867void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, 868 const llvm::Triple &triple, 869 const HeaderSearchOptions &HSOpts) { 870 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes) 871 AddDefaultCPlusPlusIncludePaths(triple); 872 873 AddDefaultCIncludePaths(triple, HSOpts); 874 875 // Add the default framework include paths on Darwin. 876 if (triple.isOSDarwin()) { 877 AddPath("/System/Library/Frameworks", System, true, false, true); 878 AddPath("/Library/Frameworks", System, true, false, true); 879 } 880} 881 882/// RemoveDuplicates - If there are duplicate directory entries in the specified 883/// search list, remove the later (dead) ones. 884static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, 885 unsigned First, bool Verbose) { 886 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; 887 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; 888 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; 889 for (unsigned i = First; i != SearchList.size(); ++i) { 890 unsigned DirToRemove = i; 891 892 const DirectoryLookup &CurEntry = SearchList[i]; 893 894 if (CurEntry.isNormalDir()) { 895 // If this isn't the first time we've seen this dir, remove it. 896 if (SeenDirs.insert(CurEntry.getDir())) 897 continue; 898 } else if (CurEntry.isFramework()) { 899 // If this isn't the first time we've seen this framework dir, remove it. 900 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) 901 continue; 902 } else { 903 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 904 // If this isn't the first time we've seen this headermap, remove it. 905 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) 906 continue; 907 } 908 909 // If we have a normal #include dir/framework/headermap that is shadowed 910 // later in the chain by a system include location, we actually want to 911 // ignore the user's request and drop the user dir... keeping the system 912 // dir. This is weird, but required to emulate GCC's search path correctly. 913 // 914 // Since dupes of system dirs are rare, just rescan to find the original 915 // that we're nuking instead of using a DenseMap. 916 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { 917 // Find the dir that this is the same of. 918 unsigned FirstDir; 919 for (FirstDir = 0; ; ++FirstDir) { 920 assert(FirstDir != i && "Didn't find dupe?"); 921 922 const DirectoryLookup &SearchEntry = SearchList[FirstDir]; 923 924 // If these are different lookup types, then they can't be the dupe. 925 if (SearchEntry.getLookupType() != CurEntry.getLookupType()) 926 continue; 927 928 bool isSame; 929 if (CurEntry.isNormalDir()) 930 isSame = SearchEntry.getDir() == CurEntry.getDir(); 931 else if (CurEntry.isFramework()) 932 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); 933 else { 934 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 935 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); 936 } 937 938 if (isSame) 939 break; 940 } 941 942 // If the first dir in the search path is a non-system dir, zap it 943 // instead of the system one. 944 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) 945 DirToRemove = FirstDir; 946 } 947 948 if (Verbose) { 949 llvm::errs() << "ignoring duplicate directory \"" 950 << CurEntry.getName() << "\"\n"; 951 if (DirToRemove != i) 952 llvm::errs() << " as it is a non-system directory that duplicates " 953 << "a system directory\n"; 954 } 955 956 // This is reached if the current entry is a duplicate. Remove the 957 // DirToRemove (usually the current dir). 958 SearchList.erase(SearchList.begin()+DirToRemove); 959 --i; 960 } 961} 962 963 964void InitHeaderSearch::Realize(const LangOptions &Lang) { 965 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. 966 std::vector<DirectoryLookup> SearchList; 967 SearchList.reserve(IncludePath.size()); 968 969 /* Quoted arguments go first. */ 970 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 971 it != ie; ++it) { 972 if (it->first == Quoted) 973 SearchList.push_back(it->second); 974 } 975 /* Deduplicate and remember index */ 976 RemoveDuplicates(SearchList, 0, Verbose); 977 unsigned quoted = SearchList.size(); 978 979 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 980 it != ie; ++it) { 981 if (it->first == Angled) 982 SearchList.push_back(it->second); 983 } 984 985 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 986 it != ie; ++it) { 987 if (it->first == System || (Lang.CPlusPlus && it->first == CXXSystem)) 988 SearchList.push_back(it->second); 989 } 990 991 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 992 it != ie; ++it) { 993 if (it->first == After) 994 SearchList.push_back(it->second); 995 } 996 997 RemoveDuplicates(SearchList, quoted, Verbose); 998 999 bool DontSearchCurDir = false; // TODO: set to true if -I- is set? 1000 Headers.SetSearchPaths(SearchList, quoted, DontSearchCurDir); 1001 1002 // If verbose, print the list of directories that will be searched. 1003 if (Verbose) { 1004 llvm::errs() << "#include \"...\" search starts here:\n"; 1005 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { 1006 if (i == quoted) 1007 llvm::errs() << "#include <...> search starts here:\n"; 1008 const char *Name = SearchList[i].getName(); 1009 const char *Suffix; 1010 if (SearchList[i].isNormalDir()) 1011 Suffix = ""; 1012 else if (SearchList[i].isFramework()) 1013 Suffix = " (framework directory)"; 1014 else { 1015 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); 1016 Suffix = " (headermap)"; 1017 } 1018 llvm::errs() << " " << Name << Suffix << "\n"; 1019 } 1020 llvm::errs() << "End of search list.\n"; 1021 } 1022} 1023 1024void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, 1025 const HeaderSearchOptions &HSOpts, 1026 const LangOptions &Lang, 1027 const llvm::Triple &Triple) { 1028 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); 1029 1030 // Add the user defined entries. 1031 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { 1032 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; 1033 Init.AddPath(E.Path, E.Group, false, E.IsUserSupplied, E.IsFramework, 1034 !E.IsSysRootRelative); 1035 } 1036 1037 // Add entries from CPATH and friends. 1038 Init.AddDelimitedPaths(HSOpts.EnvIncPath); 1039 if (Lang.CPlusPlus && Lang.ObjC1) 1040 Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath); 1041 else if (Lang.CPlusPlus) 1042 Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath); 1043 else if (Lang.ObjC1) 1044 Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath); 1045 else 1046 Init.AddDelimitedPaths(HSOpts.CEnvIncPath); 1047 1048 if (HSOpts.UseStandardIncludes) 1049 Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts); 1050 1051 Init.Realize(Lang); 1052} 1053