[aspectc-user] Can I pass tjp as a parameter?

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Tue Sep 21 18:18:17 CEST 2004


Hi,

GL.Guo wrote:
> Hi,
>     I want pass tjp to a method.
>    eg:f(JoinPoint *jp);
> but how can i Include file that has JoinPoint Class?
> Is tjp's type is JoinPoint?
>                 yours
>                          Ray

The JoinPoint class is not defined in a separate header file.
It is a built-in data type that varies for each join point. Therefore,
you can't pass tjp as a function argument.

However tjp's type JoinPoint can be used by advice to instantiate
a template. Such templates can get tjp as an argument, e.g.

#include <iostream>
using namespace std;

template <int I> struct ArgPrinter {
  template <class JP> static inline void work (JP &tjp) {
    ArgPrinter<I - 1>::work (tjp);
    cout << *tjp.template arg<I - 1> ();
  }
};

template <> struct ArgPrinter<0> {
  template <class JP> static inline void work (JP &tjp) {}
};

aspect Trace {
  advice execution("% main(...)") : before()  {
    tjp->arg<0>(); // ugly workaround
    ArgPrinter<JoinPoint::ARGS>::work (*tjp);
  }
};

int main (int argc, char**argv) {
  cout << "Hello\n";
}

This feature is not yet documented, because the current weaknesses
in the template analysis don't allow to detect that arg() is used in an
instantiated template. Therefore, the ugly workaround (see comment)
is needed.

Olaf



More information about the aspectc-user mailing list