-
-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathEduCfrontVtable7Test.expect
More file actions
131 lines (105 loc) · 2.77 KB
/
EduCfrontVtable7Test.expect
File metadata and controls
131 lines (105 loc) · 2.77 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
/*************************************************************************************
* 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 Fruit
{
__mptr * __vptrFruit;
double md;
} Fruit;
inline void Destructor_Fruit(Fruit * __this)
{
__this->__vptrFruit = __vtbl_array[0];
puts("~Fruit");
}
inline void FunFruit(Fruit * __this)
{
puts("Fruit's Fun");
}
inline Fruit * Constructor_Fruit(Fruit * __this)
{
__this->__vptrFruit = __vtbl_array[0];
return __this;
}
typedef struct Apple
{
__mptr * __vptrFruit;
double md;
int mX;
} Apple;
inline void FunApple(Apple * __this)
{
printf("Apple's Fun: %d\n", __this->mX);
}
inline void Destructor_Apple(Apple * __this)
{
Destructor_Fruit((Fruit *)__this);
}
inline Apple * Constructor_Apple(Apple * __this)
{
Constructor_Fruit((Fruit *)__this);
__this->__vptrFruit = __vtbl_array[1];
__this->mX = 5;
return __this;
}
typedef struct PinkLady
{
__mptr * __vptrFruit;
double md;
int mX;
int mApple;
} PinkLady;
inline void FunPinkLady(PinkLady * __this)
{
printf("Pink Ladies Fun: %d\n", __this->mApple);
}
inline void Destructor_PinkLady(PinkLady * __this)
{
Destructor_Apple((Apple *)__this);
}
inline PinkLady * Constructor_PinkLady(PinkLady * __this)
{
Constructor_Apple((Apple *)__this);
__this->__vptrFruit = __vtbl_array[2];
__this->mApple = 8;
return __this;
}
int __main(void)
{
PinkLady delicious;
Constructor_PinkLady((PinkLady *)&delicious);
(*((void (*)(PinkLady *))((&delicious)->__vptrFruit[1]).f))((((PinkLady *)(char *)(&delicious)) + ((&delicious)->__vptrFruit[1]).d));
Fruit * f = (Fruit *)&delicious;
(*((void (*)(Fruit *))((f)->__vptrFruit[1]).f))((((Fruit *)(char *)(f)) + ((f)->__vptrFruit[1]).d));
return 0;
(*((void (*)(PinkLady *))((&delicious)->__vptrFruit[0]).f))((((PinkLady *)(char *)(&delicious)) + ((&delicious)->__vptrFruit[0]).d));
}
int main(void)
{
__cxa_start();
int ret = __main();
__cxa_atexit();
return ret;
/* ret // lifetime ends here */
}
__mptr __vtbl_Fruit[2] = {{0, 0, (__vptp)Destructor_Fruit}, {0, 0, (__vptp)FunFruit}};
__mptr __vtbl_Apple[2] = {{0, 0, (__vptp)Destructor_Apple}, {0, 0, (__vptp)FunApple}};
__mptr __vtbl_PinkLady[2] = {{0, 0, (__vptp)Destructor_PinkLady}, {0, 0, (__vptp)FunPinkLady}};
__mptr * __vtbl_array[3] = {__vtbl_Fruit, __vtbl_Apple, __vtbl_PinkLady};
void __cxa_start(void)
{
}
void __cxa_atexit(void)
{
}