From b646287c9baf6f7fc81f62e5b094a02f7496dcfb Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 30 Jan 2025 18:05:37 +0100 Subject: [PATCH] WIP: add a Val struct as an input/output when calling a function --- src/generator.h | 22 ++++++++++++++-------- src/val.cpp | 18 +++++++++++++++++- src/val.h | 12 ++++++++++++ 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/generator.h b/src/generator.h index 3318947..0f0596e 100644 --- a/src/generator.h +++ b/src/generator.h @@ -2059,10 +2059,13 @@ bool Generator::EvaluateFunctions(pt::Stream & out_stream, ValWrapper & valwrapp { valwrapper.has_evaluated_val = true; - if( out_stream.size() != current_size ) + if( valwrapper.evaluated_val.is_allowed_to_cache() ) { - valwrapper.evaluated_str = out_stream.new_empty(); - copy_stream(out_stream, current_size, out_stream.size(), *valwrapper.evaluated_str); + if( out_stream.size() != current_size ) + { + valwrapper.evaluated_str = out_stream.new_empty(); + copy_stream(out_stream, current_size, out_stream.size(), *valwrapper.evaluated_str); + } } } else @@ -2124,13 +2127,16 @@ bool Generator::FindLastModelWrapper(FindHelper & find_helper, bool is_for_alias ValWrapper valwrapper; valwrapper.val = model->get_ezc_val(nullptr, field.c_str()); // may it would be better to provide a pointer to get_ezc_val() method? - if( (find_helper.field_index + 1 < find_helper.fields.size()) || !is_for_alias ) + if( valwrapper.val.has_function() || valwrapper.val.has_method() ) { - bool use_parameters = (find_helper.field_index + 1 == find_helper.fields.size()); - - if( EvaluateFunctions(find_helper, use_parameters, valwrapper) ) + if( (find_helper.field_index + 1 < find_helper.fields.size()) || !is_for_alias ) { - child_valwrapper = find_helper.valwrapper->add_child(field, valwrapper); + bool use_parameters = (find_helper.field_index + 1 == find_helper.fields.size()); + + if( !EvaluateFunctions(find_helper, use_parameters, valwrapper) ) + { + return false; + } } } diff --git a/src/val.cpp b/src/val.cpp index c592c8e..b4d7ef6 100644 --- a/src/val.cpp +++ b/src/val.cpp @@ -105,6 +105,7 @@ void Val::copy(const Val & val) // space = val.space; output_stream = val.output_stream; + allow_to_cache_value = val.allow_to_cache_value; increment_model_container_wrapper_ref(); increment_space_wrapper_ref(); @@ -160,6 +161,7 @@ void Val::initialize_empty() model_method4 = nullptr; space_wrapper = nullptr; space_table_index = 0; + allow_to_cache_value = false; } @@ -496,6 +498,7 @@ void Val::set_pointer_to(morm::ModelContainerWrapper * model_container_wrapper) clear(); type = TYPE_MODEL_CONTAINER_WRAPPER; this->pointer = model_container_wrapper; + this->allow_to_cache_value = true; model_container_wrapper->increment_reference_counter(); } @@ -507,6 +510,7 @@ void Val::set_pointer_to(morm::SpaceWrapper * space_wrapper) this->pointer = space_wrapper->get_space(); this->space_wrapper = space_wrapper; this->space_wrapper->increment_reference_counter(); + this->allow_to_cache_value = true; } @@ -518,7 +522,8 @@ void Val::set_pointer_to(pt::Space * space, bool create_wrapper) if( create_wrapper ) { - space_wrapper = new morm::SpaceWrapper(space); + this->space_wrapper = new morm::SpaceWrapper(space); + this->allow_to_cache_value = true; } } @@ -1344,6 +1349,17 @@ void Val::put_pod_type_to_stream() } +void Val::allow_to_cache(bool allow_to_cache) +{ + this->allow_to_cache_value = allow_to_cache; +} + + +bool Val::is_allowed_to_cache() +{ + return this->allow_to_cache_value; +} + } // namespace Ezc diff --git a/src/val.h b/src/val.h index b645f2f..b334545 100644 --- a/src/val.h +++ b/src/val.h @@ -237,8 +237,14 @@ public: Val & operator=(bool res); + void put_pod_type_to_stream(); + + void allow_to_cache(bool allow_to_cache); + bool is_allowed_to_cache(); + + Type type; pt::Space space_local; void * pointer; @@ -255,6 +261,8 @@ public: morm::SpaceWrapper * space_wrapper; size_t space_table_index; + bool allow_to_cache_value; + // UserFunction user_function; // // Wrapper @@ -340,6 +348,7 @@ void Val::set_pointer_to(std::vector * model_container) clear(); type = TYPE_MODEL_CONTAINER_WRAPPER; this->pointer = new morm::ModelWrapperVector(model_container); + this->allow_to_cache_value = true; } @@ -349,6 +358,7 @@ void Val::set_pointer_to(std::list * model_container) clear(); type = TYPE_MODEL_CONTAINER_WRAPPER; this->pointer = new morm::ModelWrapperList(model_container); + this->allow_to_cache_value = true; } @@ -358,6 +368,7 @@ void Val::set_pointer_to(std::vector * model_container) clear(); type = TYPE_MODEL_CONTAINER_WRAPPER; this->pointer = new morm::ModelWrapperVectorPointer(model_container); + this->allow_to_cache_value = true; } @@ -367,6 +378,7 @@ void Val::set_pointer_to(std::list * model_container) clear(); type = TYPE_MODEL_CONTAINER_WRAPPER; this->pointer = new morm::ModelWrapperListPointer(model_container); + this->allow_to_cache_value = true; }