-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenviroment.cpp
executable file
·93 lines (93 loc) · 2.01 KB
/
enviroment.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "enviroment.h"
void enviroment::insert(routine_head * tmp){
q.push_back(tmp);
}
routine_head * enviroment::top(){
return q.back();
}
void enviroment::pop(){
q.pop_back();
}
shared_ptr <enviroment> enviroment::single(){
static bool flag = false;
static shared_ptr <enviroment> res;
if(flag)
return res;
res.reset(new enviroment());
flag = true;
return res;
}
pair<int, int> enviroment::search(const string &id){
int l = q.size();
int off = 0;
for(int i = l - 1; i >= 0; --i){
auto res = q[i] -> v_r -> search(id);
if(res.second == -1){
off += res.first;
continue;
}
else{
off += res.first;
return make_pair(off, res.second);
}
}
return make_pair(off, -1);
}
pair<int, int> enviroment::search(const string & id, int index){
int l = q.size();
int off = 0;
for(int i = l - 1; i >= 0; --i){
auto res = q[i] -> v_r -> search(id, index);
if(res.second == -1){
off += res.first;
continue;
}
else{
off += res.first;
return make_pair(off, res.second);
}
}
return make_pair(off, -1);
}
pair<int, int> enviroment::search(const string & id, const string & member){
int l = q.size();
int off = 0;
for(int i = l - 1; i >= 0; --i){
auto res = q[i] -> v_r -> search(id, member);
if(res.second == -1){
off += res.first;
continue;
}
else{
off += res.first;
return make_pair(off, res.second);
}
}
return make_pair(off, -1);
}
pair <shared_ptr <routine>, int> enviroment::searchfunc(const string & id){
int l = q.size();
int off = 0;
for(int i = l - 1; i >= 0; --i){
for(int j = 0; j < q[i] -> r_r -> vt.size(); ++j){
if(q[i] -> r_r -> vt[j] -> name == id){
return make_pair(q[i] -> r_r -> vt[j], off);
}
}
off += q[i] -> v_r -> getsize();
}
return make_pair(nullptr, -1);
}
void enviroment::clear(){
q.clear();
}
key_value_tuple enviroment::searchconst(const string & id){
int l = q.size();
key_value_tuple res;
for(int i = l - 1; i >= 0; --i){
res = q[i] -> c_r -> const_replace(id);
if(res.first != nullptr)
return res;
}
return res;
}