@@ -78,8 +78,7 @@ class BaseCCPPVisitor : public ASR::BaseVisitor<Struct>
78
78
size_t template_number;
79
79
std::string from_std_vector_helper;
80
80
81
- std::unique_ptr<CCPPList> list_api;
82
- std::unique_ptr<CCPPTuple> tuple_api;
81
+ std::unique_ptr<CCPPDSUtils> c_ds_api;
83
82
std::string const_name;
84
83
size_t const_list_count;
85
84
@@ -92,15 +91,13 @@ class BaseCCPPVisitor : public ASR::BaseVisitor<Struct>
92
91
platform{platform},
93
92
gen_stdstring{gen_stdstring}, gen_stdcomplex{gen_stdcomplex},
94
93
is_c{is_c}, global_scope{nullptr }, lower_bound{default_lower_bound},
95
- template_number{0 }, list_api {std::make_unique<CCPPList >()},
96
- tuple_api{std::make_unique<CCPPTuple>()}, const_name{" constname" },
94
+ template_number{0 }, c_ds_api {std::make_unique<CCPPDSUtils >()},
95
+ const_name{" constname" },
97
96
const_list_count{0 }, is_string_concat_present{false } {
98
97
if ( is_c ) {
99
- list_api->set_deepcopy_function (&CUtils::deepcopy);
100
- tuple_api->set_deepcopy_function (&CUtils::deepcopy);
98
+ c_ds_api->set_deepcopy_function (&CUtils::deepcopy);
101
99
} else {
102
- list_api->set_deepcopy_function (&CPPUtils::deepcopy);
103
- tuple_api->set_deepcopy_function (&CPPUtils::deepcopy);
100
+ c_ds_api->set_deepcopy_function (&CPPUtils::deepcopy);
104
101
}
105
102
}
106
103
@@ -112,10 +109,8 @@ class BaseCCPPVisitor : public ASR::BaseVisitor<Struct>
112
109
std::string unit_src = " " ;
113
110
indentation_level = 0 ;
114
111
indentation_spaces = 4 ;
115
- list_api->set_indentation (indentation_level + 1 , indentation_spaces);
116
- list_api->set_global_scope (global_scope);
117
- tuple_api->set_indentation (indentation_level + 1 , indentation_spaces);
118
- tuple_api->set_global_scope (global_scope);
112
+ c_ds_api->set_indentation (indentation_level + 1 , indentation_spaces);
113
+ c_ds_api->set_global_scope (global_scope);
119
114
120
115
std::string headers =
121
116
R"( #include <stdio.h>
@@ -341,11 +336,10 @@ R"(#include <stdio.h>
341
336
sub = " void* " ;
342
337
} else if (ASR::is_a<ASR::List_t>(*return_var->m_type )) {
343
338
ASR::List_t* list_type = ASR::down_cast<ASR::List_t>(return_var->m_type );
344
- std::string list_element_type = CUtils::get_c_type_from_ttype_t (list_type->m_type );
345
- sub = list_api->get_list_type (list_type, list_element_type) + " " ;
339
+ sub = c_ds_api->get_list_type (list_type) + " " ;
346
340
} else if (ASR::is_a<ASR::Tuple_t>(*return_var->m_type )) {
347
341
ASR::Tuple_t* tup_type = ASR::down_cast<ASR::Tuple_t>(return_var->m_type );
348
- sub = tuple_api ->get_tuple_type (tup_type) + " " ;
342
+ sub = c_ds_api ->get_tuple_type (tup_type) + " " ;
349
343
} else if (ASR::is_a<ASR::Const_t>(*return_var->m_type )) {
350
344
ASR::Const_t* const_type = ASR::down_cast<ASR::Const_t>(return_var->m_type );
351
345
std::string const_type_str = CUtils::get_c_type_from_ttype_t (const_type->m_type );
@@ -529,13 +523,12 @@ R"(#include <stdio.h>
529
523
last_expr_precedence = 2 ;
530
524
if ( ASR::is_a<ASR::List_t>(*x.m_type ) ) {
531
525
ASR::List_t* list_type = ASR::down_cast<ASR::List_t>(x.m_type );
532
- std::string list_element_type = CUtils::get_c_type_from_ttype_t (list_type->m_type );
533
526
const_name += std::to_string (const_list_count);
534
527
const_list_count += 1 ;
535
528
const_name = current_scope->get_unique_name (const_name);
536
529
std::string indent (indentation_level*indentation_spaces, ' ' );
537
- current_body += indent + list_api ->get_list_type (list_type,
538
- list_element_type) + " " + const_name + " = " + src + " ;\n " ;
530
+ current_body += indent + c_ds_api ->get_list_type (list_type) + " " +
531
+ const_name + " = " + src + " ;\n " ;
539
532
src = const_name;
540
533
}
541
534
}
@@ -646,7 +639,7 @@ R"(#include <stdio.h>
646
639
} else if (ASR::is_a<ASR::FunctionCall_t>(*x.m_value )) {
647
640
self ().visit_FunctionCall (*ASR::down_cast<ASR::FunctionCall_t>(x.m_value ));
648
641
ASR::Tuple_t* t = ASR::down_cast<ASR::Tuple_t>(tup_c->m_type );
649
- std::string tuple_type_c = tuple_api ->get_tuple_type (t);
642
+ std::string tuple_type_c = c_ds_api ->get_tuple_type (t);
650
643
const_name += std::to_string (const_list_count);
651
644
const_list_count += 1 ;
652
645
const_name = current_scope->get_unique_name (const_name);
@@ -687,7 +680,7 @@ R"(#include <stdio.h>
687
680
}
688
681
if ( is_target_list && is_value_list ) {
689
682
ASR::List_t* list_target = ASR::down_cast<ASR::List_t>(ASRUtils::expr_type (x.m_target ));
690
- std::string list_dc_func = list_api ->get_list_deepcopy_func (list_target);
683
+ std::string list_dc_func = c_ds_api ->get_list_deepcopy_func (list_target);
691
684
if ( ASR::is_a<ASR::ListConstant_t>(*x.m_value ) ) {
692
685
src += value;
693
686
src += indent + list_dc_func + " (&" + const_name + " , &" + target + " );\n\n " ;
@@ -773,11 +766,10 @@ R"(#include <stdio.h>
773
766
const_list_count += 1 ;
774
767
const_name = current_scope->get_unique_name (const_name);
775
768
ASR::List_t* t = ASR::down_cast<ASR::List_t>(x.m_type );
776
- std::string list_element_type = CUtils::get_c_type_from_ttype_t (t->m_type );
777
- std::string list_type_c = list_api->get_list_type (t, list_element_type);
769
+ std::string list_type_c = c_ds_api->get_list_type (t);
778
770
std::string src_tmp = " " ;
779
771
src_tmp += indent + list_type_c + " " + const_name + " ;\n " ;
780
- std::string list_init_func = list_api ->get_list_init_func (t);
772
+ std::string list_init_func = c_ds_api ->get_list_init_func (t);
781
773
src_tmp += indent + list_init_func + " (&" + const_name + " , " +
782
774
std::to_string (x.n_args ) + " );\n " ;
783
775
for ( size_t i = 0 ; i < x.n_args ; i++ ) {
@@ -802,7 +794,7 @@ R"(#include <stdio.h>
802
794
const_list_count += 1 ;
803
795
const_name = current_scope->get_unique_name (const_name);
804
796
ASR::Tuple_t* t = ASR::down_cast<ASR::Tuple_t>(x.m_type );
805
- std::string tuple_type_c = tuple_api ->get_tuple_type (t);
797
+ std::string tuple_type_c = c_ds_api ->get_tuple_type (t);
806
798
std::string src_tmp = " " ;
807
799
src_tmp += indent + tuple_type_c + " " + const_name + " ;\n " ;
808
800
for (size_t i = 0 ; i < x.n_elements ; i++) {
@@ -824,7 +816,7 @@ R"(#include <stdio.h>
824
816
void visit_ListAppend (const ASR::ListAppend_t& x) {
825
817
ASR::ttype_t * t_ttype = ASRUtils::expr_type (x.m_a );
826
818
ASR::List_t* t = ASR::down_cast<ASR::List_t>(t_ttype);
827
- std::string list_append_func = list_api ->get_list_append_func (t);
819
+ std::string list_append_func = c_ds_api ->get_list_append_func (t);
828
820
self ().visit_expr (*x.m_a );
829
821
std::string list_var = std::move (src);
830
822
self ().visit_expr (*x.m_ele );
@@ -835,7 +827,7 @@ R"(#include <stdio.h>
835
827
836
828
void visit_ListConcat (const ASR::ListConcat_t& x) {
837
829
ASR::List_t* t = ASR::down_cast<ASR::List_t>(x.m_type );
838
- std::string list_concat_func = list_api ->get_list_concat_func (t);
830
+ std::string list_concat_func = c_ds_api ->get_list_concat_func (t);
839
831
self ().visit_expr (*x.m_left );
840
832
std::string left = std::move (src);
841
833
if (!ASR::is_a<ASR::ListConcat_t>(*x.m_left )) {
@@ -853,7 +845,7 @@ R"(#include <stdio.h>
853
845
void visit_ListClear (const ASR::ListClear_t& x) {
854
846
ASR::ttype_t * t_ttype = ASRUtils::expr_type (x.m_a );
855
847
ASR::List_t* t = ASR::down_cast<ASR::List_t>(t_ttype);
856
- std::string list_clear_func = list_api ->get_list_clear_func (t);
848
+ std::string list_clear_func = c_ds_api ->get_list_clear_func (t);
857
849
self ().visit_expr (*x.m_a );
858
850
std::string list_var = std::move (src);
859
851
std::string indent (indentation_level * indentation_spaces, ' ' );
@@ -863,7 +855,7 @@ R"(#include <stdio.h>
863
855
void visit_ListInsert (const ASR::ListInsert_t& x) {
864
856
ASR::ttype_t * t_ttype = ASRUtils::expr_type (x.m_a );
865
857
ASR::List_t* t = ASR::down_cast<ASR::List_t>(t_ttype);
866
- std::string list_insert_func = list_api ->get_list_insert_func (t);
858
+ std::string list_insert_func = c_ds_api ->get_list_insert_func (t);
867
859
self ().visit_expr (*x.m_a );
868
860
std::string list_var = std::move (src);
869
861
self ().visit_expr (*x.m_ele );
@@ -877,7 +869,7 @@ R"(#include <stdio.h>
877
869
void visit_ListRemove (const ASR::ListRemove_t& x) {
878
870
ASR::ttype_t * t_ttype = ASRUtils::expr_type (x.m_a );
879
871
ASR::List_t* t = ASR::down_cast<ASR::List_t>(t_ttype);
880
- std::string list_remove_func = list_api ->get_list_remove_func (t);
872
+ std::string list_remove_func = c_ds_api ->get_list_remove_func (t);
881
873
self ().visit_expr (*x.m_a );
882
874
std::string list_var = std::move (src);
883
875
self ().visit_expr (*x.m_ele );
0 commit comments