137
135
setup_search (func, node->Son (s));
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 = "*";
147
type->BaseType ()->TypeText (out, ptr_name.c_str (), true, true);
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 ())
142
else if (rtype->isAddress ())
143
rtype = rtype->BaseType ();
145
rtype->TypeText (type, "", true, true);
153
149
void ThisJoinPoint::gen_tjp_struct (ostream &code, JPL_Code *loc,
154
BackEndProblems &bep, int depth) const {
150
BackEndProblems &bep, int depth) const {
152
TI_Code *ti = (TI_Code*)loc->transform_info ();
156
154
// the level 0 struct -> contains all the data and types
155
code << "template <typename TResult, typename TThat, typename TTarget, ";
156
code << "typename TArgs> struct ";
158
157
Naming::tjp_struct (code, loc, depth);
160
159
// the level N > 0 structs -> are derived from level N - 1
162
161
Naming::tjp_struct (code, loc, depth - 1);
162
code << "<TResult, TThat, TTarget, TArgs>";
165
165
// the level N == 0 structs are derived from AC::Action, if action() used
167
167
code << " : AC::Action";
169
169
code << " {" << endl;
171
Naming::tjp_struct (code, loc, depth);
172
code << " __TJP;" << endl; // internal type definition
171
174
stringstream types, data, fct;
173
176
// start: type definitions --------------------------------------------------
175
types << " typedef ";
176
make_result_type (types, loc->result_type ().type_info (), "Result");
177
types << ";" << endl;
180
types << " typedef ";
181
((JPL_Code*)loc)->that_type ()->TypeText (types, "That", true, true);
182
types << ";" << endl;
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 ();
181
types << " typedef TResult " << (res_is_ref ? "*" : "") << "Result;" << endl;
182
types << " typedef TThat That;" << endl;
183
types << " typedef TTarget Target;" << endl;
185
// argument count and types
186
types << " enum { ARGS = TArgs::ARGS };" << endl;
187
types << " template <int I> struct Arg : AC::Arg<TArgs, I> {};" << endl;
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 ()
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;
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;
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;
214
202
// argument types
215
203
unsigned arg_count = loc->arg_count ();
216
types << " enum { ARGS = " << arg_count << " };" << endl;
217
types << " template <int I";
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 <";
228
types << "int DUMMY";
229
types << "> struct Arg<" << a;
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;
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;
211
fct << " inline static const char *filename () { return \"";
212
fct << loc->filename () << "\";}" << endl;
215
fct << " inline static int line () { return ";
216
fct << loc->line () << ";}" << endl;
251
219
fct << " inline static const int args () { return ";
252
220
fct << arg_count << ";";
352
321
// the closing bracket is *NOT* generated here -> for external extensions
355
void ThisJoinPoint::dump (ostream &out)
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");
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 ();
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));
340
if (tjp.pointer_needed ()) {
343
Naming::tjp_instance(code, loc);
346
int args = ((JPL_Code*)loc)->arg_count ();
347
if (tjp.arg() || tjp.useAction() ||
348
(tjp.proceed () && loc->proceed_needs_args ())) {
350
if (tjp.useAction ()) {
352
Naming::tjp_args_array(code, loc);
354
for (int i = 0; i < args; i++) {
355
if (i > 0) code << ", ";
356
code << "(void*)&arg" << i;
358
code << " };" << endl;
362
if (tjp.useAction ()) {
364
Naming::tjp_instance(code, loc);
367
Naming::tjp_args_array(code, loc);
373
for (int i = 0; i < args; i++) {
375
Naming::tjp_instance(code, loc);
376
code << "._args[" << i << "] = (void*)&arg" << i << ";" << endl;
381
if (tjp.result() || tjp.useAction() ||
382
(tjp.proceed () && loc->proceed_needs_result ())) {
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 ())
390
code << "&(__TJP::Result&)result";
397
if (tjp.target() || tjp.useAction() ||
398
(tjp.proceed () && ti->proceed_needs_target ())) {
400
Naming::tjp_instance(code, loc);
401
code << "._target = ";
402
if (ti->tjp_target () && WeaverBase::needs_this (ti->tjp_target())) {
404
if (tjp.useAction ())
407
code << "__TJP::Target*)";
410
case JoinPointLoc::Construction:
411
case JoinPointLoc::Destruction:
412
case JoinPointLoc::Method:
415
case JoinPointLoc::MethodCall:
427
if (tjp.that() || tjp.useAction() ||
428
(tjp.proceed () && ti->proceed_needs_that ())) {
430
Naming::tjp_instance(code, loc);
432
if (ti->tjp_that () && WeaverBase::needs_this (ti->tjp_that())) {
434
if (tjp.useAction ())
437
code << "__TJP::That*)";
440
case JoinPointLoc::Construction:
441
case JoinPointLoc::Destruction:
442
case JoinPointLoc::Method:
445
case JoinPointLoc::MethodCall:
457
if (tjp.useAction () ||
458
(tjp.proceed () && ti->proceed_needs_fptr ())) {
460
Naming::tjp_instance(code, loc);
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");