From ce73909da6745b276fe32f3f5a54db20a8dc50aa Mon Sep 17 00:00:00 2001 From: kevstone Date: Thu, 18 Jan 2024 14:53:47 +0000 Subject: [PATCH] Better for() generation --- .../code_object/for_statement.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/clang_convert/code_object/for_statement.py b/src/clang_convert/code_object/for_statement.py index b95e62d7e..6fd9cab43 100755 --- a/src/clang_convert/code_object/for_statement.py +++ b/src/clang_convert/code_object/for_statement.py @@ -62,18 +62,19 @@ class ForStatement(code_interface.CodeInterface): return self._statement def as_lines(self): - lines = ["for("] + init_string = cond_string = iter_string = "" if self._init_statement: - lines.extend(self._init_statement.as_lines()) - if not lines[-1].endswith(";"): - lines[-1] += ";" + init_string = self._init_statement.as_string() + if not init_string.endswith(";"): + init_string += ";" if self._condition: - lines.extend(self._condition.as_lines()) - if not lines[-1].endswith(";"): - lines[-1] += ";" + cond_string = self._condition.as_string() + if not cond_string.endswith(";"): + cond_string += ";" if self._iteration_expression: - lines.extend(self._iteration_expression.as_lines()) - lines[-1] += ")" + iter_string = self._iteration_expression.as_string() + + lines = [f"for({init_string}{cond_string}{iter_string})"] if self._statement: lines.extend(self._statement.as_lines())