1c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===--- SourceManager.h - Track and cache source files ---------*- C++ -*-===// 2c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 3c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// The LLVM Compiler Infrastructure 4c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 5c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file is distributed under the University of Illinois Open Source 6c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// License. See LICENSE.TXT for details. 7c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 8c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 9c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 10c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \file 11c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Defines the SourceManager interface. 12c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 13c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// There are three different types of locations in a %file: a spelling 14c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// location, an expansion location, and a presumed location. 15c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 16c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Given an example of: 17c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \code 18c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// #define min(x, y) x < y ? x : y 19c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \endcode 20c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 21c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// and then later on a use of min: 22c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \code 23c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// #line 17 24c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// return min(a, b); 25c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \endcode 26c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 27c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// The expansion location is the line in the source code where the macro 28c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// was expanded (the return statement), the spelling location is the 29c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// location in the source where the macro was originally defined, 30c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// and the presumed location is where the line directive states that 31c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// the line is 17, or any other line. 32c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 33c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 34c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 35c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H 36c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#define LLVM_CLANG_BASIC_SOURCEMANAGER_H 37c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 38c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "clang/Basic/FileManager.h" 39c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "clang/Basic/LLVM.h" 40c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "clang/Basic/SourceLocation.h" 41c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/ArrayRef.h" 42c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/BitVector.h" 43c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/DenseMap.h" 44c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/DenseSet.h" 45c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/IntrusiveRefCntPtr.h" 46c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/PointerIntPair.h" 47c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/SmallVector.h" 48c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/StringRef.h" 49c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/Allocator.h" 50c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/Compiler.h" 51c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/MemoryBuffer.h" 52c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <algorithm> 53c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <cassert> 54c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <cstddef> 55c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <cstdint> 56c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <map> 57c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <memory> 58c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <string> 59c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <utility> 60c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <vector> 61c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 62c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace clang { 63c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 64c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ASTReader; 65c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ASTWriter; 66c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass DiagnosticsEngine; 67c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass LineTableInfo; 68c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass SourceManager; 69c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 70c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Public enums and private classes that are part of the 71c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// SourceManager implementation. 72c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 73c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace SrcMgr { 74c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 75c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Indicates whether a file or directory holds normal user code, 76c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// system code, or system code which is implicitly 'extern "C"' in C++ mode. 77c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 78c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Entire directories can be tagged with this (this is maintained by 79c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// DirectoryLookup and friends) as can specific FileInfos when a \#pragma 80c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// system_header is seen or in various other cases. 81c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 82c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot enum CharacteristicKind { 83c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot C_User, C_System, C_ExternCSystem, C_User_ModuleMap, C_System_ModuleMap 84c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 85c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 86c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Determine whether a file / directory characteristic is for system code. 87c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot inline bool isSystem(CharacteristicKind CK) { 88c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return CK != C_User && CK != C_User_ModuleMap; 89c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 90c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 91c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Determine whether a file characteristic is for a module map. 92c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot inline bool isModuleMap(CharacteristicKind CK) { 93c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return CK == C_User_ModuleMap || CK == C_System_ModuleMap; 94c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 95c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 96c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief One instance of this struct is kept for every file loaded or used. 97c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 98c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This object owns the MemoryBuffer object. 99c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot class LLVM_ALIGNAS(8) ContentCache { 100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot enum CCFlags { 101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Whether the buffer is invalid. 102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot InvalidFlag = 0x01, 103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Whether the buffer should not be freed on destruction. 104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DoNotFreeFlag = 0x02 105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The actual buffer containing the characters from the input 108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// file. 109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is owned by the ContentCache object. The bits indicate 111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// whether the buffer is invalid. 112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable llvm::PointerIntPair<llvm::MemoryBuffer *, 2> Buffer; 113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot public: 115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Reference to the file entry representing this ContentCache. 116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This reference does not own the FileEntry object. 118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// It is possible for this to be NULL if the ContentCache encapsulates 120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// an imaginary text buffer. 121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const FileEntry *OrigEntry; 122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief References the file which the contents were actually loaded from. 124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Can be different from 'Entry' if we overridden the contents of one file 126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// with the contents of another file. 127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const FileEntry *ContentsEntry; 128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief A bump pointer allocated array of offsets for each source line. 130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is lazily computed. This is owned by the SourceManager 132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// BumpPointerAllocator object. 133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned *SourceLineCache; 134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The number of lines in this ContentCache. 136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is only valid if SourceLineCache is non-null. 138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned NumLines; 139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Indicates whether the buffer itself was provided to override 141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// the actual file contents. 142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// When true, the original entry may be a virtual file that does not 144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// exist. 145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned BufferOverridden : 1; 146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief True if this content cache was initially created for a source 148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// file considered as a system one. 149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned IsSystemFile : 1; 150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief True if this file may be transient, that is, if it might not 152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// exist at some later point in time when this content entry is used, 153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// after serialization and deserialization. 154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned IsTransient : 1; 155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ContentCache(const FileEntry *Ent = nullptr) : ContentCache(Ent, Ent) {} 157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ContentCache(const FileEntry *Ent, const FileEntry *contentEnt) 159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : Buffer(nullptr, false), OrigEntry(Ent), ContentsEntry(contentEnt), 160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLineCache(nullptr), NumLines(0), BufferOverridden(false), 161c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot IsSystemFile(false), IsTransient(false) {} 162c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 163c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// The copy ctor does not allow copies where source object has either 164c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory 165c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// is not transferred, so this is a logical error. 166c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ContentCache(const ContentCache &RHS) 167c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : Buffer(nullptr, false), SourceLineCache(nullptr), 168c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BufferOverridden(false), IsSystemFile(false), IsTransient(false) { 169c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot OrigEntry = RHS.OrigEntry; 170c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ContentsEntry = RHS.ContentsEntry; 171c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 172c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(RHS.Buffer.getPointer() == nullptr && 173c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot RHS.SourceLineCache == nullptr && 174c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot "Passed ContentCache object cannot own a buffer."); 175c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 176c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot NumLines = RHS.NumLines; 177c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 178c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 179c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ContentCache &operator=(const ContentCache& RHS) = delete; 180c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 181c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ~ContentCache(); 182c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 183c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the memory buffer for the associated content. 184c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 185c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Diag Object through which diagnostics will be emitted if the 186c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// buffer cannot be retrieved. 187c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 188c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Loc If specified, is the location that invalid file diagnostics 189c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// will be emitted at. 190c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 191c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Invalid If non-NULL, will be set \c true if an error occurred. 192c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::MemoryBuffer *getBuffer(DiagnosticsEngine &Diag, 193c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SourceManager &SM, 194c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation Loc = SourceLocation(), 195c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const; 196c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 197c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the size of the content encapsulated by this 198c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// ContentCache. 199c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 200c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This can be the size of the source file or the size of an 201c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// arbitrary scratch buffer. If the ContentCache encapsulates a source 202c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// file this size is retrieved from the file's FileEntry. 203c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getSize() const; 204c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 205c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the number of bytes actually mapped for this 206c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// ContentCache. 207c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 208c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This can be 0 if the MemBuffer was not actually expanded. 209c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getSizeBytesMapped() const; 210c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 211c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Returns the kind of memory used to back the memory buffer for 212c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// this content cache. This is used for performance analysis. 213c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const; 214c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 215c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the underlying buffer, returning NULL if the buffer is not 216c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// yet available. 217c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::MemoryBuffer *getRawBuffer() const { return Buffer.getPointer(); } 218c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 219c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Replace the existing buffer (which will be deleted) 220c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// with the given buffer. 221c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree = false); 222c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 223c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Determine whether the buffer itself is invalid. 224c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isBufferInvalid() const { 225c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Buffer.getInt() & InvalidFlag; 226c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 227c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 228c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Determine whether the buffer should be freed. 229c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool shouldFreeBuffer() const { 230c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return (Buffer.getInt() & DoNotFreeFlag) == 0; 231c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 232c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 233c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 234c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Assert that the \c ContentCache objects will always be 8-byte aligned so 235c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // that we can pack 3 bits of integer into pointers to such objects. 236c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static_assert(alignof(ContentCache) >= 8, 237c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot "ContentCache must be 8-byte aligned."); 238c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 239c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Information about a FileID, basically just the logical file 240c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// that it represents and include stack information. 241c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 242c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Each FileInfo has include stack information, indicating where it came 243c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// from. This information encodes the \#include chain that a token was 244c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// expanded from. The main include file has an invalid IncludeLoc. 245c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 246c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// FileInfos contain a "ContentCache *", with the contents of the file. 247c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 248c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot class FileInfo { 249c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The location of the \#include that brought in this file. 250c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 251c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is an invalid SLOC for the main file (top of the \#include chain). 252c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned IncludeLoc; // Really a SourceLocation 253c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 254c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Number of FileIDs (files and macros) that were created during 255c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// preprocessing of this \#include, including this SLocEntry. 256c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 257c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Zero means the preprocessor didn't provide such info for this SLocEntry. 258c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned NumCreatedFIDs : 31; 259c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 260c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Whether this FileInfo has any \#line directives. 261c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned HasLineDirectives : 1; 262c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 263c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The content cache and the characteristic of the file. 264c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::PointerIntPair<const ContentCache*, 3, CharacteristicKind> 265c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ContentAndKind; 266c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 267c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class clang::SourceManager; 268c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class clang::ASTWriter; 269c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class clang::ASTReader; 270c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 271c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot public: 272c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return a FileInfo object. 273c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static FileInfo get(SourceLocation IL, const ContentCache *Con, 274c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot CharacteristicKind FileCharacter) { 275c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileInfo X; 276c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot X.IncludeLoc = IL.getRawEncoding(); 277c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot X.NumCreatedFIDs = 0; 278c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot X.HasLineDirectives = false; 279c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot X.ContentAndKind.setPointer(Con); 280c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot X.ContentAndKind.setInt(FileCharacter); 281c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return X; 282c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 283c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 284c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getIncludeLoc() const { 285c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SourceLocation::getFromRawEncoding(IncludeLoc); 286c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 287c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 288c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ContentCache *getContentCache() const { 289c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ContentAndKind.getPointer(); 290c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 291c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 292c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return whether this is a system header or not. 293c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot CharacteristicKind getFileCharacteristic() const { 294c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ContentAndKind.getInt(); 295c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 296c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 297c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return true if this FileID has \#line directives in it. 298c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool hasLineDirectives() const { return HasLineDirectives; } 299c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 300c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Set the flag that indicates that this FileID has 301c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// line table entries associated with it. 302c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setHasLineDirectives() { 303c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot HasLineDirectives = true; 304c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 305c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 306c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 307c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Each ExpansionInfo encodes the expansion location - where 308c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// the token was ultimately expanded, and the SpellingLoc - where the actual 309c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// character data for the token came from. 310c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot class ExpansionInfo { 311c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Really these are all SourceLocations. 312c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 313c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Where the spelling for the token can be found. 314c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned SpellingLoc; 315c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 316c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// In a macro expansion, ExpansionLocStart and ExpansionLocEnd 317c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// indicate the start and end of the expansion. In object-like macros, 318c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// they will be the same. In a function-like macro expansion, the start 319c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// will be the identifier and the end will be the ')'. Finally, in 320c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// macro-argument instantiations, the end will be 'SourceLocation()', an 321c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// invalid location. 322c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned ExpansionLocStart, ExpansionLocEnd; 323c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 324c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot public: 325c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getSpellingLoc() const { 326c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SourceLocation::getFromRawEncoding(SpellingLoc); 327c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 328c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 329c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getExpansionLocStart() const { 330c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SourceLocation::getFromRawEncoding(ExpansionLocStart); 331c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 332c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 333c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getExpansionLocEnd() const { 334c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation EndLoc = 335c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation::getFromRawEncoding(ExpansionLocEnd); 336c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return EndLoc.isInvalid() ? getExpansionLocStart() : EndLoc; 337c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 338c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 339c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<SourceLocation,SourceLocation> getExpansionLocRange() const { 340c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::make_pair(getExpansionLocStart(), getExpansionLocEnd()); 341c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 342c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 343c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isMacroArgExpansion() const { 344c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Note that this needs to return false for default constructed objects. 345c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getExpansionLocStart().isValid() && 346c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation::getFromRawEncoding(ExpansionLocEnd).isInvalid(); 347c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 348c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 349c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isMacroBodyExpansion() const { 350c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getExpansionLocStart().isValid() && 351c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation::getFromRawEncoding(ExpansionLocEnd).isValid(); 352c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 353c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 354c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isFunctionMacroExpansion() const { 355c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getExpansionLocStart().isValid() && 356c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getExpansionLocStart() != getExpansionLocEnd(); 357c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 358c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 359c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return a ExpansionInfo for an expansion. 360c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 361c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Start and End specify the expansion range (where the macro is 362c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// expanded), and SpellingLoc specifies the spelling location (where 363c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// the characters from the token come from). All three can refer to 364c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// normal File SLocs or expansion locations. 365c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static ExpansionInfo create(SourceLocation SpellingLoc, 366c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation Start, SourceLocation End) { 367c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ExpansionInfo X; 368c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot X.SpellingLoc = SpellingLoc.getRawEncoding(); 369c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot X.ExpansionLocStart = Start.getRawEncoding(); 370c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot X.ExpansionLocEnd = End.getRawEncoding(); 371c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return X; 372c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 373c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 374c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return a special ExpansionInfo for the expansion of 375c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// a macro argument into a function-like macro's body. 376c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 377c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// ExpansionLoc specifies the expansion location (where the macro is 378c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// expanded). This doesn't need to be a range because a macro is always 379c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// expanded at a macro parameter reference, and macro parameters are 380c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// always exactly one token. SpellingLoc specifies the spelling location 381c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// (where the characters from the token come from). ExpansionLoc and 382c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// SpellingLoc can both refer to normal File SLocs or expansion locations. 383c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 384c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Given the code: 385c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \code 386c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// #define F(x) f(x) 387c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// F(42); 388c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \endcode 389c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 390c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// When expanding '\c F(42)', the '\c x' would call this with an 391c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// SpellingLoc pointing at '\c 42' and an ExpansionLoc pointing at its 392c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// location in the definition of '\c F'. 393c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static ExpansionInfo createForMacroArg(SourceLocation SpellingLoc, 394c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation ExpansionLoc) { 395c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // We store an intentionally invalid source location for the end of the 396c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // expansion range to mark that this is a macro argument ion rather than 397c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // a normal one. 398c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return create(SpellingLoc, ExpansionLoc, SourceLocation()); 399c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 400c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 401c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 402c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief This is a discriminated union of FileInfo and ExpansionInfo. 403c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 404c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// SourceManager keeps an array of these objects, and they are uniquely 405c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// identified by the FileID datatype. 406c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot class SLocEntry { 407c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned Offset : 31; 408c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned IsExpansion : 1; 409c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot union { 410c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileInfo File; 411c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ExpansionInfo Expansion; 412c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 413c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 414c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot public: 415c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SLocEntry() : Offset(), IsExpansion(), File() {} 416c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 417c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getOffset() const { return Offset; } 418c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 419c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isExpansion() const { return IsExpansion; } 420c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isFile() const { return !isExpansion(); } 421c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 422c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const FileInfo &getFile() const { 423c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(isFile() && "Not a file SLocEntry!"); 424c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return File; 425c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 426c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 427c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const ExpansionInfo &getExpansion() const { 428c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(isExpansion() && "Not a macro expansion SLocEntry!"); 429c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Expansion; 430c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 431c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 432c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static SLocEntry get(unsigned Offset, const FileInfo &FI) { 433c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(!(Offset & (1 << 31)) && "Offset is too large"); 434c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SLocEntry E; 435c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot E.Offset = Offset; 436c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot E.IsExpansion = false; 437c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot E.File = FI; 438c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return E; 439c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 440c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 441c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static SLocEntry get(unsigned Offset, const ExpansionInfo &Expansion) { 442c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(!(Offset & (1 << 31)) && "Offset is too large"); 443c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SLocEntry E; 444c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot E.Offset = Offset; 445c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot E.IsExpansion = true; 446c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot E.Expansion = Expansion; 447c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return E; 448c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 449c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 450c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 451c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // end SrcMgr namespace. 452c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 453c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief External source of source location entries. 454c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ExternalSLocEntrySource { 455c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 456c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual ~ExternalSLocEntrySource(); 457c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 458c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Read the source location entry with index ID, which will always be 459c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// less than -1. 460c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 461c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \returns true if an error occurred that prevented the source-location 462c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// entry from being loaded. 463c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual bool ReadSLocEntry(int ID) = 0; 464c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 465c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Retrieve the module import location and name for the given ID, if 466c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// in fact it was loaded from a module (rather than, say, a precompiled 467c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// header). 468c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) = 0; 469c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 470c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 471c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Holds the cache used by isBeforeInTranslationUnit. 472c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 473c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// The cache structure is complex enough to be worth breaking out of 474c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// SourceManager. 475c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass InBeforeInTUCacheEntry { 476c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The FileID's of the cached query. 477c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 478c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If these match up with a subsequent query, the result can be reused. 479c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID LQueryFID, RQueryFID; 480c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 481c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief True if LQueryFID was created before RQueryFID. 482c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 483c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is used to compare macro expansion locations. 484c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool IsLQFIDBeforeRQFID; 485c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 486c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The file found in common between the two \#include traces, i.e., 487c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// the nearest common ancestor of the \#include tree. 488c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID CommonFID; 489c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 490c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The offset of the previous query in CommonFID. 491c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 492c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Usually, this represents the location of the \#include for QueryFID, but 493c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// if LQueryFID is a parent of RQueryFID (or vice versa) then these can be a 494c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// random token in the parent. 495c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned LCommonOffset, RCommonOffset; 496c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 497c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 498c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return true if the currently cached values match up with 499c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// the specified LHS/RHS query. 500c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 501c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If not, we can't use the cache. 502c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isCacheValid(FileID LHS, FileID RHS) const { 503c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return LQueryFID == LHS && RQueryFID == RHS; 504c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 505c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 506c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief If the cache is valid, compute the result given the 507c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// specified offsets in the LHS/RHS FileID's. 508c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool getCachedResult(unsigned LOffset, unsigned ROffset) const { 509c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // If one of the query files is the common file, use the offset. Otherwise, 510c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // use the #include loc in the common file. 511c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (LQueryFID != CommonFID) LOffset = LCommonOffset; 512c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (RQueryFID != CommonFID) ROffset = RCommonOffset; 513c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 514c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // It is common for multiple macro expansions to be "included" from the same 515c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // location (expansion location), in which case use the order of the FileIDs 516c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // to determine which came first. This will also take care the case where 517c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // one of the locations points at the inclusion/expansion point of the other 518c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // in which case its FileID will come before the other. 519c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (LOffset == ROffset) 520c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return IsLQFIDBeforeRQFID; 521c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 522c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return LOffset < ROffset; 523c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 524c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 525c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Set up a new query. 526c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setQueryFIDs(FileID LHS, FileID RHS, bool isLFIDBeforeRFID) { 527c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(LHS != RHS); 528c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot LQueryFID = LHS; 529c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot RQueryFID = RHS; 530c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot IsLQFIDBeforeRQFID = isLFIDBeforeRFID; 531c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 532c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 533c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void clear() { 534c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot LQueryFID = RQueryFID = FileID(); 535c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot IsLQFIDBeforeRQFID = false; 536c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 537c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 538c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setCommonLoc(FileID commonFID, unsigned lCommonOffset, 539c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned rCommonOffset) { 540c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot CommonFID = commonFID; 541c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot LCommonOffset = lCommonOffset; 542c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot RCommonOffset = rCommonOffset; 543c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 544c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 545c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 546c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief The stack used when building modules on demand, which is used 547c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// to provide a link between the source managers of the different compiler 548c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// instances. 549c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottypedef ArrayRef<std::pair<std::string, FullSourceLoc>> ModuleBuildStack; 550c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 551c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief This class handles loading and caching of source files into memory. 552c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 553c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// This object owns the MemoryBuffer objects for all of the loaded 554c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// files and assigns unique FileID's for each unique \#include chain. 555c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 556c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// The SourceManager can be queried for information about SourceLocation 557c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// objects, turning them into either spelling or expansion locations. Spelling 558c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// locations represent where the bytes corresponding to a token came from and 559c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// expansion locations represent where the location is in the user's view. In 560c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// the case of a macro expansion, for example, the spelling location indicates 561c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// where the expanded token came from and the expansion location specifies 562c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// where it was expanded. 563c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass SourceManager : public RefCountedBase<SourceManager> { 564c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief DiagnosticsEngine object. 565c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine &Diag; 566c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 567c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileManager &FileMgr; 568c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 569c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable llvm::BumpPtrAllocator ContentCacheAlloc; 570c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 571c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Memoized information about all of the files tracked by this 572c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// SourceManager. 573c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 574c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This map allows us to merge ContentCache entries based 575c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// on their FileEntry*. All ContentCache objects will thus have unique, 576c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// non-null, FileEntry pointers. 577c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos; 578c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 579c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief True if the ContentCache for files that are overridden by other 580c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// files, should report the original file name. Defaults to true. 581c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool OverridenFilesKeepOriginalName; 582c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 583c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief True if non-system source files should be treated as volatile 584c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// (likely to change while trying to use them). Defaults to false. 585c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool UserFilesAreVolatile; 586c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 587c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief True if all files read during this compilation should be treated 588c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// as transient (may not be present in later compilations using a module 589c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// file created from this compilation). Defaults to false. 590c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool FilesAreTransient; 591c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 592c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot struct OverriddenFilesInfoTy { 593c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Files that have been overridden with the contents from another 594c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// file. 595c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles; 596c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Files that were overridden with a memory buffer. 597c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::DenseSet<const FileEntry *> OverriddenFilesWithBuffer; 598c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 599c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 600c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Lazily create the object keeping overridden files info, since 601c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// it is uncommonly used. 602c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo; 603c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 604c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot OverriddenFilesInfoTy &getOverriddenFilesInfo() { 605c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!OverriddenFilesInfo) 606c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot OverriddenFilesInfo.reset(new OverriddenFilesInfoTy); 607c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return *OverriddenFilesInfo; 608c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 609c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 610c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Information about various memory buffers that we have read in. 611c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 612c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// All FileEntry* within the stored ContentCache objects are NULL, 613c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// as they do not refer to a file. 614c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::vector<SrcMgr::ContentCache*> MemBufferInfos; 615c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 616c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The table of SLocEntries that are local to this module. 617c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 618c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Positive FileIDs are indexes into this table. Entry 0 indicates an invalid 619c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// expansion. 620c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SmallVector<SrcMgr::SLocEntry, 0> LocalSLocEntryTable; 621c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 622c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The table of SLocEntries that are loaded from other modules. 623c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 624c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Negative FileIDs are indexes into this table. To get from ID to an index, 625c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// use (-ID - 2). 626c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable SmallVector<SrcMgr::SLocEntry, 0> LoadedSLocEntryTable; 627c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 628c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The starting offset of the next local SLocEntry. 629c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 630c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is LocalSLocEntryTable.back().Offset + the size of that entry. 631c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned NextLocalOffset; 632c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 633c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The starting offset of the latest batch of loaded SLocEntries. 634c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 635c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is LoadedSLocEntryTable.back().Offset, except that that entry might 636c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// not have been loaded, so that value would be unknown. 637c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned CurrentLoadedOffset; 638c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 639c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The highest possible offset is 2^31-1, so CurrentLoadedOffset 640c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// starts at 2^31. 641c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static const unsigned MaxLoadedOffset = 1U << 31U; 642c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 643c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief A bitmap that indicates whether the entries of LoadedSLocEntryTable 644c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// have already been loaded from the external source. 645c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 646c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Same indexing as LoadedSLocEntryTable. 647c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::BitVector SLocEntryLoaded; 648c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 649c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief An external source for source location entries. 650c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ExternalSLocEntrySource *ExternalSLocEntries; 651c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 652c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief A one-entry cache to speed up getFileID. 653c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 654c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// LastFileIDLookup records the last FileID looked up or created, because it 655c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// is very common to look up many tokens from the same file. 656c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable FileID LastFileIDLookup; 657c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 658c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Holds information for \#line directives. 659c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 660c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is referenced by indices from SLocEntryTable. 661c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot LineTableInfo *LineTable; 662c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 663c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief These ivars serve as a cache used in the getLineNumber 664c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// method which is used to speedup getLineNumber calls to nearby locations. 665c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable FileID LastLineNoFileIDQuery; 666c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable SrcMgr::ContentCache *LastLineNoContentCache; 667c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable unsigned LastLineNoFilePos; 668c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable unsigned LastLineNoResult; 669c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 670c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The file ID for the main source file of the translation unit. 671c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID MainFileID; 672c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 673c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The file ID for the precompiled preamble there is one. 674c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID PreambleFileID; 675c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 676c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Statistics for -print-stats. 677c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable unsigned NumLinearScans, NumBinaryProbes; 678c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 679c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Associates a FileID with its "included/expanded in" decomposed 680c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// location. 681c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 682c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Used to cache results from and speed-up \c getDecomposedIncludedLoc 683c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// function. 684c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable llvm::DenseMap<FileID, std::pair<FileID, unsigned>> IncludedLocMap; 685c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 686c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// The key value into the IsBeforeInTUCache table. 687c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot typedef std::pair<FileID, FileID> IsBeforeInTUCacheKey; 688c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 689c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// The IsBeforeInTranslationUnitCache is a mapping from FileID pairs 690c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// to cache results. 691c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot typedef llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry> 692c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot InBeforeInTUCache; 693c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 694c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Cache results for the isBeforeInTranslationUnit method. 695c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable InBeforeInTUCache IBTUCache; 696c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable InBeforeInTUCacheEntry IBTUCacheOverflow; 697c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 698c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Return the cache entry for comparing the given file IDs 699c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// for isBeforeInTranslationUnit. 700c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot InBeforeInTUCacheEntry &getInBeforeInTUCache(FileID LFID, FileID RFID) const; 701c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 702c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Cache for the "fake" buffer used for error-recovery purposes. 703c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery; 704c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 705c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery; 706c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 707c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Lazily computed map of macro argument chunks to their expanded 708c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// source location. 709c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot typedef std::map<unsigned, SourceLocation> MacroArgsMap; 710c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 711c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot mutable llvm::DenseMap<FileID, std::unique_ptr<MacroArgsMap>> 712c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot MacroArgsCacheMap; 713c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 714c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The stack of modules being built, which is used to detect 715c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// cycles in the module dependency graph as modules are being built, as 716c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// well as to describe why we're rebuilding a particular module. 717c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 718c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// There is no way to set this value from the command line. If we ever need 719c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// to do so (e.g., if on-demand module construction moves out-of-process), 720c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// we can add a cc1-level option to do so. 721c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SmallVector<std::pair<std::string, FullSourceLoc>, 2> StoredModuleBuildStack; 722c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 723c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 724c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceManager(DiagnosticsEngine &Diag, FileManager &FileMgr, 725c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool UserFilesAreVolatile = false); 726c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot explicit SourceManager(const SourceManager &) = delete; 727c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceManager &operator=(const SourceManager &) = delete; 728c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ~SourceManager(); 729c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 730c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void clearIDTables(); 731c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 732c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Initialize this source manager suitably to replay the compilation 733c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// described by \p Old. Requires that \p Old outlive \p *this. 734c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void initializeForReplay(const SourceManager &Old); 735c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 736c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine &getDiagnostics() const { return Diag; } 737c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 738c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileManager &getFileManager() const { return FileMgr; } 739c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 740c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Set true if the SourceManager should report the original file name 741c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// for contents of files that were overridden by other files. Defaults to 742c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// true. 743c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setOverridenFilesKeepOriginalName(bool value) { 744c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot OverridenFilesKeepOriginalName = value; 745c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 746c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 747c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief True if non-system source files should be treated as volatile 748c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// (likely to change while trying to use them). 749c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool userFilesAreVolatile() const { return UserFilesAreVolatile; } 750c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 751c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Retrieve the module build stack. 752c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ModuleBuildStack getModuleBuildStack() const { 753c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return StoredModuleBuildStack; 754c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 755c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 756c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Set the module build stack. 757c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setModuleBuildStack(ModuleBuildStack stack) { 758c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StoredModuleBuildStack.clear(); 759c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StoredModuleBuildStack.append(stack.begin(), stack.end()); 760c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 761c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 762c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Push an entry to the module build stack. 763c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc) { 764c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc)); 765c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 766c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 767c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 768c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // MainFileID creation and querying methods. 769c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 770c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 771c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the FileID of the main source file. 772c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID getMainFileID() const { return MainFileID; } 773c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 774c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Set the file ID for the main source file. 775c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setMainFileID(FileID FID) { 776c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot MainFileID = FID; 777c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 778c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 779c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Set the file ID for the precompiled preamble. 780c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setPreambleFileID(FileID Preamble) { 781c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(PreambleFileID.isInvalid() && "PreambleFileID already set!"); 782c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot PreambleFileID = Preamble; 783c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 784c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 785c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the file ID for the precompiled preamble if there is one. 786c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID getPreambleFileID() const { return PreambleFileID; } 787c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 788c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 789c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Methods to create new FileID's and macro expansions. 790c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 791c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 792c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Create a new FileID that represents the specified file 793c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// being \#included from the specified IncludePosition. 794c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 795c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This translates NULL into standard input. 796c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, 797c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SrcMgr::CharacteristicKind FileCharacter, 798c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot int LoadedID = 0, unsigned LoadedOffset = 0) { 799c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::ContentCache *IR = 800c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getOrCreateContentCache(SourceFile, isSystem(FileCharacter)); 801c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(IR && "getOrCreateContentCache() cannot return NULL"); 802c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset); 803c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 804c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 805c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Create a new FileID that represents the specified memory buffer. 806c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 807c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This does no caching of the buffer and takes ownership of the 808c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// MemoryBuffer, so only pass a MemoryBuffer to this once. 809c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID createFileID(std::unique_ptr<llvm::MemoryBuffer> Buffer, 810c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User, 811c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot int LoadedID = 0, unsigned LoadedOffset = 0, 812c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation IncludeLoc = SourceLocation()) { 813c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return createFileID( 814c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot createMemBufferContentCache(Buffer.release(), /*DoNotFree*/ false), 815c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot IncludeLoc, FileCharacter, LoadedID, LoadedOffset); 816c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 817c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 818c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot enum UnownedTag { Unowned }; 819c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 820c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Create a new FileID that represents the specified memory buffer. 821c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 822c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This does no caching of the buffer and takes ownership of the 823c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// MemoryBuffer, so only pass a MemoryBuffer to this once. 824c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID createFileID(UnownedTag, llvm::MemoryBuffer *Buffer, 825c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User, 826c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot int LoadedID = 0, unsigned LoadedOffset = 0, 827c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation IncludeLoc = SourceLocation()) { 828c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return createFileID(createMemBufferContentCache(Buffer, /*DoNotFree*/true), 829c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot IncludeLoc, FileCharacter, LoadedID, LoadedOffset); 830c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 831c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 832c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the FileID for \p SourceFile if it exists. Otherwise, create a 833c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// new FileID for the \p SourceFile. 834c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID getOrCreateFileID(const FileEntry *SourceFile, 835c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SrcMgr::CharacteristicKind FileCharacter) { 836c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID ID = translateFile(SourceFile); 837c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ID.isValid() ? ID : createFileID(SourceFile, SourceLocation(), 838c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileCharacter); 839c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 840c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 841c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return a new SourceLocation that encodes the 842c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// fact that a token from SpellingLoc should actually be referenced from 843c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// ExpansionLoc, and that it represents the expansion of a macro argument 844c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// into the function-like macro body. 845c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation createMacroArgExpansionLoc(SourceLocation Loc, 846c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation ExpansionLoc, 847c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned TokLength); 848c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 849c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return a new SourceLocation that encodes the fact 850c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// that a token from SpellingLoc should actually be referenced from 851c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// ExpansionLoc. 852c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation createExpansionLoc(SourceLocation Loc, 853c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation ExpansionLocStart, 854c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation ExpansionLocEnd, 855c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned TokLength, 856c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot int LoadedID = 0, 857c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned LoadedOffset = 0); 858c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 859c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Retrieve the memory buffer associated with the given file. 860c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 861c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Invalid If non-NULL, will be set \c true if an error 862c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// occurs while retrieving the memory buffer. 863c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::MemoryBuffer *getMemoryBufferForFile(const FileEntry *File, 864c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr); 865c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 866c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Override the contents of the given source file by providing an 867c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// already-allocated buffer. 868c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 869c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param SourceFile the source file whose contents will be overridden. 870c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 871c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Buffer the memory buffer whose contents will be used as the 872c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// data in the given source file. 873c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 874c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param DoNotFree If true, then the buffer will not be freed when the 875c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// source manager is destroyed. 876c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void overrideFileContents(const FileEntry *SourceFile, 877c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::MemoryBuffer *Buffer, bool DoNotFree); 878c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void overrideFileContents(const FileEntry *SourceFile, 879c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::unique_ptr<llvm::MemoryBuffer> Buffer) { 880c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot overrideFileContents(SourceFile, Buffer.release(), /*DoNotFree*/ false); 881c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 882c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 883c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Override the given source file with another one. 884c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 885c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param SourceFile the source file which will be overridden. 886c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 887c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param NewFile the file whose contents will be used as the 888c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// data instead of the contents of the given source file. 889c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void overrideFileContents(const FileEntry *SourceFile, 890c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const FileEntry *NewFile); 891c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 892c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if the file contents have been overridden. 893c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isFileOverridden(const FileEntry *File) const { 894c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (OverriddenFilesInfo) { 895c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File)) 896c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return true; 897c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (OverriddenFilesInfo->OverriddenFiles.find(File) != 898c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot OverriddenFilesInfo->OverriddenFiles.end()) 899c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return true; 900c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 901c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return false; 902c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 903c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 904c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Disable overridding the contents of a file, previously enabled 905c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// with #overrideFileContents. 906c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 907c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This should be called before parsing has begun. 908c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void disableFileContentsOverride(const FileEntry *File); 909c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 910c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Specify that a file is transient. 911c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setFileIsTransient(const FileEntry *SourceFile); 912c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 913c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Specify that all files that are read during this compilation are 914c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// transient. 915c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setAllFilesAreTransient(bool Transient) { 916c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FilesAreTransient = Transient; 917c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 918c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 919c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 920c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // FileID manipulation methods. 921c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 922c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 923c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the buffer for the specified FileID. 924c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 925c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If there is an error opening this buffer the first time, this 926c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// manufactures a temporary buffer and returns a non-empty error string. 927c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::MemoryBuffer *getBuffer(FileID FID, SourceLocation Loc, 928c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const { 929c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool MyInvalid = false; 930c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid); 931c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (MyInvalid || !Entry.isFile()) { 932c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid) 933c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot *Invalid = true; 934c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 935c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getFakeBufferForRecovery(); 936c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 937c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 938c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Entry.getFile().getContentCache()->getBuffer(Diag, *this, Loc, 939c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Invalid); 940c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 941c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 942c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::MemoryBuffer *getBuffer(FileID FID, bool *Invalid = nullptr) const { 943c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool MyInvalid = false; 944c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid); 945c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (MyInvalid || !Entry.isFile()) { 946c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid) 947c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot *Invalid = true; 948c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 949c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getFakeBufferForRecovery(); 950c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 951c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 952c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Entry.getFile().getContentCache()->getBuffer(Diag, *this, 953c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation(), 954c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Invalid); 955c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 956c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 957c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the FileEntry record for the provided FileID. 958c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const FileEntry *getFileEntryForID(FileID FID) const { 959c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool MyInvalid = false; 960c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid); 961c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (MyInvalid || !Entry.isFile()) 962c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return nullptr; 963c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 964c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::ContentCache *Content = Entry.getFile().getContentCache(); 965c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!Content) 966c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return nullptr; 967c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Content->OrigEntry; 968c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 969c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 970c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the FileEntry record for the provided SLocEntry. 971c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const FileEntry *getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) const 972c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot { 973c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::ContentCache *Content = sloc.getFile().getContentCache(); 974c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!Content) 975c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return nullptr; 976c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Content->OrigEntry; 977c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 978c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 979c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return a StringRef to the source buffer data for the 980c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// specified FileID. 981c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 982c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param FID The file ID whose contents will be returned. 983c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Invalid If non-NULL, will be set true if an error occurred. 984c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef getBufferData(FileID FID, bool *Invalid = nullptr) const; 985c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 986c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the number of FileIDs (files and macros) that were created 987c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// during preprocessing of \p FID, including it. 988c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getNumCreatedFIDsForFileID(FileID FID) const { 989c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool Invalid = false; 990c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); 991c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid || !Entry.isFile()) 992c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return 0; 993c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 994c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Entry.getFile().NumCreatedFIDs; 995c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 996c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 997c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Set the number of FileIDs (files and macros) that were created 998c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// during preprocessing of \p FID, including it. 999c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs) const { 1000c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool Invalid = false; 1001c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); 1002c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid || !Entry.isFile()) 1003c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return; 1004c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1005c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(Entry.getFile().NumCreatedFIDs == 0 && "Already set!"); 1006c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const_cast<SrcMgr::FileInfo &>(Entry.getFile()).NumCreatedFIDs = NumFIDs; 1007c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1008c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1009c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1010c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // SourceLocation manipulation methods. 1011c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1012c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1013c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the FileID for a SourceLocation. 1014c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1015c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is a very hot method that is used for all SourceManager queries 1016c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// that start with a SourceLocation object. It is responsible for finding 1017c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// the entry in SLocEntryTable which contains the specified location. 1018c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1019c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID getFileID(SourceLocation SpellingLoc) const { 1020c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned SLocOffset = SpellingLoc.getOffset(); 1021c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1022c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // If our one-entry cache covers this offset, just return it. 1023c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (isOffsetInFileID(LastFileIDLookup, SLocOffset)) 1024c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return LastFileIDLookup; 1025c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1026c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getFileIDSlow(SLocOffset); 1027c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1028c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1029c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the filename of the file containing a SourceLocation. 1030c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef getFilename(SourceLocation SpellingLoc) const { 1031c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (const FileEntry *F = getFileEntryForID(getFileID(SpellingLoc))) 1032c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return F->getName(); 1033c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return StringRef(); 1034c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1035c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1036c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the source location corresponding to the first byte of 1037c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// the specified file. 1038c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getLocForStartOfFile(FileID FID) const { 1039c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool Invalid = false; 1040c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); 1041c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid || !Entry.isFile()) 1042c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SourceLocation(); 1043c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1044c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned FileOffset = Entry.getOffset(); 1045c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SourceLocation::getFileLoc(FileOffset); 1046c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1047c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1048c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the source location corresponding to the last byte of the 1049c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// specified file. 1050c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getLocForEndOfFile(FileID FID) const { 1051c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool Invalid = false; 1052c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); 1053c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid || !Entry.isFile()) 1054c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SourceLocation(); 1055c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1056c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned FileOffset = Entry.getOffset(); 1057c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID)); 1058c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1059c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1060c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the include location if \p FID is a \#include'd file 1061c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// otherwise it returns an invalid location. 1062c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getIncludeLoc(FileID FID) const { 1063c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool Invalid = false; 1064c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); 1065c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid || !Entry.isFile()) 1066c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SourceLocation(); 1067c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1068c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Entry.getFile().getIncludeLoc(); 1069c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1070c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1071c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // \brief Returns the import location if the given source location is 1072c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // located within a module, or an invalid location if the source location 1073c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // is within the current translation unit. 1074c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<SourceLocation, StringRef> 1075c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getModuleImportLoc(SourceLocation Loc) const { 1076c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID FID = getFileID(Loc); 1077c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1078c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Positive file IDs are in the current translation unit, and -1 is a 1079c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // placeholder. 1080c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (FID.ID >= -1) 1081c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::make_pair(SourceLocation(), ""); 1082c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1083c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ExternalSLocEntries->getModuleImportLoc(FID.ID); 1084c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1085c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1086c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Given a SourceLocation object \p Loc, return the expansion 1087c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// location referenced by the ID. 1088c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getExpansionLoc(SourceLocation Loc) const { 1089c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Handle the non-mapped case inline, defer to out of line code to handle 1090c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // expansions. 1091c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Loc.isFileID()) return Loc; 1092c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getExpansionLocSlowCase(Loc); 1093c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1094c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1095c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Given \p Loc, if it is a macro location return the expansion 1096c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// location or the spelling location, depending on if it comes from a 1097c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// macro argument or not. 1098c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getFileLoc(SourceLocation Loc) const { 1099c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Loc.isFileID()) return Loc; 1100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getFileLocSlowCase(Loc); 1101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the start/end of the expansion information for an 1104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// expansion location. 1105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \pre \p Loc is required to be an expansion location. 1107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<SourceLocation,SourceLocation> 1108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getImmediateExpansionRange(SourceLocation Loc) const; 1109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Given a SourceLocation object, return the range of 1111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// tokens covered by the expansion in the ultimate file. 1112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<SourceLocation,SourceLocation> 1113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getExpansionRange(SourceLocation Loc) const; 1114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Given a SourceRange object, return the range of 1116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// tokens covered by the expansion in the ultimate file. 1117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceRange getExpansionRange(SourceRange Range) const { 1118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SourceRange(getExpansionRange(Range.getBegin()).first, 1119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getExpansionRange(Range.getEnd()).second); 1120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Given a SourceLocation object, return the spelling 1123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// location referenced by the ID. 1124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is the place where the characters that make up the lexed token 1126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// can be found. 1127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getSpellingLoc(SourceLocation Loc) const { 1128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Handle the non-mapped case inline, defer to out of line code to handle 1129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // expansions. 1130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Loc.isFileID()) return Loc; 1131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSpellingLocSlowCase(Loc); 1132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Given a SourceLocation object, return the spelling location 1135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// referenced by the ID. 1136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is the first level down towards the place where the characters 1138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// that make up the lexed token can be found. This should not generally 1139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// be used by clients. 1140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getImmediateSpellingLoc(SourceLocation Loc) const; 1141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Decompose the specified location into a raw FileID + Offset pair. 1143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// The first element is the FileID, the second is the offset from the 1145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// start of the buffer of the location. 1146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<FileID, unsigned> getDecomposedLoc(SourceLocation Loc) const { 1147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID FID = getFileID(Loc); 1148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool Invalid = false; 1149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &E = getSLocEntry(FID, &Invalid); 1150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid) 1151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::make_pair(FileID(), 0); 1152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::make_pair(FID, Loc.getOffset()-E.getOffset()); 1153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Decompose the specified location into a raw FileID + Offset pair. 1156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If the location is an expansion record, walk through it until we find 1158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// the final location expanded. 1159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<FileID, unsigned> 1160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getDecomposedExpansionLoc(SourceLocation Loc) const { 1161c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID FID = getFileID(Loc); 1162c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool Invalid = false; 1163c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry *E = &getSLocEntry(FID, &Invalid); 1164c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid) 1165c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::make_pair(FileID(), 0); 1166c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1167c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned Offset = Loc.getOffset()-E->getOffset(); 1168c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Loc.isFileID()) 1169c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::make_pair(FID, Offset); 1170c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1171c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getDecomposedExpansionLocSlowCase(E); 1172c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1173c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1174c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Decompose the specified location into a raw FileID + Offset pair. 1175c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1176c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If the location is an expansion record, walk through it until we find 1177c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// its spelling record. 1178c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<FileID, unsigned> 1179c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getDecomposedSpellingLoc(SourceLocation Loc) const { 1180c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID FID = getFileID(Loc); 1181c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool Invalid = false; 1182c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry *E = &getSLocEntry(FID, &Invalid); 1183c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid) 1184c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::make_pair(FileID(), 0); 1185c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1186c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned Offset = Loc.getOffset()-E->getOffset(); 1187c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Loc.isFileID()) 1188c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return std::make_pair(FID, Offset); 1189c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getDecomposedSpellingLocSlowCase(E, Offset); 1190c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1191c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1192c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the "included/expanded in" decomposed location of the given 1193c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// FileID. 1194c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<FileID, unsigned> getDecomposedIncludedLoc(FileID FID) const; 1195c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1196c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the offset from the start of the file that the 1197c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// specified SourceLocation represents. 1198c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1199c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is not very meaningful for a macro ID. 1200c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getFileOffset(SourceLocation SpellingLoc) const { 1201c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getDecomposedLoc(SpellingLoc).second; 1202c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1203c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1204c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Tests whether the given source location represents a macro 1205c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// argument's expansion into the function-like macro definition. 1206c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1207c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param StartLoc If non-null and function returns true, it is set to the 1208c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// start location of the macro argument expansion. 1209c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1210c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Such source locations only appear inside of the expansion 1211c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// locations representing where a particular function-like macro was 1212c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// expanded. 1213c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isMacroArgExpansion(SourceLocation Loc, 1214c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation *StartLoc = nullptr) const; 1215c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1216c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Tests whether the given source location represents the expansion of 1217c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// a macro body. 1218c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1219c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is equivalent to testing whether the location is part of a macro 1220c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// expansion but not the expansion of an argument to a function-like macro. 1221c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isMacroBodyExpansion(SourceLocation Loc) const; 1222c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1223c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if the given MacroID location points at the beginning 1224c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// of the immediate macro expansion. 1225c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1226c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param MacroBegin If non-null and function returns true, it is set to the 1227c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// begin location of the immediate macro expansion. 1228c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isAtStartOfImmediateMacroExpansion(SourceLocation Loc, 1229c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation *MacroBegin = nullptr) const; 1230c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1231c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if the given MacroID location points at the character 1232c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// end of the immediate macro expansion. 1233c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1234c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param MacroEnd If non-null and function returns true, it is set to the 1235c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// character end location of the immediate macro expansion. 1236c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool 1237c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot isAtEndOfImmediateMacroExpansion(SourceLocation Loc, 1238c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation *MacroEnd = nullptr) const; 1239c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1240c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if \p Loc is inside the [\p Start, +\p Length) 1241c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// chunk of the source location address space. 1242c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1243c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If it's true and \p RelativeOffset is non-null, it will be set to the 1244c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// relative offset of \p Loc inside the chunk. 1245c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isInSLocAddrSpace(SourceLocation Loc, 1246c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation Start, unsigned Length, 1247c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned *RelativeOffset = nullptr) const { 1248c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(((Start.getOffset() < NextLocalOffset && 1249c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Start.getOffset()+Length <= NextLocalOffset) || 1250c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot (Start.getOffset() >= CurrentLoadedOffset && 1251c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Start.getOffset()+Length < MaxLoadedOffset)) && 1252c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot "Chunk is not valid SLoc address space"); 1253c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned LocOffs = Loc.getOffset(); 1254c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned BeginOffs = Start.getOffset(); 1255c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned EndOffs = BeginOffs + Length; 1256c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (LocOffs >= BeginOffs && LocOffs < EndOffs) { 1257c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (RelativeOffset) 1258c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot *RelativeOffset = LocOffs - BeginOffs; 1259c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return true; 1260c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1261c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1262c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return false; 1263c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1264c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1265c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return true if both \p LHS and \p RHS are in the local source 1266c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// location address space or the loaded one. 1267c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1268c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If it's true and \p RelativeOffset is non-null, it will be set to the 1269c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// offset of \p RHS relative to \p LHS. 1270c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isInSameSLocAddrSpace(SourceLocation LHS, SourceLocation RHS, 1271c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot int *RelativeOffset) const { 1272c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset(); 1273c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool LHSLoaded = LHSOffs >= CurrentLoadedOffset; 1274c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool RHSLoaded = RHSOffs >= CurrentLoadedOffset; 1275c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1276c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (LHSLoaded == RHSLoaded) { 1277c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (RelativeOffset) 1278c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot *RelativeOffset = RHSOffs - LHSOffs; 1279c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return true; 1280c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1281c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1282c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return false; 1283c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1284c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1285c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1286c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Queries about the code at a SourceLocation. 1287c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1288c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1289c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return a pointer to the start of the specified location 1290c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// in the appropriate spelling MemoryBuffer. 1291c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1292c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Invalid If non-NULL, will be set \c true if an error occurs. 1293c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const char *getCharacterData(SourceLocation SL, 1294c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const; 1295c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1296c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the column # for the specified file position. 1297c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1298c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is significantly cheaper to compute than the line number. This 1299c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// returns zero if the column number isn't known. This may only be called 1300c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// on a file sloc, so you must choose a spelling or expansion location 1301c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// before calling this method. 1302c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getColumnNumber(FileID FID, unsigned FilePos, 1303c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const; 1304c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getSpellingColumnNumber(SourceLocation Loc, 1305c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const; 1306c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getExpansionColumnNumber(SourceLocation Loc, 1307c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const; 1308c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getPresumedColumnNumber(SourceLocation Loc, 1309c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const; 1310c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1311c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Given a SourceLocation, return the spelling line number 1312c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// for the position indicated. 1313c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1314c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This requires building and caching a table of line offsets for the 1315c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// MemoryBuffer, so this is not cheap: use only when about to emit a 1316c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// diagnostic. 1317c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid = nullptr) const; 1318c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const; 1319c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const; 1320c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const; 1321c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1322c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the filename or buffer identifier of the buffer the 1323c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// location is in. 1324c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1325c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Note that this name does not respect \#line directives. Use 1326c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// getPresumedLoc for normal clients. 1327c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef getBufferName(SourceLocation Loc, bool *Invalid = nullptr) const; 1328c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1329c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the file characteristic of the specified source 1330c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// location, indicating whether this is a normal file, a system 1331c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// header, or an "implicit extern C" system header. 1332c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1333c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This state can be modified with flags on GNU linemarker directives like: 1334c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \code 1335c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// # 4 "foo.h" 3 1336c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \endcode 1337c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// which changes all source locations in the current file after that to be 1338c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// considered to be from a system header. 1339c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const; 1340c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1341c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the "presumed" location of a SourceLocation specifies. 1342c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1343c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// A "presumed location" can be modified by \#line or GNU line marker 1344c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// directives. This provides a view on the data that a user should see 1345c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// in diagnostics, for example. 1346c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1347c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Note that a presumed location is always given as the expansion point of 1348c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// an expansion location, not at the spelling location. 1349c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1350c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \returns The presumed location of the specified SourceLocation. If the 1351c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// presumed location cannot be calculated (e.g., because \p Loc is invalid 1352c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// or the file containing \p Loc has changed on disk), returns an invalid 1353c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// presumed location. 1354c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot PresumedLoc getPresumedLoc(SourceLocation Loc, 1355c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool UseLineDirectives = true) const; 1356c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1357c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns whether the PresumedLoc for a given SourceLocation is 1358c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// in the main file. 1359c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1360c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This computes the "presumed" location for a SourceLocation, then checks 1361c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// whether it came from a file other than the main file. This is different 1362c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// from isWrittenInMainFile() because it takes line marker directives into 1363c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// account. 1364c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isInMainFile(SourceLocation Loc) const; 1365c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1366c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if the spelling locations for both SourceLocations 1367c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// are part of the same file buffer. 1368c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1369c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This check ignores line marker directives. 1370c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isWrittenInSameFile(SourceLocation Loc1, SourceLocation Loc2) const { 1371c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getFileID(Loc1) == getFileID(Loc2); 1372c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1373c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1374c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if the spelling location for the given location 1375c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// is in the main file buffer. 1376c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1377c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This check ignores line marker directives. 1378c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isWrittenInMainFile(SourceLocation Loc) const { 1379c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getFileID(Loc) == getMainFileID(); 1380c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1381c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1382c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns if a SourceLocation is in a system header. 1383c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isInSystemHeader(SourceLocation Loc) const { 1384c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return isSystem(getFileCharacteristic(Loc)); 1385c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1386c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1387c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns if a SourceLocation is in an "extern C" system header. 1388c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isInExternCSystemHeader(SourceLocation Loc) const { 1389c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getFileCharacteristic(Loc) == SrcMgr::C_ExternCSystem; 1390c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1391c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1392c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns whether \p Loc is expanded from a macro in a system header. 1393c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isInSystemMacro(SourceLocation loc) const { 1394c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return loc.isMacroID() && isInSystemHeader(getSpellingLoc(loc)); 1395c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1396c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1397c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The size of the SLocEntry that \p FID represents. 1398c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getFileIDSize(FileID FID) const; 1399c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1400c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Given a specific FileID, returns true if \p Loc is inside that 1401c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// FileID chunk and sets relative offset (offset of \p Loc from beginning 1402c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// of FileID) to \p relativeOffset. 1403c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isInFileID(SourceLocation Loc, FileID FID, 1404c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned *RelativeOffset = nullptr) const { 1405c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned Offs = Loc.getOffset(); 1406c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (isOffsetInFileID(FID, Offs)) { 1407c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (RelativeOffset) 1408c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot *RelativeOffset = Offs - getSLocEntry(FID).getOffset(); 1409c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return true; 1410c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1411c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1412c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return false; 1413c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1414c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1415c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1416c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Line Table Manipulation Routines 1417c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1418c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1419c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the uniqued ID for the specified filename. 1420c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1421c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getLineTableFilenameID(StringRef Str); 1422c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1423c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Add a line note to the line table for the FileID and offset 1424c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// specified by Loc. 1425c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1426c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If FilenameID is -1, it is considered to be unspecified. 1427c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, 1428c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool IsFileEntry, bool IsFileExit, 1429c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SrcMgr::CharacteristicKind FileKind); 1430c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1431c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Determine if the source manager has a line table. 1432c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool hasLineTable() const { return LineTable != nullptr; } 1433c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1434c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Retrieve the stored line table. 1435c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot LineTableInfo &getLineTable(); 1436c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1437c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1438c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Queries for performance analysis. 1439c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1440c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1441c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the total amount of physical memory allocated by the 1442c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// ContentCache allocator. 1443c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot size_t getContentCacheSize() const { 1444c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return ContentCacheAlloc.getTotalMemory(); 1445c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1446c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1447c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot struct MemoryBufferSizes { 1448c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const size_t malloc_bytes; 1449c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const size_t mmap_bytes; 1450c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1451c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes) 1452c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {} 1453c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 1454c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1455c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the amount of memory used by memory buffers, breaking down 1456c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// by heap-backed versus mmap'ed memory. 1457c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot MemoryBufferSizes getMemoryBufferSizes() const; 1458c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1459c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return the amount of memory used for various side tables and 1460c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// data structures in the SourceManager. 1461c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot size_t getDataStructureSizes() const; 1462c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1463c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1464c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Other miscellaneous methods. 1465c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot //===--------------------------------------------------------------------===// 1466c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1467c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the source location for the given file:line:col triplet. 1468c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1469c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If the source file is included multiple times, the source location will 1470c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// be based upon the first inclusion. 1471c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation translateFileLineCol(const FileEntry *SourceFile, 1472c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned Line, unsigned Col) const; 1473c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1474c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the FileID for the given file. 1475c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1476c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If the source file is included multiple times, the FileID will be the 1477c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// first inclusion. 1478c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID translateFile(const FileEntry *SourceFile) const; 1479c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1480c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the source location in \p FID for the given line:col. 1481c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Returns null location if \p FID is not a file SLocEntry. 1482c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation translateLineCol(FileID FID, 1483c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned Line, unsigned Col) const; 1484c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1485c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief If \p Loc points inside a function macro argument, the returned 1486c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// location will be the macro location in which the argument was expanded. 1487c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// If a macro argument is used multiple times, the expanded location will 1488c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// be at the first expansion of the argument. 1489c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// e.g. 1490c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// MY_MACRO(foo); 1491c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// ^ 1492c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Passing a file location pointing at 'foo', will yield a macro location 1493c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// where 'foo' was expanded into. 1494c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getMacroArgExpandedLocation(SourceLocation Loc) const; 1495c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1496c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Determines the order of 2 source locations in the translation unit. 1497c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1498c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \returns true if LHS source location comes before RHS, false otherwise. 1499c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const; 1500c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1501c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Determines whether the two decomposed source location is in the 1502c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// same translation unit. As a byproduct, it also calculates the order 1503c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// of the source locations in case they are in the same TU. 1504c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1505c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \returns Pair of bools the first component is true if the two locations 1506c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// are in the same TU. The second bool is true if the first is true 1507c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// and \p LOffs is before \p ROffs. 1508c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<bool, bool> 1509c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot isInTheSameTranslationUnit(std::pair<FileID, unsigned> &LOffs, 1510c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<FileID, unsigned> &ROffs) const; 1511c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1512c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Determines the order of 2 source locations in the "source location 1513c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// address space". 1514c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation RHS) const { 1515c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return isBeforeInSLocAddrSpace(LHS, RHS.getOffset()); 1516c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1517c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1518c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Determines the order of a source location and a source location 1519c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// offset in the "source location address space". 1520c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1521c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Note that we always consider source locations loaded from 1522c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isBeforeInSLocAddrSpace(SourceLocation LHS, unsigned RHS) const { 1523c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned LHSOffset = LHS.getOffset(); 1524c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool LHSLoaded = LHSOffset >= CurrentLoadedOffset; 1525c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool RHSLoaded = RHS >= CurrentLoadedOffset; 1526c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (LHSLoaded == RHSLoaded) 1527c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return LHSOffset < RHS; 1528c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1529c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return LHSLoaded; 1530c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1531c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1532c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Return true if the Point is within Start and End. 1533c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isPointWithin(SourceLocation Location, SourceLocation Start, 1534c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation End) const { 1535c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Location == Start || Location == End || 1536c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot (isBeforeInTranslationUnit(Start, Location) && 1537c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot isBeforeInTranslationUnit(Location, End)); 1538c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1539c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1540c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Iterators over FileInfos. 1541c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot typedef llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> 1542c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ::const_iterator fileinfo_iterator; 1543c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot fileinfo_iterator fileinfo_begin() const { return FileInfos.begin(); } 1544c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot fileinfo_iterator fileinfo_end() const { return FileInfos.end(); } 1545c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool hasFileInfo(const FileEntry *File) const { 1546c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return FileInfos.find(File) != FileInfos.end(); 1547c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1548c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1549c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Print statistics to stderr. 1550c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1551c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void PrintStats() const; 1552c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1553c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void dump() const; 1554c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1555c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the number of local SLocEntries we have. 1556c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned local_sloc_entry_size() const { return LocalSLocEntryTable.size(); } 1557c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1558c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get a local SLocEntry. This is exposed for indexing. 1559c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index, 1560c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const { 1561c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(Index < LocalSLocEntryTable.size() && "Invalid index"); 1562c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return LocalSLocEntryTable[Index]; 1563c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1564c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1565c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the number of loaded SLocEntries we have. 1566c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned loaded_sloc_entry_size() const { return LoadedSLocEntryTable.size();} 1567c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1568c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get a loaded SLocEntry. This is exposed for indexing. 1569c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &getLoadedSLocEntry(unsigned Index, 1570c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const { 1571c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(Index < LoadedSLocEntryTable.size() && "Invalid index"); 1572c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (SLocEntryLoaded[Index]) 1573c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return LoadedSLocEntryTable[Index]; 1574c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return loadSLocEntry(Index, Invalid); 1575c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1576c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1577c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &getSLocEntry(FileID FID, 1578c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const { 1579c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (FID.ID == 0 || FID.ID == -1) { 1580c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (Invalid) *Invalid = true; 1581c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return LocalSLocEntryTable[0]; 1582c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1583c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getSLocEntryByID(FID.ID, Invalid); 1584c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1585c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1586c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned getNextLocalOffset() const { return NextLocalOffset; } 1587c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1588c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setExternalSLocEntrySource(ExternalSLocEntrySource *Source) { 1589c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(LoadedSLocEntryTable.empty() && 1590c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot "Invalidating existing loaded entries"); 1591c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ExternalSLocEntries = Source; 1592c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1593c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1594c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Allocate a number of loaded SLocEntries, which will be actually 1595c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// loaded on demand from the external source. 1596c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1597c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// NumSLocEntries will be allocated, which occupy a total of TotalSize space 1598c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// in the global source view. The lowest ID and the base offset of the 1599c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// entries will be returned. 1600c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<int, unsigned> 1601c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot AllocateLoadedSLocEntries(unsigned NumSLocEntries, unsigned TotalSize); 1602c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1603c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if \p Loc came from a PCH/Module. 1604c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isLoadedSourceLocation(SourceLocation Loc) const { 1605c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Loc.getOffset() >= CurrentLoadedOffset; 1606c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1607c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1608c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if \p Loc did not come from a PCH/Module. 1609c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isLocalSourceLocation(SourceLocation Loc) const { 1610c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return Loc.getOffset() < NextLocalOffset; 1611c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1612c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1613c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if \p FID came from a PCH/Module. 1614c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isLoadedFileID(FileID FID) const { 1615c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(FID.ID != -1 && "Using FileID sentinel value"); 1616c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return FID.ID < 0; 1617c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1618c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1619c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns true if \p FID did not come from a PCH/Module. 1620c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isLocalFileID(FileID FID) const { 1621c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return !isLoadedFileID(FID); 1622c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1623c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1624c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Gets the location of the immediate macro caller, one level up the stack 1625c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// toward the initial macro typed into the source. 1626c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const { 1627c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (!Loc.isMacroID()) return Loc; 1628c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1629c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // When we have the location of (part of) an expanded parameter, its 1630c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // spelling location points to the argument as expanded in the macro call, 1631c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // and therefore is used to locate the macro caller. 1632c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (isMacroArgExpansion(Loc)) 1633c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getImmediateSpellingLoc(Loc); 1634c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1635c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Otherwise, the caller of the macro is located where this macro is 1636c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // expanded (while the spelling is part of the macro definition). 1637c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getImmediateExpansionRange(Loc).first; 1638c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1639c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1640c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate: 1641c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot llvm::MemoryBuffer *getFakeBufferForRecovery() const; 1642c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::ContentCache *getFakeContentCacheForRecovery() const; 1643c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1644c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &loadSLocEntry(unsigned Index, bool *Invalid) const; 1645c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1646c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the entry with the given unwrapped FileID. 1647c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &getSLocEntryByID(int ID, 1648c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool *Invalid = nullptr) const { 1649c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(ID != -1 && "Using FileID sentinel value"); 1650c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (ID < 0) 1651c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getLoadedSLocEntryByID(ID, Invalid); 1652c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getLocalSLocEntry(static_cast<unsigned>(ID), Invalid); 1653c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1654c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1655c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry & 1656c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getLoadedSLocEntryByID(int ID, bool *Invalid = nullptr) const { 1657c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid); 1658c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1659c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1660c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Implements the common elements of storing an expansion info struct into 1661c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// the SLocEntry table and producing a source location that refers to it. 1662c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion, 1663c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned TokLength, 1664c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot int LoadedID = 0, 1665c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned LoadedOffset = 0); 1666c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1667c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Return true if the specified FileID contains the 1668c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// specified SourceLocation offset. This is a very hot method. 1669c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot inline bool isOffsetInFileID(FileID FID, unsigned SLocOffset) const { 1670c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::SLocEntry &Entry = getSLocEntry(FID); 1671c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // If the entry is after the offset, it can't contain it. 1672c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (SLocOffset < Entry.getOffset()) return false; 1673c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1674c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // If this is the very last entry then it does. 1675c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (FID.ID == -2) 1676c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return true; 1677c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1678c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // If it is the last local entry, then it does if the location is local. 1679c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size())) 1680c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SLocOffset < NextLocalOffset; 1681c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1682c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Otherwise, the entry after it has to not include it. This works for both 1683c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // local and loaded entries. 1684c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset(); 1685c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1686c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1687c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the previous in-order FileID or an invalid FileID if there 1688c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// is no previous one. 1689c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID getPreviousFileID(FileID FID) const; 1690c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1691c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Returns the next in-order FileID or an invalid FileID if there is 1692c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// no next one. 1693c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID getNextFileID(FileID FID) const; 1694c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1695c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Create a new fileID for the specified ContentCache and 1696c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// include position. 1697c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 1698c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This works regardless of whether the ContentCache corresponds to a 1699c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// file or some other input source. 1700c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID createFileID(const SrcMgr::ContentCache* File, 1701c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation IncludePos, 1702c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SrcMgr::CharacteristicKind DirCharacter, 1703c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot int LoadedID, unsigned LoadedOffset); 1704c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1705c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::ContentCache * 1706c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getOrCreateContentCache(const FileEntry *SourceFile, 1707c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isSystemFile = false); 1708c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1709c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Create a new ContentCache for the specified memory buffer. 1710c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const SrcMgr::ContentCache * 1711c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot createMemBufferContentCache(llvm::MemoryBuffer *Buf, bool DoNotFree); 1712c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1713c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID getFileIDSlow(unsigned SLocOffset) const; 1714c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID getFileIDLocal(unsigned SLocOffset) const; 1715c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID getFileIDLoaded(unsigned SLocOffset) const; 1716c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1717c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getExpansionLocSlowCase(SourceLocation Loc) const; 1718c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const; 1719c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation getFileLocSlowCase(SourceLocation Loc) const; 1720c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1721c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<FileID, unsigned> 1722c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getDecomposedExpansionLocSlowCase(const SrcMgr::SLocEntry *E) const; 1723c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::pair<FileID, unsigned> 1724c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E, 1725c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned Offset) const; 1726c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID) const; 1727c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache, 1728c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot FileID FID, 1729c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation SpellLoc, 1730c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation ExpansionLoc, 1731c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned ExpansionLength) const; 1732c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class ASTReader; 1733c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class ASTWriter; 1734c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 1735c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1736c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Comparison function object. 1737c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate<typename T> 1738c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass BeforeThanCompare; 1739c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1740c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Compare two source locations. 1741c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate<> 1742c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass BeforeThanCompare<SourceLocation> { 1743c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceManager &SM; 1744c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1745c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 1746c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot explicit BeforeThanCompare(SourceManager &SM) : SM(SM) { } 1747c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1748c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool operator()(SourceLocation LHS, SourceLocation RHS) const { 1749c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SM.isBeforeInTranslationUnit(LHS, RHS); 1750c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1751c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 1752c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1753c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Compare two non-overlapping source ranges. 1754c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate<> 1755c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass BeforeThanCompare<SourceRange> { 1756c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceManager &SM; 1757c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1758c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 1759c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot explicit BeforeThanCompare(SourceManager &SM) : SM(SM) { } 1760c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1761c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool operator()(SourceRange LHS, SourceRange RHS) const { 1762c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return SM.isBeforeInTranslationUnit(LHS.getBegin(), RHS.getBegin()); 1763c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 1764c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 1765c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1766c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // end namespace clang 1767c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 1768c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#endif // LLVM_CLANG_BASIC_SOURCEMANAGER_H 1769