Skip to content

Commit 09e33de

Browse files
authored
Merge branch 'main' into if_sigle_line
2 parents 1785406 + 0526607 commit 09e33de

119 files changed

Lines changed: 740 additions & 462 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/libasr/ASR.asdl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,19 @@ expr
214214
| FunctionCall(symbol name, symbol? original_name,
215215
call_arg* args, ttype type, expr? value, expr? dt)
216216
| DerivedTypeConstructor(symbol dt_sym, expr* args, ttype type)
217-
| ConstantArray(expr* args, ttype type)
218217
| ImpliedDoLoop(expr* values, expr var, expr start, expr end,
219218
expr? increment, ttype type, expr? value)
220-
| ConstantInteger(int n, ttype type)
221-
| ConstantReal(float r, ttype type)
222-
| ConstantComplex(float re, float im, ttype type)
223-
| ConstantLogical(bool value, ttype type)
224-
| ConstantList(expr* args, ttype type)
225-
| ConstantSet(expr* elements, ttype type)
226-
| ConstantTuple(expr* elements, ttype type)
227-
| ConstantString(string s, ttype type)
228-
| ConstantDictionary(expr* keys, expr* values, ttype type)
229-
| BOZ(int v, boz boz_type, ttype? type)
219+
| IntegerConstant(int n, ttype type)
220+
| IntegerBOZ(int v, integerboz intboz_type, ttype? type)
221+
| RealConstant(float r, ttype type)
222+
| ComplexConstant(float re, float im, ttype type)
223+
| LogicalConstant(bool value, ttype type)
224+
| ListConstant(expr* args, ttype type)
225+
| ArrayConstant(expr* args, ttype type)
226+
| SetConstant(expr* elements, ttype type)
227+
| TupleConstant(expr* elements, ttype type)
228+
| StringConstant(string s, ttype type)
229+
| DictConstant(expr* keys, expr* values, ttype type)
230230
| Var(symbol v)
231231
| ArrayRef(symbol v, array_index* args, ttype type, expr? value)
232232
| DerivedRef(expr v, symbol m, ttype type, expr? value)
@@ -262,7 +262,7 @@ strop = Concat | Repeat
262262

263263
cmpop = Eq | NotEq | Lt | LtE | Gt | GtE
264264

265-
boz = Binary | Hex | Octal
265+
integerboz = Binary | Hex | Octal
266266

267267
cast_kind
268268
= RealToInteger

src/libasr/asr_utils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ void visit(
2020
std::vector<std::string>& result
2121
) {
2222
visited.insert(a);
23-
if (auto it = deps.find(a); it != deps.end()) {
23+
auto it = deps.find(a);
24+
if (it != deps.end()) {
2425
for (auto n : it->second) {
2526
if (!visited.count(n)) visit(n, deps, visited, result);
2627
}

src/libasr/asr_utils.h

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,18 @@ static inline ASR::ttype_t* expr_type(const ASR::expr_t *f)
103103
case ASR::exprType::IfExp: { return ((ASR::IfExp_t*)f)->m_type; }
104104
case ASR::exprType::FunctionCall: { return ((ASR::FunctionCall_t*)f)->m_type; }
105105
case ASR::exprType::DerivedTypeConstructor: { return ((ASR::DerivedTypeConstructor_t*)f)->m_type; }
106-
case ASR::exprType::ConstantArray: { return ((ASR::ConstantArray_t*)f)->m_type; }
106+
case ASR::exprType::ArrayConstant: { return ((ASR::ArrayConstant_t*)f)->m_type; }
107107
case ASR::exprType::ImpliedDoLoop: { return ((ASR::ImpliedDoLoop_t*)f)->m_type; }
108-
case ASR::exprType::ConstantInteger: { return ((ASR::ConstantInteger_t*)f)->m_type; }
109-
case ASR::exprType::ConstantReal: { return ((ASR::ConstantReal_t*)f)->m_type; }
110-
case ASR::exprType::ConstantComplex: { return ((ASR::ConstantComplex_t*)f)->m_type; }
111-
case ASR::exprType::ConstantSet: { return ((ASR::ConstantSet_t*)f)->m_type; }
112-
case ASR::exprType::ConstantList: { return ((ASR::ConstantList_t*)f)->m_type; }
113-
case ASR::exprType::ConstantTuple: { return ((ASR::ConstantTuple_t*)f)->m_type; }
114-
case ASR::exprType::ConstantLogical: { return ((ASR::ConstantLogical_t*)f)->m_type; }
115-
case ASR::exprType::ConstantString: { return ((ASR::ConstantString_t*)f)->m_type; }
116-
case ASR::exprType::ConstantDictionary: { return ((ASR::ConstantDictionary_t*)f)->m_type; }
117-
case ASR::exprType::BOZ: { return ((ASR::BOZ_t*)f)->m_type; }
108+
case ASR::exprType::IntegerConstant: { return ((ASR::IntegerConstant_t*)f)->m_type; }
109+
case ASR::exprType::RealConstant: { return ((ASR::RealConstant_t*)f)->m_type; }
110+
case ASR::exprType::ComplexConstant: { return ((ASR::ComplexConstant_t*)f)->m_type; }
111+
case ASR::exprType::SetConstant: { return ((ASR::SetConstant_t*)f)->m_type; }
112+
case ASR::exprType::ListConstant: { return ((ASR::ListConstant_t*)f)->m_type; }
113+
case ASR::exprType::TupleConstant: { return ((ASR::TupleConstant_t*)f)->m_type; }
114+
case ASR::exprType::LogicalConstant: { return ((ASR::LogicalConstant_t*)f)->m_type; }
115+
case ASR::exprType::StringConstant: { return ((ASR::StringConstant_t*)f)->m_type; }
116+
case ASR::exprType::DictConstant: { return ((ASR::DictConstant_t*)f)->m_type; }
117+
case ASR::exprType::IntegerBOZ: { return ((ASR::IntegerBOZ_t*)f)->m_type; }
118118
case ASR::exprType::Var: { return EXPR2VAR(f)->m_type; }
119119
case ASR::exprType::ArrayRef: { return ((ASR::ArrayRef_t*)f)->m_type; }
120120
case ASR::exprType::DerivedRef: { return ((ASR::DerivedRef_t*)f)->m_type; }
@@ -214,15 +214,15 @@ static inline ASR::expr_t* expr_value(ASR::expr_t *f)
214214
case ASR::exprType::Var: { return EXPR2VAR(f)->m_value; }
215215
case ASR::exprType::StrOp: { return ASR::down_cast<ASR::StrOp_t>(f)->m_value; }
216216
case ASR::exprType::ImpliedDoLoop: { return ASR::down_cast<ASR::ImpliedDoLoop_t>(f)->m_value; }
217-
case ASR::exprType::ConstantArray: // Drop through
218-
case ASR::exprType::ConstantInteger: // Drop through
219-
case ASR::exprType::ConstantReal: // Drop through
220-
case ASR::exprType::ConstantComplex: // Drop through
221-
case ASR::exprType::ConstantLogical: // Drop through
222-
case ASR::exprType::ConstantTuple: // Drop through
223-
case ASR::exprType::ConstantDictionary: // Drop through
224-
case ASR::exprType::ConstantSet: // Drop through
225-
case ASR::exprType::ConstantString:{ // For all Constants
217+
case ASR::exprType::ArrayConstant: // Drop through
218+
case ASR::exprType::IntegerConstant: // Drop through
219+
case ASR::exprType::RealConstant: // Drop through
220+
case ASR::exprType::ComplexConstant: // Drop through
221+
case ASR::exprType::LogicalConstant: // Drop through
222+
case ASR::exprType::TupleConstant: // Drop through
223+
case ASR::exprType::DictConstant: // Drop through
224+
case ASR::exprType::SetConstant: // Drop through
225+
case ASR::exprType::StringConstant:{ // For all Constants
226226
return f;
227227
}
228228
default : throw LFortranException("Not implemented");
@@ -424,15 +424,15 @@ static inline bool is_value_constant(ASR::expr_t *a_value) {
424424
if( a_value == nullptr ) {
425425
return false;
426426
}
427-
if (ASR::is_a<ASR::ConstantInteger_t>(*a_value)) {
427+
if (ASR::is_a<ASR::IntegerConstant_t>(*a_value)) {
428428
// OK
429-
} else if (ASR::is_a<ASR::ConstantReal_t>(*a_value)) {
429+
} else if (ASR::is_a<ASR::RealConstant_t>(*a_value)) {
430430
// OK
431-
} else if (ASR::is_a<ASR::ConstantComplex_t>(*a_value)) {
431+
} else if (ASR::is_a<ASR::ComplexConstant_t>(*a_value)) {
432432
// OK
433-
} else if (ASR::is_a<ASR::ConstantLogical_t>(*a_value)) {
433+
} else if (ASR::is_a<ASR::LogicalConstant_t>(*a_value)) {
434434
// OK
435-
} else if (ASR::is_a<ASR::ConstantString_t>(*a_value)) {
435+
} else if (ASR::is_a<ASR::StringConstant_t>(*a_value)) {
436436
// OK
437437
} else {
438438
return false;
@@ -444,8 +444,8 @@ static inline bool is_value_constant(ASR::expr_t *a_value, int64_t& const_value)
444444
if( a_value == nullptr ) {
445445
return false;
446446
}
447-
if (ASR::is_a<ASR::ConstantInteger_t>(*a_value)) {
448-
ASR::ConstantInteger_t* const_int = ASR::down_cast<ASR::ConstantInteger_t>(a_value);
447+
if (ASR::is_a<ASR::IntegerConstant_t>(*a_value)) {
448+
ASR::IntegerConstant_t* const_int = ASR::down_cast<ASR::IntegerConstant_t>(a_value);
449449
const_value = const_int->m_n;
450450
} else {
451451
return false;
@@ -457,8 +457,8 @@ static inline bool is_value_constant(ASR::expr_t *a_value, bool& const_value) {
457457
if( a_value == nullptr ) {
458458
return false;
459459
}
460-
if (ASR::is_a<ASR::ConstantLogical_t>(*a_value)) {
461-
ASR::ConstantLogical_t* const_logical = ASR::down_cast<ASR::ConstantLogical_t>(a_value);
460+
if (ASR::is_a<ASR::LogicalConstant_t>(*a_value)) {
461+
ASR::LogicalConstant_t* const_logical = ASR::down_cast<ASR::LogicalConstant_t>(a_value);
462462
const_value = const_logical->m_value;
463463
} else {
464464
return false;
@@ -470,11 +470,11 @@ static inline bool is_value_constant(ASR::expr_t *a_value, double& const_value)
470470
if( a_value == nullptr ) {
471471
return false;
472472
}
473-
if (ASR::is_a<ASR::ConstantInteger_t>(*a_value)) {
474-
ASR::ConstantInteger_t* const_int = ASR::down_cast<ASR::ConstantInteger_t>(a_value);
473+
if (ASR::is_a<ASR::IntegerConstant_t>(*a_value)) {
474+
ASR::IntegerConstant_t* const_int = ASR::down_cast<ASR::IntegerConstant_t>(a_value);
475475
const_value = const_int->m_n;
476-
} else if (ASR::is_a<ASR::ConstantReal_t>(*a_value)) {
477-
ASR::ConstantReal_t* const_real = ASR::down_cast<ASR::ConstantReal_t>(a_value);
476+
} else if (ASR::is_a<ASR::RealConstant_t>(*a_value)) {
477+
ASR::RealConstant_t* const_real = ASR::down_cast<ASR::RealConstant_t>(a_value);
478478
const_value = const_real->m_r;
479479
} else {
480480
return false;
@@ -486,8 +486,8 @@ static inline bool is_value_constant(ASR::expr_t *a_value, std::string& const_va
486486
if( a_value == nullptr ) {
487487
return false;
488488
}
489-
if (ASR::is_a<ASR::ConstantString_t>(*a_value)) {
490-
ASR::ConstantString_t* const_string = ASR::down_cast<ASR::ConstantString_t>(a_value);
489+
if (ASR::is_a<ASR::StringConstant_t>(*a_value)) {
490+
ASR::StringConstant_t* const_string = ASR::down_cast<ASR::StringConstant_t>(a_value);
491491
const_value = std::string(const_string->m_s);
492492
} else {
493493
return false;
@@ -505,14 +505,14 @@ static inline bool is_value_equal(ASR::expr_t* test_expr, ASR::expr_t* desired_e
505505
}
506506

507507
switch( desired_value->type ) {
508-
case ASR::exprType::ConstantInteger: {
509-
ASR::ConstantInteger_t* test_int = ASR::down_cast<ASR::ConstantInteger_t>(test_value);
510-
ASR::ConstantInteger_t* desired_int = ASR::down_cast<ASR::ConstantInteger_t>(desired_value);
508+
case ASR::exprType::IntegerConstant: {
509+
ASR::IntegerConstant_t* test_int = ASR::down_cast<ASR::IntegerConstant_t>(test_value);
510+
ASR::IntegerConstant_t* desired_int = ASR::down_cast<ASR::IntegerConstant_t>(desired_value);
511511
return test_int->m_n == desired_int->m_n;
512512
}
513-
case ASR::exprType::ConstantString: {
514-
ASR::ConstantString_t* test_str = ASR::down_cast<ASR::ConstantString_t>(test_value);
515-
ASR::ConstantString_t* desired_str = ASR::down_cast<ASR::ConstantString_t>(desired_value);
513+
case ASR::exprType::StringConstant: {
514+
ASR::StringConstant_t* test_str = ASR::down_cast<ASR::StringConstant_t>(test_value);
515+
ASR::StringConstant_t* desired_str = ASR::down_cast<ASR::StringConstant_t>(desired_value);
516516
return std::string(test_str->m_s) == std::string(desired_str->m_s);
517517
}
518518
default: {
@@ -593,8 +593,8 @@ static inline bool extract_value(ASR::expr_t* value_expr, T& value) {
593593
}
594594

595595
switch( value_expr->type ) {
596-
case ASR::exprType::ConstantReal: {
597-
ASR::ConstantReal_t* const_real = ASR::down_cast<ASR::ConstantReal_t>(value_expr);
596+
case ASR::exprType::RealConstant: {
597+
ASR::RealConstant_t* const_real = ASR::down_cast<ASR::RealConstant_t>(value_expr);
598598
value = (T) const_real->m_r;
599599
break;
600600
}
@@ -863,8 +863,8 @@ inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) {
863863
inline int extract_kind(ASR::expr_t* kind_expr, const Location& loc) {
864864
int a_kind = 4;
865865
switch( kind_expr->type ) {
866-
case ASR::exprType::ConstantInteger: {
867-
a_kind = ASR::down_cast<ASR::ConstantInteger_t>
866+
case ASR::exprType::IntegerConstant: {
867+
a_kind = ASR::down_cast<ASR::IntegerConstant_t>
868868
(kind_expr)->m_n;
869869
break;
870870
}
@@ -877,7 +877,7 @@ inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) {
877877
if( kind_variable->m_storage == ASR::storage_typeType::Parameter ) {
878878
if( kind_variable->m_type->type == ASR::ttypeType::Integer ) {
879879
LFORTRAN_ASSERT( kind_variable->m_value != nullptr );
880-
a_kind = ASR::down_cast<ASR::ConstantInteger_t>(kind_variable->m_value)->m_n;
880+
a_kind = ASR::down_cast<ASR::IntegerConstant_t>(kind_variable->m_value)->m_n;
881881
} else {
882882
std::string msg = "Integer variable required. " + std::string(kind_variable->m_name) +
883883
" is not an Integer variable.";
@@ -902,8 +902,8 @@ inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) {
902902
inline int extract_len(ASR::expr_t* len_expr, const Location& loc) {
903903
int a_len = -10;
904904
switch( len_expr->type ) {
905-
case ASR::exprType::ConstantInteger: {
906-
a_len = ASR::down_cast<ASR::ConstantInteger_t>
905+
case ASR::exprType::IntegerConstant: {
906+
a_len = ASR::down_cast<ASR::IntegerConstant_t>
907907
(len_expr)->m_n;
908908
break;
909909
}
@@ -916,7 +916,7 @@ inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) {
916916
if( len_variable->m_storage == ASR::storage_typeType::Parameter ) {
917917
if( len_variable->m_type->type == ASR::ttypeType::Integer ) {
918918
LFORTRAN_ASSERT( len_variable->m_value != nullptr );
919-
a_len = ASR::down_cast<ASR::ConstantInteger_t>(len_variable->m_value)->m_n;
919+
a_len = ASR::down_cast<ASR::IntegerConstant_t>(len_variable->m_value)->m_n;
920920
} else {
921921
std::string msg = "Integer variable required. " + std::string(len_variable->m_name) +
922922
" is not an Integer variable.";

src/libasr/codegen/asr_to_cpp.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ std::string convert_dims(size_t n_dims, ASR::dimension_t *m_dims)
5151
if (!start && !end) {
5252
dims += "*";
5353
} else if (start && end) {
54-
if (ASR::is_a<ASR::ConstantInteger_t>(*start) && ASR::is_a<ASR::ConstantInteger_t>(*end)) {
55-
ASR::ConstantInteger_t *s = ASR::down_cast<ASR::ConstantInteger_t>(start);
56-
ASR::ConstantInteger_t *e = ASR::down_cast<ASR::ConstantInteger_t>(end);
54+
if (ASR::is_a<ASR::IntegerConstant_t>(*start) && ASR::is_a<ASR::IntegerConstant_t>(*end)) {
55+
ASR::IntegerConstant_t *s = ASR::down_cast<ASR::IntegerConstant_t>(start);
56+
ASR::IntegerConstant_t *e = ASR::down_cast<ASR::IntegerConstant_t>(end);
5757
if (s->m_n == 1) {
5858
dims += "[" + std::to_string(e->m_n) + "]";
5959
} else {
@@ -539,27 +539,27 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
539539
src = indent + target + " = " + value + ";\n";
540540
}
541541

542-
void visit_ConstantInteger(const ASR::ConstantInteger_t &x) {
542+
void visit_IntegerConstant(const ASR::IntegerConstant_t &x) {
543543
src = std::to_string(x.m_n);
544544
last_expr_precedence = 2;
545545
}
546546

547-
void visit_ConstantReal(const ASR::ConstantReal_t &x) {
547+
void visit_RealConstant(const ASR::RealConstant_t &x) {
548548
src = std::to_string(x.m_r);
549549
last_expr_precedence = 2;
550550
}
551551

552-
void visit_ConstantString(const ASR::ConstantString_t &x) {
552+
void visit_StringConstant(const ASR::StringConstant_t &x) {
553553
src = "\"" + std::string(x.m_s) + "\"";
554554
last_expr_precedence = 2;
555555
}
556556

557-
void visit_ConstantComplex(const ASR::ConstantComplex_t &x) {
557+
void visit_ComplexConstant(const ASR::ComplexConstant_t &x) {
558558
src = "std::complex<double>(" + std::to_string(x.m_re) + ", " + std::to_string(x.m_im) + ")";
559559
last_expr_precedence = 2;
560560
}
561561

562-
void visit_ConstantLogical(const ASR::ConstantLogical_t &x) {
562+
void visit_LogicalConstant(const ASR::LogicalConstant_t &x) {
563563
if (x.m_value == true) {
564564
src = "true";
565565
} else {
@@ -568,7 +568,7 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
568568
last_expr_precedence = 2;
569569
}
570570

571-
void visit_ConstantSet(const ASR::ConstantSet_t &x) {
571+
void visit_SetConstant(const ASR::SetConstant_t &x) {
572572
std::string out = "{";
573573
for (size_t i=0; i<x.n_elements; i++) {
574574
visit_expr(*x.m_elements[i]);
@@ -605,7 +605,7 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
605605
src = out;
606606
}
607607

608-
void visit_ConstantDictionary(const ASR::ConstantDictionary_t &x) {
608+
void visit_DictConstant(const ASR::DictConstant_t &x) {
609609
LFORTRAN_ASSERT(x.n_keys == x.n_values);
610610
std::string out = "{";
611611
for(size_t i=0; i<x.n_keys; i++) {
@@ -870,7 +870,7 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
870870
}
871871
}
872872

873-
void visit_ConstantArray(const ASR::ConstantArray_t &x) {
873+
void visit_ArrayConstant(const ASR::ArrayConstant_t &x) {
874874
std::string out = "from_std_vector<float>({";
875875
for (size_t i=0; i<x.n_args; i++) {
876876
this->visit_expr(*x.m_args[i]);
@@ -1038,13 +1038,13 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
10381038
if (!c) {
10391039
increment = 1;
10401040
} else {
1041-
if (c->type == ASR::exprType::ConstantInteger) {
1042-
increment = ASR::down_cast<ASR::ConstantInteger_t>(c)->m_n;
1041+
if (c->type == ASR::exprType::IntegerConstant) {
1042+
increment = ASR::down_cast<ASR::IntegerConstant_t>(c)->m_n;
10431043
} else if (c->type == ASR::exprType::UnaryOp) {
10441044
ASR::UnaryOp_t *u = ASR::down_cast<ASR::UnaryOp_t>(c);
10451045
LFORTRAN_ASSERT(u->m_op == ASR::unaryopType::USub);
1046-
LFORTRAN_ASSERT(u->m_operand->type == ASR::exprType::ConstantInteger);
1047-
increment = - ASR::down_cast<ASR::ConstantInteger_t>(u->m_operand)->m_n;
1046+
LFORTRAN_ASSERT(u->m_operand->type == ASR::exprType::IntegerConstant);
1047+
increment = - ASR::down_cast<ASR::IntegerConstant_t>(u->m_operand)->m_n;
10481048
} else {
10491049
throw CodeGenError("Do loop increment type not supported");
10501050
}

0 commit comments

Comments
 (0)