-
-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathEduCfrontVtable4Test.expect
More file actions
139 lines (111 loc) · 2.45 KB
/
EduCfrontVtable4Test.expect
File metadata and controls
139 lines (111 loc) · 2.45 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*************************************************************************************
* NOTE: This an educational hand-rolled transformation. Things can be incorrect or *
* buggy. *
*************************************************************************************/
void __cxa_start(void);
void __cxa_atexit(void);
typedef int (*__vptp)();
struct __mptr
{
short d;
short i;
__vptp f;
};
extern struct __mptr* __vtbl_array[];
#include <cstdio>
typedef struct A
{
__mptr * __vptrA;
double md;
} A;
inline void Destructor_A(A * __this)
{
__this->__vptrA = __vtbl_array[0];
puts("dtor");
}
inline void FunA(A * __this)
{
puts("fun a");
}
inline A * Constructor_A(A * __this)
{
__this->__vptrA = __vtbl_array[0];
return __this;
}
typedef struct B
{
__mptr * __vptrA;
double md;
int mX;
} B;
inline void FunB(B * __this)
{
printf("fun b: %d\n", __this->mX);
}
inline void OtherB(B * __this)
{
}
inline void Destructor_B(B * __this)
{
Destructor_A((A *)__this);
}
inline B * Constructor_B(B * __this)
{
Constructor_A((A *)__this);
__this->__vptrA = __vtbl_array[1];
__this->mX = 5;
return __this;
}
typedef struct C
{
__mptr * __vptrA;
double md;
int mX;
int mB;
} C;
inline void FunC(C * __this)
{
printf("fun c: %d\n", __this->mB);
}
inline void OtherC(C * __this)
{
}
inline void Destructor_C(C * __this)
{
Destructor_B((B *)__this);
}
inline C * Constructor_C(C * __this)
{
Constructor_B((B *)__this);
__this->__vptrA = __vtbl_array[2];
__this->mB = 8;
return __this;
}
int __main(void)
{
C b;
Constructor_C((C *)&b);
(*((void (*)(C *))((&b)->__vptrA[1]).f))((((C *)(char *)(&b)) + ((&b)->__vptrA[1]).d));
A * a = (A *)&b;
(*((void (*)(A *))((a)->__vptrA[1]).f))((((A *)(char *)(a)) + ((a)->__vptrA[1]).d));
return 0;
(*((void (*)(C *))((&b)->__vptrA[0]).f))((((C *)(char *)(&b)) + ((&b)->__vptrA[0]).d));
}
int main(void)
{
__cxa_start();
int ret = __main();
__cxa_atexit();
return ret;
/* ret // lifetime ends here */
}
__mptr __vtbl_A[2] = {{0, 0, (__vptp)Destructor_A}, {0, 0, (__vptp)FunA}};
__mptr __vtbl_B[3] = {{0, 0, (__vptp)Destructor_B}, {0, 0, (__vptp)FunB}, {0, 0, (__vptp)OtherB}};
__mptr __vtbl_C[3] = {{0, 0, (__vptp)Destructor_C}, {0, 0, (__vptp)FunC}, {0, 0, (__vptp)OtherC}};
__mptr * __vtbl_array[3] = {__vtbl_A, __vtbl_B, __vtbl_C};
void __cxa_start(void)
{
}
void __cxa_atexit(void)
{
}