~ubuntu-branches/ubuntu/quantal/aspectc++/quantal

« back to all changes in this revision

Viewing changes to AspectC++/MatchName.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:
203
203
  return true;
204
204
}
205
205
 
 
206
bool MatchName::scope_matches (vector<Name> &scopes,
 
207
  vector<MatchTemplateArgList*> &scope_template_args,
 
208
  int match_pos, int sig_pos) {
 
209
 
 
210
  assert (this->scopes () > 0 && this->scopes () > match_pos);
 
211
 
 
212
  Name &name = _scopes[match_pos];
 
213
  MatchTemplateArgList *mtal = _scope_template_args[match_pos];
 
214
  match_pos--;
 
215
  
 
216
  static DString dots ("...");
 
217
  if (name.str () == dots) {
 
218
    // if '...' is the start of the qualified name match expression => match
 
219
    if (match_pos == -1)
 
220
      return true;
 
221
    // handle ellipses (brute force :-( )
 
222
    while (sig_pos >= 0) {
 
223
      if (scope_matches (scopes, scope_template_args, match_pos, sig_pos))
 
224
        return true;
 
225
      sig_pos--;
 
226
    }
 
227
    return false;
 
228
  }
 
229
 
 
230
  // if the argument scope is the global scope it is a mismatch
 
231
  if (sig_pos == -1)
 
232
    return false;
 
233
 
 
234
  // check template arguments of the scope
 
235
  if (mtal) {
 
236
    MatchTemplateArgList *sig_mtal = scope_template_args[sig_pos];
 
237
    if (!sig_mtal || !mtal->matches(*sig_mtal))
 
238
      return false;
 
239
  }
 
240
         
 
241
  // compare the name pattern
 
242
  if (!name.matches (scopes[sig_pos].str ()))
 
243
    return false;
 
244
 
 
245
  sig_pos--;
 
246
  // check the next scope
 
247
  if (match_pos >= 0)
 
248
    return scope_matches (scopes, scope_template_args, match_pos, sig_pos);
 
249
    
 
250
  // no scope to check left, 'scope' must be defined in the global scope
 
251
  if (sig_pos != -1)
 
252
    return false;
 
253
    
 
254
  // everything ok
 
255
  return true;
 
256
}
 
257
 
206
258
bool MatchName::oper_matches (CFunctionInfo *obj) {
207
259
  static DString any ("%");
208
260
  
241
293
  return obj->Name () == obstr[((int)_oper) - 1];
242
294
}
243
295
 
 
296
bool MatchName::oper_matches (Operator oper) {
 
297
  static DString any ("%");
 
298
  
 
299
  // '%' as a function name also matches operators
 
300
  if (!_name.str ().empty ())
 
301
    return _name.str () == any;
 
302
      
 
303
  // only operator signatures are considered
 
304
  if (_oper == OP_UNDEFINED)
 
305
    return false;
 
306
    
 
307
  // any operator
 
308
  if (_oper == OP_ANY)
 
309
    return true;
 
310
 
 
311
  // return true, iff the operator is the same
 
312
  return _oper == oper;
 
313
}
 
314
 
244
315
bool MatchName::conv_matches (CFunctionInfo *obj) {
245
316
  static DString any ("%");
246
317
  
257
328
  return ct && !_conv_type.is_undefined () && _conv_type.matches (ct);
258
329
}
259
330
 
 
331
bool MatchName::conv_matches (MatchTypeRef type) {
 
332
  static DString any ("%");
 
333
  
 
334
  // '%' as a function name also matches operators
 
335
  if (!_name.str ().empty ())
 
336
    return _name.str () == any;
 
337
      
 
338
  // any operator is ok
 
339
  if (_oper == OP_ANY)
 
340
    return true;
 
341
 
 
342
  // check the conversion type of the function (if it is a conversion function)
 
343
  return !type.is_undefined () && !_conv_type.is_undefined () &&
 
344
    _conv_type.matches (type);
 
345
}
 
346
 
260
347
bool MatchName::name_matches (CObjectInfo *obj) {
261
348
  if (_name_template_args) {
262
349
    CTemplateInstance *instance = obj->TemplateInstance ();
266
353
  return _name.matches (obj->Name ());
267
354
}
268
355
 
 
356
bool MatchName::name_matches (Name &name,
 
357
  MatchTemplateArgList *name_template_args) {
 
358
  if (_name_template_args) {
 
359
    if (!name_template_args ||
 
360
        !_name_template_args->matches (*name_template_args))
 
361
      return false;
 
362
  }
 
363
  return _name.matches (name.str ());
 
364
}
 
365
 
269
366
bool MatchName::matches (CObjectInfo *obj) {
270
367
  // if the match name contains a scope check it first
271
368
  CScopeInfo *obj_scope = nscope (obj);
291
388
    return false;
292
389
}
293
390
 
 
391
bool MatchName::matches (MatchName &matched_name) {
 
392
  // if the matched name is not defined in the global scope and the match
 
393
  // name has no scopes, it is no match
 
394
  if (scopes () == 0 && matched_name.scopes () > 0)
 
395
    return false;
 
396
 
 
397
  // if the match name has a scope, compare it
 
398
  if (scopes () > 0 && !scope_matches (matched_name._scopes,
 
399
    matched_name._scope_template_args,
 
400
    scopes () - 1, matched_name.scopes () - 1))
 
401
    return false;
 
402
    
 
403
  if (matched_name.oper () != OP_UNDEFINED) {
 
404
    // this an operator name match expression
 
405
    return oper_matches (matched_name.oper ());
 
406
  }
 
407
  else if (!matched_name.conv_type ().is_undefined ()) {
 
408
    // this is a conversion operator match expression
 
409
    return conv_matches (matched_name.conv_type ());
 
410
  }
 
411
  else if (_oper == OP_UNDEFINED && _conv_type.is_undefined ()) {
 
412
    // normal name
 
413
    return name_matches (matched_name._name, matched_name._name_template_args);
 
414
  }
 
415
  else
 
416
    return false;
 
417
}
 
418