Merge initializers and assignments (#1088)

This commit is contained in:
pi1024e
2020-03-16 18:52:48 -04:00
committed by GitHub
parent 319f0e850c
commit d14423d0f1
8 changed files with 69 additions and 130 deletions

View File

@@ -36,18 +36,15 @@ namespace
IDC_RSHF,3, IDC_LSHF,3, IDC_RSHFL,3,
IDC_MOD,3, IDC_DIV,3, IDC_MUL,3,
IDC_PWR,4, IDC_ROOT,4, IDC_LOGBASEX,4 };
unsigned int iPrec;
iPrec = 0;
while ((iPrec < size(rgbPrec)) && (nopCode != rgbPrec[iPrec]))
for (unsigned int iPrec = 0; iPrec < size(rgbPrec); iPrec += 2)
{
iPrec += 2;
if (nopCode == rgbPrec[iPrec])
{
return rgbPrec[iPrec + 1];
}
}
if (iPrec >= size(rgbPrec))
{
iPrec = 0;
}
return rgbPrec[iPrec + 1];
return 0;
}
}
@@ -104,8 +101,6 @@ void CCalcEngine::ProcessCommand(OpCode wParam)
void CCalcEngine::ProcessCommandWorker(OpCode wParam)
{
int nx, ni;
// Save the last command. Some commands are not saved in this manor, these
// commands are:
// Inv, Deg, Rad, Grad, Stat, FE, MClear, Back, and Exp. The excluded
@@ -163,14 +158,11 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
DisplayNum(); // Causes 3.000 to shrink to 3. on first op.
}
}
else
else if (IsDigitOpCode(wParam) || wParam == IDC_PNT)
{
if (IsDigitOpCode(wParam) || wParam == IDC_PNT)
{
m_bRecord = true;
m_input.Clear();
CheckAndAddLastBinOpToHistory();
}
m_bRecord = true;
m_input.Clear();
CheckAndAddLastBinOpToHistory();
}
// Interpret digit keys.
@@ -203,7 +195,6 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
// Change the operation if last input was operation.
if (IsBinOpCode(m_nLastCom))
{
int nPrev;
bool fPrecInvToHigher = false; // Is Precedence Inversion from lower to higher precedence happening ??
m_nOpCode = (int)wParam;
@@ -214,9 +205,9 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
// Here * is m_nPrevOpCode, m_currentVal is 2 (by 1*2), m_nLastCom is +, m_nOpCode is ^
if (m_fPrecedence && 0 != m_nPrevOpCode)
{
nPrev = NPrecedenceOfOp(m_nPrevOpCode);
nx = NPrecedenceOfOp(m_nLastCom);
ni = NPrecedenceOfOp(m_nOpCode);
int nPrev = NPrecedenceOfOp(m_nPrevOpCode);
int nx = NPrecedenceOfOp(m_nLastCom);
int ni = NPrecedenceOfOp(m_nOpCode);
if (nx <= nPrev && ni > nPrev) // condition for Precedence Inversion
{
fPrecInvToHigher = true;
@@ -243,8 +234,8 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
{
DoPrecedenceCheckAgain:
nx = NPrecedenceOfOp((int)wParam);
ni = NPrecedenceOfOp(m_nOpCode);
int nx = NPrecedenceOfOp((int)wParam);
int ni = NPrecedenceOfOp(m_nOpCode);
if ((nx > ni) && m_fPrecedence)
{
@@ -492,8 +483,8 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
m_lastVal = m_precedenceVals[m_precedenceOpCount];
// Precedence Inversion check
ni = NPrecedenceOfOp(m_nPrevOpCode);
nx = NPrecedenceOfOp(m_nOpCode);
int ni = NPrecedenceOfOp(m_nPrevOpCode);
int nx = NPrecedenceOfOp(m_nOpCode);
if (ni <= nx)
{
m_HistoryCollector.EnclosePrecInversionBrackets();
@@ -518,20 +509,15 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
case IDC_OPENP:
case IDC_CLOSEP:
nx = 0;
if (wParam == IDC_OPENP)
{
nx = 1;
}
// -IF- the Paren holding array is full and we try to add a paren
// -OR- the paren holding array is empty and we try to remove a
// paren
// -OR- the precedence holding array is full
if ((m_openParenCount >= MAXPRECDEPTH && nx) || (!m_openParenCount && !nx)
if ((m_openParenCount >= MAXPRECDEPTH && (wParam == IDC_OPENP)) || (!m_openParenCount && (wParam != IDC_OPENP))
|| ((m_precedenceOpCount >= MAXPRECDEPTH && m_nPrecOp[m_precedenceOpCount - 1] != 0)))
{
if (!m_openParenCount && !nx)
if (!m_openParenCount && (wParam != IDC_OPENP))
{
m_pCalcDisplay->OnNoRightParenAdded();
}
@@ -540,7 +526,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
break;
}
if (nx)
if (wParam == IDC_OPENP)
{
CheckAndAddLastBinOpToHistory();
m_HistoryCollector.AddOpenBraceToHistory();
@@ -588,8 +574,8 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
for (m_nOpCode = m_nPrecOp[--m_precedenceOpCount]; m_nOpCode; m_nOpCode = m_nPrecOp[--m_precedenceOpCount])
{
// Precedence Inversion check
ni = NPrecedenceOfOp(m_nPrevOpCode);
nx = NPrecedenceOfOp(m_nOpCode);
int ni = NPrecedenceOfOp(m_nPrevOpCode);
int nx = NPrecedenceOfOp(m_nOpCode);
if (ni <= nx)
{
m_HistoryCollector.EnclosePrecInversionBrackets();
@@ -952,7 +938,7 @@ static const std::unordered_map<int, FunctionNameElement> operatorStringTable =
{ IDC_SECH, { SIDS_SECH, SIDS_ASECH } },
{ IDC_CSCH, { SIDS_CSCH, SIDS_ACSCH } },
{ IDC_COTH, { SIDS_COTH, SIDS_ACOTH } },
{ IDC_LN, { L"", SIDS_POWE } },
{ IDC_SQR, { SIDS_SQR } },
{ IDC_CUB, { SIDS_CUBE } },
@@ -971,8 +957,8 @@ static const std::unordered_map<int, FunctionNameElement> operatorStringTable =
{ IDC_RSHFL, { SIDS_RSH } },
{ IDC_RORC, { SIDS_ROR } },
{ IDC_ROLC, { SIDS_ROL } },
{ IDC_CUBEROOT, {SIDS_CUBEROOT} },
{ IDC_MOD, {SIDS_MOD, L"", L"", L"", L"", L"", SIDS_PROGRAMMER_MOD} },
{ IDC_CUBEROOT, { SIDS_CUBEROOT } },
{ IDC_MOD, { SIDS_MOD, L"", L"", L"", L"", L"", SIDS_PROGRAMMER_MOD } },
};
wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE angletype)