Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e67c83

Browse files
committed
Pass current_scope to replace_args_with_FunctionParam()
1 parent 825575a commit 7e67c83

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/libasr/asr_utils.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,10 +3247,12 @@ class ReplaceWithFunctionParamVisitor: public ASR::BaseExprReplacer<ReplaceWithF
32473247

32483248
size_t n_args;
32493249

3250+
SymbolTable* current_scope;
3251+
32503252
public:
32513253

32523254
ReplaceWithFunctionParamVisitor(Allocator& al_, ASR::expr_t** m_args_, size_t n_args_) :
3253-
al(al_), m_args(m_args_), n_args(n_args_) {}
3255+
al(al_), m_args(m_args_), n_args(n_args_), current_scope(nullptr) {}
32543256

32553257
void replace_Var(ASR::Var_t* x) {
32563258
size_t arg_idx = 0;
@@ -3268,14 +3270,16 @@ class ReplaceWithFunctionParamVisitor: public ASR::BaseExprReplacer<ReplaceWithF
32683270
if( idx_found ) {
32693271
LCOMPILERS_ASSERT(current_expr);
32703272
ASR::ttype_t* t_ = replace_args_with_FunctionParam(
3271-
ASRUtils::symbol_type(x->m_v));
3273+
ASRUtils::symbol_type(x->m_v), current_scope);
32723274
*current_expr = ASRUtils::EXPR(ASR::make_FunctionParam_t(
32733275
al, m_args[arg_idx]->base.loc, arg_idx,
32743276
t_, nullptr));
32753277
}
32763278
}
32773279

3278-
ASR::ttype_t* replace_args_with_FunctionParam(ASR::ttype_t* t) {
3280+
ASR::ttype_t* replace_args_with_FunctionParam(ASR::ttype_t* t, SymbolTable* current_scope) {
3281+
this->current_scope = current_scope;
3282+
32793283
ASRUtils::ExprStmtDuplicator duplicator(al);
32803284
duplicator.allow_procedure_calls = true;
32813285

@@ -3312,21 +3316,21 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
33123316
ASR::expr_t* a_return_var, ASR::abiType a_abi, ASR::deftypeType a_deftype,
33133317
char* a_bindc_name, bool a_elemental, bool a_pure, bool a_module, bool a_inline,
33143318
bool a_static,
3315-
ASR::symbol_t** a_restrictions, size_t n_restrictions, bool a_is_restriction) {
3319+
ASR::symbol_t** a_restrictions, size_t n_restrictions, bool a_is_restriction, SymbolTable* current_scope) {
33163320
Vec<ASR::ttype_t*> arg_types;
33173321
arg_types.reserve(al, n_args);
33183322
ReplaceWithFunctionParamVisitor replacer(al, a_args, n_args);
33193323
for( size_t i = 0; i < n_args; i++ ) {
33203324
// We need to substitute all direct argument variable references with
33213325
// FunctionParam.
33223326
ASR::ttype_t *t = replacer.replace_args_with_FunctionParam(
3323-
expr_type(a_args[i]));
3327+
expr_type(a_args[i]), current_scope);
33243328
arg_types.push_back(al, t);
33253329
}
33263330
ASR::ttype_t* return_var_type = nullptr;
33273331
if( a_return_var ) {
33283332
return_var_type = replacer.replace_args_with_FunctionParam(
3329-
ASRUtils::expr_type(a_return_var));
3333+
ASRUtils::expr_type(a_return_var), current_scope);
33303334
}
33313335

33323336
LCOMPILERS_ASSERT(arg_types.size() == n_args);
@@ -3338,12 +3342,12 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
33383342
}
33393343

33403344
inline ASR::asr_t* make_FunctionType_t_util(Allocator &al, const Location &a_loc,
3341-
ASR::expr_t** a_args, size_t n_args, ASR::expr_t* a_return_var, ASR::FunctionType_t* ft) {
3345+
ASR::expr_t** a_args, size_t n_args, ASR::expr_t* a_return_var, ASR::FunctionType_t* ft, SymbolTable* current_scope) {
33423346
return ASRUtils::make_FunctionType_t_util(al, a_loc, a_args, n_args, a_return_var,
33433347
ft->m_abi, ft->m_deftype, ft->m_bindc_name, ft->m_elemental,
33443348
ft->m_pure, ft->m_module, ft->m_inline, ft->m_static,
33453349
ft->m_restrictions,
3346-
ft->n_restrictions, ft->m_is_restriction);
3350+
ft->n_restrictions, ft->m_is_restriction, current_scope);
33473351
}
33483352

33493353
inline ASR::asr_t* make_Function_t_util(Allocator& al, const Location& loc,
@@ -3357,7 +3361,7 @@ inline ASR::asr_t* make_Function_t_util(Allocator& al, const Location& loc,
33573361
ASR::ttype_t* func_type = ASRUtils::TYPE(ASRUtils::make_FunctionType_t_util(
33583362
al, loc, a_args, n_args, m_return_var, m_abi, m_deftype, m_bindc_name,
33593363
m_elemental, m_pure, m_module, m_inline, m_static,
3360-
m_restrictions, n_restrictions, m_is_restriction));
3364+
m_restrictions, n_restrictions, m_is_restriction, m_symtab));
33613365
return ASR::make_Function_t(
33623366
al, loc, m_symtab, m_name, func_type, m_dependencies, n_dependencies,
33633367
a_args, n_args, m_body, n_body, m_return_var, m_access, m_deterministic,

src/libasr/pass/pass_array_by_data.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class PassArrayByDataProcedureVisitor : public PassUtils::PassVisitor<PassArrayB
199199

200200
ASR::FunctionType_t* func_type = ASRUtils::get_FunctionType(*x);
201201
x->m_function_signature = ASRUtils::TYPE(ASRUtils::make_FunctionType_t_util(
202-
al, func_type->base.base.loc, new_args.p, new_args.size(), x->m_return_var, func_type));
202+
al, func_type->base.base.loc, new_args.p, new_args.size(), x->m_return_var, func_type, current_scope));
203203
x->m_args = new_args.p;
204204
x->n_args = new_args.size();
205205
}

src/libasr/pass/pass_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ namespace LCompilers {
744744
for(auto &e: a_args) {
745745
ASRUtils::ReplaceWithFunctionParamVisitor replacer(al, x->m_args, x->n_args);
746746
arg_types.push_back(al, replacer.replace_args_with_FunctionParam(
747-
ASRUtils::expr_type(e)));
747+
ASRUtils::expr_type(e), x->m_symtab));
748748
}
749749
s_func_type->m_arg_types = arg_types.p;
750750
s_func_type->n_arg_types = arg_types.n;

0 commit comments

Comments
 (0)