@@ -2453,23 +2453,35 @@ static inline ASR::dimension_t* duplicate_dimensions(Allocator& al, ASR::dimensi
24532453static inline ASR::asr_t * make_StructType_t_util (Allocator& al, Location loc, ASR::symbol_t * der){
24542454 ASR::Struct_t* st = ASR::down_cast<ASR::Struct_t>(ASRUtils::symbol_get_past_external (der));
24552455 Vec<ASR::ttype_t *> members;
2456- members.reserve (al, st->n_members );
2456+ members.reserve (al, 1 );
2457+ Vec<ASR::ttype_t *> member_functions;
2458+ member_functions.reserve (al, 1 );
24572459 SymbolTable* current_scope = st->m_symtab ;
24582460 for (size_t i = 0 ; i < st->n_members ; i++){
24592461 ASR::symbol_t * temp = current_scope->get_symbol (st->m_members [i]);
24602462 if (ASR::is_a<ASR::Variable_t>(*temp)){
24612463 ASR::Variable_t* var = ASR::down_cast<ASR::Variable_t>(
24622464 ASRUtils::symbol_get_past_external (temp));
2463- members.push_back (al,var->m_type );
2465+ members.push_back (al,var->m_type );
24642466 }
24652467 }
2466- return ASR::make_StructType_t (al,
2467- loc,
2468- members.p ,
2468+ for (size_t i = 0 ; i < st->n_member_functions ; i++){
2469+ ASR::symbol_t * sym = current_scope->get_symbol (st->m_member_functions [i]);
2470+ if (sym && ASR::is_a<ASR::Function_t>(*sym)){
2471+ ASR::Function_t *f = ASR::down_cast<ASR::Function_t>(
2472+ ASRUtils::symbol_get_past_external (sym));
2473+ ASR::ttype_t * f_type = f->m_function_signature ;
2474+ member_functions.push_back (al, f_type);
2475+ }
2476+ }
2477+ bool is_cstruct = member_functions.n == 0 ;
2478+ return ASR::make_StructType_t (al,
2479+ loc,
2480+ members.p ,
24692481 members.n ,
2470- nullptr , // Correct this when mem fn added to Struct_t
2471- 0 , // Correct this when mem fn added to Struct_t
2472- true , // Correct this when mem fn added to Struct_t
2482+ member_functions. p ,
2483+ member_functions. n ,
2484+ is_cstruct,
24732485 der);
24742486
24752487}
@@ -2530,12 +2542,12 @@ static inline ASR::ttype_t* duplicate_type(Allocator& al, const ASR::ttype_t* t,
25302542 }
25312543 case ASR::ttypeType::StructType: {
25322544 ASR::StructType_t* tnew = ASR::down_cast<ASR::StructType_t>(t);
2533- t_ = ASRUtils::TYPE (ASR::make_StructType_t (al, t->base .loc ,
2534- tnew->m_data_member_types ,
2545+ t_ = ASRUtils::TYPE (ASR::make_StructType_t (al, t->base .loc ,
2546+ tnew->m_data_member_types ,
25352547 tnew->n_data_member_types ,
25362548 tnew->m_member_function_types ,
25372549 tnew->n_member_function_types ,
2538- tnew->m_is_cstruct ,
2550+ tnew->m_is_cstruct ,
25392551 tnew->m_derived_type ));
25402552 break ;
25412553 }
@@ -2686,12 +2698,12 @@ static inline ASR::ttype_t* duplicate_type_without_dims(Allocator& al, const ASR
26862698 }
26872699 case ASR::ttypeType::StructType: {
26882700 ASR::StructType_t* tstruct = ASR::down_cast<ASR::StructType_t>(t);
2689- return ASRUtils::TYPE (ASR::make_StructType_t (al, t->base .loc ,
2690- tstruct->m_data_member_types ,
2701+ return ASRUtils::TYPE (ASR::make_StructType_t (al, t->base .loc ,
2702+ tstruct->m_data_member_types ,
26912703 tstruct->n_data_member_types ,
26922704 tstruct->m_member_function_types ,
26932705 tstruct->n_member_function_types ,
2694- tstruct->m_is_cstruct ,
2706+ tstruct->m_is_cstruct ,
26952707 tstruct->m_derived_type ));
26962708 }
26972709 case ASR::ttypeType::Pointer: {
@@ -4299,7 +4311,9 @@ class SymbolDuplicator {
42994311 return ASR::down_cast<ASR::symbol_t >(ASR::make_Struct_t (
43004312 al, struct_type_t ->base .base .loc , struct_type_symtab,
43014313 struct_type_t ->m_name , struct_type_t ->m_dependencies , struct_type_t ->n_dependencies ,
4302- struct_type_t ->m_members , struct_type_t ->n_members , struct_type_t ->m_abi ,
4314+ struct_type_t ->m_members , struct_type_t ->n_members ,
4315+ struct_type_t ->m_member_functions , struct_type_t ->n_member_functions ,
4316+ struct_type_t ->m_abi ,
43034317 struct_type_t ->m_access , struct_type_t ->m_is_packed , struct_type_t ->m_is_abstract ,
43044318 struct_type_t ->m_initializers , struct_type_t ->n_initializers , struct_type_t ->m_alignment ,
43054319 struct_type_t ->m_parent ));
0 commit comments