annotate clang-tools-extra/modularize/CoverageChecker.h @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 0572611fdcc8
children 1f2b6ac9f198
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===-- CoverageChecker.h - Module map coverage checker -*- C++ -*-------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===--------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8 ///
anatofuz
parents:
diff changeset
9 /// \file
anatofuz
parents:
diff changeset
10 /// Definitions for CoverageChecker.
anatofuz
parents:
diff changeset
11 ///
anatofuz
parents:
diff changeset
12 //===--------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 #ifndef COVERAGECHECKER_H
anatofuz
parents:
diff changeset
15 #define COVERAGECHECKER_H
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 #include "clang/Basic/Diagnostic.h"
anatofuz
parents:
diff changeset
18 #include "clang/Basic/FileManager.h"
anatofuz
parents:
diff changeset
19 #include "clang/Basic/LangOptions.h"
anatofuz
parents:
diff changeset
20 #include "clang/Basic/TargetInfo.h"
anatofuz
parents:
diff changeset
21 #include "clang/Basic/TargetOptions.h"
anatofuz
parents:
diff changeset
22 #include "clang/Frontend/TextDiagnosticPrinter.h"
anatofuz
parents:
diff changeset
23 #include "clang/Lex/HeaderSearch.h"
anatofuz
parents:
diff changeset
24 #include "clang/Lex/HeaderSearchOptions.h"
anatofuz
parents:
diff changeset
25 #include "clang/Lex/ModuleMap.h"
anatofuz
parents:
diff changeset
26 #include "clang/Lex/Preprocessor.h"
anatofuz
parents:
diff changeset
27 #include "llvm/ADT/StringSet.h"
anatofuz
parents:
diff changeset
28 #include "llvm/Support/Host.h"
anatofuz
parents:
diff changeset
29 #include <string>
anatofuz
parents:
diff changeset
30 #include <vector>
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 namespace Modularize {
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 /// Module map checker class.
anatofuz
parents:
diff changeset
35 /// This is the heart of the checker.
anatofuz
parents:
diff changeset
36 /// The doChecks function does the main work.
anatofuz
parents:
diff changeset
37 /// The data members store the options and internally collected data.
anatofuz
parents:
diff changeset
38 class CoverageChecker {
anatofuz
parents:
diff changeset
39 // Checker arguments.
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 /// The module.modulemap file path. Can be relative or absolute.
anatofuz
parents:
diff changeset
42 llvm::StringRef ModuleMapPath;
anatofuz
parents:
diff changeset
43 /// The include paths to check for files.
anatofuz
parents:
diff changeset
44 /// (Note that other directories above these paths are ignored.
anatofuz
parents:
diff changeset
45 /// To expect all files to be accounted for from the module.modulemap
anatofuz
parents:
diff changeset
46 /// file directory on down, leave this empty.)
anatofuz
parents:
diff changeset
47 std::vector<std::string> IncludePaths;
anatofuz
parents:
diff changeset
48 /// The remaining arguments, to be passed to the front end.
anatofuz
parents:
diff changeset
49 llvm::ArrayRef<std::string> CommandLine;
anatofuz
parents:
diff changeset
50 /// The module map.
anatofuz
parents:
diff changeset
51 clang::ModuleMap *ModMap;
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 // Internal data.
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 /// Directory containing the module map.
anatofuz
parents:
diff changeset
56 /// Might be relative to the current directory, or absolute.
anatofuz
parents:
diff changeset
57 std::string ModuleMapDirectory;
anatofuz
parents:
diff changeset
58 /// Set of all the headers found in the module map.
anatofuz
parents:
diff changeset
59 llvm::StringSet<llvm::MallocAllocator> ModuleMapHeadersSet;
anatofuz
parents:
diff changeset
60 /// All the headers found in the file system starting at the
anatofuz
parents:
diff changeset
61 /// module map, or the union of those from the include paths.
anatofuz
parents:
diff changeset
62 std::vector<std::string> FileSystemHeaders;
anatofuz
parents:
diff changeset
63 /// Headers found in file system, but not in module map.
anatofuz
parents:
diff changeset
64 std::vector<std::string> UnaccountedForHeaders;
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 public:
anatofuz
parents:
diff changeset
67 /// Constructor.
anatofuz
parents:
diff changeset
68 /// You can use the static createCoverageChecker to create an instance
anatofuz
parents:
diff changeset
69 /// of this object.
anatofuz
parents:
diff changeset
70 /// \param ModuleMapPath The module.modulemap file path.
anatofuz
parents:
diff changeset
71 /// Can be relative or absolute.
anatofuz
parents:
diff changeset
72 /// \param IncludePaths The include paths to check for files.
anatofuz
parents:
diff changeset
73 /// (Note that other directories above these paths are ignored.
anatofuz
parents:
diff changeset
74 /// To expect all files to be accounted for from the module.modulemap
anatofuz
parents:
diff changeset
75 /// file directory on down, leave this empty.)
anatofuz
parents:
diff changeset
76 /// \param CommandLine Compile command line arguments.
anatofuz
parents:
diff changeset
77 /// \param ModuleMap The module map to check.
anatofuz
parents:
diff changeset
78 CoverageChecker(llvm::StringRef ModuleMapPath,
anatofuz
parents:
diff changeset
79 std::vector<std::string> &IncludePaths,
anatofuz
parents:
diff changeset
80 llvm::ArrayRef<std::string> CommandLine,
anatofuz
parents:
diff changeset
81 clang::ModuleMap *ModuleMap);
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 /// Create instance of CoverageChecker.
anatofuz
parents:
diff changeset
84 /// \param ModuleMapPath The module.modulemap file path.
anatofuz
parents:
diff changeset
85 /// Can be relative or absolute.
anatofuz
parents:
diff changeset
86 /// \param IncludePaths The include paths to check for files.
anatofuz
parents:
diff changeset
87 /// (Note that other directories above these paths are ignored.
anatofuz
parents:
diff changeset
88 /// To expect all files to be accounted for from the module.modulemap
anatofuz
parents:
diff changeset
89 /// file directory on down, leave this empty.)
anatofuz
parents:
diff changeset
90 /// \param CommandLine Compile command line arguments.
anatofuz
parents:
diff changeset
91 /// \param ModuleMap The module map to check.
anatofuz
parents:
diff changeset
92 /// \returns Initialized CoverageChecker object.
anatofuz
parents:
diff changeset
93 static std::unique_ptr<CoverageChecker> createCoverageChecker(
anatofuz
parents:
diff changeset
94 llvm::StringRef ModuleMapPath, std::vector<std::string> &IncludePaths,
anatofuz
parents:
diff changeset
95 llvm::ArrayRef<std::string> CommandLine, clang::ModuleMap *ModuleMap);
anatofuz
parents:
diff changeset
96
anatofuz
parents:
diff changeset
97 /// Do checks.
anatofuz
parents:
diff changeset
98 /// Starting from the directory of the module.modulemap file,
anatofuz
parents:
diff changeset
99 /// Find all header files, optionally looking only at files
anatofuz
parents:
diff changeset
100 /// covered by the include path options, and compare against
anatofuz
parents:
diff changeset
101 /// the headers referenced by the module.modulemap file.
anatofuz
parents:
diff changeset
102 /// Display warnings for unaccounted-for header files.
anatofuz
parents:
diff changeset
103 /// \returns 0 if there were no errors or warnings, 1 if there
anatofuz
parents:
diff changeset
104 /// were warnings, 2 if any other problem, such as a bad
anatofuz
parents:
diff changeset
105 /// module map path argument was specified.
anatofuz
parents:
diff changeset
106 std::error_code doChecks();
anatofuz
parents:
diff changeset
107
anatofuz
parents:
diff changeset
108 // The following functions are called by doChecks.
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 /// Collect module headers.
anatofuz
parents:
diff changeset
111 /// Walks the modules and collects referenced headers into
anatofuz
parents:
diff changeset
112 /// ModuleMapHeadersSet.
anatofuz
parents:
diff changeset
113 void collectModuleHeaders();
anatofuz
parents:
diff changeset
114
anatofuz
parents:
diff changeset
115 /// Collect referenced headers from one module.
anatofuz
parents:
diff changeset
116 /// Collects the headers referenced in the given module into
anatofuz
parents:
diff changeset
117 /// ModuleMapHeadersSet.
anatofuz
parents:
diff changeset
118 /// \param Mod The module reference.
anatofuz
parents:
diff changeset
119 /// \return True if no errors.
anatofuz
parents:
diff changeset
120 bool collectModuleHeaders(const clang::Module &Mod);
anatofuz
parents:
diff changeset
121
anatofuz
parents:
diff changeset
122 /// Collect headers from an umbrella directory.
anatofuz
parents:
diff changeset
123 /// \param UmbrellaDirName The umbrella directory name.
anatofuz
parents:
diff changeset
124 /// \return True if no errors.
anatofuz
parents:
diff changeset
125 bool collectUmbrellaHeaders(llvm::StringRef UmbrellaDirName);
anatofuz
parents:
diff changeset
126
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
127 /// Collect headers referenced from an umbrella file.
150
anatofuz
parents:
diff changeset
128 /// \param UmbrellaHeaderName The umbrella file path.
anatofuz
parents:
diff changeset
129 /// \return True if no errors.
anatofuz
parents:
diff changeset
130 bool collectUmbrellaHeaderHeaders(llvm::StringRef UmbrellaHeaderName);
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 /// Called from CoverageCheckerCallbacks to track a header included
anatofuz
parents:
diff changeset
133 /// from an umbrella header.
anatofuz
parents:
diff changeset
134 /// \param HeaderName The header file path.
anatofuz
parents:
diff changeset
135 void collectUmbrellaHeaderHeader(llvm::StringRef HeaderName);
anatofuz
parents:
diff changeset
136
anatofuz
parents:
diff changeset
137 /// Collect file system header files.
anatofuz
parents:
diff changeset
138 /// This function scans the file system for header files,
anatofuz
parents:
diff changeset
139 /// starting at the directory of the module.modulemap file,
anatofuz
parents:
diff changeset
140 /// optionally filtering out all but the files covered by
anatofuz
parents:
diff changeset
141 /// the include path options.
anatofuz
parents:
diff changeset
142 /// \returns True if no errors.
anatofuz
parents:
diff changeset
143 bool collectFileSystemHeaders();
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 /// Collect file system header files from the given path.
anatofuz
parents:
diff changeset
146 /// This function scans the file system for header files,
anatofuz
parents:
diff changeset
147 /// starting at the given directory, which is assumed to be
anatofuz
parents:
diff changeset
148 /// relative to the directory of the module.modulemap file.
anatofuz
parents:
diff changeset
149 /// \returns True if no errors.
anatofuz
parents:
diff changeset
150 bool collectFileSystemHeaders(llvm::StringRef IncludePath);
anatofuz
parents:
diff changeset
151
anatofuz
parents:
diff changeset
152 /// Find headers unaccounted-for in module map.
anatofuz
parents:
diff changeset
153 /// This function compares the list of collected header files
anatofuz
parents:
diff changeset
154 /// against those referenced in the module map. Display
anatofuz
parents:
diff changeset
155 /// warnings for unaccounted-for header files.
anatofuz
parents:
diff changeset
156 /// Save unaccounted-for file list for possible.
anatofuz
parents:
diff changeset
157 /// fixing action.
anatofuz
parents:
diff changeset
158 void findUnaccountedForHeaders();
anatofuz
parents:
diff changeset
159 };
anatofuz
parents:
diff changeset
160
anatofuz
parents:
diff changeset
161 } // end namespace Modularize
anatofuz
parents:
diff changeset
162
anatofuz
parents:
diff changeset
163 #endif // COVERAGECHECKER_H