-
Notifications
You must be signed in to change notification settings - Fork 3
/
local.cpp
155 lines (116 loc) · 2.26 KB
/
local.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// local.cpp
// Revision 10-jan-2007
#include "local.h"
#include "asmreal.h"
#include "trace.h"
namespace pasmo
{
namespace impl
{
pasmo_fatal LocalNotExist ("Trying to use a non existent local level");
LocalLevel::LocalLevel (AsmReal & asmin_n) :
asmin (asmin_n)
{ }
LocalLevel::~LocalLevel ()
{
TRFUNC (tr, "LocalLevel::~LocalLevel");
for (mapvar_t::iterator it= saved.begin ();
it != saved.end ();
++it)
{
const string locname= it->first;
const string & globname= globalized [locname];
Defined d= asmin.defvar (locname);
if (d == NoDefined)
{
asmin.emitwarning ("LOCAL " + locname +
" is not used");
}
asmin.setvar (globname, locname);
asmin.setvar (locname, it->second);
}
}
bool LocalLevel::is_auto () const
{
return false;
}
void LocalLevel::add (const string & varname)
{
// Ignore redeclarations as LOCAL of the same identifier.
if (saved.hasvar (varname) )
return;
saved.set (varname, asmin.rawgetvar (varname) );
const string globname= asmin.genlocalname (varname);
globalized [varname]= globname;
switch (asmin.currentpass () )
{
case 1:
asmin.setvar (varname, VarData (true) );
break;
case 2:
asmin.setvar (varname, globname);
break;
default:
throw InvalidPassValue;
}
}
AutoLevel::AutoLevel (AsmReal & asmin_n) :
LocalLevel (asmin_n)
{ }
AutoLevel::~AutoLevel ()
{
TRFUNC (tr, "AutoLevel::~AutoLevel");
}
bool AutoLevel::is_auto () const
{
return true;
}
ProcLevel::ProcLevel (AsmReal & asmin_n, size_t line) :
LocalLevel (asmin_n),
line (line)
{ }
ProcLevel::~ProcLevel ()
{
TRFUNC (tr, "ProcLevel::~ProcLevel");
}
size_t ProcLevel::getline () const
{
return line;
}
MacroLevel::MacroLevel (AsmReal & asmin_n) :
LocalLevel (asmin_n)
{ }
MacroLevel::~MacroLevel ()
{
TRFUNC (tr, "MacroLevel::~MacroLevel");
}
LocalStack::~LocalStack ()
{
TRFUNC (tr, "LocalStack::~LocalStack");
while (! st.empty () )
pop ();
}
bool LocalStack::empty () const
{
return st.empty ();
}
void LocalStack::push (LocalLevel * level)
{
st.push (level);
}
LocalLevel * LocalStack::top () const
{
if (st.empty () )
throw LocalNotExist;
return st.top ();
}
void LocalStack::pop ()
{
if (st.empty () )
throw LocalNotExist;
delete st.top ();
st.pop ();
}
} // namespace impl
} // namespace pasmo
// End of local.cpp