@@ -3087,6 +3087,30 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
30873087 }
30883088 }
30893089
3090+ void instantiate_methods (const ASR::Struct_t &x) {
3091+ SymbolTable *current_scope_copy = current_scope;
3092+ current_scope = x.m_symtab ;
3093+ for ( auto &item : x.m_symtab ->get_scope () ) {
3094+ if ( is_a<ASR::Function_t>(*item.second ) ) {
3095+ ASR::Function_t *v = down_cast<ASR::Function_t>(item.second );
3096+ instantiate_function (*v);
3097+ }
3098+ }
3099+ current_scope = current_scope_copy;
3100+ }
3101+
3102+ void visit_methods (const ASR::Struct_t &x) {
3103+ SymbolTable *current_scope_copy = current_scope;
3104+ current_scope = x.m_symtab ;
3105+ for ( auto &item : x.m_symtab ->get_scope () ) {
3106+ if ( is_a<ASR::Function_t>(*item.second ) ) {
3107+ ASR::Function_t *v = down_cast<ASR::Function_t>(item.second );
3108+ visit_Function (*v);
3109+ }
3110+ }
3111+ current_scope = current_scope_copy;
3112+ }
3113+
30903114 void start_module_init_function_prototype (const ASR::Module_t &x) {
30913115 uint32_t h = get_hash ((ASR::asr_t *)&x);
30923116 llvm::FunctionType *function_type = llvm::FunctionType::get (
@@ -3128,6 +3152,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
31283152 } else if (is_a<ASR::EnumType_t>(*item.second )) {
31293153 ASR::EnumType_t *et = down_cast<ASR::EnumType_t>(item.second );
31303154 visit_EnumType (*et);
3155+ } else if (is_a<ASR::Struct_t>(*item.second )) {
3156+ ASR::Struct_t *st = down_cast<ASR::Struct_t>(item.second );
3157+ instantiate_methods (*st);
31313158 }
31323159 }
31333160 finish_module_init_function_prototype (x);
@@ -4179,6 +4206,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
41794206 if (is_a<ASR::Function_t>(*item.second )) {
41804207 ASR::Function_t *s = ASR::down_cast<ASR::Function_t>(item.second );
41814208 visit_Function (*s);
4209+ } else if ( is_a<ASR::Struct_t>(*item.second ) ) {
4210+ ASR::Struct_t *st = down_cast<ASR::Struct_t>(item.second );
4211+ visit_methods (*st);
41824212 }
41834213 }
41844214 }
0 commit comments