84
// insert a generated string at the beginning of a unit
85
// The implementation makes sure that all pasted tokens will appear after the
86
// transformation in front of tokens that were pasted ahead of the first token
87
void WeaverBase::paste_first (Unit *unit, const string &str) {
88
UnitTokenMap::iterator i = _start_token_map.find (unit);
89
Token *start_token = 0;
90
if (i != _start_token_map.end ()) {
91
start_token = i->second;
94
start_token = new Token; // just a marker token without text etc.
95
Token *first = (Token*)unit->first ();
96
if (unit == (Unit*)_primary_start->belonging_to ())
97
first = _primary_start;
98
start_token->location (first->location ());
100
marker.append (*start_token);
101
unit->move_before (first, marker);
102
_start_token_map.insert (UnitTokenMap::value_type (unit, start_token));
104
paste (weave_pos (start_token, WeavePos::WP_BEFORE), str);
107
// insert the contents of a generated unit at the end of the translation
109
void WeaverBase::paste_end (Unit *unit) {
111
// this is our position ...
112
const WeavePos &pos = weave_pos (_primary_end, WeavePos::WP_AFTER);
114
// return immediately if the there is a problem with macro manipulation
115
if (macro_problem (pos))
118
_commander.addBuffer (unit);
119
Token *first = (Token*)unit->first ();
120
Token *last = (Token*)unit->last ();
121
_commander.move (first, last, pos._token);
124
// insert a generated string at the end of the translation unit (with move)
125
void WeaverBase::paste_end (const string &str) {
126
// return immediately if the string to paste is empty
130
ACUnit *unit = new ACUnit (_err);
131
bool has_nl = (strstr (str.c_str (), "\n") != NULL);
133
_line_mgr.directive (*unit);
134
*unit << str.c_str ();
136
_line_mgr.directive (*unit, (Unit*)_primary_end->belonging_to (), _primary_end);
85
141
// replace the text between two positions with some new text
86
142
void WeaverBase::replace (const WeavePos &from, const WeavePos &to,
87
143
const string &str) {
155
211
if (macro_problem (from) || macro_problem (to))
158
bool has_nl = (strstr (from._token->text ().c_str (), "\n") != NULL);
214
bool has_nl = (strstr (from._token->text (), "\n") != NULL);
159
215
if (to._token && from._token != to._token || has_nl)
160
216
_line_mgr.insert ((Unit*)to._token->belonging_to (), to._token, true);
161
217
_commander.kill (from._token, to._token);
171
bool WeaverBase::commit ()
173
ManipError terror = _commander.valid ();
175
_commander.commit ();
177
_err << terror << endMessage;
227
bool WeaverBase::commit () {
228
ManipError terror = _commander.valid ();
230
_commander.commit ();
232
_err << terror << endMessage;
234
// delete the artificially inserted unit start markers that are needed
236
for (UnitTokenMap::iterator i = _start_token_map.begin ();
237
i != _start_token_map.end (); ++i) {
238
i->first->kill (i->second);
181
243
bool WeaverBase::macro_problem (const WeavePos &pos) {
182
244
Token *token = pos._token;
239
301
CScopeInfo *WeaverBase::nscope(CObjectInfo *obj) {
240
302
// template instances are stored in a special scope, better take the template
241
if (obj->TemplateInstance ())
242
obj = obj->TemplateInstance ()->Template ();
303
// if (obj->TemplateInstance ())
304
// obj = obj->TemplateInstance ()->Template ();
244
306
// functions that are only friend declarations of an assigned scope
245
307
CScopeInfo *assigned = obj->AssignedScope ();