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
This commit is contained in:
Tomasz Sowa 2012-02-25 03:29:44 +00:00
parent 8e85a398d6
commit 4fc842ad91
2 changed files with 47 additions and 21 deletions

View File

@ -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;
}

View File

@ -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<class CharType>
CharType ToLower(CharType c);
@ -177,6 +180,7 @@ private:
bool Find(const Item::Function & item_fun, typename Functions<StreamType>::Function ** function);
void PrepareInfo(FunInfo<StreamType> & info);
void Call(typename Functions<StreamType>::Function * function, FunInfo<StreamType> & info);
void Call(typename Functions<StreamType>::Function * function, std::vector<std::wstring> & params,
StreamType & out_stream, bool clear_out_stream, const StreamType & in_stream);
@ -268,12 +272,15 @@ Generator<StreamType> & Generator<StreamType>::operator=(const Generator<StreamT
trim_white = n.trim_white;
skip_new_line = n.skip_new_line;
// !! IMROVE ME
// does we really need to clear those two stacks?
// don't copy filter tab
ClearFilterTab();
// don't copy [for] stack
ClearForStack();
// !! CHECK ME
// may copying should be denied when generator is working?
// don't copy 'is_generator_working' flag
is_generator_working = false;
@ -325,7 +332,7 @@ template<class StreamType>
void Generator<StreamType>::ClearForStack()
{
for(size_t i=0 ; i<stack_tab.size() ; ++i)
delete stack_tab[i].fun_data;
RemoveStackFunData(stack_tab[i]);
stack_tab.clear();
}
@ -342,6 +349,18 @@ void Generator<StreamType>::ClearStream(StreamType & str)
}
template<class StreamType>
void Generator<StreamType>::RemoveStackFunData(StackItem & sitem)
{
if( sitem.fun_data && sitem.remove )
{
delete sitem.fun_data;
sitem.fun_data = 0;
}
}
template<class StreamType>
template<class CharType>
CharType Generator<StreamType>::ToLower(CharType c)
@ -509,10 +528,8 @@ return true;
}
template<class StreamType>
void Generator<StreamType>::Call(typename Functions<StreamType>::Function * function, FunInfo<StreamType> & info)
void Generator<StreamType>::PrepareInfo(FunInfo<StreamType> & info)
{
info.Clear();
@ -537,10 +554,20 @@ void Generator<StreamType>::Call(typename Functions<StreamType>::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<class StreamType>
void Generator<StreamType>::Call(typename Functions<StreamType>::Function * function, FunInfo<StreamType> & info)
{
PrepareInfo(info);
if( function->type == Functions<StreamType>::function )
{
@ -552,20 +579,20 @@ void Generator<StreamType>::Call(typename Functions<StreamType>::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<StreamType>::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());
}