Skip to content

Commit

Permalink
[NFC][llvm-objcopy] Cleanup namespace usage in llvm-objcopy.
Browse files Browse the repository at this point in the history
Nest any classes not used outside of a file into anon. Nest any classes used
across files in llvm-objcopy into namespace llvm::objcopy.


Differential Revision: https://reviews.llvm.org/D49449





git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337337 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
plotfi committed Jul 18, 2018
1 parent 9722c06 commit b5b60c3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
3 changes: 3 additions & 0 deletions tools/llvm-objcopy/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <vector>

using namespace llvm;
using namespace llvm::objcopy;
using namespace object;
using namespace ELF;

Expand Down Expand Up @@ -1387,6 +1388,7 @@ void BinaryWriter::finalize() {
}

namespace llvm {
namespace objcopy {

template class ELFBuilder<ELF64LE>;
template class ELFBuilder<ELF64BE>;
Expand All @@ -1397,4 +1399,5 @@ template class ELFWriter<ELF64LE>;
template class ELFWriter<ELF64BE>;
template class ELFWriter<ELF32LE>;
template class ELFWriter<ELF32BE>;
} // end namespace objcopy
} // end namespace llvm
2 changes: 2 additions & 0 deletions tools/llvm-objcopy/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <vector>

namespace llvm {
namespace objcopy {

class Buffer;
class SectionBase;
Expand Down Expand Up @@ -714,6 +715,7 @@ class Object {
return *Segments.back();
}
};
} // end namespace objcopy
} // end namespace llvm

#endif // LLVM_TOOLS_OBJCOPY_OBJECT_H
61 changes: 32 additions & 29 deletions tools/llvm-objcopy/llvm-objcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <utility>

using namespace llvm;
using namespace llvm::objcopy;
using namespace object;
using namespace ELF;

Expand Down Expand Up @@ -114,35 +115,6 @@ class StripOptTable : public opt::OptTable {
StripOptTable() : OptTable(StripInfoTable, true) {}
};

} // namespace

// The name this program was invoked as.
static StringRef ToolName;

namespace llvm {

LLVM_ATTRIBUTE_NORETURN void error(Twine Message) {
errs() << ToolName << ": " << Message << ".\n";
errs().flush();
exit(1);
}

LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, std::error_code EC) {
assert(EC);
errs() << ToolName << ": '" << File << "': " << EC.message() << ".\n";
exit(1);
}

LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Error E) {
assert(E);
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
OS.flush();
errs() << ToolName << ": '" << File << "': " << Buf;
exit(1);
}

struct CopyConfig {
StringRef OutputFilename;
StringRef InputFilename;
Expand Down Expand Up @@ -179,6 +151,37 @@ struct CopyConfig {

using SectionPred = std::function<bool(const SectionBase &Sec)>;

} // namespace

namespace llvm {
namespace objcopy {

// The name this program was invoked as.
StringRef ToolName;

LLVM_ATTRIBUTE_NORETURN void error(Twine Message) {
errs() << ToolName << ": " << Message << ".\n";
errs().flush();
exit(1);
}

LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, std::error_code EC) {
assert(EC);
errs() << ToolName << ": '" << File << "': " << EC.message() << ".\n";
exit(1);
}

LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Error E) {
assert(E);
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
OS.flush();
errs() << ToolName << ": '" << File << "': " << Buf;
exit(1);
}

} // end namespace objcopy
} // end namespace llvm

static bool IsDWOSection(const SectionBase &Sec) {
Expand Down
2 changes: 2 additions & 0 deletions tools/llvm-objcopy/llvm-objcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string>

namespace llvm {
namespace objcopy {

LLVM_ATTRIBUTE_NORETURN extern void error(Twine Message);
LLVM_ATTRIBUTE_NORETURN extern void reportError(StringRef File, Error E);
Expand All @@ -35,6 +36,7 @@ template <class T> T unwrapOrError(Expected<T> EO) {
error(Buf);
}

} // end namespace objcopy
} // end namespace llvm

#endif // LLVM_TOOLS_OBJCOPY_OBJCOPY_H

0 comments on commit b5b60c3

Please sign in to comment.