* Added support for multiple BOOPSI classes in one module. The class can be a general...
[AROS.git] / tools / genmodule / boopsisupport.c
blob9b98f00053415d72bd7fb9ebe47ceb9da3df5629
1 /*
2 Copyright © 1995-2005, 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 for
46 methlistit = cl->methlist;
47 methlistit != NULL;
48 methlistit = methlistit->next
51 int first = 1;
53 fprintf(out, "%s %s(", methlistit->type, methlistit->name);
55 for
57 arglistit = methlistit->arguments;
58 arglistit != NULL;
59 arglistit = arglistit->next
62 if (!first)
63 fprintf(out, ", ");
64 else
65 first = 0;
67 fprintf(out, "%s", arglistit->arg);
70 fprintf(out, ");\n");
73 fprintf
75 out,
76 "\n"
77 "\n"
78 "/*** Dispatcher *************************************************************/\n"
79 "BOOPSI_DISPATCHER(IPTR, %s_Dispatcher, CLASS, self, message)\n"
80 "{\n"
81 " switch (message->MethodID)\n"
82 " {\n",
83 cl->basename
86 for
88 methlistit = cl->methlist;
89 methlistit != NULL;
90 methlistit = methlistit->next
93 char *type;
95 fprintf(out, " ");
96 for
98 aliasit = methlistit->aliases;
99 aliasit != NULL;
100 aliasit = aliasit->next
103 fprintf(out, "case %s: ", aliasit->s);
105 if (strcmp(methlistit->type, "void") != 0)
106 fprintf(out, "return (IPTR)");
107 fprintf(out,"%s(", methlistit->name);
109 if (methlistit->argcount != 3)
111 fprintf(stderr, "Method \"%s\" has wrong number of arguments\n", methlistit->name);
112 exit(20);
115 arglistit = methlistit->arguments;
116 fprintf(out, "CLASS, ");
118 arglistit = arglistit->next;
119 type = getargtype(arglistit);
120 if (type == NULL)
122 fprintf(stderr,
123 "Argument \"%s\" not understood for function %s\n",
124 arglistit->arg, methlistit->name
126 exit(20);
128 fprintf(out, "(%s)self, ", type);
129 free(type);
131 arglistit = arglistit->next;
132 type = getargtype(arglistit);
133 if (type == NULL)
135 fprintf(stderr,
136 "Argument \"%s\" not understood for function %s\n",
137 arglistit->arg, methlistit->name
139 exit(20);
141 fprintf(out, "(%s) message);", type);
142 free(type);
144 if (strcmp(methlistit->type, "void") == 0)
145 fprintf(out, " break;");
147 fprintf(out, "\n");
150 fprintf
152 out,
153 " default: return DoSuperMethodA(CLASS, self, message);\n"
154 " }\n"
155 " \n"
156 " return (IPTR) NULL;\n"
157 "}\n"
158 "BOOPSI_DISPATCHER_END\n"
161 else
163 fprintf
165 out,
166 "\n"
167 "\n"
168 "/*** Custom dispatcher prototype ********************************************/\n"
169 "BOOPSI_DISPATCHER_PROTO(IPTR, %s, CLASS, object, message);\n",
170 cl->dispatcher
175 void writeclassinit(FILE *out, struct classinfo *cl)
177 struct functionhead *methlistit;
178 struct functionarg *arglistit;
179 unsigned int lvo;
181 fprintf
183 out,
184 "/* Initialisation routines for a BOOPSI class */\n"
185 "/* ===========================================*/\n"
186 "\n"
189 writeboopsidispatcher(out, cl);
191 if (cl->classdatatype == NULL)
192 fprintf(out, "#define %s_DATA_SIZE (0)\n", cl->basename);
193 else
194 fprintf(out,
195 "#define %s_DATA_SIZE (sizeof(%s))\n",
196 cl->basename, cl->classdatatype
199 fprintf
201 out,
202 "\n"
203 "\n"
204 "/*** Library startup and shutdown *******************************************/\n"
205 "AROS_SET_LIBFUNC(BOOPSI_%s_Startup, LIBBASETYPE, LIBBASE)\n"
206 "{\n"
207 " AROS_SET_LIBFUNC_INIT\n"
208 "\n"
209 " struct IClass *cl = NULL;\n"
210 " \n"
211 " cl = MakeClass(%s, %s, NULL, %s_DATA_SIZE, 0);\n"
212 " if (cl != NULL)\n"
213 " {\n"
214 "#if %s_STORE_CLASSPTR\n"
215 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
216 "#endif\n",
217 cl->basename,
218 cl->classid, cl->superclass, cl->basename,
219 cl->basename,
220 cl->basename
223 if (cl->dispatcher == NULL)
224 fprintf(out,
225 " cl->cl_Dispatcher.h_Entry = (APTR)%s_Dispatcher;\n",
226 cl->basename
228 else
229 fprintf(out,
230 " cl->cl_Dispatcher.h_Entry = (APTR)%s;\n",
231 cl->dispatcher
234 fprintf
236 out,
237 " cl->cl_Dispatcher.h_SubEntry = NULL;\n"
238 " cl->cl_UserData = (IPTR)LIBBASE\n;"
241 if (!(cl->options & COPTION_PRIVATE))
242 fprintf
244 out,
245 "\n"
246 " AddClass(cl);\n"
249 fprintf
251 out,
252 "\n"
253 " return TRUE;\n"
254 " }\n"
255 " else\n"
256 " return FALSE;\n"
257 " \n"
258 " AROS_SET_LIBFUNC_EXIT\n"
259 "}\n"
260 "\n"
261 "AROS_SET_LIBFUNC(BOOPSI_%s_Shutdown, LIBBASETYPE, LIBBASE)\n"
262 "{\n"
263 " AROS_SET_LIBFUNC_INIT\n"
264 " \n"
265 " if (%s_CLASSPTR_FIELD(LIBBASE) != NULL)\n"
266 " {\n",
267 cl->basename, cl->basename
269 if (!(cl->options & COPTION_PRIVATE))
270 fprintf(out,
271 " RemoveClass(%s_CLASSPTR_FIELD(LIBBASE));\n",
272 cl->basename
274 fprintf
276 out,
277 " FreeClass(%s_CLASSPTR_FIELD(LIBBASE));\n"
278 "#if %s_STORE_CLASSPTR\n"
279 " %s_CLASSPTR_FIELD(LIBBASE) = NULL;\n"
280 "#endif\n"
281 " }\n"
282 "\n"
283 " return TRUE;\n"
284 "\n"
285 " AROS_SET_LIBFUNC_EXIT\n"
286 "}\n"
287 "\n"
288 "ADD2INITCLASSES(BOOPSI_%s_Startup, %d);\n"
289 "ADD2EXPUNGECLASSES(BOOPSI_%s_Shutdown, %d);\n",
290 cl->basename,
291 cl->basename,
292 cl->basename,
293 cl->basename, -cl->initpri,
294 cl->basename, -cl->initpri