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 " OOP_AttrBase MetaAttrBase = OOP_ObtainAttrBase(IID_Meta);\n"
58 " OOP_Class *cl = NULL;\n"
63 /* Write variables initialization */
64 for (methlistit
= cl
->methlist
, interface
= NULL
, methods
= 0;
66 methlistit
= methlistit
->next
69 if (interface
!= methlistit
->interface
)
71 if (interface
!= NULL
)
73 /* Close the previous declaration */
77 "#define NUM_%s_%s_METHODS %d\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
88 interface
= methlistit
->interface
;
93 fprintf(out
, " {(OOP_MethodFunc)%s, %s},\n",
94 methlistit
->internalname
, methlistit
->method
97 /* Close the last declaration */
101 "#define NUM_%s_%s_METHODS %d\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
)
111 " {%s_%s_descr, IID_%s, NUM_%s_%s_METHODS},\n",
112 cl
->basename
, interface
->s
,
114 cl
->basename
, interface
->s
123 /* Write the class creation TagList */
125 " struct TagItem %s_tags[] =\n"
129 if (cl
->superclass
!= NULL
)
131 " {aMeta_SuperID, (IPTR)%s},\n",
134 else if (cl
->superclass_field
!= NULL
)
136 " {aMeta_SuperPtr, (IPTR)LIBBASE->%s},\n",
141 fprintf(stderr
, "Internal error: both superclass and superclass_field are NULL\n");
146 " {aMeta_InterfaceDescr, (IPTR)%s_ifdescr},\n"
147 " {aMeta_InstSize, (IPTR)%s_DATA_SIZE},\n",
151 if (cl
->classid
!= NULL
)
153 " {aMeta_ID, (IPTR)%s},\n",
156 fprintf(out
, " {TAG_DONE, (IPTR)0}\n };\n");
158 /* Write class constructor */
163 " if (MetaAttrBase == 0)\n"
166 " cl = OOP_NewObject(NULL, CLID_HiddMeta, %s_tags);\n"
169 " cl->UserData = (APTR)LIBBASE;\n"
170 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
171 " OOP_AddClass(cl);\n"
174 " OOP_ReleaseAttrBase(IID_Meta);\n"
175 " return cl != NULL;\n"
182 /* Write class destructor */
186 "static void OOP_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
188 " if (%s_CLASSPTR_FIELD(LIBBASE) != NULL)\n"
190 " OOP_RemoveClass(%s_CLASSPTR_FIELD(LIBBASE));\n"
191 " OOP_DisposeObject((OOP_Object *)%s_CLASSPTR_FIELD(LIBBASE));\n"
205 "ADD2INITCLASSES(OOP_%s_Startup, %d);\n"
206 "ADD2EXPUNGECLASSES(OOP_%s_Shutdown, %d);\n",
207 cl
->basename
, -cl
->initpri
,
208 cl
->basename
, -cl
->initpri