summaryrefslogtreecommitdiff
path: root/modules/tools
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-03-25 17:19:32 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-03-25 17:19:32 +0100
commitd765dfafc995e8f722847fb1d6ab189714af8987 (patch)
tree5c5cbc356c2721045c95262155bf1d2ac98cd347 /modules/tools
parentde935efe4f102aca47d67a43d2d9f73fdc87fd77 (diff)
tools: Work on struct generation
Diffstat (limited to 'modules/tools')
-rw-r--r--modules/tools/c++/c_gen_iface.hpp104
1 files changed, 97 insertions, 7 deletions
diff --git a/modules/tools/c++/c_gen_iface.hpp b/modules/tools/c++/c_gen_iface.hpp
index 1610553..7ee4613 100644
--- a/modules/tools/c++/c_gen_iface.hpp
+++ b/modules/tools/c++/c_gen_iface.hpp
@@ -229,7 +229,7 @@ struct lang_bind<schema::Primitive<T,L>, binding::SyncC> {
return void_t{};
}
- static error_or<void> generate(buffer& buff, buffer& src, const language_binding_config& cfg, language_binding_state& state){
+ static error_or<void> generate(buffer& head, buffer& src, const language_binding_config& cfg, language_binding_state& state){
constexpr uint64_t hash = schema_hash<Schema>::apply();
{
@@ -237,31 +237,31 @@ struct lang_bind<schema::Primitive<T,L>, binding::SyncC> {
auto emp = state.hashes.emplace(std::make_pair(hash, hash_type_str));
if(emp.second){
{
- auto eov = lang_bind_helper::append_string(buff, "typedef ");
+ auto eov = lang_bind_helper::append_string(head, "typedef ");
if(eov.is_error()){
return eov;
}
}
{
- auto eov = lang_bind_helper::append_string(buff, c_primitive_string<Schema>::value.view());
+ auto eov = lang_bind_helper::append_string(head, c_primitive_string<Schema>::value.view());
if(eov.is_error()){
return eov;
}
}
{
- auto eov = lang_bind_helper::append_string(buff, " ");
+ auto eov = lang_bind_helper::append_string(head, " ");
if(eov.is_error()){
return eov;
}
}
{
- auto eov = lang_bind_helper::append_string(buff, hash_type_str);
+ auto eov = lang_bind_helper::append_string(head, hash_type_str);
if(eov.is_error()){
return eov;
}
}
{
- auto eov = lang_bind_helper::append_string(buff, ";\n");
+ auto eov = lang_bind_helper::append_string(head, ";\n");
if(eov.is_error()){
return eov;
}
@@ -273,6 +273,87 @@ struct lang_bind<schema::Primitive<T,L>, binding::SyncC> {
}
};
+template<typename... V, string_literal... K>
+struct lang_bind<schema::Struct<schema::Member<V,K>...>, binding::SyncC> {
+ using Schema = schema::Struct<schema::Member<V,K>...>;
+
+ template<uint64_t i>
+ static error_or<void> generate_ele(buffer& head, buffer& src, const language_binding_config& cfg, language_binding_state& state){
+ using MT = typename parameter_pack_type<i,V...>::type;
+ constexpr uint64_t hash = schema_hash<MT>::apply();
+ std::string hash_type_str = cfg.prefix + "_" + std::to_string(hash) + "_t";
+ auto emp = state.hashes.emplace(std::make_pair(hash, hash_type_str));
+ /**
+ * If successful insertion did happen that means we have no struct def yet.
+ */
+ if (emp.second) {
+ {
+ auto eov = lang_bind_helper::append_hashed_type(head, cfg.prefix, hash);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = lang_bind_helper::append_string(head, "};\n");
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ }
+
+ if constexpr ( (i+1) < sizeof...(V) ){
+ return generate_ele<i+1u>(head, src, cfg, state);
+ }
+ return void_t{};
+ }
+
+ static error_or<void> generate(buffer& head, buffer& src, const language_binding_config& cfg, language_binding_state& state){
+ constexpr uint64_t hash = schema_hash<Schema>::apply();
+
+ std::string hash_type_str = cfg.prefix + "_" + std::to_string(hash) + "_t";
+ auto emp = state.hashes.emplace(std::make_pair(hash, hash_type_str));
+
+ /**
+ * If successful insertion did happen that means we have no struct def yet.
+ */
+ if(emp.second){
+ /**
+ * Generate struct type
+ */
+ {
+ auto eov = lang_bind_helper::append_string(head, "struct ");
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = lang_bind_helper::append_hashed_type(head, cfg.prefix, hash);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = lang_bind_helper::append_string(head, " {\n\t");
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ if constexpr ( sizeof...(V) > 0 ) {
+ auto eov = generate_ele<0>(head, src, cfg, state);
+ }
+ {
+ auto eov = lang_bind_helper::append_string(head, "\n};\n");
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+
+ }
+
+ return void_t{};
+ }
+};
+
template<typename T, uint64_t D>
struct lang_bind<schema::Array<T,D>, binding::SyncC> {
using Schema = schema::Array<T,D>;
@@ -293,19 +374,28 @@ struct lang_bind<schema::Array<T,D>, binding::SyncC> {
std::string hash_type_str = cfg.prefix + "_" + std::to_string(hash) + "_t";
auto emp = state.hashes.emplace(std::make_pair(hash, hash_type_str));
if(emp.second){
+ /**
+ * Guarante existance of length type
+ */
{
auto eov = lang_bind<schema::UInt64, binding::SyncC>::generate(buff, src, cfg, state);
if(eov.is_error()){
return eov;
}
}
+ /**
+ * Guarante existance of inner type
+ */
{
auto eov = lang_bind<T, binding::SyncC>::generate(buff, src, cfg, state);
if(eov.is_error()){
return eov;
}
}
-
+
+ /**
+ * Generate struct type
+ */
{
auto eov = lang_bind_helper::append_string(buff, "struct ");
if(eov.is_error()){