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_DEPENDENCYSCANNING_DEPENDENCYSCANNINGSERVICE_H
10 #define LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGSERVICE_H
11 
12 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
13 #include "llvm/ADT/BitmaskEnum.h"
14 
15 namespace clang {
16 namespace tooling {
17 namespace dependencies {
18 
19 /// The mode in which the dependency scanner will operate to find the
20 /// dependencies.
21 enum class ScanningMode {
22   /// This mode is used to compute the dependencies by running the preprocessor
23   /// over the source files.
24   CanonicalPreprocessing,
25 
26   /// This mode is used to compute the dependencies by running the preprocessor
27   /// with special kind of lexing after scanning header and source files to get
28   /// the minimum necessary preprocessor directives for evaluating includes.
29   DependencyDirectivesScan,
30 };
31 
32 /// The format that is output by the dependency scanner.
33 enum class ScanningOutputFormat {
34   /// This is the Makefile compatible dep format. This will include all of the
35   /// deps necessary for an implicit modules build, but won't include any
36   /// intermodule dependency information.
37   Make,
38 
39   /// This outputs the full clang module dependency graph suitable for use for
40   /// explicitly building modules.
41   Full,
42 
43   /// This outputs the dependency graph for standard c++ modules in P1689R5
44   /// format.
45   P1689,
46 };
47 
48 enum class ScanningOptimizations {
49   None = 0,
50 
51   /// Remove unused header search paths including header maps.
52   HeaderSearch = 1,
53 
54   /// Remove warnings from system modules.
55   SystemWarnings = 2,
56 
57   LLVM_MARK_AS_BITMASK_ENUM(SystemWarnings),
58   All = HeaderSearch | SystemWarnings,
59   Default = All
60 };
61 
62 /// The dependency scanning service contains shared configuration and state that
63 /// is used by the individual dependency scanning workers.
64 class DependencyScanningService {
65 public:
66   DependencyScanningService(
67       ScanningMode Mode, ScanningOutputFormat Format,
68       ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default,
69       bool EagerLoadModules = false);
70 
71   ScanningMode getMode() const { return Mode; }
72 
73   ScanningOutputFormat getFormat() const { return Format; }
74 
75   ScanningOptimizations getOptimizeArgs() const { return OptimizeArgs; }
76 
77   bool shouldEagerLoadModules() const { return EagerLoadModules; }
78 
79   DependencyScanningFilesystemSharedCache &getSharedCache() {
80     return SharedCache;
81   }
82 
83 private:
84   const ScanningMode Mode;
85   const ScanningOutputFormat Format;
86   /// Whether to optimize the modules' command-line arguments.
87   const ScanningOptimizations OptimizeArgs;
88   /// Whether to set up command-lines to load PCM files eagerly.
89   const bool EagerLoadModules;
90   /// The global file system cache.
91   DependencyScanningFilesystemSharedCache SharedCache;
92 };
93 
94 } // end namespace dependencies
95 } // end namespace tooling
96 } // end namespace clang
97 
98 #endif // LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGSERVICE_H
99