4
Copyright (c) 2022 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo/loom
9
#include "simodo/variable/Variable.h"
11
#include "simodo/inout/convert/functions.h"
16
using namespace simodo::variable;
19
u16string simodo::variable::toString(const Value & value, bool need_whole_info, bool quote_strings, int depth)
30
case ValueType::String:
31
if (!holds_alternative<u16string>(value.variant()))
32
str = u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
34
u16string text = get<u16string>(value.variant());
37
inout::replaceAll(text, u"\\", u"\\\\");
38
inout::replaceAll(text, u"\"", u"\\\"");
39
text = u"\""+text+u"\"";
45
str = holds_alternative<bool>(value.variant())
46
? (get<bool>(value.variant()) ? u"true"s : u"false"s)
47
: u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
50
str = holds_alternative<int64_t>(value.variant())
51
? inout::toU16(to_string(get<int64_t>(value.variant())))
52
: u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
54
case ValueType::Float:
55
str = holds_alternative<double>(value.variant())
56
? inout::toU16(inout::clearNumberFractionalPart(to_string(get<double>(value.variant()))))
57
: u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
59
// case ValueType::Undefined:
62
// case ValueType::Function:
63
// if (name.substr(0,4) == u"get_") {
64
// const VariableSet_t & params = get<shared_ptr<Record>>(value.variant())->variables();
65
// assert(params.size() >= 2);
66
// if(params.size() == 2 && params[1].declared != DeclaredType::Error) {
67
// callFunction(var,{},InterpreterMode::FullExecution);
68
// return toString(_return_value, need_whole_info, true);
72
case ValueType::Object:
73
if (!holds_alternative<shared_ptr<Object>>(value.variant()))
74
str = u"<" + inout::toU16(getValueTypeName(value.type())) + u">";
79
const VariableSet_t & record = get<shared_ptr<Object>>(value.variant())->variables();
82
for(const Variable & n : record) {
83
const Variable & n_origin = n.origin();
85
if (n_origin.type() == ValueType::Function && n.name().substr(0,4) == u"set_" && !need_whole_info)
88
if (n_origin.type() == ValueType::Function && n.name().substr(0,4) != u"get_" && !need_whole_info)
95
str += u"\"\":" + toString(n.origin().value(), need_whole_info, true, depth);
96
else if (n_origin.type() == ValueType::Function && n.name().substr(0,4) == u"get_")
97
str += n.name().substr(4) + u":" + toString(n.origin().value(), need_whole_info, true, depth);
99
str += n.name() + u":" + toString(n.origin().value(), need_whole_info, true, depth);
106
case ValueType::Array:
107
if (!holds_alternative<shared_ptr<Array>>(value.variant()))
108
str = u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
113
const std::shared_ptr<Array> array = value.getArray();
116
for(size_t i=0; i < array->values().size(); ++i)
118
if (!first) str += u", ";
119
str += toString(array->values()[i], need_whole_info, true, depth);
127
str = u"<" + inout::toU16(getValueTypeName(value.type()));
129
if ((value.type() == ValueType::IntFunction && holds_alternative<InternalFunction>(value.variant()))
130
|| (value.type() == ValueType::ExtFunction && holds_alternative<ExternalFunction>(value.variant())))
131
str += u"{}"; // Обозначаем непустую (определённую) функцию