Skip to content

Commit eed9899

Browse files
committed
Move print operators into the ur_print namespace
1 parent eff8063 commit eed9899

File tree

3 files changed

+799
-873
lines changed

3 files changed

+799
-873
lines changed

scripts/templates/print.hpp.mako

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ from templates import helper as th
2727

2828
<%def name="member(iname, itype, loop)">
2929
%if iname == "pNext":
30-
${x}_print::printStruct(os, ${caller.body()});
30+
printStruct(os, ${caller.body()});
3131
%elif th.type_traits.is_flags(itype):
32-
${x}_print::printFlag<${th.type_traits.get_flag_type(itype)}>(os, ${caller.body()});
32+
printFlag<${th.type_traits.get_flag_type(itype)}>(os, ${caller.body()});
3333
%elif not loop and th.type_traits.is_pointer(itype):
34-
${x}_print::printPtr(os, ${caller.body()});
34+
printPtr(os, ${caller.body()});
3535
%elif loop and th.type_traits.is_pointer_to_pointer(itype):
36-
${x}_print::printPtr(os, ${caller.body()});
36+
printPtr(os, ${caller.body()});
3737
%elif th.type_traits.is_handle(itype):
38-
${x}_print::printPtr(os, ${caller.body()});
38+
printPtr(os, ${caller.body()});
3939
%elif iname and iname.startswith("pfn"):
4040
os << reinterpret_cast<void*>(${caller.body()});
4141
%else:
@@ -83,7 +83,7 @@ def findMemberType(_item):
8383
os << "}";
8484
%elif findMemberType(item) is not None and findMemberType(item)['type'] == "union":
8585
os << ".${iname} = ";
86-
${x}_print::printUnion(os, ${deref}(params${access}${item['name']}), params${access}${th.param_traits.tagged_member(item)});
86+
printUnion(os, ${deref}(params${access}${item['name']}), params${access}${th.param_traits.tagged_member(item)});
8787
%elif th.type_traits.is_array(item['type']):
8888
os << ".${iname} = {";
8989
for(auto i = 0; i < ${th.type_traits.get_array_length(item['type'])}; i++){
@@ -97,7 +97,7 @@ def findMemberType(_item):
9797
os << "}";
9898
%elif typename is not None:
9999
os << ".${iname} = ";
100-
${x}_print::printTagged(os, ${deref}(params${access}${pname}), ${deref}(params${access}${prefix}${typename}), ${deref}(params${access}${prefix}${typename_size}));
100+
printTagged(os, ${deref}(params${access}${pname}), ${deref}(params${access}${prefix}${typename}), ${deref}(params${access}${prefix}${typename_size}));
101101
%else:
102102
os << ".${iname} = ";
103103
<%call expr="member(iname, itype, False)">
@@ -147,7 +147,6 @@ template <typename T> inline void printTagged(std::ostream &os, const void *ptr,
147147
%endif
148148
%endfor # obj in spec['objects']
149149
%endfor
150-
} // namespace ${x}_print
151150

152151
%for spec in specs:
153152
%for obj in spec['objects']:
@@ -188,7 +187,6 @@ template <typename T> inline void printTagged(std::ostream &os, const void *ptr,
188187
}
189188
%endif
190189
%if obj.get('typed_etors', False) is True:
191-
namespace ${x}_print {
192190
template <>
193191
inline void printTagged(std::ostream &os, const void *ptr, ${th.make_enum_name(n, tags, obj)} value, size_t size) {
194192
if (ptr == NULL) {
@@ -248,12 +246,11 @@ template <typename T> inline void printTagged(std::ostream &os, const void *ptr,
248246
break;
249247
}
250248
}
251-
}
249+
252250
%elif "structure_type" in obj['name']:
253-
namespace ${x}_print {
254251
inline void printStruct(std::ostream &os, const void *ptr) {
255252
if (ptr == NULL) {
256-
${x}_print::printPtr(os, ptr);
253+
printPtr(os, ptr);
257254
return;
258255
}
259256

@@ -266,18 +263,16 @@ template <typename T> inline void printTagged(std::ostream &os, const void *ptr,
266263
%>
267264
case ${ename}: {
268265
const ${th.subt(n, tags, item['desc'])} *pstruct = (const ${th.subt(n, tags, item['desc'])} *)ptr;
269-
${x}_print::printPtr(os, pstruct);
266+
printPtr(os, pstruct);
270267
} break;
271268
%endfor
272269
default:
273270
os << "unknown enumerator";
274271
break;
275272
}
276273
}
277-
} // namespace ${x}_print
278274
%endif
279275
%if th.type_traits.is_flags(obj['name']):
280-
namespace ${x}_print {
281276

282277
template<>
283278
inline void printFlag<${th.make_enum_name(n, tags, obj)}>(std::ostream &os, uint32_t flag) {
@@ -310,7 +305,6 @@ inline void printFlag<${th.make_enum_name(n, tags, obj)}>(std::ostream &os, uint
310305
os << "0";
311306
}
312307
}
313-
} // namespace ${x}_print
314308
%endif
315309
## STRUCT/UNION ###############################################################
316310
%elif re.match(r"struct", obj['type']):
@@ -332,7 +326,7 @@ inline std::ostream &operator<<(std::ostream &os, const ${obj['type']} ${th.make
332326
}
333327
%elif re.match(r"union", obj['type']) and obj['name']:
334328
<% tag = findUnionTag(obj) %>
335-
inline void ${x}_print::printUnion(
329+
inline void printUnion(
336330
std::ostream &os,
337331
const ${obj['type']} ${th.make_type_name(n, tags, obj)} params,
338332
const ${tag['type']} ${th.make_type_name(n, tags, tag)} tag
@@ -381,8 +375,6 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
381375
%endfor
382376
%endfor
383377

384-
namespace ${x}_print {
385-
386378
template <typename T> inline void printPtr(std::ostream &os, const T *ptr) {
387379
if (ptr == nullptr) {
388380
os << "nullptr";

source/common/logger/ur_sinks.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
#include "ur_filesystem_resolved.hpp"
1515
#include "ur_level.hpp"
16+
#include "ur_print.hpp"
1617

1718
namespace logger {
19+
using namespace ur_print;
1820

1921
class Sink {
2022
public:

0 commit comments

Comments
 (0)