Skip to content

Commit cba7320

Browse files
authored
Merge pull request #2383 from anutosh491/fix_printing_symbolic_lists
Fixed printing elements from a symbolic list
2 parents d41216c + 5c95290 commit cba7320

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

integration_tests/symbolics_11.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ def test_extraction_of_elements():
1414
assert(ele3 == sin(x))
1515
assert(ele4 == Symbol("y"))
1616
print(ele1, ele2, ele3, ele4)
17+
print(l1[0], l1[1], l1[2], l1[3])
1718

1819
test_extraction_of_elements()

src/libasr/pass/replace_symbolic.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,24 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
12611261
sym, sym, call_args.p, call_args.n, ASRUtils::TYPE(ASR::make_Logical_t(al, x.base.base.loc, 4)), nullptr, nullptr));
12621262
print_tmp.push_back(function_call);
12631263
}
1264+
} else if (ASR::is_a<ASR::ListItem_t>(*val)) {
1265+
ASR::ListItem_t* list_item = ASR::down_cast<ASR::ListItem_t>(val);
1266+
if (list_item->m_type->type == ASR::ttypeType::SymbolicExpression) {
1267+
ASR::ttype_t *CPtr_type = ASRUtils::TYPE(ASR::make_CPtr_t(al, x.base.base.loc));
1268+
ASR::symbol_t* basic_str_sym = declare_basic_str_function(al, x.base.base.loc, module_scope);
1269+
1270+
Vec<ASR::call_arg_t> call_args;
1271+
call_args.reserve(al, 1);
1272+
ASR::call_arg_t call_arg;
1273+
call_arg.loc = x.base.base.loc;
1274+
call_arg.m_value = ASRUtils::EXPR(ASR::make_ListItem_t(al, x.base.base.loc, list_item->m_a,
1275+
list_item->m_pos, CPtr_type, nullptr));
1276+
call_args.push_back(al, call_arg);
1277+
ASR::expr_t* function_call = ASRUtils::EXPR(ASRUtils::make_FunctionCall_t_util(al, x.base.base.loc,
1278+
basic_str_sym, basic_str_sym, call_args.p, call_args.n,
1279+
ASRUtils::TYPE(ASR::make_Character_t(al, x.base.base.loc, 1, -2, nullptr)), nullptr, nullptr));
1280+
print_tmp.push_back(function_call);
1281+
}
12641282
} else {
12651283
print_tmp.push_back(x.m_values[i]);
12661284
}

0 commit comments

Comments
 (0)