added: two flags to FunInfo<> struct:
// indicates that this function is from [for ...] statement bool is_for; // indicates that this function is from [for ...] statement // and this is a first iteration (iter=0 too) // this is only for convenience -- you don't have to check is_for and iter==0 bool is_for_first_iter; git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@380 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
71bec1049b
commit
4480268172
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Tomasz Sowa
|
||||
* Copyright (c) 2007-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -72,6 +72,15 @@ struct FunInfo
|
|||
// if there is other statement than [filter] then this is an empty stream
|
||||
const StreamType & in;
|
||||
|
||||
// indicates that this function is from [for ...] statement
|
||||
bool is_for;
|
||||
|
||||
// indicates that this function is from [for ...] statement
|
||||
// and this is a first iteration (iter=0 too)
|
||||
// this is only for convenience -- you don't have to check is_for and iter==0
|
||||
// !! may a better name?
|
||||
bool is_for_first_iter;
|
||||
|
||||
// this is set by Generator
|
||||
// it indicates the number of a current iteration in the last [for] statement (the first is 0)
|
||||
// if there was not any [for] before the value is zero
|
||||
|
@ -92,8 +101,10 @@ struct FunInfo
|
|||
|
||||
void Clear()
|
||||
{
|
||||
res = false; // false by default
|
||||
iter = 0;
|
||||
res = false; // result is false by default
|
||||
is_for = false;
|
||||
is_for_first_iter = false;
|
||||
iter = 0;
|
||||
case_sensitive = true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Tomasz Sowa
|
||||
* Copyright (c) 2007-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -132,6 +132,9 @@ private:
|
|||
// true if this Generator is working now
|
||||
bool is_generator_working;
|
||||
|
||||
// true if the Generator is working with [for ...] statement
|
||||
bool is_generating_for;
|
||||
|
||||
// an empty string for FunInfo objects
|
||||
// when there is no any parameters
|
||||
const std::wstring empty;
|
||||
|
@ -492,6 +495,9 @@ void Generator<StreamType>::Call(typename Functions<StreamType>::Function * func
|
|||
else
|
||||
info.iter = stack_tab.back().iter;
|
||||
|
||||
info.is_for = is_generating_for;
|
||||
info.is_for_first_iter = (info.is_for && info.iter == 0);
|
||||
|
||||
if( function->type == Functions<StreamType>::function )
|
||||
{
|
||||
(function->user_function)(info);
|
||||
|
@ -500,7 +506,6 @@ void Generator<StreamType>::Call(typename Functions<StreamType>::Function * func
|
|||
{
|
||||
info.out << function->variable;
|
||||
info.res = !function->variable.empty();
|
||||
info.case_sensitive = true;
|
||||
}
|
||||
|
||||
last_res = info.res;
|
||||
|
@ -1048,6 +1053,9 @@ void Generator<StreamType>::MakeTextForLoop(Item & item, typename Functions<Stre
|
|||
break;
|
||||
}
|
||||
|
||||
// is_generating_for will be changed by next call to MakeText()
|
||||
// so we should set it in each iterations
|
||||
is_generating_for = true;
|
||||
Call(function, item.functions[0].params, stream_temp1, true, empty_stream);
|
||||
|
||||
if( !last_res )
|
||||
|
@ -1167,6 +1175,8 @@ void Generator<StreamType>::MakeText(Item & item)
|
|||
return;
|
||||
}
|
||||
|
||||
is_generating_for = false;
|
||||
|
||||
if ( item.type == Item::item_text ) MakeItemText(item);
|
||||
else if( item.type == Item::item_container )MakeTextContainer(item);
|
||||
else if( item.type == Item::item_normal ) MakeTextNormal(item);
|
||||
|
|
Loading…
Reference in New Issue