Skip to content

Commit df83b5a

Browse files
authored
Merge pull request #2326 from Shaikh-Ubaid/changes_from_lfortran
Changes from lfortran
2 parents 825575a + 12a376a commit df83b5a

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

src/libasr/asdl_cpp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,8 @@ def visitField(self, field):
13031303
self.emit(" self().replace_expr(x->m_%s[i]);"%(field.name), level)
13041304
self.emit(" current_expr = current_expr_copy_%d;" % (self.current_expr_copy_variable_count), level)
13051305
self.current_expr_copy_variable_count += 1
1306+
elif field.type == "ttype":
1307+
self.emit(" self().replace_%s(x->m_%s[i]);" % (field.type, field.name), level)
13061308
self.emit("}", level)
13071309
else:
13081310
if field.type != "symbol":

src/libasr/asr_utils.h

Lines changed: 23 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,26 @@ 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+
void replace_Struct(ASR::Struct_t *x) {
3281+
std::string derived_type_name = ASRUtils::symbol_name(x->m_derived_type);
3282+
ASR::symbol_t* derived_type_sym = current_scope->resolve_symbol(derived_type_name);
3283+
LCOMPILERS_ASSERT_MSG( derived_type_sym != nullptr,
3284+
"derived_type_sym cannot be nullptr");
3285+
if (derived_type_sym != x->m_derived_type) {
3286+
x->m_derived_type = derived_type_sym;
3287+
}
3288+
}
3289+
3290+
ASR::ttype_t* replace_args_with_FunctionParam(ASR::ttype_t* t, SymbolTable* current_scope) {
3291+
this->current_scope = current_scope;
3292+
32793293
ASRUtils::ExprStmtDuplicator duplicator(al);
32803294
duplicator.allow_procedure_calls = true;
32813295

@@ -3312,21 +3326,21 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
33123326
ASR::expr_t* a_return_var, ASR::abiType a_abi, ASR::deftypeType a_deftype,
33133327
char* a_bindc_name, bool a_elemental, bool a_pure, bool a_module, bool a_inline,
33143328
bool a_static,
3315-
ASR::symbol_t** a_restrictions, size_t n_restrictions, bool a_is_restriction) {
3329+
ASR::symbol_t** a_restrictions, size_t n_restrictions, bool a_is_restriction, SymbolTable* current_scope) {
33163330
Vec<ASR::ttype_t*> arg_types;
33173331
arg_types.reserve(al, n_args);
33183332
ReplaceWithFunctionParamVisitor replacer(al, a_args, n_args);
33193333
for( size_t i = 0; i < n_args; i++ ) {
33203334
// We need to substitute all direct argument variable references with
33213335
// FunctionParam.
33223336
ASR::ttype_t *t = replacer.replace_args_with_FunctionParam(
3323-
expr_type(a_args[i]));
3337+
expr_type(a_args[i]), current_scope);
33243338
arg_types.push_back(al, t);
33253339
}
33263340
ASR::ttype_t* return_var_type = nullptr;
33273341
if( a_return_var ) {
33283342
return_var_type = replacer.replace_args_with_FunctionParam(
3329-
ASRUtils::expr_type(a_return_var));
3343+
ASRUtils::expr_type(a_return_var), current_scope);
33303344
}
33313345

33323346
LCOMPILERS_ASSERT(arg_types.size() == n_args);
@@ -3338,12 +3352,12 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
33383352
}
33393353

33403354
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) {
3355+
ASR::expr_t** a_args, size_t n_args, ASR::expr_t* a_return_var, ASR::FunctionType_t* ft, SymbolTable* current_scope) {
33423356
return ASRUtils::make_FunctionType_t_util(al, a_loc, a_args, n_args, a_return_var,
33433357
ft->m_abi, ft->m_deftype, ft->m_bindc_name, ft->m_elemental,
33443358
ft->m_pure, ft->m_module, ft->m_inline, ft->m_static,
33453359
ft->m_restrictions,
3346-
ft->n_restrictions, ft->m_is_restriction);
3360+
ft->n_restrictions, ft->m_is_restriction, current_scope);
33473361
}
33483362

33493363
inline ASR::asr_t* make_Function_t_util(Allocator& al, const Location& loc,
@@ -3357,7 +3371,7 @@ inline ASR::asr_t* make_Function_t_util(Allocator& al, const Location& loc,
33573371
ASR::ttype_t* func_type = ASRUtils::TYPE(ASRUtils::make_FunctionType_t_util(
33583372
al, loc, a_args, n_args, m_return_var, m_abi, m_deftype, m_bindc_name,
33593373
m_elemental, m_pure, m_module, m_inline, m_static,
3360-
m_restrictions, n_restrictions, m_is_restriction));
3374+
m_restrictions, n_restrictions, m_is_restriction, m_symtab));
33613375
return ASR::make_Function_t(
33623376
al, loc, m_symtab, m_name, func_type, m_dependencies, n_dependencies,
33633377
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)