Avoid having "using namespace" for both "clang" and "llvm" namespaces.

This is fragile, as there are classes with the same name in both
namespaces (e.g. llvm::Module and clang::Module).

llvm-svn: 219855
This commit is contained in:
Alexey Samsonov 2014-10-15 22:00:40 +00:00
parent 732e0aa9fb
commit d1127d2d1f
2 changed files with 24 additions and 26 deletions

View File

@ -94,9 +94,8 @@ using namespace clang;
using namespace clang::driver; using namespace clang::driver;
using namespace clang::driver::options; using namespace clang::driver::options;
using namespace clang::tooling; using namespace clang::tooling;
using namespace llvm; namespace cl = llvm::cl;
using namespace llvm::opt; namespace sys = llvm::sys;
using namespace llvm::sys;
// Option for include paths. // Option for include paths.
static cl::list<std::string> static cl::list<std::string>
@ -212,7 +211,7 @@ ModuleMapChecker::ModuleMapChecker(StringRef ModuleMapPath,
DumpModuleMap(DumpModuleMap), CommandLine(CommandLine), DumpModuleMap(DumpModuleMap), CommandLine(CommandLine),
LangOpts(new LangOptions()), DiagIDs(new DiagnosticIDs()), LangOpts(new LangOptions()), DiagIDs(new DiagnosticIDs()),
DiagnosticOpts(new DiagnosticOptions()), DiagnosticOpts(new DiagnosticOptions()),
DC(errs(), DiagnosticOpts.get()), DC(llvm::errs(), DiagnosticOpts.get()),
Diagnostics( Diagnostics(
new DiagnosticsEngine(DiagIDs, DiagnosticOpts.get(), &DC, false)), new DiagnosticsEngine(DiagIDs, DiagnosticOpts.get(), &DC, false)),
TargetOpts(new ModuleMapTargetOptions()), TargetOpts(new ModuleMapTargetOptions()),
@ -267,7 +266,7 @@ std::error_code ModuleMapChecker::doChecks() {
// Dump module map if requested. // Dump module map if requested.
if (DumpModuleMap) { if (DumpModuleMap) {
errs() << "\nDump of module map:\n\n"; llvm::errs() << "\nDump of module map:\n\n";
ModMap->dump(); ModMap->dump();
} }
@ -285,7 +284,7 @@ bool ModuleMapChecker::loadModuleMap() {
// return error if not found. // return error if not found.
if (!ModuleMapEntry) { if (!ModuleMapEntry) {
errs() << "error: File \"" << ModuleMapPath << "\" not found.\n"; llvm::errs() << "error: File \"" << ModuleMapPath << "\" not found.\n";
return false; return false;
} }
@ -365,16 +364,16 @@ bool ModuleMapChecker::collectUmbrellaHeaders(StringRef UmbrellaDirName) {
Directory = "."; Directory = ".";
// Walk the directory. // Walk the directory.
std::error_code EC; std::error_code EC;
fs::file_status Status; sys::fs::file_status Status;
for (fs::directory_iterator I(Directory.str(), EC), E; I != E; for (sys::fs::directory_iterator I(Directory.str(), EC), E; I != E;
I.increment(EC)) { I.increment(EC)) {
if (EC) if (EC)
return false; return false;
std::string File(I->path()); std::string File(I->path());
I->status(Status); I->status(Status);
fs::file_type Type = Status.type(); sys::fs::file_type Type = Status.type();
// If the file is a directory, ignore the name. // If the file is a directory, ignore the name.
if (Type == fs::file_type::directory_file) if (Type == sys::fs::file_type::directory_file)
continue; continue;
// If the file does not have a common header extension, ignore it. // If the file does not have a common header extension, ignore it.
if (!isHeader(File)) if (!isHeader(File))
@ -475,24 +474,24 @@ bool ModuleMapChecker::collectFileSystemHeaders(StringRef IncludePath) {
Directory = "."; Directory = ".";
if (IncludePath.startswith("/") || IncludePath.startswith("\\") || if (IncludePath.startswith("/") || IncludePath.startswith("\\") ||
((IncludePath.size() >= 2) && (IncludePath[1] == ':'))) { ((IncludePath.size() >= 2) && (IncludePath[1] == ':'))) {
errs() << "error: Include path \"" << IncludePath llvm::errs() << "error: Include path \"" << IncludePath
<< "\" is not relative to the module map file.\n"; << "\" is not relative to the module map file.\n";
return false; return false;
} }
// Recursively walk the directory tree. // Recursively walk the directory tree.
std::error_code EC; std::error_code EC;
fs::file_status Status; sys::fs::file_status Status;
int Count = 0; int Count = 0;
for (fs::recursive_directory_iterator I(Directory.str(), EC), E; I != E; for (sys::fs::recursive_directory_iterator I(Directory.str(), EC), E; I != E;
I.increment(EC)) { I.increment(EC)) {
if (EC) if (EC)
return false; return false;
std::string file(I->path()); std::string file(I->path());
I->status(Status); I->status(Status);
fs::file_type type = Status.type(); sys::fs::file_type type = Status.type();
// If the file is a directory, ignore the name (but still recurses). // If the file is a directory, ignore the name (but still recurses).
if (type == fs::file_type::directory_file) if (type == sys::fs::file_type::directory_file)
continue; continue;
// If the file does not have a common header extension, ignore it. // If the file does not have a common header extension, ignore it.
if (!isHeader(file)) if (!isHeader(file))
@ -502,8 +501,8 @@ bool ModuleMapChecker::collectFileSystemHeaders(StringRef IncludePath) {
Count++; Count++;
} }
if (Count == 0) { if (Count == 0) {
errs() << "warning: No headers found in include path: \"" << IncludePath llvm::errs() << "warning: No headers found in include path: \""
<< "\"\n"; << IncludePath << "\"\n";
} }
return true; return true;
} }
@ -526,7 +525,7 @@ void ModuleMapChecker::findUnaccountedForHeaders() {
// Look for header in module map. // Look for header in module map.
if (ModuleMapHeadersSet.insert(*I)) { if (ModuleMapHeadersSet.insert(*I)) {
UnaccountedForHeaders.push_back(*I); UnaccountedForHeaders.push_back(*I);
errs() << "warning: " << ModuleMapPath llvm::errs() << "warning: " << ModuleMapPath
<< " does not account for file: " << *I << "\n"; << " does not account for file: " << *I << "\n";
} }
} }

View File

@ -27,8 +27,6 @@
#include "llvm/Support/Path.h" #include "llvm/Support/Path.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
using namespace llvm;
using namespace llvm::sys;
using namespace clang; using namespace clang;
namespace { namespace {
@ -142,7 +140,7 @@ protected:
FileMgr.getVirtualFile(HeaderPath, 0, 0); FileMgr.getVirtualFile(HeaderPath, 0, 0);
// Add header's parent path to search path. // Add header's parent path to search path.
StringRef SearchPath = path::parent_path(HeaderPath); StringRef SearchPath = llvm::sys::path::parent_path(HeaderPath);
const DirectoryEntry *DE = FileMgr.getDirectory(SearchPath); const DirectoryEntry *DE = FileMgr.getDirectory(SearchPath);
DirectoryLookup DL(DE, SrcMgr::C_User, false); DirectoryLookup DL(DE, SrcMgr::C_User, false);
HeaderInfo.AddSearchPath(DL, IsSystemHeader); HeaderInfo.AddSearchPath(DL, IsSystemHeader);
@ -160,7 +158,8 @@ protected:
// the InclusionDirective callback. // the InclusionDirective callback.
CharSourceRange InclusionDirectiveFilenameRange(const char* SourceText, CharSourceRange InclusionDirectiveFilenameRange(const char* SourceText,
const char* HeaderPath, bool SystemHeader) { const char* HeaderPath, bool SystemHeader) {
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(SourceText); std::unique_ptr<llvm::MemoryBuffer> Buf =
llvm::MemoryBuffer::getMemBuffer(SourceText);
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf))); SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
VoidModuleLoader ModLoader; VoidModuleLoader ModLoader;
@ -197,8 +196,8 @@ protected:
LangOptions OpenCLLangOpts; LangOptions OpenCLLangOpts;
OpenCLLangOpts.OpenCL = 1; OpenCLLangOpts.OpenCL = 1;
std::unique_ptr<MemoryBuffer> SourceBuf = std::unique_ptr<llvm::MemoryBuffer> SourceBuf =
MemoryBuffer::getMemBuffer(SourceText, "test.cl"); llvm::MemoryBuffer::getMemBuffer(SourceText, "test.cl");
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(SourceBuf))); SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(SourceBuf)));
VoidModuleLoader ModLoader; VoidModuleLoader ModLoader;