Overhauled GRUB menus to reduce number of entries, mainly by making use
[cake.git] / tools / genmodule / oopsupport.c
blob988723057da15e6cc0742d23c091c3410a5ba513
1 /*
2 Copyright © 2005-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Support functions for oop.library classes. Part of genmodule.
6 */
7 #include "genmodule.h"
8 #include "oopsupport.h"
10 void writeoopincludes(FILE *out)
12 fprintf
14 out,
15 "#include <proto/oop.h>\n"
16 "#include <oop/oop.h>\n"
17 "#include <hidd/hidd.h>\n"
18 "\n"
22 void writeoopinit(FILE *out, struct classinfo *cl)
24 struct functionhead *methlistit;
25 struct functionarg *arglistit;
26 struct stringlist *interface;
27 int methods;
28 fprintf
30 out,
31 "/* Initialisation routines of a OOP class */\n"
32 "/* =======================================*/\n"
33 "\n"
36 fprintf(out,
37 "#ifdef GM_OOPBASE_FIELD\n"
38 "# ifdef OOPBase\n"
39 "# undef OOPBase\n"
40 "# endif\n"
41 "# define OOPBase GM_OOPBASE_FIELD(LIBBASE)\n"
42 "#endif\n"
43 "\n"
46 if (cl->classdatatype == NULL)
47 fprintf(out, "# define %s_DATA_SIZE (0)\n", cl->basename);
48 else
49 fprintf
51 out,
52 "# define %s_DATA_SIZE (sizeof(%s))\n",
53 cl->basename, cl->classdatatype
56 /* Write defines of methods */
57 writefuncdefs(out, NULL, cl->methlist);
59 fprintf
61 out,
62 "\n"
63 "\n"
64 "/*** Library startup and shutdown *******************************************/\n"
65 "static int OOP_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
66 "{\n"
67 " OOP_AttrBase MetaAttrBase = OOP_ObtainAttrBase(IID_Meta);\n"
68 " OOP_Class *cl = NULL;\n"
69 "\n",
70 cl->basename
73 /* Write variables initialization */
74 for (methlistit = cl->methlist, interface = NULL, methods = 0;
75 methlistit != NULL;
76 methlistit = methlistit->next
79 if (interface != methlistit->interface)
81 if (interface != NULL)
83 /* Close the previous declaration */
84 fprintf(out,
85 " {NULL, 0}\n"
86 " };\n"
87 "#define NUM_%s_%s_METHODS %d\n"
88 "\n",
89 cl->basename, interface->s, methods
93 /* Start new MethodDescr declaration */
94 fprintf(out, " struct OOP_MethodDescr %s_%s_descr[] =\n {\n",
95 cl->basename, methlistit->interface->s
97 methods = 1;
98 interface = methlistit->interface;
100 else
101 methods++;
103 fprintf(out, " {(OOP_MethodFunc)%s, %s},\n",
104 methlistit->name, methlistit->method
107 /* Close the last declaration */
108 fprintf(out,
109 " {NULL, 0}\n"
110 " };\n"
111 "#define NUM_%s_%s_METHODS %d\n"
112 "\n",
113 cl->basename, interface->s, methods
116 /* Write the interface description */
117 fprintf(out, " struct OOP_InterfaceDescr %s_ifdescr[] =\n {\n", cl->basename);
118 for (interface = cl->interfaces; interface != NULL; interface = interface->next)
120 fprintf(out,
121 " {%s_%s_descr, IID_%s, NUM_%s_%s_METHODS},\n",
122 cl->basename, interface->s,
123 interface->s,
124 cl->basename, interface->s
127 fprintf(out,
128 " {NULL, NULL}\n"
129 " };\n"
130 "\n"
133 /* Write the class creation TagList */
134 fprintf(out,
135 " struct TagItem %s_tags[] =\n"
136 " {\n",
137 cl->basename
139 if (cl->superclass != NULL)
140 fprintf(out,
141 " {aMeta_SuperID, (IPTR)%s},\n",
142 cl->superclass
144 else if (cl->superclass_field != NULL)
145 fprintf(out,
146 " {aMeta_SuperPtr, (IPTR)LIBBASE->%s},\n",
147 cl->superclass_field
149 else
151 fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n");
152 exit(20);
155 fprintf(out,
156 " {aMeta_InterfaceDescr, (IPTR)%s_ifdescr},\n"
157 " {aMeta_InstSize, (IPTR)%s_DATA_SIZE},\n",
158 cl->basename,
159 cl->basename
161 if (cl->classid != NULL)
162 fprintf(out,
163 " {aMeta_ID, (IPTR)%s},\n",
164 cl->classid
166 fprintf(out, " {TAG_DONE, (IPTR)0}\n };\n");
168 /* Write class constructor */
169 fprintf
171 out,
172 "\n"
173 " if (MetaAttrBase == 0)\n"
174 " return FALSE;\n"
175 "\n"
176 " cl = OOP_NewObject(NULL, CLID_HiddMeta, %s_tags);\n"
177 " if (cl != NULL)\n"
178 " {\n"
179 " cl->UserData = (APTR)LIBBASE;\n"
180 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
181 " OOP_AddClass(cl);\n"
182 " }\n"
183 "\n"
184 " OOP_ReleaseAttrBase(IID_Meta);\n"
185 " return cl != NULL;\n"
186 "}\n",
187 cl->basename,
188 cl->basename,
189 cl->basename
192 /* Write class destructor */
193 fprintf
195 out,
196 "static void OOP_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
197 "{\n"
198 " if (%s_CLASSPTR_FIELD(LIBBASE) != NULL)\n"
199 " {\n"
200 " OOP_RemoveClass(%s_CLASSPTR_FIELD(LIBBASE));\n"
201 " OOP_DisposeObject((OOP_Object *)%s_CLASSPTR_FIELD(LIBBASE));\n"
202 " }\n"
203 "\n"
204 // " return TRUE;\n"
205 "}\n",
206 cl->basename,
207 cl->basename,
208 cl->basename,
209 cl->basename
212 fprintf
214 out,
215 "ADD2INITCLASSES(OOP_%s_Startup, %d);\n"
216 "ADD2EXPUNGECLASSES(OOP_%s_Shutdown, %d);\n",
217 cl->basename, -cl->initpri,
218 cl->basename, -cl->initpri