Import SB128-v5.24 to main branch
[AROS.git] / tools / genmodule / oopsupport.c
blob93f7dc35eef4163732deb00f2424a7407a3500e0
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 if (cl->classdatatype == NULL)
37 fprintf(out, "# define %s_DATA_SIZE (0)\n", cl->basename);
38 else
39 fprintf
41 out,
42 "# define %s_DATA_SIZE (sizeof(%s))\n",
43 cl->basename, cl->classdatatype
46 /* Write defines of methods */
47 writefuncdefs(out, NULL, cl->methlist);
49 fprintf
51 out,
52 "\n"
53 "\n"
54 "/*** Library startup and shutdown *******************************************/\n"
55 "static int OOP_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
56 "{\n"
57 " OOP_AttrBase MetaAttrBase = OOP_ObtainAttrBase(IID_Meta);\n"
58 " OOP_Class *cl = NULL;\n"
59 "\n",
60 cl->basename
63 /* Write variables initialization */
64 for (methlistit = cl->methlist, interface = NULL, methods = 0;
65 methlistit != NULL;
66 methlistit = methlistit->next
69 if (interface != methlistit->interface)
71 if (interface != NULL)
73 /* Close the previous declaration */
74 fprintf(out,
75 " {NULL, 0}\n"
76 " };\n"
77 "#define NUM_%s_%s_METHODS %d\n"
78 "\n",
79 cl->basename, interface->s, methods
83 /* Start new MethodDescr declaration */
84 fprintf(out, " struct OOP_MethodDescr %s_%s_descr[] =\n {\n",
85 cl->basename, methlistit->interface->s
87 methods = 1;
88 interface = methlistit->interface;
90 else
91 methods++;
93 fprintf(out, " {(OOP_MethodFunc)%s, %s},\n",
94 methlistit->internalname, methlistit->method
97 /* Close the last declaration */
98 fprintf(out,
99 " {NULL, 0}\n"
100 " };\n"
101 "#define NUM_%s_%s_METHODS %d\n"
102 "\n",
103 cl->basename, interface->s, methods
106 /* Write the interface description */
107 fprintf(out, " struct OOP_InterfaceDescr %s_ifdescr[] =\n {\n", cl->basename);
108 for (interface = cl->interfaces; interface != NULL; interface = interface->next)
110 fprintf(out,
111 " {%s_%s_descr, IID_%s, NUM_%s_%s_METHODS},\n",
112 cl->basename, interface->s,
113 interface->s,
114 cl->basename, interface->s
117 fprintf(out,
118 " {NULL, NULL}\n"
119 " };\n"
120 "\n"
123 /* Write the class creation TagList */
124 fprintf(out,
125 " struct TagItem %s_tags[] =\n"
126 " {\n",
127 cl->basename
129 if (cl->superclass != NULL)
130 fprintf(out,
131 " {aMeta_SuperID, (IPTR)%s},\n",
132 cl->superclass
134 else if (cl->superclass_field != NULL)
135 fprintf(out,
136 " {aMeta_SuperPtr, (IPTR)LIBBASE->%s},\n",
137 cl->superclass_field
139 else
141 fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n");
142 exit(20);
145 fprintf(out,
146 " {aMeta_InterfaceDescr, (IPTR)%s_ifdescr},\n"
147 " {aMeta_InstSize, (IPTR)%s_DATA_SIZE},\n",
148 cl->basename,
149 cl->basename
151 if (cl->classid != NULL)
152 fprintf(out,
153 " {aMeta_ID, (IPTR)%s},\n",
154 cl->classid
156 fprintf(out, " {TAG_DONE, (IPTR)0}\n };\n");
158 /* Write class constructor */
159 fprintf
161 out,
162 "\n"
163 " if (MetaAttrBase == 0)\n"
164 " return FALSE;\n"
165 "\n"
166 " cl = OOP_NewObject(NULL, CLID_HiddMeta, %s_tags);\n"
167 " if (cl != NULL)\n"
168 " {\n"
169 " cl->UserData = (APTR)LIBBASE;\n"
170 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
171 " OOP_AddClass(cl);\n"
172 " }\n"
173 "\n"
174 " OOP_ReleaseAttrBase(IID_Meta);\n"
175 " return cl != NULL;\n"
176 "}\n",
177 cl->basename,
178 cl->basename,
179 cl->basename
182 /* Write class destructor */
183 fprintf
185 out,
186 "static void OOP_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
187 "{\n"
188 " if (%s_CLASSPTR_FIELD(LIBBASE) != NULL)\n"
189 " {\n"
190 " OOP_RemoveClass(%s_CLASSPTR_FIELD(LIBBASE));\n"
191 " OOP_DisposeObject((OOP_Object *)%s_CLASSPTR_FIELD(LIBBASE));\n"
192 " }\n"
193 "\n"
194 // " return TRUE;\n"
195 "}\n",
196 cl->basename,
197 cl->basename,
198 cl->basename,
199 cl->basename
202 fprintf
204 out,
205 "ADD2INITCLASSES(OOP_%s_Startup, %d);\n"
206 "ADD2EXPUNGECLASSES(OOP_%s_Shutdown, %d);\n",
207 cl->basename, -cl->initpri,
208 cl->basename, -cl->initpri