-
Notifications
You must be signed in to change notification settings - Fork 3
/
macro.cpp
204 lines (157 loc) · 3.6 KB
/
macro.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// macro.cpp
// Revision 23-jan-2006
#include "macro.h"
#include "trace.h"
#include <algorithm>
#include <stdexcept>
namespace pasmo {
namespace impl {
using std::transform;
using std::runtime_error;
namespace {
vector <string> normalizeparam (const vector <string> & param)
{
vector <string> result;
transform (param.begin (), param.end (),
back_inserter (result), stripdollar);
return result;
}
class Expected : public runtime_error {
public:
#if 0
Expected (const Token & tokexp, const Token & tokfound) :
runtime_error ("'" + tokexp.str () + "' expected but '" +
tokfound.str () + "' found")
{ }
Expected (const string & expected, const Token & tok) :
runtime_error (expected + " expected but '" +
tok.str () + "' found")
{ }
#endif
Expected (const string & expected, const string & found) :
runtime_error (expected + " expected but '" +
found + "' found")
{ }
};
class MacroExpected : public Expected {
public:
MacroExpected (const string & name) :
Expected ("Macro name", name)
{ }
};
} // namespace
MacroBase::MacroBase ()
{
TRFUNC (tr, "MacroBase::MacroBase");
}
MacroBase::MacroBase (const vector <string> & param) :
param (normalizeparam (param) )
{
TRFUNC (tr, "MacroBase::MacroBase");
}
MacroBase::MacroBase (const string & sparam) :
param (1)
{
TRFUNC (tr, "MacroBase::MacroBase");
TRMESSAGE (tr, sparam);
param [0]= stripdollar (sparam);
}
MacroBase::~MacroBase ()
{
TRFUNC (tr, "MacroBase::~MacroBase");
}
size_t MacroBase::getparam (const string & name) const
{
const string normname= stripdollar (name);
for (size_t i= 0; i < param.size (); ++i)
if (normname == param [i])
return i;
return noparam;
}
string MacroBase::getparam (size_t n) const
{
if (n >= param.size () )
return "(none)";
return param [n];
}
Macro::Macro (const vector <string> & param,
size_t linen, size_t endlinen) :
MacroBase (param),
line (linen),
endline (endlinen)
{ }
Macro::~Macro ()
{
TRFUNC (tr, "Macro::~Macro");
}
size_t Macro::getline () const
{ return line; }
size_t Macro::getendline () const
{ return endline; }
MacroIRPbase::MacroIRPbase (const string & sparam) :
MacroBase (sparam)
{ }
MacroIRP::MacroIRP (const string & sparam) :
MacroIRPbase (sparam)
{ }
MacroIRPC::MacroIRPC (const string & sparam) :
MacroIRPbase (sparam)
{ }
MacroREPT::MacroREPT (const string & sparam) :
MacroBase (sparam)
{ }
void MapMacro::clear ()
{
mapmacro.clear ();
}
void MapMacro::erase (const string & name)
{
mapmacro_t::iterator it= mapmacro.find (name);
if (it != mapmacro.end () )
mapmacro.erase (it);
}
void MapMacro::insert (const string & name,
const vector <string> & param,
size_t beginline, size_t endline)
{
erase (name);
mapmacro.insert (make_pair (stripdollar (name),
Macro (param, beginline, endline) ) );
}
MapMacro::const_iterator MapMacro::begin () const
{
return mapmacro.begin ();
}
MapMacro::const_iterator MapMacro::end () const
{
return mapmacro.end ();
}
MapMacro::const_iterator MapMacro::find (const string & name) const
{
return mapmacro.find (stripdollar (name) );
}
void MacroStore::clear ()
{
mapmacro.clear ();
}
const Macro & MacroStore::getmacro (const string & name)
{
MapMacro::const_iterator it= mapmacro.find (name);
if (it == mapmacro.end () )
throw MacroExpected (name);
else
return it->second;
}
bool MacroStore::ismacro (const string & name) const
{
return mapmacro.find (name) != mapmacro.end ();
}
void MacroStore::insert (const string & name,
const vector <string> & param,
size_t beginline, size_t endline)
{
mapmacro.insert (name, param, beginline, endline);
}
} // namespace impl
} // namespace pasmo
// End of macro.cpp