Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/libasr/asr_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::expr_t>(
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<ASR::StringConstant_t>(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::expr_t>(ASR::make_IntegerConstant_t(al, a_loc, value_integer, a_type));
} else if (a_kind == ASR::cast_kindType::IntegerToSymbolicExpression) {
Vec<ASR::expr_t*> args;
args.reserve(al, 1);
Expand Down
1 change: 1 addition & 0 deletions src/libasr/casting_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down