From 3ccab503850f87e8f6c68bc4fe4487312a871738 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 27 Mar 2024 17:22:29 +0100 Subject: tools: Added primitive translation to cpp for inputs --- modules/tools/c++/c_gen_iface.hpp | 111 ++++++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/tools/c++/c_gen_iface.hpp b/modules/tools/c++/c_gen_iface.hpp index e70479d..ebbf5f7 100644 --- a/modules/tools/c++/c_gen_iface.hpp +++ b/modules/tools/c++/c_gen_iface.hpp @@ -269,7 +269,7 @@ struct lang_bind, 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){ + if(emp.second) { /** * We want this id to access the vector */ @@ -312,6 +312,77 @@ struct lang_bind, binding::SyncC> { return eov; } } + /** + * Translation in source + */ + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "namespace {\nsaw::error_or "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(tpe.at(id).source, cfg.prefix, hash); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "_translate_c_to_cpp ( "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, " const "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, hash_type_str); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "* c_input, saw::data<"); + if(eov.is_error()){ + return eov; + } + } + { + std::stringstream ss; + try{ + { + schema_stringify::apply(ss); + auto eov = lang_bind_helper::append_string(tpe.at(id).source, ss.str()); + if(eov.is_error()){ + return eov; + } + } + }catch(const std::exception&){ + return make_error(); + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, ">& cpp_output) {\n\t"); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "cpp_output.set(*c_input);\n"); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "\n\treturn void_t{};\n}\n}\n"); + if(eov.is_error()){ + return eov; + } + } } } @@ -733,6 +804,24 @@ struct lang_bind, binding::SyncC> { return eov; } } + { + auto eov = lang_bind_helper::append_string(tpe.at(f_id).source, "\t{\n\t\tauto eov = "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(tpe.at(f_id).source, cfg.prefix, schema_hash::apply()); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(f_id).source, "_translate_c_to_cpp(c_input, cpp_input_root);\n\t\tif(eov.is_error()) return eov.get_error().get_code();\n\t}\n"); + if(eov.is_error()){ + return eov; + } + } /** * Call the c++ implementation */ @@ -885,15 +974,13 @@ struct lang_bind, binding::SyncC> { static error_or guarantee_element(const language_binding_config& cfg, language_binding_state& state){ using Member = typename parameter_pack_type::type; using MValue = typename Member::ValueType; + /** + * Guarantee + */ { - /** - * Guarantee - */ - { - auto eov = lang_bind::guarantee(cfg, state); - if(eov.is_error()){ - return eov; - } + auto eov = lang_bind::guarantee(cfg, state); + if(eov.is_error()){ + return eov; } } @@ -928,6 +1015,12 @@ struct lang_bind, binding::SyncC> { } f_id = eoid.get_value(); } + { + auto eov = lang_bind::generate(cfg, state, MKey.view(), f_id); + if(eov.is_error()){ + return eov; + } + } if constexpr ((i+1) < sizeof...(M) ){ return generate_element(cfg, state); -- cgit v1.2.3