Skip to content

Commit

Permalink
add visitors
Browse files Browse the repository at this point in the history
  • Loading branch information
khushi-411 committed Feb 12, 2024
1 parent c2ab636 commit be0f8e3
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/libasr/codegen/asr_to_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,57 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>
s = ASRUtils::symbol_name(x.m_v);
}

void visit_ExternalSymbol(const ASR::ExternalSymbol_t &x) {
visit_symbol(*x.m_external);
}

void visit_If(const ASR::If_t &x) {
std::string r = indent;
r += "if";
visit_expr(*x.m_test);
r += s;
r += ":";
r += "\n";
inc_indent();
for (size_t i = 0; i < x.n_body; i++) {
visit_stmt(*x.m_body[i]);
r += s;
}
dec_indent();
if (x.n_orelse == 0) {
r += "\n";
} else {
for (size_t i = 0; i < x.n_orelse; i++) {
r += "else:";
r += "\n";
inc_indent();
visit_stmt(*x.m_orelse[i]);
r += s;
dec_indent();
}
r += "\n";
}
s = r;
}

void visit_StringCompare(const ASR::StringCompare_t &x) {
std::string r;
r = "(";
visit_expr(*x.m_left);
r += s;
r += cmpop2str(x.m_op);
visit_expr(*x.m_right);
r += s;
r += ")";
s = r;
}

void visit_StringConstant(const ASR::StringConstant_t &x) {
s = "\"";
s.append(x.m_s);
s += "\"";
}

void visit_IntegerBinOp(const ASR::IntegerBinOp_t &x) {
std::string r;
// TODO: Handle precedence based on the last_operator_precedence
Expand Down

0 comments on commit be0f8e3

Please sign in to comment.