@@ -210,17 +210,6 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
210210 return dummy_variable_sym;
211211 }
212212
213- ASR::asr_t * make_Assignment_t_util (Allocator &al, const Location &a_loc,
214- ASR::expr_t * a_target, ASR::expr_t * a_value, ASR::stmt_t * a_overloaded) {
215- if ( ASR::is_a<ASR::AddressOf_t>(*a_value) ) {
216- a_value = ASRUtils::EXPR (ASR::make_Var_t (al, a_value->base .loc ,
217- ASR::down_cast<ASR::AddressOf_t>(a_value)->m_v ));
218- return ASR::make_Associate_t (al, a_loc, a_target, a_value);
219- }
220-
221- return ASR::make_Assignment_t (al, a_loc, a_target, a_value, a_overloaded);
222- }
223-
224213 void construct_program () {
225214 // Convert the main function into a program
226215 ASR::TranslationUnit_t* tu = (ASR::TranslationUnit_t*)this ->tu ;
@@ -247,7 +236,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
247236
248237 ASR::symbol_t * exit_variable_sym = declare_dummy_variable (" exit_code" , program_scope, loc, int32_type);
249238 ASR::expr_t * variable_var = ASRUtils::EXPR (ASR::make_Var_t (al, loc, exit_variable_sym));
250- ASR::asr_t * assign_stmt = make_Assignment_t_util (al, loc, variable_var, ASRUtils::EXPR (func_call_main), nullptr );
239+ ASR::asr_t * assign_stmt = ASR::make_Assignment_t (al, loc, variable_var, ASRUtils::EXPR (func_call_main), nullptr );
251240
252241 prog_body.push_back (al, ASRUtils::STMT (assign_stmt));
253242
@@ -737,7 +726,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
737726 ASR::expr_t * value = ASRUtils::EXPR (tmp.get ());
738727 cast_helper (obj, value, true );
739728 ASRUtils::make_ArrayBroadcast_t_util (al, Lloc (x), obj, value);
740- tmp = make_Assignment_t_util (al, Lloc (x), obj, value, nullptr );
729+ tmp = ASR::make_Assignment_t (al, Lloc (x), obj, value, nullptr );
741730 is_stmt_created = true ;
742731 }
743732 assignment_target = nullptr ;
@@ -748,7 +737,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
748737 if ( !is_stmt_created ) {
749738 ASR::expr_t * value = ASRUtils::EXPR (tmp.get ());
750739 cast_helper (obj, value, true );
751- tmp = make_Assignment_t_util (al, Lloc (x), obj, value, nullptr );
740+ tmp = ASR::make_Assignment_t (al, Lloc (x), obj, value, nullptr );
752741 is_stmt_created = true ;
753742 }
754743 assignment_target = nullptr ;
@@ -973,7 +962,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
973962 ASR::abiType::Source, false , target_physical_type, override_physical_type, false );
974963 ASR::expr_t * new_shape = ASRUtils::cast_to_descriptor (al, args.p [0 ]);
975964 tmp = ASR::make_ArrayReshape_t (al, Lloc (x), callee, new_shape, target_type, nullptr );
976- tmp = make_Assignment_t_util (al, Lloc (x), callee, ASRUtils::EXPR (tmp.get ()), nullptr );
965+ tmp = ASR::make_Assignment_t (al, Lloc (x), callee, ASRUtils::EXPR (tmp.get ()), nullptr );
977966 is_stmt_created = true ;
978967 } else if (sf == SpecialFunc::Size) {
979968 if ( args.size () != 0 ) {
@@ -993,7 +982,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
993982
994983 ASR::expr_t * arg = args.p [0 ];
995984 ASRUtils::make_ArrayBroadcast_t_util (al, Lloc (x), callee, arg);
996- tmp = make_Assignment_t_util (al, Lloc (x), callee, arg, nullptr );
985+ tmp = ASR::make_Assignment_t (al, Lloc (x), callee, arg, nullptr );
997986 is_stmt_created = true ;
998987 } else if ( sf == SpecialFunc::All ) {
999988 // Handles xt::all() - no arguments
@@ -1342,7 +1331,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
13421331 if ( tmp != nullptr && !is_stmt_created ) {
13431332 ASR::expr_t * init_val = ASRUtils::EXPR (tmp.get ());
13441333 add_reshape_if_needed (init_val, var);
1345- tmp = make_Assignment_t_util (al, Lloc (x), var, init_val, nullptr );
1334+ tmp = ASR::make_Assignment_t (al, Lloc (x), var, init_val, nullptr );
13461335 is_stmt_created = true ;
13471336 }
13481337 }
@@ -1556,7 +1545,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
15561545 if ( op == clang::BO_Assign ) {
15571546 cast_helper (x_lhs, x_rhs, true );
15581547 ASRUtils::make_ArrayBroadcast_t_util (al, Lloc (x), x_lhs, x_rhs);
1559- tmp = make_Assignment_t_util (al, Lloc (x), x_lhs, x_rhs, nullptr );
1548+ tmp = ASR::make_Assignment_t (al, Lloc (x), x_lhs, x_rhs, nullptr );
15601549 is_stmt_created = true ;
15611550 } else {
15621551 bool is_binop = false , is_cmpop = false ;
@@ -1700,10 +1689,22 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
17001689 }
17011690
17021691 void cast_helper (ASR::expr_t *& left, ASR::expr_t *& right, bool is_assign) {
1692+ bool no_cast = ((ASR::is_a<ASR::Pointer_t>(*ASRUtils::expr_type (left)) &&
1693+ ASR::is_a<ASR::Var_t>(*left)) ||
1694+ (ASR::is_a<ASR::Pointer_t>(*ASRUtils::expr_type (right)) &&
1695+ ASR::is_a<ASR::Var_t>(*right)));
17031696 ASR::ttype_t *right_type = ASRUtils::expr_type (right);
17041697 ASR::ttype_t *left_type = ASRUtils::expr_type (left);
17051698 left_type = ASRUtils::extract_type (left_type);
17061699 right_type = ASRUtils::extract_type (right_type);
1700+ if ( no_cast ) {
1701+ int lkind = ASRUtils::extract_kind_from_ttype_t (left_type);
1702+ int rkind = ASRUtils::extract_kind_from_ttype_t (right_type);
1703+ if ( left_type->type != right_type->type || lkind != rkind ) {
1704+ throw SemanticError (" Casting for mismatching pointer types not supported yet." ,
1705+ right_type->base .loc );
1706+ }
1707+ }
17071708
17081709 // Handle presence of logical types in binary operations
17091710 // by converting them into 32-bit integers.
@@ -1889,7 +1890,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
18891890 ASR::symbol_t * return_sym = current_scope->resolve_symbol (" __return_var" );
18901891 ASR::expr_t * return_var = ASRUtils::EXPR (ASR::make_Var_t (al, Lloc (x), return_sym));
18911892 TraverseStmt (x->getRetValue ());
1892- tmp = make_Assignment_t_util (al, Lloc (x), return_var, ASRUtils::EXPR (tmp.get ()), nullptr );
1893+ tmp = ASR::make_Assignment_t (al, Lloc (x), return_var, ASRUtils::EXPR (tmp.get ()), nullptr );
18931894 current_body->push_back (al, ASRUtils::STMT (tmp.get ()));
18941895 tmp = ASR::make_Return_t (al, Lloc (x));
18951896 is_stmt_created = true ;
@@ -1942,7 +1943,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
19421943 ASR::expr_t * x_rhs = ASRUtils::EXPR (tmp.get ());
19431944 CreateBinOp (x_lhs, x_rhs, ASR::binopType::Add, Lloc (x));
19441945 ASR::expr_t * sum_expr = ASRUtils::EXPR (tmp.get ());
1945- tmp = make_Assignment_t_util (al, Lloc (x), x_lhs, sum_expr, nullptr );
1946+ tmp = ASR::make_Assignment_t (al, Lloc (x), x_lhs, sum_expr, nullptr );
19461947 is_stmt_created = true ;
19471948 return true ;
19481949 }
@@ -1959,7 +1960,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
19591960 ASRUtils::EXPR (ASR::make_IntegerConstant_t (
19601961 al, Lloc (x), 1 , ASRUtils::expr_type (var))),
19611962 ASRUtils::expr_type (var), nullptr ));
1962- tmp = make_Assignment_t_util (al, Lloc (x), var, incbyone, nullptr );
1963+ tmp = ASR::make_Assignment_t (al, Lloc (x), var, incbyone, nullptr );
19631964 is_stmt_created = true ;
19641965 break ;
19651966 }
@@ -1971,31 +1972,8 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
19711972 CreateLogicalNot (var, Lloc (x));
19721973 break ;
19731974 }
1974- case clang::UnaryOperatorKind::UO_AddrOf: {
1975- if ( !ASR::is_a<ASR::Var_t>(*var) ) {
1976- throw std::runtime_error (" Address of operator is only supported for symbols." );
1977- }
1978-
1979- ASR::Var_t* var_t = ASR::down_cast<ASR::Var_t>(var);
1980- tmp = ASR::make_AddressOf_t (al, Lloc (x), var_t ->m_v , ASRUtils::TYPE (
1981- ASR::make_Pointer_t (al, Lloc (x), ASRUtils::expr_type (var))));
1982- is_stmt_created = false ;
1983- break ;
1984- }
1985- case clang::UnaryOperatorKind::UO_Deref: {
1986- if ( !ASR::is_a<ASR::Var_t>(*var) ) {
1987- throw std::runtime_error (" Dereference operator is only supported for symbols." );
1988- }
1989-
1990- ASR::Var_t* var_t = ASR::down_cast<ASR::Var_t>(var);
1991- tmp = ASR::make_DereferencePointer_t (al, Lloc (x), var_t ->m_v ,
1992- ASRUtils::type_get_past_pointer (ASRUtils::expr_type (var)));
1993- is_stmt_created = false ;
1994- break ;
1995- }
19961975 default : {
1997- throw std::runtime_error (" Only postfix increment, minus and "
1998- " address of operators are supported so far." );
1976+ throw std::runtime_error (" Only postfix increment and minus are supported so far." );
19991977 }
20001978 }
20011979 return true ;
0 commit comments