From 943026a3acfc6018845c67c8550de9cb761927d6 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Mon, 22 Nov 2021 15:44:37 +0100 Subject: [PATCH] I forget to add modified files to previous commit (added support for Space tables, removed Models class) --- src/Makefile.dep | 1 - src/Makefile.o.dep | 2 +- src/generator.h | 161 +++++++++++++++++---------------------------- src/var.h | 70 ++++++++++++++++++++ src/vars.h | 100 ++++++++++++++++++++++++++++ 5 files changed, 230 insertions(+), 104 deletions(-) diff --git a/src/Makefile.dep b/src/Makefile.dep index 732d874..e2a9ba4 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep @@ -25,7 +25,6 @@ cache.o: ../../pikotools/src/textstream/types.h cache.o: ../../pikotools/src/membuffer/membuffer.h cache.o: ../../pikotools/src/textstream/types.h objects.h blocks.h item.o: item.h -models.o: models.h pattern.o: pattern.h item.h cache.h functions.h pattern.o: ../../pikotools/src/utf8/utf8.h pattern.o: ../../pikotools/src/textstream/stream.h diff --git a/src/Makefile.o.dep b/src/Makefile.o.dep index 32a64b6..fbc81ca 100644 --- a/src/Makefile.o.dep +++ b/src/Makefile.o.dep @@ -1 +1 @@ -o = blocks.o cache.o item.o models.o pattern.o patternparser.o var.o \ No newline at end of file +o = blocks.o cache.o item.o pattern.o patternparser.o var.o \ No newline at end of file diff --git a/src/generator.h b/src/generator.h index c11d3eb..75eff6b 100644 --- a/src/generator.h +++ b/src/generator.h @@ -48,7 +48,6 @@ #include "objects.h" #include "outstreams.h" #include "expressionparser.h" -#include "models.h" #include "log/log.h" #include "utf8/utf8.h" #include "vars.h" @@ -84,7 +83,7 @@ public: void SetLogger(pt::Log & logger); #ifdef EZC_HAS_MORM_LIBRARY - void SetModels(Models & models); + //void SetModels(Models & models); #endif void SetMax(size_t max_items_, size_t max_for_items_); @@ -235,7 +234,7 @@ private: #ifdef EZC_HAS_MORM_LIBRARY - Models * pmodels; + //Models * pmodels; #endif Vars * pvars; @@ -469,7 +468,7 @@ Generator::Generator() : plog = nullptr; #ifdef EZC_HAS_MORM_LIBRARY - pmodels = nullptr; + //pmodels = nullptr; #endif max_items = 50000; @@ -506,7 +505,7 @@ Generator::operator=(cons plog = n.plog; #ifdef EZC_HAS_MORM_LIBRARY - pmodels = n.pmodels; + //pmodels = n.pmodels; #endif max_items = n.max_items; @@ -576,11 +575,11 @@ void Generator::SetLogger #ifdef EZC_HAS_MORM_LIBRARY -template -void Generator::SetModels(Models & models) -{ - pmodels = ⊧ -} +//template +//void Generator::SetModels(Models & models) +//{ +// pmodels = ⊧ +//} #endif @@ -1340,24 +1339,19 @@ void Generator::CallSpace morm::SpaceWrapper & space_wrapper, pt::Space & space, FindHelper & find_helper, size_t model_wrapper_space_table_index) { pt::Space::TableType * table = space.get_table(); + find_helper.result->set(space_wrapper); if( is_generating_for ) { // we are in [for...]statement, increment iterator and check the range space_wrapper.increment_iterator(model_wrapper_space_table_index, table->size()); space_wrapper.invalidate_iterators(model_wrapper_space_table_index + 1); - //size_t iterator_value = space_wrapper.get_space_iterator_value(model_wrapper_space_table_index); - space_wrapper.get_space_iterator_value(model_wrapper_space_table_index); - //last_res = (iterator_value < table->size()); - } - else - { - // we are not in [for..], it can be for example [if...], return true if the table is not empty - // if we are in [if-def...] - then last_res is set later in MakeTextIfDef(Item & item) when Call() method returns - //last_res = !table->empty(); + size_t iterator_value = space_wrapper.get_space_iterator_value(model_wrapper_space_table_index); + bool for_status = (iterator_value < table->size()); + space_wrapper.set_last_for_loop_status(for_status); } - if( !IsTestingFunctionExistence() ) + if( !IsTestingFunctionExistence() && find_helper.is_last_field() ) { DumpSpaceIfNeeded(space, find_helper); @@ -1432,33 +1426,19 @@ bool Generator::CallSpace { pt::Space * space = space_wrapper.get_space(); size_t model_wrapper_space_table_index = 0; -// bool status = false; + space_wrapper.set_last_for_loop_status(false); - /* - * - * we are iterating through such objects: - * [root_space, fields[field_index], fields[field_index+1], fields[field_index+2], fields[field_index+3] ...] - * the first item is the root_space with a find_helper.fun_name name - * - */ - while( (find_helper.field_index < find_helper.fields.size() + 1) && space ) + while( find_helper.field_index < find_helper.fields.size() ) { if( space->is_object() ) { - if( find_helper.field_index < find_helper.fields.size() ) - { - const std::wstring & next_field = find_helper.fields[find_helper.field_index]; - pt::Space * next_space = space->get_space(next_field); + const std::wstring & next_field = find_helper.fields[find_helper.field_index]; + pt::Space * next_space = space->get_space(next_field); - if( next_space ) - { - find_helper.field_index += 1; - space = next_space; - } - else - { - break; - } + if( next_space ) + { + find_helper.field_index += 1; + space = next_space; } else { @@ -1470,76 +1450,53 @@ bool Generator::CallSpace { if( model_wrapper_space_table_index < space_wrapper.space_indices_table_size() ) { - if( find_helper.is_last_field() ) + space = CallSpaceTableForMiddleField(space_wrapper, *space, find_helper, model_wrapper_space_table_index); + + if( !space ) { - CallSpaceTableForLastField(space_wrapper, *space, find_helper, model_wrapper_space_table_index); - find_helper.field_index += 1; -// status = true; + // a [for ...] was not used beforehand + return false; } - else + + // increment field_index only if next_field is 'this' and space is not an object + if( !space->is_object() ) { - space = CallSpaceTableForMiddleField(space_wrapper, *space, find_helper, model_wrapper_space_table_index); - // increment field_index only if next_field is 'this' and space is not an object + std::wstring & next_field = find_helper.fields[find_helper.field_index]; - if( space && !space->is_object() ) + if( next_field == L"this" ) { - std::wstring & next_field = find_helper.fields[find_helper.field_index]; - - if( next_field == L"this" ) - { - find_helper.field_index += 1; - } + find_helper.field_index += 1; } } } else { CreateMsg(L"", find_helper.name, find_helper.fields, find_helper.field_index, L" exceeded the maximum number of fields for a space object"); - space = nullptr; + return false; } } else { -// PrintLastSpaceField(*space, find_helper); -// status = true; -// // increment field_index here? break; - -// if( is_last_field ) -// { -// if( !IsTestingFunctionExistence() ) -// { -// PrintLastSpaceField(space, result, parameters); -// } -// -// field_index += 1; -// } -// else -// { -// if( !IsTestingFunctionExistence() ) -// { -// CreateMsg(L"", name, fields, field_index, L" of a space is not an object nor a table"); -// } -// -// space = nullptr; -// } } model_wrapper_space_table_index += 1; } - if( space ) + if( space->is_table() ) + { + CallSpaceTableForLastField(space_wrapper, *space, find_helper, model_wrapper_space_table_index); + } + else + if( !IsTestingFunctionExistence() ) { PrintLastSpaceField(*space, find_helper); - if( !IsTestingFunctionExistence() ) - { + if( find_helper.is_last_field() ) DumpSpaceIfNeeded(*space, find_helper); - } } return true; - //return status; } @@ -1882,7 +1839,7 @@ void Generator::FindVaria template void Generator::EvaluateVariable(FindHelper & find_helper) { - bool was_child_found = false; + Var * result_child = nullptr; find_helper.found = false; find_helper.current_var = nullptr; const std::wstring & name = find_helper.current_name(); @@ -1890,8 +1847,8 @@ void Generator::EvaluateV if( find_helper.previous_var ) { find_helper.current_var = find_helper.previous_var->find_child(name); + result_child = find_helper.current_var; find_helper.found = (find_helper.current_var != nullptr); - was_child_found = (find_helper.current_var != nullptr); if( find_helper.current_var ) *find_helper.result = *find_helper.current_var; @@ -1955,7 +1912,7 @@ void Generator::EvaluateV } } - if( find_helper.previous_var && !was_child_found ) + if( find_helper.previous_var && !result_child ) { // may only model_container_wrapper and space_wrapper here? if( find_helper.result->type == Var::TYPE_MODEL || @@ -1963,13 +1920,16 @@ void Generator::EvaluateV find_helper.result->type == Var::TYPE_SPACE_WRAPPER || find_helper.result->type == Var::TYPE_FUNCTION ) { - Var * previous = find_helper.previous_var->add_child(name, *find_helper.result); + result_child = find_helper.previous_var->add_child(name, *find_helper.result); + } + } - if( find_helper.result->type == Var::TYPE_SPACE_WRAPPER && find_helper.result->space_wrapper ) - { - find_helper.result->clear(); - find_helper.found = CallSpace(*previous->space_wrapper, find_helper); - } + if( result_child ) + { + if( result_child->type == Var::TYPE_SPACE_WRAPPER && result_child->space_wrapper ) + { + find_helper.result->clear(); + find_helper.found = CallSpace(*result_child->space_wrapper, find_helper); } } @@ -2722,19 +2682,16 @@ void Generator::MakeTextF break; } else -// if( result.type == Var::Type::TYPE_SPACE_WRAPPER ) -// { -// if( !result.space_wrapper->is_iterator_correct() ) -// break; -// } -// else + if( result.type == Var::Type::TYPE_SPACE_WRAPPER ) + { + if( !result.space_wrapper->get_last_for_loop_status() ) + break; + } + else { break; } -// if( !result.to_bool() ) -// break; - if( !item.item_tab.empty() ) MakeText( *item.item_tab[0] ); // should be only one item } diff --git a/src/var.h b/src/var.h index 820e729..e4ddb07 100644 --- a/src/var.h +++ b/src/var.h @@ -152,6 +152,13 @@ public: template void set(std::list & model_container); + template + void set(std::vector & model_container); + + template + void set(std::list & model_container); + + void set(morm::SpaceWrapper & space_wrapper); bool is_equal(const char * str) const; bool is_equal(const wchar_t * str) const; @@ -394,10 +401,15 @@ bool Var::to_bool() const return space_local.to_bool(); case TYPE_STREAM: + return !stream.empty(); + case TYPE_FUNCTION: case TYPE_DATE: case TYPE_MODEL: + break; + case TYPE_SPACE_WRAPPER: + return space_wrapper->get_space()->to_bool(); break; case TYPE_MODEL_CONTAINER_WRAPPER: @@ -414,6 +426,7 @@ bool Var::to_bool() const template void Var::set(const char * str) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(str); } @@ -422,6 +435,7 @@ void Var::set(const char * str) template void Var::set(const wchar_t * str) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(str); } @@ -430,6 +444,7 @@ void Var::set(const wchar_t * str) template void Var::set(const std::string & str) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(str); } @@ -438,6 +453,7 @@ void Var::set(const std::string & str) template void Var::set(const std::wstring & str) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(str); } @@ -446,6 +462,7 @@ void Var::set(const std::wstring & str) template void Var::set(char val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(str); } @@ -453,6 +470,7 @@ void Var::set(char val) template void Var::set(unsigned char val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(str); } @@ -460,6 +478,7 @@ void Var::set(unsigned char val) template void Var::set(wchar_t val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(str); } @@ -469,6 +488,7 @@ void Var::set(wchar_t val) template void Var::set(bool val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -478,6 +498,7 @@ void Var::set(bool val) template void Var::set(short val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -485,6 +506,7 @@ void Var::set(short val) template void Var::set(int val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -492,6 +514,7 @@ void Var::set(int val) template void Var::set(long val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -499,6 +522,7 @@ void Var::set(long val) template void Var::set(long long val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -506,6 +530,7 @@ void Var::set(long long val) template void Var::set(unsigned short val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -513,6 +538,7 @@ void Var::set(unsigned short val) template void Var::set(unsigned int val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -520,6 +546,7 @@ void Var::set(unsigned int val) template void Var::set(unsigned long val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -527,6 +554,7 @@ void Var::set(unsigned long val) template void Var::set(unsigned long long val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -535,6 +563,7 @@ void Var::set(unsigned long long val) template void Var::set(float val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -543,6 +572,7 @@ void Var::set(float val) template void Var::set(double val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -551,6 +581,7 @@ void Var::set(double val) template void Var::set(long double val) { + clear(); type = TYPE_SPACE_LOCAL; space_local.set(val); } @@ -559,6 +590,7 @@ void Var::set(long double val) template void Var::set(const pt::Stream & str) { + clear(); type = TYPE_STREAM; stream.clear(); stream << str; @@ -569,6 +601,7 @@ void Var::set(const pt::Stream & str) template void Var::set(UserFunction user_function) { + clear(); type = TYPE_FUNCTION; this->user_function = user_function; } @@ -577,6 +610,7 @@ void Var::set(UserFunction user_function) template void Var::set(const pt::Date & date) { + clear(); type = TYPE_DATE; this->date = &date; } @@ -585,6 +619,7 @@ void Var::set(const pt::Date & date) template void Var::set(morm::Model & model) { + clear(); type = TYPE_MODEL; this->model = &model; } @@ -593,8 +628,10 @@ void Var::set(morm::Model & model) template void Var::set(morm::ModelContainerWrapper & model_container_wrapper) { + clear(); type = TYPE_MODEL_CONTAINER_WRAPPER; this->model_container_wrapper = &model_container_wrapper; + this->model_container_wrapper->increment_reference_counter(); } @@ -602,6 +639,7 @@ template template void Var::set(std::vector & model_container) { + clear(); type = TYPE_MODEL_CONTAINER_WRAPPER; this->model_container_wrapper = new morm::ModelWrapperVector(&model_container); } @@ -611,11 +649,43 @@ template template void Var::set(std::list & model_container) { + clear(); type = TYPE_MODEL_CONTAINER_WRAPPER; this->model_container_wrapper = new morm::ModelWrapperList(&model_container); } +template +template +void Var::set(std::vector & model_container) +{ + clear(); + type = TYPE_MODEL_CONTAINER_WRAPPER; + this->model_container_wrapper = new morm::ModelWrapperVectorPointer(&model_container); +} + + +template +template +void Var::set(std::list & model_container) +{ + clear(); + type = TYPE_MODEL_CONTAINER_WRAPPER; + this->model_container_wrapper = new morm::ModelWrapperListPointer(&model_container); +} + + +template +void Var::set(morm::SpaceWrapper & space_wrapper) +{ + clear(); + type = TYPE_SPACE_WRAPPER; + this->space_wrapper = &space_wrapper; + this->space_wrapper->increment_reference_counter(); +} + + + template diff --git a/src/vars.h b/src/vars.h index 4ad71e7..9234e87 100644 --- a/src/vars.h +++ b/src/vars.h @@ -102,6 +102,33 @@ public: template Var & add(const std::wstring & name, std::list & model_container); + + template + Var & add(const char * name, std::vector & model_container); + + template + Var & add(const wchar_t * name, std::vector & model_container); + + template + Var & add(const std::string & name, std::vector & model_container); + + template + Var & add(const std::wstring & name, std::vector & model_container); + + template + Var & add(const char * name, std::list & model_container); + + template + Var & add(const wchar_t * name, std::list & model_container); + + template + Var & add(const std::string & name, std::list & model_container); + + template + Var & add(const std::wstring & name, std::list & model_container); + + + Var * find(const char * name) const; Var * find(const wchar_t * name) const; Var * find(const std::string & name) const; @@ -337,6 +364,79 @@ Var & Vars::add(const std::wstring & name, std::list +template +Var & Vars::add(const char * name, std::vector & model_container) +{ + Var & var = add(name); + var.set(model_container); + return var; +} + +template +template +Var & Vars::add(const wchar_t * name, std::vector & model_container) +{ + Var & var = add(name); + var.set(model_container); + return var; +} + +template +template +Var & Vars::add(const std::string & name, std::vector & model_container) +{ + Var & var = add(name); + var.set(model_container); + return var; +} + +template +template +Var & Vars::add(const std::wstring & name, std::vector & model_container) +{ + Var & var = add(name); + var.set(model_container); + return var; +} + + + +template +template +Var & Vars::add(const char * name, std::list & model_container) +{ + Var & var = add(name); + var.set(model_container); + return var; +} + +template +template +Var & Vars::add(const wchar_t * name, std::list & model_container) +{ + Var & var = add(name); + var.set(model_container); + return var; +} + +template +template +Var & Vars::add(const std::string & name, std::list & model_container) +{ + Var & var = add(name); + var.set(model_container); + return var; +} + +template +template +Var & Vars::add(const std::wstring & name, std::list & model_container) +{ + Var & var = add(name); + var.set(model_container); + return var; +}