Coverage Report

Created: 2019-02-20 07:29

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/FileSystemStatCache.h
Line
Count
Source (jump to first uncovered line)
1
//===- FileSystemStatCache.h - Caching for 'stat' calls ---------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
/// \file
10
/// Defines the FileSystemStatCache interface.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_BASIC_FILESYSTEMSTATCACHE_H
15
#define LLVM_CLANG_BASIC_FILESYSTEMSTATCACHE_H
16
17
#include "clang/Basic/LLVM.h"
18
#include "llvm/ADT/StringMap.h"
19
#include "llvm/ADT/StringRef.h"
20
#include "llvm/Support/Allocator.h"
21
#include "llvm/Support/FileSystem.h"
22
#include <cstdint>
23
#include <ctime>
24
#include <memory>
25
#include <string>
26
#include <utility>
27
28
namespace llvm {
29
30
namespace vfs {
31
32
class File;
33
class FileSystem;
34
35
} // namespace vfs
36
} // namespace llvm
37
38
namespace clang {
39
40
// FIXME: should probably replace this with vfs::Status
41
struct FileData {
42
  std::string Name;
43
  uint64_t Size = 0;
44
  time_t ModTime = 0;
45
  llvm::sys::fs::UniqueID UniqueID;
46
  bool IsDirectory = false;
47
  bool IsNamedPipe = false;
48
  bool InPCH = false;
49
50
  // FIXME: remove this when files support multiple names
51
  bool IsVFSMapped = false;
52
53
1.12M
  FileData() = default;
54
};
55
56
/// Abstract interface for introducing a FileManager cache for 'stat'
57
/// system calls, which is used by precompiled and pretokenized headers to
58
/// improve performance.
59
class FileSystemStatCache {
60
  virtual void anchor();
61
62
public:
63
11
  virtual ~FileSystemStatCache() = default;
64
65
  enum LookupResult {
66
    /// We know the file exists and its cached stat data.
67
    CacheExists,
68
69
    /// We know that the file doesn't exist.
70
    CacheMissing
71
  };
72
73
  /// Get the 'stat' information for the specified path, using the cache
74
  /// to accelerate it if possible.
75
  ///
76
  /// \returns \c true if the path does not exist or \c false if it exists.
77
  ///
78
  /// If isFile is true, then this lookup should only return success for files
79
  /// (not directories).  If it is false this lookup should only return
80
  /// success for directories (not files).  On a successful file lookup, the
81
  /// implementation can optionally fill in \p F with a valid \p File object and
82
  /// the client guarantees that it will close it.
83
  static bool get(StringRef Path, FileData &Data, bool isFile,
84
                  std::unique_ptr<llvm::vfs::File> *F,
85
                  FileSystemStatCache *Cache, llvm::vfs::FileSystem &FS);
86
87
protected:
88
  // FIXME: The pointer here is a non-owning/optional reference to the
89
  // unique_ptr. Optional<unique_ptr<vfs::File>&> might be nicer, but
90
  // Optional needs some work to support references so this isn't possible yet.
91
  virtual LookupResult getStat(StringRef Path, FileData &Data, bool isFile,
92
                               std::unique_ptr<llvm::vfs::File> *F,
93
                               llvm::vfs::FileSystem &FS) = 0;
94
};
95
96
/// A stat "cache" that can be used by FileManager to keep
97
/// track of the results of stat() calls that occur throughout the
98
/// execution of the front end.
99
class MemorizeStatCalls : public FileSystemStatCache {
100
public:
101
  /// The set of stat() calls that have been seen.
102
  llvm::StringMap<FileData, llvm::BumpPtrAllocator> StatCalls;
103
104
  using iterator =
105
      llvm::StringMap<FileData, llvm::BumpPtrAllocator>::const_iterator;
106
107
0
  iterator begin() const { return StatCalls.begin(); }
108
0
  iterator end() const { return StatCalls.end(); }
109
110
  LookupResult getStat(StringRef Path, FileData &Data, bool isFile,
111
                       std::unique_ptr<llvm::vfs::File> *F,
112
                       llvm::vfs::FileSystem &FS) override;
113
};
114
115
} // namespace clang
116
117
#endif // LLVM_CLANG_BASIC_FILESYSTEMSTATCACHE_H