Skip to content

Commit 13a0eae

Browse files
authored
Merge branch 'main' into stack-typedef
2 parents 853179f + 913849e commit 13a0eae

File tree

312 files changed

+3141
-1335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+3141
-1335
lines changed

clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace clang {
2929
namespace doc {
3030
static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
3131
StringRef Path, raw_fd_ostream &OS,
32-
const ClangDocContext &CDCtx);
32+
const ClangDocContext &CDCtx,
33+
StringRef HTMLRootPath);
3334

3435
static Error createFileOpenError(StringRef FileName, std::error_code EC) {
3536
return createFileError("cannot open file " + FileName, EC);
@@ -159,16 +160,24 @@ Error MustacheHTMLGenerator::generateDocs(
159160
{
160161
llvm::TimeTraceScope TS("Iterate JSON files");
161162
std::error_code EC;
162-
sys::fs::directory_iterator JSONIter(JSONPath, EC);
163+
sys::fs::recursive_directory_iterator JSONIter(JSONPath, EC);
163164
std::vector<json::Value> JSONFiles;
164165
JSONFiles.reserve(Infos.size());
165166
if (EC)
166167
return createStringError("Failed to create directory iterator.");
167168

168-
SmallString<128> HTMLDirPath(RootDir.str() + "/html/");
169+
SmallString<128> HTMLDirPath(RootDir.str() + "/html");
169170
if (auto EC = sys::fs::create_directories(HTMLDirPath))
170171
return createFileError(HTMLDirPath, EC);
171-
while (JSONIter != sys::fs::directory_iterator()) {
172+
while (JSONIter != sys::fs::recursive_directory_iterator()) {
173+
// create the same directory structure in the HTML dir
174+
if (JSONIter->type() == sys::fs::file_type::directory_file) {
175+
SmallString<128> HTMLClonedPath(JSONIter->path());
176+
sys::path::replace_path_prefix(HTMLClonedPath, JSONPath, HTMLDirPath);
177+
if (auto EC = sys::fs::create_directories(HTMLClonedPath))
178+
return createFileError(HTMLClonedPath, EC);
179+
}
180+
172181
if (EC)
173182
return createFileError("Failed to iterate: " + JSONIter->path(), EC);
174183

@@ -190,15 +199,16 @@ Error MustacheHTMLGenerator::generateDocs(
190199
return Parsed.takeError();
191200

192201
std::error_code FileErr;
193-
SmallString<128> HTMLFilePath(HTMLDirPath);
194-
sys::path::append(HTMLFilePath, sys::path::filename(Path));
202+
SmallString<128> HTMLFilePath(JSONIter->path());
203+
sys::path::replace_path_prefix(HTMLFilePath, JSONPath, HTMLDirPath);
195204
sys::path::replace_extension(HTMLFilePath, "html");
196205
raw_fd_ostream InfoOS(HTMLFilePath, FileErr, sys::fs::OF_None);
197206
if (FileErr)
198207
return createFileOpenError(Path, FileErr);
199208

200-
if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLFilePath),
201-
HTMLFilePath, InfoOS, CDCtx))
209+
if (Error Err =
210+
generateDocForJSON(*Parsed, sys::path::stem(HTMLFilePath),
211+
HTMLFilePath, InfoOS, CDCtx, HTMLDirPath))
202212
return Err;
203213
JSONIter.increment(EC);
204214
}
@@ -207,16 +217,16 @@ Error MustacheHTMLGenerator::generateDocs(
207217
return Error::success();
208218
}
209219

210-
static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V) {
220+
static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
221+
SmallString<128> RelativeHTMLPath) {
211222
V.getAsObject()->insert({"ProjectName", CDCtx.ProjectName});
212223
json::Value StylesheetArr = Array();
213-
SmallString<128> RelativePath("./");
214-
sys::path::native(RelativePath, sys::path::Style::posix);
224+
sys::path::native(RelativeHTMLPath, sys::path::Style::posix);
215225

216226
auto *SSA = StylesheetArr.getAsArray();
217227
SSA->reserve(CDCtx.UserStylesheets.size());
218228
for (const auto &FilePath : CDCtx.UserStylesheets) {
219-
SmallString<128> StylesheetPath = RelativePath;
229+
SmallString<128> StylesheetPath = RelativeHTMLPath;
220230
sys::path::append(StylesheetPath, sys::path::Style::posix,
221231
sys::path::filename(FilePath));
222232
SSA->emplace_back(StylesheetPath);
@@ -227,7 +237,7 @@ static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V) {
227237
auto *SCA = ScriptArr.getAsArray();
228238
SCA->reserve(CDCtx.JsScripts.size());
229239
for (auto Script : CDCtx.JsScripts) {
230-
SmallString<128> JsPath = RelativePath;
240+
SmallString<128> JsPath = RelativeHTMLPath;
231241
sys::path::append(JsPath, sys::path::Style::posix,
232242
sys::path::filename(Script));
233243
SCA->emplace_back(JsPath);
@@ -238,7 +248,8 @@ static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V) {
238248

239249
static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
240250
StringRef Path, raw_fd_ostream &OS,
241-
const ClangDocContext &CDCtx) {
251+
const ClangDocContext &CDCtx,
252+
StringRef HTMLRootPath) {
242253
auto StrValue = (*JSON.getAsObject())["InfoType"];
243254
if (StrValue.kind() != json::Value::Kind::String)
244255
return createStringError("JSON file '%s' does not contain key: 'InfoType'.",
@@ -249,13 +260,17 @@ static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
249260
"JSON file '%s' does not contain 'InfoType' field as a string.",
250261
Filename.str().c_str());
251262

263+
SmallString<128> PathVec(Path);
264+
// Remove filename, or else the relative path will have an extra "../"
265+
sys::path::remove_filename(PathVec);
266+
auto RelativeHTMLPath = computeRelativePath(HTMLRootPath, PathVec);
252267
if (ObjTypeStr.value() == "namespace") {
253-
if (auto Err = setupTemplateValue(CDCtx, JSON))
268+
if (auto Err = setupTemplateValue(CDCtx, JSON, RelativeHTMLPath))
254269
return Err;
255270
assert(NamespaceTemplate && "NamespaceTemplate is nullptr.");
256271
NamespaceTemplate->render(JSON, OS);
257272
} else if (ObjTypeStr.value() == "record") {
258-
if (auto Err = setupTemplateValue(CDCtx, JSON))
273+
if (auto Err = setupTemplateValue(CDCtx, JSON, RelativeHTMLPath))
259274
return Err;
260275
assert(RecordTemplate && "RecordTemplate is nullptr.");
261276
RecordTemplate->render(JSON, OS);

clang-tools-extra/clang-doc/JSONGenerator.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -581,22 +581,14 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
581581
if (I->IT == InfoType::IT_record) {
582582
auto *RecordSymbolInfo = static_cast<SymbolInfo *>(I);
583583
FileName = RecordSymbolInfo->MangledName;
584-
} else if (I->USR == GlobalNamespaceID)
584+
} else if (I->IT == InfoType::IT_namespace) {
585585
FileName = "index";
586-
else if (I->IT == InfoType::IT_namespace) {
587-
for (const auto &NS : I->Namespace) {
588-
FileName += NS.Name;
589-
FileName += "_";
590-
}
591-
FileName += I->Name;
592586
} else
593587
FileName = I->Name;
594588
sys::path::append(Path, FileName + ".json");
595589
return FileName;
596590
}
597591

598-
// FIXME: Revert back to creating nested directories for namespaces instead of
599-
// putting everything in a flat directory structure.
600592
Error JSONGenerator::generateDocs(
601593
StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
602594
const ClangDocContext &CDCtx) {
@@ -609,6 +601,7 @@ Error JSONGenerator::generateDocs(
609601
auto RootDirStr = RootDir.str() + "/json";
610602
StringRef JSONDir = StringRef(RootDirStr);
611603
sys::path::native(JSONDir, Path);
604+
sys::path::append(Path, Info->getRelativeFilePath(""));
612605
if (!CreatedDirs.contains(Path)) {
613606
if (std::error_code Err = sys::fs::create_directories(Path);
614607
Err != std::error_code())

clang-tools-extra/clang-doc/assets/class-template.mustache

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@
141141
<div>
142142
{{#PublicMembers}}
143143
<div id="{{Name}}" class="delimiter-container">
144-
<pre>
145-
<code class="language-cpp code-clang-doc" >{{Type}} {{Name}}</code>
146-
</pre>
144+
<pre><code class="language-cpp code-clang-doc" >{{Type}} {{Name}}</code></pre>
147145
{{#MemberComments}}
148146
<div>
149147
{{>Comments}}
@@ -160,9 +158,7 @@
160158
<div>
161159
{{#Obj}}
162160
<div id="{{Name}}" class="delimiter-container">
163-
<pre>
164-
<code class="language-cpp code-clang-doc" >{{Type}} {{Name}}</code>
165-
</pre>
161+
<pre><code class="language-cpp code-clang-doc" >{{Type}} {{Name}}</code></pre>
166162
{{#MemberComments}}
167163
<div>
168164
{{>Comments}}

clang-tools-extra/clang-doc/assets/namespace-template.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@
9292
{{#Records}}
9393
<li id="{{USR}}" style="max-height: 40px;">
9494
<a href="{{DocumentationFileName}}.html">
95-
<pre>
96-
<code class="language-cpp code-clang-doc">class {{Name}}</code>
97-
</pre>
95+
<pre><code class="language-cpp code-clang-doc">class {{Name}}</code></pre>
9896
</a>
9997
</li>
10098
{{/Records}}

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ class ErrorReporter {
117117

118118
void reportDiagnostic(const ClangTidyError &Error) {
119119
const tooling::DiagnosticMessage &Message = Error.Message;
120-
SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);
120+
const SourceLocation Loc =
121+
getLocation(Message.FilePath, Message.FileOffset);
121122
// Contains a pair for each attempted fix: location and whether the fix was
122123
// applied successfully.
123124
SmallVector<std::pair<SourceLocation, bool>, 4> FixLocations;
@@ -157,11 +158,11 @@ class ErrorReporter {
157158
// FIXME: Implement better conflict handling.
158159
llvm::errs() << "Trying to resolve conflict: "
159160
<< llvm::toString(std::move(Err)) << "\n";
160-
unsigned NewOffset =
161+
const unsigned NewOffset =
161162
Replacements.getShiftedCodePosition(R.getOffset());
162-
unsigned NewLength = Replacements.getShiftedCodePosition(
163-
R.getOffset() + R.getLength()) -
164-
NewOffset;
163+
const unsigned NewLength = Replacements.getShiftedCodePosition(
164+
R.getOffset() + R.getLength()) -
165+
NewOffset;
165166
if (NewLength == R.getLength()) {
166167
R = Replacement(R.getFilePath(), NewOffset, NewLength,
167168
R.getReplacementText());
@@ -200,7 +201,7 @@ class ErrorReporter {
200201

201202
for (const auto &FileAndReplacements : FileReplacements) {
202203
Rewriter Rewrite(SourceMgr, LangOpts);
203-
StringRef File = FileAndReplacements.first();
204+
const StringRef File = FileAndReplacements.first();
204205
VFS.setCurrentWorkingDirectory(FileAndReplacements.second.BuildDir);
205206
llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
206207
SourceMgr.getFileManager().getBufferForFile(File);
@@ -210,7 +211,7 @@ class ErrorReporter {
210211
// FIXME: Maybe don't apply fixes for other files as well.
211212
continue;
212213
}
213-
StringRef Code = Buffer.get()->getBuffer();
214+
const StringRef Code = Buffer.get()->getBuffer();
214215
auto Style = format::getStyle(
215216
*Context.getOptionsForFile(File).FormatStyle, File, "none");
216217
if (!Style) {
@@ -262,7 +263,7 @@ class ErrorReporter {
262263
if (!File)
263264
return {};
264265

265-
FileID ID = SourceMgr.getOrCreateFileID(*File, SrcMgr::C_User);
266+
const FileID ID = SourceMgr.getOrCreateFileID(*File, SrcMgr::C_User);
266267
return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
267268
}
268269

@@ -284,7 +285,8 @@ class ErrorReporter {
284285
}
285286

286287
void reportNote(const tooling::DiagnosticMessage &Message) {
287-
SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);
288+
const SourceLocation Loc =
289+
getLocation(Message.FilePath, Message.FileOffset);
288290
auto Diag =
289291
Diags.Report(Loc, Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0"))
290292
<< Message.Message;
@@ -296,8 +298,9 @@ class ErrorReporter {
296298
CharSourceRange getRange(const FileByteRange &Range) {
297299
SmallString<128> AbsoluteFilePath{Range.FilePath};
298300
Files.makeAbsolutePath(AbsoluteFilePath);
299-
SourceLocation BeginLoc = getLocation(AbsoluteFilePath, Range.FileOffset);
300-
SourceLocation EndLoc = BeginLoc.getLocWithOffset(Range.Length);
301+
const SourceLocation BeginLoc =
302+
getLocation(AbsoluteFilePath, Range.FileOffset);
303+
const SourceLocation EndLoc = BeginLoc.getLocWithOffset(Range.Length);
301304
// Retrieve the source range for applicable highlights and fixes. Macro
302305
// definition on the command line have locations in a virtual buffer and
303306
// don't have valid file paths and are therefore not applicable.
@@ -353,7 +356,8 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
353356
if (Context.canExperimentalCustomChecks() && custom::RegisterCustomChecks)
354357
custom::RegisterCustomChecks(Context.getOptions(), *CheckFactories);
355358
#endif
356-
for (ClangTidyModuleRegistry::entry E : ClangTidyModuleRegistry::entries()) {
359+
for (ClangTidyModuleRegistry::entry const E :
360+
ClangTidyModuleRegistry::entries()) {
357361
std::unique_ptr<ClangTidyModule> Module = E.instantiate();
358362
Module->addCheckFactories(*CheckFactories);
359363
}
@@ -394,8 +398,9 @@ static CheckersList getAnalyzerCheckersAndPackages(ClangTidyContext &Context,
394398
// Always add all core checkers if any other static analyzer check is enabled.
395399
// This is currently necessary, as other path sensitive checks rely on the
396400
// core checkers.
397-
for (StringRef CheckName : RegisteredCheckers) {
398-
std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());
401+
for (const StringRef CheckName : RegisteredCheckers) {
402+
const std::string ClangTidyCheckName(
403+
(AnalyzerCheckNamePrefix + CheckName).str());
399404

400405
if (CheckName.starts_with("core") ||
401406
Context.isCheckEnabled(ClangTidyCheckName)) {
@@ -504,7 +509,7 @@ std::vector<std::string> ClangTidyASTConsumerFactory::getCheckNames() {
504509

505510
ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
506511
ClangTidyOptions::OptionMap Options;
507-
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
512+
const std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
508513
CheckFactories->createChecks(&Context);
509514
for (const auto &Check : Checks)
510515
Check->storeOptions(Options);
@@ -564,7 +569,7 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
564569
std::make_shared<PCHContainerOperations>(), BaseFS);
565570

566571
// Add extra arguments passed by the clang-tidy command-line.
567-
ArgumentsAdjuster PerFileExtraArgumentsInserter =
572+
const ArgumentsAdjuster PerFileExtraArgumentsInserter =
568573
[&Context](const CommandLineArguments &Args, StringRef Filename) {
569574
ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
570575
CommandLineArguments AdjustedArgs = Args;
@@ -703,7 +708,7 @@ ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers,
703708

704709
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
705710
SmallString<64> Buffer(AnalyzerCheckNamePrefix);
706-
size_t DefSize = Buffer.size();
711+
const size_t DefSize = Buffer.size();
707712
for (const auto &AnalyzerCheck : AnalyzerOptions::getRegisteredCheckers(
708713
AllowEnablingAnalyzerAlphaCheckers)) {
709714
Buffer.truncate(DefSize);

clang-tools-extra/clang-tidy/ClangTidyCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
161161
if (Iter == CheckOptions.end())
162162
return std::nullopt;
163163

164-
StringRef Value = Iter->getValue().Value;
164+
const StringRef Value = Iter->getValue().Value;
165165
StringRef Closest;
166166
unsigned EditDistance = 3;
167167
for (const auto &NameAndEnum : Mapping) {
@@ -173,7 +173,7 @@ ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
173173
EditDistance = 0;
174174
continue;
175175
}
176-
unsigned Distance =
176+
const unsigned Distance =
177177
Value.edit_distance(NameAndEnum.second, true, EditDistance);
178178
if (Distance < EditDistance) {
179179
EditDistance = Distance;

clang-tools-extra/clang-tidy/ClangTidyCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
458458
template <typename T>
459459
std::enable_if_t<std::is_enum_v<T>, std::vector<NameAndValue>>
460460
typeEraseMapping() const {
461-
ArrayRef<std::pair<T, StringRef>> Mapping =
461+
const ArrayRef<std::pair<T, StringRef>> Mapping =
462462
OptionEnumMapping<T>::getEnumMapping();
463463
std::vector<NameAndValue> Result;
464464
Result.reserve(Mapping.size());

0 commit comments

Comments
 (0)