-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluationcontext.cpp
35 lines (29 loc) · 975 Bytes
/
evaluationcontext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "evaluationcontext.h"
EvaluationContext::EvaluationContext() {
}
EvaluationContext::~EvaluationContext() {
}
const Value* EvaluationContext::getValue(QString identifier) const {
QMap<QString, const Value*>::const_iterator result;
result = symbols.find(identifier);
if (result == symbols.end()) {
throw new RuntimeError("Undefined variable: " + identifier);
}
return result.value();
}
void EvaluationContext::setValue(QString identifier, const Value* value) {
symbols.insert(identifier, value);
emit contextChanged();
}
void EvaluationContext::clear() {
symbols.clear();
}
QString EvaluationContext::toString() const {
QString content;
QMap<QString, const Value*>::const_iterator i;
for (i = symbols.constBegin(); i != symbols.constEnd(); ++i) {
const Value* value = i.value();
content += QString("%1: %2 = %3\n").arg(i.key()).arg(value->type()).arg(value->ast());
}
return content;
}