removed: statements: [if-index ...] [is ...] and [is-no ...]
we can provide a user definied function which does the same added: to FunInfo<>: Stack * stack_tab size_t stack_index a stack table and an index to the current stack item git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@988 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
159
src/generator.h
159
src/generator.h
@@ -199,9 +199,9 @@ private:
|
||||
// used in [0] [1] [2] when there is no such argument defined
|
||||
std::wstring empty_argument;
|
||||
|
||||
// temporary streams used in [if..] [is...] or [for...]
|
||||
// temporary streams used in [if..] [for...] or [def ...]
|
||||
// or if output_stream is null and an ezc function should be called
|
||||
StreamType stream_temp1, stream_temp2, stream_temp_define;
|
||||
StreamType stream_temp1, stream_temp_define;
|
||||
|
||||
// last result from a user function (FunInfo::res)
|
||||
bool last_res;
|
||||
@@ -212,7 +212,6 @@ private:
|
||||
// true if the Generator is working with [for ...], [if ...] etc.
|
||||
bool is_generating_for;
|
||||
bool is_generating_if;
|
||||
bool is_generating_is;
|
||||
bool is_generating_normal;
|
||||
bool is_generating_filter;
|
||||
|
||||
@@ -242,8 +241,6 @@ private:
|
||||
template<class CharType>
|
||||
CharType ToLower(CharType c);
|
||||
|
||||
bool AreStreamsEqual(StreamType & str1, StreamType & str2);
|
||||
|
||||
bool FindInCache(const Item::Function & item_fun,
|
||||
typename Functions<StreamType>::UserFunction ** function,
|
||||
Item ** item_block,
|
||||
@@ -288,7 +285,6 @@ private:
|
||||
void TrimWhite(const wchar_t *& start, const wchar_t *& end);
|
||||
void SkipWhite(const wchar_t *& str);
|
||||
size_t StrToSize(const wchar_t * str, const wchar_t ** str_end = 0);
|
||||
bool LookForLastForStatement(size_t & last_for_index);
|
||||
|
||||
|
||||
void WriteTmpStreamToStreams();
|
||||
@@ -300,21 +296,16 @@ private:
|
||||
bool LimitAchieved();
|
||||
|
||||
void MakeTextIf_go(Item & item, bool result);
|
||||
bool MakeTextIfindexnumber(Item & item, size_t for_index, bool & result);
|
||||
void MakeTextIf(Item & item);
|
||||
void MakeTextIfno(Item & item);
|
||||
void MakeTextIfany(Item & item);
|
||||
void MakeTextIfone(Item & item);
|
||||
void MakeTextIfanyno(Item & item);
|
||||
void MakeTextIfoneno(Item & item);
|
||||
void MakeTextIfindex(Item & item);
|
||||
void MakeTextFor(Item & item);
|
||||
void MakeItemText(Item & item);
|
||||
void MakeTextContainer(Item & item);
|
||||
void MakeTextNormal(Item & item);
|
||||
void MakeTextIs(Item & item, bool equal);
|
||||
void MakeTextIs(Item & item);
|
||||
void MakeTextIsno(Item & item);
|
||||
void MakeTextDefine(Item & item);
|
||||
void MakeTextFilter(Item & item);
|
||||
void MakeTextEzc(Item & item);
|
||||
@@ -629,18 +620,6 @@ return c;
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
bool Generator<StreamType>::AreStreamsEqual(StreamType & str1, StreamType & str2)
|
||||
{
|
||||
#ifdef EZC_HAS_SPECIAL_STREAM
|
||||
return str1.Str() == str2.Str();
|
||||
#else
|
||||
return str1.str() == str2.str();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Generator<StreamType>::SetMax(size_t max_items_, size_t max_for_items_)
|
||||
{
|
||||
@@ -910,12 +889,13 @@ void Generator<StreamType>::CallFunction(typename Functions<StreamType>::UserFun
|
||||
{
|
||||
info.Clear();
|
||||
|
||||
info.is_for = is_generating_for;
|
||||
info.is_if = is_generating_if;
|
||||
info.is_is = is_generating_is;
|
||||
info.is_normal = is_generating_normal;
|
||||
info.is_filter = is_generating_filter;
|
||||
info.iter = info.stack.iter;
|
||||
info.is_for = is_generating_for;
|
||||
info.is_if = is_generating_if;
|
||||
info.is_normal = is_generating_normal;
|
||||
info.is_filter = is_generating_filter;
|
||||
info.iter = info.stack.iter;
|
||||
info.stack_tab = stack_tab.data();
|
||||
info.stack_index = stack_index-1;
|
||||
|
||||
(*function)(info);
|
||||
|
||||
@@ -1496,121 +1476,6 @@ void Generator<StreamType>::MakeTextIfoneno(Item & item)
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Generator<StreamType>::MakeTextIs(Item & item, bool equal)
|
||||
{
|
||||
if( item.functions.size() != 2 )
|
||||
return;
|
||||
|
||||
is_generating_is = true;
|
||||
|
||||
if( !Call(item.functions[0], stream_temp1, true, empty_stream) )
|
||||
return;
|
||||
|
||||
if( !Call(item.functions[1], stream_temp2, true, empty_stream) )
|
||||
return;
|
||||
|
||||
bool res = AreStreamsEqual(stream_temp1, stream_temp2);
|
||||
|
||||
if( !equal )
|
||||
res = !res;
|
||||
|
||||
MakeTextIf_go(item, res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Generator<StreamType>::MakeTextIs(Item & item)
|
||||
{
|
||||
MakeTextIs(item, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Generator<StreamType>::MakeTextIsno(Item & item)
|
||||
{
|
||||
MakeTextIs(item, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
bool Generator<StreamType>::LookForLastForStatement(size_t & last_for_index)
|
||||
{
|
||||
last_for_index = stack_index;
|
||||
|
||||
while( last_for_index-- > 0 )
|
||||
{
|
||||
if( stack_tab[last_for_index].is_for )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
bool Generator<StreamType>::MakeTextIfindexnumber(Item & item, size_t for_index, bool & result)
|
||||
{
|
||||
if( item.functions.size() != 1 )
|
||||
return false;
|
||||
|
||||
const wchar_t * number_text = item.functions[0].name.c_str();
|
||||
const wchar_t * last_char;
|
||||
|
||||
size_t number = StrToSize(number_text, &last_char);
|
||||
|
||||
if( *last_char != '\0' )
|
||||
{
|
||||
CreateMsg(L"if-index: syntax error");
|
||||
return false;
|
||||
}
|
||||
|
||||
result = (stack_tab[for_index].iter == number);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Generator<StreamType>::MakeTextIfindex(Item & item)
|
||||
{
|
||||
size_t for_index;
|
||||
|
||||
if( item.functions.size() != 1 || !LookForLastForStatement(for_index) )
|
||||
return;
|
||||
|
||||
bool result = false;
|
||||
|
||||
if( item.functions[0].name == L"odd" )
|
||||
{
|
||||
result = (stack_tab[for_index].iter & 1) == 1;
|
||||
}
|
||||
else
|
||||
if( item.functions[0].name == L"even" )
|
||||
{
|
||||
result = (stack_tab[for_index].iter & 1) == 0;
|
||||
}
|
||||
else
|
||||
if( item.functions[0].name == L"first" )
|
||||
{
|
||||
result = stack_tab[for_index].iter == 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !MakeTextIfindexnumber(item, for_index, result) )
|
||||
return;
|
||||
}
|
||||
|
||||
MakeTextIf_go(item, result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Generator<StreamType>::MakeTextFor(Item & item)
|
||||
{
|
||||
@@ -1879,7 +1744,6 @@ void Generator<StreamType>::MakeText(Item & item)
|
||||
stack_index += 1;
|
||||
is_generating_for = false;
|
||||
is_generating_if = false;
|
||||
is_generating_is = false;
|
||||
is_generating_normal = false;
|
||||
is_generating_filter = false;
|
||||
|
||||
@@ -1894,9 +1758,6 @@ void Generator<StreamType>::MakeText(Item & item)
|
||||
else if( item.type == Item::item_ifone ) MakeTextIfone(item);
|
||||
else if( item.type == Item::item_ifanyno ) MakeTextIfanyno(item);
|
||||
else if( item.type == Item::item_ifoneno ) MakeTextIfoneno(item);
|
||||
else if( item.type == Item::item_ifindex ) MakeTextIfindex(item);
|
||||
else if( item.type == Item::item_is ) MakeTextIs(item);
|
||||
else if( item.type == Item::item_isno ) MakeTextIsno(item);
|
||||
else if( item.type == Item::item_def ) MakeTextDefine(item);
|
||||
else if( item.type == Item::item_for ) MakeTextFor(item);
|
||||
else if( item.type == Item::item_filter ) MakeTextFilter(item);
|
||||
@@ -1916,3 +1777,5 @@ void Generator<StreamType>::MakeText(Item & item)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user