1 //===- DependencyScanningService.h - clang-scan-deps service ===-*- 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 #ifndef LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_SERVICE_H
10 #define LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_SERVICE_H
11 
12 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
13 
14 namespace clang {
15 namespace tooling {
16 namespace dependencies {
17 
18 /// The mode in which the dependency scanner will operate to find the
19 /// dependencies.
20 enum class ScanningMode {
21   /// This mode is used to compute the dependencies by running the preprocessor
22   /// over
23   /// the unmodified source files.
24   CanonicalPreprocessing,
25 
26   /// This mode is used to compute the dependencies by running the preprocessor
27   /// over
28   /// the source files that have been minimized to contents that might affect
29   /// the dependencies.
30   MinimizedSourcePreprocessing
31 };
32 
33 /// The format that is output by the dependency scanner.
34 enum class ScanningOutputFormat {
35   /// This is the Makefile compatible dep format. This will include all of the
36   /// deps necessary for an implicit modules build, but won't include any
37   /// intermodule dependency information.
38   Make,
39 
40   /// This outputs the full module dependency graph suitable for use for
41   /// explicitly building modules.
42   Full,
43 };
44 
45 /// The dependency scanning service contains the shared state that is used by
46 /// the invidual dependency scanning workers.
47 class DependencyScanningService {
48 public:
49   DependencyScanningService(ScanningMode Mode, ScanningOutputFormat Format,
50                             bool ReuseFileManager = true,
51                             bool SkipExcludedPPRanges = true);
52 
53   ScanningMode getMode() const { return Mode; }
54 
55   ScanningOutputFormat getFormat() const { return Format; }
56 
57   bool canReuseFileManager() const { return ReuseFileManager; }
58 
59   bool canSkipExcludedPPRanges() const { return SkipExcludedPPRanges; }
60 
61   DependencyScanningFilesystemSharedCache &getSharedCache() {
62     return SharedCache;
63   }
64 
65 private:
66   const ScanningMode Mode;
67   const ScanningOutputFormat Format;
68   const bool ReuseFileManager;
69   /// Set to true to use the preprocessor optimization that skips excluded PP
70   /// ranges by bumping the buffer pointer in the lexer instead of lexing the
71   /// tokens in the range until reaching the corresponding directive.
72   const bool SkipExcludedPPRanges;
73   /// The global file system cache.
74   DependencyScanningFilesystemSharedCache SharedCache;
75 };
76 
77 } // end namespace dependencies
78 } // end namespace tooling
79 } // end namespace clang
80 
81 #endif // LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_SERVICE_H
82