diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 0ce3958739..61e609eac3 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -592,6 +592,7 @@ RUN(NAME structs_28 LABELS cpython llvm c) RUN(NAME structs_29 LABELS cpython llvm) RUN(NAME structs_30 LABELS cpython llvm c) RUN(NAME structs_31 LABELS cpython llvm c) +RUN(NAME structs_32 LABELS cpython llvm c) RUN(NAME symbolics_01 LABELS cpython_sym c_sym) RUN(NAME symbolics_02 LABELS cpython_sym c_sym) diff --git a/integration_tests/structs_10.py b/integration_tests/structs_10.py index 8e55c9a5ae..b6f2780778 100644 --- a/integration_tests/structs_10.py +++ b/integration_tests/structs_10.py @@ -3,16 +3,16 @@ @dataclass class Mat: - mat: f64[2, 2] + mat: f64[2, 2] = empty((2, 2), dtype=float64) @dataclass class Vec: - vec: f64[2] + vec: f64[2] = empty(2, dtype=float64) @dataclass class MatVec: - mat: Mat = Mat([f64(0.0), f64(0.0)]) - vec: Vec = Vec([f64(0.0), f64(0.0)]) + mat: Mat = Mat() + vec: Vec = Vec() def rotate(mat_vec: MatVec) -> f64[2]: rotated_vec: f64[2] = empty(2, dtype=float64) diff --git a/integration_tests/structs_27.py b/integration_tests/structs_27.py index a3fd09d08b..4009794f48 100644 --- a/integration_tests/structs_27.py +++ b/integration_tests/structs_27.py @@ -1,4 +1,4 @@ -from lpython import dataclass, i32 +from lpython import dataclass, i32, u16, f32 @dataclass @@ -7,6 +7,15 @@ class StringIO: _0cursor : i32 = 10 _len : i32 = 1 +@dataclass +class StringIONew: + _buf : str + _0cursor : i32 = i32(142) + _len : i32 = i32(2439) + _var1 : u16 = u16(23) + _var2 : f32 = f32(30.24) + +#print("ok") def test_issue_1928(): integer_asr : str = '(Integer 4 [])' @@ -47,4 +56,22 @@ def test_issue_1928(): assert test_dude4._0cursor == 31 +def test_issue_1981(): + integer_asr : str = '(Integer 4 [])' + test_dude : StringIONew = StringIONew(integer_asr) + assert test_dude._buf == integer_asr + assert test_dude._len == 2439 + assert test_dude._0cursor == 142 + assert test_dude._var1 == u16(23) + assert abs(test_dude._var2 - f32(30.24)) < f32(1e-5) + test_dude._len = 13 + test_dude._0cursor = 52 + test_dude._var1 = u16(34) + assert test_dude._buf == integer_asr + assert test_dude._len == 13 + assert test_dude._0cursor == 52 + assert test_dude._var1 == u16(34) + + +test_issue_1981() test_issue_1928() diff --git a/integration_tests/structs_32.py b/integration_tests/structs_32.py new file mode 100644 index 0000000000..32babac66d --- /dev/null +++ b/integration_tests/structs_32.py @@ -0,0 +1,45 @@ +from lpython import packed, dataclass, i32, InOut + + +@packed +@dataclass +class inner_struct: + a: i32 + + +@packed +@dataclass +class outer_struct: + b: inner_struct = inner_struct(0) + + +def update_my_inner_struct(my_inner_struct: InOut[inner_struct]) -> None: + my_inner_struct.a = 99999 + + +def update_my_outer_struct(my_outer_struct: InOut[outer_struct]) -> None: + my_outer_struct.b.a = 12345 + + +def main() -> None: + my_outer_struct: outer_struct = outer_struct() + my_inner_struct: inner_struct = my_outer_struct.b + + assert my_outer_struct.b.a == 0 + + my_outer_struct.b.a = 12345 + assert my_outer_struct.b.a == 12345 + + my_outer_struct.b.a = 0 + assert my_outer_struct.b.a == 0 + + update_my_outer_struct(my_outer_struct) + assert my_outer_struct.b.a == 12345 + + my_inner_struct.a = 1111 + assert my_inner_struct.a == 1111 + + update_my_inner_struct(my_inner_struct) + assert my_inner_struct.a == 99999 + +main() diff --git a/src/libasr/ASR.asdl b/src/libasr/ASR.asdl index e4d54f237c..89062d3b98 100644 --- a/src/libasr/ASR.asdl +++ b/src/libasr/ASR.asdl @@ -96,12 +96,12 @@ symbol identifier original_name, access access) | StructType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, bool is_packed, bool is_abstract, - expr? alignment, symbol? parent) + call_arg* initializers, expr? alignment, symbol? parent) | EnumType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, enumtype enum_value_type, ttype type, symbol? parent) | UnionType(symbol_table symtab, identifier name, identifier* dependencies, - identifier* members, abi abi, access access, symbol? parent) + identifier* members, abi abi, access access, call_arg* initializers, symbol? parent) | Variable(symbol_table parent_symtab, identifier name, identifier* dependencies, intent intent, expr? symbolic_value, expr? value, storage_type storage, ttype type, symbol? type_declaration, diff --git a/src/libasr/codegen/asr_to_c.cpp b/src/libasr/codegen/asr_to_c.cpp index 45fa2534cc..c1318392c1 100644 --- a/src/libasr/codegen/asr_to_c.cpp +++ b/src/libasr/codegen/asr_to_c.cpp @@ -146,11 +146,12 @@ class ASRToCVisitor : public BaseCCPPVisitor void allocate_array_members_of_struct(ASR::StructType_t* der_type_t, std::string& sub, std::string indent, std::string name) { for( auto itr: der_type_t->m_symtab->get_scope() ) { - if( ASR::is_a(*itr.second) || - ASR::is_a(*itr.second) ) { + ASR::symbol_t *sym = ASRUtils::symbol_get_past_external(itr.second); + if( ASR::is_a(*sym) || + ASR::is_a(*sym) ) { continue ; } - ASR::ttype_t* mem_type = ASRUtils::symbol_type(itr.second); + ASR::ttype_t* mem_type = ASRUtils::symbol_type(sym); if( ASRUtils::is_character(*mem_type) ) { sub += indent + name + "->" + itr.first + " = NULL;\n"; } else if( ASRUtils::is_array(mem_type) && diff --git a/src/libasr/codegen/asr_to_c_cpp.h b/src/libasr/codegen/asr_to_c_cpp.h index e568d0eb95..c060f24431 100644 --- a/src/libasr/codegen/asr_to_c_cpp.h +++ b/src/libasr/codegen/asr_to_c_cpp.h @@ -1305,6 +1305,11 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) { last_expr_precedence = 2; } + void visit_UnsignedIntegerConstant(const ASR::UnsignedIntegerConstant_t &x) { + src = std::to_string(x.m_n); + last_expr_precedence = 2; + } + void visit_RealConstant(const ASR::RealConstant_t &x) { // TODO: remove extra spaces from the front of double_to_scientific result src = double_to_scientific(x.m_r); diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 36d4eb945b..4369419aa3 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -809,7 +809,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Type* max_sized_type = nullptr; size_t max_type_size = 0; for( auto itr = scope.begin(); itr != scope.end(); itr++ ) { - ASR::Variable_t* member = ASR::down_cast(itr->second); + ASR::Variable_t* member = ASR::down_cast(ASRUtils::symbol_get_past_external(itr->second)); llvm::Type* llvm_mem_type = getMemberType(member->m_type, member); size_t type_size = data_layout.getTypeAllocSize(llvm_mem_type); if( max_type_size < type_size ) { @@ -3316,14 +3316,18 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASRUtils::symbol_get_past_external(struct_t->m_derived_type)); std::string struct_type_name = struct_type_t->m_name; for( auto item: struct_type_t->m_symtab->get_scope() ) { - if( ASR::is_a(*item.second) || - ASR::is_a(*item.second) || - ASR::is_a(*item.second) || - ASR::is_a(*item.second) || - ASR::is_a(*item.second) ) { + ASR::symbol_t *sym = ASRUtils::symbol_get_past_external(item.second); + if (name2memidx[struct_type_name].find(item.first) == name2memidx[struct_type_name].end()) { + continue; + } + if( ASR::is_a(*sym) || + ASR::is_a(*sym) || + ASR::is_a(*sym) || + ASR::is_a(*sym) || + ASR::is_a(*sym) ) { continue ; } - ASR::ttype_t* symbol_type = ASRUtils::symbol_type(item.second); + ASR::ttype_t* symbol_type = ASRUtils::symbol_type(sym); int idx = name2memidx[struct_type_name][item.first]; llvm::Value* ptr_member = llvm_utils->create_gep(ptr, idx); ASR::Variable_t* v = nullptr; @@ -8569,7 +8573,7 @@ Result> asr_to_llvm(ASR::TranslationUnit_t &asr, pass_manager.apply_passes(al, &asr, pass_options, diagnostics); // Uncomment for debugging the ASR after the transformation - // std::cout << LFortran::pickle(asr, false, false, false) << std::endl; + // std::cout << LCompilers::LPython::pickle(asr, true, true, false) << std::endl; try { v.visit_asr((ASR::asr_t&)asr); diff --git a/src/libasr/codegen/c_utils.h b/src/libasr/codegen/c_utils.h index c04906d7e9..84dbed81e2 100644 --- a/src/libasr/codegen/c_utils.h +++ b/src/libasr/codegen/c_utils.h @@ -843,26 +843,28 @@ class CCPPDSUtils { + struct_type_str + "* dest)"; func_decls += "inline " + signature + ";\n"; generated_code += indent + signature + " {\n"; - for( auto item: struct_type_t->m_symtab->get_scope() ) { - ASR::ttype_t* member_type_asr = ASRUtils::symbol_type(item.second); + for(size_t i=0; i < struct_type_t->n_members; i++) { + std::string mem_name = std::string(struct_type_t->m_members[i]); + ASR::symbol_t* member = struct_type_t->m_symtab->get_symbol(mem_name); + ASR::ttype_t* member_type_asr = ASRUtils::symbol_type(member); if( CUtils::is_non_primitive_DT(member_type_asr) || ASR::is_a(*member_type_asr) ) { - generated_code += indent + tab + get_deepcopy(member_type_asr, "&(src->" + item.first + ")", - "&(dest->" + item.first + ")") + ";\n"; + generated_code += indent + tab + get_deepcopy(member_type_asr, "&(src->" + mem_name + ")", + "&(dest->" + mem_name + ")") + ";\n"; } else if( ASRUtils::is_array(member_type_asr) ) { ASR::dimension_t* m_dims = nullptr; size_t n_dims = ASRUtils::extract_dimensions_from_ttype(member_type_asr, m_dims); if( ASRUtils::is_fixed_size_array(m_dims, n_dims) ) { std::string array_size = std::to_string(ASRUtils::get_fixed_size_of_array(m_dims, n_dims)); array_size += "*sizeof(" + CUtils::get_c_type_from_ttype_t(member_type_asr) + ")"; - generated_code += indent + tab + "memcpy(dest->" + item.first + ", src->" + item.first + + generated_code += indent + tab + "memcpy(dest->" + mem_name + ", src->" + mem_name + ", " + array_size + ");\n"; } else { - generated_code += indent + tab + get_deepcopy(member_type_asr, "src->" + item.first, - "dest->" + item.first) + ";\n"; + generated_code += indent + tab + get_deepcopy(member_type_asr, "src->" + mem_name, + "dest->" + mem_name) + ";\n"; } } else { - generated_code += indent + tab + "dest->" + item.first + " = " + " src->" + item.first + ";\n"; + generated_code += indent + tab + "dest->" + mem_name + " = " + " src->" + mem_name + ";\n"; } } generated_code += indent + "}\n\n"; diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 07130bb87a..4ca37d8982 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -1315,13 +1315,7 @@ class CommonVisitor : public AST::BaseVisitor { args.p[i].m_value = arg_new_i; } for (size_t i = args.size(); i < StructType->n_members; i++) { - std::string member_name = StructType->m_members[i]; - ASR::Variable_t* member_var = ASR::down_cast( - StructType->m_symtab->resolve_symbol(member_name)); - ASR::call_arg_t arg; - arg.loc = loc; - arg.m_value = member_var->m_value; - args.push_back(al, arg); + args.push_back(al, StructType->m_initializers[i]); } ASR::ttype_t* der_type = ASRUtils::TYPE(ASR::make_Struct_t(al, loc, stemp)); return ASR::make_StructTypeConstructor_t(al, loc, stemp, args.p, args.size(), der_type, nullptr); @@ -2767,8 +2761,10 @@ class CommonVisitor : public AST::BaseVisitor { } void visit_AnnAssignUtil(const AST::AnnAssign_t& x, std::string& var_name, + ASR::expr_t* &init_expr, bool wrap_derived_type_in_pointer=false, - ASR::expr_t* init_expr=nullptr, ASR::abiType abi=ASR::abiType::Source) { + ASR::abiType abi=ASR::abiType::Source, + bool inside_struct=false) { bool is_allocatable = false; ASR::ttype_t *type = ast_expr_to_asr_type(x.base.base.loc, *x.m_annotation, is_allocatable); ASR::ttype_t* ann_assign_target_type_copy = ann_assign_target_type; @@ -2838,8 +2834,13 @@ class CommonVisitor : public AST::BaseVisitor { } if( !is_c_p_pointer_call ) { - create_add_variable_to_scope(var_name, init_expr, type, - x.base.base.loc, abi, storage_type); + if (inside_struct && !ASR::is_a(*type)) { + create_add_variable_to_scope(var_name, nullptr, type, + x.base.base.loc, abi, storage_type); + } else { + create_add_variable_to_scope(var_name, init_expr, type, + x.base.base.loc, abi, storage_type); + } } if (is_allocatable && x.m_value && AST::is_a(*x.m_value)) { @@ -2858,6 +2859,7 @@ class CommonVisitor : public AST::BaseVisitor { void visit_ClassMembers(const AST::ClassDef_t& x, Vec& member_names, SetChar& struct_dependencies, + Vec &member_init, bool is_enum_scope=false, ASR::abiType abi=ASR::abiType::Source) { int64_t prev_value = 1; for( size_t i = 0; i < x.n_body; i++ ) { @@ -2891,8 +2893,12 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t* i64_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, 8)); init_expr = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, x.base.base.loc, -1, i64_type)); } - visit_AnnAssignUtil(*ann_assign, var_name, false, init_expr, abi); + visit_AnnAssignUtil(*ann_assign, var_name, init_expr, false, abi, true); ASR::symbol_t* var_sym = current_scope->resolve_symbol(var_name); + ASR::call_arg_t c_arg; + c_arg.loc = var_sym->base.loc; + c_arg.m_value = init_expr; + member_init.push_back(al, c_arg); if( is_enum_scope ) { if( AST::is_a(*ann_assign->m_value) ) { AST::Call_t* auto_call_cand = AST::down_cast(ann_assign->m_value); @@ -2958,20 +2964,22 @@ class CommonVisitor : public AST::BaseVisitor { void visit_ClassDef(const AST::ClassDef_t& x) { std::string x_m_name = x.m_name; - if( current_scope->resolve_symbol(x_m_name) ) { - return ; - } if( is_enum(x.m_bases, x.n_bases) ) { + if( current_scope->resolve_symbol(x_m_name) ) { + return ; + } ASR::abiType enum_abi = get_abi_from_decorators(x.m_decorator_list, x.n_decorator_list); SymbolTable *parent_scope = current_scope; current_scope = al.make_new(parent_scope); Vec member_names; + Vec member_init; member_names.reserve(al, x.n_body); + member_init.reserve(al, 1); Vec* current_body_copy = current_body; current_body = nullptr; SetChar struct_dependencies; struct_dependencies.reserve(al, 1); - visit_ClassMembers(x, member_names, struct_dependencies, true, enum_abi); + visit_ClassMembers(x, member_names, struct_dependencies, member_init, true, enum_abi); current_body = current_body_copy; ASR::ttype_t* common_type = nullptr; for( auto sym: current_scope->get_scope() ) { @@ -3050,18 +3058,28 @@ class CommonVisitor : public AST::BaseVisitor { SymbolTable *parent_scope = current_scope; current_scope = al.make_new(parent_scope); Vec member_names; + Vec member_init; member_names.reserve(al, x.n_body); + member_init.reserve(al, x.n_body); SetChar struct_dependencies; struct_dependencies.reserve(al, 1); - visit_ClassMembers(x, member_names, struct_dependencies); + visit_ClassMembers(x, member_names, struct_dependencies, member_init); + LCOMPILERS_ASSERT(member_init.size() == member_names.size()); ASR::symbol_t* union_type = ASR::down_cast(ASR::make_UnionType_t(al, x.base.base.loc, current_scope, x.m_name, struct_dependencies.p, struct_dependencies.size(), member_names.p, member_names.size(), ASR::abiType::Source, ASR::accessType::Public, - nullptr)); + member_init.p, member_init.size(), nullptr)); current_scope = parent_scope; - current_scope->add_symbol(std::string(x.m_name), union_type); + if (current_scope->resolve_symbol(x_m_name)) { + ASR::symbol_t* sym = current_scope->resolve_symbol(x_m_name); + ASR::UnionType_t *ut = ASR::down_cast(sym); + ut->m_initializers = member_init.p; + ut->n_initializers = member_init.size(); + } else { + current_scope->add_symbol(x_m_name, union_type); + } return ; } ASR::expr_t* algined_expr = nullptr; @@ -3080,23 +3098,33 @@ class CommonVisitor : public AST::BaseVisitor { SymbolTable *parent_scope = current_scope; current_scope = al.make_new(parent_scope); Vec member_names; + Vec member_init; member_names.reserve(al, x.n_body); + member_init.reserve(al, x.n_body); SetChar struct_dependencies; struct_dependencies.reserve(al, 1); ASR::abiType class_abi = ASR::abiType::Source; if( is_bindc_class(x.m_decorator_list, x.n_decorator_list) ) { class_abi = ASR::abiType::BindC; } - visit_ClassMembers(x, member_names, struct_dependencies, false, class_abi); + visit_ClassMembers(x, member_names, struct_dependencies, member_init, false, class_abi); + LCOMPILERS_ASSERT(member_init.size() == member_names.size()); ASR::symbol_t* class_type = ASR::down_cast(ASR::make_StructType_t(al, x.base.base.loc, current_scope, x.m_name, struct_dependencies.p, struct_dependencies.size(), member_names.p, member_names.size(), class_abi, ASR::accessType::Public, - is_packed, false, algined_expr, + is_packed, false, member_init.p, member_init.size(), algined_expr, nullptr)); current_scope = parent_scope; - current_scope->add_symbol(std::string(x.m_name), class_type); + if (current_scope->resolve_symbol(x_m_name)) { + ASR::symbol_t* sym = current_scope->resolve_symbol(x_m_name); + ASR::StructType_t *st = ASR::down_cast(sym); + st->m_initializers = member_init.p; + st->n_initializers = member_init.size(); + } else { + current_scope->add_symbol(x_m_name, class_type); + } } void add_name(const Location &loc) { @@ -4845,8 +4873,8 @@ class BodyVisitor : public CommonVisitor { })); } } - - visit_AnnAssignUtil(x, var_name); + ASR::expr_t *init_expr = nullptr; + visit_AnnAssignUtil(x, var_name, init_expr); assign_ast_target = assign_ast_target_copy; } diff --git a/tests/reference/asr-array_01_decl-39cf894.json b/tests/reference/asr-array_01_decl-39cf894.json index a96a84d05f..67b87c3f97 100644 --- a/tests/reference/asr-array_01_decl-39cf894.json +++ b/tests/reference/asr-array_01_decl-39cf894.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-array_01_decl-39cf894.stdout", - "stdout_hash": "670c914b3851f034855be4bc0d0672dedb9d81bdf8afb85a4d7a09ba", + "stdout_hash": "f8ba6c730aea2846362708c15bb4ff33f587f833f791d26b55fc70b8", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-array_01_decl-39cf894.stdout b/tests/reference/asr-array_01_decl-39cf894.stdout index 803735aeb0..a294f478d2 100644 --- a/tests/reference/asr-array_01_decl-39cf894.stdout +++ b/tests/reference/asr-array_01_decl-39cf894.stdout @@ -19,7 +19,7 @@ [] Local (IntegerConstant 10 (Integer 4)) - (IntegerConstant -1 (Integer 8)) + () Default (Integer 4) () @@ -35,7 +35,7 @@ [] Local (IntegerConstant 3 (Integer 4)) - (IntegerConstant -1 (Integer 8)) + () Default (Integer 4) () diff --git a/tests/reference/asr-intent_01-66824bc.json b/tests/reference/asr-intent_01-66824bc.json index a4b3c8871c..a78386d973 100644 --- a/tests/reference/asr-intent_01-66824bc.json +++ b/tests/reference/asr-intent_01-66824bc.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-intent_01-66824bc.stdout", - "stdout_hash": "3e31bd2856093504660cf2523bd5e1170e70390d0ba9e448e9d18556", + "stdout_hash": "c0705fb1198e342bcc4b376fd83d8b981654f48cf14b8e563bb0ed2e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-intent_01-66824bc.stdout b/tests/reference/asr-intent_01-66824bc.stdout index a8d6aa9d80..aa57159988 100644 --- a/tests/reference/asr-intent_01-66824bc.stdout +++ b/tests/reference/asr-intent_01-66824bc.stdout @@ -5,7 +5,7 @@ _global_symbols: (Module (SymbolTable - 5 + 6 { Foo: (StructType @@ -36,6 +36,7 @@ Public .false. .false. + [(())] () () ), @@ -55,7 +56,7 @@ Default (Array (Struct - 5 Foo + 6 Foo ) [((IntegerConstant 0 (Integer 4)) (IntegerConstant 5 (Integer 4)))] @@ -130,7 +131,7 @@ ) (Array (Struct - 5 Foo + 6 Foo ) [((IntegerConstant 0 (Integer 4)) (IntegerConstant 5 (Integer 4)))] @@ -169,7 +170,7 @@ main_program: (Program (SymbolTable - 4 + 5 { }) diff --git a/tests/reference/asr-structs_01-66dc2c9.json b/tests/reference/asr-structs_01-66dc2c9.json index 83c2603b5c..330b5aab93 100644 --- a/tests/reference/asr-structs_01-66dc2c9.json +++ b/tests/reference/asr-structs_01-66dc2c9.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_01-66dc2c9.stdout", - "stdout_hash": "de1e0ae69531d96b875d6da5c8885d25f39bfaf8b58ab8e0fe94d644", + "stdout_hash": "f4abca45051c53d030a0ed049e37e9d22069b73321bc9f4adf4842ce", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_01-66dc2c9.stdout b/tests/reference/asr-structs_01-66dc2c9.stdout index 2a64f2b310..e3f76bef12 100644 --- a/tests/reference/asr-structs_01-66dc2c9.stdout +++ b/tests/reference/asr-structs_01-66dc2c9.stdout @@ -5,7 +5,7 @@ _global_symbols: (Module (SymbolTable - 6 + 7 { S: (StructType @@ -53,13 +53,15 @@ Public .false. .false. + [(()) + (())] () () ), _lpython_main_program: (Function (SymbolTable - 5 + 6 { }) @@ -82,7 +84,7 @@ [main0] [] [(SubroutineCall - 6 main0 + 7 main0 () [] () @@ -108,7 +110,7 @@ () Default (Struct - 6 S + 7 S ) () Source @@ -138,11 +140,11 @@ [(= (Var 3 s) (StructTypeConstructor - 6 S + 7 S [((IntegerConstant 2 (Integer 4))) (())] (Struct - 6 S + 7 S ) () ) @@ -163,13 +165,13 @@ main_program: (Program (SymbolTable - 4 + 5 { _lpython_main_program: (ExternalSymbol - 4 + 5 _lpython_main_program - 6 _lpython_main_program + 7 _lpython_main_program _global_symbols [] _lpython_main_program @@ -179,7 +181,7 @@ main_program [_global_symbols] [(SubroutineCall - 4 _lpython_main_program + 5 _lpython_main_program () [] () diff --git a/tests/reference/asr-structs_01-be14d49.json b/tests/reference/asr-structs_01-be14d49.json index 542aad7cbf..73a464266f 100644 --- a/tests/reference/asr-structs_01-be14d49.json +++ b/tests/reference/asr-structs_01-be14d49.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_01-be14d49.stdout", - "stdout_hash": "abaac1320ea7c83ced0b27e66209c126ba59487ef2230d446992f4a7", + "stdout_hash": "e649bec597d2b56125b28cffe90f5577bc3b94ae504ecf667ad6f4e2", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_01-be14d49.stdout b/tests/reference/asr-structs_01-be14d49.stdout index 8bbdddfc96..1eef95021e 100644 --- a/tests/reference/asr-structs_01-be14d49.stdout +++ b/tests/reference/asr-structs_01-be14d49.stdout @@ -5,7 +5,7 @@ _global_symbols: (Module (SymbolTable - 8 + 9 { A: (StructType @@ -53,13 +53,15 @@ Public .false. .false. + [(()) + (())] () () ), _lpython_main_program: (Function (SymbolTable - 7 + 8 { }) @@ -82,7 +84,7 @@ [g] [] [(SubroutineCall - 8 g + 9 g () [] () @@ -108,7 +110,7 @@ () Default (Struct - 8 A + 9 A ) () Source @@ -120,7 +122,7 @@ change_struct (FunctionType [(Struct - 8 A + 9 A )] () Source @@ -208,7 +210,7 @@ () Default (Struct - 8 A + 9 A ) () Source @@ -220,7 +222,7 @@ f (FunctionType [(Struct - 8 A + 9 A )] () Source @@ -280,7 +282,7 @@ () Default (Struct - 8 A + 9 A ) () Source @@ -311,7 +313,7 @@ [(= (Var 5 x) (StructTypeConstructor - 8 A + 9 A [((Cast (RealConstant 3.250000 @@ -326,14 +328,14 @@ )) ((IntegerConstant 3 (Integer 4)))] (Struct - 8 A + 9 A ) () ) () ) (SubroutineCall - 8 f + 9 f () [((Var 5 x))] () @@ -408,7 +410,7 @@ () ) (SubroutineCall - 8 f + 9 f () [((Var 5 x))] () @@ -452,7 +454,7 @@ () ) (SubroutineCall - 8 change_struct + 9 change_struct () [((Var 5 x))] () @@ -510,13 +512,13 @@ main_program: (Program (SymbolTable - 6 + 7 { _lpython_main_program: (ExternalSymbol - 6 + 7 _lpython_main_program - 8 _lpython_main_program + 9 _lpython_main_program _global_symbols [] _lpython_main_program @@ -526,7 +528,7 @@ main_program [_global_symbols] [(SubroutineCall - 6 _lpython_main_program + 7 _lpython_main_program () [] () diff --git a/tests/reference/asr-structs_02-2ab459a.json b/tests/reference/asr-structs_02-2ab459a.json index 44f40e24de..2056a9f832 100644 --- a/tests/reference/asr-structs_02-2ab459a.json +++ b/tests/reference/asr-structs_02-2ab459a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_02-2ab459a.stdout", - "stdout_hash": "d00a784956e717045fd5bb8f917b315f717754c7e11069b96d3d3b57", + "stdout_hash": "e5df0fb84bfc694b884736c1c4a5ddaec25933d8dba54e894de3e961", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_02-2ab459a.stdout b/tests/reference/asr-structs_02-2ab459a.stdout index 83d7c4fd50..feaf95ffa6 100644 --- a/tests/reference/asr-structs_02-2ab459a.stdout +++ b/tests/reference/asr-structs_02-2ab459a.stdout @@ -5,7 +5,7 @@ _global_symbols: (Module (SymbolTable - 7 + 8 { A: (StructType @@ -53,13 +53,15 @@ Public .false. .false. + [(()) + (())] () () ), _lpython_main_program: (Function (SymbolTable - 6 + 7 { }) @@ -82,7 +84,7 @@ [g] [] [(SubroutineCall - 7 g + 8 g () [] () @@ -124,7 +126,7 @@ () Default (Struct - 7 A + 8 A ) () Source @@ -143,7 +145,7 @@ Default (Pointer (Struct - 7 A + 8 A ) ) () @@ -206,7 +208,7 @@ [(= (Var 3 a1) (StructTypeConstructor - 7 A + 8 A [((IntegerConstant 3 (Integer 4))) ((Cast (RealConstant @@ -221,7 +223,7 @@ ) ))] (Struct - 7 A + 8 A ) () ) @@ -233,7 +235,7 @@ (Var 3 a1) (Pointer (Struct - 7 A + 8 A ) ) () @@ -247,7 +249,7 @@ (Var 3 a1) (Pointer (Struct - 7 A + 8 A ) ) () @@ -317,7 +319,7 @@ (Var 3 a1) (Pointer (Struct - 7 A + 8 A ) ) () @@ -379,7 +381,7 @@ () ) (SubroutineCall - 7 f + 8 f () [((Var 4 b))] () @@ -399,13 +401,13 @@ main_program: (Program (SymbolTable - 5 + 6 { _lpython_main_program: (ExternalSymbol - 5 + 6 _lpython_main_program - 7 _lpython_main_program + 8 _lpython_main_program _global_symbols [] _lpython_main_program @@ -415,7 +417,7 @@ main_program [_global_symbols] [(SubroutineCall - 5 _lpython_main_program + 6 _lpython_main_program () [] () diff --git a/tests/reference/asr-structs_03-0cef911.json b/tests/reference/asr-structs_03-0cef911.json index 82bb41f46f..c32ac21d52 100644 --- a/tests/reference/asr-structs_03-0cef911.json +++ b/tests/reference/asr-structs_03-0cef911.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_03-0cef911.stdout", - "stdout_hash": "8c73f5c2455f451863f0d73c754e5fbc66c2bf5416e3af26e576ec76", + "stdout_hash": "20115d1f8dca7941b29396a78cdbe47268a66c5206935057f46b4eac", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_03-0cef911.stdout b/tests/reference/asr-structs_03-0cef911.stdout index b272a69a50..2945263e02 100644 --- a/tests/reference/asr-structs_03-0cef911.stdout +++ b/tests/reference/asr-structs_03-0cef911.stdout @@ -5,7 +5,7 @@ _global_symbols: (Module (SymbolTable - 7 + 8 { A: (StructType @@ -53,13 +53,15 @@ Public .false. .false. + [(()) + (())] () () ), _lpython_main_program: (Function (SymbolTable - 6 + 7 { }) @@ -82,7 +84,7 @@ [g] [] [(SubroutineCall - 7 g + 8 g () [] () @@ -109,7 +111,7 @@ Default (Pointer (Struct - 7 A + 8 A ) ) () @@ -123,7 +125,7 @@ (FunctionType [(Pointer (Struct - 7 A + 8 A ) )] () @@ -184,7 +186,7 @@ () Default (Struct - 7 A + 8 A ) () Source @@ -203,7 +205,7 @@ Default (Pointer (Struct - 7 A + 8 A ) ) () @@ -234,7 +236,7 @@ [(= (Var 4 x) (StructTypeConstructor - 7 A + 8 A [((IntegerConstant 3 (Integer 4))) ((Cast (RealConstant @@ -249,7 +251,7 @@ ) ))] (Struct - 7 A + 8 A ) () ) @@ -261,7 +263,7 @@ (Var 4 x) (Pointer (Struct - 7 A + 8 A ) ) () @@ -338,7 +340,7 @@ () ) (SubroutineCall - 7 f + 8 f () [((Var 4 xp))] () @@ -358,13 +360,13 @@ main_program: (Program (SymbolTable - 5 + 6 { _lpython_main_program: (ExternalSymbol - 5 + 6 _lpython_main_program - 7 _lpython_main_program + 8 _lpython_main_program _global_symbols [] _lpython_main_program @@ -374,7 +376,7 @@ main_program [_global_symbols] [(SubroutineCall - 5 _lpython_main_program + 6 _lpython_main_program () [] () diff --git a/tests/reference/asr-structs_04-387747b.json b/tests/reference/asr-structs_04-387747b.json index 979a329bc9..49c4f009fa 100644 --- a/tests/reference/asr-structs_04-387747b.json +++ b/tests/reference/asr-structs_04-387747b.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_04-387747b.stdout", - "stdout_hash": "eafcbb90004b8a67322c5ca8856378aeb538be88fdbe3ce17f581e30", + "stdout_hash": "6455b9b06618ea7e76fadf9c0b64d01072e76d067ffd163d2bf8001e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_04-387747b.stdout b/tests/reference/asr-structs_04-387747b.stdout index 23c8d91642..5c5bd1208d 100644 --- a/tests/reference/asr-structs_04-387747b.stdout +++ b/tests/reference/asr-structs_04-387747b.stdout @@ -5,7 +5,7 @@ _global_symbols: (Module (SymbolTable - 8 + 10 { A: (StructType @@ -53,6 +53,8 @@ Public .false. .false. + [(()) + (())] () () ), @@ -71,7 +73,7 @@ () Default (Struct - 8 A + 10 A ) () Source @@ -104,13 +106,34 @@ Public .false. .false. + [(()) + ((StructTypeConstructor + 10 A + [((Cast + (RealConstant + 0.000000 + (Real 8) + ) + RealToReal + (Real 4) + (RealConstant + 0.000000 + (Real 4) + ) + )) + ((IntegerConstant 0 (Integer 4)))] + (Struct + 10 A + ) + () + ))] () () ), _lpython_main_program: (Function (SymbolTable - 7 + 9 { }) @@ -133,7 +156,7 @@ [g] [] [(SubroutineCall - 8 g + 10 g () [] () @@ -159,7 +182,7 @@ () Default (Struct - 8 B + 10 B ) () Source @@ -171,7 +194,7 @@ f (FunctionType [(Struct - 8 B + 10 B )] () Source @@ -201,7 +224,7 @@ (Var 4 b) 3 a (Struct - 8 A + 10 A ) () ) @@ -214,7 +237,7 @@ (Var 4 b) 3 a (Struct - 8 A + 10 A ) () ) @@ -247,7 +270,7 @@ (Var 4 b) 3 a (Struct - 8 A + 10 A ) () ) @@ -270,7 +293,7 @@ (Var 4 b) 3 a (Struct - 8 A + 10 A ) () ) @@ -313,7 +336,7 @@ () Default (Struct - 8 A + 10 A ) () Source @@ -331,7 +354,7 @@ () Default (Struct - 8 A + 10 A ) () Source @@ -349,7 +372,7 @@ () Default (Struct - 8 B + 10 B ) () Source @@ -379,7 +402,7 @@ [(= (Var 5 a1) (StructTypeConstructor - 8 A + 10 A [((Cast (RealConstant 1.000000 @@ -394,7 +417,7 @@ )) ((IntegerConstant 1 (Integer 4)))] (Struct - 8 A + 10 A ) () ) @@ -403,7 +426,7 @@ (= (Var 5 a2) (StructTypeConstructor - 8 A + 10 A [((Cast (RealConstant 2.000000 @@ -418,7 +441,7 @@ )) ((IntegerConstant 2 (Integer 4)))] (Struct - 8 A + 10 A ) () ) @@ -427,11 +450,11 @@ (= (Var 5 b) (StructTypeConstructor - 8 B + 10 B [((IntegerConstant 1 (Integer 4))) ((Var 5 a1))] (Struct - 8 B + 10 B ) () ) @@ -442,7 +465,7 @@ (Var 5 b) 3 a (Struct - 8 A + 10 A ) () ) @@ -465,7 +488,7 @@ (Var 5 b) 3 a (Struct - 8 A + 10 A ) () ) @@ -482,7 +505,7 @@ (Var 5 b) 3 a (Struct - 8 A + 10 A ) () ) @@ -581,7 +604,7 @@ () ) (SubroutineCall - 8 f + 10 f () [((Var 5 b))] () @@ -601,13 +624,13 @@ main_program: (Program (SymbolTable - 6 + 8 { _lpython_main_program: (ExternalSymbol - 6 + 8 _lpython_main_program - 8 _lpython_main_program + 10 _lpython_main_program _global_symbols [] _lpython_main_program @@ -617,7 +640,7 @@ main_program [_global_symbols] [(SubroutineCall - 6 _lpython_main_program + 8 _lpython_main_program () [] () diff --git a/tests/reference/asr-structs_05-fa98307.json b/tests/reference/asr-structs_05-fa98307.json index 8d28e8d8e5..152e6eb1c3 100644 --- a/tests/reference/asr-structs_05-fa98307.json +++ b/tests/reference/asr-structs_05-fa98307.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_05-fa98307.stdout", - "stdout_hash": "f965c641d2970ca777a23442ec9f061e9a4240a31e5f0c25eba29623", + "stdout_hash": "89178aaa9800865290a98917ec98733999257c474639ebb3019454bc", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_05-fa98307.stdout b/tests/reference/asr-structs_05-fa98307.stdout index 7a3e808533..bcdae0a6ce 100644 --- a/tests/reference/asr-structs_05-fa98307.stdout +++ b/tests/reference/asr-structs_05-fa98307.stdout @@ -5,7 +5,7 @@ _global_symbols: (Module (SymbolTable - 206 + 207 { A: (StructType @@ -138,13 +138,20 @@ Public .false. .false. + [(()) + (()) + (()) + (()) + (()) + (()) + (())] () () ), _lpython_main_program: (Function (SymbolTable - 205 + 206 { }) @@ -167,7 +174,7 @@ [g] [] [(SubroutineCall - 206 g + 207 g () [] () @@ -194,7 +201,7 @@ Default (Array (Struct - 206 A + 207 A ) [((IntegerConstant 0 (Integer 4)) (IntegerConstant 2 (Integer 4)))] @@ -233,13 +240,13 @@ (IntegerConstant 0 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () ) (StructTypeConstructor - 206 A + 207 A [((RealConstant 1.100000 (Real 8) @@ -280,7 +287,7 @@ (Logical 4) ))] (Struct - 206 A + 207 A ) () ) @@ -293,13 +300,13 @@ (IntegerConstant 1 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () ) (StructTypeConstructor - 206 A + 207 A [((RealConstant 2.200000 (Real 8) @@ -340,14 +347,14 @@ (Logical 4) ))] (Struct - 206 A + 207 A ) () ) () ) (SubroutineCall - 206 verify + 207 verify () [((Var 203 y)) ((IntegerConstant 1 (Integer 4))) @@ -363,7 +370,7 @@ () ) (SubroutineCall - 206 update_1 + 207 update_1 () [((ArrayItem (Var 203 y) @@ -371,7 +378,7 @@ (IntegerConstant 0 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () @@ -379,13 +386,13 @@ () ) (SubroutineCall - 206 update_2 + 207 update_2 () [((Var 203 y))] () ) (SubroutineCall - 206 verify + 207 verify () [((Var 203 y)) ((IntegerConstant 2 (Integer 4))) @@ -421,7 +428,7 @@ () Default (Struct - 206 A + 207 A ) () Source @@ -433,7 +440,7 @@ update_1 (FunctionType [(Struct - 206 A + 207 A )] () Source @@ -561,7 +568,7 @@ Default (Array (Struct - 206 A + 207 A ) [(() ())] @@ -577,7 +584,7 @@ (FunctionType [(Array (Struct - 206 A + 207 A ) [(() ())] @@ -605,7 +612,7 @@ (IntegerConstant 1 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () @@ -625,7 +632,7 @@ (IntegerConstant 1 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () @@ -648,7 +655,7 @@ (IntegerConstant 1 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () @@ -673,7 +680,7 @@ (IntegerConstant 1 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () @@ -704,7 +711,7 @@ (IntegerConstant 1 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () @@ -729,7 +736,7 @@ (IntegerConstant 1 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () @@ -784,7 +791,7 @@ Default (Array (Struct - 206 A + 207 A ) [(() ())] @@ -805,7 +812,7 @@ () Default (Struct - 206 A + 207 A ) () Source @@ -823,7 +830,7 @@ () Default (Struct - 206 A + 207 A ) () Source @@ -900,7 +907,7 @@ (FunctionType [(Array (Struct - 206 A + 207 A ) [(() ())] @@ -944,7 +951,7 @@ (IntegerConstant 0 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () @@ -1160,7 +1167,7 @@ (IntegerConstant 1 (Integer 4)) ())] (Struct - 206 A + 207 A ) RowMajor () @@ -1385,13 +1392,13 @@ main_program: (Program (SymbolTable - 204 + 205 { _lpython_main_program: (ExternalSymbol - 204 + 205 _lpython_main_program - 206 _lpython_main_program + 207 _lpython_main_program _global_symbols [] _lpython_main_program @@ -1401,7 +1408,7 @@ main_program [_global_symbols] [(SubroutineCall - 204 _lpython_main_program + 205 _lpython_main_program () [] ()