Skip to content

Commit 4f0198d

Browse files
authored
Merge pull request #100 from namannimmo10/last_prec
Improve C++ codegen by using last precedence
2 parents 04b0e81 + 0ad0add commit 4f0198d

File tree

9 files changed

+197
-154
lines changed

9 files changed

+197
-154
lines changed

src/libasr/asr_utils.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,35 @@ static inline std::string unop_to_str(const ASR::unaryopType t) {
153153
}
154154
}
155155

156+
static inline std::string binop_to_str(const ASR::binopType t) {
157+
switch (t) {
158+
case (ASR::binopType::Add): { return " + "; }
159+
case (ASR::binopType::Sub): { return " - "; }
160+
case (ASR::binopType::Mul): { return "*"; }
161+
case (ASR::binopType::Div): { return "/"; }
162+
default : throw LFortranException("Cannot represent the binary operator as a string");
163+
}
164+
}
165+
156166
static inline std::string cmpop_to_str(const ASR::cmpopType t) {
157167
switch (t) {
158-
case (ASR::cmpopType::Eq): { return "=="; }
159-
case (ASR::cmpopType::NotEq): { return "!="; }
160-
case (ASR::cmpopType::Lt): { return "<"; }
161-
case (ASR::cmpopType::LtE): { return "<="; }
162-
case (ASR::cmpopType::Gt): { return ">"; }
163-
case (ASR::cmpopType::GtE): { return ">="; }
164-
default : throw LFortranException("Not implemented");
168+
case (ASR::cmpopType::Eq): { return " == "; }
169+
case (ASR::cmpopType::NotEq): { return " != "; }
170+
case (ASR::cmpopType::Lt): { return " < "; }
171+
case (ASR::cmpopType::LtE): { return " <= "; }
172+
case (ASR::cmpopType::Gt): { return " > "; }
173+
case (ASR::cmpopType::GtE): { return " >= "; }
174+
default : throw LFortranException("Cannot represent the comparison as a string");
175+
}
176+
}
177+
178+
static inline std::string boolop_to_str(const ASR::boolopType t) {
179+
switch (t) {
180+
case (ASR::boolopType::And): { return " && "; }
181+
case (ASR::boolopType::Or): { return " || "; }
182+
case (ASR::boolopType::Eqv): { return " == "; }
183+
case (ASR::boolopType::NEqv): { return " != "; }
184+
default : throw LFortranException("Cannot represent the boolean operator as a string");
165185
}
166186
}
167187

0 commit comments

Comments
 (0)