@@ -47,7 +47,7 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitor<InlineFunctionCa
4747 bool fixed_duplicated_expr_stmt;
4848 bool is_fast;
4949
50- // Stores the local variables corresponding to the ones
50+ // Stores the local variables or/and block symbol corresponding to the ones
5151 // present in function symbol table.
5252 std::map<std::string, ASR::symbol_t *> arg2value;
5353
@@ -95,31 +95,35 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitor<InlineFunctionCa
9595 current_routine.clear ();
9696 }
9797
98+ // If anything is not local to a function being inlined
99+ // then do not inline the function by setting
100+ // fixed_duplicated_expr_stmt to false.
101+ // To be supported later.
102+ #define replace_symbol (sym, symbol_t, m_v ) \
103+ std::string sym_name = ASRUtils::symbol_name(sym); \
104+ if ( current_routine_scope && \
105+ current_routine_scope->get_symbol (sym_name) == nullptr ) { \
106+ fixed_duplicated_expr_stmt = false ; \
107+ return ; \
108+ } \
109+ LCOMPILERS_ASSERT (ASR::is_a<symbol_t >(*sym)) \
110+ if( arg2value.find(sym_name) != arg2value.end() ) { \
111+ symbol_t *x_var = ASR::down_cast<symbol_t >(arg2value[sym_name]); \
112+ if ( current_scope->get_symbol (std::string (x_var->m_name ))) { \
113+ m_v = arg2value[sym_name]; \
114+ } \
115+ } else { \
116+ fixed_duplicated_expr_stmt = false ; \
117+ }
118+
98119 void visit_Var (const ASR::Var_t& x) {
99120 ASR::Var_t& xx = const_cast <ASR::Var_t&>(x);
100- std::string x_var_name = std::string (ASRUtils::symbol_name (x.m_v ));
101-
102- // If anything is not local to a function being inlined
103- // then do not inline the function by setting
104- // fixed_duplicated_expr_stmt to false.
105- // To be supported later.
106- if ( current_routine_scope &&
107- current_routine_scope->get_symbol (x_var_name) == nullptr ) {
108- fixed_duplicated_expr_stmt = false ;
109- return ;
110- }
111- if ( x.m_v ->type == ASR::symbolType::Variable ) {
112- ASR::Variable_t* x_var = ASR::down_cast<ASR::Variable_t>(x.m_v );
113- if ( arg2value.find (x_var_name) != arg2value.end () ) {
114- x_var = ASR::down_cast<ASR::Variable_t>(arg2value[x_var_name]);
115- if ( current_scope->get_symbol (std::string (x_var->m_name )) != nullptr ) {
116- xx.m_v = arg2value[x_var_name];
117- }
118- x_var = ASR::down_cast<ASR::Variable_t>(x.m_v );
119- }
120- } else {
121- fixed_duplicated_expr_stmt = false ;
122- }
121+ replace_symbol (x.m_v , ASR::Variable_t, xx.m_v );
122+ }
123+
124+ void visit_BlockCall (const ASR::BlockCall_t &x) {
125+ ASR::BlockCall_t& xx = const_cast <ASR::BlockCall_t&>(x);
126+ replace_symbol (x.m_m , ASR::Block_t, xx.m_m );
123127 }
124128
125129 void set_empty_block (SymbolTable* scope, const Location& loc) {
@@ -133,6 +137,7 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitor<InlineFunctionCa
133137 s2c (al, empty_block_name), nullptr , 0 ));
134138 scope->add_symbol (empty_block_name, empty_block);
135139 }
140+ arg2value[empty_block_name] = empty_block;
136141 }
137142
138143 void remove_empty_block (SymbolTable* scope) {
0 commit comments