Skip to content

Commit b89fadf

Browse files
committed
Fix variable decl order
1 parent 56bd232 commit b89fadf

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/bin/lpython.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ EMSCRIPTEN_KEEPALIVE char* emit_cpp_from_source(char *input) {
12481248
out = diagnostics.render(lm, compiler_options);
12491249
if (asr.ok) {
12501250
auto res = LCompilers::asr_to_cpp(al, *asr.result, diagnostics,
1251-
compiler_options.platform, 0);
1251+
compiler_options, 0);
12521252
out = diagnostics.render(lm, compiler_options);
12531253
if (res.ok) {
12541254
out += res.result;

src/libasr/codegen/asr_to_c_cpp.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ R"(#include <stdio.h>
242242
if (ASR::is_a<ASR::Variable_t>(*var_sym)) {
243243
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(var_sym);
244244
std::string decl = self().convert_variable_decl(*v);
245+
decl = check_tmp_buffer() + decl;
245246
bool used_define_for_const = (ASR::is_a<ASR::Const_t>(*v->m_type) &&
246247
v->m_intent == ASRUtils::intent_local);
247248
if (used_define_for_const) {
@@ -300,11 +301,12 @@ R"(#include <stdio.h>
300301
ASR::symbol_t* var_sym = x.m_symtab->get_symbol(item);
301302
if (ASR::is_a<ASR::Variable_t>(*var_sym)) {
302303
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(var_sym);
303-
decl += self().convert_variable_decl(*v);
304+
std::string d = self().convert_variable_decl(*v);
304305
if( !ASR::is_a<ASR::Const_t>(*v->m_type) ||
305306
v->m_intent == ASRUtils::intent_return_var ) {
306-
decl += ";\n";
307+
d += ";\n";
307308
}
309+
decl += check_tmp_buffer() + d;
308310
}
309311
}
310312

@@ -336,11 +338,12 @@ R"(#include <stdio.h>
336338
ASR::symbol_t* var_sym = block->m_symtab->get_symbol(item);
337339
if (ASR::is_a<ASR::Variable_t>(*var_sym)) {
338340
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(var_sym);
339-
decl += indent + self().convert_variable_decl(*v);
341+
std::string d = indent + self().convert_variable_decl(*v);
340342
if( !ASR::is_a<ASR::Const_t>(*v->m_type) ||
341343
v->m_intent == ASRUtils::intent_return_var ) {
342-
decl += ";\n";
344+
d += ";\n";
343345
}
346+
decl += check_tmp_buffer() + d;
344347
}
345348
}
346349
for (size_t i=0; i<block->n_body; i++) {
@@ -539,11 +542,12 @@ R"(#include <stdio.h>
539542
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(var_sym);
540543
if (v->m_intent == ASRUtils::intent_local ||
541544
v->m_intent == ASRUtils::intent_return_var) {
542-
decl += indent + self().convert_variable_decl(*v);
545+
std::string d = indent + self().convert_variable_decl(*v);
543546
if( !ASR::is_a<ASR::Const_t>(*v->m_type) ||
544547
v->m_intent == ASRUtils::intent_return_var ) {
545-
decl += ";\n";
548+
d += ";\n";
546549
}
550+
decl += check_tmp_buffer() + d;
547551
}
548552
if (ASR::is_a<ASR::TypeParameter_t>(*v->m_type)) {
549553
has_typevar = true;

0 commit comments

Comments
 (0)