gwenhywfar  5.10.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 ");
46  GWEN_Buffer_AppendString(tbuf, s);
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 
57  GWEN_Buffer_Reset(tbuf);
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) {
66  GWEN_Buffer_AppendString(tbuf, s);
67  GWEN_Buffer_AppendString(tbuf, " ");
68  }
69  GWEN_Buffer_AppendString(tbuf, "GWEN_SLOT *");
71  GWEN_Buffer_AppendString(tbuf, s);
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 ");
78  GWEN_Buffer_AppendString(tbuf, s);
79  GWEN_Buffer_AppendString(tbuf, " *p_struct);\n");
80 
81 
82  slot=Typemaker2_Slot_List_Next(slot);
83  }
85  GWEN_Buffer_Reset(tbuf);
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 ");
95  GWEN_Buffer_AppendString(tbuf, s);
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, " ");
104  GWEN_Buffer_AppendString(tbuf, s);
105  GWEN_Buffer_AppendString(tbuf, " *p_struct;\n");
106 
107  GWEN_Buffer_AppendString(tbuf, "\n");
108  GWEN_Buffer_AppendString(tbuf, " p_struct=(");
109  GWEN_Buffer_AppendString(tbuf, s);
110  GWEN_Buffer_AppendString(tbuf, "*) userData;\n");
111 
112  GWEN_Buffer_AppendString(tbuf, " return ");
114  GWEN_Buffer_AppendString(tbuf, s);
115  GWEN_Buffer_AppendString(tbuf, "_");
116  s=Typemaker2_Slot_GetName(slot);
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, ", (");
124  GWEN_Buffer_AppendString(tbuf, s);
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, ", (");
130  GWEN_Buffer_AppendString(tbuf, s);
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 *");
146  GWEN_Buffer_AppendString(tbuf, s);
147  GWEN_Buffer_AppendString(tbuf, "_GetSlot_");
148  s=Typemaker2_Slot_GetName(slot);
149  GWEN_Buffer_AppendByte(tbuf, toupper(*s));
150  GWEN_Buffer_AppendString(tbuf, s+1);
151  GWEN_Buffer_AppendString(tbuf, "(const ");
153  GWEN_Buffer_AppendString(tbuf, s);
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, "\"");
160  GWEN_Buffer_AppendString(tbuf, s);
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 */
207  s=Typemaker2_Slot_GetName(slot);
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 }
int TM2C_BuildSlotFunctions(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPE *ty)
Definition: tm2c_slot.c:24
TYPEMAKER2_TYPEMANAGER * Typemaker2_Builder_GetTypeManager(const TYPEMAKER2_BUILDER *tb)
Definition: tm_builder.c:133
TYPEMAKER2_VIRTUALFN_LIST * Typemaker2_Type_GetVirtualFns(const TYPEMAKER2_TYPE *ty)
Definition: tm_type.c:695
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
void Typemaker2_VirtualFn_Param_SetType(TYPEMAKER2_VIRTUALFN_PARAM *prm, const char *s)
Definition: tm_virtualfn.c:466
TYPEMAKER2_SLOT_LIST * Typemaker2_Type_GetSlots(const TYPEMAKER2_TYPE *ty)
Definition: tm_type.c:713
TYPEMAKER2_VIRTUALFN_PARAM_LIST * Typemaker2_VirtualFn_GetParamTypeList(const TYPEMAKER2_VIRTUALFN *vf)
Definition: tm_virtualfn.c:370
struct TYPEMAKER2_VIRTUALFN_PARAM TYPEMAKER2_VIRTUALFN_PARAM
Definition: tm_virtualfn.h:24
#define TYPEMAKER2_VIRTUALFN_FLAGS_FROMSLOT
Definition: tm_virtualfn.h:28
struct TYPEMAKER2_SLOT TYPEMAKER2_SLOT
Definition: tm_slot.h:27
#define TYPEMAKER2_SLOT_FLAGS_USE_PARAM3
Definition: tm_slot.h:17
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
void Typemaker2_VirtualFn_SetAccess(TYPEMAKER2_VIRTUALFN *vf, int i)
Definition: tm_virtualfn.c:292
void GWEN_Buffer_Reset(GWEN_BUFFER *bf)
Definition: buffer.c:650
void Typemaker2_Builder_AddPrivateDeclaration(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:196
struct TYPEMAKER2_VIRTUALFN TYPEMAKER2_VIRTUALFN
Definition: tm_virtualfn.h:21
TYPEMAKER2_VIRTUALFN_PARAM * Typemaker2_VirtualFn_Param_new()
Definition: tm_virtualfn.c:413
void Typemaker2_VirtualFn_free(TYPEMAKER2_VIRTUALFN *vf)
Definition: tm_virtualfn.c:45
void Typemaker2_VirtualFn_AddFlags(TYPEMAKER2_VIRTUALFN *vf, uint32_t fl)
Definition: tm_virtualfn.c:262
uint32_t Typemaker2_Slot_GetFlags(const TYPEMAKER2_SLOT *p_struct)
Definition: tm_slot.c:146
const char * Typemaker2_Type_GetIdentifier(const TYPEMAKER2_TYPE *ty)
Definition: tm_type.c:543
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
Definition: buffer.c:394
const char * Typemaker2_Slot_GetName(const TYPEMAKER2_SLOT *p_struct)
Definition: tm_slot.c:128
void Typemaker2_VirtualFn_SetDefaultReturnValue(TYPEMAKER2_VIRTUALFN *vf, const char *s)
Definition: tm_virtualfn.c:356
struct TYPEMAKER2_BUILDER TYPEMAKER2_BUILDER
Definition: tm_builder.h:26
void TM2C_DelVirtualFnsFromSlots(TYPEMAKER2_TYPE *ty)
Definition: tm2c_slot.c:267
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
void Typemaker2_Builder_AddCode(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:204
struct TYPEMAKER2_TYPE TYPEMAKER2_TYPE
Definition: tm_type.h:21
#define TYPEMAKER2_SLOT_FLAGS_USE_PARAM4
Definition: tm_slot.h:18
void Typemaker2_Builder_AddPublicDeclaration(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:172
void Typemaker2_VirtualFn_SetReturnType(TYPEMAKER2_VIRTUALFN *vf, const char *s)
Definition: tm_virtualfn.c:312
struct TYPEMAKER2_TYPEMANAGER TYPEMAKER2_TYPEMANAGER
TYPEMAKER2_VIRTUALFN * Typemaker2_VirtualFn_new()
Definition: tm_virtualfn.c:30
void Typemaker2_VirtualFn_SetName(TYPEMAKER2_VIRTUALFN *vf, const char *s)
Definition: tm_virtualfn.c:180
const char * Typemaker2_Slot_GetParamType2(const TYPEMAKER2_SLOT *p_struct)
Definition: tm_slot.c:140
const char * Typemaker2_Type_GetPrefix(const TYPEMAKER2_TYPE *ty)
Definition: tm_type.c:565
void Typemaker2_VirtualFn_SetLocation(TYPEMAKER2_VIRTUALFN *vf, const char *s)
Definition: tm_virtualfn.c:204
int TM2C_AddVirtualFnsFromSlots(TYPEMAKER2_TYPE *ty)
Definition: tm2c_slot.c:187
const char * Typemaker2_Slot_GetParamType1(const TYPEMAKER2_SLOT *p_struct)
Definition: tm_slot.c:134
const char * Typemaker2_TypeManager_GetApiDeclaration(const TYPEMAKER2_TYPEMANAGER *tym)
uint32_t Typemaker2_VirtualFn_GetFlags(const TYPEMAKER2_VIRTUALFN *vf)
Definition: tm_virtualfn.c:242
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:989