Skip to content

Commit d79c3be

Browse files
committed
[COFF] Wrap definitions in namespace lld { namespace coff {. NFC
Similar to D67323, but for COFF. Many lld/COFF/ files already use `namespace lld { namespace coff {`. Only a few need changing. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D68772 llvm-svn: 374314
1 parent 95e264f commit d79c3be

File tree

7 files changed

+63
-50
lines changed

7 files changed

+63
-50
lines changed

lld/COFF/DebugTypes.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
1818
#include "llvm/Support/Path.h"
1919

20-
using namespace lld;
21-
using namespace lld::coff;
2220
using namespace llvm;
2321
using namespace llvm::codeview;
2422

23+
namespace lld {
24+
namespace coff {
25+
2526
namespace {
2627
// The TypeServerSource class represents a PDB type server, a file referenced by
2728
// OBJ files compiled with MSVC /Zi. A single PDB can be shared by several OBJ
@@ -96,27 +97,25 @@ TpiSource::TpiSource(TpiKind k, const ObjFile *f) : kind(k), file(f) {
9697
GC.push_back(std::unique_ptr<TpiSource>(this));
9798
}
9899

99-
TpiSource *lld::coff::makeTpiSource(const ObjFile *f) {
100+
TpiSource *makeTpiSource(const ObjFile *f) {
100101
return new TpiSource(TpiSource::Regular, f);
101102
}
102103

103-
TpiSource *lld::coff::makeUseTypeServerSource(const ObjFile *f,
104+
TpiSource *makeUseTypeServerSource(const ObjFile *f,
104105
const TypeServer2Record *ts) {
105106
TypeServerSource::enqueue(f, *ts);
106107
return new UseTypeServerSource(f, ts);
107108
}
108109

109-
TpiSource *lld::coff::makePrecompSource(const ObjFile *f) {
110+
TpiSource *makePrecompSource(const ObjFile *f) {
110111
return new PrecompSource(f);
111112
}
112113

113-
TpiSource *lld::coff::makeUsePrecompSource(const ObjFile *f,
114+
TpiSource *makeUsePrecompSource(const ObjFile *f,
114115
const PrecompRecord *precomp) {
115116
return new UsePrecompSource(f, precomp);
116117
}
117118

118-
namespace lld {
119-
namespace coff {
120119
template <>
121120
const PrecompRecord &retrieveDependencyInfo(const TpiSource *source) {
122121
assert(source->kind == TpiSource::UsingPCH);
@@ -128,8 +127,6 @@ const TypeServer2Record &retrieveDependencyInfo(const TpiSource *source) {
128127
assert(source->kind == TpiSource::UsingPDB);
129128
return ((const UseTypeServerSource *)source)->typeServerDependency;
130129
}
131-
} // namespace coff
132-
} // namespace lld
133130

134131
std::map<std::string, std::pair<std::string, TypeServerSource *>>
135132
TypeServerSource::instances;
@@ -210,8 +207,7 @@ TypeServerSource::findFromFile(const ObjFile *dependentFile) {
210207

211208
// FIXME: Temporary interface until PDBLinker::maybeMergeTypeServerPDB() is
212209
// moved here.
213-
Expected<llvm::pdb::NativeSession *>
214-
lld::coff::findTypeServerSource(const ObjFile *f) {
210+
Expected<llvm::pdb::NativeSession *> findTypeServerSource(const ObjFile *f) {
215211
Expected<TypeServerSource *> ts = TypeServerSource::findFromFile(f);
216212
if (!ts)
217213
return ts.takeError();
@@ -239,7 +235,7 @@ void TypeServerSource::enqueue(const ObjFile *dependentFile,
239235
// will be merged in. NOTE - a PDB load failure is not a link error: some
240236
// debug info will simply be missing from the final PDB - that is the default
241237
// accepted behavior.
242-
void lld::coff::loadTypeServerSource(llvm::MemoryBufferRef m) {
238+
void loadTypeServerSource(llvm::MemoryBufferRef m) {
243239
std::string path = normalizePdbPath(m.getBufferIdentifier());
244240

245241
Expected<TypeServerSource *> ts = TypeServerSource::getInstance(m);
@@ -266,3 +262,6 @@ Expected<TypeServerSource *> TypeServerSource::getInstance(MemoryBufferRef m) {
266262
return info.takeError();
267263
return new TypeServerSource(m, session.release());
268264
}
265+
266+
} // namespace coff
267+
} // namespace lld

lld/COFF/InputFiles.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ using llvm::Triple;
4747
using llvm::support::ulittle32_t;
4848

4949
namespace lld {
50+
51+
// Returns the last element of a path, which is supposed to be a filename.
52+
static StringRef getBasename(StringRef path) {
53+
return sys::path::filename(path, sys::path::Style::windows);
54+
}
55+
56+
// Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
57+
std::string toString(const coff::InputFile *file) {
58+
if (!file)
59+
return "<internal>";
60+
if (file->parentName.empty() || file->kind() == coff::InputFile::ImportKind)
61+
return file->getName();
62+
63+
return (getBasename(file->parentName) + "(" + getBasename(file->getName()) +
64+
")")
65+
.str();
66+
}
67+
5068
namespace coff {
5169

5270
std::vector<ObjFile *> ObjFile::instances;
@@ -908,22 +926,6 @@ std::string replaceThinLTOSuffix(StringRef path) {
908926
return (path + repl).str();
909927
return path;
910928
}
929+
911930
} // namespace coff
912931
} // namespace lld
913-
914-
// Returns the last element of a path, which is supposed to be a filename.
915-
static StringRef getBasename(StringRef path) {
916-
return sys::path::filename(path, sys::path::Style::windows);
917-
}
918-
919-
// Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
920-
std::string lld::toString(const coff::InputFile *file) {
921-
if (!file)
922-
return "<internal>";
923-
if (file->parentName.empty() || file->kind() == coff::InputFile::ImportKind)
924-
return file->getName();
925-
926-
return (getBasename(file->parentName) + "(" + getBasename(file->getName()) +
927-
")")
928-
.str();
929-
}

lld/COFF/LTO.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
using namespace llvm;
4040
using namespace llvm::object;
4141

42-
using namespace lld;
43-
using namespace lld::coff;
42+
namespace lld {
43+
namespace coff {
4444

4545
// Creates an empty file to and returns a raw_fd_ostream to write to it.
4646
static std::unique_ptr<raw_fd_ostream> openFile(StringRef file) {
@@ -206,3 +206,6 @@ std::vector<StringRef> BitcodeCompiler::compile() {
206206

207207
return ret;
208208
}
209+
210+
} // namespace coff
211+
} // namespace lld

lld/COFF/MapFile.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
using namespace llvm;
3030
using namespace llvm::object;
3131

32-
using namespace lld;
33-
using namespace lld::coff;
32+
namespace lld {
33+
namespace coff {
3434

3535
using SymbolMapTy =
3636
DenseMap<const SectionChunk *, SmallVector<DefinedRegular *, 4>>;
@@ -87,7 +87,7 @@ getSymbolStrings(ArrayRef<DefinedRegular *> syms) {
8787
return ret;
8888
}
8989

90-
void coff::writeMapFile(ArrayRef<OutputSection *> outputSections) {
90+
void writeMapFile(ArrayRef<OutputSection *> outputSections) {
9191
if (config->mapFile.empty())
9292
return;
9393

@@ -122,3 +122,6 @@ void coff::writeMapFile(ArrayRef<OutputSection *> outputSections) {
122122
}
123123
}
124124
}
125+
126+
} // namespace coff
127+
} // namespace lld

lld/COFF/MinGW.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#include "llvm/Support/Path.h"
1414
#include "llvm/Support/raw_ostream.h"
1515

16-
using namespace lld;
17-
using namespace lld::coff;
1816
using namespace llvm;
1917
using namespace llvm::COFF;
2018

19+
namespace lld {
20+
namespace coff {
21+
2122
AutoExporter::AutoExporter() {
2223
excludeLibs = {
2324
"libgcc",
@@ -146,7 +147,7 @@ bool AutoExporter::shouldExport(Defined *sym) const {
146147
return !excludeObjects.count(fileName);
147148
}
148149

149-
void coff::writeDefFile(StringRef name) {
150+
void writeDefFile(StringRef name) {
150151
std::error_code ec;
151152
raw_fd_ostream os(name, ec, sys::fs::OF_None);
152153
if (ec)
@@ -164,3 +165,6 @@ void coff::writeDefFile(StringRef name) {
164165
os << "\n";
165166
}
166167
}
168+
169+
} // namespace coff
170+
} // namespace lld

lld/COFF/PDB.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@
5959
#include "llvm/Support/ScopedPrinter.h"
6060
#include <memory>
6161

62-
using namespace lld;
63-
using namespace lld::coff;
6462
using namespace llvm;
6563
using namespace llvm::codeview;
6664

6765
using llvm::object::coff_section;
6866

67+
namespace lld {
68+
namespace coff {
69+
6970
static ExitOnError exitOnErr;
7071

7172
static Timer totalPdbLinkTimer("PDB Emission (Cumulative)", Timer::root());
@@ -1597,7 +1598,7 @@ void PDBLinker::addImportFilesToPDB(ArrayRef<OutputSection *> outputSections) {
15971598
}
15981599

15991600
// Creates a PDB file.
1600-
void coff::createPDB(SymbolTable *symtab,
1601+
void createPDB(SymbolTable *symtab,
16011602
ArrayRef<OutputSection *> outputSections,
16021603
ArrayRef<uint8_t> sectionTable,
16031604
llvm::codeview::DebugInfo *buildId) {
@@ -1798,7 +1799,7 @@ static bool findLineTable(const SectionChunk *c, uint32_t addr,
17981799
// Use CodeView line tables to resolve a file and line number for the given
17991800
// offset into the given chunk and return them, or {"", 0} if a line table was
18001801
// not found.
1801-
std::pair<StringRef, uint32_t> coff::getFileLineCodeView(const SectionChunk *c,
1802+
std::pair<StringRef, uint32_t> getFileLineCodeView(const SectionChunk *c,
18021803
uint32_t addr) {
18031804
ExitOnError exitOnErr;
18041805

@@ -1833,3 +1834,6 @@ std::pair<StringRef, uint32_t> coff::getFileLineCodeView(const SectionChunk *c,
18331834
StringRef filename = exitOnErr(getFileName(cVStrTab, checksums, *nameIndex));
18341835
return {filename, *lineNumber};
18351836
}
1837+
1838+
} // namespace coff
1839+
} // namespace lld

lld/COFF/Writer.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ using namespace llvm::COFF;
4040
using namespace llvm::object;
4141
using namespace llvm::support;
4242
using namespace llvm::support::endian;
43-
using namespace lld;
44-
using namespace lld::coff;
43+
44+
namespace lld {
45+
namespace coff {
4546

4647
/* To re-generate DOSProgram:
4748
$ cat > /tmp/DOSProgram.asm
@@ -285,9 +286,6 @@ class Writer {
285286
};
286287
} // anonymous namespace
287288

288-
namespace lld {
289-
namespace coff {
290-
291289
static Timer codeLayoutTimer("Code Layout", Timer::root());
292290
static Timer diskCommitTimer("Commit Output File", Timer::root());
293291

@@ -333,9 +331,6 @@ void OutputSection::addContributingPartialSection(PartialSection *sec) {
333331
contribSections.push_back(sec);
334332
}
335333

336-
} // namespace coff
337-
} // namespace lld
338-
339334
// Check whether the target address S is in range from a relocation
340335
// of type relType at address P.
341336
static bool isInRange(uint16_t relType, uint64_t s, uint64_t p, int margin) {
@@ -1945,3 +1940,6 @@ PartialSection *Writer::findPartialSection(StringRef name, uint32_t outChars) {
19451940
return it->second;
19461941
return nullptr;
19471942
}
1943+
1944+
} // namespace coff
1945+
} // namespace lld

0 commit comments

Comments
 (0)