~ubuntu-branches/ubuntu/wily/aspectc++/wily

« back to all changes in this revision

Viewing changes to AspectC++/tests/Introspection/main.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-06-15 10:17:02 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090615101702-qsr30iptwbxylmo2
Tags: 1.0pre4~svn.20090615-1
* New upstream release.
* don't ignore errors in the postrm script
* avoid spurious creation of empty dir ./usr/sbin/
* improve short descriptions of libpuma-doc and libpuma-dev
* bump Standards-Version to 3.8.1
* bump debhelper compat level to level 7 (latest in stable)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
template <typename T, bool AVAILABLE=(bool)AC::TypeInfo<T>::AVAILABLE>
7
7
struct PrinterSelector;
8
8
void print (bool c) { cout << (c ? "true" : "false"); }
 
9
void print (unsigned char c) { cout << (int)c; }
9
10
void print (int c) { cout << c; }
10
11
void print (float f) { cout << f; }
11
12
void print (const char *c) { if (c) cout << "\"" << c << "\""; else cout << "<null>"; }
19
20
  print (*c);
20
21
}
21
22
 
 
23
template <typename T>
 
24
struct AP {
 
25
    static void print (T c) { ::print (c); }
 
26
};
 
27
template<typename T, unsigned int N> struct AP<T[N]> {
 
28
    template <typename T2>
 
29
    static void print (T2 *c) {
 
30
        cout << "{ ";
 
31
        for (unsigned int i = 0; i < N; ++i) {
 
32
            cout << "[" << i << "]=";
 
33
            ::print (c[i]);
 
34
            cout << " ";
 
35
        }
 
36
        cout << "}";
 
37
    }
 
38
};
 
39
 
22
40
template<typename T, int I = AC::TypeInfo<T>::ELEMENTS> struct _Printer {
23
41
  static void print (T &c) {
24
42
      _Printer<T,I-1>::print (c);
25
43
      cout << " " << AC::TypeInfo<T>::member_name (c, I-1) << "=";
26
 
      ::print (*AC::TypeInfo<T>::template member<I-1>(&c));
 
44
      AP<typename AC::TypeInfo<T>::template Member<I-1>::ReferredType>::print(*AC::TypeInfo<T>::template member<I-1>(&c));
27
45
    }
28
46
};
29
47
template<typename T> struct _Printer<T,0> {
44
62
// =====================================================================
45
63
 
46
64
// The test code itself ...
 
65
// Led.h
 
66
typedef unsigned char unit8_t;
 
67
 
 
68
class LED0 {
 
69
public:
 
70
        volatile uint8_t _pad[0x2];
 
71
 
 
72
        // PINA
 
73
        volatile uint8_t
 
74
                LEDPIN  : 1,
 
75
                                : 7;
 
76
 
 
77
        // DDRA
 
78
        volatile uint8_t
 
79
                LEDDDR  : 1,
 
80
                                : 7;
 
81
 
 
82
        // PORTA
 
83
        volatile uint8_t
 
84
                LEDPORT : 1,
 
85
                                : 7;
 
86
};
 
87
 
 
88
aspect Led {
 
89
        pointcut ledfunc() = "LED%";
 
90
 
 
91
        advice ledfunc() : slice class S {
 
92
        public:
 
93
                S() {
 
94
                        LEDPORT = 0;
 
95
                        LEDDDR  = 1;
 
96
                }
 
97
 
 
98
                void on() {
 
99
                        LEDPORT = 1;
 
100
                }
 
101
 
 
102
                void off() {
 
103
                        LEDPORT = 0;
 
104
                }
 
105
        };
 
106
};
47
107
 
48
108
struct C {
49
109
    int i;
51
111
    const char *k;
52
112
};
53
113
 
 
114
C inner_c = { 43, 2.1, 0 };
 
115
C *cptr = &inner_c;
 
116
 
54
117
struct D {
55
118
    bool foo;
56
119
    int id;
57
120
    float size;
58
121
    const char *name;
59
 
    C c;
60
 
} d = {true, 42, 1.8, "Olaf Spinczyk", { 43, 2.1, 0 }};
 
122
    C **c;
 
123
    struct Inner {
 
124
      int inner;
 
125
    } i;
 
126
    int array[5];
 
127
} d = {true, 42, 1.8, "Olaf Spinczyk", &cptr, { 42 }, { 1,2,3 }};
61
128
 
62
129
struct F; // an incomplete type
 
130
LED0 l0; // constructed type with bit field and pad bytes
63
131
 
64
132
int main () {
65
133
    C c;
71
139
    print ((F*)0); cout << endl;
72
140
    print (cout); cout << endl;
73
141
    print (42); cout << endl;
 
142
    print (l0); cout << endl;
74
143
}