Skip to content

Commit

Permalink
Fix variable decl order
Browse files Browse the repository at this point in the history
  • Loading branch information
Smit-create committed Mar 16, 2023
1 parent 56bd232 commit b89fadf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ EMSCRIPTEN_KEEPALIVE char* emit_cpp_from_source(char *input) {
out = diagnostics.render(lm, compiler_options);
if (asr.ok) {
auto res = LCompilers::asr_to_cpp(al, *asr.result, diagnostics,
compiler_options.platform, 0);
compiler_options, 0);
out = diagnostics.render(lm, compiler_options);
if (res.ok) {
out += res.result;
Expand Down
16 changes: 10 additions & 6 deletions src/libasr/codegen/asr_to_c_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ R"(#include <stdio.h>
if (ASR::is_a<ASR::Variable_t>(*var_sym)) {
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(var_sym);
std::string decl = self().convert_variable_decl(*v);
decl = check_tmp_buffer() + decl;
bool used_define_for_const = (ASR::is_a<ASR::Const_t>(*v->m_type) &&
v->m_intent == ASRUtils::intent_local);
if (used_define_for_const) {
Expand Down Expand Up @@ -300,11 +301,12 @@ R"(#include <stdio.h>
ASR::symbol_t* var_sym = x.m_symtab->get_symbol(item);
if (ASR::is_a<ASR::Variable_t>(*var_sym)) {
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(var_sym);
decl += self().convert_variable_decl(*v);
std::string d = self().convert_variable_decl(*v);
if( !ASR::is_a<ASR::Const_t>(*v->m_type) ||
v->m_intent == ASRUtils::intent_return_var ) {
decl += ";\n";
d += ";\n";
}
decl += check_tmp_buffer() + d;
}
}

Expand Down Expand Up @@ -336,11 +338,12 @@ R"(#include <stdio.h>
ASR::symbol_t* var_sym = block->m_symtab->get_symbol(item);
if (ASR::is_a<ASR::Variable_t>(*var_sym)) {
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(var_sym);
decl += indent + self().convert_variable_decl(*v);
std::string d = indent + self().convert_variable_decl(*v);
if( !ASR::is_a<ASR::Const_t>(*v->m_type) ||
v->m_intent == ASRUtils::intent_return_var ) {
decl += ";\n";
d += ";\n";
}
decl += check_tmp_buffer() + d;
}
}
for (size_t i=0; i<block->n_body; i++) {
Expand Down Expand Up @@ -539,11 +542,12 @@ R"(#include <stdio.h>
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(var_sym);
if (v->m_intent == ASRUtils::intent_local ||
v->m_intent == ASRUtils::intent_return_var) {
decl += indent + self().convert_variable_decl(*v);
std::string d = indent + self().convert_variable_decl(*v);
if( !ASR::is_a<ASR::Const_t>(*v->m_type) ||
v->m_intent == ASRUtils::intent_return_var ) {
decl += ";\n";
d += ";\n";
}
decl += check_tmp_buffer() + d;
}
if (ASR::is_a<ASR::TypeParameter_t>(*v->m_type)) {
has_typevar = true;
Expand Down

0 comments on commit b89fadf

Please sign in to comment.