mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 06:13:14 -07:00
Change uintptr_t -> OpCode
This commit is contained in:
parent
c725ba7c53
commit
15c1ab6868
5 changed files with 36 additions and 33 deletions
|
@ -5,24 +5,24 @@
|
|||
#include "Header Files/CalcEngine.h"
|
||||
#include "Header Files/CalcUtils.h"
|
||||
|
||||
bool IsOpInRange(uintptr_t op, uint32_t x, uint32_t y)
|
||||
bool IsOpInRange(OpCode op, uint32_t x, uint32_t y)
|
||||
{
|
||||
return ((op >= x) && (op <= y));
|
||||
}
|
||||
|
||||
bool IsBinOpCode(uintptr_t opCode)
|
||||
bool IsBinOpCode(OpCode opCode)
|
||||
{
|
||||
return IsOpInRange(opCode, IDC_AND, IDC_PWR);
|
||||
}
|
||||
|
||||
// WARNING: IDC_SIGN is a special unary op but still this doesn't catch this. Caller has to be aware
|
||||
// of it and catch it themselves or not needing this
|
||||
bool IsUnaryOpCode(uintptr_t opCode)
|
||||
bool IsUnaryOpCode(OpCode opCode)
|
||||
{
|
||||
return IsOpInRange(opCode, IDC_UNARYFIRST, IDC_UNARYLAST);
|
||||
}
|
||||
|
||||
bool IsDigitOpCode(uintptr_t opCode)
|
||||
bool IsDigitOpCode(OpCode opCode)
|
||||
{
|
||||
return IsOpInRange(opCode, IDC_0, IDC_F);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ bool IsDigitOpCode(uintptr_t opCode)
|
|||
// so we abstract this as a separate routine. Note: There is another side to this. Some commands are not
|
||||
// gui mode setting to begin with, but once it is discovered it is invalid and we want to behave as though it
|
||||
// was never inout, we need to revert the state changes made as a result of this test
|
||||
bool IsGuiSettingOpCode(uintptr_t opCode)
|
||||
bool IsGuiSettingOpCode(OpCode opCode)
|
||||
{
|
||||
if (IsOpInRange(opCode, IDM_HEX, IDM_BIN) ||
|
||||
IsOpInRange(opCode, IDM_QWORD, IDM_BYTE) ||
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace {
|
|||
//
|
||||
// When it is discovered by the state machine that at this point the input is not valid (eg. "1+)"), we want to proceed as though this input never
|
||||
// occurred and may be some feedback to user like Beep. The rest of input can then continue by just ignoring this command.
|
||||
void CCalcEngine::HandleErrorCommand(uintptr_t idc)
|
||||
void CCalcEngine::HandleErrorCommand(OpCode idc)
|
||||
{
|
||||
if (!IsGuiSettingOpCode(idc))
|
||||
{
|
||||
|
@ -83,7 +83,7 @@ void CCalcEngine::ClearTemporaryValues()
|
|||
m_bError = false;
|
||||
}
|
||||
|
||||
void CCalcEngine::ProcessCommand(uintptr_t wParam)
|
||||
void CCalcEngine::ProcessCommand(OpCode wParam)
|
||||
{
|
||||
if (wParam == IDC_SET_RESULT)
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ void CCalcEngine::ProcessCommand(uintptr_t wParam)
|
|||
ProcessCommandWorker(wParam);
|
||||
}
|
||||
|
||||
void CCalcEngine::ProcessCommandWorker(uintptr_t wParam)
|
||||
void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
||||
{
|
||||
int nx, ni;
|
||||
|
||||
|
|
|
@ -212,7 +212,7 @@ namespace CalculationManager
|
|||
|
||||
/// <summary>
|
||||
/// Send command to the Calc Engine
|
||||
/// Cast Command Enum to uintptr_t.
|
||||
/// Cast Command Enum to OpCode.
|
||||
/// Handle special commands such as mode change and combination of two commands.
|
||||
/// </summary>
|
||||
/// <param name="command">Enum Command</command>
|
||||
|
@ -235,7 +235,7 @@ namespace CalculationManager
|
|||
this->SetProgrammerMode();
|
||||
break;
|
||||
default:
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(command));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(command));
|
||||
}
|
||||
|
||||
m_savedCommands.clear(); // Clear the previous command history
|
||||
|
@ -263,38 +263,38 @@ namespace CalculationManager
|
|||
switch (command)
|
||||
{
|
||||
case Command::CommandASIN:
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandSIN));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandSIN));
|
||||
break;
|
||||
case Command::CommandACOS:
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandCOS));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandCOS));
|
||||
break;
|
||||
case Command::CommandATAN:
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandTAN));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandTAN));
|
||||
break;
|
||||
case Command::CommandPOWE:
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandLN));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandLN));
|
||||
break;
|
||||
case Command::CommandASINH:
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandSINH));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandSINH));
|
||||
break;
|
||||
case Command::CommandACOSH:
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandCOSH));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandCOSH));
|
||||
break;
|
||||
case Command::CommandATANH:
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandTANH));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandTANH));
|
||||
break;
|
||||
case Command::CommandFE:
|
||||
m_isExponentialFormat = !m_isExponentialFormat;
|
||||
[[fallthrough]];
|
||||
default:
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(command));
|
||||
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(command));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "RadixType.h"
|
||||
#include "History.h" // for History Collector
|
||||
#include "CalcInput.h"
|
||||
#include "CalcUtils.h"
|
||||
#include "ICalcDisplay.h"
|
||||
#include "Rational.h"
|
||||
#include "RationalMath.h"
|
||||
|
@ -52,7 +53,7 @@ namespace CalculatorUnitTests
|
|||
class CCalcEngine {
|
||||
public:
|
||||
CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager::IResourceProvider* const pResourceProvider, __in_opt ICalcDisplay *pCalcDisplay, __in_opt std::shared_ptr<IHistoryDisplay> pHistoryDisplay);
|
||||
void ProcessCommand(uintptr_t wID);
|
||||
void ProcessCommand(OpCode wID);
|
||||
void DisplayError (uint32_t nError);
|
||||
std::unique_ptr<CalcEngine::Rational> PersistedMemObject();
|
||||
void PersistedMemObject(CalcEngine::Rational const& memObject);
|
||||
|
@ -127,8 +128,8 @@ private:
|
|||
wchar_t m_groupSeparator;
|
||||
|
||||
private:
|
||||
void ProcessCommandWorker(uintptr_t wParam);
|
||||
void HandleErrorCommand(uintptr_t idc);
|
||||
void ProcessCommandWorker(OpCode wParam);
|
||||
void HandleErrorCommand(OpCode idc);
|
||||
void HandleMaxDigitsReached();
|
||||
void DisplayNum(void);
|
||||
int IsNumberInvalid(const std::wstring& numberString, int iMaxExp, int iMaxMantissa, uint32_t radix) const;
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
bool IsOpInRange(uintptr_t op, uint32_t x, uint32_t y);
|
||||
bool IsBinOpCode(uintptr_t opCode);
|
||||
using OpCode = uintptr_t;
|
||||
|
||||
bool IsOpInRange(OpCode op, uint32_t x, uint32_t y);
|
||||
bool IsBinOpCode(OpCode opCode);
|
||||
|
||||
// WARNING: IDC_SIGN is a special unary op but still this doesn't catch this. Caller has to be aware
|
||||
// of it and catch it themselves or not needing this
|
||||
bool IsUnaryOpCode(uintptr_t opCode);
|
||||
bool IsDigitOpCode(uintptr_t opCode);
|
||||
bool IsGuiSettingOpCode(uintptr_t opCode);
|
||||
bool IsUnaryOpCode(OpCode opCode);
|
||||
bool IsDigitOpCode(OpCode opCode);
|
||||
bool IsGuiSettingOpCode(OpCode opCode);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue