From 8a310f40d0a325daf0c81af204c93adc3e885d10 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 19 Feb 2020 17:05:42 -0800 Subject: [PATCH] Remove namespace lld { namespace coff { from COFF LLD cpp files Instead, use `using namespace lld(::coff)`, and fully qualify the names of free functions where they are defined in cpp files. This effectively reverts d79c3be618 to follow the new style guide added in 236fcbc21a7a8872. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D74882 --- lld/COFF/DebugTypes.cpp | 25 +++++++++++++------------ lld/COFF/InputFiles.cpp | 15 +++++---------- lld/COFF/LTO.cpp | 8 ++------ lld/COFF/MapFile.cpp | 10 +++------- lld/COFF/MinGW.cpp | 10 +++------- lld/COFF/PDB.cpp | 18 +++++++----------- lld/COFF/Writer.cpp | 10 +++------- 7 files changed, 36 insertions(+), 60 deletions(-) diff --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp index cd59b4310dbb..a0d190b4a762 100644 --- a/lld/COFF/DebugTypes.cpp +++ b/lld/COFF/DebugTypes.cpp @@ -20,9 +20,8 @@ using namespace llvm; using namespace llvm::codeview; - -namespace lld { -namespace coff { +using namespace lld; +using namespace lld::coff; namespace { // The TypeServerSource class represents a PDB type server, a file referenced by @@ -94,25 +93,27 @@ public: TpiSource::TpiSource(TpiKind k, const ObjFile *f) : kind(k), file(f) {} -TpiSource *makeTpiSource(const ObjFile *f) { +TpiSource *lld::coff::makeTpiSource(const ObjFile *f) { return make(TpiSource::Regular, f); } -TpiSource *makeUseTypeServerSource(const ObjFile *f, +TpiSource *lld::coff::makeUseTypeServerSource(const ObjFile *f, const TypeServer2Record *ts) { TypeServerSource::enqueue(f, *ts); return make(f, ts); } -TpiSource *makePrecompSource(const ObjFile *f) { +TpiSource *lld::coff::makePrecompSource(const ObjFile *f) { return make(f); } -TpiSource *makeUsePrecompSource(const ObjFile *f, +TpiSource *lld::coff::makeUsePrecompSource(const ObjFile *f, const PrecompRecord *precomp) { return make(f, precomp); } +namespace lld { +namespace coff { template <> const PrecompRecord &retrieveDependencyInfo(const TpiSource *source) { assert(source->kind == TpiSource::UsingPCH); @@ -124,6 +125,8 @@ const TypeServer2Record &retrieveDependencyInfo(const TpiSource *source) { assert(source->kind == TpiSource::UsingPDB); return ((const UseTypeServerSource *)source)->typeServerDependency; } +} // namespace coff +} // namespace lld std::map> TypeServerSource::instances; @@ -204,7 +207,8 @@ TypeServerSource::findFromFile(const ObjFile *dependentFile) { // FIXME: Temporary interface until PDBLinker::maybeMergeTypeServerPDB() is // moved here. -Expected findTypeServerSource(const ObjFile *f) { +Expected +lld::coff::findTypeServerSource(const ObjFile *f) { Expected ts = TypeServerSource::findFromFile(f); if (!ts) return ts.takeError(); @@ -232,7 +236,7 @@ void TypeServerSource::enqueue(const ObjFile *dependentFile, // 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 loadTypeServerSource(llvm::MemoryBufferRef m) { +void lld::coff::loadTypeServerSource(llvm::MemoryBufferRef m) { std::string path = normalizePdbPath(m.getBufferIdentifier()); Expected ts = TypeServerSource::getInstance(m); @@ -259,6 +263,3 @@ Expected TypeServerSource::getInstance(MemoryBufferRef m) { return info.takeError(); return make(m, session.release()); } - -} // namespace coff -} // namespace lld diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index 58b0c97c700b..f322e6a9db2d 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -44,19 +44,19 @@ using namespace llvm::COFF; using namespace llvm::codeview; using namespace llvm::object; using namespace llvm::support::endian; +using namespace lld; +using namespace lld::coff; using llvm::Triple; 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) { +std::string lld::toString(const coff::InputFile *file) { if (!file) return ""; if (file->parentName.empty() || file->kind() == coff::InputFile::ImportKind) @@ -67,8 +67,6 @@ std::string toString(const coff::InputFile *file) { .str(); } -namespace coff { - std::vector ObjFile::instances; std::vector ImportFile::instances; std::vector BitcodeFile::instances; @@ -121,7 +119,7 @@ void ArchiveFile::addMember(const Archive::Symbol &sym) { driver->enqueueArchiveMember(c, sym, getName()); } -std::vector getArchiveMembers(Archive *file) { +std::vector lld::coff::getArchiveMembers(Archive *file) { std::vector v; Error err = Error::success(); for (const Archive::Child &c : file->children(err)) { @@ -967,7 +965,7 @@ MachineTypes BitcodeFile::getMachineType() { } } -std::string replaceThinLTOSuffix(StringRef path) { +std::string lld::coff::replaceThinLTOSuffix(StringRef path) { StringRef suffix = config->thinLTOObjectSuffixReplace.first; StringRef repl = config->thinLTOObjectSuffixReplace.second; @@ -975,6 +973,3 @@ std::string replaceThinLTOSuffix(StringRef path) { return (path + repl).str(); return std::string(path); } - -} // namespace coff -} // namespace lld diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp index 609871deeb69..247331b16928 100644 --- a/lld/COFF/LTO.cpp +++ b/lld/COFF/LTO.cpp @@ -38,9 +38,8 @@ using namespace llvm; using namespace llvm::object; - -namespace lld { -namespace coff { +using namespace lld; +using namespace lld::coff; // Creates an empty file to and returns a raw_fd_ostream to write to it. static std::unique_ptr openFile(StringRef file) { @@ -207,6 +206,3 @@ std::vector BitcodeCompiler::compile() { return ret; } - -} // namespace coff -} // namespace lld diff --git a/lld/COFF/MapFile.cpp b/lld/COFF/MapFile.cpp index 0fea60aab99b..a80c553637aa 100644 --- a/lld/COFF/MapFile.cpp +++ b/lld/COFF/MapFile.cpp @@ -28,9 +28,8 @@ using namespace llvm; using namespace llvm::object; - -namespace lld { -namespace coff { +using namespace lld; +using namespace lld::coff; using SymbolMapTy = DenseMap>; @@ -87,7 +86,7 @@ getSymbolStrings(ArrayRef syms) { return ret; } -void writeMapFile(ArrayRef outputSections) { +void lld::coff::writeMapFile(ArrayRef outputSections) { if (config->mapFile.empty()) return; @@ -122,6 +121,3 @@ void writeMapFile(ArrayRef outputSections) { } } } - -} // namespace coff -} // namespace lld diff --git a/lld/COFF/MinGW.cpp b/lld/COFF/MinGW.cpp index 270cdaab4d9c..bded985f04d0 100644 --- a/lld/COFF/MinGW.cpp +++ b/lld/COFF/MinGW.cpp @@ -15,9 +15,8 @@ using namespace llvm; using namespace llvm::COFF; - -namespace lld { -namespace coff { +using namespace lld; +using namespace lld::coff; AutoExporter::AutoExporter() { excludeLibs = { @@ -147,7 +146,7 @@ bool AutoExporter::shouldExport(Defined *sym) const { return !excludeObjects.count(fileName); } -void writeDefFile(StringRef name) { +void lld::coff::writeDefFile(StringRef name) { std::error_code ec; raw_fd_ostream os(name, ec, sys::fs::OF_None); if (ec) @@ -165,6 +164,3 @@ void writeDefFile(StringRef name) { os << "\n"; } } - -} // namespace coff -} // namespace lld diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp index 52740ae393a9..3754bd0d1cf6 100644 --- a/lld/COFF/PDB.cpp +++ b/lld/COFF/PDB.cpp @@ -63,12 +63,11 @@ using namespace llvm; using namespace llvm::codeview; +using namespace lld; +using namespace lld::coff; using llvm::object::coff_section; -namespace lld { -namespace coff { - static ExitOnError exitOnErr; static Timer totalPdbLinkTimer("PDB Emission (Cumulative)", Timer::root()); @@ -1679,10 +1678,10 @@ void PDBLinker::addImportFilesToPDB(ArrayRef outputSections) { } // Creates a PDB file. -void createPDB(SymbolTable *symtab, - ArrayRef outputSections, - ArrayRef sectionTable, - llvm::codeview::DebugInfo *buildId) { +void lld::coff::createPDB(SymbolTable *symtab, + ArrayRef outputSections, + ArrayRef sectionTable, + llvm::codeview::DebugInfo *buildId) { ScopedTimer t1(totalPdbLinkTimer); PDBLinker pdb(symtab); @@ -1880,7 +1879,7 @@ static bool findLineTable(const SectionChunk *c, uint32_t addr, // offset into the given chunk and return them, or None if a line table was // not found. Optional> -getFileLineCodeView(const SectionChunk *c, uint32_t addr) { +lld::coff::getFileLineCodeView(const SectionChunk *c, uint32_t addr) { ExitOnError exitOnErr; DebugStringTableSubsectionRef cVStrTab; @@ -1914,6 +1913,3 @@ getFileLineCodeView(const SectionChunk *c, uint32_t addr) { StringRef filename = exitOnErr(getFileName(cVStrTab, checksums, *nameIndex)); return std::make_pair(filename, *lineNumber); } - -} // namespace coff -} // namespace lld diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index fcad7739d300..fbef82af9d36 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -41,9 +41,8 @@ using namespace llvm::COFF; using namespace llvm::object; using namespace llvm::support; using namespace llvm::support::endian; - -namespace lld { -namespace coff { +using namespace lld; +using namespace lld::coff; /* To re-generate DOSProgram: $ cat > /tmp/DOSProgram.asm @@ -290,7 +289,7 @@ private: static Timer codeLayoutTimer("Code Layout", Timer::root()); static Timer diskCommitTimer("Commit Output File", Timer::root()); -void writeResult() { Writer().run(); } +void lld::coff::writeResult() { Writer().run(); } void OutputSection::addChunk(Chunk *c) { chunks.push_back(c); @@ -1950,6 +1949,3 @@ PartialSection *Writer::findPartialSection(StringRef name, uint32_t outChars) { return it->second; return nullptr; } - -} // namespace coff -} // namespace lld