forked from NesManrique/LenguajesII
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintsymtable.cpp
73 lines (60 loc) · 1.75 KB
/
printsymtable.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
#include "blahsymtable.h"
void Tuple::print(std::ostream& os,int depth)const {
os<<std::string(2*depth,' ')<<"("<<id<<","<<scope<<")";
}
void TType::print(std::ostream& os,int depth){
os<<std::string(2*depth,' ')<<name<<": size="<<size<<std::endl;
}
void TStructured::print(std::ostream& os,int depth){
os<<std::string(2*depth,' ')<<name<<": size="<<size<<" fields={"<<std::endl;
std::unordered_map<std::string,TVar*>::iterator it;
for(it=fields.begin();it!=fields.end();it++){
it->second->print(os,depth+1);
}
os<<std::string(2*depth,' ')<<"}"<<std::endl;
}
void TVar::print(std::ostream& os,int depth){
os<<std::string(2*depth,' ')<<name<<" type="<<type.name<<" offset="<<offset<<std::endl;
}
std::string TFunc::toStr(){
std::string str= name;
for(int i=0; i<args.size(); i++){
str += args[i]->name;
}
return str;
}
void TFunc::print(std::ostream& os, int depth){
os<<std::string(2*depth,' ')<<name<<" returntype="<<type.name;
os<<" argtypes=(";
for(int i=0;i<args.size();i++){
os<<args[i]->name<<",";
}
os<<")"<<std::endl;
}
void Symtable::printVars(std::ostream& os){
os<<"-VARIABLES-"<<std::endl;
std::unordered_map<Tuple,TVar*>::iterator it;
for(it=vars.begin();it!=vars.end();it++){
it->first.print(os,1);
it->second->print(os,1);
}
}
void Symtable::printFuncs(std::ostream& os){
os<<"-FUNCTIONS-"<<std::endl;
std::unordered_map<std::string,TFunc*>::iterator it;
for(it=functions.begin();it!=functions.end();it++){
it->second->print(os,1);
}
}
void Symtable::printTypes(std::ostream& os){
os<<"-TYPES-"<<std::endl;
std::unordered_map<std::string,TType*>::iterator it;
for(it=types.begin();it!=types.end();it++){
it->second->print(os,1);
}
}
void Symtable::print(std::ostream& os){
printTypes(os);
printVars(os);
printFuncs(os);
}