62 using util::removePrefix;
63 using util::removeSuffix;
68 using std::regex_replace;
74 const auto DIAGNOSTICS_DOUBLE_PRECISION = 8;
75 const auto DIAGNOSTICS_FLOAT_PRECISION = 5;
97 extern const string BOTTOM_INDICATOR =
"⟂";
98 extern const string FAILURE_INDICATOR =
"↯";
99 extern const string VOID_INDICATOR =
"void";
100 extern const string FUNCTION_INDICATOR=
"Function";
102 extern const string BOOL_FALSE_STR =
"false";
103 extern const string BOOL_TRUE_STR =
"true";
146 demangleCxx (Literal rawName)
149 UniqueMallocOwner<char> demangled (abi::__cxa_demangle (rawName,
153 return 0==error? demangled.get()
159 #warning "Lumiera was _not_ built with a GCC compatible compiler." 160 #warning "There are good chances this works without problems, but up to now, \ 161 the Lumiera developers lacked the resources to investigate that option; \ 170 return string (rawName);
203 #define TYP_EXP "[\\w<>\\(\\):,\\s]+" 205 static regex commonPrefixes {
"std::" 206 "|(\\w+::)+\\(anonymous namespace\\)::" 213 "|steam::(asset::|mobject::(session::)?|play::)?" 217 , regex::ECMAScript | regex::optimize};
219 static regex stdString {
"(__cxx11::)?basic_string<char, char_traits<char>, allocator<char>\\s*>(\\s+\\B)?" 220 , regex::ECMAScript | regex::optimize};
222 static regex stdAllocator {
"(\\w+<(" TYP_EXP
")), allocator<\\2>\\s*" 223 , regex::ECMAScript | regex::optimize};
225 static regex mapAllocator {
"(map<(" TYP_EXP
"), (" TYP_EXP
")),.+allocator<pair<\\2 const, \\3>\\s*>\\s*" 226 , regex::ECMAScript | regex::optimize};
228 static regex uniquePtr {
"unique_ptr<(\\w+), default_delete<\\1>\\s*" 229 , regex::ECMAScript | regex::optimize};
231 static regex lumieraP {
"P<(\\w+), shared_ptr<\\1>\\s*" 232 , regex::ECMAScript | regex::optimize};
235 auto pos = typeName.begin();
236 auto end = typeName.end();
238 end = regex_replace(pos, pos, end, commonPrefixes,
"");
239 end = regex_replace(pos, pos, end, stdString,
"string");
240 end = regex_replace(pos, pos, end, stdAllocator,
"$1");
241 end = regex_replace(pos, pos, end, mapAllocator,
"$1");
242 end = regex_replace(pos, pos, end, uniquePtr,
"unique_ptr<$1");
243 end = regex_replace(pos, pos, end, lumieraP,
"P<$1");
245 typeName.resize(end - typeName.begin());
274 removeSuffix (typeStr,
" const");
275 removeSuffix (typeStr,
" const *");
276 removeSuffix (typeStr,
"*");
277 removeSuffix (typeStr,
"&");
279 if (isnil (typeStr))
return VOID_INDICATOR;
280 if (
')' == typeStr.back())
return FUNCTION_INDICATOR;
282 auto end = typeStr.end();
283 auto beg = typeStr.begin();
289 else if (
'<' == *end and level>0)
298 if (end == beg)
return VOID_INDICATOR;
300 auto pos = typeStr.rfind(
"::", end-beg);
301 typeStr = (pos==string::npos? typeStr.substr(0, end-beg)
302 : typeStr.substr(pos+2, (end-beg)-pos-2));
317 static regex identifierChars {
"[A-Za-z]\\w*", regex::ECMAScript | regex::optimize};
319 return regex_replace (text, identifierChars,
"$&", std::regex_constants::format_no_copy);
338 using std::uppercase;
339 using std::noshowbase;
340 using std::ostringstream;
345 showFloatingPoint (F val,
size_t precision) noexcept
347 ostringstream buffer;
348 buffer.precision (precision);
353 {
return FAILURE_INDICATOR; }
362 string showDouble (
double val) noexcept {
return showFloatingPoint (val, DIAGNOSTICS_DOUBLE_PRECISION); }
363 string showFloat (
float val) noexcept {
return showFloatingPoint (val, DIAGNOSTICS_FLOAT_PRECISION); }
365 string showDecimal (
double val) noexcept {
return showFloatingPoint (val, PRECISION_DECIMAL<double>); }
366 string showDecimal (
float val) noexcept {
return showFloatingPoint (val, PRECISION_DECIMAL<float>); }
367 string showDecimal (f128 val) noexcept {
return showFloatingPoint (val, PRECISION_DECIMAL<f128>); }
369 string showComplete (
double val) noexcept {
return showFloatingPoint (val, PRECISION_COMPLETE<double>); }
370 string showComplete (
float val) noexcept {
return showFloatingPoint (val, PRECISION_COMPLETE<float>); }
371 string showComplete (f128 val) noexcept {
return showFloatingPoint (val, PRECISION_COMPLETE<f128>); }
375 showSize (
size_t val) noexcept
377 ostringstream buffer;
382 {
return FAILURE_INDICATOR; }
397 << size_t(addr) % suffix_modulus;
404 ostringstream buffer;
409 {
return FAILURE_INDICATOR; }
416 size_t suffix_modulus = size_t(1) << showBytes * 8;
417 ostringstream buffer;
421 << setw (showBytes * 2)
424 << (showBytes==8? hash : hash % suffix_modulus);
428 {
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