Import SB128-v5.24 to main branch
[AROS.git] / tools / genmodule / boopsisupport.c
blob87f53a0163c1fc3cb99eab401cf0f74f414113c7
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Support function for generating code for BOOPSI classes. Part of genmodule.
6 */
7 #include "config.h"
8 #include "functionhead.h"
9 #include "boopsisupport.h"
11 void writeboopsiincludes(FILE *out)
13 fprintf
15 out,
16 "#include <intuition/classes.h>\n"
17 "#include <intuition/classusr.h>\n"
18 "\n"
19 "#include <proto/utility.h>\n"
20 "#include <proto/intuition.h>\n"
21 "\n"
22 "#include <aros/symbolsets.h>\n"
23 "\n"
27 void writeboopsidispatcher(FILE *out, struct classinfo *cl)
29 struct functionhead *methlistit;
30 struct functionarg *arglistit;
31 struct stringlist *aliasit;
32 int i;
34 if (cl->dispatcher == NULL)
36 fprintf
38 out,
39 "\n"
40 "\n"
41 "/*** Prototypes *************************************************************/\n"
44 writefuncdefs(out, NULL, cl->methlist);
46 fprintf
48 out,
49 "\n"
50 "\n"
51 "/*** Dispatcher *************************************************************/\n"
52 "BOOPSI_DISPATCHER(IPTR, %s_Dispatcher, CLASS, self, message)\n"
53 "{\n"
54 " switch (message->MethodID)\n"
55 " {\n",
56 cl->basename
59 for
61 methlistit = cl->methlist;
62 methlistit != NULL;
63 methlistit = methlistit->next
66 char *type;
68 fprintf(out, " ");
69 for
71 aliasit = methlistit->aliases;
72 aliasit != NULL;
73 aliasit = aliasit->next
76 fprintf(out, "case %s: ", aliasit->s);
78 if (strcmp(methlistit->type, "void") != 0)
79 fprintf(out, "return (IPTR)");
80 fprintf(out,"%s(", methlistit->internalname);
82 if (methlistit->argcount != 3)
84 fprintf(stderr, "Method \"%s\" has wrong number of arguments\n", methlistit->name);
85 exit(20);
88 arglistit = methlistit->arguments;
89 fprintf(out, "CLASS, ");
91 arglistit = arglistit->next;
92 type = getargtype(arglistit);
93 if (type == NULL)
95 fprintf(stderr,
96 "Argument \"%s\" not understood for function %s\n",
97 arglistit->arg, methlistit->name
99 exit(20);
101 fprintf(out, "(%s)self, ", type);
102 free(type);
104 arglistit = arglistit->next;
105 type = getargtype(arglistit);
106 if (type == NULL)
108 fprintf(stderr,
109 "Argument \"%s\" not understood for function %s\n",
110 arglistit->arg, methlistit->name
112 exit(20);
114 fprintf(out, "(%s) message);", type);
115 free(type);
117 if (strcmp(methlistit->type, "void") == 0)
118 fprintf(out, " break;");
120 fprintf(out, "\n");
123 fprintf
125 out,
126 " default: return DoSuperMethodA(CLASS, self, message);\n"
127 " }\n"
128 " \n"
129 " return (IPTR) NULL;\n"
130 "}\n"
131 "BOOPSI_DISPATCHER_END\n"
134 else
136 fprintf
138 out,
139 "\n"
140 "\n"
141 "/*** Custom dispatcher prototype ********************************************/\n"
142 "BOOPSI_DISPATCHER_PROTO(IPTR, %s, CLASS, object, message);\n",
143 cl->dispatcher
148 void writeclassinit(FILE *out, struct classinfo *cl)
150 struct functionhead *methlistit;
151 struct functionarg *arglistit;
152 unsigned int lvo;
154 fprintf
156 out,
157 "/* Initialisation routines for a BOOPSI class */\n"
158 "/* ===========================================*/\n"
159 "\n"
162 writeboopsidispatcher(out, cl);
164 if (cl->classdatatype == NULL)
165 fprintf(out, "#define %s_DATA_SIZE (0)\n", cl->basename);
166 else
167 fprintf(out,
168 "#define %s_DATA_SIZE (sizeof(%s))\n",
169 cl->basename, cl->classdatatype
172 fprintf
174 out,
175 "\n"
176 "\n"
177 "/*** Library startup and shutdown *******************************************/\n"
178 "static int BOOPSI_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
179 "{\n"
180 " struct IClass *cl = NULL;\n"
181 " \n",
182 cl->basename
184 if (cl->superclass != NULL)
185 fprintf(out,
186 " cl = MakeClass(%s, %s, NULL, %s_DATA_SIZE, 0);\n",
187 cl->classid, cl->superclass, cl->basename
189 else if (cl->superclass_field != NULL)
190 fprintf(out,
191 " cl = MakeClass(%s, NULL, LIBBASE->%s, %s_DATA_SIZE, 0);\n",
192 cl->classid, cl->superclass_field, cl->basename
194 else
196 fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n");
197 exit(20);
199 fprintf
201 out,
202 " if (cl != NULL)\n"
203 " {\n"
204 "#if %s_STORE_CLASSPTR\n"
205 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
206 "#endif\n",
207 cl->basename,
208 cl->basename
211 if (cl->dispatcher == NULL)
212 fprintf(out,
213 " cl->cl_Dispatcher.h_Entry = (APTR)%s_Dispatcher;\n",
214 cl->basename
216 else
217 fprintf(out,
218 " cl->cl_Dispatcher.h_Entry = (APTR)%s;\n",
219 cl->dispatcher
222 fprintf
224 out,
225 " cl->cl_Dispatcher.h_SubEntry = NULL;\n"
226 " cl->cl_UserData = (IPTR)LIBBASE\n;"
229 if (!(cl->options & COPTION_PRIVATE))
230 fprintf
232 out,
233 "\n"
234 " AddClass(cl);\n"
237 fprintf
239 out,
240 "\n"
241 " return TRUE;\n"
242 " }\n"
243 " else\n"
244 " return FALSE;\n"
245 "}\n"
246 "\n"
247 "static void BOOPSI_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
248 "{\n"
249 " struct IClass *cl = %s_CLASSPTR_FIELD(LIBBASE);\n"
250 " \n"
251 " if (cl != NULL)\n"
252 " {\n",
253 cl->basename, cl->basename
255 if (!(cl->options & COPTION_PRIVATE))
256 fprintf(out, " RemoveClass(cl);\n");
257 fprintf
259 out,
260 " FreeClass(cl);\n"
261 "#if %s_STORE_CLASSPTR\n"
262 " %s_CLASSPTR_FIELD(LIBBASE) = NULL;\n"
263 "#endif\n"
264 " }\n"
265 // "\n"
266 // " return TRUE;\n"
267 "}\n"
268 "\n"
269 "ADD2INITCLASSES(BOOPSI_%s_Startup, %d);\n"
270 "ADD2EXPUNGECLASSES(BOOPSI_%s_Shutdown, %d);\n",
271 cl->basename,
272 cl->basename,
273 cl->basename, -cl->initpri,
274 cl->basename, -cl->initpri