Skip to content

Commit

Permalink
Rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
tanay-man committed Aug 2, 2024
1 parent 4cd9d27 commit c727045
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
26 changes: 26 additions & 0 deletions src/libasr/pass/pass_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,32 @@ namespace LCompilers {
bool perform_cast=false,
ASR::cast_kindType cast_kind=ASR::cast_kindType::IntegerToInteger,
ASR::ttype_t* casted_type=nullptr) {
if ( x->m_dt_sym && ASR::is_a<ASR::Struct_t>(*(x->m_dt_sym)) ) {
ASR::Struct_t* st = ASR::down_cast<ASR::Struct_t>(x->m_dt_sym);
if ( st->n_member_functions > 0 ) {
remove_original_statement = true;
if ( !ASR::is_a<ASR::Var_t>(*(replacer->result_var)) ) {
throw LCompilersException("Expected a var here");
}
ASR::Var_t* target = ASR::down_cast<ASR::Var_t>(replacer->result_var);
ASR::call_arg_t first_arg;
first_arg.loc = x->base.base.loc; first_arg.m_value = replacer->result_var;
Vec<ASR::call_arg_t> new_args; new_args.reserve(replacer->al,1);
new_args.push_back(replacer->al, first_arg);
for( size_t i = 0; i < x->n_args; i++ ) {
new_args.push_back(replacer->al, x->m_args[i]);
}
ASR::StructType_t* type = ASR::down_cast<ASR::StructType_t>(
(ASR::down_cast<ASR::Variable_t>(target->m_v))->m_type);
std::string call_name = "__init__";
ASR::symbol_t* call_sym = get_struct_member(replacer->al,type->m_derived_type, call_name,
x->base.base.loc, replacer->current_scope);
result_vec->push_back(replacer->al,
ASRUtils::STMT(make_call_helper(replacer->al,call_sym,
new_args,call_name,x->base.base.loc)));
return;
}
}
if( x->n_args == 0 ) {
if( !inside_symtab ) {
remove_original_statement = true;
Expand Down
18 changes: 0 additions & 18 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5313,17 +5313,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
if ( call->n_keywords>0 ) {
throw SemanticError("Kwargs not implemented yet", x.base.base.loc);
}
Vec<ASR::call_arg_t> args;
args.reserve(al, call->n_args + 1);
ASR::call_arg_t self_arg;
self_arg.loc = x.base.base.loc;
self_arg.m_value = ASRUtils::EXPR(ASR::make_Var_t(al, x.base.base.loc, sym));
args.push_back(al, self_arg);
visit_expr_list(call->m_args, call->n_args, args);
ASR::symbol_t* der = ASR::down_cast<ASR::StructType_t>((var->m_type))->m_derived_type;
std::string call_name = "__init__";
ASR::symbol_t* call_sym = get_struct_member(der, call_name, x.base.base.loc);
tmp = make_call_helper(al, call_sym, current_scope, args, call_name, x.base.base.loc);
}
}
}
Expand Down Expand Up @@ -5618,13 +5607,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
if ( call->n_keywords>0 ) {
throw SemanticError("Kwargs not implemented yet", x.base.base.loc);
}
visit_expr_list(call->m_args, call->n_args, new_args);
ASR::symbol_t* der = ASR::down_cast<ASR::StructType_t>(
ASR::down_cast<ASR::Variable_t>(st)->m_type)->m_derived_type;
std::string call_name = "__init__";
ASR::symbol_t* call_sym = get_struct_member(der, call_name, x.base.base.loc);
tmp_vec.push_back(make_call_helper(al, call_sym,
current_scope, new_args, call_name, x.base.base.loc));
}
}
// to make sure that we add only those statements in tmp_vec
Expand Down

0 comments on commit c727045

Please sign in to comment.