2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Support function for generating code for BOOPSI classes. Part of genmodule.
8 #include "functionhead.h"
9 #include "boopsisupport.h"
11 void writeboopsiincludes(FILE *out
)
16 "#include <intuition/classes.h>\n"
17 "#include <intuition/classusr.h>\n"
19 "#include <proto/utility.h>\n"
20 "#include <proto/intuition.h>\n"
22 "#include <aros/symbolsets.h>\n"
27 void writeboopsidispatcher(FILE *out
, struct classinfo
*cl
)
29 struct functionhead
*methlistit
;
30 struct functionarg
*arglistit
;
31 struct stringlist
*aliasit
;
34 if (cl
->dispatcher
== NULL
)
41 "/*** Prototypes *************************************************************/\n"
46 methlistit
= cl
->methlist
;
48 methlistit
= methlistit
->next
53 fprintf(out
, "%s %s(", methlistit
->type
, methlistit
->name
);
57 arglistit
= methlistit
->arguments
;
59 arglistit
= arglistit
->next
67 fprintf(out
, "%s", arglistit
->arg
);
78 "/*** Dispatcher *************************************************************/\n"
79 "BOOPSI_DISPATCHER(IPTR, %s_Dispatcher, CLASS, self, message)\n"
81 " switch (message->MethodID)\n"
88 methlistit
= cl
->methlist
;
90 methlistit
= methlistit
->next
98 aliasit
= methlistit
->aliases
;
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
);
115 arglistit
= methlistit
->arguments
;
116 fprintf(out
, "CLASS, ");
118 arglistit
= arglistit
->next
;
119 type
= getargtype(arglistit
);
123 "Argument \"%s\" not understood for function %s\n",
124 arglistit
->arg
, methlistit
->name
128 fprintf(out
, "(%s)self, ", type
);
131 arglistit
= arglistit
->next
;
132 type
= getargtype(arglistit
);
136 "Argument \"%s\" not understood for function %s\n",
137 arglistit
->arg
, methlistit
->name
141 fprintf(out
, "(%s) message);", type
);
144 if (strcmp(methlistit
->type
, "void") == 0)
145 fprintf(out
, " break;");
153 " default: return DoSuperMethodA(CLASS, self, message);\n"
156 " return (IPTR) NULL;\n"
158 "BOOPSI_DISPATCHER_END\n"
168 "/*** Custom dispatcher prototype ********************************************/\n"
169 "BOOPSI_DISPATCHER_PROTO(IPTR, %s, CLASS, object, message);\n",
175 void writeclassinit(FILE *out
, struct classinfo
*cl
)
177 struct functionhead
*methlistit
;
178 struct functionarg
*arglistit
;
184 "/* Initialisation routines for a BOOPSI class */\n"
185 "/* ===========================================*/\n"
189 writeboopsidispatcher(out
, cl
);
191 if (cl
->classdatatype
== NULL
)
192 fprintf(out
, "#define %s_DATA_SIZE (0)\n", cl
->basename
);
195 "#define %s_DATA_SIZE (sizeof(%s))\n",
196 cl
->basename
, cl
->classdatatype
204 "/*** Library startup and shutdown *******************************************/\n"
205 "AROS_SET_LIBFUNC(BOOPSI_%s_Startup, LIBBASETYPE, LIBBASE)\n"
207 " AROS_SET_LIBFUNC_INIT\n"
209 " struct IClass *cl = NULL;\n"
211 " cl = MakeClass(%s, %s, NULL, %s_DATA_SIZE, 0);\n"
214 "#if %s_STORE_CLASSPTR\n"
215 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
218 cl
->classid
, cl
->superclass
, cl
->basename
,
223 if (cl
->dispatcher
== NULL
)
225 " cl->cl_Dispatcher.h_Entry = (APTR)%s_Dispatcher;\n",
230 " cl->cl_Dispatcher.h_Entry = (APTR)%s;\n",
237 " cl->cl_Dispatcher.h_SubEntry = NULL;\n"
238 " cl->cl_UserData = (IPTR)LIBBASE\n;"
241 if (!(cl
->options
& COPTION_PRIVATE
))
258 " AROS_SET_LIBFUNC_EXIT\n"
261 "AROS_SET_LIBFUNC(BOOPSI_%s_Shutdown, LIBBASETYPE, LIBBASE)\n"
263 " AROS_SET_LIBFUNC_INIT\n"
265 " if (%s_CLASSPTR_FIELD(LIBBASE) != NULL)\n"
267 cl
->basename
, cl
->basename
269 if (!(cl
->options
& COPTION_PRIVATE
))
271 " RemoveClass(%s_CLASSPTR_FIELD(LIBBASE));\n",
277 " FreeClass(%s_CLASSPTR_FIELD(LIBBASE));\n"
278 "#if %s_STORE_CLASSPTR\n"
279 " %s_CLASSPTR_FIELD(LIBBASE) = NULL;\n"
285 " AROS_SET_LIBFUNC_EXIT\n"
288 "ADD2INITCLASSES(BOOPSI_%s_Startup, %d);\n"
289 "ADD2EXPUNGECLASSES(BOOPSI_%s_Shutdown, %d);\n",
293 cl
->basename
, -cl
->initpri
,
294 cl
->basename
, -cl
->initpri