53 using util::removePrefix;
54 using util::removeSuffix;
59 using std::regex_replace;
65 const auto DIAGNOSTICS_DOUBLE_PRECISION = 8;
66 const auto DIAGNOSTICS_FLOAT_PRECISION = 5;
88 extern const string BOTTOM_INDICATOR =
"⟂";
89 extern const string FAILURE_INDICATOR =
"↯";
90 extern const string VOID_INDICATOR =
"void";
91 extern const string FUNCTION_INDICATOR=
"Function";
93 extern const string BOOL_FALSE_STR =
"false";
94 extern const string BOOL_TRUE_STR =
"true";
137 demangleCxx (Literal rawName)
140 UniqueMallocOwner<char> demangled (abi::__cxa_demangle (rawName,
144 return 0==error? demangled.get()
150 #warning "Lumiera was _not_ built with a GCC compatible compiler." 151 #warning "There are good chances this works without problems, but up to now, \ 152 the Lumiera developers lacked the resources to investigate that option; \ 161 return string (rawName);
194 #define TYP_EXP "[\\w<>\\(\\):,\\s]+" 196 static regex commonPrefixes {
"std::" 197 "|(\\w+::)+\\(anonymous namespace\\)::" 204 "|steam::(asset::|mobject::(session::)?|play::)?" 208 , regex::ECMAScript | regex::optimize};
210 static regex lolong {
"long long" 211 , regex::ECMAScript | regex::optimize};
212 static regex unSigned {
"unsigned (\\w+)" 213 , regex::ECMAScript | regex::optimize};
215 static regex stdString {
"(__cxx11::)?basic_string<char, char_traits<char>, allocator<char>\\s*>(\\s+\\B)?" 216 , regex::ECMAScript | regex::optimize};
218 static regex stdAllocator {
"(\\w+<(" TYP_EXP
")), allocator<\\2>\\s*" 219 , regex::ECMAScript | regex::optimize};
221 static regex mapAllocator {
"(map<(" TYP_EXP
"), (" TYP_EXP
")),.+allocator<pair<\\2 const, \\3>\\s*>\\s*" 222 , regex::ECMAScript | regex::optimize};
224 static regex uniquePtr {
"unique_ptr<(\\w+), default_delete<\\1>\\s*" 225 , regex::ECMAScript | regex::optimize};
227 static regex lumieraP {
"P<(\\w+), shared_ptr<\\1>\\s*" 228 , regex::ECMAScript | regex::optimize};
231 auto pos = typeName.begin();
232 auto end = typeName.end();
234 end = regex_replace(pos, pos, end, commonPrefixes,
"");
235 end = regex_replace(pos, pos, end, lolong,
"llong");
236 end = regex_replace(pos, pos, end, unSigned,
"u$1");
237 end = regex_replace(pos, pos, end, stdString,
"string");
238 end = regex_replace(pos, pos, end, stdAllocator,
"$1");
239 end = regex_replace(pos, pos, end, mapAllocator,
"$1");
240 end = regex_replace(pos, pos, end, uniquePtr,
"unique_ptr<$1");
241 end = regex_replace(pos, pos, end, lumieraP,
"P<$1");
243 typeName.resize(end - typeName.begin());
272 removeSuffix (typeStr,
" const");
273 removeSuffix (typeStr,
" const *");
274 removeSuffix (typeStr,
"*");
275 removeSuffix (typeStr,
"&");
277 if (isnil (typeStr))
return VOID_INDICATOR;
278 if (
')' == typeStr.back())
return FUNCTION_INDICATOR;
280 auto end = typeStr.end();
281 auto beg = typeStr.begin();
287 else if (
'<' == *end and level>0)
296 if (end == beg)
return VOID_INDICATOR;
298 auto pos = typeStr.rfind(
"::", end-beg);
299 typeStr = (pos==string::npos? typeStr.substr(0, end-beg)
300 : typeStr.substr(pos+2, (end-beg)-pos-2));
315 static regex identifierChars {
"[A-Za-z]\\w*", regex::ECMAScript | regex::optimize};
317 return regex_replace (text, identifierChars,
"$&", std::regex_constants::format_no_copy);
336 using std::uppercase;
337 using std::noshowbase;
338 using std::ostringstream;
343 showFloatingPoint (F val,
size_t precision) noexcept
345 ostringstream buffer;
346 buffer.precision (precision);
351 {
return FAILURE_INDICATOR; }
360 string showDouble (
double val) noexcept {
return showFloatingPoint (val, DIAGNOSTICS_DOUBLE_PRECISION); }
361 string showFloat (
float val) noexcept {
return showFloatingPoint (val, DIAGNOSTICS_FLOAT_PRECISION); }
363 string showDecimal (
double val) noexcept {
return showFloatingPoint (val, PRECISION_DECIMAL<double>); }
364 string showDecimal (
float val) noexcept {
return showFloatingPoint (val, PRECISION_DECIMAL<float>); }
365 string showDecimal (f128 val) noexcept {
return showFloatingPoint (val, PRECISION_DECIMAL<f128>); }
367 string showComplete (
double val) noexcept {
return showFloatingPoint (val, PRECISION_COMPLETE<double>); }
368 string showComplete (
float val) noexcept {
return showFloatingPoint (val, PRECISION_COMPLETE<float>); }
369 string showComplete (f128 val) noexcept {
return showFloatingPoint (val, PRECISION_COMPLETE<f128>); }
373 showSize (
size_t val) noexcept
375 ostringstream buffer;
380 {
return FAILURE_INDICATOR; }
395 << size_t(addr) % suffix_modulus;
402 ostringstream buffer;
407 {
return FAILURE_INDICATOR; }
414 size_t suffix_modulus = size_t(1) << showBytes * 8;
415 ostringstream buffer;
419 << setw (showBytes * 2)
422 << (showBytes==8? hash : hash % suffix_modulus);
426 {
return FAILURE_INDICATOR; }
inline string literal This is a marker type to indicate that
Capture previous settings of an std::ostream and restore them when leaving scope. ...
Helper to deal with C-MALLOCed memory automatically.
Implementation namespace for support and library code.
Marker types to indicate a literal string and a Symbol.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
RAII helper to capture and restore output stream format settings.
Lumiera error handling (C++ interface).
NUM constexpr limited(NB lowerBound, NUM val, NB upperBound)
force a numeric to be within bounds, inclusively