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/CalcEngine.h"
|
||||||
#include "Header Files/CalcUtils.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));
|
return ((op >= x) && (op <= y));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsBinOpCode(uintptr_t opCode)
|
bool IsBinOpCode(OpCode opCode)
|
||||||
{
|
{
|
||||||
return IsOpInRange(opCode, IDC_AND, IDC_PWR);
|
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
|
// 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
|
// 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);
|
return IsOpInRange(opCode, IDC_UNARYFIRST, IDC_UNARYLAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDigitOpCode(uintptr_t opCode)
|
bool IsDigitOpCode(OpCode opCode)
|
||||||
{
|
{
|
||||||
return IsOpInRange(opCode, IDC_0, IDC_F);
|
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
|
// 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
|
// 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
|
// 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) ||
|
if (IsOpInRange(opCode, IDM_HEX, IDM_BIN) ||
|
||||||
IsOpInRange(opCode, IDM_QWORD, IDM_BYTE) ||
|
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
|
// 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.
|
// 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))
|
if (!IsGuiSettingOpCode(idc))
|
||||||
{
|
{
|
||||||
|
@ -83,7 +83,7 @@ void CCalcEngine::ClearTemporaryValues()
|
||||||
m_bError = false;
|
m_bError = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCalcEngine::ProcessCommand(uintptr_t wParam)
|
void CCalcEngine::ProcessCommand(OpCode wParam)
|
||||||
{
|
{
|
||||||
if (wParam == IDC_SET_RESULT)
|
if (wParam == IDC_SET_RESULT)
|
||||||
{
|
{
|
||||||
|
@ -94,7 +94,7 @@ void CCalcEngine::ProcessCommand(uintptr_t wParam)
|
||||||
ProcessCommandWorker(wParam);
|
ProcessCommandWorker(wParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCalcEngine::ProcessCommandWorker(uintptr_t wParam)
|
void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
||||||
{
|
{
|
||||||
int nx, ni;
|
int nx, ni;
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,7 @@ namespace CalculationManager
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Send command to the Calc Engine
|
/// 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.
|
/// Handle special commands such as mode change and combination of two commands.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command">Enum Command</command>
|
/// <param name="command">Enum Command</command>
|
||||||
|
@ -235,7 +235,7 @@ namespace CalculationManager
|
||||||
this->SetProgrammerMode();
|
this->SetProgrammerMode();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(command));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_savedCommands.clear(); // Clear the previous command history
|
m_savedCommands.clear(); // Clear the previous command history
|
||||||
|
@ -263,38 +263,38 @@ namespace CalculationManager
|
||||||
switch (command)
|
switch (command)
|
||||||
{
|
{
|
||||||
case Command::CommandASIN:
|
case Command::CommandASIN:
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandSIN));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandSIN));
|
||||||
break;
|
break;
|
||||||
case Command::CommandACOS:
|
case Command::CommandACOS:
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandCOS));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandCOS));
|
||||||
break;
|
break;
|
||||||
case Command::CommandATAN:
|
case Command::CommandATAN:
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandTAN));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandTAN));
|
||||||
break;
|
break;
|
||||||
case Command::CommandPOWE:
|
case Command::CommandPOWE:
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandLN));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandLN));
|
||||||
break;
|
break;
|
||||||
case Command::CommandASINH:
|
case Command::CommandASINH:
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandSINH));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandSINH));
|
||||||
break;
|
break;
|
||||||
case Command::CommandACOSH:
|
case Command::CommandACOSH:
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandCOSH));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandCOSH));
|
||||||
break;
|
break;
|
||||||
case Command::CommandATANH:
|
case Command::CommandATANH:
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandINV));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(Command::CommandTANH));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandTANH));
|
||||||
break;
|
break;
|
||||||
case Command::CommandFE:
|
case Command::CommandFE:
|
||||||
m_isExponentialFormat = !m_isExponentialFormat;
|
m_isExponentialFormat = !m_isExponentialFormat;
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
default:
|
default:
|
||||||
m_currentCalculatorEngine->ProcessCommand(static_cast<uintptr_t>(command));
|
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(command));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "RadixType.h"
|
#include "RadixType.h"
|
||||||
#include "History.h" // for History Collector
|
#include "History.h" // for History Collector
|
||||||
#include "CalcInput.h"
|
#include "CalcInput.h"
|
||||||
|
#include "CalcUtils.h"
|
||||||
#include "ICalcDisplay.h"
|
#include "ICalcDisplay.h"
|
||||||
#include "Rational.h"
|
#include "Rational.h"
|
||||||
#include "RationalMath.h"
|
#include "RationalMath.h"
|
||||||
|
@ -52,7 +53,7 @@ namespace CalculatorUnitTests
|
||||||
class CCalcEngine {
|
class CCalcEngine {
|
||||||
public:
|
public:
|
||||||
CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager::IResourceProvider* const pResourceProvider, __in_opt ICalcDisplay *pCalcDisplay, __in_opt std::shared_ptr<IHistoryDisplay> pHistoryDisplay);
|
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);
|
void DisplayError (uint32_t nError);
|
||||||
std::unique_ptr<CalcEngine::Rational> PersistedMemObject();
|
std::unique_ptr<CalcEngine::Rational> PersistedMemObject();
|
||||||
void PersistedMemObject(CalcEngine::Rational const& memObject);
|
void PersistedMemObject(CalcEngine::Rational const& memObject);
|
||||||
|
@ -127,8 +128,8 @@ private:
|
||||||
wchar_t m_groupSeparator;
|
wchar_t m_groupSeparator;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ProcessCommandWorker(uintptr_t wParam);
|
void ProcessCommandWorker(OpCode wParam);
|
||||||
void HandleErrorCommand(uintptr_t idc);
|
void HandleErrorCommand(OpCode idc);
|
||||||
void HandleMaxDigitsReached();
|
void HandleMaxDigitsReached();
|
||||||
void DisplayNum(void);
|
void DisplayNum(void);
|
||||||
int IsNumberInvalid(const std::wstring& numberString, int iMaxExp, int iMaxMantissa, uint32_t radix) const;
|
int IsNumberInvalid(const std::wstring& numberString, int iMaxExp, int iMaxMantissa, uint32_t radix) const;
|
||||||
|
|
|
@ -3,11 +3,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
bool IsOpInRange(uintptr_t op, uint32_t x, uint32_t y);
|
using OpCode = uintptr_t;
|
||||||
bool IsBinOpCode(uintptr_t opCode);
|
|
||||||
|
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
|
// 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
|
// of it and catch it themselves or not needing this
|
||||||
bool IsUnaryOpCode(uintptr_t opCode);
|
bool IsUnaryOpCode(OpCode opCode);
|
||||||
bool IsDigitOpCode(uintptr_t opCode);
|
bool IsDigitOpCode(OpCode opCode);
|
||||||
bool IsGuiSettingOpCode(uintptr_t opCode);
|
bool IsGuiSettingOpCode(OpCode opCode);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue