2 Copyright © 1995-2006, 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(struct config
*cfg
, 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"
44 writefuncdefs(out
, NULL
, cl
->methlist
);
51 "/*** Dispatcher *************************************************************/\n"
52 "BOOPSI_DISPATCHER(IPTR, %s_Dispatcher, CLASS, self, message)\n"
56 if (cfg
->options
& OPTION_DUPBASE
)
58 " __aros_setoffsettable(CLASS->cl_UserData);\n"
63 " switch (message->MethodID)\n"
69 methlistit
= cl
->methlist
;
71 methlistit
= methlistit
->next
79 aliasit
= methlistit
->aliases
;
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
);
96 arglistit
= methlistit
->arguments
;
97 fprintf(out
, "CLASS, ");
99 arglistit
= arglistit
->next
;
100 type
= getargtype(arglistit
);
104 "Argument \"%s\" not understood for function %s\n",
105 arglistit
->arg
, methlistit
->name
109 fprintf(out
, "(%s)self, ", type
);
112 arglistit
= arglistit
->next
;
113 type
= getargtype(arglistit
);
117 "Argument \"%s\" not understood for function %s\n",
118 arglistit
->arg
, methlistit
->name
122 fprintf(out
, "(%s) message);", type
);
125 if (strcmp(methlistit
->type
, "void") == 0)
126 fprintf(out
, " break;");
134 " default: return DoSuperMethodA(CLASS, self, message);\n"
137 " return (IPTR) NULL;\n"
139 "BOOPSI_DISPATCHER_END\n"
149 "/*** Custom dispatcher prototype ********************************************/\n"
150 "BOOPSI_DISPATCHER_PROTO(IPTR, %s, CLASS, object, message);\n",
156 void writeclassinit(struct config
*cfg
, FILE *out
, struct classinfo
*cl
)
158 struct functionhead
*methlistit
;
159 struct functionarg
*arglistit
;
165 "/* Initialisation routines for a BOOPSI class */\n"
166 "/* ===========================================*/\n"
170 writeboopsidispatcher(cfg
, out
, cl
);
172 if (cl
->classdatatype
== NULL
)
173 fprintf(out
, "#define %s_DATA_SIZE (0)\n", cl
->basename
);
176 "#define %s_DATA_SIZE (sizeof(%s))\n",
177 cl
->basename
, cl
->classdatatype
185 "/*** Library startup and shutdown *******************************************/\n"
186 "static int BOOPSI_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
188 " struct IClass *cl = NULL;\n"
192 if (cl
->superclass
!= NULL
)
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
)
199 " cl = MakeClass(%s, NULL, LIBBASE->%s, %s_DATA_SIZE, 0);\n",
200 cl
->classid
, cl
->superclass_field
, cl
->basename
204 fprintf(stderr
, "Internal error: both superclass and superclass_field are NULL\n");
212 "#if %s_STORE_CLASSPTR\n"
213 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
219 if (cl
->dispatcher
== NULL
)
221 " cl->cl_Dispatcher.h_Entry = (APTR)%s_Dispatcher;\n",
226 " cl->cl_Dispatcher.h_Entry = (APTR)%s;\n",
233 " cl->cl_Dispatcher.h_SubEntry = NULL;\n"
234 " cl->cl_UserData = (IPTR)LIBBASE\n;"
237 if (!(cl
->options
& COPTION_PRIVATE
))
255 "static void BOOPSI_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
257 " struct IClass *cl = %s_CLASSPTR_FIELD(LIBBASE);\n"
261 cl
->basename
, cl
->basename
263 if (!(cl
->options
& COPTION_PRIVATE
))
264 fprintf(out
, " RemoveClass(cl);\n");
269 "#if %s_STORE_CLASSPTR\n"
270 " %s_CLASSPTR_FIELD(LIBBASE) = NULL;\n"
277 "ADD2INITCLASSES(BOOPSI_%s_Startup, %d);\n"
278 "ADD2EXPUNGECLASSES(BOOPSI_%s_Shutdown, %d);\n",
281 cl
->basename
, -cl
->initpri
,
282 cl
->basename
, -cl
->initpri