From 7acd886ecfa0adc8a14476eafe8cf1fa981cfe18 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 11 Jun 2014 19:05:50 +0000 Subject: Use std::error_code instead of llvm::error_code. The idea of this patch is to turn llvm/Support/system_error.h into a transitional header that just brings in the erorr_code api to the llvm namespace. I will remove it shortly afterwards. The cases where the general idea needed some tweaking: * std::errc is a namespace in msvc, so we cannot use "using std::errc". I could add an #ifdef, but there were not that many uses, so I just added std:: to them in this patch. * Template specialization had to be moved to the std namespace in this patch set already. * The msvc implementation of default_error_condition doesn't seem to provide the same transformations as we need. Not too surprising since the standard doesn't actually say what "equivalent" means. I fixed the problem by keeping our old mapping and using it at error_code construction time. Despite these shortcomings I think this is still a good thing. Some reasons: * The different implementations of system_error might improve over time. * It removes 925 lines of code from llvm already. * It removes 6313 bytes from the text segment of the clang binary when it is built with gcc and 2816 bytes when building with clang and libstdc++. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210687 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Unix/Path.inc | 12 ++++++------ lib/Support/Unix/system_error.inc | 34 ---------------------------------- 2 files changed, 6 insertions(+), 40 deletions(-) delete mode 100644 lib/Support/Unix/system_error.inc (limited to 'lib/Support/Unix') diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 11ea10e120..ef291db52d 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -317,7 +317,7 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { // effectively prevents LLVM from erasing things like /dev/null, any block // special file, or other things that aren't "regular" files. if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode)) - return make_error_code(errc::operation_not_permitted); + return make_error_code(std::errc::operation_not_permitted); if (::remove(p.begin()) == -1) { if (errno != ENOENT || !IgnoreNonExisting) @@ -402,7 +402,7 @@ static error_code fillStatus(int StatRet, const struct stat &Status, file_status &Result) { if (StatRet != 0) { error_code ec(errno, generic_category()); - if (ec == errc::no_such_file_or_directory) + if (ec == std::errc::no_such_file_or_directory) Result = file_status(file_type::file_not_found); else Result = file_status(file_type::status_error); @@ -466,7 +466,7 @@ error_code setLastModificationAndAccessTime(int FD, TimeValue Time) { return error_code(); #else #warning Missing futimes() and futimens() - return make_error_code(errc::not_supported); + return make_error_code(std::errc::not_supported); #endif } @@ -510,7 +510,7 @@ mapped_file_region::mapped_file_region(const Twine &path, , Mapping() { // Make sure that the requested size fits within SIZE_T. if (length > std::numeric_limits::max()) { - ec = make_error_code(errc::invalid_argument); + ec = make_error_code(std::errc::invalid_argument); return; } @@ -539,7 +539,7 @@ mapped_file_region::mapped_file_region(int fd, , Mapping() { // Make sure that the requested size fits within SIZE_T. if (length > std::numeric_limits::max()) { - ec = make_error_code(errc::invalid_argument); + ec = make_error_code(std::errc::invalid_argument); return; } @@ -645,7 +645,7 @@ error_code get_magic(const Twine &path, uint32_t len, if (std::feof(file) != 0) { std::fclose(file); result.set_size(size); - return make_error_code(errc::value_too_large); + return make_error_code(std::errc::value_too_large); } } std::fclose(file); diff --git a/lib/Support/Unix/system_error.inc b/lib/Support/Unix/system_error.inc deleted file mode 100644 index 681e919edb..0000000000 --- a/lib/Support/Unix/system_error.inc +++ /dev/null @@ -1,34 +0,0 @@ -//===- llvm/Support/Unix/system_error.inc - Unix error_code ------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file provides the Unix specific implementation of the error_code -// and error_condition classes. -// -//===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only generic UNIX code that -//=== is guaranteed to work on *all* UNIX variants. -//===----------------------------------------------------------------------===// - -using namespace llvm; - -std::string -_system_error_category::message(int ev) const { - return _do_message::message(ev); -} - -error_condition -_system_error_category::default_error_condition(int ev) const { -#ifdef ELAST - if (ev > ELAST) - return error_condition(ev, system_category()); -#endif // ELAST - return error_condition(ev, generic_category()); -} -- cgit v1.2.3