added a 'for_name' (std::string*) in Stack

this is a user defined name of a [for] statement



git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@1037 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2016-03-23 15:22:59 +00:00
parent 2190fae789
commit 18696d412b
1 changed files with 57 additions and 7 deletions

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2007-2012, Tomasz Sowa * Copyright (c) 2007-2016, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -82,8 +82,8 @@ struct FunData
to an object derived from FunData to an object derived from FunData
(this have sense only in [for...] statement because in other statements (this have sense only in [for...] statement because in other statements
this object would be immediately removed) this object would be immediately removed)
auto_remove - when true it means that object pointing by fun_data should be automatically auto_remove - when true it means that object pointing by fun_data and for_name should be automatically
removed -- (by using delete fun_data) removed -- (by using delete fun_data and delete for_name)
is_for - true if the item is from [for] statement is_for - true if the item is from [for] statement
currently used only in [if-index] currently used only in [if-index]
(it has to look for the last [for] item) (it has to look for the last [for] item)
@ -93,7 +93,9 @@ struct Stack
size_t iter; size_t iter;
FunData * fun_data; FunData * fun_data;
bool auto_remove; bool auto_remove;
bool is_for; // !! CHECK ME it is needed here? we have something similar in FunInfo... bool is_for;
std::wstring * for_name; // !! IMPROVE ME give a better name
Stack() Stack()
{ {
@ -102,10 +104,19 @@ struct Stack
~Stack() ~Stack()
{ {
if( fun_data && auto_remove ) if( auto_remove )
{ {
delete fun_data; if( fun_data )
fun_data = 0; {
delete fun_data;
fun_data = 0;
}
if( for_name )
{
delete for_name;
for_name = 0;
}
} }
} }
@ -113,6 +124,7 @@ struct Stack
{ {
iter = 0; iter = 0;
fun_data = 0; fun_data = 0;
for_name = 0;
auto_remove = true; auto_remove = true;
is_for = false; is_for = false;
} }
@ -198,6 +210,44 @@ struct FunInfo
stack_tab = 0; stack_tab = 0;
stack_index = 0; stack_index = 0;
} }
/*
* CHECK ME can it be done only for [for] statements?
*
* can return a null pointer if there is no such an item on the stack
*
* add a function with const wchar_t *
*/
Stack * FindLastFor(const std::wstring & name)
{
for(size_t i = stack_index ; i > 0 ; --i)
{
if( stack_tab[i-1].for_name && *stack_tab[i-1].for_name == name )
return &stack_tab[i-1];
}
return 0;
}
Stack * FindLastFor()
{
if( !params.empty() )
return FindLastFor(params[0].str); // or last item?
return 0;
}
Stack * FindLastFor(const std::wstring & first_name, const std::wstring & second_name)
{
if( !first_name.empty() )
return FindLastFor(first_name);
else
if( !second_name.empty() )
return FindLastFor(second_name);
return 0;
}
}; };