From 4fc842ad91eb221c76ec6abbc1d69e227314637e Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 25 Feb 2012 03:29:44 +0000 Subject: [PATCH] added: to FunInfo<>: bool remove_fun_data fun_data is removed only when remove_fun_data is true (default) git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@392 e52654a7-88a9-db11-a3e9-0013d4bc506e --- src/funinfo.h | 5 ++-- src/generator.h | 63 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/funinfo.h b/src/funinfo.h index b14cdb1..01bb0f0 100755 --- a/src/funinfo.h +++ b/src/funinfo.h @@ -107,10 +107,10 @@ struct FunInfo // can be null FunData * fun_data; - - FunData * last_fun_data; + bool remove_fun_data; + // this is set by Generator // it indicates the number of a current iteration for the [for] statement (the first iteration is 0) @@ -150,6 +150,7 @@ struct FunInfo iter = 0; last_iter = 0; case_sensitive = true; + remove_fun_data = true; fun_data = 0; last_fun_data = 0; } diff --git a/src/generator.h b/src/generator.h index 5d858dc..f2b7a38 100755 --- a/src/generator.h +++ b/src/generator.h @@ -149,11 +149,13 @@ private: { size_t iter; FunData * fun_data; + bool remove; StackItem() { iter = 0; fun_data = 0; + remove = true; } }; @@ -165,6 +167,7 @@ private: void ClearFilterTab(); void ClearForStack(); void ClearStream(StreamType & str); + void RemoveStackFunData(StackItem & sitem); template CharType ToLower(CharType c); @@ -177,6 +180,7 @@ private: bool Find(const Item::Function & item_fun, typename Functions::Function ** function); + void PrepareInfo(FunInfo & info); void Call(typename Functions::Function * function, FunInfo & info); void Call(typename Functions::Function * function, std::vector & params, StreamType & out_stream, bool clear_out_stream, const StreamType & in_stream); @@ -268,12 +272,15 @@ Generator & Generator::operator=(const Generator void Generator::ClearForStack() { for(size_t i=0 ; i::ClearStream(StreamType & str) } +template +void Generator::RemoveStackFunData(StackItem & sitem) +{ + if( sitem.fun_data && sitem.remove ) + { + delete sitem.fun_data; + sitem.fun_data = 0; + } +} + + + template template CharType Generator::ToLower(CharType c) @@ -509,10 +528,8 @@ return true; } - - template -void Generator::Call(typename Functions::Function * function, FunInfo & info) +void Generator::PrepareInfo(FunInfo & info) { info.Clear(); @@ -537,10 +554,20 @@ void Generator::Call(typename Functions::Function * func } if( !stack_tab.empty() ) - info.fun_data = stack_tab.back().fun_data; + { + info.fun_data = stack_tab.back().fun_data; + info.remove_fun_data = stack_tab.back().remove; + } if( stack_tab.size() >= 2 ) info.last_fun_data = stack_tab[stack_tab.size()-2].fun_data; +} + + +template +void Generator::Call(typename Functions::Function * function, FunInfo & info) +{ + PrepareInfo(info); if( function->type == Functions::function ) { @@ -552,20 +579,20 @@ void Generator::Call(typename Functions::Function * func info.res = !function->variable.empty(); } - if( info.fun_data ) + if( !stack_tab.empty() ) { - if( !stack_tab.empty() ) + if( stack_tab.back().fun_data != info.fun_data ) { - if( stack_tab.back().fun_data != info.fun_data ) - { - delete stack_tab.back().fun_data; - stack_tab.back().fun_data = info.fun_data; - } + RemoveStackFunData(stack_tab.back()); + stack_tab.back().fun_data = info.fun_data; } - else - { + + stack_tab.back().remove = info.remove_fun_data; + } + else + { + if( info.remove_fun_data ) delete info.fun_data; - } } last_res = info.res; @@ -1155,10 +1182,8 @@ void Generator::MakeTextFor(Item & item) return; stack_tab.push_back(StackItem()); - MakeTextForLoop(item, function); - - delete stack_tab.back().fun_data; + RemoveStackFunData(stack_tab.back()); stack_tab.erase(--stack_tab.end()); }