[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

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@374314 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/COFF/DebugTypes.cpp b/COFF/DebugTypes.cpp
index c41c49c..6c7d70e 100644
--- a/COFF/DebugTypes.cpp
+++ b/COFF/DebugTypes.cpp
@@ -17,11 +17,12 @@
 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/Support/Path.h"
 
-using namespace lld;
-using namespace lld::coff;
 using namespace llvm;
 using namespace llvm::codeview;
 
+namespace lld {
+namespace coff {
+
 namespace {
 // The TypeServerSource class represents a PDB type server, a file referenced by
 // OBJ files compiled with MSVC /Zi. A single PDB can be shared by several OBJ
@@ -96,27 +97,25 @@
   GC.push_back(std::unique_ptr<TpiSource>(this));
 }
 
-TpiSource *lld::coff::makeTpiSource(const ObjFile *f) {
+TpiSource *makeTpiSource(const ObjFile *f) {
   return new TpiSource(TpiSource::Regular, f);
 }
 
-TpiSource *lld::coff::makeUseTypeServerSource(const ObjFile *f,
+TpiSource *makeUseTypeServerSource(const ObjFile *f,
                                               const TypeServer2Record *ts) {
   TypeServerSource::enqueue(f, *ts);
   return new UseTypeServerSource(f, ts);
 }
 
-TpiSource *lld::coff::makePrecompSource(const ObjFile *f) {
+TpiSource *makePrecompSource(const ObjFile *f) {
   return new PrecompSource(f);
 }
 
-TpiSource *lld::coff::makeUsePrecompSource(const ObjFile *f,
+TpiSource *makeUsePrecompSource(const ObjFile *f,
                                            const PrecompRecord *precomp) {
   return new UsePrecompSource(f, precomp);
 }
 
-namespace lld {
-namespace coff {
 template <>
 const PrecompRecord &retrieveDependencyInfo(const TpiSource *source) {
   assert(source->kind == TpiSource::UsingPCH);
@@ -128,8 +127,6 @@
   assert(source->kind == TpiSource::UsingPDB);
   return ((const UseTypeServerSource *)source)->typeServerDependency;
 }
-} // namespace coff
-} // namespace lld
 
 std::map<std::string, std::pair<std::string, TypeServerSource *>>
     TypeServerSource::instances;
@@ -210,8 +207,7 @@
 
 // FIXME: Temporary interface until PDBLinker::maybeMergeTypeServerPDB() is
 // moved here.
-Expected<llvm::pdb::NativeSession *>
-lld::coff::findTypeServerSource(const ObjFile *f) {
+Expected<llvm::pdb::NativeSession *> findTypeServerSource(const ObjFile *f) {
   Expected<TypeServerSource *> ts = TypeServerSource::findFromFile(f);
   if (!ts)
     return ts.takeError();
@@ -239,7 +235,7 @@
 // will be merged in. NOTE - a PDB load failure is not a link error: some
 // debug info will simply be missing from the final PDB - that is the default
 // accepted behavior.
-void lld::coff::loadTypeServerSource(llvm::MemoryBufferRef m) {
+void loadTypeServerSource(llvm::MemoryBufferRef m) {
   std::string path = normalizePdbPath(m.getBufferIdentifier());
 
   Expected<TypeServerSource *> ts = TypeServerSource::getInstance(m);
@@ -266,3 +262,6 @@
     return info.takeError();
   return new TypeServerSource(m, session.release());
 }
+
+} // namespace coff
+} // namespace lld
diff --git a/COFF/InputFiles.cpp b/COFF/InputFiles.cpp
index 4bfb9c9..d1ef201 100644
--- a/COFF/InputFiles.cpp
+++ b/COFF/InputFiles.cpp
@@ -47,6 +47,24 @@
 using llvm::support::ulittle32_t;
 
 namespace lld {
+
+// Returns the last element of a path, which is supposed to be a filename.
+static StringRef getBasename(StringRef path) {
+  return sys::path::filename(path, sys::path::Style::windows);
+}
+
+// Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
+std::string toString(const coff::InputFile *file) {
+  if (!file)
+    return "<internal>";
+  if (file->parentName.empty() || file->kind() == coff::InputFile::ImportKind)
+    return file->getName();
+
+  return (getBasename(file->parentName) + "(" + getBasename(file->getName()) +
+          ")")
+      .str();
+}
+
 namespace coff {
 
 std::vector<ObjFile *> ObjFile::instances;
@@ -908,22 +926,6 @@
     return (path + repl).str();
   return path;
 }
+
 } // namespace coff
 } // namespace lld
-
-// Returns the last element of a path, which is supposed to be a filename.
-static StringRef getBasename(StringRef path) {
-  return sys::path::filename(path, sys::path::Style::windows);
-}
-
-// Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
-std::string lld::toString(const coff::InputFile *file) {
-  if (!file)
-    return "<internal>";
-  if (file->parentName.empty() || file->kind() == coff::InputFile::ImportKind)
-    return file->getName();
-
-  return (getBasename(file->parentName) + "(" + getBasename(file->getName()) +
-          ")")
-      .str();
-}
diff --git a/COFF/LTO.cpp b/COFF/LTO.cpp
index 7aa3b17..1c21236 100644
--- a/COFF/LTO.cpp
+++ b/COFF/LTO.cpp
@@ -39,8 +39,8 @@
 using namespace llvm;
 using namespace llvm::object;
 
-using namespace lld;
-using namespace lld::coff;
+namespace lld {
+namespace coff {
 
 // Creates an empty file to and returns a raw_fd_ostream to write to it.
 static std::unique_ptr<raw_fd_ostream> openFile(StringRef file) {
@@ -206,3 +206,6 @@
 
   return ret;
 }
+
+} // namespace coff
+} // namespace lld
diff --git a/COFF/MapFile.cpp b/COFF/MapFile.cpp
index 70017d3..0fea60a 100644
--- a/COFF/MapFile.cpp
+++ b/COFF/MapFile.cpp
@@ -29,8 +29,8 @@
 using namespace llvm;
 using namespace llvm::object;
 
-using namespace lld;
-using namespace lld::coff;
+namespace lld {
+namespace coff {
 
 using SymbolMapTy =
     DenseMap<const SectionChunk *, SmallVector<DefinedRegular *, 4>>;
@@ -87,7 +87,7 @@
   return ret;
 }
 
-void coff::writeMapFile(ArrayRef<OutputSection *> outputSections) {
+void writeMapFile(ArrayRef<OutputSection *> outputSections) {
   if (config->mapFile.empty())
     return;
 
@@ -122,3 +122,6 @@
     }
   }
 }
+
+} // namespace coff
+} // namespace lld
diff --git a/COFF/MinGW.cpp b/COFF/MinGW.cpp
index 008e654..270cdaa 100644
--- a/COFF/MinGW.cpp
+++ b/COFF/MinGW.cpp
@@ -13,11 +13,12 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 
-using namespace lld;
-using namespace lld::coff;
 using namespace llvm;
 using namespace llvm::COFF;
 
+namespace lld {
+namespace coff {
+
 AutoExporter::AutoExporter() {
   excludeLibs = {
       "libgcc",
@@ -146,7 +147,7 @@
   return !excludeObjects.count(fileName);
 }
 
-void coff::writeDefFile(StringRef name) {
+void writeDefFile(StringRef name) {
   std::error_code ec;
   raw_fd_ostream os(name, ec, sys::fs::OF_None);
   if (ec)
@@ -164,3 +165,6 @@
     os << "\n";
   }
 }
+
+} // namespace coff
+} // namespace lld
diff --git a/COFF/PDB.cpp b/COFF/PDB.cpp
index d0f8f3d..765f820 100644
--- a/COFF/PDB.cpp
+++ b/COFF/PDB.cpp
@@ -59,13 +59,14 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include <memory>
 
-using namespace lld;
-using namespace lld::coff;
 using namespace llvm;
 using namespace llvm::codeview;
 
 using llvm::object::coff_section;
 
+namespace lld {
+namespace coff {
+
 static ExitOnError exitOnErr;
 
 static Timer totalPdbLinkTimer("PDB Emission (Cumulative)", Timer::root());
@@ -1597,7 +1598,7 @@
 }
 
 // Creates a PDB file.
-void coff::createPDB(SymbolTable *symtab,
+void createPDB(SymbolTable *symtab,
                      ArrayRef<OutputSection *> outputSections,
                      ArrayRef<uint8_t> sectionTable,
                      llvm::codeview::DebugInfo *buildId) {
@@ -1798,7 +1799,7 @@
 // Use CodeView line tables to resolve a file and line number for the given
 // offset into the given chunk and return them, or {"", 0} if a line table was
 // not found.
-std::pair<StringRef, uint32_t> coff::getFileLineCodeView(const SectionChunk *c,
+std::pair<StringRef, uint32_t> getFileLineCodeView(const SectionChunk *c,
                                                          uint32_t addr) {
   ExitOnError exitOnErr;
 
@@ -1833,3 +1834,6 @@
   StringRef filename = exitOnErr(getFileName(cVStrTab, checksums, *nameIndex));
   return {filename, *lineNumber};
 }
+
+} // namespace coff
+} // namespace lld
diff --git a/COFF/Writer.cpp b/COFF/Writer.cpp
index 8387361..9729c69 100644
--- a/COFF/Writer.cpp
+++ b/COFF/Writer.cpp
@@ -40,8 +40,9 @@
 using namespace llvm::object;
 using namespace llvm::support;
 using namespace llvm::support::endian;
-using namespace lld;
-using namespace lld::coff;
+
+namespace lld {
+namespace coff {
 
 /* To re-generate DOSProgram:
 $ cat > /tmp/DOSProgram.asm
@@ -285,9 +286,6 @@
 };
 } // anonymous namespace
 
-namespace lld {
-namespace coff {
-
 static Timer codeLayoutTimer("Code Layout", Timer::root());
 static Timer diskCommitTimer("Commit Output File", Timer::root());
 
@@ -333,9 +331,6 @@
   contribSections.push_back(sec);
 }
 
-} // namespace coff
-} // namespace lld
-
 // Check whether the target address S is in range from a relocation
 // of type relType at address P.
 static bool isInRange(uint16_t relType, uint64_t s, uint64_t p, int margin) {
@@ -1945,3 +1940,6 @@
     return it->second;
   return nullptr;
 }
+
+} // namespace coff
+} // namespace lld