//===--- SourceManager.cpp - Track and cache source files -----------------===////// The LLVM Compiler Infrastructure//// This file is distributed under the University of Illinois Open Source// License. See LICENSE.TXT for details.////===----------------------------------------------------------------------===////// This file implements the SourceManager interface.////===----------------------------------------------------------------------===//#include"clang/Basic/SourceManager.h"#include"clang/Basic/SourceManagerInternals.h"#include"clang/Basic/Diagnostic.h"#include"clang/Basic/FileManager.h"#include"llvm/ADT/StringSwitch.h"#include"llvm/ADT/Optional.h"#include"llvm/Support/Compiler.h"#include"llvm/Support/MemoryBuffer.h"#include"llvm/Support/raw_ostream.h"#include"llvm/Support/Path.h"#include<algorithm>#include<string>#include<cstring>#include<sys/stat.h>usingnamespaceclang;usingnamespaceSrcMgr;usingllvm::MemoryBuffer;//===----------------------------------------------------------------------===//// SourceManager Helper Classes//===----------------------------------------------------------------------===//ContentCache::~ContentCache(){if(shouldFreeBuffer())deleteBuffer.getPointer();}/// getSizeBytesMapped - Returns the number of bytes actually mapped for/// this ContentCache. This can be 0 if the MemBuffer was not actually/// instantiated.unsignedContentCache::getSizeBytesMapped()const{returnBuffer.getPointer()?Buffer.getPointer()->getBufferSize():0;}/// getSize - Returns the size of the content encapsulated by this ContentCache./// This can be the size of the source file or the size of an arbitrary/// scratch buffer. If the ContentCache encapsulates a source file, that/// file is not lazily brought in from disk to satisfy this query.unsignedContentCache::getSize()const{returnBuffer.getPointer()?(unsigned)Buffer.getPointer()->getBufferSize():(unsigned)Entry->getSize();}voidContentCache::replaceBuffer(constllvm::MemoryBuffer*B,boolDoNotFree){assert(B!=Buffer.getPointer());if(shouldFreeBuffer())deleteBuffer.getPointer();Buffer.setPointer(B);Buffer.setInt(DoNotFree?DoNotFreeFlag: