Made first pass at retokenizing negative numbers. May still have some issues.
This commit is contained in:
parent
f4c871c9b9
commit
094b44c66e
|
@ -428,7 +428,47 @@ QVector<ApplesoftToken> Retokenizer::retokenizeNegativeNumbers(QVector<Applesoft
|
|||
// Best bet would be to look at how AppleSoft handles these values.
|
||||
// A = - 0 is the same as 0
|
||||
|
||||
QList<ApplesoftToken> tmptokens = QList<ApplesoftToken>::fromVector(datatokens);
|
||||
ApplesoftToken token;
|
||||
|
||||
QMutableListIterator<ApplesoftToken>it(tmptokens);
|
||||
|
||||
bool lastWasInt = false;
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
token = it.next();
|
||||
if (token.getTokenId() == ApplesoftToken::IntegerTokenVal) lastWasInt = true;
|
||||
else if (token.getTokenId() == ApplesoftToken::FloatTokenVal) lastWasInt = true;
|
||||
else if (token.getTokenId() == ApplesoftToken::IntVarTokenVal) lastWasInt = true;
|
||||
else if (token.getTokenId() == ApplesoftToken::FloatVarTokenVal) lastWasInt = true;
|
||||
else if (token.getTokenId() == ')') lastWasInt = true;
|
||||
else
|
||||
if (token.getTokenId() == ApplesoftToken::ASMINUS)
|
||||
{
|
||||
if (!lastWasInt && it.hasNext() && it.peekNext().getTokenId() == ApplesoftToken::IntegerTokenVal)
|
||||
{
|
||||
it.remove();
|
||||
token = it.next();
|
||||
it.remove();
|
||||
int val = token.getUnsignedIntegerValue() * -1;
|
||||
token.setValue(val);
|
||||
it.insert(token);
|
||||
lastWasInt = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastWasInt = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastWasInt = false;
|
||||
}
|
||||
|
||||
|
||||
return datatokens;
|
||||
|
||||
}
|
||||
|
||||
return tmptokens.toVector();
|
||||
}
|
||||
|
|
|
@ -81,13 +81,15 @@ QString ApplesoftFormatter::formatText()
|
|||
|
||||
if (okToConvert)
|
||||
{
|
||||
quint32 ui32val = token.getIntegerValue();
|
||||
if (ui32val < 256)
|
||||
quint32 ui32val = token.getUnsignedIntegerValue();
|
||||
qint32 i32val = token.getIntegerValue();
|
||||
qDebug() << "UI32: " << ui32val << " I32: " << i32val;
|
||||
if ((i32val < 128 && i32val >= -128) || ui32val < 256)
|
||||
{
|
||||
quint8 ui8 = ui32val;
|
||||
tokenstr = "0x"+uint8ToHex(ui8);
|
||||
}
|
||||
else if (ui32val < 65536)
|
||||
else if ((i32val < 32768 && i32val >= -32768) || ui32val < 65536)
|
||||
{
|
||||
quint16 ui16 = ui32val;
|
||||
tokenstr = "0x"+uint16ToHex(ui16);
|
||||
|
|
|
@ -137,7 +137,9 @@ public:
|
|||
|
||||
QByteArray getByteStringValue() const { return m_payload.toByteArray(); }
|
||||
QString getStringValue() const { return m_payload.toString(); }
|
||||
quint32 getIntegerValue() const { return (quint32) (m_payload.toUInt() & 0xFFFFFFFF); }
|
||||
quint32 getUnsignedIntegerValue() const { return (quint32) (m_payload.toUInt() & 0xFFFFFFFF); }
|
||||
qint32 getIntegerValue() const { return (qint32) (m_payload.toInt() & 0xFFFFFFFF); }
|
||||
|
||||
quint16 getWordValue() const { return (quint16) (m_payload.toUInt() & 0xFFFF); }
|
||||
quint8 getByteValue() const { return (quint8) (m_payload.toUInt() & 0xFF); }
|
||||
|
||||
|
|
Loading…
Reference in New Issue