diff --git a/src/libasr/asr_utils.cpp b/src/libasr/asr_utils.cpp index bfb718216d..40a606eb35 100644 --- a/src/libasr/asr_utils.cpp +++ b/src/libasr/asr_utils.cpp @@ -1357,6 +1357,16 @@ ASR::asr_t* make_Cast_t_value(Allocator &al, const Location &a_loc, double real = value_complex->m_re; value = ASR::down_cast( ASR::make_RealConstant_t(al, a_loc, real, a_type)); + } else if (a_kind == ASR::cast_kindType::CharacterToInteger) { + int64_t value_integer; + int integer_type = ASRUtils::extract_kind_from_ttype_t(a_type); + std::string src_string = ASR::down_cast(ASRUtils::expr_value(a_arg))->m_s; + if (integer_type <= 4) { + value_integer = std::stoi(src_string); + } else { + value_integer = std::stol(src_string); + } + value = ASR::down_cast(ASR::make_IntegerConstant_t(al, a_loc, value_integer, a_type)); } else if (a_kind == ASR::cast_kindType::IntegerToSymbolicExpression) { Vec args; args.reserve(al, 1); diff --git a/src/libasr/casting_utils.cpp b/src/libasr/casting_utils.cpp index 0a8a1c1cd3..0395d19142 100644 --- a/src/libasr/casting_utils.cpp +++ b/src/libasr/casting_utils.cpp @@ -27,6 +27,7 @@ namespace LCompilers::CastingUtil { {std::make_pair(ASR::ttypeType::Integer, ASR::ttypeType::Complex), ASR::cast_kindType::IntegerToComplex}, {std::make_pair(ASR::ttypeType::Integer, ASR::ttypeType::Real), ASR::cast_kindType::IntegerToReal}, {std::make_pair(ASR::ttypeType::Integer, ASR::ttypeType::Logical), ASR::cast_kindType::IntegerToLogical}, + {std::make_pair(ASR::ttypeType::Character, ASR::ttypeType::Integer), ASR::cast_kindType::CharacterToInteger}, {std::make_pair(ASR::ttypeType::Integer, ASR::ttypeType::UnsignedInteger), ASR::cast_kindType::IntegerToUnsignedInteger}, {std::make_pair(ASR::ttypeType::Logical, ASR::ttypeType::Real), ASR::cast_kindType::LogicalToReal}, {std::make_pair(ASR::ttypeType::Logical, ASR::ttypeType::Integer), ASR::cast_kindType::LogicalToInteger},