Fix some code analysis warnings in CalcManager (#1074)

This commit is contained in:
Matt Cooley
2020-03-30 15:23:22 -07:00
committed by GitHub
parent cf735bbcf5
commit f552428d97
30 changed files with 225 additions and 219 deletions

View File

@@ -210,7 +210,7 @@ bool CHistoryCollector::FOpndAddedToHistory()
// This is does the postfix to prefix translation of the input and adds the text to the history. Eg. doing 2 + 4 (sqrt),
// this routine will ensure the last sqrt call unary operator, actually goes back in history and wraps 4 in sqrt(4)
//
void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE angletype)
void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, AngleType angletype)
{
int iCommandEnd;
// When successfully applying a unary op, there should be an opnd already
@@ -230,15 +230,15 @@ void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE a
else
{
CalculationManager::Command angleOpCode;
if (angletype == ANGLE_DEG)
if (angletype == AngleType::Degrees)
{
angleOpCode = CalculationManager::Command::CommandDEG;
}
else if (angletype == ANGLE_RAD)
else if (angletype == AngleType::Radians)
{
angleOpCode = CalculationManager::Command::CommandRAD;
}
else // (angletype == ANGLE_GRAD)
else // (angletype == AngleType::Gradians)
{
angleOpCode = CalculationManager::Command::CommandGRAD;
}

View File

@@ -460,7 +460,7 @@ namespace CalcEngine
return !(lhs < rhs);
}
wstring Rational::ToString(uint32_t radix, NUMOBJ_FMT fmt, int32_t precision) const
wstring Rational::ToString(uint32_t radix, NumberFormat fmt, int32_t precision) const
{
PRAT rat = this->ToPRAT();
wstring result{};

View File

@@ -147,7 +147,7 @@ Rational RationalMath::Abs(Rational const& rat)
return Rational{ Number{ 1, rat.P().Exp(), rat.P().Mantissa() }, Number{ 1, rat.Q().Exp(), rat.Q().Mantissa() } };
}
Rational RationalMath::Sin(Rational const& rat, ANGLE_TYPE angletype)
Rational RationalMath::Sin(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
@@ -167,7 +167,7 @@ Rational RationalMath::Sin(Rational const& rat, ANGLE_TYPE angletype)
return result;
}
Rational RationalMath::Cos(Rational const& rat, ANGLE_TYPE angletype)
Rational RationalMath::Cos(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
@@ -187,7 +187,7 @@ Rational RationalMath::Cos(Rational const& rat, ANGLE_TYPE angletype)
return result;
}
Rational RationalMath::Tan(Rational const& rat, ANGLE_TYPE angletype)
Rational RationalMath::Tan(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
@@ -207,7 +207,7 @@ Rational RationalMath::Tan(Rational const& rat, ANGLE_TYPE angletype)
return result;
}
Rational RationalMath::ASin(Rational const& rat, ANGLE_TYPE angletype)
Rational RationalMath::ASin(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
@@ -227,7 +227,7 @@ Rational RationalMath::ASin(Rational const& rat, ANGLE_TYPE angletype)
return result;
}
Rational RationalMath::ACos(Rational const& rat, ANGLE_TYPE angletype)
Rational RationalMath::ACos(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
@@ -247,7 +247,7 @@ Rational RationalMath::ACos(Rational const& rat, ANGLE_TYPE angletype)
return result;
}
Rational RationalMath::ATan(Rational const& rat, ANGLE_TYPE angletype)
Rational RationalMath::ATan(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();

View File

@@ -73,7 +73,7 @@ CCalcEngine::CCalcEngine(
, m_bRecord(false)
, m_bSetCalcState(false)
, m_input(DEFAULT_DEC_SEPARATOR)
, m_nFE(FMT_FLOAT)
, m_nFE(NumberFormat::Float)
, m_memoryValue{ make_unique<Rational>() }
, m_holdVal{}
, m_currentVal{}
@@ -94,8 +94,8 @@ CCalcEngine::CCalcEngine(
, m_nPrecOp()
, m_precedenceOpCount(0)
, m_nLastCom(0)
, m_angletype(ANGLE_DEG)
, m_numwidth(QWORD_WIDTH)
, m_angletype(AngleType::Degrees)
, m_numwidth(NUM_WIDTH::QWORD_WIDTH)
, m_HistoryCollector(pCalcDisplay, pHistoryDisplay, DEFAULT_DEC_SEPARATOR)
, m_groupSeparator(DEFAULT_GRP_SEPARATOR)
{
@@ -105,7 +105,7 @@ CCalcEngine::CCalcEngine(
m_maxTrigonometricNum = RationalMath::Pow(10, 100);
SetRadixTypeAndNumWidth(DEC_RADIX, m_numwidth);
SetRadixTypeAndNumWidth(RadixType::Decimal, m_numwidth);
SettingsChanged();
DisplayNum();
}
@@ -128,10 +128,20 @@ void CCalcEngine::InitChopNumbers()
auto maxVal = m_chopNumbers[i] / 2;
maxVal = RationalMath::Integer(maxVal);
m_maxDecimalValueStrings[i] = maxVal.ToString(10, FMT_FLOAT, m_precision);
m_maxDecimalValueStrings[i] = maxVal.ToString(10, NumberFormat::Float, m_precision);
}
}
CalcEngine::Rational CCalcEngine::GetChopNumber() const
{
return m_chopNumbers[static_cast<int>(m_numwidth)];
}
std::wstring CCalcEngine::GetMaxDecimalValueString() const
{
return m_maxDecimalValueStrings[static_cast<int>(m_numwidth)];
}
// Gets the number in memory for UI to keep it persisted and set it again to a different instance
// of CCalcEngine. Otherwise it will get destructed with the CalcEngine
unique_ptr<Rational> CCalcEngine::PersistedMemObject()

View File

@@ -177,7 +177,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
return;
}
if (!m_input.TryAddDigit(iValue, m_radix, m_fIntegerMode, m_maxDecimalValueStrings[m_numwidth], m_dwWordBitWidth, m_cIntDigitsSav))
if (!m_input.TryAddDigit(iValue, m_radix, m_fIntegerMode, GetMaxDecimalValueString(), m_dwWordBitWidth, m_cIntDigitsSav))
{
HandleErrorCommand(wParam);
HandleMaxDigitsReached();
@@ -619,7 +619,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
case IDM_OCT:
case IDM_BIN:
{
SetRadixTypeAndNumWidth((RADIX_TYPE)(wParam - IDM_HEX), (NUM_WIDTH)-1);
SetRadixTypeAndNumWidth((RadixType)(wParam - IDM_HEX), (NUM_WIDTH)-1);
m_HistoryCollector.UpdateHistoryExpression(m_radix, m_precision);
break;
}
@@ -635,20 +635,20 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
}
// Compat. mode BaseX: Qword, Dword, Word, Byte
SetRadixTypeAndNumWidth((RADIX_TYPE)-1, (NUM_WIDTH)(wParam - IDM_QWORD));
SetRadixTypeAndNumWidth((RadixType)-1, (NUM_WIDTH)(wParam - IDM_QWORD));
break;
case IDM_DEG:
case IDM_RAD:
case IDM_GRAD:
m_angletype = static_cast<ANGLE_TYPE>(wParam - IDM_DEG);
m_angletype = static_cast<AngleType>(wParam - IDM_DEG);
break;
case IDC_SIGN:
{
if (m_bRecord)
{
if (m_input.TryToggleSign(m_fIntegerMode, m_maxDecimalValueStrings[m_numwidth]))
if (m_input.TryToggleSign(m_fIntegerMode, GetMaxDecimalValueString()))
{
DisplayNum();
}
@@ -766,7 +766,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
break;
case IDC_FE:
// Toggle exponential notation display.
m_nFE = NUMOBJ_FMT(!(int)m_nFE);
m_nFE = NumberFormat(!(int)m_nFE);
DisplayNum();
break;
@@ -961,7 +961,7 @@ static const std::unordered_map<int, FunctionNameElement> operatorStringTable =
{ IDC_MOD, { SIDS_MOD, L"", L"", L"", L"", L"", SIDS_PROGRAMMER_MOD } },
};
wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE angletype)
wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, AngleType angletype)
{
// Try to lookup the ID in the UFNE table
wstring ids = L"";
@@ -969,7 +969,7 @@ wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE
if (auto pair = operatorStringTable.find(nOpCode); pair != operatorStringTable.end())
{
const FunctionNameElement& element = pair->second;
if (!element.hasAngleStrings || ANGLE_DEG == angletype)
if (!element.hasAngleStrings || AngleType::Degrees == angletype)
{
if (fInv)
{
@@ -981,7 +981,7 @@ wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE
ids = element.degreeString;
}
}
else if (ANGLE_RAD == angletype)
else if (AngleType::Radians == angletype)
{
if (fInv)
{
@@ -992,7 +992,7 @@ wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE
ids = element.radString;
}
}
else if (ANGLE_GRAD == angletype)
else if (AngleType::Gradians == angletype)
{
if (fInv)
{
@@ -1094,7 +1094,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
if ((radix == 10) && fMsb)
{
// If high bit is set, then get the decimal number in negative 2's complement form.
tempRat = -((tempRat ^ m_chopNumbers[m_numwidth]) + 1);
tempRat = -((tempRat ^ GetChopNumber()) + 1);
}
result = tempRat.ToString(radix, m_nFE, m_precision);

View File

@@ -67,10 +67,10 @@ CalcEngine::Rational CCalcEngine::TruncateNumForIntMath(CalcEngine::Rational con
{
// if negative make positive by doing a twos complement
result = -(result)-1;
result ^= m_chopNumbers[m_numwidth];
result ^= GetChopNumber();
}
result &= m_chopNumbers[m_numwidth];
result &= GetChopNumber();
return result;
}

View File

@@ -42,7 +42,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
}
else
{
result = rat ^ m_chopNumbers[m_numwidth];
result = rat ^ GetChopNumber();
}
break;

View File

@@ -29,11 +29,11 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
break;
case IDC_NAND:
result = (result & rhs) ^ m_chopNumbers[m_numwidth];
result = (result & rhs) ^ GetChopNumber();
break;
case IDC_NOR:
result = (result | rhs) ^ m_chopNumbers[m_numwidth];
result = (result | rhs) ^ GetChopNumber();
break;
case IDC_RSHF:
@@ -53,10 +53,10 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
{
result = Integer(result);
auto tempRat = m_chopNumbers[m_numwidth] >> holdVal;
auto tempRat = GetChopNumber() >> holdVal;
tempRat = Integer(tempRat);
result |= tempRat ^ m_chopNumbers[m_numwidth];
result |= tempRat ^ GetChopNumber();
}
break;
}
@@ -105,7 +105,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
if (fMsb)
{
result = (rhs ^ m_chopNumbers[m_numwidth]) + 1;
result = (rhs ^ GetChopNumber()) + 1;
iNumeratorSign = -1;
}
@@ -115,7 +115,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
if (fMsb)
{
temp = (temp ^ m_chopNumbers[m_numwidth]) + 1;
temp = (temp ^ GetChopNumber()) + 1;
iDenominatorSign = -1;
}

View File

@@ -9,7 +9,7 @@ using namespace std;
// To be called when either the radix or num width changes. You can use -1 in either of these values to mean
// dont change that.
void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwidth)
void CCalcEngine::SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidth)
{
// When in integer mode, the number is represented in 2's complement form. When a bit width is changing, we can
// change the number representation back to sign, abs num form in ratpak. Soon when display sees this, it will
@@ -24,19 +24,19 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
if (fMsb)
{
// If high bit is set, then get the decimal number in -ve 2'scompl form.
auto tempResult = m_currentVal ^ m_chopNumbers[m_numwidth];
auto tempResult = m_currentVal ^ GetChopNumber();
m_currentVal = -(tempResult + 1);
}
}
if (radixtype >= HEX_RADIX && radixtype <= BIN_RADIX)
if (radixtype >= RadixType::Hex && radixtype <= RadixType::Binary)
{
m_radix = NRadixFromRadixType(radixtype);
// radixtype is not even saved
}
if (numwidth >= QWORD_WIDTH && numwidth <= BYTE_WIDTH)
if (numwidth >= NUM_WIDTH::QWORD_WIDTH && numwidth <= NUM_WIDTH::BYTE_WIDTH)
{
m_numwidth = numwidth;
m_dwWordBitWidth = DwWordBitWidthFromeNumWidth(numwidth);
@@ -50,29 +50,36 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
DisplayNum();
}
int32_t CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH /*numwidth*/)
int32_t CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth)
{
static constexpr int nBitMax[] = { 64, 32, 16, 8 };
int32_t wmax = nBitMax[0];
if (m_numwidth >= 0 && (size_t)m_numwidth < size(nBitMax))
switch (numwidth)
{
wmax = nBitMax[m_numwidth];
case NUM_WIDTH::DWORD_WIDTH:
return 32;
case NUM_WIDTH::WORD_WIDTH:
return 16;
case NUM_WIDTH::BYTE_WIDTH:
return 8;
case NUM_WIDTH::QWORD_WIDTH:
default:
return 64;
}
return wmax;
}
uint32_t CCalcEngine::NRadixFromRadixType(RADIX_TYPE radixtype)
uint32_t CCalcEngine::NRadixFromRadixType(RadixType radixtype)
{
static constexpr uint32_t rgnRadish[4] = { 16, 10, 8, 2 }; /* Number bases in the same order as radixtype */
uint32_t radix = 10;
// convert special bases into symbolic values
if (radixtype >= 0 && (size_t)radixtype < size(rgnRadish))
switch (radixtype)
{
radix = rgnRadish[radixtype];
case RadixType::Hex:
return 16;
case RadixType::Octal:
return 8;
case RadixType::Binary:
return 2;
case RadixType::Decimal:
default:
return 10;
}
return radix;
}
// Toggles a given bit into the number representation. returns true if it changed it actually.
@@ -141,7 +148,7 @@ void CCalcEngine::UpdateMaxIntDigits()
// if in integer mode you still have to honor the max digits you can enter based on bit width
if (m_fIntegerMode)
{
m_cIntDigitsSav = static_cast<int>(m_maxDecimalValueStrings[m_numwidth].length()) - 1;
m_cIntDigitsSav = static_cast<int>(GetMaxDecimalValueString().length()) - 1;
// This is the max digits you can enter a decimal in fixed width mode aka integer mode -1. The last digit
// has to be checked separately
}