| 1 |
#include <stdio.h> |
| 2 |
|
| 3 |
class C { |
| 4 |
int _priv_attr; |
| 5 |
void priv_fct () { printf (" in private function\n"); _priv_attr++; } |
| 6 |
public: |
| 7 |
C() : _priv_attr (0) {} |
| 8 |
void pub_fct () {} |
| 9 |
}; |
| 10 |
|
| 11 |
union U { |
| 12 |
int u1; |
| 13 |
char u2; |
| 14 |
}; |
| 15 |
|
| 16 |
slice class Slice { |
| 17 |
int _priv_slice_attr; |
| 18 |
class Inner { |
| 19 |
int _priv_inner_attr; |
| 20 |
public: |
| 21 |
Inner () : _priv_inner_attr (0) {} |
| 22 |
} _inner; |
| 23 |
union InnerUnion { |
| 24 |
int i; |
| 25 |
long j; |
| 26 |
} _inner_union; |
| 27 |
}; |
| 28 |
|
| 29 |
template <typename X> class T { static void f() { printf (" in private T::f()\n"); } }; |
| 30 |
|
| 31 |
int main() { |
| 32 |
C c; |
| 33 |
printf ("AspectPrivileges: Check whether aspects are friends of all classes\n"); |
| 34 |
printf ("==================================================================\n"); |
| 35 |
c.pub_fct (); |
| 36 |
printf ("==================================================================\n"); |
| 37 |
} |
| 38 |
|
| 39 |
aspect A { |
| 40 |
U _u; |
| 41 |
|
| 42 |
advice "C" : slice Slice; |
| 43 |
|
| 44 |
advice execution("void C::pub_fct()") : before () { |
| 45 |
printf ("printing private attribute\n"); |
| 46 |
printf (" private attribute: %d\n", tjp->that ()->_priv_attr); |
| 47 |
printf ("increasing private attribute by calling private member function\n"); |
| 48 |
tjp->that ()->priv_fct (); |
| 49 |
printf ("printing private attribute again\n"); |
| 50 |
printf (" private attribute: %d\n", tjp->that ()->_priv_attr); |
| 51 |
printf ("writing into private attribute of introduced class\n"); |
| 52 |
tjp->that ()->_inner._priv_inner_attr++; |
| 53 |
printf ("writing into private attribute of a union\n"); |
| 54 |
_u.u1 = 42; |
| 55 |
printf ("calling private member function of template\n"); |
| 56 |
T<int>::f(); |
| 57 |
} |
| 58 |
}; |