From 44802681723b94de43e79e821ce0d49a96bd08c6 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 17 Jan 2012 22:57:06 +0000 Subject: [PATCH] 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 --- src/funinfo.h | 17 ++++++++++++++--- src/generator.h | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/funinfo.h b/src/funinfo.h index 3ffd4a0..c3ef8ff 100755 --- a/src/funinfo.h +++ b/src/funinfo.h @@ -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; } }; diff --git a/src/generator.h b/src/generator.h index 1e29887..4cd22d5 100755 --- a/src/generator.h +++ b/src/generator.h @@ -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::Call(typename Functions::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::function ) { (function->user_function)(info); @@ -500,7 +506,6 @@ void Generator::Call(typename Functions::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::MakeTextForLoop(Item & item, typename Functions::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);