@@ -24,8 +24,9 @@ namespace {
24
24
class IncludeModernizePPCallbacks : public PPCallbacks {
25
25
public:
26
26
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);
29
30
30
31
void InclusionDirective (SourceLocation HashLoc, const Token &IncludeTok,
31
32
StringRef FileName, bool IsAngled,
@@ -37,8 +38,7 @@ class IncludeModernizePPCallbacks : public PPCallbacks {
37
38
38
39
private:
39
40
std::vector<IncludeMarker> &IncludesToBeProcessed;
40
- LangOptions LangOpts;
41
- llvm::StringMap<std::string> CStyledHeaderToCxx;
41
+ llvm::StringMap<StringRef> CStyledHeaderToCxx;
42
42
llvm::StringSet<> DeleteHeaders;
43
43
const SourceManager &SM;
44
44
bool CheckHeaderFile;
@@ -131,48 +131,38 @@ void DeprecatedHeadersCheck::check(
131
131
}
132
132
133
133
IncludeModernizePPCallbacks::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),
137
137
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" }})) {
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
+ for (const auto &KeyValue : CXX98Headers)
158
151
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" }})) {
152
+
153
+ static constexpr std::pair<StringRef, StringRef> CXX11Headers[] = {
154
+ {" fenv.h" , " cfenv" }, {" stdint.h" , " cstdint" },
155
+ {" inttypes.h" , " cinttypes" }, {" tgmath.h" , " ctgmath" },
156
+ {" uchar.h" , " cuchar" },
157
+ };
158
+ if (LangOpts.CPlusPlus11 )
159
+ for (const auto &KeyValue : CXX11Headers)
169
160
CStyledHeaderToCxx.insert (KeyValue);
170
- }
171
- }
172
- for ( const auto &Key :
173
- std::vector<std::string>({ " stdalign.h " , " stdbool.h " , " iso646.h " })) {
161
+
162
+ static constexpr StringRef HeadersToDelete[] = { " stdalign.h " , " stdbool.h " ,
163
+ " iso646.h " };
164
+ for ( const auto &Key : HeadersToDelete)
174
165
DeleteHeaders.insert (Key);
175
- }
176
166
}
177
167
178
168
void IncludeModernizePPCallbacks::InclusionDirective (
@@ -205,7 +195,7 @@ void IncludeModernizePPCallbacks::InclusionDirective(
205
195
} else if (DeleteHeaders.contains (FileName)) {
206
196
IncludesToBeProcessed.emplace_back (
207
197
// NOLINTNEXTLINE(modernize-use-emplace) - false-positive
208
- IncludeMarker{std::string {}, FileName,
198
+ IncludeMarker{StringRef {}, FileName,
209
199
SourceRange{HashLoc, FilenameRange.getEnd ()}, DiagLoc});
210
200
}
211
201
}
0 commit comments