blob: f444faab76cb90139fffb886a6c8bd9fe2f91b4e [file] [log] [blame]
swissChili7babd922021-12-02 22:46:48 -08001#include "VarContext.h"
2
swissChili3e98c062021-12-04 22:07:38 -08003void VarContext::add(char t, const QString &name, const Token &value) {
swissChilia44bf722022-04-16 18:41:54 -07004 _vars.insert(name, Var{t, value, {}});
swissChili7babd922021-12-02 22:46:48 -08005}
6
7char VarContext::exists(const QString &name) {
swissChili3e98c062021-12-04 22:07:38 -08008 return _vars.contains(name) ? _vars[name].t : 0;
swissChili7babd922021-12-02 22:46:48 -08009}
10
swissChili3e98c062021-12-04 22:07:38 -080011Token VarContext::singleVar(const QString &name) {
swissChili7babd922021-12-02 22:46:48 -080012 return _vars[name].value;
13}
14
15VarContext::VarContext(const VarContext &other) noexcept {
16 _vars = other._vars;
17}
swissChili3e98c062021-12-04 22:07:38 -080018
19void VarContext::add(char t, const QString &name, const QList<Token> &value) {
20 _vars.insert(name,Var{t,{},value});
21}
22
23QList<Token> VarContext::expressionVar(const QString &name) {
24 return _vars[name].expressionValue;
25}
swissChilid17b5a12021-12-05 20:46:42 -080026
27QDebug &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}