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

« back to all changes in this revision

Viewing changes to AspectC++/JoinPointLoc.h

  • 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:
19
19
#ifndef __join_point_loc_h__
20
20
#define __join_point_loc_h__
21
21
 
22
 
#include <ostream>
 
22
#include <vector>
 
23
using std::vector;
 
24
#include <list>
 
25
using std::list;
 
26
#include <set>
 
27
using std::set;
 
28
#include <map>
 
29
using std::map;
23
30
#include <string>
24
 
using std::ostream;
25
31
using std::string;
26
 
using std::endl;
27
 
using std::ends;
28
 
#include <map>
29
 
using std::map;
30
 
#include <vector>
31
 
using std::vector;
32
 
 
33
 
#include "Puma/Signature.h"
34
 
#include "Puma/DString.h"
35
 
#include "Puma/CRecord.h"
36
 
#include "Puma/CAttributeInfo.h"
37
 
#include "Puma/CClassInfo.h"
38
 
#include "Puma/ACAspectInfo.h"
39
 
#include "Puma/CFunctionInfo.h"
40
 
#include "Puma/CTree.h"
41
 
#include "Puma/Filter.h"
42
 
using namespace Puma;
43
 
 
44
 
#include "MatchName.h"
 
32
 
 
33
#include "Puma/Unit.h"
 
34
 
 
35
#include "MatchExpr.h"
 
36
#include "SourceLoc.h"
 
37
#include "RepoXMLNode.h"
 
38
#include "JoinPointModelElement.h"
45
39
 
46
40
namespace Puma {
47
 
  class CTypeInfo;
48
 
  class Unit;
49
 
} // namespace Puma
 
41
  class CTree; // pointcuts are currently represented as a CTree
 
42
}
50
43
 
 
44
class ModelTransformInfo {
 
45
public:
 
46
  virtual ~ModelTransformInfo () {}
 
47
};
51
48
class JoinPointPlan;
52
49
 
53
 
class JoinPointLoc {
54
 
 
 
50
 
 
51
// forward declaration (for cyclic relations)
 
52
class JPL_Name;
 
53
class JPL_AdviceCode;
 
54
class JPL_Introduction;
 
55
class JPL_Order;
 
56
 
 
57
/**
 
58
 * \class JoinPointLoc
 
59
 * \brief the common base class of all join point location types
 
60
 * 
 
61
 * The class contains elements to store join point locations in a hierarchical
 
62
 * structure, associated source locations, etc.
 
63
 * In order to associate a weaving plan and parser-specific syntax information
 
64
 * two (almost) untyped pointers are included. They can be used by higher
 
65
 * layer.
 
66
 */
 
67
 
 
68
class JoinPointLoc : public JoinPointModelElement {
55
69
public:
56
70
  enum join_point_type {
57
 
    None            = 0x0000,
58
 
    FieldReference  = 0x0001,
59
 
    FieldAssignment = 0x0002,
60
 
    MethodCall      = 0x0004,
61
 
    Method          = 0x0008,
62
 
    Construction    = 0x0010,
63
 
    Destruction     = 0x0020,
64
 
    Code            = 0x003f,
65
 
    Class           = 0x0100,
66
 
    Aspect          = 0x0200,
67
 
    Function        = 0x0400,
68
 
    Type            = 0x0800,
69
 
    Name            = 0x0f00,
70
 
    Any             = 0x0f3f
 
71
    None            = 0x000000,
 
72
    FieldReference  = 0x000001,
 
73
    FieldAssignment = 0x000002,
 
74
    MethodCall      = 0x000004,
 
75
    Method          = 0x000008,
 
76
    Construction    = 0x000010,
 
77
    Destruction     = 0x000020,
 
78
    Code            = 0x00003f,
 
79
    Class           = 0x000100,
 
80
    Aspect          = 0x000200,
 
81
    Function        = 0x000400,
 
82
    Type            = 0x000800,
 
83
    Namespace       = 0x001000,
 
84
    AdviceCode      = 0x002000,
 
85
    ClassSlice      = 0x004000,
 
86
    Name            = 0x007f00,
 
87
    Any             = 0x007f3f,
 
88
    Introduction    = 0x008000,
 
89
    Order           = 0x010000,
 
90
    Advice          = 0x018000
71
91
  };
72
92
 
73
93
protected:
74
94
  
75
 
  string _sig;            // the signature of this jp as a string
76
 
  int _lid;               // local id for this jp inside the current function
77
 
  JoinPointPlan *_plan;   // the weaving plan for advised jps
78
 
  int _id;                // a unique id for each joinpoint location
79
 
 
80
 
  void signature (ostream &, CFunctionInfo *func_info);
81
 
  void signature (ostream &, CAttributeInfo *func_info);
82
 
  void signature (ostream &, CTypeInfo *type_info);
 
95
  /// parent in the hierarchical join point model structure
 
96
  JPL_Name *_parent;
 
97
  /// source code location(s) of this join point (shadow)
 
98
  set<SourceLoc> _source_locs;
 
99
  /// the signature of this jp as a string
 
100
  string _sig;
 
101
  /// the weaving plan for advised jps
 
102
  JoinPointPlan *_plan;
 
103
  /// parser-provided info for code transformation
 
104
  ModelTransformInfo *_trans;
 
105
  /// translation units in which this element was detected
 
106
  IdSet _tunits;
83
107
  
84
108
 public:
85
109
 
86
 
  JoinPointLoc () : _lid (0), _plan (0), _id (-1) {}
87
 
  virtual ~JoinPointLoc () {}
88
 
 
89
 
  const char *signature () { return _sig.c_str (); }
90
 
  int lid () const { return _lid; }
 
110
  JoinPointLoc () : _parent (0), _plan (0), _trans (0) {}
 
111
  JoinPointLoc (const JoinPointLoc &jpl) : _parent (0), _plan (0), _trans (0) {
 
112
    _sig = jpl._sig;
 
113
  }
 
114
  JoinPointLoc (RepoXMLNode jn, RepoXMLNode::iter &curr);
 
115
  virtual ~JoinPointLoc () { if (_trans) delete _trans; }
 
116
 
 
117
  void parent (JPL_Name *p);
 
118
  JPL_Name *parent () const { return _parent; }
 
119
 
 
120
  const IdSet &tunits () const { return _tunits; }
 
121
  IdSet &tunits () { return _tunits; }
 
122
  virtual const char *signature () const { return _sig.c_str (); }
 
123
  string filename () const;
 
124
  int line () const;
 
125
  typedef const set<SourceLoc> SSet;
 
126
  const set<SourceLoc> &source_locs () const { return _source_locs; }
 
127
  set<SourceLoc> &source_locs () { return _source_locs; }
 
128
  void source_loc (const SourceLoc &sl) { _source_locs.insert (sl); }
91
129
  JoinPointPlan *plan () const { return _plan; }
92
130
  void plan (JoinPointPlan *p) { _plan = p; }
93
 
  int line () const;
94
 
  int lines () const;
95
 
  Unit *unit () const;
96
 
  int id () const { return _id; }
97
 
  void id (int new_id) { _id = new_id; }
 
131
  ModelTransformInfo *transform_info () const { return _trans; }
 
132
  void transform_info (ModelTransformInfo *trans) { _trans = trans; }
98
133
 
99
 
  virtual join_point_type type () { return None; }
 
134
  virtual join_point_type type () const { return None; }
100
135
  virtual const char *type_str () const { return (const char*)0; }
101
 
  virtual CTree *tree () const { return 0; }
102
 
  virtual CObjectInfo *assoc_obj () { return 0; }
103
 
  virtual Token *insertloc_tjp_struct() { return 0; }
104
 
  virtual Token *insertloc_before () { return 0; }
105
 
  virtual Token *insertloc_after () { return 0; }
106
 
  virtual CFunctionInfo *tjp_type() {return 0;}
107
 
  virtual CFunctionInfo *tjp_target() {return 0;}
108
 
  virtual CFunctionInfo *tjp_that() {return 0;}
109
 
  virtual CFunctionInfo *action_dst_func() {return 0;}
110
 
  virtual CFunctionInfo *action_src_func() {return 0;}
 
136
 
 
137
  bool operator == (const JoinPointLoc &right) const {
 
138
    return type () == right.type () && _sig == right._sig;
 
139
  }
 
140
  bool operator != (const JoinPointLoc &right) const {
 
141
    return !(*this == right);
 
142
  }
 
143
 
 
144
  virtual void dump (int indent = 0) const;
 
145
 
 
146
  virtual RepoXMLNode make_xml (RepoXMLNode parent) const;
 
147
  
 
148
  /// create a join point loc tree from an XML document subtree
 
149
  static JoinPointLoc *create (RepoXMLNode node);
 
150
  static IdElementMap *_map;
 
151
  
 
152
  /// check whether this join point is seen by a specific tranlation unit
 
153
  virtual bool is_known_in_tunit (File *tunit);
 
154
};
 
155
 
 
156
class JPL_Type : public JoinPointLoc {
 
157
protected:
 
158
  mutable MatchSignature _match_sig; // calculated on demand
 
159
  void parse_match_signature () const {
 
160
    Location l;
 
161
    ErrorStream e (cerr);
 
162
    _match_sig.parse (e, l, signature ());
 
163
  }
 
164
public:
 
165
  JPL_Type (const string &sig) { _sig = sig; }
 
166
  join_point_type type () const { return Type; }
 
167
  virtual const char *type_str () const { return "type"; }
 
168
  const MatchSignature &match_signature () const {
 
169
    if (_match_sig.is_new ())
 
170
      parse_match_signature ();
 
171
    return _match_sig;
 
172
  }
111
173
};
112
174
 
113
175
class JPL_Name : public JoinPointLoc {
114
 
 
115
 
  CTypeInfo *_ctype;
116
 
protected:    
117
 
  JPL_Name (CTypeInfo *t) : _ctype (t) {}
118
 
  virtual ~JPL_Name () {}
119
 
  
120
 
public:
121
 
  CTypeInfo *type_info () const { return _ctype; }
122
 
  virtual CObjectInfo *obj_info () = 0;
 
176
public:
 
177
  typedef list<const JoinPointLoc*> CList;
 
178
 
 
179
private:
 
180
  typedef std::map<string, JPL_Name*> NameMap;
 
181
  NameMap _name_map;
 
182
  CList _children;
 
183
  string _name;
 
184
  bool _is_built_in;
 
185
 
 
186
protected:
 
187
  mutable MatchSignature _match_sig; // calculated on demand
 
188
  virtual void parse_match_signature () const {
 
189
    Location l ("<no filename>", 0);
 
190
    ErrorStream e (cerr);
 
191
    _match_sig.parse (e, l, signature ());
 
192
  }
 
193
 
 
194
public:
 
195
  JPL_Name () : _is_built_in (false) {}
 
196
  JPL_Name (const JPL_Name &jpl) : JoinPointLoc (jpl), _name (jpl._name),
 
197
    _is_built_in (jpl._is_built_in) {}
 
198
  JPL_Name (RepoXMLNode node, RepoXMLNode::iter &curr);
 
199
  const CList &children () const { return _children; }
 
200
  void add_child (JoinPointLoc *child) {
 
201
    _children.push_back (child);
 
202
    if (child->type () & JoinPointLoc::Name) {
 
203
      _name_map.insert (NameMap::value_type (child->signature (),
 
204
        (JPL_Name*)child));
 
205
    }
 
206
  }
 
207
  void remove_child (const JoinPointLoc *child) {
 
208
    _children.remove (child);
 
209
    _name_map.erase (child->signature ());
 
210
  }
 
211
  void name (const string &name) { _name = name; }
 
212
  const string &name () const { return _name; }
 
213
  virtual void dump (int indent = 0) const;
 
214
  virtual RepoXMLNode make_xml (RepoXMLNode parent) const;
 
215
  bool is_root () const { return _sig == "::"; }
 
216
  bool is_built_in () const { return _is_built_in; }
 
217
  void is_built_in (bool b) { _is_built_in = b; }
 
218
  const MatchSignature &match_signature () const {
 
219
    if (_match_sig.is_new ())
 
220
      parse_match_signature ();
 
221
    return _match_sig;
 
222
  }
 
223
  JPL_Name *lookup (const string &name) {
 
224
    NameMap::const_iterator i = _name_map.find (name);
 
225
    return (i == _name_map.end ()) ? 0 : i->second;
 
226
  } 
 
227
};
 
228
 
 
229
class JPL_Namespace : public JPL_Name {
 
230
public:
 
231
  JPL_Namespace (const string &name) { _sig = name; }
 
232
  JPL_Namespace (const JPL_Namespace &jpl) : JPL_Name (jpl) {}
 
233
  JPL_Namespace (RepoXMLNode node, RepoXMLNode::iter &curr);
 
234
  join_point_type type () const { return Namespace; }
 
235
  virtual const char *type_str () const { return "namespace"; }
123
236
};
124
237
 
125
238
class JPL_Class : public JPL_Name {
126
 
  CClassInfo *class_obj;
127
 
  CObjectInfo *link_once_object (CClassInfo *);
 
239
protected:
 
240
  bool _intro_target;
 
241
  set<int> _derived_ids;
 
242
  set<int> _base_ids;
128
243
  
129
244
public:
130
 
  JPL_Class (CClassInfo *c);
131
 
  CClassInfo *class_info () { return class_obj; }
132
 
  virtual CObjectInfo *obj_info () { return class_obj; }
133
 
  join_point_type type () { return Class; }
 
245
  JPL_Class (const string &name) { _sig = name; }
 
246
  JPL_Class (const JPL_Class &jpl) : JPL_Name (jpl), _intro_target (jpl._intro_target) {}
 
247
  JPL_Class (RepoXMLNode node, RepoXMLNode::iter &curr);
 
248
  virtual RepoXMLNode make_xml (RepoXMLNode parent) const;
 
249
  
 
250
  join_point_type type () const { return Class; }
134
251
  virtual const char *type_str () const { return "class"; }
135
 
  virtual CTree *tree () const;
136
 
  // find a member that is/must be link-once (global) code
137
 
  CObjectInfo *link_once_object () { return link_once_object (class_obj); }
 
252
  void intro_target (bool i) { _intro_target = i; }
 
253
  bool intro_target () const { return _intro_target; }
 
254
 
 
255
  // get the list of base classes (IDs) => can be mapped with 'map'
 
256
  const set<int> &base_class_ids () const { return _base_ids; }
 
257
  
 
258
  // get the list of derived classes (IDs) => can be mapped with 'map'
 
259
  const set<int> &derived_class_ids () const { return _derived_ids; }
 
260
  
 
261
  // declare a class to be a base class of this class
 
262
  void base (JPL_Class *base) {
 
263
    _base_ids.insert (base->id ());
 
264
    base->_derived_ids.insert (id ());
 
265
  }
 
266
 
 
267
  // generate back links
 
268
  void generate_back_links () {
 
269
    for (set<int>::const_iterator i = _base_ids.begin ();
 
270
      i != _base_ids.end (); ++i)
 
271
      ((JPL_Class*)map (*i))->_derived_ids.insert (id ());
 
272
  }
138
273
};
139
274
 
140
275
class JPL_Aspect : public JPL_Class {
141
 
  ACAspectInfo *aspect_obj;
 
276
  list<JPL_AdviceCode*> _advice_codes;
 
277
  list<JPL_Introduction*> _intro_infos;
 
278
  list<JPL_Order*> _order_infos;
 
279
  
142
280
public:
143
 
  JPL_Aspect (ACAspectInfo *a) : JPL_Class (a->ClassInfo ()), aspect_obj (a) {}
144
 
  ACAspectInfo *aspect_info () const { return aspect_obj; }
145
 
  virtual join_point_type type () { return Aspect; }
 
281
  JPL_Aspect (const string &name) : JPL_Class (name) {}
 
282
  JPL_Aspect (const JPL_Aspect &jpl) : JPL_Class (jpl) {}
 
283
  JPL_Aspect (RepoXMLNode node, RepoXMLNode::iter &curr) :
 
284
    JPL_Class (node, curr) {}
 
285
  virtual join_point_type type () const { return Aspect; }
146
286
  virtual const char *type_str () const { return "aspect"; }
 
287
  
 
288
  /// the list of associated code advice nodes
 
289
  list<JPL_AdviceCode*> &advice_codes () { return _advice_codes; }
 
290
  
 
291
  /// the list of associated order advice nodes
 
292
  list<JPL_Order*> &order_infos () { return _order_infos; }
 
293
  
 
294
  /// the list of associated introduction nodes
 
295
  list<JPL_Introduction*> &intro_infos () { return _intro_infos; }
 
296
  
 
297
  /// collect the advice codes from this aspect and all base aspects
 
298
  void collect_advice_codes (list<JPL_AdviceCode*> &codes) const {
 
299
    for (list<JPL_AdviceCode*>::const_iterator i = _advice_codes.begin ();
 
300
      i != _advice_codes.end (); ++i)
 
301
      codes.push_back (*i);
 
302
    const set<int> &bases = base_class_ids ();
 
303
    for (set<int>::const_iterator i = bases.begin (); i != bases.end (); ++i) {
 
304
      JPL_Class *cls = (JPL_Class*)map (*i);
 
305
      if (cls->type () == JoinPointLoc::Aspect)
 
306
        ((JPL_Aspect*)cls)->collect_advice_codes (codes);
 
307
    }
 
308
  }
 
309
  
 
310
  /// collect the advice codes from this aspect and all base aspects
 
311
  void collect_intros (list<JPL_Introduction*> &intros) const {
 
312
    for (list<JPL_Introduction*>::const_iterator i = _intro_infos.begin ();
 
313
      i != _intro_infos.end (); ++i)
 
314
      intros.push_back (*i);
 
315
    const set<int> &bases = base_class_ids ();
 
316
    for (set<int>::const_iterator i = bases.begin (); i != bases.end (); ++i) {
 
317
      JPL_Class *cls = (JPL_Class*)map (*i);
 
318
      if (cls->type () == JoinPointLoc::Aspect)
 
319
        ((JPL_Aspect*)cls)->collect_intros (intros);
 
320
    }
 
321
  }
 
322
  
 
323
  /// collect the advice codes from this aspect and all base aspects
 
324
  void collect_orders (list<JPL_Order*> &orders) const {
 
325
    for (list<JPL_Order*>::const_iterator i = _order_infos.begin ();
 
326
      i != _order_infos.end (); ++i)
 
327
      orders.push_back (*i);
 
328
    const set<int> &bases = base_class_ids ();
 
329
    for (set<int>::const_iterator i = bases.begin (); i != bases.end (); ++i) {
 
330
      JPL_Class *cls = (JPL_Class*)map (*i);
 
331
      if (cls->type () == JoinPointLoc::Aspect)
 
332
        ((JPL_Aspect*)cls)->collect_orders (orders);
 
333
    }
 
334
  }
147
335
};
148
336
 
149
337
class JPL_Function : public JPL_Name {
150
 
  CFunctionInfo *func_obj;
151
 
public:
152
 
  JPL_Function (CFunctionInfo *f);
153
 
  CFunctionInfo *func_info () { return func_obj; }
154
 
  virtual CObjectInfo *obj_info () { return func_obj; }
155
 
  join_point_type type () { return Function; }
 
338
public:
 
339
  enum FunctionType {
 
340
    NON_MEMBER, STATIC_MEMBER, MEMBER, VIRTUAL_MEMBER, CONSTRUCTOR, DESTRUCTOR,
 
341
    UNKNOWN
 
342
  };
 
343
 
 
344
private:
 
345
  FunctionType _function_type;
 
346
  vector<JPL_Type *> _arg_types;
 
347
  JPL_Type *_result_type;
 
348
 
 
349
protected:
 
350
  virtual void parse_match_signature () const {
 
351
    JPL_Name::parse_match_signature ();
 
352
    if (is_virtual ())
 
353
      _match_sig.declare_virtual_function ();
 
354
  }
 
355
  
 
356
public:
 
357
  JPL_Function (const string &n, const string &s) :
 
358
    _function_type (UNKNOWN), _result_type (0) {
 
359
    name (n); _sig = s;
 
360
  }
 
361
  JPL_Function (const JPL_Function &jpl) :
 
362
    JPL_Name (jpl), _function_type (jpl._function_type) {}
 
363
  JPL_Function (RepoXMLNode node, RepoXMLNode::iter &curr);
 
364
  ~JPL_Function ();
 
365
 
 
366
  // set the function type
 
367
  void function_type (FunctionType ft) { _function_type = ft; }
 
368
 
 
369
  // helper functions to check the function type
 
370
  bool is_non_member () const        { return _function_type == NON_MEMBER; }
 
371
  bool is_static_member () const     { return _function_type == STATIC_MEMBER; }
 
372
  bool is_non_static_member () const { return _function_type == MEMBER ||
 
373
                                              _function_type == VIRTUAL_MEMBER; }
 
374
  bool is_virtual () const           { return _function_type == VIRTUAL_MEMBER; }
 
375
  bool is_constructor () const       { return _function_type == CONSTRUCTOR; }
 
376
  bool is_destructor () const        { return _function_type == DESTRUCTOR; }
 
377
 
 
378
  // argument handling
 
379
  int arg_count () const {
 
380
    return (int)_arg_types.size ();
 
381
  }
 
382
  const JPL_Type &arg_type (int i) const {
 
383
    assert (i >= 0 && i < arg_count ());
 
384
    return *_arg_types[i]; 
 
385
  }
 
386
  void add_arg_type (JPL_Type *type) { _arg_types.push_back (type); }
 
387
  void reset_types () {
 
388
    for (int i = 0; i < arg_count (); i++)
 
389
      delete _arg_types[i];
 
390
    _arg_types.clear ();
 
391
    if (_result_type) {
 
392
      delete _result_type;
 
393
      _result_type = 0;
 
394
    }
 
395
  }
 
396
  
 
397
  // manage the result type
 
398
  void result_type (JPL_Type *type) {
 
399
    if (_result_type) delete _result_type;
 
400
    _result_type = type;
 
401
  }
 
402
  const JPL_Type &result_type () const { return *_result_type; }
 
403
  
 
404
  join_point_type type () const { return Function; }
156
405
  virtual const char *type_str () const { return "function"; }
157
 
  virtual CTree *tree () const;
158
 
};
159
 
 
160
 
class JPL_Type : public JPL_Name {
161
 
public:
162
 
  JPL_Type (CTypeInfo *t);
163
 
  virtual CObjectInfo *obj_info () { return 0; }
164
 
  join_point_type type () { return Type; }
165
 
  virtual const char *type_str () const { return "type"; }
166
 
  virtual CTree *tree () const;
167
 
};
168
 
 
169
 
 
 
406
  bool has_same_name_and_args (const JPL_Function &func) const;
 
407
};
 
408
 
 
409
class JPL_ClassSlice : public JPL_Name {
 
410
public:
 
411
  enum class_slice_type { CS_OLD_BASE, CS_OLD_OTHER, CS_NORMAL, CS_ERROR };
 
412
  
 
413
private:
 
414
  class_slice_type _type;
 
415
  CProtection::Type _prot;
 
416
  Unit _pattern;
 
417
  
 
418
public:
 
419
  JPL_ClassSlice (const string &name) :
 
420
    _type (CS_NORMAL), _prot (CProtection::PROT_PRIVATE) {
 
421
    _sig = name;
 
422
  }
 
423
  JPL_ClassSlice (RepoXMLNode node, RepoXMLNode::iter &curr);
 
424
  JPL_ClassSlice (const JPL_ClassSlice &jpl) : _type (jpl._type),
 
425
    _prot (jpl._prot), _pattern (jpl._pattern) {}
 
426
  virtual RepoXMLNode make_xml (RepoXMLNode parent) const;
 
427
    
 
428
  void slice_type (class_slice_type t) { _type = t; }
 
429
  class_slice_type slice_type () const { return _type; }
 
430
  void prot (CProtection::Type p) { _prot = p; }
 
431
  CProtection::Type prot () const { return _prot; }
 
432
  const Unit &pattern () const { return _pattern; }
 
433
  Unit &pattern () { return _pattern; }
 
434
  virtual join_point_type type () const { return ClassSlice; }
 
435
  virtual const char *type_str () const {
 
436
    switch (_type) {
 
437
      case CS_OLD_BASE:  return "slice-dep-base";
 
438
      case CS_OLD_OTHER: return "slice-dep-member";
 
439
      case CS_NORMAL:    return "slice-class";
 
440
      default:           return "error";
 
441
    }
 
442
  }
 
443
};
 
444
 
 
445
/**
 
446
 * \class JPL_Code
 
447
 * \brief the common base class of all code join-point locations
 
448
 */
 
449
 
170
450
class JPL_Code : public JoinPointLoc {
171
 
  vector<JPL_Type *> _arg_types;
172
 
  JPL_Type *_result_type;
 
451
protected:
 
452
  /// local id for this jp inside the current function (or -1)
 
453
  int _lid;
173
454
public:
174
 
  JPL_Code () : _result_type (0) {}
175
 
  ~JPL_Code ();
 
455
  JPL_Code () : _lid (0) {}
 
456
  JPL_Code (const JPL_Code &jpl) : JoinPointLoc (jpl), _lid (jpl._lid) {}
 
457
  JPL_Code (RepoXMLNode node, RepoXMLNode::iter &curr) :
 
458
    JoinPointLoc (node, curr), _lid (0) {}
176
459
 
177
460
  virtual bool is_pseudo () const { return false; }
178
461
  
 
462
  // get the local id within the current function
 
463
  int lid () const { return _lid; }
 
464
 
 
465
  // set the local id within the current function
 
466
  void lid (int lid) { _lid = lid; }
 
467
 
 
468
  // the lexical scope of this code join point as needed by 'within'
 
469
  virtual JPL_Name *lexical_scope () const = 0;
 
470
  
179
471
  // argument handling
180
 
  int arg_count () const {
181
 
    return (int)_arg_types.size ();
182
 
  }
183
 
  const JPL_Type &arg_type (int i) const {
184
 
    assert (i >= 0 && i < arg_count ());
185
 
    return *_arg_types[i]; 
186
 
  }
187
 
  void add_arg_type (CTypeInfo *ctype) {
188
 
    _arg_types.push_back (new JPL_Type (ctype));
189
 
  }
 
472
  virtual int arg_count () const = 0;
 
473
  virtual const JPL_Type &arg_type (int i) const = 0;
190
474
  
191
475
  // manage the result type
192
 
  void result_type (CTypeInfo *ctype) { _result_type = new JPL_Type (ctype); }
193
 
  const JPL_Type &result_type () const { return *_result_type; }
194
 
  
195
 
  // That and Target types for the JoinPoint-API
196
 
  virtual CTypeInfo *that_type () = 0;
197
 
  virtual CTypeInfo *target_type () const = 0;
198
 
  
199
 
  // helper functions for derived class
200
 
  CTypeInfo *get_that_type (CObjectInfo *obj);
201
 
  
202
 
  // generates the signature of a wrapper function for exec/cons/dest join pts
203
 
  string wrapper_function_signature (CFunctionInfo *func, bool def);
 
476
  virtual const JPL_Type &result_type () const = 0;
204
477
  
205
478
  // interface needed to generate proper proceed code
206
479
  virtual bool proceed_needs_args () const {
207
480
    return arg_count () > 0;
208
481
  }
209
482
  virtual bool proceed_needs_result () const {
210
 
    return _result_type && !_result_type->type_info ()->is_void ();
211
 
  }
212
 
  virtual bool proceed_needs_target () const { return false; }
213
 
  virtual bool proceed_needs_that () const { return false; }
214
 
  virtual bool proceed_needs_fptr () const { return false; }
215
 
  
216
 
  // helper function: check if a function is a method (needs a 'this' pointer)
217
 
  static bool needs_this (CFunctionInfo *func) {
218
 
    if (func->isMethod () && !func->isStaticMethod ()) {
219
 
      return !(func->isOperator () &&
220
 
        (strcmp (func->Name (), "operator new") == 0 ||
221
 
         strcmp (func->Name (), "operator new[]") == 0 ||
222
 
         strcmp (func->Name (), "operator delete") == 0 ||
223
 
         strcmp (func->Name (), "operator delete[]") == 0));
 
483
    return result_type () != JPL_Type ("void");
 
484
  }
 
485
};
 
486
 
 
487
class JPL_Method : public JPL_Code {
 
488
public:
 
489
  JPL_Method () { _lid = -1; }
 
490
  JPL_Method (const JPL_Method &jpl) : JPL_Code (jpl) {}
 
491
  JPL_Method (RepoXMLNode node, RepoXMLNode::iter &curr) :
 
492
    JPL_Code (node, curr) {}
 
493
  join_point_type type () const { return Method; }
 
494
  virtual const char *type_str () const { return "exec"; }
 
495
 
 
496
  // argument handling
 
497
  virtual int arg_count () const { return function ()->arg_count (); }
 
498
  virtual const JPL_Type &arg_type (int i) const { return function ()->arg_type (i); }
 
499
  
 
500
  // manage the result type
 
501
  const JPL_Type &result_type () const { return function ()->result_type (); }
 
502
  
 
503
  // the lexical scope of this code join point as needed by 'within'
 
504
  virtual JPL_Name *lexical_scope () const { return (JPL_Name*)parent ()->parent (); }
 
505
 
 
506
  // the executed function
 
507
  JPL_Function *function () const { return (JPL_Function*)parent (); }
 
508
  
 
509
  // the signature of the exec join point (= signature of the function)
 
510
  virtual const char *signature () const { return function ()->signature (); }
 
511
  
 
512
  /// check whether this join point is seen by a specific tranlation unit
 
513
  virtual bool is_known_in_tunit (File *tunit) {
 
514
    return function ()->is_known_in_tunit (tunit);
 
515
  }
 
516
};
 
517
 
 
518
class JPL_MethodCall : public JPL_Code {
 
519
  int _target_id;
 
520
 
 
521
  vector<JPL_Type *> _arg_types;
 
522
  JPL_Type *_result_type;
 
523
  
 
524
public:
 
525
  JPL_MethodCall () { _lid = -1; }
 
526
  JPL_MethodCall (const JPL_MethodCall &jpl) : JPL_Code (jpl),
 
527
    _target_id (jpl._target_id) {}
 
528
  JPL_MethodCall (RepoXMLNode node, RepoXMLNode::iter &curr) :
 
529
    JPL_Code (node, curr) {
 
530
    _target_id = node.get_int_prop ("target");
 
531
  }
 
532
  ~JPL_MethodCall ();
 
533
 
 
534
  virtual bool is_pseudo () const { return !parent (); }
 
535
 
 
536
  JPL_Function *target_function () const {
 
537
    return (JPL_Function*)map (_target_id);
 
538
  }
 
539
  void target_function (JPL_Function *f) {
 
540
    _target_id = f->id ();
 
541
    _sig = f->signature ();
 
542
  }
 
543
  
 
544
  // the signature of the exec join point (= signature of the function)
 
545
  // TODO: better create the signature from the arg and result types
 
546
  virtual const char *signature () const { return target_function ()->signature (); }
 
547
  
 
548
  // for internal use only:
 
549
  int target_id () const { return _target_id; }
 
550
  
 
551
  JPL_Function *caller_function () const {
 
552
    return (parent () && parent ()->type () == JoinPointLoc::Function) ?
 
553
      (JPL_Function*)parent () : 0;
 
554
  }
 
555
 
 
556
  // argument handling
 
557
  virtual int arg_count () const {
 
558
    return (int)_arg_types.size ();
 
559
  }
 
560
  virtual const JPL_Type &arg_type (int i) const {
 
561
    assert (i >= 0 && i < arg_count ());
 
562
    return *_arg_types[i]; 
 
563
  }
 
564
  void add_arg_type (JPL_Type *type) { _arg_types.push_back (type); }
 
565
  
 
566
  // manage the result type
 
567
  void result_type (JPL_Type *type) { _result_type = type; }
 
568
  virtual const JPL_Type &result_type () const { return *_result_type; }
 
569
 
 
570
  join_point_type type () const { return MethodCall; }
 
571
  virtual const char *type_str () const { return "call"; }
 
572
 
 
573
  // the lexical scope of this code join point as needed by 'within'
 
574
  virtual JPL_Name *lexical_scope () const { return (JPL_Name*)parent (); }
 
575
 
 
576
  // save as XML
 
577
  virtual RepoXMLNode make_xml (RepoXMLNode parent) const;
 
578
};
 
579
 
 
580
class JPL_Construction : public JPL_Code {
 
581
public:
 
582
  JPL_Construction () { _lid = -1; }
 
583
 
 
584
  JPL_Construction (RepoXMLNode node, RepoXMLNode::iter &curr) :
 
585
    JPL_Code (node, curr) {}
 
586
    
 
587
  JPL_Construction (const JPL_Construction &jpl) : JPL_Code (jpl) {}
 
588
 
 
589
  join_point_type type () const { return Construction; }
 
590
  virtual const char *type_str () const { return "construction"; }
 
591
 
 
592
  // the executed constructor function
 
593
  JPL_Function *function () const { return (JPL_Function*)parent (); }
 
594
 
 
595
  // the lexical scope of this code join point as needed by 'within'
 
596
  virtual JPL_Name *lexical_scope () const { return (JPL_Name*)parent ()->parent (); }
 
597
 
 
598
  // argument handling
 
599
  virtual int arg_count () const { return function ()->arg_count (); }
 
600
  virtual const JPL_Type &arg_type (int i) const { return function ()->arg_type (i); }
 
601
  
 
602
  // manage the result type
 
603
  const JPL_Type &result_type () const { return function ()->result_type (); }
 
604
  
 
605
  // the signature of the exec join point (= signature of the function)
 
606
  virtual const char *signature () const { return function ()->signature (); }
 
607
  
 
608
  /// check whether this join point is seen by a specific tranlation unit
 
609
  virtual bool is_known_in_tunit (File *tunit) {
 
610
    return function ()->is_known_in_tunit (tunit);
 
611
  }
 
612
};
 
613
 
 
614
class JPL_Destruction : public JPL_Code {
 
615
public:
 
616
  JPL_Destruction () { _lid = -1; }
 
617
 
 
618
  JPL_Destruction (RepoXMLNode node, RepoXMLNode::iter &curr) :
 
619
    JPL_Code (node, curr) {}
 
620
 
 
621
  JPL_Destruction (const JPL_Destruction &jpl) : JPL_Code (jpl) {}
 
622
 
 
623
  join_point_type type () const { return Destruction; }
 
624
  virtual const char *type_str () const { return "destruction"; }
 
625
 
 
626
  // the executed destructor function
 
627
  JPL_Function *function () const { return (JPL_Function*)parent (); }
 
628
 
 
629
  // the lexical scope of this code join point as needed by 'within'
 
630
  virtual JPL_Name *lexical_scope () const { return (JPL_Name*)parent ()->parent (); }
 
631
 
 
632
  // argument handling
 
633
  virtual int arg_count () const { return function ()->arg_count (); }
 
634
  virtual const JPL_Type &arg_type (int i) const { return function ()->arg_type (i); }
 
635
  
 
636
  // manage the result type
 
637
  const JPL_Type &result_type () const { return function ()->result_type (); }
 
638
  
 
639
  // the signature of the exec join point (= signature of the function)
 
640
  virtual const char *signature () const { return function ()->signature (); }
 
641
  
 
642
  /// check whether this join point is seen by a specific tranlation unit
 
643
  virtual bool is_known_in_tunit (File *tunit) {
 
644
    return function ()->is_known_in_tunit (tunit);
 
645
  }
 
646
};
 
647
 
 
648
class JPL_Advice {
 
649
  CTree *_pce;
 
650
 
 
651
public:
 
652
  JPL_Advice (CTree *pce = 0) : _pce (pce) {}
 
653
  CTree *expr () const { return _pce; }
 
654
  void expr (CTree *pce) { _pce = pce; }
 
655
};
 
656
 
 
657
class JPL_AdviceCode : public JPL_Advice, public JPL_Function {
 
658
public:
 
659
  enum advice_type { ADVICE_BEFORE, ADVICE_AROUND, ADVICE_AFTER };
 
660
 
 
661
private:
 
662
  CTree *_pce;
 
663
  advice_type _type;
 
664
 
 
665
public:
 
666
  JPL_AdviceCode (const string &n, const string &s) :
 
667
    JPL_Function (n, s) {
 
668
    const char *nm = n.c_str ();
 
669
    if (strstr (nm, "before"))
 
670
      _type = ADVICE_BEFORE;
 
671
    else if (strstr (nm, "after"))
 
672
      _type = ADVICE_AFTER;
 
673
    else
 
674
      _type = ADVICE_AROUND;
 
675
  }
 
676
  JPL_AdviceCode (const JPL_AdviceCode &jpl) : JPL_Advice (jpl), JPL_Function (jpl),
 
677
    _pce (jpl._pce), _type (jpl._type) {}
 
678
  JPL_AdviceCode (RepoXMLNode node, RepoXMLNode::iter &curr);
 
679
  virtual RepoXMLNode make_xml (RepoXMLNode parent) const;
 
680
 
 
681
  virtual join_point_type type () const { return AdviceCode; }
 
682
  virtual const char *type_str () const {
 
683
    switch (_type) {
 
684
      case ADVICE_BEFORE: return "advice-before";
 
685
      case ADVICE_AROUND: return "advice-around";
 
686
      case ADVICE_AFTER:  return "advice-after";
224
687
    }
225
 
    return false;
226
 
  }
227
 
};
228
 
 
229
 
class JPL_Method : public JPL_Code
230
 
 {
231
 
      CFunctionInfo *_func_info;
232
 
 
233
 
   public:
234
 
 
235
 
      JPL_Method (CFunctionInfo *f);
236
 
 
237
 
      join_point_type type () { return Method; }
238
 
      virtual const char *type_str () const { return "exec"; }
239
 
      virtual CTree *tree () const;
240
 
      virtual CTypeInfo *target_type () const;
241
 
      virtual CTypeInfo *that_type ();
242
 
      CFunctionInfo *func_info () { return _func_info; }
243
 
      virtual CObjectInfo *assoc_obj () { return _func_info; }
244
 
      virtual Token *insertloc_tjp_struct();
245
 
      virtual Token *insertloc_before () { return _func_info->Tree ()->token (); }
246
 
      virtual Token *insertloc_after () { return _func_info->Tree ()->end_token (); }
247
 
      CFunctionInfo *tjp_type() {return _func_info;}
248
 
      CFunctionInfo *tjp_target() {return _func_info;}
249
 
      CFunctionInfo *tjp_that() {return _func_info;}
250
 
      CFunctionInfo *action_dst_func() {return _func_info;}
251
 
      CFunctionInfo *action_src_func() {return _func_info;}
252
 
      virtual bool proceed_needs_that () const {
253
 
        return needs_this (_func_info);
254
 
      }
255
 
 };
256
 
 
257
 
class JPL_MethodCall : public JPL_Code
258
 
 {
259
 
      CFunctionInfo *called_func;
260
 
      CObjectInfo *caller_obj;
261
 
      CT_CallExpr *node;
262
 
      bool _member_init;
263
 
 
264
 
   public:
265
 
 
266
 
      JPL_MethodCall (CFunctionInfo *called, CT_CallExpr *ce,
267
 
                      CObjectInfo *caller, int local_id, bool mi);
268
 
 
269
 
      virtual bool is_pseudo () const { return !caller_obj; }
270
 
      CFunctionInfo *caller () { 
271
 
        return caller_obj ? caller_obj->FunctionInfo () : 0;
272
 
      }
273
 
      CFunctionInfo *called () const { return called_func; }
274
 
      bool in_member_init () const { return _member_init; }
275
 
 
276
 
      const char *type_called() { return _sig.c_str (); }
277
 
      
278
 
      // the call expression node in the syntax tree
279
 
      CT_CallExpr *CallExprNode() const { return node;}
280
 
      
281
 
      // the target object of the call or NULL
282
 
      CT_Expression *target_expr (bool &is_ptr) const;
283
 
      
284
 
      // checks if the original call uses a qualified target function name
285
 
      bool is_qualified () const;
286
 
      
287
 
      // returns true if the call needs special access rights
288
 
      bool needs_rights () const;
289
 
      
290
 
      join_point_type type () { return MethodCall; }
291
 
      virtual const char *type_str () const { return "call"; }
292
 
      virtual CTree *tree () const;
293
 
      virtual CTypeInfo *that_type ();
294
 
      virtual CTypeInfo *target_type () const;
295
 
      virtual CObjectInfo *assoc_obj () { return caller_obj; }
296
 
      virtual Token *insertloc_tjp_struct();
297
 
      virtual Token *insertloc_before ();
298
 
      virtual Token *insertloc_after ();
299
 
      CFunctionInfo *tjp_type() { return called_func;}
300
 
      CFunctionInfo *tjp_target() { return called_func;}
301
 
      CFunctionInfo *tjp_that() { return caller_obj->FunctionInfo ();}
302
 
      CFunctionInfo *action_dst_func() {return called_func;}
303
 
      CFunctionInfo *action_src_func() {return caller_obj->FunctionInfo ();}
304
 
 
305
 
      virtual bool proceed_needs_target () const {
306
 
        return needs_this (called_func);
307
 
      }
308
 
      virtual bool proceed_needs_fptr () const {
309
 
        return needs_rights ();
310
 
      }
311
 
 };
312
 
 
313
 
class JPL_FieldReference : public JPL_Code
314
 
 {
315
 
      CAttributeInfo *attr;
316
 
      CTree *field;
317
 
      
318
 
   public:
319
 
 
320
 
      JPL_FieldReference (CAttributeInfo *a, CTree *f, int local_id);
321
 
      join_point_type type () { return FieldReference; }
322
 
      virtual const char *type_str () const { return "get"; }
323
 
      virtual CTree *tree () const;
324
 
      virtual CTypeInfo *that_type ();
325
 
      virtual CTypeInfo *target_type () const;
326
 
 };
327
 
 
328
 
class JPL_FieldAssignment : public JPL_Code
329
 
 {
330
 
      CAttributeInfo *attr;
331
 
      CT_CallExpr *assignment;
332
 
      CTree *field;
333
 
      
334
 
   public:
335
 
 
336
 
      JPL_FieldAssignment (CAttributeInfo *a, CT_CallExpr *as,
337
 
                           CTree *f, int local_id);
338
 
      join_point_type type () { return FieldAssignment; }
339
 
      virtual const char *type_str () const { return "set"; }
340
 
      virtual CTree *tree () const;
341
 
      virtual CTypeInfo *that_type ();
342
 
      virtual CTypeInfo *target_type () const;
343
 
 };
344
 
 
345
 
class JPL_Construction : public JPL_Code
346
 
 {
347
 
      CFunctionInfo *_func_info;
348
 
 
349
 
   public:
350
 
 
351
 
      JPL_Construction (CFunctionInfo *f);
352
 
 
353
 
      join_point_type type () { return Construction; }
354
 
      virtual const char *type_str () const { return "construction"; }
355
 
      virtual CTree *tree () const;
356
 
      virtual CTypeInfo *that_type ();
357
 
      virtual CTypeInfo *target_type () const;
358
 
      CFunctionInfo *func_info () { return _func_info; }
359
 
      virtual CObjectInfo *assoc_obj () { return _func_info; }
360
 
      virtual Token *insertloc_tjp_struct();
361
 
      virtual Token *insertloc_before () { return _func_info->Tree ()->token (); }
362
 
      virtual Token *insertloc_after () { return _func_info->Tree ()->end_token (); }
363
 
      CFunctionInfo *tjp_type() {return _func_info;}
364
 
      CFunctionInfo *tjp_target() {return _func_info;}
365
 
      CFunctionInfo *tjp_that() {return _func_info;}
366
 
      CFunctionInfo *action_dst_func() {return _func_info;}
367
 
      CFunctionInfo *action_src_func() {return _func_info;}
368
 
      virtual bool proceed_needs_that () const { return true; }
369
 
 };
370
 
 
371
 
class JPL_Destruction : public JPL_Code
372
 
 {
373
 
      CFunctionInfo *_func_info;
374
 
 
375
 
   public:
376
 
 
377
 
      JPL_Destruction (CFunctionInfo *f);
378
 
 
379
 
      join_point_type type () { return Destruction; }
380
 
      virtual const char *type_str () const { return "destruction"; }
381
 
      virtual CTree *tree () const;
382
 
      virtual CTypeInfo *that_type ();
383
 
      virtual CTypeInfo *target_type () const;
384
 
      CFunctionInfo *func_info () { return _func_info; }
385
 
      virtual CObjectInfo *assoc_obj () { return _func_info; }
386
 
      virtual Token *insertloc_tjp_struct();
387
 
      virtual Token *insertloc_before () { return _func_info->Tree ()->token (); }
388
 
      virtual Token *insertloc_after () { return _func_info->Tree ()->end_token (); }
389
 
      CFunctionInfo *tjp_type() {return _func_info;}
390
 
      CFunctionInfo *tjp_target() {return _func_info;}
391
 
      CFunctionInfo *tjp_that() {return _func_info;}
392
 
      CFunctionInfo *action_dst_func() {return _func_info;}
393
 
      CFunctionInfo *action_src_func() {return _func_info;}
394
 
      virtual bool proceed_needs_that () const { return true; }
395
 
 };
 
688
    return "error"; // just to suppress warnings
 
689
  }
 
690
 
 
691
  advice_type type () { return _type; }
 
692
};
 
693
 
 
694
class JPL_Introduction : public JPL_Advice, public JoinPointLoc {
 
695
  int _slice_id;
 
696
public:
 
697
  JPL_Introduction () : _slice_id (-1) {
 
698
    _sig = "<no sig>";
 
699
  }
 
700
  JPL_Introduction (RepoXMLNode node, RepoXMLNode::iter &curr);
 
701
  JPL_Introduction (const JPL_Introduction &jpl) : JPL_Advice (jpl), _slice_id (0) {}
 
702
  virtual RepoXMLNode make_xml (RepoXMLNode parent) const;
 
703
 
 
704
  void parent (JPL_Aspect *ai) {
 
705
    JoinPointLoc::parent (ai);
 
706
    ai->intro_infos ().push_back (this);
 
707
  }
 
708
  using JoinPointLoc::parent;
 
709
  
 
710
  int slice_id () const { return _slice_id; }
 
711
 
 
712
  virtual join_point_type type () const { return Introduction; }
 
713
  const char *type_str () const { return "intro"; }
 
714
  void introduced (JPL_ClassSlice *s) { _slice_id = s->id (); }
 
715
  JPL_ClassSlice *introduced () const { return (JPL_ClassSlice*)map (_slice_id); }
 
716
};
 
717
 
 
718
class JPL_Order : public JPL_Advice, public JoinPointLoc {
 
719
  list<CTree*> _pces;
 
720
public:
 
721
  JPL_Order () {
 
722
    expr (0);
 
723
    _sig = "<no sig>";
 
724
  }
 
725
  void parent (JPL_Aspect *ai) {
 
726
    JoinPointLoc::parent (ai);
 
727
    ai->order_infos ().push_back (this);
 
728
  }
 
729
  using JoinPointLoc::parent;
 
730
 
 
731
  virtual join_point_type type () const { return Order; }
 
732
  virtual const char *type_str () const { return "order"; }
 
733
 
 
734
  void add_pce (CTree *pce) { _pces.push_back (pce); }
 
735
  const list<CTree*> &pces () const { return _pces; }
 
736
};
396
737
 
397
738
#endif // __join_point_loc_h__