From d3747f7c4203146aea0ab2f130aa1100988c71c0 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Mon, 17 Oct 2022 15:47:15 +0530 Subject: [PATCH] CPP: Implement list --- src/libasr/codegen/asr_to_cpp.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_cpp.cpp b/src/libasr/codegen/asr_to_cpp.cpp index efd7115179..bbd0f0f614 100644 --- a/src/libasr/codegen/asr_to_cpp.cpp +++ b/src/libasr/codegen/asr_to_cpp.cpp @@ -341,6 +341,12 @@ class ASRToCPPVisitor : public BaseCCPPVisitor } else { sub = format_type(dims, "struct", v.m_name, use_ref, dummy); } + } else if (ASR::is_a(*v.m_type)) { + ASR::List_t* t = ASR::down_cast(v.m_type); + std::string list_element_type = get_c_type_from_ttype_t(t->m_type); + std::string list_type_c = list_api->get_list_type(t, list_element_type); + sub = format_type("", list_type_c, v.m_name, + false, false); } else { diag.codegen_error_label("Type number '" + std::to_string(v.m_type->type) @@ -369,6 +375,9 @@ class ASRToCPPVisitor : public BaseCCPPVisitor indentation_level = 0; indentation_spaces = 4; + list_api->set_indentation(indentation_level, indentation_spaces); + list_api->set_global_scope(global_scope); + std::string headers = R"(#include #include @@ -455,7 +464,16 @@ Kokkos::View from_std_vector(const std::vector &v) } } - src = headers + array_types_decls + unit_src; + if (list_api->get_list_func_decls().size() > 0) { + array_types_decls += "\n" + list_api->get_list_func_decls() + "\n"; + } + + std::string list_funcs_defined = ""; + if (list_api->get_generated_code().size() > 0) { + list_funcs_defined = "\n" + list_api->get_generated_code() + "\n"; + } + + src = headers + array_types_decls + unit_src + list_funcs_defined; } void visit_Program(const ASR::Program_t &x) {