Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
added error to warn about using bytecode export and variable factories. I did not enable the error.  It is not necessarily a problem just tricky to manage.
  • Loading branch information
Ingo Berg committed Oct 14, 2023
1 parent 310b56c commit a815443
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 339 deletions.
6 changes: 3 additions & 3 deletions include/muParserBytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ namespace mu
return &m_vRPN[0];
}

void StoreEnvironment(string_type a_expr, stringbuf_type const& a_strBuf)
void StoreEnvironment(string_type expr, stringbuf_type const& strBuf)
{
m_stringBuffer = a_strBuf;
m_expr = a_expr;
m_stringBuffer = strBuf;
m_expr = expr;
}

std::tuple<string_type, stringbuf_type> RestoreEnvironment() const
Expand Down
4 changes: 3 additions & 1 deletion include/muParserDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ namespace mu
ecINVALID_CHARACTERS_FOUND = 38,///< The expression or identifier contains invalid non printable characters

// internal errors
ecINTERNAL_ERROR = 39, ///< Internal error of any kind.
ecINTERNAL_ERROR = 39, ///< Internal error of any kind.

ecBYTECODE_IMPORT_EXPORT_DISABLED = 40, ///< Bytecode cannot be exported.

// The last two are special entries
ecCOUNT, ///< This is no error code, It just stores just the total number of error codes
Expand Down
9 changes: 9 additions & 0 deletions include/muParserTokenReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ namespace mu
void SetFormula(const string_type& a_strFormula);
void SetArgSep(char_type cArgSep);

/** \brief Check whether a variable factory is installed.
Variable factories automatically create new variables when a unknown variable is found in an expression.
*/
bool HasVarCreator() const
{
return m_pFactory != nullptr;
}

int GetPos() const;
const string_type& GetExpr() const;
varmap_type& GetUsedVar();
Expand Down
1 change: 1 addition & 0 deletions samples/example1/example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "muParserTest.h"
#include "muParser.h"
#include "muParserBytecode.h"

using namespace std;
using namespace mu;
Expand Down
10 changes: 10 additions & 0 deletions src/muParserBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,23 @@ namespace mu
*/
const ParserByteCode& ParserBase::GetByteCode() const
{
// If a variable factory is defined the bytecode may contain references to implicitely
// created variables.
// if (m_pTokenReader->HasVarCreator())
// Error(ecBYTECODE_IMPORT_EXPORT_DISABLED);

return m_vRPN;
}


/** \brief Restore a previously saved bytecode. */
void ParserBase::SetByteCode(const ParserByteCode& a_ByteCode)
{
// If a variable factory is defined the bytecode may contain references to dynamically
// created variables.
// if (m_pTokenReader->HasVarCreator())
// Error(ecBYTECODE_IMPORT_EXPORT_DISABLED);

m_vRPN = a_ByteCode;

// restore expression environment
Expand Down
Loading

0 comments on commit a815443

Please sign in to comment.