mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
[muparser] Clean up constructors and other miscellaneous
This commit is contained in:
parent
e675a66504
commit
732b32c8b4
4 changed files with 18 additions and 55 deletions
|
@ -67,15 +67,9 @@ class ParserBase {
|
|||
*/
|
||||
typedef ValueOrError (ParserBase::*ParseFunction)() const;
|
||||
|
||||
/** \brief Type used for storing an array of values. */
|
||||
typedef std::vector<value_type> valbuf_type;
|
||||
|
||||
/** \brief Type for a vector of strings. */
|
||||
typedef std::vector<string_type> stringbuf_type;
|
||||
|
||||
/** \brief Typedef for the token reader. */
|
||||
typedef ParserTokenReader token_reader_type;
|
||||
|
||||
/** \brief Type used for parser tokens. */
|
||||
typedef ParserToken<value_type, string_type> token_type;
|
||||
|
||||
|
@ -199,7 +193,6 @@ class ParserBase {
|
|||
};
|
||||
|
||||
private:
|
||||
void InitTokenReader();
|
||||
void ReInit() const;
|
||||
|
||||
OptionalError AddCallback(const string_type &a_strName, const ParserCallback &a_Callback,
|
||||
|
@ -247,8 +240,7 @@ class ParserBase {
|
|||
m_vStringBuf; ///< String buffer, used for storing string function arguments
|
||||
stringbuf_type m_vStringVarBuf;
|
||||
|
||||
std::auto_ptr<token_reader_type>
|
||||
m_pTokenReader; ///< Managed pointer to the token reader object.
|
||||
std::unique_ptr<ParserTokenReader> m_pTokenReader;
|
||||
|
||||
funmap_type m_FunDef; ///< Map of function names and pointers.
|
||||
funmap_type m_PostOprtDef; ///< Postfix operator callbacks
|
||||
|
@ -258,16 +250,17 @@ class ParserBase {
|
|||
strmap_type m_StrVarDef; ///< user defined string constants
|
||||
varmap_type m_VarDef; ///< user defind variables.
|
||||
|
||||
bool m_bBuiltInOp; ///< Flag that can be used for switching built in operators on and off
|
||||
bool m_bBuiltInOp =
|
||||
true; ///< Flag that can be used for switching built in operators on and off
|
||||
|
||||
string_type m_sNameChars; ///< Charset for names
|
||||
string_type m_sOprtChars; ///< Charset for postfix/ binary operator tokens
|
||||
string_type m_sInfixOprtChars; ///< Charset for infix operator tokens
|
||||
|
||||
// items merely used for caching state information
|
||||
mutable valbuf_type
|
||||
m_vStackBuffer; ///< This is merely a buffer used for the stack in the cmd parsing routine
|
||||
mutable int m_nFinalResultIdx;
|
||||
/// This is merely a buffer used for the stack in the cmd parsing routine
|
||||
mutable std::vector<value_type> m_vStackBuffer;
|
||||
mutable int m_nFinalResultIdx = 0;
|
||||
};
|
||||
} // namespace mu
|
||||
|
||||
|
|
|
@ -83,9 +83,6 @@ class ParserByteCode {
|
|||
/** \brief Token type for internal use only. */
|
||||
typedef ParserToken<value_type, string_type> token_type;
|
||||
|
||||
/** \brief Token vector for storing the RPN. */
|
||||
typedef std::vector<SToken> rpn_type;
|
||||
|
||||
/** \brief Position in the Calculation array. */
|
||||
unsigned m_iStackPos;
|
||||
|
||||
|
@ -93,7 +90,7 @@ class ParserByteCode {
|
|||
std::size_t m_iMaxStackSize;
|
||||
|
||||
/** \brief The actual rpn storage. */
|
||||
rpn_type m_vRPN;
|
||||
std::vector<SToken> m_vRPN;
|
||||
|
||||
public:
|
||||
ParserByteCode();
|
||||
|
|
|
@ -64,25 +64,7 @@ const char_type *ParserBase::c_DefaultOprt[] = {
|
|||
\param a_szFormula the formula to interpret.
|
||||
\throw ParserException if a_szFormula is null.
|
||||
*/
|
||||
ParserBase::ParserBase()
|
||||
: m_vRPN(),
|
||||
m_vStringBuf(),
|
||||
m_pTokenReader(),
|
||||
m_FunDef(),
|
||||
m_PostOprtDef(),
|
||||
m_InfixOprtDef(),
|
||||
m_OprtDef(),
|
||||
m_ConstDef(),
|
||||
m_StrVarDef(),
|
||||
m_VarDef(),
|
||||
m_bBuiltInOp(true),
|
||||
m_sNameChars(),
|
||||
m_sOprtChars(),
|
||||
m_sInfixOprtChars(),
|
||||
m_vStackBuffer(),
|
||||
m_nFinalResultIdx(0) {
|
||||
InitTokenReader();
|
||||
}
|
||||
ParserBase::ParserBase() : m_pTokenReader(new ParserTokenReader(this)) {}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
ParserBase::~ParserBase() = default;
|
||||
|
@ -124,16 +106,6 @@ void ParserBase::ResetLocale() {
|
|||
SetArgSep(',');
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
/** \brief Initialize the token reader.
|
||||
|
||||
Create new token reader object and submit pointers to function, operator,
|
||||
constant and variable definitions.
|
||||
|
||||
\post m_pTokenReader.get()!=0
|
||||
*/
|
||||
void ParserBase::InitTokenReader() { m_pTokenReader.reset(new token_reader_type(this)); }
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
/** \brief Reset parser to string parsing mode and clear internal buffers.
|
||||
|
||||
|
@ -539,7 +511,6 @@ OptionalError ParserBase::ApplyStrFunc(const token_type &a_FunTok,
|
|||
return Error(ecVAL_EXPECTED, m_pTokenReader->GetPos(), a_FunTok.GetAsString());
|
||||
}
|
||||
|
||||
// string functions won't be optimized
|
||||
m_vRPN.AddStrFun(pFunc, a_FunTok.GetArgCount(), a_vArg.back().GetIdx());
|
||||
return {};
|
||||
}
|
||||
|
@ -766,7 +737,6 @@ ValueOrError ParserBase::InvokeFunction(generic_fun_type func, const value_type
|
|||
ValueOrError ParserBase::ExecuteRPN() const {
|
||||
assert(! m_vRPN.empty() && "Missing RPN");
|
||||
value_type *Stack = &m_vStackBuffer[0];
|
||||
value_type buf;
|
||||
int sidx(0);
|
||||
for (const SToken *pTok = m_vRPN.GetBase(); pTok->Cmd != cmEND; ++pTok) {
|
||||
switch (pTok->Cmd) {
|
||||
|
|
|
@ -179,27 +179,30 @@ void ParserByteCode::Finalize() {
|
|||
SToken tok;
|
||||
tok.Cmd = cmEND;
|
||||
m_vRPN.push_back(tok);
|
||||
rpn_type(m_vRPN).swap(m_vRPN); // shrink bytecode vector to fit
|
||||
m_vRPN.shrink_to_fit();
|
||||
|
||||
// Determine the if-then-else jump offsets
|
||||
ParserStack<int> stIf, stElse;
|
||||
int idx;
|
||||
for (int i = 0; i < (int)m_vRPN.size(); ++i) {
|
||||
switch (m_vRPN[i].Cmd) {
|
||||
case cmIF:
|
||||
stIf.push_back(i);
|
||||
break;
|
||||
|
||||
case cmELSE:
|
||||
case cmELSE: {
|
||||
int idx = stIf.back();
|
||||
stIf.pop_back();
|
||||
m_vRPN[idx].Oprt.offset = i - idx;
|
||||
stElse.push_back(i);
|
||||
idx = stIf.pop();
|
||||
m_vRPN[idx].Oprt.offset = i - idx;
|
||||
break;
|
||||
}
|
||||
|
||||
case cmENDIF:
|
||||
idx = stElse.pop();
|
||||
case cmENDIF: {
|
||||
int idx = stElse.back();
|
||||
stElse.pop_back();
|
||||
m_vRPN[idx].Oprt.offset = i - idx;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue