2 * Copyright (C) 2012, The AROS Development Team
4 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
6 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
8 * Generate include/interface/XXXX.h files
10 #include "genmodule.h"
12 static void writeincinterface(struct config
*cfg
, struct interfaceinfo
*in
)
15 char line
[256], *banner
;
16 struct functionhead
*funclistit
;
19 snprintf(line
, 255, "%s/interface/%s.h", cfg
->gendir
, in
->interfacename
);
20 out
= fopen(line
, "w");
28 banner
= getBanner(cfg
);
30 "#ifndef INTERFACE_%s_H\n"
31 "#define INTERFACE_%s_H\n"
36 " Desc: interface inlines for %s\n"
39 "#include <exec/types.h>\n"
40 "#include <proto/oop.h>\n"
42 "#define IID_%-32s \"%s\"\n"
53 /* Emit the get-the-methodbase stub */
55 "#if !defined(%s) && !defined(__OOP_NOMETHODBASES__) && !defined(__%s_NOMETHODBASE__)\n"
56 "#define %s %s_GetMethodBase(__obj)\n"
58 "static inline OOP_MethodID %s_GetMethodBase(OOP_Object *obj)\n"
60 " static OOP_MethodID %s_mid;\n"
62 " struct Library *OOPBase = (struct Library *)OOP_OCLASS(obj)->OOPBasePtr;\n"
63 " %s_mid = OOP_GetMethodID(IID_%s, 0);\n"
81 if (in
->attributelist
) {
83 "#define %-32s __I%s\n"
85 "#if !defined(__OOP_NOATTRBASES__) && !defined(__%s_NOATTRBASE__)\n"
86 "extern OOP_AttrBase %s;\n"
98 /* Define all the attribute ids */
99 for (funclistit
= in
->attributelist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
107 if (funclistit
->comment
)
111 , funclistit
->comment
115 if ((int)funclistit
->lvo
> maxlvo
)
116 maxlvo
= funclistit
->lvo
;
121 " num_%s_Attrs = %d,\n"
129 for (funclistit
= in
->attributelist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
132 "#define a%s_%-32s (%s + ao%s_%s)\n"
144 /* Define method ids */
150 for (funclistit
= in
->methodlist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
158 if ((int)funclistit
->lvo
> maxlvo
)
159 maxlvo
= funclistit
->lvo
;
163 " num_%s_Methods = %d\n"
170 /* Define method stubs */
171 for (funclistit
= in
->methodlist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
173 struct functionarg
*arg
;
175 /* Define message types */
179 " OOP_MethodID mID;\n"
184 for (arg
= funclistit
->arguments
; arg
; arg
= arg
->next
)
197 if (funclistit
->comment
)
201 , funclistit
->comment
206 "#define %s_%s(obj, args...) \\\n"
207 " ({OOP_Object *__obj = obj;\\\n"
208 " %s_%s_(%s, __obj ,##args); })\n"
218 "static inline %s %s_%s_(OOP_MethodID __%s, OOP_Object *__obj"
225 for (arg
= funclistit
->arguments
; arg
; arg
= arg
->next
)
236 " struct p%s_%s p;\n"
237 " p.mID = __%s + mo%s_%s;\n"
245 for (arg
= funclistit
->arguments
; arg
; arg
= arg
->next
)
250 ptr
= arg
->arg
+ strlen(arg
->arg
) - 1;
251 while (isspace(*ptr
))
254 while (isalnum(*ptr
) || (*ptr
== '_'))
258 /* Function prototype */
260 ptr
= strchr(arg
->arg
, '(');
261 while (!(isalnum(*ptr
) || (*ptr
== '_'))) ptr
++;
263 while (isalnum(*ptr
) || (*ptr
== '_')) ptr
++;
264 name
= malloc(ptr
- cp
+ 1);
265 memcpy(name
, cp
, ptr
- cp
);
268 name
= strdup(ptr
+ 1);
281 " %s(%s)OOP_DoMethod(__obj, &p.mID);\n"
284 , (strcasecmp(funclistit
->type
, "void") == 0) ? "" : "return "
291 "#endif /* INTERFACE_%s_H */\n"
298 void writeincinterfaces(struct config
*cfg
)
300 struct interfaceinfo
*in
;
302 for (in
= cfg
->interfacelist
; in
; in
= in
->next
) {
303 writeincinterface(cfg
, in
);