@@ -24,8 +24,9 @@ namespace {
2424class IncludeModernizePPCallbacks : public PPCallbacks {
2525public:
2626 explicit IncludeModernizePPCallbacks (
27- std::vector<IncludeMarker> &IncludesToBeProcessed, LangOptions LangOpts,
28- const SourceManager &SM, bool CheckHeaderFile);
27+ std::vector<IncludeMarker> &IncludesToBeProcessed,
28+ const LangOptions &LangOpts, const SourceManager &SM,
29+ bool CheckHeaderFile);
2930
3031 void InclusionDirective (SourceLocation HashLoc, const Token &IncludeTok,
3132 StringRef FileName, bool IsAngled,
@@ -37,8 +38,7 @@ class IncludeModernizePPCallbacks : public PPCallbacks {
3738
3839private:
3940 std::vector<IncludeMarker> &IncludesToBeProcessed;
40- LangOptions LangOpts;
41- llvm::StringMap<std::string> CStyledHeaderToCxx;
41+ llvm::StringMap<StringRef> CStyledHeaderToCxx;
4242 llvm::StringSet<> DeleteHeaders;
4343 const SourceManager &SM;
4444 bool CheckHeaderFile;
@@ -131,48 +131,35 @@ void DeprecatedHeadersCheck::check(
131131}
132132
133133IncludeModernizePPCallbacks::IncludeModernizePPCallbacks (
134- std::vector<IncludeMarker> &IncludesToBeProcessed, LangOptions LangOpts,
135- const SourceManager &SM, bool CheckHeaderFile)
136- : IncludesToBeProcessed(IncludesToBeProcessed), LangOpts(LangOpts), SM(SM),
134+ std::vector<IncludeMarker> &IncludesToBeProcessed,
135+ const LangOptions &LangOpts, const SourceManager &SM, bool CheckHeaderFile)
136+ : IncludesToBeProcessed(IncludesToBeProcessed), SM(SM),
137137 CheckHeaderFile(CheckHeaderFile) {
138- for (const auto &KeyValue :
139- std::vector<std::pair<llvm::StringRef, std::string>>(
140- {{" assert.h" , " cassert" },
141- {" complex.h" , " complex" },
142- {" ctype.h" , " cctype" },
143- {" errno.h" , " cerrno" },
144- {" float.h" , " cfloat" },
145- {" limits.h" , " climits" },
146- {" locale.h" , " clocale" },
147- {" math.h" , " cmath" },
148- {" setjmp.h" , " csetjmp" },
149- {" signal.h" , " csignal" },
150- {" stdarg.h" , " cstdarg" },
151- {" stddef.h" , " cstddef" },
152- {" stdio.h" , " cstdio" },
153- {" stdlib.h" , " cstdlib" },
154- {" string.h" , " cstring" },
155- {" time.h" , " ctime" },
156- {" wchar.h" , " cwchar" },
157- {" wctype.h" , " cwctype" }})) {
158- CStyledHeaderToCxx.insert (KeyValue);
159- }
160- // Add C++11 headers.
161- if (LangOpts.CPlusPlus11 ) {
162- for (const auto &KeyValue :
163- std::vector<std::pair<llvm::StringRef, std::string>>(
164- {{" fenv.h" , " cfenv" },
165- {" stdint.h" , " cstdint" },
166- {" inttypes.h" , " cinttypes" },
167- {" tgmath.h" , " ctgmath" },
168- {" uchar.h" , " cuchar" }})) {
169- CStyledHeaderToCxx.insert (KeyValue);
170- }
171- }
172- for (const auto &Key :
173- std::vector<std::string>({" stdalign.h" , " stdbool.h" , " iso646.h" })) {
174- DeleteHeaders.insert (Key);
175- }
138+
139+ static constexpr std::pair<StringRef, StringRef> CXX98Headers[] = {
140+ {" assert.h" , " cassert" }, {" complex.h" , " complex" },
141+ {" ctype.h" , " cctype" }, {" errno.h" , " cerrno" },
142+ {" float.h" , " cfloat" }, {" limits.h" , " climits" },
143+ {" locale.h" , " clocale" }, {" math.h" , " cmath" },
144+ {" setjmp.h" , " csetjmp" }, {" signal.h" , " csignal" },
145+ {" stdarg.h" , " cstdarg" }, {" stddef.h" , " cstddef" },
146+ {" stdio.h" , " cstdio" }, {" stdlib.h" , " cstdlib" },
147+ {" string.h" , " cstring" }, {" time.h" , " ctime" },
148+ {" wchar.h" , " cwchar" }, {" wctype.h" , " cwctype" },
149+ };
150+ CStyledHeaderToCxx.insert (std::begin (CXX98Headers), std::end (CXX98Headers));
151+
152+ static constexpr std::pair<StringRef, StringRef> CXX11Headers[] = {
153+ {" fenv.h" , " cfenv" }, {" stdint.h" , " cstdint" },
154+ {" inttypes.h" , " cinttypes" }, {" tgmath.h" , " ctgmath" },
155+ {" uchar.h" , " cuchar" },
156+ };
157+ if (LangOpts.CPlusPlus11 )
158+ CStyledHeaderToCxx.insert (std::begin (CXX11Headers), std::end (CXX11Headers));
159+
160+ static constexpr StringRef HeadersToDelete[] = {" stdalign.h" , " stdbool.h" ,
161+ " iso646.h" };
162+ DeleteHeaders.insert_range (HeadersToDelete);
176163}
177164
178165void IncludeModernizePPCallbacks::InclusionDirective (
@@ -205,7 +192,7 @@ void IncludeModernizePPCallbacks::InclusionDirective(
205192 } else if (DeleteHeaders.contains (FileName)) {
206193 IncludesToBeProcessed.emplace_back (
207194 // NOLINTNEXTLINE(modernize-use-emplace) - false-positive
208- IncludeMarker{std::string {}, FileName,
195+ IncludeMarker{StringRef {}, FileName,
209196 SourceRange{HashLoc, FilenameRange.getEnd ()}, DiagLoc});
210197 }
211198}
0 commit comments