swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 1 | #include "VarContext.h" |
| 2 | |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 3 | void VarContext::add(char t, const QString &name, const Token &value) { |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 4 | _vars.insert(name, Var{t, value}); |
| 5 | } |
| 6 | |
| 7 | char VarContext::exists(const QString &name) { |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 8 | return _vars.contains(name) ? _vars[name].t : 0; |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 9 | } |
| 10 | |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 11 | Token VarContext::singleVar(const QString &name) { |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 12 | return _vars[name].value; |
| 13 | } |
| 14 | |
| 15 | VarContext::VarContext(const VarContext &other) noexcept { |
| 16 | _vars = other._vars; |
| 17 | } |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 18 | |
| 19 | void VarContext::add(char t, const QString &name, const QList<Token> &value) { |
| 20 | _vars.insert(name,Var{t,{},value}); |
| 21 | } |
| 22 | |
| 23 | QList<Token> VarContext::expressionVar(const QString &name) { |
| 24 | return _vars[name].expressionValue; |
| 25 | } |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 26 | |
| 27 | QDebug &operator <<(QDebug &debug, const VarContext &ctx) { |
| 28 | for (const auto &name: ctx._vars.keys()) { |
| 29 | char t = ctx._vars[name].t; |
| 30 | auto d = debug.nospace().noquote() << t << '.' << name << ":"; |
| 31 | |
| 32 | if (t != 'e') |
| 33 | d.nospace() << "( " << ctx._vars[name].value << " )"; |
| 34 | else |
| 35 | d << "( " << ctx._vars[name].expressionValue << " )"; |
| 36 | d << "; "; |
| 37 | } |
| 38 | |
| 39 | if (ctx._vars.empty()) { |
| 40 | debug << "{}"; |
| 41 | } |
| 42 | |
| 43 | return debug; |
| 44 | } |