-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scope.h
35 lines (28 loc) · 1.1 KB
/
Scope.h
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
#ifndef WTIIINTERPRETER_SCOPE_H
#define WTIIINTERPRETER_SCOPE_H
#include <map>
#include <string>
#include "ParsedScripts/ClassDefinition.h"
#include "ParsedScripts/Statements/MethodDefinitiionStatement.h"
class Scope {
public:
std::map<std::string, std::pair<std::string, Value*>> Variables;
std::map<std::string, MethodDefinitionStatement*> Functions;
std::map<std::string, ClassDefinition*> Classes;
Scope() = default;
Scope(const Scope& parent) {
Variables = parent.Variables;
Functions = parent.Functions;
Classes = parent.Classes;
}
void AppendScope(Scope* scope) {
Variables.insert(scope->Variables.begin(), scope->Variables.end());
Functions.insert(scope->Functions.begin(), scope->Functions.end());
Classes.insert(scope->Classes.begin(), scope->Classes.end());
}
void SetVariable(const std::string& name, Value* value) {
if (Variables.find(name) != Variables.end()) Variables[name] = {Variables[name].first, value};
else Variables.insert({name, {value->ObjectType, value}});
}
};
#endif //WTIIINTERPRETER_SCOPE_H