-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime_variables.h
71 lines (47 loc) · 1.48 KB
/
runtime_variables.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
namespace basically::runtime::variables
{
struct Info
{
std::string name;
typing::TypeRef type;
ast::OptionalExpression initializer;
size_t array_count;
bool is_const;
typing::Visibility visibility;
Info(std::string const& new_name,
std::string const& new_type_name,
size_t new_array_count,
bool new_is_const);
Info(ast::VariableDeclarationStatementPtr const& declaration);
bool is_array() const noexcept;
size_t size() const noexcept;
};
using InfoPtr = std::shared_ptr<Info>;
using InfoMap = std::unordered_map<std::string, InfoPtr>;
using InfoList = std::vector<InfoPtr>;
class Scope;
using ScopePtr = std::shared_ptr<Scope>;
class Scope
{
public:
ScopePtr parent;
InfoMap variables;
public:
Scope() = default;
Scope(ScopePtr& parent);
Scope(Scope const& scope) = default;
Scope(Scope&& scope) = default;
~Scope() = default;
public:
Scope& operator =(Scope const& scope) = default;
Scope& operator =(Scope&& scope) = default;
public:
InfoPtr find(std::string const& name) const noexcept;
void insert(InfoPtr const& variable);
};
inline ScopePtr make_scope(ScopePtr parent = {})
{
return std::make_shared<Scope>(parent);
}
}