diff --git a/src/funinfo.h b/src/funinfo.h index 0c51c6d..68da521 100644 --- a/src/funinfo.h +++ b/src/funinfo.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2007-2012, Tomasz Sowa + * Copyright (c) 2007-2016, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -82,8 +82,8 @@ struct FunData to an object derived from FunData (this have sense only in [for...] statement because in other statements this object would be immediately removed) - auto_remove - when true it means that object pointing by fun_data should be automatically - removed -- (by using delete fun_data) + auto_remove - when true it means that object pointing by fun_data and for_name should be automatically + removed -- (by using delete fun_data and delete for_name) is_for - true if the item is from [for] statement currently used only in [if-index] (it has to look for the last [for] item) @@ -93,7 +93,9 @@ struct Stack size_t iter; FunData * fun_data; 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() { @@ -102,10 +104,19 @@ struct Stack ~Stack() { - if( fun_data && auto_remove ) + if( auto_remove ) { - delete fun_data; - fun_data = 0; + if( fun_data ) + { + delete fun_data; + fun_data = 0; + } + + if( for_name ) + { + delete for_name; + for_name = 0; + } } } @@ -113,6 +124,7 @@ struct Stack { iter = 0; fun_data = 0; + for_name = 0; auto_remove = true; is_for = false; } @@ -198,6 +210,44 @@ struct FunInfo stack_tab = 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; + } + };