From b80b157489f988694c1c506f8bad4668f4959392 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Fri, 27 Oct 2017 19:53:38 +0200 Subject: [PATCH] Add a space between a minus sign and a negative constant. When a constant was negative internally, it was output with the sign included. The code was not prepared to handle this, and could therefore cause double minus signs. For example, -2147483648 was output as --2147483648, and -4294967296 was output as --1. Fixed by adding a space for floats, and by translating the number to the range 2147483648..4294967295 for integers (hex would have worked just as well). --- lslopt/lsloutput.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lslopt/lsloutput.py b/lslopt/lsloutput.py index 7ef0abf..461aaaa 100644 --- a/lslopt/lsloutput.py +++ b/lslopt/lsloutput.py @@ -329,10 +329,20 @@ class outscript(object): paren = False if nt == 'NEG': ret = '-' + if (lnt == 'CONST' and child[0]['t'] == 'integer' + and child[0]['value'] < 0 + ): + # shortcut + ret += str(child[0]['value'] + 4294967296) + return ret if lnt in self.op_priority: paren = self.op_priority[lnt] <= self.op_priority['-'] - elif lnt == 'NEG' or lnt == '--V': - ret += ' ' # don't output -- as that's a different token + elif (lnt == 'NEG' or lnt == '--V' + or lnt == 'CONST' + and child[0]['t'] == 'float' + and child[0]['value'] < 0 + ): + ret += ' ' # don't output "--" as that's a different token else: if lnt in self.op_priority: paren = True