gwenhywfar 5.14.1
tm2c_slot.c
Go to the documentation of this file.
1/***************************************************************************
2 begin : Thu Jul 02 2009
3 copyright : (C) 2018 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * Please see toplevel file COPYING for license details *
8 ***************************************************************************/
9
10#ifdef HAVE_CONFIG_H
11# include <config.h>
12#endif
13
14
15#include "tm2c_slot.h"
16#include "tm2c_misc.h"
17
18#include <gwenhywfar/debug.h>
19
20#include <ctype.h>
21
22
23
25{
26 GWEN_BUFFER *tbuf;
27 const char *s;
29 TYPEMAKER2_SLOT_LIST *slotList;
30
32 tbuf=GWEN_Buffer_new(0, 256, 0, 1);
33
34 slotList=Typemaker2_Type_GetSlots(ty);
35 if (slotList) {
36 TYPEMAKER2_SLOT *slot;
37
38 /* private prototypes */
39 GWEN_Buffer_AppendString(tbuf, "/* slot functions */\n");
40 slot=Typemaker2_Slot_List_First(slotList);
41 while (slot) {
42
43 /* callback function */
44 GWEN_Buffer_AppendString(tbuf, "static int GWENHYWFAR_CB ");
47 GWEN_Buffer_AppendString(tbuf, "_SlotCallback_");
49 GWEN_Buffer_AppendByte(tbuf, toupper(*s));
50 GWEN_Buffer_AppendString(tbuf, s+1);
51 GWEN_Buffer_AppendString(tbuf, "(GWEN_SLOT *slot, void *userData, void *p1, void *p2, int p3, int p4);\n");
52
53 slot=Typemaker2_Slot_List_Next(slot);
54 }
55
58
59 /* public prototypes */
60 GWEN_Buffer_AppendString(tbuf, "/* slot functions */\n");
61 slot=Typemaker2_Slot_List_First(slotList);
62 while (slot) {
63 /* GetSlot */
65 if (s) {
67 GWEN_Buffer_AppendString(tbuf, " ");
68 }
69 GWEN_Buffer_AppendString(tbuf, "GWEN_SLOT *");
72 GWEN_Buffer_AppendString(tbuf, "_GetSlot_");
74 GWEN_Buffer_AppendByte(tbuf, toupper(*s));
75 GWEN_Buffer_AppendString(tbuf, s+1);
76 GWEN_Buffer_AppendString(tbuf, "(const ");
79 GWEN_Buffer_AppendString(tbuf, " *p_struct);\n");
80
81
82 slot=Typemaker2_Slot_List_Next(slot);
83 }
86
87 /* implementation */
88 GWEN_Buffer_AppendString(tbuf, "/* slot functions */\n");
89 slot=Typemaker2_Slot_List_First(slotList);
90 while (slot) {
91
92 /* callback function */
93 GWEN_Buffer_AppendString(tbuf, "static int GWENHYWFAR_CB ");
96 GWEN_Buffer_AppendString(tbuf, "_SlotCallback_");
98 GWEN_Buffer_AppendByte(tbuf, toupper(*s));
99 GWEN_Buffer_AppendString(tbuf, s+1);
100 GWEN_Buffer_AppendString(tbuf, "(GWEN_SLOT *slot, void *userData, void *p1, void *p2, int p3, int p4) {\n");
101
102 GWEN_Buffer_AppendString(tbuf, " ");
105 GWEN_Buffer_AppendString(tbuf, " *p_struct;\n");
106
107 GWEN_Buffer_AppendString(tbuf, "\n");
108 GWEN_Buffer_AppendString(tbuf, " p_struct=(");
110 GWEN_Buffer_AppendString(tbuf, "*) userData;\n");
111
112 GWEN_Buffer_AppendString(tbuf, " return ");
115 GWEN_Buffer_AppendString(tbuf, "_");
117 GWEN_Buffer_AppendByte(tbuf, toupper(*s));
118 GWEN_Buffer_AppendString(tbuf, s+1);
119 GWEN_Buffer_AppendString(tbuf, "(p_struct");
120
121 s=Typemaker2_Slot_GetParamType1(slot); /* param 1 */
122 if (s && *s && strcasecmp(s, "none")) {
123 GWEN_Buffer_AppendString(tbuf, ", (");
125 GWEN_Buffer_AppendString(tbuf, ") p1");
126 }
127 s=Typemaker2_Slot_GetParamType2(slot); /* param 2 */
128 if (s && *s && strcasecmp(s, "none")) {
129 GWEN_Buffer_AppendString(tbuf, ", (");
131 GWEN_Buffer_AppendString(tbuf, ") p2");
132 }
134 GWEN_Buffer_AppendString(tbuf, ", p3");
136 GWEN_Buffer_AppendString(tbuf, ", p4");
137
138 GWEN_Buffer_AppendString(tbuf, ");\n");
139
140 GWEN_Buffer_AppendString(tbuf, "}\n\n");
141
142
143 /* GetSlot */
144 GWEN_Buffer_AppendString(tbuf, "GWEN_SLOT *");
147 GWEN_Buffer_AppendString(tbuf, "_GetSlot_");
149 GWEN_Buffer_AppendByte(tbuf, toupper(*s));
150 GWEN_Buffer_AppendString(tbuf, s+1);
151 GWEN_Buffer_AppendString(tbuf, "(const ");
154 GWEN_Buffer_AppendString(tbuf, " *p_struct) {\n");
155
156 GWEN_Buffer_AppendString(tbuf, " assert(p_struct);\n");
157 GWEN_Buffer_AppendString(tbuf, " return GWEN_SignalObject_FindSlot(p_struct->_signalObject, ");
158 s=Typemaker2_Slot_GetName(slot); /* name */
159 GWEN_Buffer_AppendString(tbuf, "\"");
161 GWEN_Buffer_AppendString(tbuf, "\", ");
162 s=Typemaker2_Slot_GetParamType1(slot); /* param 1 */
163 GWEN_Buffer_AppendString(tbuf, "\"");
164 GWEN_Buffer_AppendString(tbuf, s?s:"none");
165 GWEN_Buffer_AppendString(tbuf, "\", ");
166 s=Typemaker2_Slot_GetParamType2(slot); /* param 2 */
167 GWEN_Buffer_AppendString(tbuf, "\"");
168 GWEN_Buffer_AppendString(tbuf, s?s:"none");
169 GWEN_Buffer_AppendString(tbuf, "\");\n");
170
171 GWEN_Buffer_AppendString(tbuf, "}\n");
172 GWEN_Buffer_AppendString(tbuf, "\n");
173
174 slot=Typemaker2_Slot_List_Next(slot);
175 }
177 GWEN_Buffer_Reset(tbuf);
178
179 }
180 GWEN_Buffer_free(tbuf);
181
182 return 0;
183}
184
185
186
188{
189 GWEN_BUFFER *tbuf;
190 const char *s;
191 TYPEMAKER2_VIRTUALFN_LIST *fnList;
192 TYPEMAKER2_SLOT_LIST *slotList;
193
194 tbuf=GWEN_Buffer_new(0, 256, 0, 1);
196
197 slotList=Typemaker2_Type_GetSlots(ty);
198 if (slotList) {
199 TYPEMAKER2_SLOT *slot;
200
201 slot=Typemaker2_Slot_List_First(slotList);
202 while (slot) {
204 TYPEMAKER2_VIRTUALFN_PARAM_LIST *plist;
205
206 /* callback function */
208 GWEN_Buffer_AppendByte(tbuf, tolower(*s));
209 GWEN_Buffer_AppendString(tbuf, s+1);
210
213
214 /* name */
216
217 s=Typemaker2_Slot_GetParamType1(slot); /* param 1 */
218 if (s && *s && strcasecmp(s, "none")) {
220
223 Typemaker2_VirtualFn_Param_List_Add(prm, plist);
224 }
225 s=Typemaker2_Slot_GetParamType2(slot); /* param 2 */
226 if (s && *s && strcasecmp(s, "none")) {
228
231 Typemaker2_VirtualFn_Param_List_Add(prm, plist);
232 }
235
238 Typemaker2_VirtualFn_Param_List_Add(prm, plist);
239 }
242
245 Typemaker2_VirtualFn_Param_List_Add(prm, plist);
246 }
247
251 Typemaker2_VirtualFn_SetDefaultReturnValue(fn, "GWEN_ERROR_NOT_IMPLEMENTED");
252
254
255 Typemaker2_VirtualFn_List_Add(fn, fnList);
256
257 slot=Typemaker2_Slot_List_Next(slot);
258 }
259 }
260 GWEN_Buffer_free(tbuf);
261
262 return 0;
263}
264
265
266
268{
269 TYPEMAKER2_VIRTUALFN_LIST *fnList;
270
272 if (fnList) {
274
275 fn=Typemaker2_VirtualFn_List_First(fnList);
276 while (fn) {
277 TYPEMAKER2_VIRTUALFN *fnNext;
278
279 fnNext=Typemaker2_VirtualFn_List_Next(fn);
281 Typemaker2_VirtualFn_List_Del(fn);
283 }
284 fn=fnNext;
285 }
286 }
287}
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition buffer.c:42
void GWEN_Buffer_Reset(GWEN_BUFFER *bf)
Definition buffer.c:653
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition buffer.c:89
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition buffer.c:992
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition buffer.c:235
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
Definition buffer.c:393
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition buffer.h:38
int TM2C_AddVirtualFnsFromSlots(TYPEMAKER2_TYPE *ty)
Definition tm2c_slot.c:187
void TM2C_DelVirtualFnsFromSlots(TYPEMAKER2_TYPE *ty)
Definition tm2c_slot.c:267
int TM2C_BuildSlotFunctions(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPE *ty)
Definition tm2c_slot.c:24
void Typemaker2_Builder_AddCode(TYPEMAKER2_BUILDER *tb, const char *s)
Definition tm_builder.c:204
void Typemaker2_Builder_AddPublicDeclaration(TYPEMAKER2_BUILDER *tb, const char *s)
Definition tm_builder.c:172
void Typemaker2_Builder_AddPrivateDeclaration(TYPEMAKER2_BUILDER *tb, const char *s)
Definition tm_builder.c:196
TYPEMAKER2_TYPEMANAGER * Typemaker2_Builder_GetTypeManager(const TYPEMAKER2_BUILDER *tb)
Definition tm_builder.c:133
struct TYPEMAKER2_BUILDER TYPEMAKER2_BUILDER
Definition tm_builder.h:26
uint32_t Typemaker2_Slot_GetFlags(const TYPEMAKER2_SLOT *p_struct)
Definition tm_slot.c:146
const char * Typemaker2_Slot_GetParamType2(const TYPEMAKER2_SLOT *p_struct)
Definition tm_slot.c:140
const char * Typemaker2_Slot_GetName(const TYPEMAKER2_SLOT *p_struct)
Definition tm_slot.c:128
const char * Typemaker2_Slot_GetParamType1(const TYPEMAKER2_SLOT *p_struct)
Definition tm_slot.c:134
struct TYPEMAKER2_SLOT TYPEMAKER2_SLOT
Definition tm_slot.h:27
#define TYPEMAKER2_SLOT_FLAGS_USE_PARAM4
Definition tm_slot.h:18
#define TYPEMAKER2_SLOT_FLAGS_USE_PARAM3
Definition tm_slot.h:17
const char * Typemaker2_Type_GetIdentifier(const TYPEMAKER2_TYPE *ty)
Definition tm_type.c:585
TYPEMAKER2_SLOT_LIST * Typemaker2_Type_GetSlots(const TYPEMAKER2_TYPE *ty)
Definition tm_type.c:755
TYPEMAKER2_VIRTUALFN_LIST * Typemaker2_Type_GetVirtualFns(const TYPEMAKER2_TYPE *ty)
Definition tm_type.c:737
const char * Typemaker2_Type_GetPrefix(const TYPEMAKER2_TYPE *ty)
Definition tm_type.c:607
struct TYPEMAKER2_TYPE TYPEMAKER2_TYPE
Definition tm_type.h:21
@ TypeMaker2_Access_Public
Definition tm_type.h:86
const char * Typemaker2_TypeManager_GetApiDeclaration(const TYPEMAKER2_TYPEMANAGER *tym)
struct TYPEMAKER2_TYPEMANAGER TYPEMAKER2_TYPEMANAGER
void Typemaker2_VirtualFn_SetDefaultReturnValue(TYPEMAKER2_VIRTUALFN *vf, const char *s)
void Typemaker2_VirtualFn_SetName(TYPEMAKER2_VIRTUALFN *vf, const char *s)
void Typemaker2_VirtualFn_Param_SetType(TYPEMAKER2_VIRTUALFN_PARAM *prm, const char *s)
uint32_t Typemaker2_VirtualFn_GetFlags(const TYPEMAKER2_VIRTUALFN *vf)
void Typemaker2_VirtualFn_free(TYPEMAKER2_VIRTUALFN *vf)
TYPEMAKER2_VIRTUALFN * Typemaker2_VirtualFn_new()
TYPEMAKER2_VIRTUALFN_PARAM * Typemaker2_VirtualFn_Param_new()
void Typemaker2_VirtualFn_SetAccess(TYPEMAKER2_VIRTUALFN *vf, int i)
void Typemaker2_VirtualFn_SetReturnType(TYPEMAKER2_VIRTUALFN *vf, const char *s)
void Typemaker2_VirtualFn_AddFlags(TYPEMAKER2_VIRTUALFN *vf, uint32_t fl)
TYPEMAKER2_VIRTUALFN_PARAM_LIST * Typemaker2_VirtualFn_GetParamTypeList(const TYPEMAKER2_VIRTUALFN *vf)
void Typemaker2_VirtualFn_SetLocation(TYPEMAKER2_VIRTUALFN *vf, const char *s)
struct TYPEMAKER2_VIRTUALFN TYPEMAKER2_VIRTUALFN
struct TYPEMAKER2_VIRTUALFN_PARAM TYPEMAKER2_VIRTUALFN_PARAM
#define TYPEMAKER2_VIRTUALFN_FLAGS_FROMSLOT