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"
37 "#ifdef GM_OOPBASE_FIELD\n"
41 "# define OOPBase GM_OOPBASE_FIELD(LIBBASE)\n"
46 if (cl
->classdatatype
== NULL
)
47 fprintf(out
, "# define %s_DATA_SIZE (0)\n", cl
->basename
);
52 "# define %s_DATA_SIZE (sizeof(%s))\n",
53 cl
->basename
, cl
->classdatatype
56 /* Write defines of methods */
57 writefuncdefs(out
, NULL
, cl
->methlist
);
64 "/*** Library startup and shutdown *******************************************/\n"
65 "static int OOP_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
67 " OOP_AttrBase MetaAttrBase = OOP_ObtainAttrBase(IID_Meta);\n"
68 " OOP_Class *cl = NULL;\n"
73 /* Write variables initialization */
74 for (methlistit
= cl
->methlist
, interface
= NULL
, methods
= 0;
76 methlistit
= methlistit
->next
79 if (interface
!= methlistit
->interface
)
81 if (interface
!= NULL
)
83 /* Close the previous declaration */
87 "#define NUM_%s_%s_METHODS %d\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
98 interface
= methlistit
->interface
;
103 fprintf(out
, " {(OOP_MethodFunc)%s, %s},\n",
104 methlistit
->name
, methlistit
->method
107 /* Close the last declaration */
111 "#define NUM_%s_%s_METHODS %d\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
)
121 " {%s_%s_descr, IID_%s, NUM_%s_%s_METHODS},\n",
122 cl
->basename
, interface
->s
,
124 cl
->basename
, interface
->s
133 /* Write the class creation TagList */
135 " struct TagItem %s_tags[] =\n"
139 if (cl
->superclass
!= NULL
)
141 " {aMeta_SuperID, (IPTR)%s},\n",
144 else if (cl
->superclass_field
!= NULL
)
146 " {aMeta_SuperPtr, (IPTR)LIBBASE->%s},\n",
151 fprintf(stderr
, "Internal error: both superclass and superclass_field are NULL\n");
156 " {aMeta_InterfaceDescr, (IPTR)%s_ifdescr},\n"
157 " {aMeta_InstSize, (IPTR)%s_DATA_SIZE},\n",
161 if (cl
->classid
!= NULL
)
163 " {aMeta_ID, (IPTR)%s},\n",
166 fprintf(out
, " {TAG_DONE, (IPTR)0}\n };\n");
168 /* Write class constructor */
173 " if (MetaAttrBase == 0)\n"
176 " cl = OOP_NewObject(NULL, CLID_HiddMeta, %s_tags);\n"
179 " cl->UserData = (APTR)LIBBASE;\n"
180 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
181 " OOP_AddClass(cl);\n"
184 " OOP_ReleaseAttrBase(IID_Meta);\n"
185 " return cl != NULL;\n"
192 /* Write class destructor */
196 "static void OOP_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
198 " if (%s_CLASSPTR_FIELD(LIBBASE) != NULL)\n"
200 " OOP_RemoveClass(%s_CLASSPTR_FIELD(LIBBASE));\n"
201 " OOP_DisposeObject((OOP_Object *)%s_CLASSPTR_FIELD(LIBBASE));\n"
215 "ADD2INITCLASSES(OOP_%s_Startup, %d);\n"
216 "ADD2EXPUNGECLASSES(OOP_%s_Shutdown, %d);\n",
217 cl
->basename
, -cl
->initpri
,
218 cl
->basename
, -cl
->initpri