Skip to content

Commit 7d913c5

Browse files
davidstonecor3ntin
andauthored
[clang][Modules] Make Module::Requirement a struct (NFC) (#67900)
`Module::Requirement` was defined as a `std::pair<std::string, bool>`. This required a comment to explain what the data members mean and makes the usage harder to understand. Replace this with a struct with two members, `FeatureName` and `RequiredState`. --------- Co-authored-by: cor3ntin <[email protected]>
1 parent 9154a32 commit 7d913c5

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

clang/include/clang/Basic/Module.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ class alignas(8) Module {
284284
/// found on the file system.
285285
SmallVector<UnresolvedHeaderDirective, 1> MissingHeaders;
286286

287-
/// An individual requirement: a feature name and a flag indicating
288-
/// the required state of that feature.
289-
using Requirement = std::pair<std::string, bool>;
287+
struct Requirement {
288+
std::string FeatureName;
289+
bool RequiredState;
290+
};
290291

291292
/// The set of language features required to use this module.
292293
///

clang/lib/Basic/Module.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ bool Module::isUnimportable(const LangOptions &LangOpts,
140140
return true;
141141
}
142142
for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) {
143-
if (hasFeature(Current->Requirements[I].first, LangOpts, Target) !=
144-
Current->Requirements[I].second) {
143+
if (hasFeature(Current->Requirements[I].FeatureName, LangOpts, Target) !=
144+
Current->Requirements[I].RequiredState) {
145145
Req = Current->Requirements[I];
146146
return true;
147147
}
@@ -319,7 +319,7 @@ bool Module::directlyUses(const Module *Requested) {
319319
void Module::addRequirement(StringRef Feature, bool RequiredState,
320320
const LangOptions &LangOpts,
321321
const TargetInfo &Target) {
322-
Requirements.push_back(Requirement(std::string(Feature), RequiredState));
322+
Requirements.push_back(Requirement{std::string(Feature), RequiredState});
323323

324324
// If this feature is currently available, we're done.
325325
if (hasFeature(Feature, LangOpts, Target) == RequiredState)
@@ -504,9 +504,9 @@ void Module::print(raw_ostream &OS, unsigned Indent, bool Dump) const {
504504
for (unsigned I = 0, N = Requirements.size(); I != N; ++I) {
505505
if (I)
506506
OS << ", ";
507-
if (!Requirements[I].second)
507+
if (!Requirements[I].RequiredState)
508508
OS << "!";
509-
OS << Requirements[I].first;
509+
OS << Requirements[I].FeatureName;
510510
}
511511
OS << "\n";
512512
}

clang/lib/Lex/PPDirectives.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,8 @@ bool Preprocessor::checkModuleIsAvailable(const LangOptions &LangOpts,
19181918
// FIXME: Track the location at which the requirement was specified, and
19191919
// use it here.
19201920
Diags.Report(M.DefinitionLoc, diag::err_module_unavailable)
1921-
<< M.getFullModuleName() << Requirement.second << Requirement.first;
1921+
<< M.getFullModuleName() << Requirement.RequiredState
1922+
<< Requirement.FeatureName;
19221923
}
19231924
return true;
19241925
}

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,8 +2988,8 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
29882988

29892989
// Emit the requirements.
29902990
for (const auto &R : Mod->Requirements) {
2991-
RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second};
2992-
Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first);
2991+
RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.RequiredState};
2992+
Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.FeatureName);
29932993
}
29942994

29952995
// Emit the umbrella header, if there is one.

0 commit comments

Comments
 (0)