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

« back to all changes in this revision

Viewing changes to AspectC++/ThisJoinPoint.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:
24
24
#include "Binding.h"
25
25
#include "JPAdvice.h"
26
26
#include "JoinPointLoc.h"
 
27
#include "WeaverBase.h"
27
28
 
28
29
#include "Puma/CTree.h"
29
30
#include "Puma/CClassInfo.h"
34
35
#include <sstream>
35
36
using std::stringstream;
36
37
using std::endl;
37
 
using std::ends;
38
38
#include <string>
39
39
using std::string;
40
40
 
41
 
static CClassInfo *cscope(CObjectInfo *obj) {
42
 
  if (obj->QualifiedScope ())
43
 
    return obj->QualifiedScope ()->ClassInfo ();
44
 
  return obj->Scope ()->ClassInfo ();
45
 
}
46
 
 
47
41
// special setup function for bindings
48
42
void ThisJoinPoint::setup (const Binding &binding) {
49
43
  _setup = true;
75
69
  CClassInfo *cls;
76
70
 
77
71
  const char *nodename = node->NodeName ();
78
 
 
 
72
  
79
73
  if (nodename == CT_SimpleName::NodeId () &&
80
74
      (obj = ((CT_SimpleName*)node)->Object ())) {
81
75
    if (obj->Scope ()->GlobalScope () &&
105
99
 
106
100
    if (strcmp (field, "signature") == 0)
107
101
      _used |= SIGNATURE;
 
102
    else if (strcmp (field, "filename") == 0)
 
103
      _used |= FILENAME;
 
104
    else if (strcmp (field, "line") == 0)
 
105
      _used |= LINE;
108
106
    else if (strcmp (field, "args") == 0)
109
107
      _used |= ARGS;
110
108
    else if (strcmp (field, "arg") == 0)
137
135
    setup_search (func, node->Son (s));
138
136
}   
139
137
 
140
 
void ThisJoinPoint::make_result_type(ostream &out, CTypeInfo *type,
141
 
                                     const char *rt_name) {
142
 
  if (type->isVoid () || type->isUndefined ())
143
 
    out << "void " << rt_name;
144
 
  else if (type->isAddress ()) {
145
 
    string ptr_name = "*";
146
 
    ptr_name += rt_name;
147
 
    type->BaseType ()->TypeText (out, ptr_name.c_str (), true, true);
148
 
  }
149
 
  else
150
 
    type->TypeText (out, rt_name, true, true);
 
138
string ThisJoinPoint::gen_result_type (JPL_Code *jpl) {
 
139
  CTypeInfo *rtype = TI_Type::of (jpl->result_type ())->type_info ();
 
140
  if (rtype->isVoid () || rtype->isUndefined ())
 
141
    return "void";
 
142
  else if (rtype->isAddress ())
 
143
    rtype = rtype->BaseType ();
 
144
  stringstream type;
 
145
  rtype->TypeText (type, "", true, true);
 
146
  return type.str ();
151
147
}
152
148
 
153
149
void ThisJoinPoint::gen_tjp_struct (ostream &code, JPL_Code *loc,
154
 
                                    BackEndProblems &bep, int depth) const {
 
150
                                  BackEndProblems &bep, int depth) const {
 
151
 
 
152
  TI_Code *ti = (TI_Code*)loc->transform_info ();
155
153
 
156
154
  // the level 0 struct -> contains all the data and types
157
 
  code << "struct ";
 
155
  code << "template <typename TResult, typename TThat, typename TTarget, ";
 
156
  code << "typename TArgs> struct ";
158
157
  Naming::tjp_struct (code, loc, depth);
159
158
  if (depth > 0) {
160
159
    // the level N > 0 structs -> are derived from level N - 1
161
160
    code << " : ";
162
161
    Naming::tjp_struct (code, loc, depth - 1);
 
162
    code << "<TResult, TThat, TTarget, TArgs>";
163
163
  }
164
164
  else {
165
165
    // the level N == 0 structs are derived from AC::Action, if action() used
167
167
      code << " : AC::Action";
168
168
  }
169
169
  code << " {" << endl;
 
170
  code << "  typedef ";
 
171
  Naming::tjp_struct (code, loc, depth);
 
172
  code << " __TJP;" << endl; // internal type definition
170
173
  
171
174
  stringstream types, data, fct;
172
175
 
173
176
  // start: type definitions --------------------------------------------------
174
 
  // Result type
175
 
  types << "  typedef ";
176
 
  make_result_type (types, loc->result_type ().type_info (), "Result");
177
 
  types << ";" << endl;
178
 
 
179
 
  // that type
180
 
  types << "  typedef ";
181
 
  ((JPL_Code*)loc)->that_type ()->TypeText (types, "That", true, true);
182
 
  types << ";" << endl;
183
 
 
184
 
  // target type
185
 
  types << "  typedef ";
186
 
  ((JPL_Code*)loc)->target_type ()->TypeText (types, "Target", true, true);
187
 
  types << ";" << endl;
 
177
  CTypeInfo *rtype  = TI_Type::of (loc->result_type ())->type_info ();
 
178
  bool res_is_ref   = rtype->isAddress ();
 
179
  bool res_is_undef = rtype->isUndefined ();
 
180
 
 
181
  types << "  typedef TResult " << (res_is_ref ? "*" : "") << "Result;" << endl;
 
182
  types << "  typedef TThat   That;" << endl;
 
183
  types << "  typedef TTarget Target;" << endl;
 
184
  
 
185
  // argument count and types
 
186
  types << "  enum { ARGS = TArgs::ARGS };" << endl;
 
187
  types << "  template <int I> struct Arg : AC::Arg<TArgs, I> {};" << endl;
188
188
    
189
189
  // join point id and type;
190
 
  types << "  static const int JPID = " << loc->id () << ";" << endl;
 
190
  int jpid = (loc->assigned_id () == -1 ? loc->id () : loc->assigned_id ());
 
191
  types << "  static const int JPID = " << jpid << ";" << endl;
191
192
  types << "  static const AC::JPType JPTYPE = (AC::JPType)" << loc->type ()
192
193
        << ";" << endl;
193
194
        
194
195
  // result type
195
196
  types << "  struct Res {" << endl;
196
 
  CTypeInfo *restype = loc->result_type ().type_info ();
197
 
  if (restype->isUndefined ()) {
198
 
    types << "    typedef void Type;" << endl;
199
 
    types << "    typedef void ReferredType;" << endl;
200
 
  }
201
 
  else {
202
 
    types << "    typedef ";
203
 
    restype->TypeText (types, "Type", true, true);
204
 
    types << ";" << endl;
205
 
    CTypeInfo *refrestype = restype;
206
 
    if (refrestype->isAddress ())
207
 
      refrestype = restype->BaseType ();
208
 
    types << "    typedef ";
209
 
    refrestype->TypeText (types, "ReferredType", true, true);
210
 
    types << ";" << endl;
211
 
  }
 
197
  types << "    typedef " << (res_is_undef ? "void" : "TResult") << " "
 
198
        << (res_is_ref ? "&" : "") << "Type;" << endl;
 
199
  types << "    typedef " << (res_is_undef ? "void" : "TResult") << " ReferredType;" << endl;
212
200
  types << "  };" << endl;
213
201
  
214
202
  // argument types
215
203
  unsigned arg_count = loc->arg_count ();
216
 
  types << "  enum { ARGS = " << arg_count << " };" << endl;
217
 
  types << "  template <int I";
218
 
  if (bep._spec_scope)
219
 
    types << ", int DUMMY = 0";
220
 
  types << "> struct Arg {" << endl;
221
 
  types << "    typedef void Type;" << endl;
222
 
  types << "    typedef void ReferredType;" << endl;
223
 
  types << "  };" << endl;
224
 
  for (unsigned a = 0; a < arg_count; a++) {
225
 
    CTypeInfo *argtype = loc->arg_type (a).type_info ();
226
 
    types << "  template <";
227
 
    if (bep._spec_scope)
228
 
      types << "int DUMMY";
229
 
    types << "> struct Arg<" << a;
230
 
    if (bep._spec_scope)
231
 
      types << ", DUMMY";
232
 
    types << "> {" << endl;
233
 
    types << "    typedef ";
234
 
    argtype->TypeText (types, "Type", true, true);
235
 
    types << ";" << endl;
236
 
    CTypeInfo *refargtype = argtype;
237
 
    if (refargtype->isAddress ())
238
 
      refargtype = argtype->BaseType ();
239
 
    types << "    typedef ";
240
 
    refargtype->TypeText (types, "ReferredType", true, true);
241
 
    types << ";" << endl;
242
 
    types << "  };" << endl;
243
 
  }
244
204
  
245
205
  // begin of static data -----------------------------------------------------
246
206
  if (signature ()) {
247
207
    fct << "  inline static const char *signature () { return \"";
248
208
    fct << loc->signature () << "\";}" << endl;
249
209
  }
 
210
  if (filename ()) {
 
211
    fct << "  inline static const char *filename () { return \"";
 
212
    fct << loc->filename () << "\";}" << endl;
 
213
  }
 
214
  if (line ()) {
 
215
    fct << "  inline static int line () { return ";
 
216
    fct << loc->line () << ";}" << endl;
 
217
  }
250
218
  if (args ()) {
251
219
    fct << "  inline static const int args () { return ";
252
220
    fct << arg_count << ";";
254
222
  }
255
223
  if (type()) {
256
224
    fct << "  inline static  AC::Type type() { return ";
257
 
    if (loc->tjp_type()) {
 
225
    if (ti->tjp_type()) {
258
226
      fct << "\"";
259
 
      loc->tjp_type()->TypeInfo()->Mangled(fct);
 
227
      ti->tjp_type()->TypeInfo()->Mangled(fct);
260
228
      fct << "\";";
261
229
    } else fct << "\"<unknown type>\";";
262
230
    fct << "}" << endl;
267
235
  
268
236
  if (resulttype()) {
269
237
    fct << "  inline static AC::Type resulttype() {return ";
270
 
    if (!loc->result_type ().type_info ()->isUndefined ()) {
 
238
    if (!TI_Type::of (loc->result_type ())->type_info ()->isUndefined ()) {
271
239
      fct << "\"";
272
 
      loc->result_type().type_info()->Mangled(fct);
 
240
      TI_Type::of (loc->result_type())->type_info()->Mangled(fct);
273
241
      fct << "\";";
274
242
    } else fct << "\"<unknown signature>\";";
275
243
    fct << "}" << endl;    
286
254
      for (unsigned i = 0; i < arg_count; i++) {
287
255
        if (i > 0) fct << ", ";
288
256
        fct << "\"";
289
 
        loc->arg_type (i).type_info ()->Mangled(fct);
 
257
        TI_Type::of (loc->arg_type (i))->type_info ()->Mangled(fct);
290
258
        fct << "\"";
291
259
      }
292
260
      fct << "};" << endl;
300
268
   
301
269
  // begin of dynamic data ----------------------------------------------------
302
270
  if (arg () || useAction () || (proceed () && loc->proceed_needs_args ())) {
303
 
    if (!useAction ())
304
 
      data << "  void **_args;" << endl;
305
 
    fct <<  "  inline void *arg (int n) {return _args[n];}" << endl;
 
271
    if (!useAction () && arg_count > 0)
 
272
      data << "  void *_args[ARGS];" << endl;
 
273
    fct <<  "  inline void *arg (int n) {return "
 
274
        << (arg_count > 0 ? "_args[n]" : "0") << ";}" << endl;
306
275
    fct <<  "  template <int I> typename Arg<I>::ReferredType *arg () {"
307
276
        << endl;
308
277
    fct <<  "    return (typename Arg<I>::ReferredType*)arg (I);" << endl;
315
284
    fct <<  "  inline Result *result() {return (Result*)_result;}" << endl;
316
285
  }
317
286
 
318
 
  if (target() || useAction () || (proceed () && loc->proceed_needs_target ())) {
 
287
  if (target() || useAction () || (proceed () && ti->proceed_needs_target ())) {
319
288
    if (!useAction ())
320
289
      data << "  Target *_target;" << endl;
321
290
    fct <<  "  inline Target *target() {return (Target*)_target;}" << endl;
322
291
  }
323
292
 
324
 
  if (that() || useAction () || (proceed () && loc->proceed_needs_that ())) {
 
293
  if (that() || useAction () || (proceed () && ti->proceed_needs_that ())) {
325
294
    if (!useAction ())
326
295
      data << "  That *_that;" << endl;
327
296
    fct <<  "  inline That *that() {return (That*)_that;}" << endl;
328
297
  }
329
298
 
330
 
  if (proceed () && loc->proceed_needs_fptr ()) {
 
299
  if (proceed () && ti->proceed_needs_fptr ()) {
331
300
    data << "  void *_fptr;" << endl;
332
301
  }
333
302
  
338
307
  }
339
308
 
340
309
  // terminate all the strings
341
 
  types << endl << ends;
342
 
  data << endl << ends;
343
 
  fct << endl << ends;
 
310
  types << endl;
 
311
  data << endl;
 
312
  fct << endl;
344
313
  
345
314
  // add all types, attributes, and functions (on level 0)
346
315
  if (depth == 0) {
352
321
  // the closing bracket is *NOT* generated here -> for external extensions
353
322
}
354
323
 
355
 
void ThisJoinPoint::dump (ostream &out)
356
 
 {
357
 
   out << "ThisJoinPoint (";
358
 
   out << "signature=" << (signature () ? "true" : "false");
359
 
   out << ", args=" << (args () ? "true" : "false");
360
 
   out << ", arg=" << (arg() ? "true" : "false");
361
 
   out << ", argtype=" << (argtype() ? "true" : "false");
362
 
   out << ", type=" << (type() ? "true" : "false");
363
 
   out << ", id=" << (id() ? "true" : "false");
364
 
   out << ", resulttype=" << (resulttype() ? "true" : "false");
365
 
   out << ", that=" << (that() ? "true" : "false");
366
 
   out << ", target=" << (target() ? "true" : "false");
367
 
   out << ", result=" << (result() ? "true" : "false");
368
 
   out << ", jptype=" << (jptype() ? "true" : "false");
369
 
   out << ", action=" << (action() ? "true" : "false");
370
 
   out << ", proceed=" << (proceed() ? "true" : "false");
371
 
   out << ")" << endl;
372
 
 }
 
324
void ThisJoinPoint::gen_tjp_init (ostream &code, JPL_Code *loc,
 
325
                                    BackEndProblems &bep, int depth) const {
 
326
  TI_Code *ti = (TI_Code*)TransformInfo::of (*loc);
 
327
  const ThisJoinPoint &tjp = *this; // TODO: not necessary!
 
328
  JoinPointLoc::join_point_type jptype = loc->type ();
 
329
 
 
330
  bool local_class = false, havefuncptr = false;
 
331
  // determine the weaving parameters
 
332
  if (jptype == JoinPointLoc::MethodCall) {
 
333
//    local_class = (!_problems._local_class &&
 
334
//                   !((JPL_MethodCall*)loc)->in_member_init () &&
 
335
//                   ((JPL_MethodCall*)loc)->needs_rights ());
 
336
    havefuncptr = (ti->proceed_needs_fptr () &&
 
337
                   (!local_class || depth > 0));
 
338
  }
 
339
 
 
340
  if (tjp.pointer_needed ()) {    
 
341
 
 
342
    code << "  __TJP ";
 
343
    Naming::tjp_instance(code, loc);
 
344
    code << ";" << endl;
 
345
 
 
346
    int args = ((JPL_Code*)loc)->arg_count ();
 
347
    if (tjp.arg() || tjp.useAction() ||
 
348
        (tjp.proceed () && loc->proceed_needs_args ())) {
 
349
      if (args) {
 
350
        if (tjp.useAction ()) {
 
351
                code << "  void *";
 
352
              Naming::tjp_args_array(code, loc);
 
353
            code << "[] = { ";
 
354
          for (int i = 0; i < args; i++) {
 
355
                  if (i > 0) code << ", ";
 
356
                code << "(void*)&arg" << i;
 
357
                }
 
358
                code << " };" << endl;
 
359
        }
 
360
      }
 
361
 
 
362
        if (tjp.useAction ()) {
 
363
            code << "  ";
 
364
            Naming::tjp_instance(code, loc);
 
365
          code << "._args = ";
 
366
        if (args)
 
367
                Naming::tjp_args_array(code, loc);
 
368
        else
 
369
                code << "0";
 
370
        code << ";" << endl;
 
371
                        }
 
372
                        else {
 
373
          for (int i = 0; i < args; i++) {
 
374
                      code << "  ";
 
375
                    Naming::tjp_instance(code, loc);
 
376
                  code << "._args[" << i << "] = (void*)&arg" << i << ";" << endl;
 
377
          }
 
378
                        }
 
379
    }
 
380
    
 
381
    if (tjp.result() || tjp.useAction() ||
 
382
        (tjp.proceed () && loc->proceed_needs_result ())) {
 
383
      code << "  ";
 
384
      Naming::tjp_instance(code, loc);
 
385
      code << "._result = ";
 
386
      CTypeInfo *rtype = TI_Type::of (((JPL_Code*)loc)->result_type ())->type_info ();
 
387
      if (!(rtype->isVoid() || rtype->isUndefined ())) {
 
388
        if (tjp.useAction ())
 
389
          code << "(void*)";
 
390
        code << "&(__TJP::Result&)result";
 
391
      } else {
 
392
        code << "0";
 
393
      }
 
394
      code << ";" << endl;
 
395
    }
 
396
    
 
397
    if (tjp.target() || tjp.useAction() ||
 
398
        (tjp.proceed () && ti->proceed_needs_target ())) {
 
399
      code << "  ";
 
400
      Naming::tjp_instance(code, loc);
 
401
      code << "._target = ";
 
402
      if (ti->tjp_target () && WeaverBase::needs_this (ti->tjp_target())) {
 
403
        code << " (";
 
404
        if (tjp.useAction ())
 
405
          code << "void*)";
 
406
        else {
 
407
          code << "__TJP::Target*)";
 
408
        }
 
409
        switch (jptype) {
 
410
          case JoinPointLoc::Construction:
 
411
          case JoinPointLoc::Destruction:
 
412
          case JoinPointLoc::Method:
 
413
            code << "this";
 
414
            break;
 
415
          case JoinPointLoc::MethodCall:
 
416
            code << "dstthis";
 
417
            break;
 
418
          default:
 
419
            code << " 0";
 
420
          }
 
421
      } else {
 
422
        code << " 0";
 
423
      }
 
424
      code << ";" << endl;
 
425
    }
 
426
 
 
427
    if (tjp.that() || tjp.useAction() ||
 
428
        (tjp.proceed () && ti->proceed_needs_that ())) {
 
429
      code << "  ";
 
430
      Naming::tjp_instance(code, loc);
 
431
      code << "._that = ";
 
432
      if (ti->tjp_that () && WeaverBase::needs_this (ti->tjp_that())) {
 
433
        code << " (";
 
434
        if (tjp.useAction ())
 
435
          code << "void*)";
 
436
        else {
 
437
          code << "__TJP::That*)";
 
438
        }
 
439
        switch (jptype) {
 
440
          case JoinPointLoc::Construction:
 
441
          case JoinPointLoc::Destruction:
 
442
          case JoinPointLoc::Method:
 
443
            code << "this";
 
444
            break;
 
445
          case JoinPointLoc::MethodCall:
 
446
            code << "srcthis";
 
447
            break;
 
448
          default:
 
449
            code << " 0";
 
450
        }
 
451
      } else {
 
452
        code << " 0";
 
453
      }
 
454
      code << ";" << endl;
 
455
    }
 
456
    
 
457
    if (tjp.useAction () ||
 
458
        (tjp.proceed () && ti->proceed_needs_fptr ())) {
 
459
      code << "  ";
 
460
      Naming::tjp_instance(code, loc);
 
461
      code << "._fptr = ";
 
462
      if (havefuncptr)
 
463
        code << "&fptr";
 
464
      else  
 
465
        code << "0";
 
466
      code << ";" << endl;
 
467
    }
 
468
  }
 
469
 
 
470
}
 
471
 
 
472
void ThisJoinPoint::dump (ostream &out) const {
 
473
  out << "ThisJoinPoint (";
 
474
  out << "signature=" << (signature () ? "true" : "false");
 
475
  out << ", filename=" << (filename () ? "true" : "false");
 
476
  out << ", line=" << (line () ? "true" : "false");
 
477
  out << ", args=" << (args () ? "true" : "false");
 
478
  out << ", arg=" << (arg() ? "true" : "false");
 
479
  out << ", argtype=" << (argtype() ? "true" : "false");
 
480
  out << ", type=" << (type() ? "true" : "false");
 
481
  out << ", id=" << (id() ? "true" : "false");
 
482
  out << ", resulttype=" << (resulttype() ? "true" : "false");
 
483
  out << ", that=" << (that() ? "true" : "false");
 
484
  out << ", target=" << (target() ? "true" : "false");
 
485
  out << ", result=" << (result() ? "true" : "false");
 
486
  out << ", jptype=" << (jptype() ? "true" : "false");
 
487
  out << ", action=" << (action() ? "true" : "false");
 
488
  out << ", proceed=" << (proceed() ? "true" : "false");
 
489
  out << ")" << endl;
 
490
}