//===--- HeaderMap.cpp - A file that acts like dir of symlinks ------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the HeaderMap interface. // //===----------------------------------------------------------------------===// #include "clang/Lex/HeaderMap.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/FileManager.h" #include "clang/Lex/HeaderMapTypes.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SwapByteOrder.h" #include "llvm/Support/SystemZ/zOSSupport.h" #include <cstring> #include <memory> #include <optional> usingnamespaceclang; /// HashHMapKey - This is the 'well known' hash function required by the file /// format, used to look up keys in the hash table. The hash table uses simple /// linear probing based on this function. static inline unsigned HashHMapKey(StringRef Str) { … } //===----------------------------------------------------------------------===// // Verification and Construction //===----------------------------------------------------------------------===// /// HeaderMap::Create - This attempts to load the specified file as a header /// map. If it doesn't look like a HeaderMap, it gives up and returns null. /// If it looks like a HeaderMap but is obviously corrupted, it puts a reason /// into the string error argument and returns null. std::unique_ptr<HeaderMap> HeaderMap::Create(FileEntryRef FE, FileManager &FM) { … } bool HeaderMapImpl::checkHeader(const llvm::MemoryBuffer &File, bool &NeedsByteSwap) { … } //===----------------------------------------------------------------------===// // Utility Methods //===----------------------------------------------------------------------===// /// getFileName - Return the filename of the headermap. StringRef HeaderMapImpl::getFileName() const { … } unsigned HeaderMapImpl::getEndianAdjustedWord(unsigned X) const { … } /// getHeader - Return a reference to the file header, in unbyte-swapped form. /// This method cannot fail. const HMapHeader &HeaderMapImpl::getHeader() const { … } /// getBucket - Return the specified hash table bucket from the header map, /// bswap'ing its fields as appropriate. If the bucket number is not valid, /// this return a bucket with an empty key (0). HMapBucket HeaderMapImpl::getBucket(unsigned BucketNo) const { … } std::optional<StringRef> HeaderMapImpl::getString(unsigned StrTabIdx) const { … } //===----------------------------------------------------------------------===// // The Main Drivers //===----------------------------------------------------------------------===// /// dump - Print the contents of this headermap to stderr. LLVM_DUMP_METHOD void HeaderMapImpl::dump() const { … } StringRef HeaderMapImpl::lookupFilename(StringRef Filename, SmallVectorImpl<char> &DestPath) const { … } StringRef HeaderMapImpl::reverseLookupFilename(StringRef DestPath) const { … }