@@ -2956,7 +2956,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
29562956 }
29572957
29582958 void get_members_init (const AST::FunctionDef_t &x,
2959- Vec<char *>& member_names, Vec<ASR::call_arg_t > &member_init){
2959+ Vec<char *>& member_names, Vec<ASR::call_arg_t > &member_init,
2960+ SetChar& struct_dependencies){
29602961 if (x.n_decorator_list > 0 ) {
29612962 throw SemanticError (" Decorators for __init__ not implemented" ,
29622963 x.base .base .loc );
@@ -2997,6 +2998,22 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
29972998 c_arg.loc = var_sym->base .loc ;
29982999 c_arg.m_value = nullptr ;
29993000 member_init.push_back (al, c_arg);
3001+ ASR::ttype_t * var_type = ASRUtils::type_get_past_pointer (ASRUtils::symbol_type (var_sym));
3002+ char * aggregate_type_name = nullptr ;
3003+ if ( ASR::is_a<ASR::StructType_t>(*var_type) ) {
3004+ aggregate_type_name = ASRUtils::symbol_name (
3005+ ASR::down_cast<ASR::StructType_t>(var_type)->m_derived_type );
3006+ } else if ( ASR::is_a<ASR::Enum_t>(*var_type) ) {
3007+ aggregate_type_name = ASRUtils::symbol_name (
3008+ ASR::down_cast<ASR::Enum_t>(var_type)->m_enum_type );
3009+ } else if ( ASR::is_a<ASR::Union_t>(*var_type) ) {
3010+ aggregate_type_name = ASRUtils::symbol_name (
3011+ ASR::down_cast<ASR::Union_t>(var_type)->m_union_type );
3012+ }
3013+ if ( aggregate_type_name &&
3014+ !current_scope->get_symbol (std::string (aggregate_type_name)) ) {
3015+ struct_dependencies.push_back (al, aggregate_type_name);
3016+ }
30003017 }
30013018 }
30023019
@@ -3027,7 +3044,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
30273044 *f = AST::down_cast<AST::FunctionDef_t>(x.m_body [i]);
30283045 std::string f_name = f->m_name ;
30293046 if (f_name == " __init__" ) {
3030- this ->get_members_init (*f, member_names, member_init);
3047+ this ->get_members_init (*f, member_names, member_init, struct_dependencies );
30313048 this ->visit_stmt (*x.m_body [i]);
30323049 member_fn_names.push_back (al, f->m_name );
30333050 } else {
@@ -8244,6 +8261,31 @@ we will have to use something else.
82448261 }
82458262 handle_builtin_attribute (subscript_expr, at->m_attr , loc, eles);
82468263 return ;
8264+ } else if ( AST::is_a<AST::Attribute_t>(*at->m_value ) ) {
8265+ AST::Attribute_t* at_m_value = AST::down_cast<AST::Attribute_t>(at->m_value );
8266+ visit_Attribute (*at_m_value);
8267+ ASR::expr_t * e = ASRUtils::EXPR (tmp);
8268+ if ( !ASR::is_a<ASR::StructInstanceMember_t>(*e) ) {
8269+ throw SemanticError (" Expected a class variable here" , loc);
8270+ }
8271+ if ( !ASR::is_a<ASR::StructType_t>(*ASRUtils::expr_type (e)) ) {
8272+ throw SemanticError (" Only Classes supported in nested attribute call" , loc);
8273+ }
8274+ ASR::StructType_t* der = ASR::down_cast<ASR::StructType_t>(ASRUtils::expr_type (e));
8275+ ASR::symbol_t * der_sym = ASRUtils::symbol_get_past_external (der->m_derived_type );
8276+ std::string call_name = at->m_attr ;
8277+
8278+ Vec<ASR::call_arg_t > new_args; new_args.reserve (al, args.n + 1 );
8279+ ASR::call_arg_t self_arg;
8280+ self_arg.loc = args[0 ].loc ;
8281+ self_arg.m_value = e;
8282+ new_args.push_back (al, self_arg);
8283+ for (size_t i=0 ; i<args.n ; i++) {
8284+ new_args.push_back (al, args[i]);
8285+ }
8286+ ASR::symbol_t * st = get_struct_member (der_sym, call_name, loc);
8287+ tmp = make_call_helper (al, st, current_scope, new_args, call_name, loc);
8288+ return ;
82478289 } else {
82488290 throw SemanticError (" Only Name type and constant integers supported in Call" , loc);
82498291 }
0 commit comments