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(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"
54 " switch (message->MethodID)\n"
61 methlistit
= cl
->methlist
;
63 methlistit
= methlistit
->next
71 aliasit
= methlistit
->aliases
;
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
->name
);
82 if (methlistit
->argcount
!= 3)
84 fprintf(stderr
, "Method \"%s\" has wrong number of arguments\n", methlistit
->name
);
88 arglistit
= methlistit
->arguments
;
89 fprintf(out
, "CLASS, ");
91 arglistit
= arglistit
->next
;
92 type
= getargtype(arglistit
);
96 "Argument \"%s\" not understood for function %s\n",
97 arglistit
->arg
, methlistit
->name
101 fprintf(out
, "(%s)self, ", type
);
104 arglistit
= arglistit
->next
;
105 type
= getargtype(arglistit
);
109 "Argument \"%s\" not understood for function %s\n",
110 arglistit
->arg
, methlistit
->name
114 fprintf(out
, "(%s) message);", type
);
117 if (strcmp(methlistit
->type
, "void") == 0)
118 fprintf(out
, " break;");
126 " default: return DoSuperMethodA(CLASS, self, message);\n"
129 " return (IPTR) NULL;\n"
131 "BOOPSI_DISPATCHER_END\n"
141 "/*** Custom dispatcher prototype ********************************************/\n"
142 "BOOPSI_DISPATCHER_PROTO(IPTR, %s, CLASS, object, message);\n",
148 void writeclassinit(FILE *out
, struct classinfo
*cl
)
150 struct functionhead
*methlistit
;
151 struct functionarg
*arglistit
;
157 "/* Initialisation routines for a BOOPSI class */\n"
158 "/* ===========================================*/\n"
162 writeboopsidispatcher(out
, cl
);
164 if (cl
->classdatatype
== NULL
)
165 fprintf(out
, "#define %s_DATA_SIZE (0)\n", cl
->basename
);
168 "#define %s_DATA_SIZE (sizeof(%s))\n",
169 cl
->basename
, cl
->classdatatype
177 "/*** Library startup and shutdown *******************************************/\n"
178 "static int BOOPSI_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
180 " struct IClass *cl = NULL;\n"
184 if (cl
->superclass
!= NULL
)
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
)
191 " cl = MakeClass(%s, NULL, LIBBASE->%s, %s_DATA_SIZE, 0);\n",
192 cl
->classid
, cl
->superclass_field
, cl
->basename
196 fprintf(stderr
, "Internal error: both superclass and superclass_field are NULL\n");
204 "#if %s_STORE_CLASSPTR\n"
205 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
211 if (cl
->dispatcher
== NULL
)
213 " cl->cl_Dispatcher.h_Entry = (APTR)%s_Dispatcher;\n",
218 " cl->cl_Dispatcher.h_Entry = (APTR)%s;\n",
225 " cl->cl_Dispatcher.h_SubEntry = NULL;\n"
226 " cl->cl_UserData = (IPTR)LIBBASE\n;"
229 if (!(cl
->options
& COPTION_PRIVATE
))
247 "static void BOOPSI_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
249 " struct IClass *cl = %s_CLASSPTR_FIELD(LIBBASE);\n"
253 cl
->basename
, cl
->basename
255 if (!(cl
->options
& COPTION_PRIVATE
))
256 fprintf(out
, " RemoveClass(cl);\n");
261 "#if %s_STORE_CLASSPTR\n"
262 " %s_CLASSPTR_FIELD(LIBBASE) = NULL;\n"
269 "ADD2INITCLASSES(BOOPSI_%s_Startup, %d);\n"
270 "ADD2EXPUNGECLASSES(BOOPSI_%s_Shutdown, %d);\n",
273 cl
->basename
, -cl
->initpri
,
274 cl
->basename
, -cl
->initpri