2 Copyright © 2005-2006, The AROS Development Team. All rights reserved.
5 Desc: Support functions for oop.library classes. Part of genmodule.
8 #include "oopsupport.h"
10 void writeoopincludes(FILE *out
)
15 "#include <proto/oop.h>\n"
16 "#include <oop/oop.h>\n"
17 "#include <hidd/hidd.h>\n"
22 void writeoopinit(FILE *out
, struct classinfo
*cl
)
24 struct functionhead
*methlistit
;
25 struct functionarg
*arglistit
;
26 struct stringlist
*interface
;
31 "/* Initialisation routines of a OOP class */\n"
32 "/* =======================================*/\n"
36 if (cl
->classdatatype
== NULL
)
37 fprintf(out
, "# define %s_DATA_SIZE (0)\n", cl
->basename
);
42 "# define %s_DATA_SIZE (sizeof(%s))\n",
43 cl
->basename
, cl
->classdatatype
46 /* Write defines of methods */
47 writefuncdefs(out
, NULL
, cl
->methlist
);
54 "/*** Library startup and shutdown *******************************************/\n"
55 "static int OOP_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
57 "#ifdef GM_OOPBASE_FIELD\n"
58 " struct Library *OOPBase = GM_OOPBASE_FIELD(LIBBASE);\n"
60 " OOP_AttrBase MetaAttrBase = OOP_ObtainAttrBase(IID_Meta);\n"
61 " OOP_Class *cl = NULL;\n"
66 /* Write variables initialization */
67 for (methlistit
= cl
->methlist
, interface
= NULL
, methods
= 0;
69 methlistit
= methlistit
->next
72 if (interface
!= methlistit
->interface
)
74 if (interface
!= NULL
)
76 /* Close the previous declaration */
80 "#define NUM_%s_%s_METHODS %d\n"
82 cl
->basename
, interface
->s
, methods
86 /* Start new MethodDescr declaration */
87 fprintf(out
, " struct OOP_MethodDescr %s_%s_descr[] =\n {\n",
88 cl
->basename
, methlistit
->interface
->s
91 interface
= methlistit
->interface
;
96 fprintf(out
, " {(OOP_MethodFunc)%s, %s},\n",
97 methlistit
->internalname
, methlistit
->method
101 /* Close the last declaration */
105 "#define NUM_%s_%s_METHODS %d\n"
107 cl
->basename
, interface
->s
, methods
111 /* Write the interface description */
112 fprintf(out
, " struct OOP_InterfaceDescr %s_ifdescr[] =\n {\n", cl
->basename
);
113 for (interface
= cl
->interfaces
; interface
!= NULL
; interface
= interface
->next
)
116 " {%s_%s_descr, IID_%s, NUM_%s_%s_METHODS},\n",
117 cl
->basename
, interface
->s
,
119 cl
->basename
, interface
->s
128 /* Write the class creation TagList */
130 " struct TagItem %s_tags[] =\n"
134 if (cl
->superclass
!= NULL
)
136 " {aMeta_SuperID, (IPTR)%s},\n",
139 else if (cl
->superclass_field
!= NULL
)
141 " {aMeta_SuperPtr, (IPTR)LIBBASE->%s},\n",
146 fprintf(stderr
, "Internal error: both superclass and superclass_field are NULL\n");
151 " {aMeta_InterfaceDescr, (IPTR)%s_ifdescr},\n"
152 " {aMeta_InstSize, (IPTR)%s_DATA_SIZE},\n",
156 if (cl
->classid
!= NULL
)
158 " {aMeta_ID, (IPTR)%s},\n",
161 fprintf(out
, " {TAG_DONE, (IPTR)0}\n };\n");
163 /* Write class constructor */
168 " if (MetaAttrBase == 0)\n"
171 " cl = OOP_NewObject(NULL, CLID_HiddMeta, %s_tags);\n"
174 " cl->UserData = (APTR)LIBBASE;\n"
175 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
176 " OOP_AddClass(cl);\n"
179 " OOP_ReleaseAttrBase(IID_Meta);\n"
180 " return cl != NULL;\n"
186 /* Write class destructor */
190 "static void OOP_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
192 "#ifdef GM_OOPBASE_FIELD\n"
193 " struct Library *OOPBase = GM_OOPBASE_FIELD(LIBBASE);\n"
195 " if (%s_CLASSPTR_FIELD(LIBBASE) != NULL)\n"
197 " OOP_RemoveClass(%s_CLASSPTR_FIELD(LIBBASE));\n"
198 " OOP_DisposeObject((OOP_Object *)%s_CLASSPTR_FIELD(LIBBASE));\n"
212 "ADD2INITCLASSES(OOP_%s_Startup, %d);\n"
213 "ADD2EXPUNGECLASSES(OOP_%s_Shutdown, %d);\n",
214 cl
->basename
, -cl
->initpri
,
215 cl
->basename
, -cl
->initpri