grub2: bring back build of aros-side grub2 tools
[AROS.git] / tools / genmodule / boopsisupport.c
blobbe59148179ebd1f7b5a09ceba34a96c3875a0dd1
1 /*
2 Copyright © 1995-2016, 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(struct config *cfg, 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 , cl->basename
56 if (cfg->options & OPTION_DUPBASE)
57 fprintf(out,
58 " __aros_setoffsettable(CLASS->cl_UserData);\n"
60 fprintf
62 out,
63 " switch (message->MethodID)\n"
64 " {\n"
67 for
69 methlistit = cl->methlist;
70 methlistit != NULL;
71 methlistit = methlistit->next
74 char *type;
76 fprintf(out, " ");
77 for
79 aliasit = methlistit->aliases;
80 aliasit != NULL;
81 aliasit = aliasit->next
84 fprintf(out, "case %s: ", aliasit->s);
86 if (strcmp(methlistit->type, "void") != 0)
87 fprintf(out, "return (IPTR)");
88 fprintf(out,"%s(", methlistit->internalname);
90 if (methlistit->argcount != 3)
92 fprintf(stderr, "Method \"%s\" has wrong number of arguments\n", methlistit->name);
93 exit(20);
96 arglistit = methlistit->arguments;
97 fprintf(out, "CLASS, ");
99 arglistit = arglistit->next;
100 type = getargtype(arglistit);
101 if (type == NULL)
103 fprintf(stderr,
104 "Argument \"%s\" not understood for function %s\n",
105 arglistit->arg, methlistit->name
107 exit(20);
109 fprintf(out, "(%s)self, ", type);
110 free(type);
112 arglistit = arglistit->next;
113 type = getargtype(arglistit);
114 if (type == NULL)
116 fprintf(stderr,
117 "Argument \"%s\" not understood for function %s\n",
118 arglistit->arg, methlistit->name
120 exit(20);
122 fprintf(out, "(%s) message);", type);
123 free(type);
125 if (strcmp(methlistit->type, "void") == 0)
126 fprintf(out, " break;");
128 fprintf(out, "\n");
131 fprintf
133 out,
134 " default: return DoSuperMethodA(CLASS, self, message);\n"
135 " }\n"
136 " \n"
137 " return (IPTR) NULL;\n"
138 "}\n"
139 "BOOPSI_DISPATCHER_END\n"
142 else
144 fprintf
146 out,
147 "\n"
148 "\n"
149 "/*** Custom dispatcher prototype ********************************************/\n"
150 "BOOPSI_DISPATCHER_PROTO(IPTR, %s, CLASS, object, message);\n",
151 cl->dispatcher
156 void writeclassinit(struct config *cfg, FILE *out, struct classinfo *cl)
158 struct functionhead *methlistit;
159 struct functionarg *arglistit;
160 unsigned int lvo;
162 fprintf
164 out,
165 "/* Initialisation routines for a BOOPSI class */\n"
166 "/* ===========================================*/\n"
167 "\n"
170 writeboopsidispatcher(cfg, out, cl);
172 if (cl->classdatatype == NULL)
173 fprintf(out, "#define %s_DATA_SIZE (0)\n", cl->basename);
174 else
175 fprintf(out,
176 "#define %s_DATA_SIZE (sizeof(%s))\n",
177 cl->basename, cl->classdatatype
180 fprintf
182 out,
183 "\n"
184 "\n"
185 "/*** Library startup and shutdown *******************************************/\n"
186 "static int BOOPSI_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
187 "{\n"
188 " struct IClass *cl = NULL;\n"
189 " \n",
190 cl->basename
192 if (cl->superclass != NULL)
193 fprintf(out,
194 " cl = MakeClass(%s, %s, NULL, %s_DATA_SIZE, 0);\n",
195 cl->classid, cl->superclass, cl->basename
197 else if (cl->superclass_field != NULL)
198 fprintf(out,
199 " cl = MakeClass(%s, NULL, LIBBASE->%s, %s_DATA_SIZE, 0);\n",
200 cl->classid, cl->superclass_field, cl->basename
202 else
204 fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n");
205 exit(20);
207 fprintf
209 out,
210 " if (cl != NULL)\n"
211 " {\n"
212 "#if %s_STORE_CLASSPTR\n"
213 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
214 "#endif\n",
215 cl->basename,
216 cl->basename
219 if (cl->dispatcher == NULL)
220 fprintf(out,
221 " cl->cl_Dispatcher.h_Entry = (APTR)%s_Dispatcher;\n",
222 cl->basename
224 else
225 fprintf(out,
226 " cl->cl_Dispatcher.h_Entry = (APTR)%s;\n",
227 cl->dispatcher
230 fprintf
232 out,
233 " cl->cl_Dispatcher.h_SubEntry = NULL;\n"
234 " cl->cl_UserData = (IPTR)LIBBASE\n;"
237 if (!(cl->options & COPTION_PRIVATE))
238 fprintf
240 out,
241 "\n"
242 " AddClass(cl);\n"
245 fprintf
247 out,
248 "\n"
249 " return TRUE;\n"
250 " }\n"
251 " else\n"
252 " return FALSE;\n"
253 "}\n"
254 "\n"
255 "static void BOOPSI_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
256 "{\n"
257 " struct IClass *cl = %s_CLASSPTR_FIELD(LIBBASE);\n"
258 " \n"
259 " if (cl != NULL)\n"
260 " {\n",
261 cl->basename, cl->basename
263 if (!(cl->options & COPTION_PRIVATE))
264 fprintf(out, " RemoveClass(cl);\n");
265 fprintf
267 out,
268 " FreeClass(cl);\n"
269 "#if %s_STORE_CLASSPTR\n"
270 " %s_CLASSPTR_FIELD(LIBBASE) = NULL;\n"
271 "#endif\n"
272 " }\n"
273 // "\n"
274 // " return TRUE;\n"
275 "}\n"
276 "\n"
277 "ADD2INITCLASSES(BOOPSI_%s_Startup, %d)\n"
278 "ADD2EXPUNGECLASSES(BOOPSI_%s_Shutdown, %d)\n",
279 cl->basename,
280 cl->basename,
281 cl->basename, -cl->initpri,
282 cl->basename, -cl->initpri