ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
boxing_format_debug.cpp
1#if ALIB_DEBUG_BOXING
3namespace alib::boxing::debug {
4
5void typeInfo( AString& target,
6 const detail::VTable* vtable,
7 const String& indent,
8 bool srcIsPointer,
9 bool srcIsStringType,
10 bool srcIsUnboxableStringType,
11 bool isValueTypeCustomized,
12 bool isPointerTypeCustomized,
13 bool fitsToPlaceholder,
14 bool copyConstructible,
15 bool triviallyDestructible,
16 bool isUnboxable ) {
17 target <<indent << "Mapping: " << ( vtable->Mapping == detail::VTable::MappingType::Pointer
18 ? "Pointer"
20 ? "Value"
22 ? "Enum"
23 : "Array"
24 ) << NEW_LINE;
26 target << indent << "Mapped Type: "; typeName(vtable, target ); target << " (Enumeration)" << NEW_LINE;
27 target << indent << "Customized: Not customizable (always boxed as enum value type)" << NEW_LINE;
28 } else {
29 bool valueBoxing = vtable->Mapping == detail::VTable::MappingType::Value;
30 bool pointerBoxing= vtable->Mapping == detail::VTable::MappingType::Pointer;
31 bool arrayBoxing = vtable->IsArray();
32 bool srcIsValue = !srcIsPointer;
33
34 target << indent << "Mapped Type: "; typeName(vtable, target ); target << NEW_LINE;
35
36 target <<indent << "Customized T: " << isValueTypeCustomized << NEW_LINE;
37 target <<indent << "Customized T*: " << isPointerTypeCustomized << NEW_LINE;
38 target <<indent << "Is Unboxable: "
39 <<( isUnboxable
40 ? ( srcIsValue && valueBoxing && isValueTypeCustomized
41 ? "Yes (By customization)"
42
43 : srcIsValue && valueBoxing && !isValueTypeCustomized
44 ? "Yes (Value fits in placeholder and is copy-constructible)"
45
46 : srcIsPointer && pointerBoxing && isPointerTypeCustomized
47 ? "Yes (By customization)"
48
49 : srcIsPointer && pointerBoxing && !isPointerTypeCustomized && (!copyConstructible || !triviallyDestructible)
50 ? "Yes (Value would not be copy-constructible or trivially destructible)"
51
52 : srcIsPointer && pointerBoxing && !isPointerTypeCustomized && !fitsToPlaceholder
53 ? "Yes (Value would not fit to placeholder)"
54
55 : srcIsValue && arrayBoxing && isValueTypeCustomized
56 ? "Yes (Custom unboxing from array type)"
57
58 : srcIsValue && arrayBoxing && isPointerTypeCustomized
59 ? "Yes (Unboxing from array type, customized with pointer type)"
60
61 : srcIsPointer && arrayBoxing && isPointerTypeCustomized
62 ? "Yes (Custom unboxing from array type)"
63
64 : srcIsPointer && arrayBoxing && isValueTypeCustomized
65 ? "Yes (Unboxing from array type, customized with value type)"
66
67 : srcIsUnboxableStringType
68 ? "Yes (Unboxing from character array type)"
69
70 : "INTERNAL ERROR IN DBG METHDO: CASE NOT MATCHED (E1)"
71 )
72 : (
73 srcIsValue && isValueTypeCustomized
74 ? "Forbidden (By customization)"
75
76 : srcIsValue && pointerBoxing && isPointerTypeCustomized
77 ? "Not as value (Pointer type is customized)"
78
79 : srcIsValue && pointerBoxing && !isPointerTypeCustomized && (!copyConstructible || !triviallyDestructible)
80 ? "Not as value (Not copy-constructible or trivially destructible)"
81
82 : srcIsValue && pointerBoxing && !isPointerTypeCustomized && !fitsToPlaceholder
83 ? "Not as value (Does not fit to placeholder)"
84
85 : srcIsPointer && isPointerTypeCustomized
86 ? "Forbidden (By customization)"
87
88 : srcIsPointer && valueBoxing && isValueTypeCustomized
89 ? "Not as pointer (Value type is customized)"
90
91 : srcIsPointer && valueBoxing && !isValueTypeCustomized
92 ? "Not as pointer (Value fits in placeholder and is copy-constructible and trivially destructible)"
93
94 : arrayBoxing
95 ? "Arrays cannot be unboxed"
96
97 : srcIsStringType
98 ? "No (String type is not marked for implicit construction from character array type)"
99
100 : "INTERNAL ERROR IN DBG METHOd: CASE NOT MATCHED (E2)"
101 )
102 ) << NEW_LINE;
103 } // not enum
104
105 target << indent << "VTable Type: " << ( vtable->DbgProduction == detail::VTable::DbgFactoryType::Unregistered
106 ? "STATIC VTABLE NOT REGISTERED"
108 ? "Dynamic Singleton"
109 : "Static Singleton (Specialized VTableOptimizationTraits)"
110 )
111 << NEW_LINE;
112
113 target << indent << "Usage Counter: " << vtable->DbgCntUsage << NEW_LINE;
114
115 ALIB_ASSERT_ERROR( target.IndexOf( A_CHAR("INTERNAL ERROR") ) < 0, "BOXING",
116 "An internal error occurred while describing type. Description follows:\n"
117 , target)
118
119 ALIB_ASSERT_WARNING( target.IndexOf( A_CHAR("STATIC VTABLE NOT REGISTERED") ) < 0, "BOXING",
120 "An warning occurred while describing type. Description follows:\n"
121 , target)
122 auto functions= GetSpecificFunctionTypes(vtable);
124 DbgStringTable<uinteger> tmpStrings( la );
125 String256 headline; headline << '\n' << indent << "Associated Specialized Functions:";
126 String256 indent2; indent2 << indent << indent;
127 dumpFunctions( functions, target, headline, indent2, tmpStrings );
128}
129
130
131//##################################################################################################
132// Dump Type Lists (conversion for type lists)
133//##################################################################################################
134AString DumpFunctions( const std::vector<std::pair<const std::type_info*,uinteger>>& input,
135 const String& headline,
136 const String& indent ) {
137 AString result;
139 DbgStringTable<uinteger> tmpStrings( la );
140
141 // repeat twice to get auto-tabs adjusted
143 Formatter& formatter= *Formatter::DEFAULT;
144 formatter.Reset();
145 for( int theSakeOfAutoTabs= 0 ; theSakeOfAutoTabs < 2 ; ++theSakeOfAutoTabs ) {
146 result.Reset();
147 dumpFunctions( input, result, headline, indent, tmpStrings );
148 }
149
150 return result;
151}
152
153void dumpFunctions( const std::vector<std::pair<const std::type_info*,uinteger>>& input,
154 AString& output,
155 const String& headline,
156 const String& indent,
157 DbgStringTable<uinteger>& tmpStrings ) {
158 String512 buffer;
159 tmpStrings.clear();
160 for( auto& type : input )
161 tmpStrings.Add( RemoveNamespaces(buffer.Reset() << *type.first, 0), type.second );
162
163 std::sort( tmpStrings.begin(), tmpStrings.end(),
164 [] (std::tuple<String, uinteger>& a,
165 std::tuple<String, uinteger>& b )
166 {
167 return std::get<0>(a).template CompareTo<CHK, lang::Case::Ignore>( std::get<0>(b) ) < 0;
168 }
169 );
170
171 if ( headline.IsNotEmpty() )
172 output << headline << NEW_LINE;
173
174 Formatter& formatter= *Formatter::DEFAULT;
175 auto& args= formatter.Reset();
176 args.Add( indent, "{} {!ATab5}{:>2})\n", nullptr, '(', nullptr );
177 for( auto& nameAndUse : tmpStrings ) {
178 args[2]= std::get<0>(nameAndUse);
179 args[4]= std::get<1>(nameAndUse) != (std::numeric_limits<uinteger>::max)()
180 ? Box( std::get<1>(nameAndUse) )
181 : Box( "No default implementation" );
182 formatter.FormatArgs( output, args );
183 }
184 output << NEW_LINE;
185}
186
187AString DumpVTables( bool staticVtables, bool includeFunctions ) {
188 AString result;
189 LocalAllocator8K allocator;
190
191 // repeat twice to get auto-tabs adjusted
193 Formatter& formatter= *Formatter::DEFAULT;
194 formatter.Reset();
195
196 for( int theSakeOfAutoTabs= 0 ; theSakeOfAutoTabs < 2 ; ++theSakeOfAutoTabs ) {
197 result .Reset();
198 allocator .Reset();
199 DbgStringTable<const detail::VTable*> vtableNames( allocator );
200 dumpVTables( result, vtableNames, staticVtables , includeFunctions );
201 }
202
203 return result;
204}
205
206
207void dumpVTables( AString& result,
209 bool staticVtables,
210 bool includeFunctions ) {
211 // dump vtables and their interfaces
212 result << ( staticVtables ? A_CHAR("Mapped types with static VTables")
213 : A_CHAR("Mapped types with dynamic VTables") );
214 if( includeFunctions )
215 result << A_CHAR(" and their associated specialized functions");
216
217 (result << ':' << NEW_LINE) .InsertChars('-', 77) << NEW_LINE;
218
219 // Get vtables and add names to string array
220 vtableNames.clear();
221 String1K temp;
222 DbgLockMaps(true);
223 for( int i= 0 ; i < 2; ++i )
224 for( auto& it : ( i == 0 ? DbgKnownVTables : DbgKnownVTablesArray) ) {
225 if( (it.second->DbgProduction == (staticVtables ? detail::VTable::DbgFactoryType::Static
227 || it.second->DbgProduction == detail::VTable::DbgFactoryType::Unregistered )
228 {
229
230 temp.Reset();
231
232 temp << Field( String64("(") << it.second->DbgCntUsage<< ") ", 6, lang::Alignment::Left );
233 typeName( it.second, temp );
234 if( it.second->DbgProduction == detail::VTable::DbgFactoryType::Unregistered )
235 temp << " ATTENTION: Unregistered customized VTable!!! This is an Error";
236
237 vtableNames.Add( temp, it.second );
238 } }
239 DbgLockMaps(false);
240
241 std::sort( vtableNames.begin(), vtableNames.end(),
244 {
245 // skip the prepended usage number
246 Substring lhs= std::get<0>(a); lhs.TrimStart().ConsumeToken(' '); lhs.TrimStart();
247 Substring rhs= std::get<0>(b); rhs.TrimStart().ConsumeToken(' '); rhs.TrimStart();
248 return lhs.CompareTo<CHK, lang::Case::Ignore>( rhs ) < 0;
249 }
250 );
251
253 DbgStringTable<uinteger> tempStrings( la );
254 std::vector<std::pair<const std::type_info*,uinteger>> tempFunctions;
255 for( auto& vtable: vtableNames ) {
256 result << std::get<0>(vtable) << NEW_LINE;
257 if( includeFunctions ) {
258 getFunctionTypes(std::get<1>(vtable)->Functions, tempFunctions );
259 dumpFunctions( tempFunctions, result, NULL_STRING, A_CHAR(" "), tempStrings );
260} } }
261
262
264 AString result;
265
266 // Get vtables and add names to string array
268
269 // repeat twice to get auto-tabs adjusted
271 Formatter::DEFAULT->Reset();
272 for( int theSakeOfAutoTabs= 0 ; theSakeOfAutoTabs < 2 ; ++theSakeOfAutoTabs ) {
273 result .Reset();
274 la.Reset();
276 DbgStringTable<uinteger> tempStrings( la);
277
278 dumpVTables( result, vtableNames, true , true ); result.NewLine();
279 dumpVTables( result, vtableNames, false, true ); result.NewLine();
280
281 auto knownFunctions= GetKnownFunctionTypes();
282 (result << "Known Function Declarators And Usage Of Default Implementation:"
283 << NEW_LINE) .InsertChars('-', 77) << NEW_LINE;
284 dumpFunctions( knownFunctions, result, NULL_STRING, A_CHAR(" "), tempStrings );
285
286 #if ALIB_DEBUG_CONTAINERS
287 (result << NEW_LINE << "Metrics Of Custom Function Implementation HashMap: "
288 << NEW_LINE) .InsertChars('-', 77) << NEW_LINE;
289 DumpCustomFunctionHashMapMetrics( result, false );
290 result << NEW_LINE;
291 #endif
292 }
293
294 return result;
295}
296
297#if ALIB_DEBUG_CONTAINERS
298void DumpCustomFunctionHashMapMetrics( AString& target, bool detailedBucketList ) {
299 target << containers::DbgDumpDistribution( detail::customFunctionMap, detailedBucketList );
300}
301#endif
302} // namespace [alib::boxing::debug]
303
304# include "ALib.Lang.CIMethods.H"
305#endif // ALIB_DEBUG_BOXING
#define A_CHAR(STR)
#define ALIB_ASSERT_WARNING(cond, domain,...)
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define ALIB_ASSERT_ERROR(cond, domain,...)
static threads::RecursiveLock DEFAULT_LOCK
static SPFormatter DEFAULT
void Reset(Snapshot snapshot=Snapshot())
integer IndexOf(TChar needle, integer startIdx=0) const
Definition string.hpp:799
constexpr bool IsNotEmpty() const
Definition string.hpp:353
void typeInfo(AString &target, const detail::VTable *vtable, const String &indent, bool srcIsPointer, bool srcIsStringType, bool srcIsUnboxableStringType, bool isValueTypeCustomized, bool isPointerTypeCustomized, bool fitsToPlaceholder, bool copyConstructible, bool triviallyDestructible, bool isUnboxable)
std::vector< std::pair< const std::type_info *, uinteger > > GetKnownFunctionTypes()
Definition vtable.cpp:136
AString & RemoveNamespaces(AString &string, integer startIndex)
void dumpFunctions(const std::vector< std::pair< const std::type_info *, uinteger > > &input, AString &output, const String &headline, const String &indent, DbgStringTable< uinteger > &tmpStrings)
AString DumpFunctions(const std::vector< std::pair< const std::type_info *, uinteger > > &input, const String &headline, const String &indent)
void getFunctionTypes(const detail::FunctionTable &input, std::vector< std::pair< const std::type_info *, uinteger > > &output)
Definition vtable.cpp:167
std::vector< std::pair< const std::type_info *, uinteger > > GetSpecificFunctionTypes(const detail::VTable *vtable)
void dumpVTables(AString &result, DbgStringTable< const detail::VTable * > &vtableNames, bool staticVtables, bool includeFunctions)
AString DumpVTables(bool staticVtables, bool includeFunctions)
void DumpCustomFunctionHashMapMetrics(AString &target, bool detailedBucketList)
void typeName(const detail::VTable *vtable, AString &result)
AString DbgDumpDistribution(const THashtable &hashtable, bool detailedBucketList)
@ Left
Chooses left alignment.
format::Formatter Formatter
Type alias in namespace #"%alib".
constexpr String NULL_STRING
A nulled string of the default character type.
Definition string.hpp:2247
monomem::TLocalAllocator< 8 > LocalAllocator8K
Type alias in namespace #"%alib". Allocates 8kB of stack memory.
LocalString< 64 > String64
Type alias name for #"TLocalString;TLocalString<character,64>".
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.hpp:536
boxing::Box Box
Type alias in namespace #"%alib".
Definition box.hpp:1128
strings::TField< character > Field
Type alias in namespace #"%alib".
strings::TString< character > String
Type alias in namespace #"%alib".
Definition string.hpp:2165
LocalString< 1024 > String1K
Type alias name for #"TLocalString;TLocalString<character,1024>".
LocalString< 256 > String256
Type alias name for #"TLocalString;TLocalString<character,256>".
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace #"%alib".
LocalString< 512 > String512
Type alias name for #"TLocalString;TLocalString<character,512>".
std::tuple< String, TAssociatedTypes... > ElementType
Shortcut to the std::tuple-type that instantiations of this template class store.
String & Add(const String &src, TArgs &&... args)
The custom function hash.
Definition vtable.hpp:226
DbgFactoryType DbgProduction
Debug information.
Definition vtable.hpp:271
const MappingType Mapping
Definition vtable.hpp:248
@ Pointer
Pointer boxing.
Definition vtable.hpp:233
@ Enum
Enum type boxing.
Definition vtable.hpp:234
@ Static
A static VTable is in place.
Definition vtable.hpp:265