~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to AspectC++/WeaverBase.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <sstream>
36
36
using std::stringstream;
37
37
using std::endl;
38
 
using std::ends;
39
38
#include <cstring>
40
39
using std::strstr;
41
40
 
82
81
  paste (pos, unit);
83
82
}
84
83
 
 
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;
 
92
  }
 
93
  else {
 
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 ());
 
99
    List marker;
 
100
    marker.append (*start_token);
 
101
    unit->move_before (first, marker);
 
102
    _start_token_map.insert (UnitTokenMap::value_type (unit, start_token));
 
103
  }
 
104
  paste (weave_pos (start_token, WeavePos::WP_BEFORE), str);
 
105
}
 
106
 
 
107
// insert the contents of a generated unit at the end of the translation
 
108
// unit (with move)
 
109
void WeaverBase::paste_end (Unit *unit) {
 
110
  
 
111
  // this is our position ...
 
112
  const WeavePos &pos = weave_pos (_primary_end, WeavePos::WP_AFTER);
 
113
  
 
114
  // return immediately if the there is a problem with macro manipulation
 
115
  if (macro_problem (pos))
 
116
    return;
 
117
    
 
118
  _commander.addBuffer (unit);
 
119
  Token *first = (Token*)unit->first ();
 
120
  Token *last  = (Token*)unit->last ();
 
121
  _commander.move (first, last, pos._token);
 
122
}
 
123
 
 
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
 
127
  if (str == "")
 
128
    return;
 
129
  
 
130
  ACUnit *unit = new ACUnit (_err);
 
131
  bool has_nl = (strstr (str.c_str (), "\n") != NULL);
 
132
  if (has_nl)
 
133
    _line_mgr.directive (*unit);
 
134
  *unit << str.c_str ();
 
135
  if (has_nl)
 
136
    _line_mgr.directive (*unit, (Unit*)_primary_end->belonging_to (), _primary_end);
 
137
  *unit << endu;
 
138
  paste_end (unit);
 
139
}
 
140
 
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))
156
212
    return;
157
213
    
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);
168
224
  kill (from, to);
169
225
}
170
226
 
171
 
bool WeaverBase::commit ()
172
 
 {
173
 
   ManipError terror = _commander.valid ();
174
 
   if (!terror)
175
 
      _commander.commit ();
176
 
   else
177
 
      _err << terror << endMessage;
178
 
   return (bool)terror;
179
 
 }
 
227
bool WeaverBase::commit () {
 
228
  ManipError terror = _commander.valid ();
 
229
  if (!terror)
 
230
    _commander.commit ();
 
231
  else
 
232
    _err << terror << endMessage;
 
233
   
 
234
  // delete the artificially inserted unit start markers that are needed
 
235
  // by paste_first
 
236
  for (UnitTokenMap::iterator i = _start_token_map.begin ();
 
237
    i != _start_token_map.end (); ++i) {
 
238
    i->first->kill (i->second);
 
239
  }
 
240
  return (bool)terror;
 
241
}
180
242
 
181
243
bool WeaverBase::macro_problem (const WeavePos &pos) {
182
244
  Token *token = pos._token;
238
300
 
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 ();
243
305
    
244
306
  // functions that are only friend declarations of an assigned scope
245
307
  CScopeInfo *assigned = obj->AssignedScope ();
283
345
  name << " " << new_name; 
284
346
  if (app >= 0) // append an index to the name?
285
347
    name << app;
286
 
  name << ends;
287
348
 
288
349
  if (arg_name->NodeName () != CT_PrivateName::NodeId ()) {
289
350
    replace (arg_name, name.str ());