From f2c255560d4ac83bdcb87c2d1a75a95ec540508c Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 10 Mar 2024 19:27:46 +0100 Subject: codec,tools: Fixed Header generation --- modules/tools/c++/c_gen_iface.hpp | 218 ++++++++++++++++++++++++++++++++++---- 1 file changed, 195 insertions(+), 23 deletions(-) (limited to 'modules/tools/c++/c_gen_iface.hpp') diff --git a/modules/tools/c++/c_gen_iface.hpp b/modules/tools/c++/c_gen_iface.hpp index 2dfa36f..7c26f80 100644 --- a/modules/tools/c++/c_gen_iface.hpp +++ b/modules/tools/c++/c_gen_iface.hpp @@ -151,6 +151,7 @@ struct lang_bind_helper { } }; + template struct lang_bind, binding::C> { using Schema = schema::Primitive; @@ -199,9 +200,84 @@ struct lang_bind, binding::C> { } }; +template +struct lang_bind, binding::C> { + using Schema = schema::Array; + + static_assert(is_primitive::value, "Currently only primitive type arrays are supported"); + + static error_or generate(buffer& buff, const language_binding_config& cfg, language_binding_state& state){ + constexpr uint64_t hash = schema_hash::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(emp.second){ + { + auto eov = lang_bind::generate(buff, cfg, state); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind::generate(buff, cfg, state); + if(eov.is_error()){ + return eov; + } + } + + { + auto eov = lang_bind_helper::append_string(buff, "struct "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(buff, cfg.prefix, hash); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, " {\n\t"); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(buff, cfg.prefix, schema_hash::apply()); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, "* data;\n\t"); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(buff, cfg.prefix, schema_hash::apply()); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, " length;\n};\n"); + if(eov.is_error()){ + return eov; + } + } + } + + return void_t{}; + } +}; + template struct lang_bind, binding::C> { - static error_or generate(buffer& buff, const language_binding_config& cfg, language_binding_state& state){ + static error_or append_function_def(buffer& buff, + + static error_or generate(buffer& buff, buffer& src, const language_binding_config& cfg, language_binding_state& state, const std::string_view& f_name){ constexpr uint64_t input_hash = schema_hash::apply(); constexpr uint64_t output_hash = schema_hash::apply(); @@ -217,26 +293,66 @@ struct lang_bind, binding::C> { return eov; } } - - return void_t{}; - } -}; - -template -struct lang_bind, binding::C> { - template - static error_or generate_element(buffer& buff, const language_binding_config& cfg, language_binding_state& state){ - using Member = typename parameter_pack_type::type; - using MValue = typename Member::ValueType; - static constexpr string_literal MKey = Member::KeyLiteral; - { - auto eov = lang_bind::generate(buff, cfg, state); + auto eov = lang_bind_helper::append_string(buff, "typedef "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(buff, cfg.prefix, schema_hash::apply()); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, " "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, cfg.prefix); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, "_"); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, f_name); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, "_input_t;\n"); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, "typedef "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(buff, cfg.prefix, schema_hash::apply()); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, " "); if(eov.is_error()){ return eov; } } - { auto eov = lang_bind_helper::append_string(buff, cfg.prefix); if(eov.is_error()){ @@ -250,31 +366,86 @@ struct lang_bind, binding::C> { } } { - auto eov = lang_bind_helper::append_string(buff, MKey.view()); + auto eov = lang_bind_helper::append_string(buff, f_name); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, "_output_t;\n"); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, "int "); if(eov.is_error()){ return eov; } } { - auto eov = lang_bind_helper::append_string(buff, "("); + auto eov = lang_bind_helper::append_string(buff, cfg.prefix); if(eov.is_error()){ return eov; } } { - auto eov = lang_bind_helper::append_hashed_type(buff, cfg.prefix, schema_hash::apply()); + auto eov = lang_bind_helper::append_string(buff, "_"); if(eov.is_error()){ return eov; } } { - auto eov = lang_bind_helper::append_string(buff, ","); + auto eov = lang_bind_helper::append_string(buff, f_name); if(eov.is_error()){ return eov; } } { - auto eov = lang_bind_helper::append_string(buff, ");"); + auto eov = lang_bind_helper::append_string(buff, "( const "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(buff, cfg.prefix, schema_hash::apply()); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, "* input, "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(buff, cfg.prefix, schema_hash::apply()); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(buff, "* output);\n\n"); + if(eov.is_error()){ + return eov; + } + } + + return void_t{}; + } +}; + +template +struct lang_bind, binding::C> { + template + static error_or generate_element(buffer& buff, const language_binding_config& cfg, language_binding_state& state){ + using Member = typename parameter_pack_type::type; + using MValue = typename Member::ValueType; + static constexpr string_literal MKey = Member::KeyLiteral; + + { + auto eov = lang_bind::generate(buff, cfg, state, MKey.view()); if(eov.is_error()){ return eov; } @@ -290,6 +461,7 @@ struct lang_bind, binding::C> { if(cfg.prefix.size() == 0){ return make_error("C interfaces need a prefix."); } + language_binding_state state; if constexpr (sizeof...(M) > 0){ @@ -308,8 +480,8 @@ struct language_binding { template struct language_binding { - static error_or generate(buffer& buff, const language_binding_config& cfg){ - return impl::lang_bind::generate(buff, cfg); + static error_or generate(buffer& buff, buffer& src, const language_binding_config& cfg){ + return impl::lang_bind::generate(buff, src, cfg); } }; } -- cgit v1.2.3