Skip to content

Improve C++ codegen by using last precedence #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 23, 2022
Merged
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
34 changes: 27 additions & 7 deletions src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,35 @@ static inline std::string unop_to_str(const ASR::unaryopType t) {
}
}

static inline std::string binop_to_str(const ASR::binopType t) {
switch (t) {
case (ASR::binopType::Add): { return " + "; }
case (ASR::binopType::Sub): { return " - "; }
case (ASR::binopType::Mul): { return "*"; }
case (ASR::binopType::Div): { return "/"; }
default : throw LFortranException("Cannot represent the binary operator as a string");
}
}

static inline std::string cmpop_to_str(const ASR::cmpopType t) {
switch (t) {
case (ASR::cmpopType::Eq): { return "=="; }
case (ASR::cmpopType::NotEq): { return "!="; }
case (ASR::cmpopType::Lt): { return "<"; }
case (ASR::cmpopType::LtE): { return "<="; }
case (ASR::cmpopType::Gt): { return ">"; }
case (ASR::cmpopType::GtE): { return ">="; }
default : throw LFortranException("Not implemented");
case (ASR::cmpopType::Eq): { return " == "; }
case (ASR::cmpopType::NotEq): { return " != "; }
case (ASR::cmpopType::Lt): { return " < "; }
case (ASR::cmpopType::LtE): { return " <= "; }
case (ASR::cmpopType::Gt): { return " > "; }
case (ASR::cmpopType::GtE): { return " >= "; }
default : throw LFortranException("Cannot represent the comparison as a string");
}
}

static inline std::string boolop_to_str(const ASR::boolopType t) {
switch (t) {
case (ASR::boolopType::And): { return " && "; }
case (ASR::boolopType::Or): { return " || "; }
case (ASR::boolopType::Eqv): { return " == "; }
case (ASR::boolopType::NEqv): { return " != "; }
default : throw LFortranException("Cannot represent the boolean operator as a string");
}
}

Expand Down
Loading