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)
25
case ValueType::String:
26
if (!holds_alternative<u16string>(value.variant()))
27
str = u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
29
u16string text = get<u16string>(value.variant());
32
inout::replaceAll(text, u"\\", u"\\\\");
33
inout::replaceAll(text, u"\"", u"\\\"");
34
text = u"\""+text+u"\"";
40
str = holds_alternative<bool>(value.variant())
41
? (get<bool>(value.variant()) ? u"true"s : u"false"s)
42
: u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
45
str = holds_alternative<int64_t>(value.variant())
46
? inout::toU16(to_string(get<int64_t>(value.variant())))
47
: u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
49
case ValueType::Float:
50
str = holds_alternative<double>(value.variant())
51
? inout::toU16(inout::clearNumberFractionalPart(to_string(get<double>(value.variant()))))
52
: u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
54
// case ValueType::Undefined:
57
// case ValueType::Function:
58
// if (name.substr(0,4) == u"get_") {
59
// const VariableSet_t & params = get<shared_ptr<Record>>(value.variant())->variables();
60
// assert(params.size() >= 2);
61
// if(params.size() == 2 && params[1].declared != DeclaredType::Error) {
62
// callFunction(var,{},InterpreterMode::FullExecution);
63
// return toString(_return_value, need_whole_info, true);
67
case ValueType::Object:
68
if (!holds_alternative<shared_ptr<Object>>(value.variant()))
69
str = u"<" + inout::toU16(getValueTypeName(value.type())) + u">";
72
const VariableSet_t & record = get<shared_ptr<Object>>(value.variant())->variables();
75
for(const Variable & n : record) {
76
const Variable & n_origin = n.origin();
78
if (n_origin.type() == ValueType::Function && n.name().substr(0,4) == u"set_" && !need_whole_info)
81
if (n_origin.type() == ValueType::Function && n.name().substr(0,4) != u"get_" && !need_whole_info)
88
str += u"\"\":" + toString(n.origin().value(), need_whole_info);
89
else if (n_origin.type() == ValueType::Function && n.name().substr(0,4) == u"get_")
90
str += n.name().substr(4) + u":" + toString(n.origin().value(), need_whole_info);
92
str += n.name() + u":" + toString(n.origin().value(), need_whole_info, true);
99
case ValueType::Array:
100
if (!holds_alternative<shared_ptr<Array>>(value.variant()))
101
str = u"<"+inout::toU16(getValueTypeName(value.type()))+ u">";
104
const Array & array = *value.getArray();
107
for(size_t i=0; i < array.values().size(); ++i)
109
if (!first) str += u", ";
110
str += toString(array.values()[i], need_whole_info, true);
118
str = u"<" + inout::toU16(getValueTypeName(value.type()));
120
if ((value.type() == ValueType::IntFunction && holds_alternative<InternalFunction>(value.variant()))
121
|| (value.type() == ValueType::ExtFunction && holds_alternative<ExternalFunction>(value.variant())))
122
str += u"{}"; // Обозначаем непустую (определённую) функцию