loom
1/*
2MIT License
3
4Copyright (c) 2022 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
5
6https://bmstu.codes/lsx/simodo/loom
7*/
8
9#include "simodo/variable/Variable.h"
10
11#include <cassert>
12
13namespace simodo::variable
14{
15const Variable & Variable::origin() const
16{
17if (type() != ValueType::Ref)
18return *this;
19
20const Variable & o = _value.getRef().origin();
21
22assert(o.type() != ValueType::Ref);
23
24return o;
25}
26
27Variable & Variable::origin()
28{
29if (type() != ValueType::Ref)
30return *this;
31
32Variable & o = _value.getRef().origin();
33
34assert(o.type() != ValueType::Ref);
35
36return o;
37}
38
39Variable Variable::copyVariable() const
40{
41Specification spec;
42
43if (!_spec.isNull())
44spec.clone(_spec);
45
46return { _name, _value.copy(), _location, spec };
47}
48
49VariableRef Variable::makeReference() const
50{
51if (type() == ValueType::Ref)
52return std::get<VariableRef>(variant());
53
54return VariableRef {*this};
55}
56
57}
58