@@ -498,7 +498,6 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
498
498
Vec<ASR::stmt_t *> *current_body;
499
499
ASR::ttype_t * ann_assign_target_type;
500
500
AST::expr_t * assign_ast_target;
501
- bool is_c_p_pointer_call;
502
501
503
502
std::map<std::string, int > generic_func_nums;
504
503
std::map<std::string, std::map<std::string, ASR::ttype_t *>> generic_func_subs;
@@ -535,7 +534,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
535
534
: diag{diagnostics}, al{al}, lm{lm}, current_scope{symbol_table}, main_module{main_module}, module_name{module_name},
536
535
ast_overload{ast_overload}, parent_dir{parent_dir}, import_paths{import_paths},
537
536
current_body{nullptr }, ann_assign_target_type{nullptr },
538
- assign_ast_target{nullptr }, is_c_p_pointer_call{ false }, allow_implicit_casting{allow_implicit_casting_} {
537
+ assign_ast_target{nullptr }, allow_implicit_casting{allow_implicit_casting_} {
539
538
current_module_dependencies.reserve (al, 4 );
540
539
global_init.reserve (al, 1 );
541
540
}
@@ -3023,14 +3022,12 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
3023
3022
type = ASRUtils::TYPE (ASR::make_Allocatable_t (al, type->base .loc ,
3024
3023
ASRUtils::type_get_past_pointer (type)));
3025
3024
}
3026
- bool is_c_p_pointer_call_copy = is_c_p_pointer_call;
3027
- ASR::expr_t *value = nullptr ;
3025
+
3028
3026
create_add_variable_to_scope (var_name, type,
3029
3027
x.base .base .loc , abi, storage_type);
3030
3028
3031
3029
if ( !init_expr ) {
3032
3030
tmp = nullptr ;
3033
- is_c_p_pointer_call = false ;
3034
3031
if (x.m_value ) {
3035
3032
this ->visit_expr (*x.m_value );
3036
3033
} else {
@@ -3040,13 +3037,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
3040
3037
ASRUtils::type_to_str_python (type), x.base .base .loc );
3041
3038
}
3042
3039
}
3043
- if ( is_c_p_pointer_call ) {
3044
- create_add_variable_to_scope (var_name, nullptr , type,
3045
- x.base .base .loc , abi, storage_type);
3046
- AST::Call_t* c_p_pointer_call = AST::down_cast<AST::Call_t>(x.m_value );
3047
- tmp = create_CPtrToPointer (*c_p_pointer_call);
3048
- } else if (tmp) {
3049
- value = ASRUtils::EXPR (tmp);
3040
+ if (tmp && ASR::is_a<ASR::expr_t >(*tmp)) {
3041
+ ASR::expr_t * value = ASRUtils::EXPR (tmp);
3050
3042
ASR::ttype_t * underlying_type = type;
3051
3043
if ( ASR::is_a<ASR::Const_t>(*type) ) {
3052
3044
underlying_type = ASRUtils::get_contained_type (type);
@@ -3070,10 +3062,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
3070
3062
cast_helper (type, init_expr, init_expr->base .loc );
3071
3063
}
3072
3064
3073
- if ( !is_c_p_pointer_call ) {
3074
- if (!inside_struct || ASR::is_a<ASR::Const_t>(*type)) {
3075
- process_variable_init_val (current_scope->get_symbol (var_name), x.base .base .loc , init_expr);
3076
- }
3065
+ if (!inside_struct || ASR::is_a<ASR::Const_t>(*type)) {
3066
+ process_variable_init_val (current_scope->get_symbol (var_name), x.base .base .loc , init_expr);
3077
3067
}
3078
3068
3079
3069
if (is_allocatable && x.m_value && AST::is_a<AST::Call_t>(*x.m_value )) {
@@ -3083,10 +3073,10 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
3083
3073
}
3084
3074
}
3085
3075
3086
- if ( !is_c_p_pointer_call ) {
3076
+ if ( !(tmp && ASR::is_a<ASR::stmt_t >(*tmp) &&
3077
+ ASR::is_a<ASR::CPtrToPointer_t>(*ASR::down_cast<ASR::stmt_t >(tmp))) ) {
3087
3078
tmp = nullptr ;
3088
3079
}
3089
- is_c_p_pointer_call = is_c_p_pointer_call_copy;
3090
3080
ann_assign_target_type = ann_assign_target_type_copy;
3091
3081
}
3092
3082
@@ -5253,18 +5243,13 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
5253
5243
ASR::expr_t *target, *assign_value = nullptr , *tmp_value;
5254
5244
AST::expr_t * assign_ast_target_copy = assign_ast_target;
5255
5245
assign_ast_target = x.m_targets [0 ];
5256
- bool is_c_p_pointer_call_copy = is_c_p_pointer_call;
5257
- is_c_p_pointer_call = false ;
5258
5246
this ->visit_expr (*x.m_value );
5259
- if ( is_c_p_pointer_call ) {
5260
- LCOMPILERS_ASSERT (x.n_targets == 1 );
5261
- AST::Call_t* c_p_pointer_call = AST::down_cast<AST::Call_t>(x.m_value );
5262
- tmp = create_CPtrToPointer (*c_p_pointer_call);
5263
- return ;
5264
- }
5265
- is_c_p_pointer_call = is_c_p_pointer_call_copy;
5266
5247
assign_ast_target = assign_ast_target_copy;
5267
5248
if (tmp) {
5249
+ if (ASR::is_a<ASR::stmt_t >(*tmp)) {
5250
+ // This happens for c_p_pointer()
5251
+ return ;
5252
+ }
5268
5253
// This happens if `m.m_value` is `empty`, such as in:
5269
5254
// a = empty(16)
5270
5255
// We skip this statement for now, the array is declared
@@ -7472,20 +7457,12 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
7472
7457
if (AST::is_a<AST::Name_t>(*x.m_func )) {
7473
7458
AST::Name_t *n = AST::down_cast<AST::Name_t>(x.m_func );
7474
7459
call_name = n->m_id ;
7475
- }
7476
- if (call_name == " c_p_pointer" &&
7477
- !current_scope->resolve_symbol (call_name)) {
7478
- is_c_p_pointer_call = true ;
7479
- tmp = nullptr ;
7480
- return ;
7481
- }
7482
-
7483
- if (AST::is_a<AST::Attribute_t>(*x.m_func )) {
7460
+ } else if (AST::is_a<AST::Attribute_t>(*x.m_func )) {
7484
7461
parse_args (x, args);
7485
7462
AST::Attribute_t *at = AST::down_cast<AST::Attribute_t>(x.m_func );
7486
7463
handle_attribute (at, args, x.base .base .loc );
7487
7464
return ;
7488
- } else if ( call_name == " " ) {
7465
+ } else {
7489
7466
throw SemanticError (" Only Name or Attribute type supported in Call" ,
7490
7467
x.base .base .loc );
7491
7468
}
@@ -7575,6 +7552,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
7575
7552
// with the type
7576
7553
tmp = nullptr ;
7577
7554
return ;
7555
+ } else if (call_name == " c_p_pointer" ) {
7556
+ tmp = create_CPtrToPointer (x);
7557
+ return ;
7578
7558
} else if (call_name == " empty_c_void_p" ) {
7579
7559
// TODO: check that `empty_c_void_p uses` has arguments that are compatible
7580
7560
// with the type
0 commit comments