File: main.cc

package info (click to toggle)
aspectc%2B%2B 1.0pre4~svn.20090918-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 117,308 kB
  • ctags: 410,601
  • sloc: cpp: 1,883,007; ansic: 17,279; sh: 2,190; makefile: 1,088
file content (96 lines) | stat: -rw-r--r-- 1,673 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "stdio.h"

// aspects; that() used for each kind of object

aspect On {
  pointcut virtual kind() = 0;
  advice kind () && !within("On") : after () {
    printf ("%s\n", JoinPoint::signature ());
  }
};

aspect OnA : public On { pointcut kind () = that("A"); };
aspect OnB : public On { pointcut kind () = that("B"); };
aspect OnC : public On { pointcut kind () = that("C"); };
aspect OnD : public On { pointcut kind () = that("D"); };
aspect OnTargetCorD : public On {
  pointcut kind () = target("C") || target("D");
//   pointcut kind () = that(derived("C%") && !base("A"||"B")) || target("D");
};
aspect OnThatnotCandnotD : public On {
  pointcut kind () = !that("C") && !that("D") && execution("% %::%(...)");
};

// class hierarchy; each class has an inline, static and non-inline function
//
//     A (root)
//     |
//     B
//    / \
//   C   D (leafs)

class A {
public:
  void f () {}
  void g ();
  static void h () {}
};
void A::g () {}

class B : public A {
public:
  void f () {}
  void g ();
  static void h () {}
};
void B::g () {}

class C : public B {
public:
  void f () {}
  void g ();
  static void h () {}
};
void C::g () {}

class D : public B {
public:
  void f () {}
  void g ();
  static void h () {}
};
void D::g () {}

// ordinary functions
void a () {}

void b ();
void b () {}

// testcode
int main () {
  printf ("ordinary functions (there should be no advice)\n");
  a ();
  b ();
  printf ("on A:\n");
  A a;
  a.f ();
  a.g ();
  a.h ();
  printf ("on B:\n");
  B b;
  b.f ();
  b.g ();
  b.h ();
  printf ("on C:\n");
  C c;
  c.f ();
  c.g ();
  c.h ();
  printf ("on D:\n");
  D d;
  d.f ();
  d.g ();
  d.h ();
  return 0;
}