Skip to content

Commit eff8063

Browse files
committed
Rename params stringifier
1 parent 00143fc commit eff8063

File tree

8 files changed

+1117
-1143
lines changed

8 files changed

+1117
-1143
lines changed

scripts/generate_code.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ def _mako_tracing_layer_cpp(path, namespace, tags, version, specs, meta):
278278
"""
279279
generates c/c++ files from the specification documents
280280
"""
281-
def _mako_params_hpp(path, namespace, tags, version, specs, meta):
282-
template = "params.hpp.mako"
281+
def _mako_print_hpp(path, namespace, tags, version, specs, meta):
282+
template = "print.hpp.mako"
283283
fin = os.path.join(templates_dir, template)
284284

285-
name = "%s_params"%(namespace)
285+
name = "%s_print"%(namespace)
286286
filename = "%s.hpp"%(name)
287287
fout = os.path.join(path, filename)
288288

@@ -361,6 +361,6 @@ def generate_common(path, section, namespace, tags, version, specs, meta):
361361
os.makedirs(layer_dstpath, exist_ok=True)
362362

363363
loc = 0
364-
loc += _mako_params_hpp(layer_dstpath, namespace, tags, version, specs, meta)
364+
loc += _mako_print_hpp(layer_dstpath, namespace, tags, version, specs, meta)
365365
print("COMMON Generated %s lines of code.\n"%loc)
366366

scripts/templates/params.hpp.mako renamed to scripts/templates/print.hpp.mako

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ from templates import helper as th
1818
* @file ${name}.hpp
1919
*
2020
*/
21-
#ifndef ${X}_PARAMS_HPP
22-
#define ${X}_PARAMS_HPP 1
21+
#ifndef ${X}_PRINT_HPP
22+
#define ${X}_PRINT_HPP 1
2323

2424
#include "${x}_api.h"
2525
#include <ostream>
2626
#include <bitset>
2727

2828
<%def name="member(iname, itype, loop)">
2929
%if iname == "pNext":
30-
${x}_params::serializeStruct(os, ${caller.body()});
30+
${x}_print::printStruct(os, ${caller.body()});
3131
%elif th.type_traits.is_flags(itype):
32-
${x}_params::serializeFlag<${th.type_traits.get_flag_type(itype)}>(os, ${caller.body()});
32+
${x}_print::printFlag<${th.type_traits.get_flag_type(itype)}>(os, ${caller.body()});
3333
%elif not loop and th.type_traits.is_pointer(itype):
34-
${x}_params::serializePtr(os, ${caller.body()});
34+
${x}_print::printPtr(os, ${caller.body()});
3535
%elif loop and th.type_traits.is_pointer_to_pointer(itype):
36-
${x}_params::serializePtr(os, ${caller.body()});
36+
${x}_print::printPtr(os, ${caller.body()});
3737
%elif th.type_traits.is_handle(itype):
38-
${x}_params::serializePtr(os, ${caller.body()});
38+
${x}_print::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}_params::serializeUnion(os, ${deref}(params${access}${item['name']}), params${access}${th.param_traits.tagged_member(item)});
86+
${x}_print::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}_params::serializeTagged(os, ${deref}(params${access}${pname}), ${deref}(params${access}${prefix}${typename}), ${deref}(params${access}${prefix}${typename_size}));
100+
${x}_print::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)">
@@ -106,7 +106,7 @@ def findMemberType(_item):
106106
%endif
107107
</%def>
108108

109-
namespace ${x}_params {
109+
namespace ${x}_print {
110110
template <typename T> struct is_handle : std::false_type {};
111111
%for spec in specs:
112112
%for obj in spec['objects']:
@@ -117,24 +117,24 @@ template <> struct is_handle<${th.make_type_name(n, tags, obj)}> : std::true_typ
117117
%endfor
118118
template <typename T>
119119
inline constexpr bool is_handle_v = is_handle<T>::value;
120-
template <typename T> inline void serializePtr(std::ostream &os, const T *ptr);
121-
template <typename T> inline void serializeFlag(std::ostream &os, uint32_t flag);
122-
template <typename T> inline void serializeTagged(std::ostream &os, const void *ptr, T value, size_t size);
120+
template <typename T> inline void printPtr(std::ostream &os, const T *ptr);
121+
template <typename T> inline void printFlag(std::ostream &os, uint32_t flag);
122+
template <typename T> inline void printTagged(std::ostream &os, const void *ptr, T value, size_t size);
123123

124124
%for spec in specs:
125125
%for obj in spec['objects']:
126126
## ENUM #######################################################################
127127
%if re.match(r"enum", obj['type']):
128128
%if obj.get('typed_etors', False) is True:
129-
template <> inline void serializeTagged(std::ostream &os, const void *ptr, ${th.make_enum_name(n, tags, obj)} value, size_t size);
129+
template <> inline void printTagged(std::ostream &os, const void *ptr, ${th.make_enum_name(n, tags, obj)} value, size_t size);
130130
%elif "structure_type" in obj['name']:
131-
inline void serializeStruct(std::ostream &os, const void *ptr);
131+
inline void printStruct(std::ostream &os, const void *ptr);
132132
%endif
133133
%endif
134134

135135
%if re.match(r"union", obj['type']) and obj['name']:
136136
<% tag = [_obj for _s in specs for _obj in _s['objects'] if _obj['name'] == obj['tag']][0] %>
137-
inline void serializeUnion(
137+
inline void printUnion(
138138
std::ostream &os,
139139
const ${obj['type']} ${th.make_type_name(n, tags, obj)} params,
140140
const ${tag['type']} ${th.make_type_name(n, tags, tag)} tag
@@ -143,11 +143,11 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
143143

144144

145145
%if th.type_traits.is_flags(obj['name']):
146-
template<> inline void serializeFlag<${th.make_enum_name(n, tags, obj)}>(std::ostream &os, uint32_t flag);
146+
template<> inline void printFlag<${th.make_enum_name(n, tags, obj)}>(std::ostream &os, uint32_t flag);
147147
%endif
148148
%endfor # obj in spec['objects']
149149
%endfor
150-
} // namespace ${x}_params
150+
} // namespace ${x}_print
151151

152152
%for spec in specs:
153153
%for obj in spec['objects']:
@@ -188,11 +188,11 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
188188
}
189189
%endif
190190
%if obj.get('typed_etors', False) is True:
191-
namespace ${x}_params {
191+
namespace ${x}_print {
192192
template <>
193-
inline void serializeTagged(std::ostream &os, const void *ptr, ${th.make_enum_name(n, tags, obj)} value, size_t size) {
193+
inline void printTagged(std::ostream &os, const void *ptr, ${th.make_enum_name(n, tags, obj)} value, size_t size) {
194194
if (ptr == NULL) {
195-
serializePtr(os, ptr);
195+
printPtr(os, ptr);
196196
return;
197197
}
198198

@@ -211,7 +211,7 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
211211
const ${atype} *tptr = (const ${atype} *)ptr;
212212
%endif
213213
%if "char" in atype: ## print char* arrays as simple NULL-terminated strings
214-
serializePtr(os, tptr);
214+
printPtr(os, tptr);
215215
%else:
216216
os << "{";
217217
size_t nelems = size / sizeof(${atype});
@@ -250,10 +250,10 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
250250
}
251251
}
252252
%elif "structure_type" in obj['name']:
253-
namespace ${x}_params {
254-
inline void serializeStruct(std::ostream &os, const void *ptr) {
253+
namespace ${x}_print {
254+
inline void printStruct(std::ostream &os, const void *ptr) {
255255
if (ptr == NULL) {
256-
${x}_params::serializePtr(os, ptr);
256+
${x}_print::printPtr(os, ptr);
257257
return;
258258
}
259259

@@ -266,21 +266,21 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
266266
%>
267267
case ${ename}: {
268268
const ${th.subt(n, tags, item['desc'])} *pstruct = (const ${th.subt(n, tags, item['desc'])} *)ptr;
269-
${x}_params::serializePtr(os, pstruct);
269+
${x}_print::printPtr(os, pstruct);
270270
} break;
271271
%endfor
272272
default:
273273
os << "unknown enumerator";
274274
break;
275275
}
276276
}
277-
} // namespace ${x}_params
277+
} // namespace ${x}_print
278278
%endif
279279
%if th.type_traits.is_flags(obj['name']):
280-
namespace ${x}_params {
280+
namespace ${x}_print {
281281

282282
template<>
283-
inline void serializeFlag<${th.make_enum_name(n, tags, obj)}>(std::ostream &os, uint32_t flag) {
283+
inline void printFlag<${th.make_enum_name(n, tags, obj)}>(std::ostream &os, uint32_t flag) {
284284
uint32_t val = flag;
285285
bool first = true;
286286
%for n, item in enumerate(obj['etors']):
@@ -310,7 +310,7 @@ inline void serializeFlag<${th.make_enum_name(n, tags, obj)}>(std::ostream &os,
310310
os << "0";
311311
}
312312
}
313-
} // namespace ${x}_params
313+
} // namespace ${x}_print
314314
%endif
315315
## STRUCT/UNION ###############################################################
316316
%elif re.match(r"struct", obj['type']):
@@ -332,7 +332,7 @@ inline std::ostream &operator<<(std::ostream &os, const ${obj['type']} ${th.make
332332
}
333333
%elif re.match(r"union", obj['type']) and obj['name']:
334334
<% tag = findUnionTag(obj) %>
335-
inline void ${x}_params::serializeUnion(
335+
inline void ${x}_print::printUnion(
336336
std::ostream &os,
337337
const ${obj['type']} ${th.make_type_name(n, tags, obj)} params,
338338
const ${tag['type']} ${th.make_type_name(n, tags, tag)} tag
@@ -381,14 +381,14 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct
381381
%endfor
382382
%endfor
383383

384-
namespace ${x}_params {
384+
namespace ${x}_print {
385385

386-
template <typename T> inline void serializePtr(std::ostream &os, const T *ptr) {
386+
template <typename T> inline void printPtr(std::ostream &os, const T *ptr) {
387387
if (ptr == nullptr) {
388388
os << "nullptr";
389389
} else if constexpr (std::is_pointer_v<T>) {
390390
os << (const void *)(ptr) << " (";
391-
serializePtr(os, *ptr);
391+
printPtr(os, *ptr);
392392
os << ")";
393393
} else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
394394
os << (const void *)ptr;
@@ -403,7 +403,7 @@ template <typename T> inline void serializePtr(std::ostream &os, const T *ptr) {
403403
}
404404
}
405405

406-
inline int serializeFunctionParams(std::ostream &os, uint32_t function, const void *params) {
406+
inline int printFunctionParams(std::ostream &os, uint32_t function, const void *params) {
407407
switch((enum ${x}_function_t)function) {
408408
%for tbl in th.get_pfncbtables(specs, meta, n, tags):
409409
%for obj in tbl['functions']:
@@ -416,6 +416,6 @@ inline int serializeFunctionParams(std::ostream &os, uint32_t function, const vo
416416
}
417417
return 0;
418418
}
419-
} // namespace ur_params
419+
} // namespace ur_print
420420

421-
#endif /* ${X}_PARAMS_HPP */
421+
#endif /* ${X}_PRINT_HPP */

0 commit comments

Comments
 (0)