WIP: add a Val struct as an input/output when calling a function
This commit is contained in:
@@ -323,6 +323,8 @@ private:
|
||||
|
||||
ExpressionParser * expression_parser;
|
||||
|
||||
std::vector<Val> no_parameters;
|
||||
|
||||
void InitializeTmpStreams();
|
||||
|
||||
void ResizeStreamStack(std::vector<pt::Stream*> & stream_tab, size_t stream_tab_max_size);
|
||||
@@ -371,7 +373,6 @@ private:
|
||||
//void CallFunction(FindHelper & find_helper);
|
||||
|
||||
void CallMethod(morm::Model * model, Val::ModelMethod1 method, Env & env);
|
||||
void CallMethod(morm::Model * model, Val::ModelMethod2 method, Val & res);
|
||||
bool CallMethod(morm::Model * model, Val::ModelMethod3 method);
|
||||
bool CallMethod(morm::Model * model, Val::ModelMethod4 method);
|
||||
|
||||
@@ -407,8 +408,9 @@ private:
|
||||
bool FindLastModelWrapper(FindHelper & find_helper, bool is_for_alias);
|
||||
bool FindLastSpace(FindHelper & find_helper);
|
||||
|
||||
bool EvaluateFunctions(pt::Stream & out_stream, Val & val, Val & result);
|
||||
bool EvaluateFunctions(pt::Stream & out_stream, ValWrapper & valwrapper);
|
||||
bool EvaluateFunctions(pt::Stream & out_stream, Val & val, std::vector<Val> & parameters, Val & result);
|
||||
bool EvaluateFunctions(pt::Stream & out_stream, ValWrapper & valwrapper, std::vector<Val> & parameters);
|
||||
bool EvaluateFunctions(FindHelper & find_helper, bool use_parameters, ValWrapper & valwrapper);
|
||||
|
||||
void CallObject(BaseObj & base_obj,
|
||||
int method_index,
|
||||
@@ -1344,13 +1346,6 @@ void Generator::CallMethod(morm::Model * model, Val::ModelMethod1 method, Env &
|
||||
}
|
||||
|
||||
|
||||
void Generator::CallMethod(morm::Model * model, Val::ModelMethod2 method, Val & res)
|
||||
{
|
||||
res.clear();
|
||||
(model->*method)(res);
|
||||
}
|
||||
|
||||
|
||||
bool Generator::CallMethod(morm::Model * model, Val::ModelMethod3 method)
|
||||
{
|
||||
return (model->*method)();
|
||||
@@ -1983,11 +1978,10 @@ Val * Generator::FindLastModelWrapperEvalueateFunctionsRenameMe(FindHelper & fin
|
||||
|
||||
|
||||
|
||||
bool Generator::EvaluateFunctions(pt::Stream & out_stream, Val & val, Val & result)
|
||||
bool Generator::EvaluateFunctions(pt::Stream & out_stream, Val & val, std::vector<Val> & parameters, Val & result)
|
||||
{
|
||||
size_t max_calls = 2; // change me to something reasnoable
|
||||
size_t current_call = 1;
|
||||
std::vector<Val> no_parameters; // make me some kind of a static
|
||||
Val * current_val = &val;
|
||||
result.clear();
|
||||
result.set_output_stream(out_stream);
|
||||
@@ -2002,9 +1996,12 @@ bool Generator::EvaluateFunctions(pt::Stream & out_stream, Val & val, Val & resu
|
||||
|
||||
if( current_val->has_function() )
|
||||
{
|
||||
/*
|
||||
* current_val can point to the 'result' in a second iteration
|
||||
* the result is correclty cleared in Env cctor so we have to copy current_val->pointer now
|
||||
*/
|
||||
Val::UserFunction function = reinterpret_cast<Val::UserFunction>(current_val->pointer);
|
||||
|
||||
Env env(out_stream, no_parameters, result, *empty_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
|
||||
Env env(out_stream, parameters, result, *empty_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
|
||||
CallFunction(function, env);
|
||||
}
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
@@ -2015,22 +2012,22 @@ bool Generator::EvaluateFunctions(pt::Stream & out_stream, Val & val, Val & resu
|
||||
|
||||
if( current_val->model_method1 )
|
||||
{
|
||||
Val::ModelMethod1 method = current_val->model_method1; // current_val can point to result so copy the value (Env cctor calls a clear() method on the result)
|
||||
Env env(out_stream, no_parameters, result, *empty_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
|
||||
Val::ModelMethod1 method = current_val->model_method1; // current_val can point to the result so copy the value (Env cctor calls a clear() method on the result)
|
||||
Env env(out_stream, parameters, result, *empty_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
|
||||
CallMethod(model, method, env);
|
||||
}
|
||||
else
|
||||
if( current_val->model_method2 )
|
||||
{
|
||||
Val::ModelMethod2 method = current_val->model_method2;
|
||||
CallMethod(model, method, result);
|
||||
}
|
||||
else
|
||||
if( current_val->model_method3 )
|
||||
{
|
||||
bool res = CallMethod(model, current_val->model_method3);
|
||||
result.set(res);
|
||||
}
|
||||
else
|
||||
if( current_val->model_method4 )
|
||||
{
|
||||
bool res = CallMethod(model, current_val->model_method4);
|
||||
result.set(res);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2042,7 +2039,7 @@ bool Generator::EvaluateFunctions(pt::Stream & out_stream, Val & val, Val & resu
|
||||
}
|
||||
|
||||
|
||||
bool Generator::EvaluateFunctions(pt::Stream & out_stream, ValWrapper & valwrapper)
|
||||
bool Generator::EvaluateFunctions(pt::Stream & out_stream, ValWrapper & valwrapper, std::vector<Val> & parameters)
|
||||
{
|
||||
if( valwrapper.has_evaluated_val )
|
||||
{
|
||||
@@ -2058,7 +2055,7 @@ bool Generator::EvaluateFunctions(pt::Stream & out_stream, ValWrapper & valwrapp
|
||||
{
|
||||
size_t current_size = out_stream.size();
|
||||
|
||||
if( EvaluateFunctions(out_stream, valwrapper.val, valwrapper.evaluated_val) )
|
||||
if( EvaluateFunctions(out_stream, valwrapper.val, parameters, valwrapper.evaluated_val) )
|
||||
{
|
||||
valwrapper.has_evaluated_val = true;
|
||||
|
||||
@@ -2082,6 +2079,19 @@ bool Generator::EvaluateFunctions(pt::Stream & out_stream, ValWrapper & valwrapp
|
||||
}
|
||||
|
||||
|
||||
bool Generator::EvaluateFunctions(FindHelper & find_helper, bool use_parameters, ValWrapper & valwrapper)
|
||||
{
|
||||
if( !no_parameters.empty() )
|
||||
{
|
||||
no_parameters.clear();
|
||||
}
|
||||
|
||||
std::vector<Val> * parameters = (use_parameters) ? &find_helper.parameters : &no_parameters;
|
||||
|
||||
return EvaluateFunctions(find_helper.out_stream, valwrapper, *parameters);
|
||||
}
|
||||
|
||||
|
||||
// RENAMEME
|
||||
bool Generator::FindLastModelWrapper(FindHelper & find_helper, bool is_for_alias)
|
||||
{
|
||||
@@ -2116,7 +2126,9 @@ bool Generator::FindLastModelWrapper(FindHelper & find_helper, bool is_for_alias
|
||||
|
||||
if( (find_helper.field_index + 1 < find_helper.fields.size()) || !is_for_alias )
|
||||
{
|
||||
if( EvaluateFunctions(find_helper.out_stream, valwrapper) )
|
||||
bool use_parameters = (find_helper.field_index + 1 == find_helper.fields.size());
|
||||
|
||||
if( EvaluateFunctions(find_helper, use_parameters, valwrapper) )
|
||||
{
|
||||
child_valwrapper = find_helper.valwrapper->add_child(field, valwrapper);
|
||||
}
|
||||
@@ -2330,7 +2342,10 @@ void Generator::EvaluateParameters(FindHelper & find_helper)
|
||||
{
|
||||
// parameters[i].str = fun_child.name;
|
||||
// parameters[i].res = ConvertToBool(fun_child.name);
|
||||
find_helper.parameters[i] << fun_child.name;
|
||||
|
||||
|
||||
//find_helper.parameters[i] << fun_child.name;
|
||||
find_helper.parameters[i].set_pointer_to(&fun_child.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2449,9 +2464,13 @@ bool Generator::Call(Item::Function & item_fun,
|
||||
|
||||
bool is_for_alias = false;
|
||||
|
||||
EvaluateParameters(find_helper);
|
||||
|
||||
if( !is_for_alias || find_helper.field_index < find_helper.fields.size() )
|
||||
{
|
||||
if( EvaluateFunctions(find_helper.out_stream, *find_helper.valwrapper) )
|
||||
bool use_parameters = find_helper.fields.empty();
|
||||
|
||||
if( EvaluateFunctions(find_helper, use_parameters, *find_helper.valwrapper) )
|
||||
{
|
||||
if( find_helper.valwrapper->has_evaluated_val )
|
||||
{
|
||||
@@ -2470,7 +2489,6 @@ bool Generator::Call(Item::Function & item_fun,
|
||||
if( !FindLastSpace(find_helper) )
|
||||
return false;
|
||||
|
||||
EvaluateParameters(find_helper);
|
||||
bool status = false;
|
||||
|
||||
try
|
||||
|
33
src/val.cpp
33
src/val.cpp
@@ -91,7 +91,6 @@ void Val::copy(const Val & val)
|
||||
if( type == Type::TYPE_MODEL_METHOD )
|
||||
{
|
||||
model_method1 = val.model_method1;
|
||||
model_method2 = val.model_method2;
|
||||
model_method3 = val.model_method3;
|
||||
model_method4 = val.model_method4;
|
||||
}
|
||||
@@ -157,7 +156,6 @@ void Val::initialize_empty()
|
||||
type = TYPE_VOID;
|
||||
pointer = nullptr;
|
||||
model_method1 = nullptr;
|
||||
model_method2 = nullptr;
|
||||
model_method3 = nullptr;
|
||||
model_method4 = nullptr;
|
||||
space_wrapper = nullptr;
|
||||
@@ -220,7 +218,7 @@ bool Val::has_function()
|
||||
|
||||
bool Val::has_method()
|
||||
{
|
||||
return type == Type::TYPE_MODEL_METHOD && pointer && (model_method1 || model_method2 || model_method3);
|
||||
return type == Type::TYPE_MODEL_METHOD && pointer && (model_method1 || model_method3 || model_method4);
|
||||
}
|
||||
|
||||
|
||||
@@ -458,15 +456,6 @@ void Val::set_pointer_to(morm::Model * model, ModelMethod1 model_method1)
|
||||
}
|
||||
|
||||
|
||||
void Val::set_pointer_to(morm::Model * model, ModelMethod2 model_method2)
|
||||
{
|
||||
clear();
|
||||
type = TYPE_MODEL_METHOD;
|
||||
this->pointer = model;
|
||||
this->model_method2 = model_method2;
|
||||
}
|
||||
|
||||
|
||||
void Val::set_pointer_to(morm::Model * model, ModelMethod3 model_method3)
|
||||
{
|
||||
clear();
|
||||
@@ -696,31 +685,41 @@ void Val::set_pointer_to(unsigned long long * val)
|
||||
|
||||
void Val::set_pointer_to(float * val)
|
||||
{
|
||||
// IMPLEMENTME
|
||||
clear();
|
||||
type = TYPE_FLOAT;
|
||||
pointer = val;
|
||||
}
|
||||
|
||||
|
||||
void Val::set_pointer_to(double * val)
|
||||
{
|
||||
// IMPLEMENTME
|
||||
clear();
|
||||
type = TYPE_DOUBLE;
|
||||
pointer = val;
|
||||
}
|
||||
|
||||
|
||||
void Val::set_pointer_to(long double * val)
|
||||
{
|
||||
// IMPLEMENTME
|
||||
clear();
|
||||
type = TYPE_LONG_DOUBLE;
|
||||
pointer = val;
|
||||
}
|
||||
|
||||
|
||||
void Val::set_pointer_to(std::string * val)
|
||||
{
|
||||
// IMPLEMENTME
|
||||
clear();
|
||||
type = TYPE_STRING;
|
||||
pointer = val;
|
||||
}
|
||||
|
||||
|
||||
void Val::set_pointer_to(std::wstring * val)
|
||||
{
|
||||
// IMPLEMENTME
|
||||
clear();
|
||||
type = TYPE_WSTRING;
|
||||
pointer = val;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -68,7 +68,6 @@ public:
|
||||
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
using ModelMethod1 = void (morm::Model::*)(Env &);
|
||||
using ModelMethod2 = void (morm::Model::*)(Val &);
|
||||
using ModelMethod3 = bool (morm::Model::*)();
|
||||
using ModelMethod4 = bool (morm::Model::*)() const;
|
||||
#endif
|
||||
@@ -99,6 +98,11 @@ public:
|
||||
TYPE_UNSIGNED_INT,
|
||||
TYPE_UNSIGNED_LONG,
|
||||
TYPE_UNSIGNED_LONG_LONG,
|
||||
TYPE_FLOAT,
|
||||
TYPE_DOUBLE,
|
||||
TYPE_LONG_DOUBLE,
|
||||
TYPE_STRING,
|
||||
TYPE_WSTRING,
|
||||
};
|
||||
|
||||
|
||||
@@ -153,7 +157,6 @@ public:
|
||||
void set_pointer_to(UserFunction user_function);
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
void set_pointer_to(morm::Model * model, ModelMethod1 model_method1);
|
||||
void set_pointer_to(morm::Model * model, ModelMethod2 model_method2);
|
||||
void set_pointer_to(morm::Model * model, ModelMethod3 model_method3);
|
||||
void set_pointer_to(morm::Model * model, ModelMethod4 model_method4);
|
||||
#endif
|
||||
@@ -242,7 +245,6 @@ public:
|
||||
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
ModelMethod1 model_method1;
|
||||
ModelMethod2 model_method2;
|
||||
ModelMethod3 model_method3;
|
||||
ModelMethod4 model_method4;
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user