[lld] r281803 - Use named struct instead of unnamed std::pair.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 16 19:23:41 PDT 2016
Author: ruiu
Date: Fri Sep 16 21:23:40 2016
New Revision: 281803
URL: http://llvm.org/viewvc/llvm-project?rev=281803&view=rev
Log:
Use named struct instead of unnamed std::pair.
It is important to give members names for readability.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=281803&r1=281802&r2=281803&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Sep 16 21:23:40 2016
@@ -165,19 +165,23 @@ static bool matchConstraints(ArrayRef<In
// Compute and remember which sections the InputSectionDescription matches.
template <class ELFT>
void LinkerScript<ELFT>::computeInputSections(InputSectionDescription *I) {
- for (const std::pair<Regex, Regex> &V : I->SectionsVec) {
+ // Collects all sections that satisfy constraints of I
+ // and attach them to I.
+ for (SectionPattern &Pat : I->SectionPatterns) {
for (ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) {
StringRef Filename = sys::path::filename(F->getName());
- if (!match(I->FileRe, Filename) || match(V.first, Filename))
+ if (!match(I->FileRe, Filename) || match(Pat.ExcludedFileRe, Filename))
continue;
+
for (InputSectionBase<ELFT> *S : F->getSections())
- if (!isDiscarded(S) && !S->OutSec && match(V.second, S->Name))
+ if (!isDiscarded(S) && !S->OutSec && match(Pat.SectionRe, S->Name))
I->Sections.push_back(S);
- if (match(V.second, "COMMON"))
+ if (match(Pat.SectionRe, "COMMON"))
I->Sections.push_back(CommonInputSection<ELFT>::X);
}
}
+ // Sort for SORT() commands.
if (I->SortInner != SortSectionPolicy::Default)
std::stable_sort(I->Sections.begin(), I->Sections.end(),
getComparator(I->SortInner));
@@ -1066,14 +1070,14 @@ void ScriptParser::readSectionExcludes(I
while (!Error) {
if (skip(")")) {
- Cmd->SectionsVec.push_back(
+ Cmd->SectionPatterns.push_back(
{std::move(ExcludeFileRe), compileGlobPatterns(V)});
return;
}
if (skip("EXCLUDE_FILE")) {
if (!V.empty()) {
- Cmd->SectionsVec.push_back(
+ Cmd->SectionPatterns.push_back(
{std::move(ExcludeFileRe), compileGlobPatterns(V)});
V.clear();
}
@@ -1101,10 +1105,10 @@ ScriptParser::readInputSectionRules(Stri
if (K2 != SortSectionPolicy::Default) {
Cmd->SortInner = K2;
expect("(");
- Cmd->SectionsVec.push_back({Regex(), readFilePatterns()});
+ Cmd->SectionPatterns.push_back({Regex(), readFilePatterns()});
expect(")");
} else {
- Cmd->SectionsVec.push_back({Regex(), readFilePatterns()});
+ Cmd->SectionPatterns.push_back({Regex(), readFilePatterns()});
}
expect(")");
selectSortKind(Cmd);
@@ -1125,8 +1129,8 @@ ScriptParser::readInputSectionDescriptio
StringRef FilePattern = next();
InputSectionDescription *Cmd = readInputSectionRules(FilePattern);
expect(")");
- for (std::pair<Regex, Regex> &Regex : Cmd->SectionsVec)
- Opt.KeptSections.push_back(&Regex.second);
+ for (SectionPattern &Pat : Cmd->SectionPatterns)
+ Opt.KeptSections.push_back(&Pat.SectionRe);
return Cmd;
}
return readInputSectionRules(Tok);
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=281803&r1=281802&r2=281803&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Fri Sep 16 21:23:40 2016
@@ -98,6 +98,13 @@ struct OutputSectionCommand : BaseComman
ConstraintKind Constraint = ConstraintKind::NoConstraint;
};
+// This struct reprents one section match pattern in SECTIONS() command.
+// It can optionally have negative match pattern for EXCLUDED_FILE command.
+struct SectionPattern {
+ llvm::Regex ExcludedFileRe;
+ llvm::Regex SectionRe;
+};
+
struct InputSectionDescription : BaseCommand {
InputSectionDescription(StringRef FilePattern)
: BaseCommand(InputSectionKind),
@@ -106,8 +113,10 @@ struct InputSectionDescription : BaseCom
llvm::Regex FileRe;
SortSectionPolicy SortOuter = SortSectionPolicy::Default;
SortSectionPolicy SortInner = SortSectionPolicy::Default;
+
// Pairs of section regex and files excluded.
- std::list<std::pair<llvm::Regex, llvm::Regex>> SectionsVec;
+ std::vector<SectionPattern> SectionPatterns;
+
std::vector<InputSectionData *> Sections;
};
More information about the llvm-commits
mailing list