libeval_compiler: CONTEXT runs the UCODE now (thread-safe solution), fixed some memory leaks

This commit is contained in:
Tomasz Wlostowski 2020-07-24 16:16:15 +02:00
parent a504bd0795
commit 3c80b98d1c
2 changed files with 31 additions and 0 deletions

View File

@ -129,6 +129,13 @@ std::string UOP::Format() const
}
UCODE::~UCODE()
{
for ( auto op : m_ucode )
delete op;
}
std::string UCODE::Dump() const
{
std::string rv;
@ -206,6 +213,12 @@ void COMPILER::Clear()
//free( current.token );
m_tokenizer.Clear();
if( m_tree )
{
freeTree( m_tree );
}
m_tree = nullptr;
}
@ -229,6 +242,12 @@ bool COMPILER::Compile( const std::string& aString, UCODE* aCode, CONTEXT* aPref
newString( aString );
m_errorStatus.pendingError = false;
if( m_tree )
{
freeTree( m_tree );
}
m_tree = nullptr;
m_parseFinished = false;
T_TOKEN tok;
@ -591,6 +610,12 @@ void COMPILER::setRoot( TREE_NODE root )
m_tree = copyNode( root );
}
void COMPILER::freeTree( LIBEVAL::TREE_NODE *tree )
{
if ( tree->leaf[0] )
freeTree( tree->leaf[0] );
if ( tree->leaf[1] )
freeTree( tree->leaf[1] );
bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
{
@ -710,6 +735,10 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
return false;
}
/* SREF -> FUNC_CALL -> leaf0/1 */
node->leaf[1]->leaf[0]->leaf[0] = nullptr;
node->leaf[1]->leaf[0]->leaf[1] = nullptr;
visitedNodes.insert( node->leaf[0] );
visitedNodes.insert( node->leaf[1]->leaf[0] );

View File

@ -23,6 +23,7 @@
#include <cstddef>
#include <functional>
#include <map>
#include <string>
#include <stack>
@ -421,6 +422,7 @@ public:
}
void setRoot( LIBEVAL::TREE_NODE root );
void freeTree( LIBEVAL::TREE_NODE *tree );
bool Compile( const std::string& aString, UCODE* aCode, CONTEXT* aPreflightContext );
void ReportError( const wxString& aErrorMsg );