-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathScopeUtil.cpp
49 lines (38 loc) · 1.04 KB
/
ScopeUtil.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
/*
* ScopeUtil.cpp
*
* Created on: Oct 29, 2020
* Author: ballance
*/
#include "ScopeUtil.h"
namespace pssp {
ScopeUtil::ScopeUtil() {
// TODO Auto-generated constructor stub
}
ScopeUtil::~ScopeUtil() {
// TODO Auto-generated destructor stub
}
ast::INamedScopeChild *ScopeUtil::findChild(ast::IScope *s, const std::string &name) {
std::map<std::string,ast::INamedScopeChild *>::iterator it;
if ((it=s->getSymtab().find(name)) != s->getSymtab().end()) {
return it->second;
} else {
return 0;
}
}
bool ScopeUtil::addChild(ast::IScope *s, ast::INamedScopeChild *c) {
std::map<std::string,ast::INamedScopeChild*>::iterator it;
if ((it=s->getSymtab().find(c->getName()->getId())) == s->getSymtab().end()) {
s->getChildren().push_back(ast::IScopeChildUP(c));
s->getSymtab().insert({c->getName()->getId(), c});
c->setParent(s);
return true;
} else {
return false;
}
}
void ScopeUtil::addChild(ast::IScope *s, ast::IScopeChild *c) {
s->getChildren().push_back(ast::IScopeChildUP(c));
c->setParent(s);
}
} /* namespace pssp */