diff --git a/src/lib/format-cout.hpp b/src/lib/format-cout.hpp index 637f16785..8286bfb0a 100644 --- a/src/lib/format-cout.hpp +++ b/src/lib/format-cout.hpp @@ -93,7 +93,7 @@ namespace std { operator<< (ostream& os, X* ptr) { if (ptr) - return os << (void*)ptr << " ↗" << *ptr; + return util::showAddr(os, ptr) << " ↗" << *ptr; else return os << "⟂ «" << lib::meta::typeStr() << "»"; } diff --git a/src/lib/format-obj.cpp b/src/lib/format-obj.cpp index d9e9f5885..b40da9f6c 100644 --- a/src/lib/format-obj.cpp +++ b/src/lib/format-obj.cpp @@ -64,8 +64,8 @@ namespace { // hard-wired configuration for debugging output.... const auto DIAGNOSTICS_DOUBLE_PRECISION = 8; const auto DIAGNOSTICS_FLOAT_PRECISION = 5; - /** amount of hex digits required to represent an address on this plattform */ - const auto PLATFORM_ADDRESS_HEX_DIGITS = sizeof(size_t) * 2; + /** show only this amount of trailing bytes from an address */ + const size_t DIAGNOSTICS_ADDRESS_SUFFIX_LEN = 4; } @@ -162,12 +162,13 @@ namespace util { }//(End) implementation details - using std::ostringstream; using std::hex; using std::setw; using std::right; using std::setfill; using std::noshowbase; + using std::ostringstream; + using std::ostream; /** @@ -192,7 +193,7 @@ namespace util { string showFloat (float val) noexcept try { - std::ostringstream buffer; + ostringstream buffer; buffer.precision (DIAGNOSTICS_FLOAT_PRECISION); buffer << val; return buffer.str(); @@ -201,16 +202,26 @@ namespace util { { return "↯"; } + /** @note show only the trailing X bytes of any address */ + ostream& + showAddr (ostream& stream, void* addr) + { + size_t suffix_modulus = size_t(1) << DIAGNOSTICS_ADDRESS_SUFFIX_LEN * 8; + return stream << "╲" + << hex + << noshowbase + << setw (DIAGNOSTICS_ADDRESS_SUFFIX_LEN * 2) // need 2 hex digits per byte + << setfill('_') + << right + << size_t(addr) % suffix_modulus; + } + + string showAddr (void *addr) noexcept try { - std::ostringstream buffer; - buffer << hex - << noshowbase - << setw (PLATFORM_ADDRESS_HEX_DIGITS) - << setfill('_') - << right - << addr; + ostringstream buffer; + showAddr (buffer, addr); return buffer.str(); } catch(...) diff --git a/src/lib/format-obj.hpp b/src/lib/format-obj.hpp index 7d018b396..da4e57c08 100644 --- a/src/lib/format-obj.hpp +++ b/src/lib/format-obj.hpp @@ -49,6 +49,18 @@ #include +namespace std { // forward declaration to avoid including + + template + struct char_traits; + + template + class basic_ostream; + + using ostream = basic_ostream>; +} + + namespace lib { class Literal; @@ -77,6 +89,9 @@ namespace util { std::string showFloat (float) noexcept; std::string showAddr (void *addr) noexcept; + /** preconfigured format for pretty-printing of addresses */ + std::ostream& showAddr (std::ostream&, void* addr); + } // namespace util diff --git a/src/lib/format-string.hpp b/src/lib/format-string.hpp index a6455be02..6d9ddc6fa 100644 --- a/src/lib/format-string.hpp +++ b/src/lib/format-string.hpp @@ -124,10 +124,10 @@ namespace std { // forward declaration to avoid including template class basic_ostream; - typedef basic_ostream > ostream; - + using ostream = basic_ostream>; } + namespace lib { class Literal; class Symbol; diff --git a/src/lib/meta/util.hpp b/src/lib/meta/util.hpp index 9f713aa30..8620ec3e0 100644 --- a/src/lib/meta/util.hpp +++ b/src/lib/meta/util.hpp @@ -264,7 +264,7 @@ namespace util { std::string showDouble (double) noexcept; std::string showFloat (float) noexcept; - /** pretty-print an address as hex-string */ + /** pretty-print an address as hex-suffix */ std::string showAddr (void *addr) noexcept; template