diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-03-27 17:22:29 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-03-27 17:22:29 +0100 |
commit | 3ccab503850f87e8f6c68bc4fe4487312a871738 (patch) | |
tree | 8b9f1c9df2985594fd0f97043321ad139788b075 /modules/tools | |
parent | 558c6b333f96dc4953337fa9e290b36fbbce5bc3 (diff) |
tools: Added primitive translation to cpp for inputs
Diffstat (limited to 'modules/tools')
-rw-r--r-- | modules/tools/c++/c_gen_iface.hpp | 111 |
1 files changed, 102 insertions, 9 deletions
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<schema::Primitive<T,L>, 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<schema::Primitive<T,L>, binding::SyncC> { return eov; } } + /** + * Translation in source + */ + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "namespace {\nsaw::error_or<void> "); + 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<Schema>::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<err::out_of_memory>(); + } + } + { + 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<schema::Function<Input, Output>, 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<Input>::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<schema::Interface<M...>, binding::SyncC> { static error_or<void> guarantee_element(const language_binding_config& cfg, language_binding_state& state){ using Member = typename parameter_pack_type<i, M...>::type; using MValue = typename Member::ValueType; + /** + * Guarantee + */ { - /** - * Guarantee - */ - { - auto eov = lang_bind<MValue, binding::SyncC>::guarantee(cfg, state); - if(eov.is_error()){ - return eov; - } + auto eov = lang_bind<MValue, binding::SyncC>::guarantee(cfg, state); + if(eov.is_error()){ + return eov; } } @@ -928,6 +1015,12 @@ struct lang_bind<schema::Interface<M...>, binding::SyncC> { } f_id = eoid.get_value(); } + { + auto eov = lang_bind<MValue, binding::SyncC>::generate(cfg, state, MKey.view(), f_id); + if(eov.is_error()){ + return eov; + } + } if constexpr ((i+1) < sizeof...(M) ){ return generate_element<i+1>(cfg, state); |