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"
143 "#define %s_Switch(attr, idx) \\\n"
144 "if (((idx) = (attr) - %s) < num_%s_Attrs) \\\n"
155 /* Define method ids */
161 for (funclistit
= in
->methodlist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
169 if ((int)funclistit
->lvo
> maxlvo
)
170 maxlvo
= funclistit
->lvo
;
174 " num_%s_Methods = %d\n"
181 /* Define method stubs */
182 for (funclistit
= in
->methodlist
; funclistit
!=NULL
; funclistit
= funclistit
->next
)
184 struct functionarg
*arg
;
186 /* Define message types */
190 " OOP_MethodID mID;\n"
195 for (arg
= funclistit
->arguments
; arg
; arg
= arg
->next
)
208 if (funclistit
->comment
)
212 , funclistit
->comment
217 "#define %s_%s(obj, args...) \\\n"
218 " ({OOP_Object *__obj = obj;\\\n"
219 " %s_%s_(%s, __obj ,##args); })\n"
229 "static inline %s %s_%s_(OOP_MethodID __%s, OOP_Object *__obj"
236 for (arg
= funclistit
->arguments
; arg
; arg
= arg
->next
)
247 " struct p%s_%s p;\n"
248 " p.mID = __%s + mo%s_%s;\n"
256 for (arg
= funclistit
->arguments
; arg
; arg
= arg
->next
)
261 ptr
= arg
->arg
+ strlen(arg
->arg
) - 1;
262 while (isspace(*ptr
))
265 while (isalnum(*ptr
) || (*ptr
== '_'))
269 /* Function prototype */
271 ptr
= strchr(arg
->arg
, '(');
272 while (!(isalnum(*ptr
) || (*ptr
== '_'))) ptr
++;
274 while (isalnum(*ptr
) || (*ptr
== '_')) ptr
++;
275 name
= malloc(ptr
- cp
+ 1);
276 memcpy(name
, cp
, ptr
- cp
);
279 name
= strdup(ptr
+ 1);
292 " %s(%s)OOP_DoMethod(__obj, &p.mID);\n"
295 , (strcasecmp(funclistit
->type
, "void") == 0) ? "" : "return "
302 "#endif /* INTERFACE_%s_H */\n"
309 void writeincinterfaces(struct config
*cfg
)
311 struct interfaceinfo
*in
;
313 for (in
= cfg
->interfacelist
; in
; in
= in
->next
) {
314 writeincinterface(cfg
, in
);