From e3bba294b4b08887851382573a7f2c73545e85fb Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 13 Mar 2017 16:04:29 -0700 Subject: Introduce LINE_INFO macro + struct --- toolsrc/include/vcpkg_Checks.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Checks.h b/toolsrc/include/vcpkg_Checks.h index 23869f35f..c9293b0bb 100644 --- a/toolsrc/include/vcpkg_Checks.h +++ b/toolsrc/include/vcpkg_Checks.h @@ -2,6 +2,22 @@ #include "vcpkg_Strings.h" +namespace vcpkg +{ + struct LineInfo + { + int line_number; + const char* file_name; + + constexpr LineInfo() : line_number(0), file_name(nullptr) {} + constexpr LineInfo(const int line_number, const char* file_name) : line_number(line_number), file_name(file_name) {} + + std::string toString() const; + }; +} + +#define LINE_INFO vcpkg::LineInfo(__LINE__, __FILE__) + namespace vcpkg::Checks { __declspec(noreturn) void unreachable(); -- cgit v1.2.3 From 66ebb6ce2bffa942bda973891cef9e0ae2103ce5 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 13 Mar 2017 16:27:08 -0700 Subject: Make parameter const to avoid C4239 warnings --- toolsrc/include/lazy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/lazy.h b/toolsrc/include/lazy.h index f9dbd8dc7..0fa50dc4d 100644 --- a/toolsrc/include/lazy.h +++ b/toolsrc/include/lazy.h @@ -9,7 +9,7 @@ namespace vcpkg lazy() : value(T()), initialized(false) {} template - T const& get_lazy(F& f) const + T const& get_lazy(const F& f) const { if (!initialized) { -- cgit v1.2.3 From 4ee9c451fcaec22a4e52ff003e5357907ca485d4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 13 Mar 2017 16:28:19 -0700 Subject: Rename LINE_INFO to VCPKG_LINE_INFO to avoid conflict with CppUnitTestAssert.h --- toolsrc/include/vcpkg_Checks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Checks.h b/toolsrc/include/vcpkg_Checks.h index c9293b0bb..7b9f2535f 100644 --- a/toolsrc/include/vcpkg_Checks.h +++ b/toolsrc/include/vcpkg_Checks.h @@ -16,7 +16,7 @@ namespace vcpkg }; } -#define LINE_INFO vcpkg::LineInfo(__LINE__, __FILE__) +#define VCPKG_LINE_INFO vcpkg::LineInfo(__LINE__, __FILE__) namespace vcpkg::Checks { -- cgit v1.2.3 From cbcd29c20954e400bf9f0eef60dd49b0af30abe6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 13 Mar 2017 16:39:40 -0700 Subject: Global variable g_debugging now declared in vcpkglib.h --- toolsrc/include/vcpkglib.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkglib.h b/toolsrc/include/vcpkglib.h index 353bfb0a0..710b21cd5 100644 --- a/toolsrc/include/vcpkglib.h +++ b/toolsrc/include/vcpkglib.h @@ -6,6 +6,8 @@ namespace vcpkg { + extern bool g_debugging; + StatusParagraphs database_load_check(const vcpkg_paths& paths); void write_update(const vcpkg_paths& paths, const StatusParagraph& p); -- cgit v1.2.3 From d15818c602e4031cb9ba6cf622182ca6e90f40ba Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 13 Mar 2017 16:59:21 -0700 Subject: Checks::unreachable() now needs LineInfo as an argument --- toolsrc/include/vcpkg_Checks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Checks.h b/toolsrc/include/vcpkg_Checks.h index 7b9f2535f..328e0238a 100644 --- a/toolsrc/include/vcpkg_Checks.h +++ b/toolsrc/include/vcpkg_Checks.h @@ -20,7 +20,7 @@ namespace vcpkg namespace vcpkg::Checks { - __declspec(noreturn) void unreachable(); + __declspec(noreturn) void unreachable(const LineInfo& line_info); // Part of the reason these exist is to not include extra headers in this one to avoid circular #includes. _declspec(noreturn) void exit_with_message(const char* errorMessage); -- cgit v1.2.3 From 2590371023b7eaebbd81f857a76ec95556b80705 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 13 Mar 2017 17:07:06 -0700 Subject: Remove Enums::unreachable(). Use Checks::unreachable() instead --- toolsrc/include/vcpkg_Enums.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Enums.h b/toolsrc/include/vcpkg_Enums.h index 5c4dc8b06..b1ecc311b 100644 --- a/toolsrc/include/vcpkg_Enums.h +++ b/toolsrc/include/vcpkg_Enums.h @@ -6,6 +6,4 @@ namespace vcpkg::Enums std::string nullvalue_toString(const std::string& enum_name); __declspec(noreturn) void nullvalue_used(const std::string& enum_name); - - __declspec(noreturn) void unreachable(const std::string& enum_name); } -- cgit v1.2.3 From 8e8debc8482b7241522e20243a65852c11c53fa4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 13 Mar 2017 17:14:00 -0700 Subject: Put LineInfo in separate h/cpp --- toolsrc/include/LineInfo.h | 17 +++++++++++++++++ toolsrc/include/vcpkg_Checks.h | 17 +---------------- 2 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 toolsrc/include/LineInfo.h (limited to 'toolsrc/include') diff --git a/toolsrc/include/LineInfo.h b/toolsrc/include/LineInfo.h new file mode 100644 index 000000000..a3de4fc29 --- /dev/null +++ b/toolsrc/include/LineInfo.h @@ -0,0 +1,17 @@ +#pragma once + +namespace vcpkg +{ + struct LineInfo + { + int line_number; + const char* file_name; + + constexpr LineInfo() : line_number(0), file_name(nullptr) {} + constexpr LineInfo(const int line_number, const char* file_name) : line_number(line_number), file_name(file_name) {} + + std::string toString() const; + }; +} + +#define VCPKG_LINE_INFO vcpkg::LineInfo(__LINE__, __FILE__) diff --git a/toolsrc/include/vcpkg_Checks.h b/toolsrc/include/vcpkg_Checks.h index 328e0238a..76c86cfab 100644 --- a/toolsrc/include/vcpkg_Checks.h +++ b/toolsrc/include/vcpkg_Checks.h @@ -1,22 +1,7 @@ #pragma once #include "vcpkg_Strings.h" - -namespace vcpkg -{ - struct LineInfo - { - int line_number; - const char* file_name; - - constexpr LineInfo() : line_number(0), file_name(nullptr) {} - constexpr LineInfo(const int line_number, const char* file_name) : line_number(line_number), file_name(file_name) {} - - std::string toString() const; - }; -} - -#define VCPKG_LINE_INFO vcpkg::LineInfo(__LINE__, __FILE__) +#include "LineInfo.h" namespace vcpkg::Checks { -- cgit v1.2.3 From 98ea6780e7a4af7d237783a72a2a56a6188ae3da Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 13 Mar 2017 17:15:39 -0700 Subject: Enums::nullvalue_used() now requires LineInfo as first arg --- toolsrc/include/vcpkg_Enums.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg_Enums.h b/toolsrc/include/vcpkg_Enums.h index b1ecc311b..ef41155d9 100644 --- a/toolsrc/include/vcpkg_Enums.h +++ b/toolsrc/include/vcpkg_Enums.h @@ -1,9 +1,10 @@ #pragma once #include +#include "LineInfo.h" namespace vcpkg::Enums { std::string nullvalue_toString(const std::string& enum_name); - __declspec(noreturn) void nullvalue_used(const std::string& enum_name); + __declspec(noreturn) void nullvalue_used(const LineInfo& line_info, const std::string& enum_name); } -- cgit v1.2.3 From 4114d87a0774fff7d8bc5e041bb56158bfdbcac8 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 13 Mar 2017 17:38:04 -0700 Subject: All Checks now take LineInfo as the first argument --- toolsrc/include/expected.h | 12 ++++++------ toolsrc/include/vcpkg_Checks.h | 26 +++++++++++++------------- toolsrc/include/vcpkg_Files.h | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/expected.h b/toolsrc/include/expected.h index cbb513b22..377168645 100644 --- a/toolsrc/include/expected.h +++ b/toolsrc/include/expected.h @@ -40,15 +40,15 @@ namespace vcpkg return this->m_error_code; } - T&& get_or_throw() && + T&& get_or_throw(const LineInfo& line_info) && { - throw_if_error(); + throw_if_error(line_info); return std::move(this->m_t); } - const T& get_or_throw() const & + const T& get_or_throw(const LineInfo& line_info) const & { - throw_if_error(); + throw_if_error(line_info); return this->m_t; } @@ -71,9 +71,9 @@ namespace vcpkg } private: - void throw_if_error() const + void throw_if_error(const LineInfo& line_info) const { - Checks::check_throw(!this->m_error_code, this->m_error_code.message().c_str()); + Checks::check_throw(line_info, !this->m_error_code, this->m_error_code.message().c_str()); } std::error_code m_error_code; diff --git a/toolsrc/include/vcpkg_Checks.h b/toolsrc/include/vcpkg_Checks.h index 76c86cfab..47662637f 100644 --- a/toolsrc/include/vcpkg_Checks.h +++ b/toolsrc/include/vcpkg_Checks.h @@ -8,45 +8,45 @@ namespace vcpkg::Checks __declspec(noreturn) void unreachable(const LineInfo& line_info); // Part of the reason these exist is to not include extra headers in this one to avoid circular #includes. - _declspec(noreturn) void exit_with_message(const char* errorMessage); + _declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessage); template - _declspec(noreturn) void exit_with_message(const char* errorMessageTemplate, const Args&... errorMessageArgs) + _declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Args&... errorMessageArgs) { - exit_with_message(Strings::format(errorMessageTemplate, errorMessageArgs...).c_str()); + exit_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str()); } - _declspec(noreturn) void throw_with_message(const char* errorMessage); + _declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessage); template - _declspec(noreturn) void throw_with_message(const char* errorMessageTemplate, const Args&... errorMessageArgs) + _declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Args&... errorMessageArgs) { - throw_with_message(Strings::format(errorMessageTemplate, errorMessageArgs...).c_str()); + throw_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str()); } - void check_throw(bool expression, const char* errorMessage); + void check_throw(const LineInfo& line_info, bool expression, const char* errorMessage); template - void check_throw(bool expression, const char* errorMessageTemplate, const Args&... errorMessageArgs) + void check_throw(const LineInfo& line_info, bool expression, const char* errorMessageTemplate, const Args&... errorMessageArgs) { if (!expression) { // Only create the string if the expression is false - throw_with_message(Strings::format(errorMessageTemplate, errorMessageArgs...).c_str()); + throw_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str()); } } - void check_exit(bool expression); + void check_exit(const LineInfo& line_info, bool expression); - void check_exit(bool expression, const char* errorMessage); + void check_exit(const LineInfo& line_info, bool expression, const char* errorMessage); template - void check_exit(bool expression, const char* errorMessageTemplate, const Args&... errorMessageArgs) + void check_exit(const LineInfo& line_info, bool expression, const char* errorMessageTemplate, const Args&... errorMessageArgs) { if (!expression) { // Only create the string if the expression is false - exit_with_message(Strings::format(errorMessageTemplate, errorMessageArgs...).c_str()); + exit_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str()); } } } diff --git a/toolsrc/include/vcpkg_Files.h b/toolsrc/include/vcpkg_Files.h index 3f9570946..0b0373231 100644 --- a/toolsrc/include/vcpkg_Files.h +++ b/toolsrc/include/vcpkg_Files.h @@ -8,7 +8,7 @@ namespace vcpkg::Files { static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)"; - void check_is_directory(const fs::path& dirpath); + void check_is_directory(const LineInfo& line_info, const fs::path& dirpath); bool has_invalid_chars_for_filesystem(const std::string& s); -- cgit v1.2.3