@@ -304,7 +304,7 @@ void get_calls_to_global_init_and_stmts(Allocator &al, const Location &loc, Symb
304
304
ASR::accessType::Public));
305
305
scope->add_symbol (g_func_name, es);
306
306
tmp_vec.push_back (ASRUtils::make_SubroutineCall_t_util (al, loc,
307
- es, g_func, nullptr , 0 , nullptr , nullptr , false ));
307
+ es, g_func, nullptr , 0 , nullptr , nullptr , false , false ));
308
308
}
309
309
310
310
g_func_name = mod_name + " global_stmts" ;
@@ -317,7 +317,7 @@ void get_calls_to_global_init_and_stmts(Allocator &al, const Location &loc, Symb
317
317
ASR::accessType::Public));
318
318
scope->add_symbol (g_func_name, es);
319
319
tmp_vec.push_back (ASRUtils::make_SubroutineCall_t_util (al, loc,
320
- es, g_func, nullptr , 0 , nullptr , nullptr , false ));
320
+ es, g_func, nullptr , 0 , nullptr , nullptr , false , false ));
321
321
}
322
322
}
323
323
@@ -1038,6 +1038,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
1038
1038
1039
1039
ASR::asr_t * make_dummy_assignment (ASR::expr_t * expr) {
1040
1040
ASR::ttype_t * type = ASRUtils::expr_type (expr);
1041
+ LCOMPILERS_ASSERT (type != nullptr );
1041
1042
std::string dummy_ret_name = current_scope->get_unique_name (" __lcompilers_dummy" , false );
1042
1043
SetChar variable_dependencies_vec;
1043
1044
variable_dependencies_vec.reserve (al, 1 );
@@ -1233,7 +1234,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
1233
1234
}
1234
1235
1235
1236
return ASRUtils::make_SubroutineCall_t_util (al, loc, stemp,
1236
- s_generic, args_new.p , args_new.size (), nullptr , nullptr , false );
1237
+ s_generic, args_new.p , args_new.size (), nullptr , nullptr , false , false );
1237
1238
}
1238
1239
} else if (ASR::is_a<ASR::StructType_t>(*s)) {
1239
1240
ASR::StructType_t* StructType = ASR::down_cast<ASR::StructType_t>(s);
@@ -1903,8 +1904,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
1903
1904
// See integration_tests/test_bool_binop.py for its significance.
1904
1905
if (!is_assign && ASRUtils::is_logical (*left_type) && ASRUtils::is_logical (*right_type) ) {
1905
1906
ASR::ttype_t * dest_type = ASRUtils::TYPE (ASR::make_Integer_t (al, left_type->base .loc , 4 ));
1906
- left = CastingUtil::perform_casting (left, left_type, dest_type, al, left->base .loc );
1907
- right = CastingUtil::perform_casting (right, right_type, dest_type, al, right->base .loc );
1907
+ left = CastingUtil::perform_casting (left, dest_type, al, left->base .loc );
1908
+ right = CastingUtil::perform_casting (right, dest_type, al, right->base .loc );
1908
1909
return ;
1909
1910
}
1910
1911
@@ -1915,8 +1916,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
1915
1916
if ( casted_expression_signal == 2 ) {
1916
1917
return ;
1917
1918
}
1918
- src_expr = CastingUtil::perform_casting (src_expr, src_type,
1919
- dest_type, al, src_expr->base .loc );
1919
+ src_expr = CastingUtil::perform_casting (src_expr, dest_type, al, src_expr->base .loc );
1920
1920
if ( casted_expression_signal == 0 ) {
1921
1921
left = src_expr;
1922
1922
right = dest_expr;
@@ -1938,8 +1938,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
1938
1938
if ( ASRUtils::check_equal_type (src_type, dest_type) ) {
1939
1939
return ;
1940
1940
}
1941
- src_expr = CastingUtil::perform_casting (src_expr, src_type,
1942
- dest_type, al, loc);
1941
+ src_expr = CastingUtil::perform_casting (src_expr, dest_type, al, loc);
1943
1942
}
1944
1943
1945
1944
void make_BinOp_helper (ASR::expr_t *left, ASR::expr_t *right,
@@ -2186,33 +2185,31 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
2186
2185
ASRUtils::create_intrinsic_function create_function;
2187
2186
switch (op) {
2188
2187
case (ASR::binopType::Add): {
2189
- create_function = ASRUtils::IntrinsicScalarFunctionRegistry ::get_create_function (" SymbolicAdd" );
2188
+ create_function = ASRUtils::IntrinsicElementalFunctionRegistry ::get_create_function (" SymbolicAdd" );
2190
2189
break ;
2191
2190
}
2192
2191
case (ASR::binopType::Sub): {
2193
- create_function = ASRUtils::IntrinsicScalarFunctionRegistry ::get_create_function (" SymbolicSub" );
2192
+ create_function = ASRUtils::IntrinsicElementalFunctionRegistry ::get_create_function (" SymbolicSub" );
2194
2193
break ;
2195
2194
}
2196
2195
case (ASR::binopType::Mul): {
2197
- create_function = ASRUtils::IntrinsicScalarFunctionRegistry ::get_create_function (" SymbolicMul" );
2196
+ create_function = ASRUtils::IntrinsicElementalFunctionRegistry ::get_create_function (" SymbolicMul" );
2198
2197
break ;
2199
2198
}
2200
2199
case (ASR::binopType::Div): {
2201
- create_function = ASRUtils::IntrinsicScalarFunctionRegistry ::get_create_function (" SymbolicDiv" );
2200
+ create_function = ASRUtils::IntrinsicElementalFunctionRegistry ::get_create_function (" SymbolicDiv" );
2202
2201
break ;
2203
2202
}
2204
2203
case (ASR::binopType::Pow): {
2205
- create_function = ASRUtils::IntrinsicScalarFunctionRegistry ::get_create_function (" SymbolicPow" );
2204
+ create_function = ASRUtils::IntrinsicElementalFunctionRegistry ::get_create_function (" SymbolicPow" );
2206
2205
break ;
2207
2206
}
2208
2207
default : {
2209
2208
throw SemanticError (" Not implemented: The following symbolic binary operator has not been implemented" , loc);
2210
2209
break ;
2211
2210
}
2212
2211
}
2213
- tmp = create_function (al, loc, args_with_symbolic, [&](const std::string& msg, const Location& loc) {
2214
- throw SemanticError (msg, loc);
2215
- });
2212
+ tmp = create_function (al, loc, args_with_symbolic, diag);
2216
2213
return ;
2217
2214
} else {
2218
2215
std::string ltype = ASRUtils::type_to_str_python (ASRUtils::expr_type (left));
@@ -3234,14 +3231,13 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
3234
3231
ASR::symbol_t *s = current_scope->resolve_symbol (name);
3235
3232
LCOMPILERS_ASSERT (s);
3236
3233
tmp = ASR::make_Var_t (al, x.base .base .loc , s);
3237
- } else if (ASRUtils::IntrinsicScalarFunctionRegistry ::is_intrinsic_function (name) &&
3234
+ } else if (ASRUtils::IntrinsicElementalFunctionRegistry ::is_intrinsic_function (name) &&
3238
3235
(not_cpython_builtin.find (name) == not_cpython_builtin.end () ||
3239
3236
imported_functions.find (name) != imported_functions.end () )) {
3240
3237
ASRUtils::create_intrinsic_function create_func =
3241
- ASRUtils::IntrinsicScalarFunctionRegistry ::get_create_function (name);
3238
+ ASRUtils::IntrinsicElementalFunctionRegistry ::get_create_function (name);
3242
3239
Vec<ASR::expr_t *> args_;
3243
- tmp = create_func (al, x.base .base .loc , args_, [&](const std::string &msg, const Location &loc) {
3244
- throw SemanticError (msg, loc); });
3240
+ tmp = create_func (al, x.base .base .loc , args_, diag);
3245
3241
} else {
3246
3242
throw SemanticError (" Variable '" + name + " ' not declared" ,
3247
3243
x.base .base .loc );
@@ -3333,8 +3329,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
3333
3329
ASR::ttype_t *dest_type = left_operand_type;
3334
3330
3335
3331
if (!ASRUtils::check_equal_type (left_operand_type, right_operand_type)) {
3336
- throw SemanticError (" Type mismatch: '" + ASRUtils::type_to_str_python (left_operand_type)
3337
- + " ' and '" + ASRUtils::type_to_str_python (right_operand_type)
3332
+ throw SemanticError (" Type mismatch: '" + ASRUtils::type_to_str_python (left_operand_type)
3333
+ + " ' and '" + ASRUtils::type_to_str_python (right_operand_type)
3338
3334
+ " '. Both operands must be of the same type." , x.base .base .loc );
3339
3335
}
3340
3336
// Reference: https://docs.python.org/3/reference/expressions.html#boolean-operations
@@ -3474,10 +3470,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
3474
3470
args.push_back (al, left);
3475
3471
args.push_back (al, right);
3476
3472
ASRUtils::create_intrinsic_function create_func =
3477
- ASRUtils::IntrinsicScalarFunctionRegistry::get_create_function (op_name);
3478
- tmp = create_func (al, x.base .base .loc , args,
3479
- [&](const std::string &msg, const Location &loc) {
3480
- throw SemanticError (msg, loc); });
3473
+ ASRUtils::IntrinsicElementalFunctionRegistry::get_create_function (op_name);
3474
+ tmp = create_func (al, x.base .base .loc , args, diag);
3481
3475
return ;
3482
3476
}
3483
3477
@@ -3911,7 +3905,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
3911
3905
ASR::expr_t *dim_size = ASR::down_cast<ASR::Array_t>(type)->m_dims [idx].m_length ;
3912
3906
ASR::expr_t *idx_expr = ASRUtils::EXPR (ASR::make_IntegerConstant_t (al, loc, idx + 1 , int_type));
3913
3907
ASR::expr_t *size_expr = ASRUtils::EXPR (ASRUtils::make_ArraySize_t_util (al, loc, value, idx_expr, int_type, dim_size, false ));
3914
- index = ASRUtils::EXPR (ASR::make_IntegerBinOp_t (al, loc,
3908
+ index = ASRUtils::EXPR (ASR::make_IntegerBinOp_t (al, loc,
3915
3909
size_expr, ASR::binopType::Add, neg_idx, int_type, nullptr ));
3916
3910
}
3917
3911
}
@@ -6853,9 +6847,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
6853
6847
*/
6854
6848
Vec<ASR::expr_t *> args_; args_.reserve (al, args.n );
6855
6849
ASRUtils::visit_expr_list (al, args, args_);
6856
- tmp = ASRUtils::Partition::create_partition (al, loc, args_, s_var,
6857
- [&](const std::string &msg, const Location &loc) {
6858
- throw SemanticError (msg, loc); });
6850
+ tmp = ASRUtils::Partition::create_partition (al, loc, args_, s_var, diag);
6859
6851
return ;
6860
6852
} else if (attr_name == " count" ) {
6861
6853
if (args.size () != 1 ) {
@@ -7230,9 +7222,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
7230
7222
loc, 1 , s_var.size (), nullptr ));
7231
7223
ASR::expr_t *str = ASRUtils::EXPR (ASR::make_StringConstant_t (al,
7232
7224
loc, s2c (al, s_var), char_type));
7233
- tmp = ASRUtils::Partition::create_partition (al, loc, args_, str,
7234
- [&](const std::string &msg, const Location &loc) {
7235
- throw SemanticError (msg, loc); });
7225
+ tmp = ASRUtils::Partition::create_partition (al, loc, args_, str, diag);
7236
7226
return ;
7237
7227
} else if (attr_name.size () > 2 && attr_name[0 ] == ' i' && attr_name[1 ] == ' s' ) {
7238
7228
/*
@@ -7345,7 +7335,7 @@ we will have to use something else.
7345
7335
} else if (attr_name == " isalpha" ) {
7346
7336
/*
7347
7337
* Specification -
7348
- Return True if all characters in the string are alphabets,
7338
+ Return True if all characters in the string are alphabets,
7349
7339
and there is at least one character in the string.
7350
7340
*/
7351
7341
bool is_alpha = (s_var.size () != 0 );
@@ -7361,7 +7351,7 @@ we will have to use something else.
7361
7351
} else if (attr_name == " isalnum" ) {
7362
7352
/*
7363
7353
* Specification -
7364
- Return True if all characters in the string are alphabets or numbers,
7354
+ Return True if all characters in the string are alphabets or numbers,
7365
7355
and there is at least one character in the string.
7366
7356
*/
7367
7357
bool is_alnum = (s_var.size () != 0 );
@@ -7377,7 +7367,7 @@ we will have to use something else.
7377
7367
} else if (attr_name == " isnumeric" ) {
7378
7368
/*
7379
7369
* Specification -
7380
- Return True if all characters in the string are numbers,
7370
+ Return True if all characters in the string are numbers,
7381
7371
and there is at least one character in the string.
7382
7372
*/
7383
7373
bool is_numeric = (s_var.size () != 0 );
@@ -7393,7 +7383,7 @@ we will have to use something else.
7393
7383
} else if (attr_name == " istitle" ) {
7394
7384
/*
7395
7385
* Specification -
7396
- Returns True if all words in the string are in title case,
7386
+ Returns True if all words in the string are in title case,
7397
7387
and there is at least one character in the string.
7398
7388
*/
7399
7389
bool is_title = (s_var.size () != 0 );
@@ -7457,15 +7447,13 @@ we will have to use something else.
7457
7447
if (symbolic_attributes.find (call_name) != symbolic_attributes.end () &&
7458
7448
symbolic_constants.find (mod_name) != symbolic_constants.end ()){
7459
7449
ASRUtils::create_intrinsic_function create_func;
7460
- create_func = ASRUtils::IntrinsicScalarFunctionRegistry ::get_create_function (mod_name);
7450
+ create_func = ASRUtils::IntrinsicElementalFunctionRegistry ::get_create_function (mod_name);
7461
7451
Vec<ASR::expr_t *> eles; eles.reserve (al, args.size ());
7462
7452
Vec<ASR::expr_t *> args_; args_.reserve (al, 1 );
7463
7453
for (size_t i=0 ; i<args.size (); i++) {
7464
7454
eles.push_back (al, args[i].m_value );
7465
7455
}
7466
- tmp = create_func (al, at->base .base .loc , args_,
7467
- [&](const std::string &msg, const Location &loc) {
7468
- throw SemanticError (msg, loc); });
7456
+ tmp = create_func (al, at->base .base .loc , args_, diag);
7469
7457
handle_symbolic_attribute (ASRUtils::EXPR (tmp), call_name, loc, eles);
7470
7458
return ;
7471
7459
}
@@ -7687,13 +7675,13 @@ we will have to use something else.
7687
7675
imported_functions[call_name] == " sympy" ){
7688
7676
intrinsic_name = " Symbolic" + std::string (1 , std::toupper (call_name[0 ])) + call_name.substr (1 );
7689
7677
}
7690
- if ((ASRUtils::IntrinsicScalarFunctionRegistry ::is_intrinsic_function (intrinsic_name) ||
7678
+ if ((ASRUtils::IntrinsicElementalFunctionRegistry ::is_intrinsic_function (intrinsic_name) ||
7691
7679
ASRUtils::IntrinsicArrayFunctionRegistry::is_intrinsic_function (intrinsic_name)) &&
7692
7680
(not_cpython_builtin.find (call_name) == not_cpython_builtin.end () ||
7693
7681
imported_functions.find (call_name) != imported_functions.end () )) {
7694
7682
ASRUtils::create_intrinsic_function create_func;
7695
- if (ASRUtils::IntrinsicScalarFunctionRegistry ::is_intrinsic_function (intrinsic_name)) {
7696
- create_func = ASRUtils::IntrinsicScalarFunctionRegistry ::get_create_function (intrinsic_name);
7683
+ if (ASRUtils::IntrinsicElementalFunctionRegistry ::is_intrinsic_function (intrinsic_name)) {
7684
+ create_func = ASRUtils::IntrinsicElementalFunctionRegistry ::get_create_function (intrinsic_name);
7697
7685
} else {
7698
7686
create_func = ASRUtils::IntrinsicArrayFunctionRegistry::get_create_function (intrinsic_name);
7699
7687
}
@@ -7704,9 +7692,7 @@ we will have to use something else.
7704
7692
throw SemanticError (" Function '" + call_name + " ' does not accept vector values" ,
7705
7693
x.base .base .loc );
7706
7694
}
7707
- tmp = create_func (al, x.base .base .loc , args_,
7708
- [&](const std::string &msg, const Location &loc) {
7709
- throw SemanticError (msg, loc); });
7695
+ tmp = create_func (al, x.base .base .loc , args_, diag);
7710
7696
return ;
7711
7697
} else if (intrinsic_procedures.is_intrinsic (call_name)) {
7712
7698
s = resolve_intrinsic_function (x.base .base .loc , call_name);
@@ -7789,11 +7775,9 @@ we will have to use something else.
7789
7775
} else if ( call_name == " reserve" ) {
7790
7776
parse_args (x, args);
7791
7777
ASRUtils::create_intrinsic_function create_func =
7792
- ASRUtils::IntrinsicScalarFunctionRegistry ::get_create_function (" reserve" );
7778
+ ASRUtils::IntrinsicElementalFunctionRegistry ::get_create_function (" list. reserve" );
7793
7779
Vec<ASR::expr_t *> args_exprs = ASRUtils::call_arg2expr (al, args);
7794
- tmp = create_func (al, x.base .base .loc , args_exprs,
7795
- [&](const std::string &msg, const Location &loc) {
7796
- throw SemanticError (msg, loc); });
7780
+ tmp = create_func (al, x.base .base .loc , args_exprs, diag);
7797
7781
return ;
7798
7782
} else if (call_name == " size" ) {
7799
7783
parse_args (x, args);
@@ -7866,7 +7850,7 @@ we will have to use something else.
7866
7850
} else {
7867
7851
Vec<ASR::expr_t *> arr_args;
7868
7852
arr_args.reserve (al, 0 );
7869
- tmp = ASRUtils::make_ArrayConstant_t_util (al, x.base .base .loc ,
7853
+ tmp = ASRUtils::make_ArrayConstructor_t_util (al, x.base .base .loc ,
7870
7854
arr_args.p , arr_args.size (), type, ASR::arraystorageType::RowMajor);
7871
7855
}
7872
7856
return ;
@@ -8025,10 +8009,10 @@ we will have to use something else.
8025
8009
type = ASRUtils::make_Array_t_util (al, x.base .base .loc , type, dims.p , dims.size (),
8026
8010
ASR::abiType::Source, false , ASR::array_physical_typeType::PointerToDataArray, true );
8027
8011
for ( size_t i = 0 ; i < n_args; i++ ) {
8028
- m_args[i] = CastingUtil::perform_casting (m_args[i], ASRUtils::expr_type (m_args[i] ),
8029
- ASRUtils::type_get_past_array (type), al, x.base .base .loc );
8012
+ m_args[i] = CastingUtil::perform_casting (m_args[i], ASRUtils::type_get_past_array (type ),
8013
+ al, x.base .base .loc );
8030
8014
}
8031
- tmp = ASR::make_ArrayConstant_t (al, x.base .base .loc , m_args, n_args, type, ASR::arraystorageType::RowMajor);
8015
+ tmp = ASRUtils::make_ArrayConstructor_t_util (al, x.base .base .loc , m_args, n_args, type, ASR::arraystorageType::RowMajor);
8032
8016
} else {
8033
8017
throw SemanticError (" array accepts only list for now, got " +
8034
8018
ASRUtils::type_to_str (type) + " type." , x.base .base .loc );
0 commit comments