WIP: add a Val struct as an input/output when calling a function

This commit is contained in:
2024-12-11 17:04:05 +01:00
parent 079a62c230
commit 6e2fe34a5c
2 changed files with 153 additions and 142 deletions

View File

@@ -145,6 +145,10 @@ struct Stack
struct Env
{
// a result consists of a string and a boolean value
// output stream
pt::Stream & out; // OLD INTERFACE a reference to res.stream
// table of parameters
// the table can be empty
std::vector<Val> & params;
@@ -156,9 +160,6 @@ struct Env
// old interface but still available
//
// a result consists of a string and a boolean value
// output stream
pt::Stream & out; // OLD INTERFACE a reference to res.stream
// return value from a user's function (default false if not set directly by the function)
//bool res;

View File

@@ -36,9 +36,6 @@
#ifndef headerfile_ezc_generator
#define headerfile_ezc_generator
#include <fstream>
#include <memory>
#include <sstream>
#include <vector>
#include "blocks.h"
#include "pattern.h"
@@ -48,24 +45,15 @@
#include "expressionparser.h"
#include "models.h"
#include "log/log.h"
#include "utf8/utf8.h"
#ifdef EZC_HAS_MORM_LIBRARY
#include "model.h"
#include "valwrapper.h"
#endif
namespace Ezc
{
/*
pt::Stream
we use only method write(const wchar_t * str, size_t len) from the stream
*/
class Generator
{
public:
@@ -164,7 +152,6 @@ private:
#ifdef EZC_HAS_MORM_LIBRARY
field_index = 0;
#endif
}
FindHelper(const FindHelper &) = delete;
@@ -286,7 +273,7 @@ private:
// an empty string for FunInfo objects
// when there is no any parameters
const std::wstring empty;
//const std::wstring empty;
// a stack for [for] statements
std::vector<Stack> stack_tab;
@@ -352,22 +339,21 @@ private:
void CallObject(BaseObj & base_obj, int method_index, Env & info);
void PrintDate(pt::Date * date, std::vector<Val> & parameters, pt::Stream & out_stream);
bool PrintDatePart(pt::Date * date, const std::wstring & field, std::vector<Val> & parameters, pt::Stream & out_stream);
void PrintDate(FindHelper & find_helper, pt::Date * date);
bool PrintDatePart(FindHelper & find_helper, pt::Date * date);
bool CallDate(Val & current, std::vector<std::wstring> & fields, std::vector<Val> & parameters, pt::Stream & out_stream);
bool CallDate(FindHelper & find_helper);
void PrintLastSpaceField(pt::Space * space, std::vector<Val> & parameters, pt::Stream & out_stream);
void CallSpaceObjectForLastField(std::vector<Val> & parameters, pt::Stream & out_stream, pt::Space * space);
pt::Space * CallSpaceObjectForMiddleField(std::wstring & root_space_name, std::vector<std::wstring> & fields, size_t field_index, pt::Space * space);
void PrintLastSpaceField(FindHelper & find_helper, pt::Space * space);
void CallSpaceObjectForLastField(FindHelper & find_helper, pt::Space * space);
pt::Space * CallSpaceObjectForMiddleField(FindHelper & find_helper, pt::Space * space);
void CallSpaceTableForLastField(morm::SpaceWrapper & space_wrapper, std::vector<Val> & parameters, pt::Stream & out_stream,
void CallSpaceTableForLastField(FindHelper & find_helper, morm::SpaceWrapper & space_wrapper,
pt::Space * space, size_t model_wrapper_space_table_index);
pt::Space * CallSpaceTableForMiddleField(morm::SpaceWrapper & space_wrapper, std::wstring & root_space_name, std::vector<std::wstring> & fields,
size_t field_index, pt::Space * space, size_t model_wrapper_space_table_index);
pt::Space * CallSpaceTableForMiddleField(FindHelper & find_helper, morm::SpaceWrapper & space_wrapper, pt::Space * space, size_t model_wrapper_space_table_index);
bool CallSpace(FindHelper & find_helper, std::vector<std::wstring> & fields, std::vector<Val> & parameters, Val & result, pt::Stream & out_stream);
bool CallSpace(FindHelper & find_helper);
#ifdef EZC_HAS_MORM_LIBRARY
bool CallModelField(FindHelper & find_helper, morm::Model & model);
@@ -383,12 +369,12 @@ private:
pt::Stream & out_stream,
const pt::Stream & in_stream);
bool CallVariable(Item::Function & item_fun,
Val & variable,
std::vector<Val> & parameters,
Val & result,
pt::Stream & out_stream,
const pt::Stream & in_stream);
// bool CallVariable(Item::Function & item_fun,
// Val & variable,
// std::vector<Val> & parameters,
// Val & result,
// pt::Stream & out_stream,
// const pt::Stream & in_stream);
bool PrepareParameters(FindHelper & find_helper);
bool ReduceFields(FindHelper & find_helper);
@@ -414,8 +400,8 @@ private:
bool ShouldMakeJsonDump(std::vector<Val> & parameters);
bool IsPrettyPrint(std::vector<Val> & parameters);
void DumpSpaceIfNeeded(std::vector<Val> & parameters, pt::Stream & out_stream, pt::Space * space);
void DumpModelIfNeeded(morm::Model & model, std::vector<Val> & parameters, pt::Stream & out_stream);
void DumpSpaceIfNeeded(FindHelper & find_helper, pt::Space * space);
void DumpModelIfNeeded(FindHelper & find_helper, morm::Model & model);
pt::Stream * FindAddOutputStream(const std::wstring & name);
void CopyTmpStreamToOutputStreams(Item::Function & fun, pt::Stream & ezc_out_tmp_stream);
@@ -1083,6 +1069,7 @@ bool Generator::CheckBlockArgument(FindHelper & find_helper)
bool Generator::FindInCache(Item::Function & item_fun, FindHelper & find_helper)
{
/*
if( can_find_in_cache )
{
if( item_fun.base_obj )
@@ -1104,6 +1091,7 @@ bool Generator::FindInCache(Item::Function & item_fun, FindHelper & find_helper)
return true;
}
}
*/
return false;
}
@@ -1306,6 +1294,7 @@ bool Generator::HasParam(std::vector<Val> & parameters, const wchar_t * param1,
{
for(Val & val : parameters)
{
/*
if( !val.is_function )
{
if( val.str == param1 || (param2 && val.str == param2) )
@@ -1313,6 +1302,7 @@ bool Generator::HasParam(std::vector<Val> & parameters, const wchar_t * param1,
return true;
}
}
*/
}
return false;
@@ -1339,33 +1329,33 @@ bool Generator::IsPrettyPrint(std::vector<Val> & parameters)
void Generator::DumpSpaceIfNeeded(std::vector<Val> & parameters, pt::Stream & out_stream, pt::Space * space)
void Generator::DumpSpaceIfNeeded(FindHelper & find_helper, pt::Space * space)
{
bool dump_space = ShouldMakeSpaceDump(parameters);
bool dump_json = ShouldMakeJsonDump(parameters);
bool dump_space = ShouldMakeSpaceDump(find_helper.parameters);
bool dump_json = ShouldMakeJsonDump(find_helper.parameters);
if( dump_space || dump_json )
{
bool pretty = IsPrettyPrint(parameters);
bool pretty = IsPrettyPrint(find_helper.parameters);
if( dump_space )
{
space->serialize_to_space_stream(out_stream, pretty);
space->serialize_to_space_stream(find_helper.out_stream, pretty);
}
else
if( dump_json )
{
space->serialize_to_json_stream(out_stream, pretty);
space->serialize_to_json_stream(find_helper.out_stream, pretty);
}
}
}
void Generator::DumpModelIfNeeded(morm::Model & model, std::vector<Val> & parameters, pt::Stream & out_stream)
void Generator::DumpModelIfNeeded(FindHelper & find_helper, morm::Model & model)
{
bool dump_space = ShouldMakeSpaceDump(parameters);
bool dump_json = ShouldMakeJsonDump(parameters);
bool dump_space = ShouldMakeSpaceDump(find_helper.parameters);
bool dump_json = ShouldMakeJsonDump(find_helper.parameters);
if( dump_space || dump_json )
{
@@ -1381,9 +1371,10 @@ void Generator::DumpModelIfNeeded(morm::Model & model, std::vector<Val> & parame
// IMPLEMENT ME
// depends on the model_connector (flat connector)
// need to be made in a different way
pt::TextStream temp_str;
model.to_text(temp_str, false, false);
out_stream << temp_str;
// pt::TextStream temp_str;
// model.to_text(temp_str, false, false);
// find_helper.out_stream << temp_str;
model.to_text(find_helper.out_stream);
}
}
}
@@ -1391,78 +1382,79 @@ void Generator::DumpModelIfNeeded(morm::Model & model, std::vector<Val> & parame
void Generator::PrintDate(pt::Date * date, std::vector<Val> & parameters, pt::Stream & out_stream)
void Generator::PrintDate(FindHelper & find_helper, pt::Date * date)
{
bool is_roman = HasParam(parameters, L"roman");
bool is_no_sec = HasParam(parameters, L"no_sec");
bool only_date = HasParam(parameters, L"only_date");
bool only_time = HasParam(parameters, L"only_time");
bool is_roman = HasParam(find_helper.parameters, L"roman");
bool is_no_sec = HasParam(find_helper.parameters, L"no_sec");
bool only_date = HasParam(find_helper.parameters, L"only_date");
bool only_time = HasParam(find_helper.parameters, L"only_time");
if( only_date )
{
date->SerializeYearMonthDay(out_stream, is_roman);
date->SerializeYearMonthDay(find_helper.out_stream, is_roman);
}
else
if( only_time )
{
if( is_no_sec )
date->SerializeHourMin(out_stream);
date->SerializeHourMin(find_helper.out_stream);
else
date->SerializeHourMinSec(out_stream);
date->SerializeHourMinSec(find_helper.out_stream);
}
else
{
date->Serialize(out_stream, is_roman, !is_no_sec);
date->Serialize(find_helper.out_stream, is_roman, !is_no_sec);
}
}
bool Generator::PrintDatePart(pt::Date * date, const std::wstring & field, std::vector<Val> & parameters, pt::Stream & out_stream)
bool Generator::PrintDatePart(FindHelper & find_helper, pt::Date * date)
{
bool is_test = IsTestingFunctionExistence();
std::wstring & field = find_helper.fields[find_helper.field_index];
if( field == L"year" )
{
if( !is_test )
out_stream << date->year;
find_helper.out_stream << date->year;
}
else
if( field == L"month" )
{
if( !is_test )
{
bool is_roman = HasParam(parameters, L"roman");
bool is_roman = HasParam(find_helper.parameters, L"roman");
if( is_roman )
pt::Date::SerializeMonthAsRoman(out_stream, date->month);
pt::Date::SerializeMonthAsRoman(find_helper.out_stream, date->month);
else
out_stream << date->month;
find_helper.out_stream << date->month;
}
}
else
if( field == L"day" )
{
if( !is_test )
out_stream << date->day;
find_helper.out_stream << date->day;
}
else
if( field == L"hour" )
{
if( !is_test )
out_stream << date->hour;
find_helper.out_stream << date->hour;
}
else
if( field == L"min" )
{
if( !is_test )
out_stream << date->min;
find_helper.out_stream << date->min;
}
else
if( field == L"sec" )
{
if( !is_test )
out_stream << date->sec;
find_helper.out_stream << date->sec;
}
else
{
@@ -1474,24 +1466,25 @@ bool Generator::PrintDatePart(pt::Date * date, const std::wstring & field, std::
bool Generator::CallDate(Val & current, std::vector<std::wstring> & fields, std::vector<Val> & parameters, pt::Stream & out_stream)
bool Generator::CallDate(FindHelper & find_helper)
{
bool found = true;
bool all_fields_known = (find_helper.field_index == fields.size());
bool last_field_not_known = (find_helper.field_index + 1 == fields.size());
bool all_fields_known = (find_helper.field_index == find_helper.fields.size());
bool last_field_not_known = (find_helper.field_index + 1 == find_helper.fields.size());
if( all_fields_known )
{
PrintDate(current.date, parameters, out_stream);
PrintDate(find_helper, find_helper.current.date);
}
else
if( last_field_not_known )
{
if( !PrintDatePart(current.date, fields[find_helper.field_index], parameters, out_stream) )
if( !PrintDatePart(find_helper, find_helper.current.date) )
{
if( !IsTestingFunctionExistence() )
{
CreateMsg(L"cannot find ", *find_helper.fun_name, fields, L", unknown property ", fields[find_helper.field_index].c_str(), L" of date object");
CreateMsg(L"cannot find ", find_helper.fun_name, find_helper.fields, L", unknown property ",
find_helper.fields[find_helper.field_index].c_str(), L" of a Date object");
}
found = false;
@@ -1501,7 +1494,8 @@ bool Generator::CallDate(Val & current, std::vector<std::wstring> & fields, std:
{
if( !IsTestingFunctionExistence() )
{
CreateMsg(L"cannot find ", *find_helper.fun_name, fields, L", ", fields[find_helper.field_index].c_str(), L" is not a model nor a model container nor a space");
CreateMsg(L"cannot find ", find_helper.fun_name, find_helper.fields, L", ",
find_helper.fields[find_helper.field_index].c_str(), L" is not a model nor a model container nor a space");
}
found = false;
@@ -1514,29 +1508,30 @@ bool Generator::CallDate(Val & current, std::vector<std::wstring> & fields, std:
void Generator::CallSpaceObjectForLastField(std::vector<Val> & parameters, pt::Stream & out_stream, pt::Space * space)
void Generator::CallSpaceObjectForLastField(FindHelper & find_helper, pt::Space * space)
{
if( IsTestingFunctionExistence() )
{
last_res = true;
find_helper.result.set(true);
//last_res = true;
}
else
{
DumpSpaceIfNeeded(parameters, out_stream, space);
last_res = space->object_size() > 0;
DumpSpaceIfNeeded(find_helper, space);
//last_res = space->object_size() > 0;
}
}
pt::Space * Generator::CallSpaceObjectForMiddleField(std::wstring & root_space_name, std::vector<std::wstring> & fields, size_t field_index, pt::Space * space)
pt::Space * Generator::CallSpaceObjectForMiddleField(FindHelper & find_helper, pt::Space * space)
{
std::wstring & next_field = fields[field_index];
std::wstring & next_field = find_helper.fields[find_helper.field_index];
space = space->get_space(next_field);
if( !space && !IsTestingFunctionExistence() )
{
CreateMsg(L"cannot find space field: ", root_space_name, fields, field_index + 1);
CreateMsg(L"cannot find a Space field: ", find_helper.fun_name, find_helper.fields, find_helper.field_index + 1);
}
return space;
@@ -1546,7 +1541,7 @@ pt::Space * Generator::CallSpaceObjectForMiddleField(std::wstring & root_space_n
void Generator::CallSpaceTableForLastField(
morm::SpaceWrapper & space_wrapper, std::vector<Val> & parameters, pt::Stream & out_stream, pt::Space * space, size_t model_wrapper_space_table_index)
FindHelper & find_helper, morm::SpaceWrapper & space_wrapper, pt::Space * space, size_t model_wrapper_space_table_index)
{
pt::Space::TableType * table = space->get_table();
@@ -1556,41 +1551,41 @@ void Generator::CallSpaceTableForLastField(
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);
last_res = (iterator_value < table->size());
//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( IsTestingFunctionExistence() )
{
last_res = true;
find_helper.result.set(true);
//last_res = true;
}
else
{
last_res = !table->empty();
//last_res = !table->empty();
}
}
if( !IsTestingFunctionExistence() )
{
DumpSpaceIfNeeded(parameters, out_stream, space);
DumpSpaceIfNeeded(find_helper, space);
if( HasParam(parameters, L"index") )
if( HasParam(find_helper.parameters, L"index") )
{
out_stream << space_wrapper.get_space_iterator_value(model_wrapper_space_table_index);
find_helper.out_stream << space_wrapper.get_space_iterator_value(model_wrapper_space_table_index);
}
if( HasParam(parameters, L"index-one") )
if( HasParam(find_helper.parameters, L"index-one") )
{
out_stream << (space_wrapper.get_space_iterator_value(model_wrapper_space_table_index) + 1);
find_helper.out_stream << (space_wrapper.get_space_iterator_value(model_wrapper_space_table_index) + 1);
}
}
}
pt::Space * Generator::CallSpaceTableForMiddleField(morm::SpaceWrapper & space_wrapper, std::wstring & root_space_name, std::vector<std::wstring> & fields,
size_t field_index, pt::Space * space, size_t model_wrapper_space_table_index)
pt::Space * Generator::CallSpaceTableForMiddleField(FindHelper & find_helper, morm::SpaceWrapper & space_wrapper, pt::Space * space, size_t model_wrapper_space_table_index)
{
pt::Space::TableType * table = space->get_table();
@@ -1604,7 +1599,8 @@ pt::Space * Generator::CallSpaceTableForMiddleField(morm::SpaceWrapper & space_w
else
{
// this message can be print even for [if-def...]
CreateMsg(L"space table: ", root_space_name, fields, field_index, L" is not initialized, have you forgotten to use [for...] statement?");
CreateMsg(L"space table: ", find_helper.fun_name, find_helper.fields, find_helper.field_index,
L" is not initialized, have you forgotten to use [for...] statement?");
space = nullptr;
}
@@ -1613,28 +1609,28 @@ pt::Space * Generator::CallSpaceTableForMiddleField(morm::SpaceWrapper & space_w
void Generator::PrintLastSpaceField(pt::Space * space, std::vector<Val> & parameters, pt::Stream & out_stream)
void Generator::PrintLastSpaceField(FindHelper & find_helper, pt::Space * space)
{
bool no_escape = HasParam(parameters, L"raw", L"noescape");
bool no_escape = HasParam(find_helper.parameters, L"raw", L"noescape");
if( no_escape )
{
pt::WTextStream str;
space->serialize_to_string(str);
CopyStream(str, out_stream, false);
CopyStream(str, find_helper.out_stream, false);
}
else
{
space->serialize_to_string(out_stream);
space->serialize_to_string(find_helper.out_stream);
}
}
bool Generator::CallSpace(FindHelper & find_helper, std::vector<std::wstring> & fields, std::vector<Val> & parameters, Val & result, pt::Stream & out_stream)
bool Generator::CallSpace(FindHelper & find_helper)
{
morm::SpaceWrapper * space_wrapper = find_helper.wrapper->space_wrapper;
morm::SpaceWrapper * space_wrapper = find_helper.current.space_wrapper;
pt::Space * space = space_wrapper->get_space();
//last_res = false;
size_t field_index = find_helper.field_index;
@@ -1647,19 +1643,19 @@ bool Generator::CallSpace(FindHelper & find_helper, std::vector<std::wstring> &
* the first item is the root_space with a find_helper.fun_name name
*
*/
while( (field_index < fields.size() + 1) && space )
while( (field_index < find_helper.fields.size() + 1) && space )
{
bool is_last_field = (field_index == fields.size());
bool is_last_field = (field_index == find_helper.fields.size());
if( space->is_object() )
{
if( is_last_field )
{
CallSpaceObjectForLastField(parameters, out_stream, space);
CallSpaceObjectForLastField(find_helper, space);
}
else
{
space = CallSpaceObjectForMiddleField(*find_helper.fun_name, fields, field_index, space);
space = CallSpaceObjectForMiddleField(find_helper, space);
}
field_index += 1;
@@ -1671,17 +1667,17 @@ bool Generator::CallSpace(FindHelper & find_helper, std::vector<std::wstring> &
{
if( is_last_field )
{
CallSpaceTableForLastField(*space_wrapper, parameters, out_stream, space, model_wrapper_space_table_index);
CallSpaceTableForLastField(find_helper, *space_wrapper, space, model_wrapper_space_table_index);
field_index += 1;
}
else
{
space = CallSpaceTableForMiddleField(*space_wrapper, *find_helper.fun_name, fields, field_index, space, model_wrapper_space_table_index);
space = CallSpaceTableForMiddleField(find_helper, *space_wrapper, space, model_wrapper_space_table_index);
// increment field_index only if next_field is 'this' and space is not an object
if( space && !space->is_object() )
{
std::wstring & next_field = fields[field_index];
std::wstring & next_field = find_helper.fields[field_index];
if( next_field == L"this" )
{
@@ -1692,7 +1688,7 @@ bool Generator::CallSpace(FindHelper & find_helper, std::vector<std::wstring> &
}
else
{
CreateMsg(L"", *find_helper.fun_name, fields, field_index, L" exceeded the maximum number of fields for a space object");
CreateMsg(L"", find_helper.fun_name, find_helper.fields, field_index, L" exceeded the maximum number of fields for a space object");
space = nullptr;
}
}
@@ -1706,7 +1702,7 @@ bool Generator::CallSpace(FindHelper & find_helper, std::vector<std::wstring> &
}
else
{
PrintLastSpaceField(space, parameters, out_stream);
PrintLastSpaceField(find_helper, space);
//last_res = space->to_bool();
}
@@ -1716,7 +1712,7 @@ bool Generator::CallSpace(FindHelper & find_helper, std::vector<std::wstring> &
{
if( !IsTestingFunctionExistence() )
{
CreateMsg(L"", *find_helper.fun_name, fields, field_index, L" of a space is not an object nor a table");
CreateMsg(L"", find_helper.fun_name, find_helper.fields, field_index, L" of a space is not an object nor a table");
}
space = nullptr;
@@ -1749,14 +1745,16 @@ bool Generator::CallModelField(FindHelper & find_helper, morm::Model & model)
if( find_helper.parameters.empty() )
{
Env env(find_helper.out_stream, find_helper.parameters, empty, find_helper.in_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
// what about an empty input parameter?
Env env(find_helper.out_stream, find_helper.parameters, find_helper.result, find_helper.in_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
PrepareEnvStruct(env);
found = model.get_raw_value(nullptr, field.c_str(), nullptr, env, str, false);
//last_res = env.res;
}
else
{
Env env(find_helper.out_stream, find_helper.parameters, find_helper.parameters[0].str, find_helper.in_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
Env env(find_helper.out_stream, find_helper.parameters, find_helper.result, find_helper.in_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
PrepareEnvStruct(env);
found = model.get_raw_value(nullptr, field.c_str(), nullptr, env, str, false);
//last_res = env.res;
@@ -1764,8 +1762,8 @@ bool Generator::CallModelField(FindHelper & find_helper, morm::Model & model)
if( found && !str.empty())
{
bool no_escape = HasParam(parameters, L"raw", L"noescape");
CopyStream(str, out_stream, !no_escape);
bool no_escape = HasParam(find_helper.parameters, L"raw", L"noescape");
CopyStream(str, find_helper.out_stream, !no_escape);
}
return found;
@@ -1784,7 +1782,7 @@ bool Generator::CallModel(FindHelper & find_helper, morm::Model & model)
// we don't know whether the last object has properties (fields) or not
if( !IsTestingFunctionExistence() )
{
DumpModelIfNeeded(model, find_helper.parameters, find_helper.out_stream);
DumpModelIfNeeded(find_helper, model);
}
}
else
@@ -2008,23 +2006,23 @@ bool Generator::CallBlock(FindHelper & find_helper)
bool Generator::CallVariable(Item::Function & item_fun, Var & variable, std::vector<Val> & parameters, Val & result, pt::Stream & out_stream, const pt::Stream & in_stream)
{
if( variable.is_function )
{
return Call(item_fun, &variable.str, result, out_stream, in_stream);
}
else
{
if( !IsTestingFunctionExistence() )
{
out_stream << variable.str;
last_res = variable.res;
}
// bool Generator::CallVariable(Item::Function & item_fun, Var & variable, std::vector<Val> & parameters, Val & result, pt::Stream & out_stream, const pt::Stream & in_stream)
// {
// if( variable.is_function )
// {
// return Call(item_fun, &variable.str, result, out_stream, in_stream);
// }
// else
// {
// if( !IsTestingFunctionExistence() )
// {
// out_stream << variable.str;
// last_res = variable.res;
// }
return true;
}
}
// return true;
// }
// }
bool Generator::PrepareParameters(FindHelper & find_helper)
@@ -2149,6 +2147,8 @@ bool Generator::Call(Item::Function & item_fun,
catch(...)
{
// rethrow or just generate a log?
CleanupParameters(parameters);
return false;
}
CleanupParameters(parameters);
@@ -2481,13 +2481,13 @@ void Generator::EvaluateProgramNode(Item & item)
*output_stream << " for: " << item.text;
}
last_res = false;
//last_res = false;
if( expression_parser )
{
if( expression_parser->Parse(item.text) )
{
last_res = expression_parser->LastResultToBool();
//last_res = expression_parser->LastResultToBool();
if( output_stream )
{
@@ -2674,10 +2674,12 @@ void Generator::MakeTextIfDef(Item & item)
}
else
{
last_res = Call(item.function);
//last_res = Call(item.function);
}
MakeTextIf_go(item, last_res);
//MakeTextIf_go(item, last_res);
}
@@ -2693,16 +2695,17 @@ void Generator::MakeTextIfNotDef(Item & item)
}
else
{
last_res = !Call(item.function);
//last_res = !Call(item.function);
}
MakeTextIf_go(item, last_res);
//MakeTextIf_go(item, last_res);
}
void Generator::MakeTextFor(Item & item)
{
Val result(stream_temp1);
stack_tab[stack_index-1].is_for = true;
for( ; !break_generating ; stack_tab[stack_index-1].iter += 1 )
@@ -2724,11 +2727,11 @@ void Generator::MakeTextFor(Item & item)
}
else
{
if( !Call(item.function, nullptr, *stream_temp1, true, *empty_stream) )
if( !Call(item.function, nullptr, result, *stream_temp1, *empty_stream) )
return;
}
if( !last_res )
if( !result.to_bool() )
break;
if( !item.item_tab.empty() )
@@ -2740,6 +2743,7 @@ void Generator::MakeTextFor(Item & item)
void Generator::MakeTextDefine(Item & item, Val & val)
{
/*
val.str.clear();
val.res = ConvertToBool(val.str);
var.is_function = false;
@@ -2775,6 +2779,7 @@ void Generator::MakeTextDefine(Item & item, Val & val)
val.str = fun.name;
val.res = ConvertToBool(fun.name);
}
*/
}
@@ -2816,6 +2821,7 @@ void Generator::MakeTextDefineIfNotSet(Item & item)
void Generator::MakeTextLet(Item & item, Val & val)
{
/*
val.str.clear();
val.res = ConvertToBool(val.str);
var.is_function = true;
@@ -2840,6 +2846,7 @@ void Generator::MakeTextLet(Item & item, Val & val)
{
val.res = ConvertToBool(val.str);
}
*/
}
@@ -2880,6 +2887,7 @@ void Generator::MakeTextLetIfNotSet(Item & item)
void Generator::MakeTextFilter(Item & item)
{
/*
if( filter_index >= filter_tab.size() )
{
CreateMsg(L"Generator exceeded allowed number of filters");
@@ -2910,6 +2918,7 @@ void Generator::MakeTextFilter(Item & item)
ClearStream(*output_stream);
output_stream = old_stream;
filter_index -= 1;
*/
}
@@ -3042,7 +3051,7 @@ void Generator::MakeTextEzc(Item & item)
void Generator::MakeTextReturn(Item & item)
{
last_res = false;
//last_res = false;
if( block_stack_index == 0 )
{
@@ -3058,8 +3067,9 @@ void Generator::MakeTextReturn(Item & item)
{
// output stream in [return] statement is ignored (we use only the stream produced by the whole block)
// this Call() sets last_res which is used later when we return to CallBlock()
Call(item.function, nullptr, *stream_temp1, false, *empty_stream);
ClearStream(*stream_temp1);
// Call(item.function, nullptr, *stream_temp1, false, *empty_stream);
// ClearStream(*stream_temp1);
}
}