source: trunk/ORBit2-2.14.0/src/idl-compiler/orbit-idl-c-skelimpl.c

Last change on this file was 255, checked in by cinc, 19 years ago

Parameter checking for object pointer working.

File size: 66.5 KB
Line 
1#include "config.h"
2
3#include "orbit-idl-c-backend.h"
4
5/* This file copied from the old IDL compiler orbit-c-skelimpl.c, with minimal changes. */
6
7static void orbit_cbe_write_skelimpl(FILE *outfile, IDL_tree tree, const char *hdrname);
8
9void
10orbit_idl_output_c_skelimpl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
11{
12 orbit_cbe_write_skelimpl(ci->fh, tree, ci->base_name);
13}
14
15#include <ctype.h>
16#include <glib.h>
17#include <unistd.h>
18#include <stdlib.h>
19#include <string.h>
20
21#include <errno.h>
22
23/* Used to count the static methods of a class. This is kind of a hack.
24 I would love to put it into CBESkelImplInfo but his struct is copied
25 everywhere and given as a copy to subprocedures. */
26static gulong ulNumStaticMethods[10];
27static gulong ulInstanceVarSize[10];
28static GString *gsMetaClassName[10];
29static gulong ulNumOverridenMethods[10];
30static gulong ulNumParentsInChain[10];
31
32static int ulCurInterface=0;
33static int whichPass;
34
35/* Abbreviations used here:
36 "cbe" stands for "C backend"
37 "hdr" -> "header" (duh :)
38 "of" -> "output file"
39 "ns" -> "name space"
40*/
41
42typedef struct {
43 FILE *of;
44 IDL_tree tree;
45 enum { PASS_VOYAGER_INSTANCE, PASS_VOYAGER_GETDATA, PASS_VOYAGER_CLSDATA, PASS_VOYAGER_PARMCHECK,
46 PASS_SERVANTS, PASS_PROTOS, PASS_EPVS, PASS_VEPVS,
47 PASS_IMPLSTUBS, PASS_VOYAGER_OVERRIDEN_METHODS, PASS_VOYAGER_OVERRIDEN_METHODTAB,
48 PASS_VOYAGER_STATICMETHODS, PASS_VOYAGER_METACLASS, PASS_VOYAGER_CLASSINFO, PASS_VOYAGER_NEWCLASS,
49 PASS_LAST } pass;
50} CBESkelImplInfo;
51
52typedef struct {
53 FILE *of;
54 IDL_tree realif;
55 char* chrOverridenMethodName;
56} InheritedOutputInfo;
57
58typedef struct {
59 FILE *of;
60 IDL_tree realif;
61 char* chrOverridenMethodName;
62 char* chrClassName;
63} InheritedOutputInfo2;
64
65static const char *passnames[] = {
66 "Voyager object instance data",
67 "Voyager GetData macros ",
68 "Voyager class data structures",
69 "Voyager parameter check",
70 "App-specific servant structures",
71 "Implementation stub prototypes",
72 "epv structures",
73 "vepv structures",
74 "Stub implementations",
75 "Voyager overriden methods",
76 "Voyager overriden method table",
77 "Voyager static methods",
78 "Voyager explicit metaclass (if any)",
79 "Voyager class information structure",
80 "Voyager class creation function",
81 "Boohoo!"
82};
83
84static void orbit_cbe_ski_process_piece(CBESkelImplInfo *ski);
85static void cbe_ski_do_list(CBESkelImplInfo *ski);
86static void cbe_ski_do_inherited_attr_dcl(CBESkelImplInfo *ski, IDL_tree current_interface);
87static void cbe_ski_do_attr_dcl(CBESkelImplInfo *ski);
88static void cbe_ski_do_inherited_op_dcl(CBESkelImplInfo *ski, IDL_tree current_interface);
89static void cbe_ski_do_op_dcl(CBESkelImplInfo *ski);
90static void cbe_ski_do_param_dcl(CBESkelImplInfo *ski);
91static void cbe_ski_do_interface(CBESkelImplInfo *ski);
92static void cbe_ski_do_module(CBESkelImplInfo *ski);
93
94static void cbe_ski_do_voyager_instance_vars(CBESkelImplInfo *ski);
95static void cbe_ski_do_voyager_getdata_macros(CBESkelImplInfo *ski);
96static void cbe_ski_do_voyager_classinfo_structure(CBESkelImplInfo *ski, gchar* className);
97
98static void
99orbit_cbe_write_skelimpl(FILE *outfile, IDL_tree tree, const char *hdrname)
100{
101 CBESkelImplInfo ski = {NULL, NULL, PASS_VOYAGER_INSTANCE};
102
103 ski.of = outfile;
104 ski.tree = tree;
105
106 g_return_if_fail(IDL_NODE_TYPE(tree) == IDLN_LIST);
107
108 fprintf(outfile, "/* This is a template file generated by command */\n");
109 fprintf(outfile, "/* orbit-idl-2 --skeleton-impl %s.idl */\n", hdrname);
110 fprintf(outfile, "/* User must edit this file, inserting servant */\n");
111 fprintf(outfile, "/* specific code between markers. */\n\n");
112
113 fprintf(outfile, "/* Implemented in %s */\n\n", __FILE__);
114
115 fprintf(outfile, "#include \"%s.h\"\n", hdrname);
116
117 ulNumStaticMethods[ulCurInterface]=0;
118 ulInstanceVarSize[ulCurInterface]=0;
119 ulNumOverridenMethods[ulCurInterface]=0;
120 ulNumParentsInChain[ulCurInterface]=0;
121
122 for(whichPass=ski.pass = PASS_VOYAGER_INSTANCE /*PASS_SERVANTS*/; ski.pass < PASS_LAST; ski.pass++) {
123 fprintf(ski.of, "\n/*** %s ***/\n\n", passnames[ski.pass]);
124 orbit_cbe_ski_process_piece(&ski);
125 }
126 fprintf(outfile, "\n#endif /* NOM_CLASS_IMPLEMENTATION_FILE */\n");
127}
128
129/*
130 Worker function for outputting the name of a class introducing some method.
131 Called by VoyagerOutputIntroducingClass();
132 */
133static
134void VoyagerDoOutputIntroducingClass(IDL_tree curif, InheritedOutputInfo *ioi)
135{
136 char *id;
137 IDL_tree curitem;
138 char* overridenMethodName;
139
140 if(curif == ioi->realif)
141 return;
142
143 overridenMethodName=ioi->chrOverridenMethodName;
144
145 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
146
147 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
148 IDL_tree curop = IDL_LIST(curitem).data;
149
150 switch(IDL_NODE_TYPE(curop)) {
151 case IDLN_OP_DCL:
152 {
153 /* Check if the current method (introduced by some parent) is the one to be
154 overriden. */
155 if(!strcmp(overridenMethodName, IDL_IDENT(IDL_OP_DCL(curop).ident).str)){
156 fprintf(ioi->of, "%s", id);
157 }
158 break;
159 }
160 default:
161 break;
162 }
163 }
164 g_free(id);
165}
166
167/*
168 Output the name of a class introducing an overriden method.
169*/
170static
171void VoyagerOutputIntroducingClass(IDL_tree tmptree, CBESkelImplInfo *ski, GString *gstr)
172{
173 if(IDL_INTERFACE(tmptree).inheritance_spec) {
174 InheritedOutputInfo ioi;
175
176 ioi.of = ski->of;
177 ioi.realif = tmptree;
178 ioi.chrOverridenMethodName=gstr->str;
179 IDL_tree_traverse_parents(IDL_INTERFACE(tmptree).inheritance_spec,
180 (GFunc)VoyagerDoOutputIntroducingClass, &ioi);
181 }
182}
183
184
185static
186void VoyagerOutputParentMethodSpec(IDL_tree curif, InheritedOutputInfo *ioi)
187{
188 char *id;
189 IDL_tree curitem;
190 char* overridenMethodName;
191
192 if(curif == ioi->realif)
193 return;
194
195 overridenMethodName=ioi->chrOverridenMethodName;
196
197 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
198
199 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
200 IDL_tree curop = IDL_LIST(curitem).data;
201
202 switch(IDL_NODE_TYPE(curop)) {
203 case IDLN_OP_DCL:
204 {
205 /* Check if the current method (introduced by some parent) is the one to be
206 overriden. */
207 if(!strcmp(overridenMethodName, IDL_IDENT(IDL_OP_DCL(curop).ident).str)){
208 //nomTD_NOMTest2_nomTestFunc_NOMTest2
209 fprintf(ioi->of, "nomTD_%s_%s",
210 id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
211 }
212 break;
213 }
214 default:
215 break;
216 }
217 }
218 g_free(id);
219}
220
221static
222void VoyagerWriteParamsForParentCall(IDL_tree curif, InheritedOutputInfo *ioi)
223{
224 IDL_tree curitem;
225 char* overridenMethodName;
226
227 if(curif == ioi->realif)
228 return;
229
230 overridenMethodName=ioi->chrOverridenMethodName;
231
232 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
233 IDL_tree curop = IDL_LIST(curitem).data;
234
235 switch(IDL_NODE_TYPE(curop)) {
236 case IDLN_OP_DCL:
237 {
238 /* Check if the current method (introduced by some parent) is the one to be
239 overriden. */
240 if(!strcmp(overridenMethodName, IDL_IDENT(IDL_OP_DCL(curop).ident).str)){
241 IDL_tree sub;
242
243 for (sub = IDL_OP_DCL (curop).parameter_dcls; sub; sub = IDL_LIST (sub).next) {
244 IDL_tree parm = IDL_LIST (sub).data;
245 fprintf (ioi->of, "%s, ", IDL_IDENT (IDL_PARAM_DCL (parm).simple_declarator).str);
246 }
247 }
248 break;
249 }
250 default:
251 break;
252 }
253 }
254}
255
256/*
257 This function is called for each parent to check if the current parent introduced the
258 overriden method. If yes, the parameter info is taken from this parent and put into the
259 file.
260 */
261static
262void VoyagerDoWriteOverridenMethodDeclaration(IDL_tree curif, InheritedOutputInfo2 *ioi)
263{
264 IDL_tree curitem;
265 char* overridenMethodName;
266
267 if(curif == ioi->realif)
268 return;
269
270 overridenMethodName=ioi->chrOverridenMethodName;
271
272 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
273 IDL_tree curop = IDL_LIST(curitem).data;
274
275 switch(IDL_NODE_TYPE(curop)) {
276 case IDLN_OP_DCL:
277 {
278 /* Check if the current method (introduced by some parent) is the one to be
279 overriden. */
280 if(!strcmp(overridenMethodName, IDL_IDENT(IDL_OP_DCL(curop).ident).str)){
281 IDL_tree sub;
282
283 g_assert (IDL_NODE_TYPE(curop) == IDLN_OP_DCL);
284
285 /* return typespec */
286 orbit_cbe_write_param_typespec (ioi->of, curop);
287
288 /* The methodname */
289 fprintf (ioi->of, " %s%s_%s", "NOMLINK impl_",
290 ioi->chrClassName, overridenMethodName);
291
292 fprintf (ioi->of, "(%s* nomSelf, ", ioi->chrClassName);
293
294 /* Write the params including the typespec */
295 for (sub = IDL_OP_DCL (curop).parameter_dcls; sub; sub = IDL_LIST (sub).next) {
296 IDL_tree parm = IDL_LIST (sub).data;
297
298 orbit_cbe_write_param_typespec (ioi->of, parm);
299
300 fprintf (ioi->of, " %s, ", IDL_IDENT (IDL_PARAM_DCL (parm).simple_declarator).str);
301 }
302 }
303 break;
304 }
305 default:
306 break;
307 }
308 }
309}
310
311/*
312 Overriden methods are introduced by some parent class. This function gets the parent node and
313 climbs down the list of classes to find the one introducing the method. A support function called
314 for every node while traversing actually writes the info.
315*/
316static void
317VoyagerWriteOverridenMethodDeclaration(FILE *of, IDL_tree op,
318 const char *nom_prefix,
319 gboolean for_epv)
320{
321 char *id;
322 char * id2;
323 char * ptr;
324 IDL_tree tmptree;
325
326 g_assert (IDL_NODE_TYPE(op) == IDLN_OP_DCL);
327
328 id = IDL_ns_ident_to_qstring (
329 IDL_IDENT_TO_NS (IDL_INTERFACE (
330 IDL_get_parent_node (op, IDLN_INTERFACE, NULL)).ident), "_", 0);
331
332 id2=g_strdup(IDL_IDENT (IDL_OP_DCL (op).ident).str);
333 if((ptr=strstr(id2, NOM_OVERRIDE_STRING))!=NULL)
334 *ptr='\0';
335
336 tmptree = IDL_get_parent_node(op, IDLN_INTERFACE, NULL);
337
338 if(IDL_INTERFACE(tmptree).inheritance_spec) {
339 InheritedOutputInfo2 ioi;
340
341 ioi.of = of;
342 ioi.realif = tmptree;
343 ioi.chrOverridenMethodName=id2;
344 ioi.chrClassName=id; /* The current class name. In the called function the parent is searched introducing the method.
345 When this parent is found, the current class info isn't easy to get again but it's needed. */
346
347 IDL_tree_traverse_parents(IDL_INTERFACE(tmptree).inheritance_spec, (GFunc)VoyagerDoWriteOverridenMethodDeclaration, &ioi);
348 }
349 g_free(id2);
350 g_free(id);
351}
352
353/*
354 The name of our meta class is encoded as a constant. We go over all the constants found during
355 IDL parsing and check for a special marker string in the name.
356 */
357static void
358VoyagerExtractMetaClass(CBESkelImplInfo *ski)
359{
360 char *id;
361 IDL_tree ident;
362 IDL_tree intf;
363
364
365 if(PASS_VOYAGER_METACLASS==ski->pass)
366 {
367 ident = IDL_CONST_DCL (ski->tree).ident;
368 intf = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, NULL);
369
370 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
371
372 if(IDLN_STRING==IDL_NODE_TYPE(IDL_CONST_DCL(ski->tree).const_exp))
373 {
374 // printf(" %d --- > %s\n", __LINE__,IDL_IDENT(ident).str);
375 /* Our metaclass info is a string */
376 if(strstr( IDL_IDENT(ident).str, NOM_METACLASS_STRING))
377 {
378 gsMetaClassName[ulCurInterface]=g_string_new(NULL);
379 g_string_printf(gsMetaClassName[ulCurInterface], "%s", IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value);
380 // printf(" %d --- > %s %s (%x)\n",
381 // __LINE__, id, IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value, gsMetaClassName[ulCurInterface]);
382 }
383 }
384 g_free(id);
385 }/* PASS_VOYAGER_...*/
386}
387
388/*
389 This function creates a define for methods with parameter check at the top of the *.ih file
390 to enable the check function whichis sourrounded by '#ifdef/#endif.
391 Note that this function does not create any checking code.
392
393 For methods which should have parameter checks (specified by a special macro in the IDL file)
394 a constant string is specified. The method name is encoded in the constants name while the string
395 holds all the info about the parameters to check.
396 We go over all the constants found during IDL parsing and check for a special marker string in the
397 name.
398 */
399static void
400VoyagerCreateParamCheckDefines(CBESkelImplInfo *ski)
401{
402 char *id;
403 IDL_tree ident;
404 IDL_tree intf;
405
406
407 if(PASS_VOYAGER_PARMCHECK==ski->pass)
408 {
409 ident = IDL_CONST_DCL (ski->tree).ident;
410 intf = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, NULL);
411
412 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
413
414 if(IDLN_STRING==IDL_NODE_TYPE(IDL_CONST_DCL(ski->tree).const_exp))
415 {
416 gchar *ptr;
417 // printf(" %d --- > %s\n", __LINE__,IDL_IDENT(ident).str);
418 /* Our parameter info is a string */
419 ptr=strstr( id /*IDL_IDENT(ident).str*/, NOM_PARMCHECK_STRING);
420 if(ptr)
421 {
422 *ptr='\0';
423 //printf(" %d --- > %s %s Params: %s\n",
424 //__LINE__, id, IDL_IDENT(ident).str, IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value);
425 fprintf(ski->of, "#ifndef %s_ParmCheck\n", id);
426 fprintf(ski->of, "#define %s_ParmCheck\n", id);
427 fprintf(ski->of, "#endif\n");
428 *ptr='_';
429 }
430 }
431 g_free(id);
432 }/* PASS_VOYAGER_...*/
433}
434
435/*
436 Output a generic function for checking the object pointer.
437 */
438static void
439VoyagerCreateObjectCheckFunction(char *id2, CBESkelImplInfo *ski)
440{
441#if 0
442 if(PASS_VOYAGER_PARMCHECK==ski->pass)
443 {
444
445 char *id, *id2;
446 IDL_tree curitem;
447 int level;
448 GString *gstr;
449
450 curitem = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, &level);
451 g_assert(curitem);
452
453 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(ski->tree).ident), "_", 0);
454 id2 = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curitem).ident), "_", 0);
455
456 gstr=g_string_new(IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
457#endif
458
459 /* Output a function for checking the parameters. Note that we only
460 check the object pointer. */
461 fprintf(ski->of, "\n/* Function to check if an object is valid before calling a method on it */\n");
462 fprintf(ski->of, "#ifdef NOM_NO_PARAM_CHECK /* Disabled by now because not working */\n");
463 fprintf(ski->of, "NOMEXTERN ");
464 fprintf(ski->of, "gboolean NOMLINK objectCheckFunc_%s(%s *nomSelf, gchar* chrMethodName)\n",
465 id2, id2);
466 fprintf(ski->of, "{\n");
467
468 fprintf(ski->of, "if(!nomIsObj(nomSelf) || !_nomIsANoClsCheck(nomSelf , %sClassData.classObject, NULLHANDLE))\n", id2);
469 fprintf(ski->of, " {\n");
470 fprintf(ski->of, " nomPrintObjectPointerError(nomSelf, \"%s\", chrMethodName);\n", id2);
471 fprintf(ski->of, " g_message(\"Note that NULL is returned for the call (if the method returns a value). This may not be correct. Use the NOMPARMCHECK() macro to specify default return values for methods.\");\n");
472 fprintf(ski->of, " return FALSE;\n");
473 fprintf(ski->of, " }\n");
474 fprintf(ski->of, " return TRUE;\n");
475 fprintf(ski->of, "}\n");
476 fprintf(ski->of, "#endif\n");
477 // g_free(id); g_free(id2);
478 // }
479}
480
481
482/*
483 This function outputs the parameter type of methods without the 'const'
484 qualifier.
485 */
486static void VoyagerOutputParamTypes(CBESkelImplInfo *ski)
487{
488 if(IDLN_PARAM_DCL!=IDL_NODE_TYPE(ski->tree))
489 return;
490
491 orbit_cbe_voyager_write_param_typespec(ski->of, ski->tree);
492}
493
494static void
495orbit_cbe_ski_process_piece(CBESkelImplInfo *ski)
496{
497 /* I'm not implementing this as an array of function pointers
498 because we may want to do special logic for particular cases in
499 the future. Hope this is clear enough. -ECL */
500
501
502 switch(IDL_NODE_TYPE(ski->tree)) {
503 case IDLN_ATTR_DCL:
504 //#ifdef USE_LIBIDL_CODE
505 cbe_ski_do_attr_dcl(ski);
506 //#else
507 cbe_ski_do_voyager_instance_vars(ski);
508 cbe_ski_do_voyager_getdata_macros(ski);
509 //#endif
510 break;
511 case IDLN_INTERFACE:
512 cbe_ski_do_interface(ski);
513 // printf("%d: pass --->%d %d %d\n", __LINE__, ski->pass, whichPass, ulCurInterface);
514 break;
515 case IDLN_LIST:
516 cbe_ski_do_list(ski);
517 break;
518 case IDLN_MODULE:
519 cbe_ski_do_module(ski);
520 break;
521 case IDLN_OP_DCL:
522 cbe_ski_do_op_dcl(ski);
523 break;
524 case IDLN_PARAM_DCL:
525 cbe_ski_do_param_dcl(ski);
526 break;
527 case IDLN_CONST_DCL:
528 /* Find the name of the metaclass for this class if any. */
529 VoyagerExtractMetaClass(ski);
530 /* Create enable defines for parameter checks. */
531 VoyagerCreateParamCheckDefines(ski);
532 break;
533 default:
534 break;
535 }
536}
537
538static void
539cbe_ski_do_module(CBESkelImplInfo *ski)
540{
541 CBESkelImplInfo subski = *ski;
542 subski.tree = IDL_MODULE(ski->tree).definition_list;
543 cbe_ski_do_list(&subski);
544}
545
546/* Returns 1 if the previous character written to f */
547/* was '\n', 0 otherwise. */
548static inline unsigned char
549prev_char_is_nl(FILE *f)
550{
551 char c;
552 long pos;
553 size_t count;
554 unsigned char retv = 0;
555
556 pos = ftell(f);
557 if (pos < sizeof(char))
558 return 0; /* beginning of file */
559
560 if (fseek(f, (-1)*sizeof(char), SEEK_CUR))
561 goto out;
562
563 count = fread((void*)&c, sizeof(char), 1, f);
564 if (sizeof(char) == count)
565 retv = ('\n' == c) ? 1 : 0;
566
567out:
568 fseek(f, pos, SEEK_SET);
569 return retv;
570}
571
572static void
573cbe_ski_do_list(CBESkelImplInfo *ski)
574{
575 CBESkelImplInfo subski = *ski;
576 IDL_tree curitem;
577
578 for(curitem = ski->tree; curitem; curitem = IDL_LIST(curitem).next) {
579 subski.tree = IDL_LIST(curitem).data;
580 orbit_cbe_ski_process_piece(&subski);
581 if(!prev_char_is_nl(ski->of))
582 fprintf(ski->of, "\n");
583 }
584}
585
586static void cbe_ski_do_voyager_instance_vars(CBESkelImplInfo *ski/*, IDL_tree current_interface , gboolean inherited*/)
587{
588 IDL_tree curitem;
589
590 if(ski->pass == PASS_VOYAGER_INSTANCE) {
591 for(curitem = IDL_ATTR_DCL(ski->tree).simple_declarations; curitem;
592 curitem = IDL_LIST(curitem).next) {
593 char* ptr;
594 /* Indent type */
595 fprintf(ski->of, " ");
596 orbit_cbe_write_typespec(ski->of, IDL_ATTR_DCL(ski->tree).param_type_spec);
597 ulInstanceVarSize[ulCurInterface]+=orbit_cbe_get_typespec_size(IDL_ATTR_DCL(ski->tree).param_type_spec);
598
599 /* Print the instance var name. To allow equally named vars in subclasses
600 (which isn't supported by orbit-IDL) we use a macro in the *.idl file
601 which adds a marker and the line num to the var name. Here we throw
602 this unique name extension away. */
603 if((ptr=strstr(IDL_IDENT(IDL_LIST(curitem).data).str, NOM_INSTANCEVAR_STRING))!=NULL)
604 {
605 /* This is our marked var. */
606 *ptr='\0';
607 fprintf(ski->of, " %s;\n", IDL_IDENT(IDL_LIST(curitem).data).str);
608 *ptr='_';
609 }
610 else{
611 fprintf(ski->of, " %s;\n", IDL_IDENT(IDL_LIST(curitem).data).str);
612 fprintf(ski->of, "#warning Instance var %s defined without INSTANCEVAR() macro\n",
613 IDL_IDENT(IDL_LIST(curitem).data).str);
614 }
615 }
616 }
617}
618
619static void cbe_ski_do_voyager_getdata_macros(CBESkelImplInfo *ski/*, IDL_tree current_interface , gboolean inherited*/)
620{
621 IDL_tree curitem;
622
623 if(ski->pass == PASS_VOYAGER_GETDATA) {
624 for(curitem = IDL_ATTR_DCL(ski->tree).simple_declarations; curitem;
625 curitem = IDL_LIST(curitem).next) {
626 char* ptr;
627 /* Indent type */
628 fprintf(ski->of,"#define ");
629 /* Print the instance var name. To allow equally named vars in subclasses
630 (which isn't supported by orbit-IDL) we use a macro in the *.idl file
631 which adds a marker and the line num to the var name. Here we throw
632 this unique name extension away. */
633 if((ptr=strstr(IDL_IDENT(IDL_LIST(curitem).data).str, NOM_INSTANCEVAR_STRING))!=NULL)
634 {
635 *ptr='\0';
636 fprintf(ski->of, " _%s (nomThis->%s)\n",
637 IDL_IDENT(IDL_LIST(curitem).data).str, IDL_IDENT(IDL_LIST(curitem).data).str);
638 *ptr='_';
639 }
640 else{
641 fprintf(ski->of, " _%s (nomThis->%s)\n",
642 IDL_IDENT(IDL_LIST(curitem).data).str, IDL_IDENT(IDL_LIST(curitem).data).str);
643 fprintf(ski->of, "#warning Instance var %s defined without INSTANCEVAR() macro\n",
644 IDL_IDENT(IDL_LIST(curitem).data).str);
645 }
646 }
647 }
648}
649
650static void cbe_ski_do_voyager_classinfo_structure(CBESkelImplInfo *ski, gchar * className)
651{
652
653 /* Fill the info struct */
654 fprintf(ski->of, "static nomStaticClassInfo %sSCI = {\n", className);
655 fprintf(ski->of, " 0, /* Version */\n");
656 fprintf(ski->of, " %ld, /* Number of static methods introduced by this class */\n",
657 ulNumStaticMethods[ulCurInterface]);
658 fprintf(ski->of, " %ld, /* Overrides */\n", ulNumOverridenMethods[ulCurInterface]);
659 fprintf(ski->of, " %s_MajorVersion,\n", className);
660 fprintf(ski->of, " %s_MinorVersion,\n", className);
661 fprintf(ski->of, " %ld, /* Instance data size */\n", ulInstanceVarSize[ulCurInterface]);
662 fprintf(ski->of, " 1, /* Number of parents (multiple inheritance) */\n");
663 fprintf(ski->of, " &nomIdString_%s,\n", className);
664 if(NULL!=gsMetaClassName[ulCurInterface])
665 fprintf(ski->of, " &nomIdStringMetaClass_%s, /* Explicit meta id*/\n", className);
666 else
667 fprintf(ski->of, " (nomID)0, /* Explicit meta id*/\n");
668 fprintf(ski->of, " (nomClassDataStructure*)&%sClassData,\n", className);
669 fprintf(ski->of, " (nomCClassDataStructure*)&%sCClassData,\n", className);
670 fprintf(ski->of, " (nomStaticMethodDesc*)&nomStaticMethods%s,\n", className);
671 if(0!=ulNumParentsInChain[ulCurInterface])
672 fprintf(ski->of, " nomParentClasses%s,\n", className);
673 else
674 fprintf(ski->of, " (void*)0,\n");
675 if(0!=ulNumParentsInChain[ulCurInterface])
676 fprintf(ski->of, " nomParentClassNames%s, /* Name of all the parent classes in chain */\n", className);
677 else
678 fprintf(ski->of, " (void*)0,\n");
679 fprintf(ski->of, " %ld, /* Number of parents in the chain of classes */\n", ulNumParentsInChain[ulCurInterface]);
680 if(0!=ulNumOverridenMethods[ulCurInterface])
681 fprintf(ski->of, " nomOverridenMethods%s, /* Name of all the parent classes in chain */\n", className);
682 else
683 fprintf(ski->of, " (void*)0,\n");
684
685 fprintf(ski->of, "};\n");
686
687}
688
689static void
690cbe_ski_do_voyager_parent_idstrings(IDL_tree interface, CBESkelImplInfo *ski)
691{
692 char *id = NULL, *inherit_id = NULL; /* Quiet gcc */
693
694 if(interface==ski->tree)
695 return;
696
697 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ski->tree).ident),
698 "_", 0);
699 inherit_id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(interface).ident),
700 "_", 0);
701
702 fprintf(ski->of, " static char * nomIdString_Parent_%s = \"%s\";\n", inherit_id, inherit_id);
703 ulNumParentsInChain[ulCurInterface]++;
704 g_free(id);
705 g_free(inherit_id);
706}
707
708static void
709cbe_ski_do_voyager_parent_names(IDL_tree interface, CBESkelImplInfo *ski)
710{
711 char *id = NULL, *inherit_id = NULL; /* Quiet gcc */
712
713 if(interface==ski->tree)
714 return;
715
716 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ski->tree).ident),
717 "_", 0);
718 inherit_id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(interface).ident),
719 "_", 0);
720
721 fprintf(ski->of, " \"%s\",\n", inherit_id);
722 ulNumParentsInChain[ulCurInterface]++;
723 g_free(id);
724 g_free(inherit_id);
725}
726
727static void
728cbe_ski_do_voyager_parent_ids(IDL_tree interface, CBESkelImplInfo *ski)
729{
730 char *id = NULL, *inherit_id = NULL; /* Quiet gcc */
731
732 if(interface==ski->tree)
733 return;
734
735 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ski->tree).ident),
736 "_", 0);
737 inherit_id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(interface).ident),
738 "_", 0);
739
740 fprintf(ski->of, " &nomIdString_Parent_%s,\n", inherit_id);
741
742 g_free(id);
743 g_free(inherit_id);
744}
745
746static void
747cbe_ski_do_voyager_parent_newclass(IDL_tree interface, CBESkelImplInfo *ski)
748{
749 char *id = NULL, *inherit_id = NULL; /* Quiet gcc */
750
751 if(interface==ski->tree)
752 return;
753
754 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ski->tree).ident),
755 "_", 0);
756 inherit_id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(interface).ident),
757 "_", 0);
758
759 fprintf(ski->of, " %sNewClass(%s_MajorVersion, %s_MinorVersion);\n",
760 inherit_id, inherit_id, inherit_id);
761
762 g_free(id);
763 g_free(inherit_id);
764}
765
766static void
767cbe_ski_do_attr_dcl_internal(CBESkelImplInfo *ski, IDL_tree current_interface, gboolean inherited)
768{
769 IDL_tree curop, curitem;
770 GString *attrname = g_string_new(NULL);
771 CBESkelImplInfo subski = *ski;
772
773 if(ski->pass == PASS_SERVANTS) {
774 for(curitem = IDL_ATTR_DCL(ski->tree).simple_declarations; curitem;
775 curitem = IDL_LIST(curitem).next) {
776 /* Indent type */
777 fprintf(ski->of, " ");
778 orbit_cbe_write_typespec(ski->of, IDL_ATTR_DCL(ski->tree).param_type_spec);
779 fprintf(ski->of, " attr_%s;\n", IDL_IDENT(IDL_LIST(curitem).data).str);
780 }
781 }
782
783 for(curitem = IDL_ATTR_DCL(ski->tree).simple_declarations;
784 curitem; curitem = IDL_LIST(curitem).next) {
785
786 /* Fake the attribute get/set methods as operation declarations */
787 IDL_tree ident, ns_data_save;
788 int i;
789
790 for (i = 0; i < 2; ++i) {
791
792 if (i && IDL_ATTR_DCL(ski->tree).f_readonly)
793 break;
794 /* Output the operation on this attribute */
795 g_string_printf(attrname, i ? "_set_%s" : "_get_%s",
796 IDL_IDENT(IDL_LIST(curitem).data).str);
797 ident = IDL_ident_new(g_strdup(attrname->str));
798
799 /* Tell the ident where our namespace node is, and request a return value
800 if this is the _get operation */
801 IDL_IDENT_TO_NS(ident) = IDL_IDENT_TO_NS(IDL_LIST(curitem).data);
802 curop = IDL_op_dcl_new(0, i == 0 ?
803 IDL_ATTR_DCL(ski->tree).param_type_spec : NULL,
804 ident, NULL, NULL, NULL);
805
806 curop->up = ski->tree->up;
807 subski.tree = curop;
808
809 /* Save the namespace ident (IDL_GENTREE data) reference, assign
810 back to the temporary tree, output the operation, then restore
811 the namespace ident link */
812 ns_data_save = IDL_GENTREE(IDL_IDENT_TO_NS(IDL_LIST(curitem).data)).data;
813 IDL_GENTREE(IDL_IDENT_TO_NS(IDL_LIST(curitem).data)).data = ident;
814
815 if (i) {
816 /* The set routine also needs the value, so we
817 temporarily add that to the operation
818 declaration */
819 IDL_OP_DCL(curop).parameter_dcls = IDL_list_new(
820 IDL_param_dcl_new(IDL_PARAM_IN,
821 IDL_ATTR_DCL(ski->tree).param_type_spec,
822 IDL_ident_new(g_strdup("value"))));
823 }
824
825 if(inherited==TRUE)
826 cbe_ski_do_inherited_op_dcl(&subski, current_interface);
827 else
828 orbit_cbe_ski_process_piece(&subski);
829
830 /* Restore the fake link to the original in the namespace */
831 IDL_GENTREE(IDL_IDENT_TO_NS(IDL_LIST(curitem).data)).data = ns_data_save;
832
833 if (i) {
834 /* Free only what we've created for the fake node, so remove
835 the attribute node element and then free the rest */
836 IDL_PARAM_DCL(IDL_LIST(
837 IDL_OP_DCL(curop).parameter_dcls).data).param_type_spec = NULL;
838 }
839
840 /* Remove what we've "borrowed" from ATTR_DCL from the
841 fake curop node then free the rest */
842 IDL_OP_DCL(curop).op_type_spec = NULL;
843 IDL_tree_free(curop);
844 }
845 }
846
847 g_string_free(attrname, TRUE);
848}
849
850static void
851cbe_ski_do_attr_dcl(CBESkelImplInfo *ski)
852{
853 cbe_ski_do_attr_dcl_internal(ski, NULL, FALSE);
854}
855
856void
857cbe_ski_do_inherited_attr_dcl(CBESkelImplInfo *ski, IDL_tree current_interface)
858{
859 cbe_ski_do_attr_dcl_internal(ski, current_interface, TRUE);
860}
861
862
863static void
864cbe_ski_do_op_dcl(CBESkelImplInfo *ski)
865{
866 /* If you fix anything here, please also fix it in
867 cbe_ski_do_inherited_op_dcl(), which is almost a
868 cut-and-paste of this routine */
869
870 char *id, *id2;
871 IDL_tree curitem, op;
872 int level;
873 CBESkelImplInfo subski = *ski;
874
875 switch(ski->pass) {
876#if USE_LIBIDL_CODE
877 case PASS_PROTOS:
878 case PASS_IMPLSTUBS:
879#else
880 case PASS_IMPLSTUBS:
881 break;
882 case PASS_PROTOS:
883#endif
884 {
885 GString *gstr;
886 gboolean bOverriden=FALSE;
887
888 curitem = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, &level);
889 g_assert(curitem);
890
891 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(ski->tree).ident), "_", 0);
892 id2 = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curitem).ident), "_", 0);
893
894 gstr=g_string_new(IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
895
896 /* Check for our specially marked NOM-only methods. Don't output them here, they are handled
897 specially. */
898 if(!strstr(id, NOM_INSTANCEVAR_STRING) /*&& !strstr(id, NOM_OVERRIDE_STRING)*/)
899 {
900 char *ptr=NULL;
901 char *ptr2=NULL;
902
903 if((ptr=strstr(id, NOM_OVERRIDE_STRING))!=NULL)
904 {
905 *ptr='\0';
906 bOverriden=TRUE;
907 }
908 if((ptr2=strstr(gstr->str, NOM_OVERRIDE_STRING))!=NULL)
909 {
910 *ptr2='\0';
911 }
912
913 if(bOverriden)
914 fprintf(ski->of, "/*\n * Overriden method: %s\n */\n", gstr->str);
915 else
916 fprintf(ski->of, "/*\n * New method: %s\n */\n", IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
917 /* protect with #ifdef block */
918 if(PASS_PROTOS == ski->pass)
919 fprintf(ski->of, "#if !defined(_decl_impl_");
920 else
921 fprintf(ski->of, "#if !defined(_impl_");
922
923 fprintf(ski->of, "%s_) /* %s, %s line %d */\n", id, __FILE__, __FUNCTION__, __LINE__);
924
925 if(PASS_PROTOS == ski->pass)
926 fprintf(ski->of, "#define _decl_impl_");
927 else
928 fprintf(ski->of, "#define _impl_");
929
930 fprintf(ski->of, "%s_ 1\n", id);
931#if USE_LIBIDL_CODE
932 fprintf(ski->of, "static ");
933 fprintf(ski->of, " impl_%s(impl_POA_%s *servant,\n", id, id2);
934#endif
935
936 /* Output the params */
937 if(bOverriden)
938 {
939 /* Overriden method */
940 fprintf(ski->of, "NOM_Scope ");
941 op = ski->tree;
942 VoyagerWriteOverridenMethodDeclaration(ski->of, op, "", FALSE);
943
944 for(curitem = IDL_OP_DCL(ski->tree).parameter_dcls;
945 curitem; curitem = IDL_LIST(curitem).next) {
946 subski.tree = IDL_LIST(curitem).data;
947 orbit_cbe_ski_process_piece(&subski);
948 }
949 }
950 else
951 {
952 fprintf(ski->of, "NOM_Scope ");
953
954 orbit_cbe_write_param_typespec(ski->of, ski->tree);
955 fprintf(ski->of, " NOMLINK impl_%s_%s(%s *nomSelf,\n",
956 id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str, id2);
957
958 op = ski->tree;
959 for(curitem = IDL_OP_DCL(ski->tree).parameter_dcls;
960 curitem; curitem = IDL_LIST(curitem).next) {
961 subski.tree = IDL_LIST(curitem).data;
962 orbit_cbe_ski_process_piece(&subski);
963 }
964 }
965
966 if(IDL_OP_DCL(op).context_expr)
967 fprintf(ski->of, "CORBA_Context ctx,\n");
968
969 fprintf(ski->of, "CORBA_Environment *ev)");
970#if USE_LIBIDL_CODE
971 if(ski->pass == PASS_IMPLSTUBS) {
972 fprintf(ski->of, "\n{\n ");
973 if(IDL_OP_DCL(op).op_type_spec) {
974 orbit_cbe_write_param_typespec(ski->of, ski->tree);
975 fprintf(ski->of, " retval;\n\n");
976 fprintf(ski->of, " /* ------ insert method code here ------ */\n");
977 fprintf(ski->of, " /* ------ ---------- end ------------ ------ */\n");
978 fprintf(ski->of, "\n return retval;\n");
979 }
980 else
981 {
982 fprintf(ski->of, " /* ------ insert method code here ------ */\n");
983 fprintf(ski->of, " /* ------ ---------- end ------------ ------ */\n");
984 }
985 fprintf(ski->of, "}\n");
986 } else /* PASS_PROTOS */
987#endif
988 fprintf(ski->of, ";\n");
989
990 if(bOverriden)
991 {
992 IDL_tree tmptree;
993
994 tmptree = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, NULL);;
995 fprintf(ski->of, "static char* nomIdString_%s_%s = \"",
996 id2, gstr->str);
997 /* Output name of introducing class */
998#if 0
999 if(IDL_INTERFACE(tmptree).inheritance_spec) {
1000 InheritedOutputInfo ioi;
1001
1002 ioi.of = ski->of;
1003 ioi.realif = tmptree;
1004 ioi.chrOverridenMethodName=gstr->str;
1005 IDL_tree_traverse_parents(IDL_INTERFACE(tmptree).inheritance_spec,
1006 (GFunc)VoyagerOutputIntroducingClass, &ioi);
1007 }
1008#endif
1009 VoyagerOutputIntroducingClass(tmptree, ski, gstr);
1010 fprintf(ski->of, ":%s\";\n",gstr->str); /* Output the method name */
1011
1012 fprintf(ski->of, "/* %s, %s line %d */\n", __FILE__, __FUNCTION__, __LINE__);
1013 fprintf(ski->of, "static nomMethodProc* %s_parent_resolved;\n", id);
1014 fprintf(ski->of, "#define %s_parent", id);
1015
1016 /* output params for macro */
1017 fprintf(ski->of, "(nomSelf, ");
1018 if(IDL_INTERFACE(tmptree).inheritance_spec) {
1019 InheritedOutputInfo ioi;
1020
1021 ioi.of = ski->of;
1022 ioi.realif = tmptree;
1023 ioi.chrOverridenMethodName=gstr->str;
1024 IDL_tree_traverse_parents(IDL_INTERFACE(tmptree).inheritance_spec,
1025 (GFunc)VoyagerWriteParamsForParentCall, &ioi);
1026 }
1027 fprintf(ski->of, "ev)");
1028 fprintf(ski->of, " \\\n (((");
1029
1030 /* Output the typespec of the overriden proc */
1031 if(IDL_INTERFACE(tmptree).inheritance_spec) {
1032 InheritedOutputInfo ioi;
1033
1034 ioi.of = ski->of;
1035 ioi.realif = tmptree;
1036 ioi.chrOverridenMethodName=gstr->str;
1037 IDL_tree_traverse_parents(IDL_INTERFACE(tmptree).inheritance_spec,
1038 (GFunc)VoyagerOutputParentMethodSpec, &ioi);
1039 }
1040 fprintf(ski->of, ") \\\n %s_parent_resolved)", id);
1041 /* output params for macro */
1042 // VoyagerWriteParamsForParentCall (ski->of, ski->tree );
1043 fprintf(ski->of, "((");
1044 /* Output name of introducing class */
1045#if 0
1046 if(IDL_INTERFACE(tmptree).inheritance_spec) {
1047 InheritedOutputInfo ioi;
1048
1049 ioi.of = ski->of;
1050 ioi.realif = tmptree;
1051 ioi.chrOverridenMethodName=gstr->str;
1052 IDL_tree_traverse_parents(IDL_INTERFACE(tmptree).inheritance_spec,
1053 (GFunc)VoyagerOutputIntroducingClass, &ioi);
1054 }
1055#endif
1056 VoyagerOutputIntroducingClass(tmptree, ski, gstr);
1057 fprintf(ski->of, "*)nomSelf, ");
1058
1059 if(IDL_INTERFACE(tmptree).inheritance_spec) {
1060 InheritedOutputInfo ioi;
1061
1062 ioi.of = ski->of;
1063 ioi.realif = tmptree;
1064 ioi.chrOverridenMethodName=gstr->str;
1065 IDL_tree_traverse_parents(IDL_INTERFACE(tmptree).inheritance_spec,
1066 (GFunc)VoyagerWriteParamsForParentCall, &ioi);
1067 }
1068 fprintf(ski->of, "ev)");
1069 fprintf(ski->of, ")\n");
1070 }
1071 else{
1072 fprintf(ski->of, "static char* nomIdString_%s_%s = nomMNDef_%s_%s;\n",
1073 id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str,
1074 id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
1075 fprintf(ski->of, "static char* nomFullIdString_%s_%s = nomMNFullDef_%s_%s;\n",
1076 id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str,
1077 id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
1078 }
1079
1080 /* Output the parameter info for runtime type information */
1081 if(!bOverriden)
1082 {
1083 int a=0;
1084 IDL_tree tmptree;
1085
1086 tmptree = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, NULL);
1087
1088 fprintf(ski->of, "static nomParmInfo nomParm_%s = {\n", id);
1089
1090 /* Output number of parameters */
1091 for(curitem = IDL_OP_DCL(ski->tree).parameter_dcls;
1092 curitem; curitem = IDL_LIST(curitem).next) {
1093 a++; /* Count parameters */
1094 }
1095 fprintf(ski->of, " %d, /* Number of parameters */\n", a);
1096
1097 /* Output return type */
1098 fprintf(ski->of, " /* Return type (%s: %s line %d)*/\n \"", __FILE__, __FUNCTION__, __LINE__);
1099 orbit_cbe_write_param_typespec(ski->of, ski->tree);
1100 fprintf(ski->of, "\",\n {");
1101
1102 op = ski->tree;
1103 for(curitem = IDL_OP_DCL(ski->tree).parameter_dcls;
1104 curitem; curitem = IDL_LIST(curitem).next) {
1105 subski.tree = IDL_LIST(curitem).data;
1106
1107 fprintf(ski->of, " \"");
1108 if(IDLN_PARAM_DCL==IDL_NODE_TYPE(subski.tree))
1109 VoyagerOutputParamTypes(&subski);
1110 fprintf(ski->of, "\",\n");
1111 }
1112 fprintf(ski->of, "}};\n");
1113 }
1114
1115 /* Output a function for checking the parameters. Note that we only
1116 check the object pointer for now. */
1117 if(!bOverriden)
1118 {
1119 fprintf(ski->of, "#ifdef %s_ParmCheck\n", id);
1120 fprintf(ski->of, "NOMEXTERN ");
1121 fprintf(ski->of, "gboolean NOMLINK parmCheckFunc_%s_%s(%s *nomSelf,\n",
1122 id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str, id2);
1123 op = ski->tree;
1124 for(curitem = IDL_OP_DCL(ski->tree).parameter_dcls;
1125 curitem; curitem = IDL_LIST(curitem).next) {
1126 subski.tree = IDL_LIST(curitem).data;
1127 orbit_cbe_ski_process_piece(&subski);
1128 }
1129
1130 if(IDL_OP_DCL(op).context_expr)
1131 fprintf(ski->of, "CORBA_Context ctx,\n");
1132 fprintf(ski->of, "CORBA_Environment *ev)");
1133
1134 fprintf(ski->of, "{\n");
1135
1136 fprintf(ski->of, "if(!nomIsObj(nomSelf) || !_nomIsANoClsCheck(nomSelf , %sClassData.classObject, NULLHANDLE))\n", id2);
1137 fprintf(ski->of, " {\n");
1138 fprintf(ski->of, " nomPrintObjectPointerError(nomSelf, \"%s\", \"%s\");\n", id2, id);
1139 fprintf(ski->of, " return FALSE;\n");
1140 fprintf(ski->of, " }\n");
1141 fprintf(ski->of, " g_message(\"%%s: parameter check for %%s...\", __FUNCTION__, _nomGetClassName(nomSelf, NULLHANDLE));\n");
1142 fprintf(ski->of, " return TRUE;\n");
1143 fprintf(ski->of, "}\n");
1144 fprintf(ski->of, "#endif\n");
1145 }
1146
1147
1148 if(ptr!=NULL)
1149 *ptr='_';
1150
1151 if(ptr2!=NULL)
1152 *ptr2='_';
1153
1154 g_string_free(gstr, TRUE);
1155 g_free(id); g_free(id2);
1156
1157 fprintf(ski->of, "#endif\n\n"); /* end of protective #ifdef block */
1158 }
1159 else{ /* NOM_INSTANCEVAR_STRING... */
1160 g_free(id); g_free(id2);
1161 }
1162 break; /* End PASS_PROTOS | PASS_IMPLSTUBS */
1163 }
1164 case PASS_EPVS:
1165#if USE_LIBIDL_CODE
1166 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(ski->tree).ident), "_", 0);
1167 fprintf(ski->of, "(gpointer)&impl_%s,\n", id);
1168 g_free(id);
1169#endif
1170 break;
1171 case PASS_VOYAGER_STATICMETHODS:
1172 {
1173 /* Build the structs for the static methods array. */
1174 curitem = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, &level);
1175 g_assert(curitem);
1176
1177 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(ski->tree).ident), "_", 0);
1178 id2 = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curitem).ident), "_", 0);
1179
1180 /* Check for our specially marked NOM-only methods. Don't output them, they are handled
1181 specially. */
1182 if(!strstr(id, NOM_INSTANCEVAR_STRING) &&
1183 !strstr(id, NOM_OVERRIDE_STRING))
1184 {
1185 fprintf(ski->of, "{ /* (%s, %s line %d) */\n", __FILE__, __FUNCTION__, __LINE__);
1186 fprintf(ski->of, " &%sClassData.%s,\n", id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
1187 fprintf(ski->of, " (nomID)&nomIdString_%s_%s,\n", id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
1188 fprintf(ski->of, " &nomFullIdString_%s_%s, /* char *chrMethodDescriptor */\n",
1189 id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
1190 fprintf(ski->of, " (nomMethodProc*) impl_%s_%s,\n", id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
1191 fprintf(ski->of, " &nomParm_%s_%s\n", id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
1192 fprintf(ski->of, "},\n");
1193
1194 ulNumStaticMethods[ulCurInterface]++;
1195
1196 g_free(id); g_free(id2);
1197 }
1198 else{ /* NOM_OVERRIDE_STRING... */
1199 g_free(id); g_free(id2);
1200 }
1201 break; /* End */
1202 }
1203 case PASS_VOYAGER_OVERRIDEN_METHODTAB:
1204 {
1205 char *ptr;
1206
1207 curitem = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, &level);
1208 g_assert(curitem);
1209
1210 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(ski->tree).ident), "_", 0);
1211 // id2 = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curitem).ident), "_", 0);
1212 id2 = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(ski->tree).ident), "_", 0);
1213
1214 if((ptr=strstr(id, NOM_OVERRIDE_STRING))!=NULL)
1215 {
1216 /* fprintf(ski->of, "%s\n",id); */
1217 /* This is our marked var. */
1218 *ptr='\0';
1219 // fprintf(ski->of, " %s;\n", IDL_IDENT(IDL_LIST(curitem).data).str);
1220 fprintf(ski->of, " /* (%s, %s line %d) */\n", __FILE__, __FUNCTION__, __LINE__);
1221 //fprintf(ski->of, " static gchar* string%s_overriden = \"", id);
1222 *ptr='_';
1223
1224 fprintf(ski->of, " {\n");
1225 if((ptr=strstr(id2, NOM_OVERRIDE_STRING))!=NULL){
1226 *ptr='\0';
1227 fprintf(ski->of, " &nomIdString_%s, /* line %d */\n", id2, __LINE__);
1228 fprintf(ski->of, " (nomMethodProc*) impl_%s,\n", id2);
1229 fprintf(ski->of, " &%s_parent_resolved\n", id2);
1230 *ptr='_';
1231 }
1232 fprintf(ski->of, " },\n");
1233 //fprintf(ski->of, " static gchar* string%s_overriden = \":%s %s\";\n",
1234 // id, IDL_IDENT(IDL_LIST(curitem).data).str, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
1235
1236 //fprintf(ski->of, "\n");
1237 ulNumOverridenMethods[ulCurInterface]++;
1238 }
1239
1240 g_free(id); //g_free(id2);
1241 break;
1242 }
1243 case PASS_VOYAGER_OVERRIDEN_METHODS:
1244 {
1245
1246 break;
1247 }
1248 default:
1249 break;
1250 }
1251}
1252
1253static void
1254cbe_ski_do_inherited_op_dcl(CBESkelImplInfo *ski, IDL_tree current_interface)
1255{
1256 char *id, *id2;
1257 IDL_tree ident, curitem, intf, op;
1258 int level;
1259 CBESkelImplInfo subski = *ski;
1260
1261 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(current_interface).ident), "_", 0);
1262 intf = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, NULL);
1263 id2 = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(intf).ident), "_", 0);
1264
1265 ident=IDL_OP_DCL(ski->tree).ident;
1266 g_assert(ident);
1267
1268 switch(ski->pass) {
1269#if USE_LIBIDL_CODE
1270 case PASS_PROTOS:
1271 case PASS_IMPLSTUBS:
1272#else
1273 case PASS_IMPLSTUBS:
1274 break;
1275 case PASS_PROTOS:
1276#endif
1277 curitem = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, &level);
1278 g_assert(curitem);
1279
1280
1281 /* Check for our specially marked NOM-only methods. Don't output them, they are handled
1282 specially. */
1283 if(!strstr(IDL_IDENT(ident).str, NOM_INSTANCEVAR_STRING) &&
1284 !strstr(IDL_IDENT(ident).str, NOM_OVERRIDE_STRING))
1285 {
1286 fprintf(ski->of, "/* FIXME: We don't need these for Voyager? %s, %s line %d */\n",
1287 __FILE__, __FUNCTION__, __LINE__);
1288 /* protect with #ifdef block */
1289 if(PASS_PROTOS == ski->pass)
1290 fprintf(ski->of, "#if !defined(_decl_impl_");
1291 else
1292 fprintf(ski->of, "#if !defined(_impl_");
1293 fprintf(ski->of, "%s_%s_)\n", id, IDL_IDENT(ident).str);
1294
1295 if(PASS_PROTOS == ski->pass)
1296 fprintf(ski->of, "#define _decl_impl_");
1297 else
1298 fprintf(ski->of, "#define _impl_");
1299 fprintf(ski->of, "%s_%s_ 1\n", id, IDL_IDENT(ident).str);
1300#if USE_LIBIDL_CODE
1301 fprintf(ski->of, "static ");
1302#endif
1303 orbit_cbe_write_param_typespec(ski->of, ski->tree);
1304#if USE_LIBIDL_CODE
1305 fprintf(ski->of, " impl_%s_%s(impl_POA_%s *servant,\n", id, IDL_IDENT(ident).str, id);
1306#else
1307 fprintf(ski->of, " NOMLINK impl_%s_%s(%s *nomSelf,\n", id, IDL_IDENT(ident).str, id);
1308#endif
1309
1310 op = ski->tree;
1311 for(curitem = IDL_OP_DCL(ski->tree).parameter_dcls;
1312 curitem; curitem = IDL_LIST(curitem).next) {
1313 subski.tree = IDL_LIST(curitem).data;
1314 orbit_cbe_ski_process_piece(&subski);
1315 }
1316
1317 if(IDL_OP_DCL(op).context_expr)
1318 fprintf(ski->of, "CORBA_Context ctx,\n");
1319
1320 fprintf(ski->of, "CORBA_Environment *ev)");
1321 if(ski->pass == PASS_IMPLSTUBS) {
1322 fprintf(ski->of, "\n{\n ");
1323 if(IDL_OP_DCL(op).op_type_spec) {
1324 orbit_cbe_write_param_typespec(ski->of, ski->tree);
1325 fprintf(ski->of, " retval;\n\n");
1326 fprintf(ski->of, " /* ------ insert method code here ------ */\n");
1327 fprintf(ski->of, " /* ------ ---------- end ------------ ------ */\n");
1328 fprintf(ski->of, " \nreturn retval;\n");
1329 }
1330 else
1331 {
1332 fprintf(ski->of, " /* ------ insert method code here ------ */\n");
1333 fprintf(ski->of, " /* ------ ---------- end ------------ ------ */\n");
1334 }
1335 fprintf(ski->of, "}\n");
1336 } else /* PASS_PROTOS */
1337 fprintf(ski->of, ";\n");
1338
1339 fprintf(ski->of, "#endif\n\n"); /* end of protective #ifdef block */
1340 }/* NOM_OVERRIDE_STRING... */
1341
1342 break; /* End PASS_PROTOS | PASS_IMPLSTUBS */
1343 case PASS_EPVS:
1344#if USE_LIBIDL_CODE
1345 ident=IDL_OP_DCL(ski->tree).ident;
1346 g_assert(ident);
1347
1348 fprintf(ski->of, "(gpointer)&impl_%s_%s,\n", id, IDL_IDENT(ident).str);
1349#endif
1350 default:
1351 break;
1352 }
1353
1354 g_free(id);
1355 g_free(id2);
1356}
1357
1358static void
1359cbe_ski_do_param_dcl(CBESkelImplInfo *ski)
1360{
1361 orbit_cbe_write_param_typespec(ski->of, ski->tree);
1362 fprintf(ski->of, " %s,\n", IDL_IDENT(IDL_PARAM_DCL(ski->tree).simple_declarator).str);
1363}
1364
1365static void
1366cbe_ski_do_interface_vepv_entry(IDL_tree interface, CBESkelImplInfo *ski)
1367{
1368 char *id, *inherit_id;
1369
1370 if(interface==ski->tree) {
1371 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ski->tree).ident), "_", 0);
1372 fprintf(ski->of, "&impl_%s_epv,\n", id);
1373 g_free(id);
1374 return;
1375 }
1376
1377 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ski->tree).ident), "_", 0);
1378 inherit_id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(interface).ident),
1379 "_", 0);
1380 fprintf(ski->of, "&impl_%s_%s_epv,\n", id, inherit_id);
1381
1382 g_free(id);
1383 g_free(inherit_id);
1384}
1385
1386static void
1387cbe_ski_do_inherited_methods(IDL_tree interface, CBESkelImplInfo *ski)
1388{
1389 CBESkelImplInfo subski= *ski;
1390 IDL_tree curitem;
1391 char *id = NULL, *inherit_id = NULL; /* Quiet gcc */
1392
1393 if(interface==ski->tree)
1394 return;
1395
1396 if(ski->pass==PASS_EPVS) {
1397 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ski->tree).ident),
1398 "_", 0);
1399 inherit_id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(interface).ident),
1400 "_", 0);
1401 /* protect with #ifdef block */
1402 fprintf(ski->of, "#if !defined(_impl_%s_%s_epv_)\n", id, inherit_id);
1403 fprintf(ski->of, "#define _impl_%s_%s_epv_ 1\n", id, inherit_id);
1404 fprintf(ski->of, "static POA_%s__epv impl_%s_%s_epv = {\nNULL, /* _private */\n", inherit_id, id, inherit_id);
1405 }
1406
1407 for(curitem = IDL_INTERFACE(interface).body; curitem; curitem=IDL_LIST(curitem).next) {
1408 subski.tree=IDL_LIST(curitem).data;
1409
1410 switch(IDL_NODE_TYPE(IDL_LIST(curitem).data)) {
1411 case IDLN_OP_DCL:
1412 cbe_ski_do_inherited_op_dcl(&subski, ski->tree);
1413 break;
1414 case IDLN_ATTR_DCL:
1415 cbe_ski_do_inherited_attr_dcl(&subski, ski->tree);
1416 break;
1417 default:
1418 break;
1419 }
1420 }
1421
1422 if(ski->pass==PASS_EPVS) {
1423 fprintf(ski->of, "};\n");
1424 fprintf(ski->of, "#endif\n"); /* end of protective #ifdef block */
1425
1426 g_free(id);
1427 g_free(inherit_id);
1428 }
1429}
1430
1431/*
1432 CW: When doing a pass we first end here for each interface. By calling
1433 cbe_ski_do_list() all nodes are traversed and the subfunctions are called
1434 accordingly.
1435
1436 */
1437static void
1438cbe_ski_do_interface(CBESkelImplInfo *ski)
1439{
1440 char *id;
1441 CBESkelImplInfo subski = *ski;
1442
1443 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ski->tree).ident), "_", 0);
1444
1445 switch(ski->pass) {
1446 case PASS_VOYAGER_OVERRIDEN_METHODTAB:
1447 {
1448 fprintf(ski->of, "/* Table of the overriden methods by this class */\n");
1449 fprintf(ski->of, "static nomOverridenMethodDesc nomOverridenMethods%s[] = {\n", id);
1450 subski.tree = IDL_INTERFACE(ski->tree).body;
1451 cbe_ski_do_list(&subski);
1452 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1453
1454 fprintf(ski->of, "};\n\n");
1455 break;
1456 }
1457 case PASS_VOYAGER_OVERRIDEN_METHODS:
1458 {
1459 fprintf(ski->of, "/* Description of the overriden methods by this class */\n");
1460
1461 subski.tree = IDL_INTERFACE(ski->tree).body;
1462 cbe_ski_do_list(&subski);
1463 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1464
1465 break;
1466 }
1467 case PASS_VOYAGER_CLSDATA:
1468 {
1469 /* Create the static class data structs */
1470 fprintf(ski->of, "/* %s, %s line %d */\n", __FILE__, __FUNCTION__, __LINE__);
1471 fprintf(ski->of, "#ifdef NOM_%s_IMPLEMENTATION_FILE\n\n", id);
1472 fprintf(ski->of, "struct %sClassDataStructure %sClassData = {0};\n", id, id);
1473 fprintf(ski->of, "static struct %sCClassDataStructure %sCClassData = {0};\n\n", id, id);
1474
1475 break;
1476 }
1477 case PASS_VOYAGER_NEWCLASS:
1478 {
1479 IDL_tree tmptree;
1480 char* id2;
1481
1482 if(NULL!=gsMetaClassName[ulCurInterface]){
1483 char* chrTemp;
1484 chrTemp=g_ascii_strdown(gsMetaClassName[ulCurInterface]->str, -1);
1485
1486 fprintf(ski->of, "\n#include \"%s.h\"\n\n", chrTemp);
1487 g_free(chrTemp);
1488 }
1489 fprintf(ski->of, "#include \"nomgc.h\"\n");
1490 fprintf(ski->of, "NOMClass* NOMLINK %sNewClass(gulong ulMajor, gulong ulMinor)\n{\n", id);
1491 fprintf(ski->of, " NOMClass* result;\n\n");
1492
1493 fprintf(ski->of, "#ifdef __OS2__\n");
1494 fprintf(ski->of, " gulong ulObj, ulOffset;\n gchar thePath[CCHMAXPATH];\n HMODULE hModule;\n\n");
1495 fprintf(ski->of,
1496 " g_assert(DosQueryModFromEIP( &hModule, &ulObj, CCHMAXPATH, thePath, &ulOffset, (ULONG)%sNewClass)==0);\n", id);
1497 fprintf(ski->of, " g_strlcat(thePath, \".DLL\", sizeof(thePath));\n");
1498 fprintf(ski->of, " if(!nomQueryUsingNameIsDLLRegistered(thePath))\n {\n");
1499 fprintf(ski->of, " HREGDLL hReg=nomBeginRegisterDLLWithGC();\n");
1500 fprintf(ski->of, " g_assert(nomRegisterDLLByName(hReg, thePath));\n");
1501 fprintf(ski->of, " nomEndRegisterDLLWithGC(hReg);\n }\n");
1502 fprintf(ski->of, "#else\n#error DLL must be registered with the garbage collector!\n#endif\n\n");
1503
1504 /* Make sure meta class is created if specified by the user */
1505 if(NULL!=gsMetaClassName[ulCurInterface]){
1506 fprintf(ski->of, " /* Create the metaclass */\n");
1507 fprintf(ski->of, " %sNewClass(%s_MajorVersion, %s_MinorVersion);\n",
1508 gsMetaClassName[ulCurInterface]->str, gsMetaClassName[ulCurInterface]->str, gsMetaClassName[ulCurInterface]->str);
1509 /* Free the string */
1510 g_string_free(gsMetaClassName[ulCurInterface], TRUE);
1511 gsMetaClassName[ulCurInterface]=(void*)0;
1512 }
1513 /* Do parent */
1514 /* The following traverses the whole parent tree but not the parents
1515 from multiple inheritace :
1516
1517 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_voyager_parent_newclass, ski);
1518 */
1519 tmptree = IDL_LIST(ski->tree).prev;
1520 if(tmptree){
1521 /* id2 will contain the name of the direct parent */
1522 id2 = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tmptree).ident), "_", 0);
1523 fprintf(ski->of, " %sNewClass(%s_MajorVersion, %s_MinorVersion);\n",
1524 id2, id2, id2);
1525 g_free(id2);
1526 }
1527 fprintf(ski->of, " result = nomBuildClass(1, &%sSCI, ulMajor, ulMinor);\n\n", id);
1528 fprintf(ski->of, " return result;\n");
1529 fprintf(ski->of, "};\n\n");
1530
1531 break;
1532 }
1533 case PASS_VOYAGER_METACLASS:
1534 {
1535 // gsMetaClassName[ulCurInterface]=(void*)0;
1536 subski.tree = IDL_INTERFACE(ski->tree).body;
1537 cbe_ski_do_list(&subski);
1538 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1539
1540 if(NULL!=gsMetaClassName[ulCurInterface])
1541 {
1542 /* Metaclass id */
1543 fprintf(ski->of, "/* The meta class this class is using (line %d %s) */\n", __LINE__, __FILE__);
1544 fprintf(ski->of, "static char * nomIdStringMetaClass_%s = \"%s\";\n\n", id, gsMetaClassName[ulCurInterface]->str);
1545 }
1546 break;
1547 }
1548 case PASS_VOYAGER_PARMCHECK:
1549 {
1550 subski.tree = IDL_INTERFACE(ski->tree).body;
1551 cbe_ski_do_list(&subski);
1552 /* Output parameter check defines */
1553 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1554 /* Output generic object check function */
1555 VoyagerCreateObjectCheckFunction(id, ski);
1556 break;
1557 }
1558 case PASS_VOYAGER_CLASSINFO:
1559 {
1560 IDL_tree tmptree;
1561 char* id2;
1562
1563 printf("%d: --->%d\n", __LINE__, ulCurInterface);
1564
1565 /* id contains the class name */
1566 fprintf(ski->of, "/* Identify this class */\n");
1567 /* ID of this class */
1568 fprintf(ski->of, "static char * nomIdString_%s = \"%s\";\n", id, id);
1569
1570 tmptree = IDL_LIST(ski->tree).prev;
1571
1572 if(tmptree){
1573 /* We have some parent */
1574
1575 /* id2 will contain the name of the direct parent */
1576 id2 = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tmptree).ident), "_", 0);
1577
1578 fprintf(ski->of, "\n/* Array of parent names */\nstatic char* nomParentClassNames%s[]=\n{\n", id);
1579 /* The following traverses the whole parent tree but not the parents
1580 from multiple inheritace */
1581 // IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_voyager_parent_idstrings, ski);
1582
1583 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_voyager_parent_names, ski);
1584 fprintf(ski->of, "};\n\n");
1585
1586 /* IDs of parent class(es) */
1587 fprintf(ski->of, "static char * nomIdString_Parent_%s = \"%s\";\n\n", id2, id2);
1588
1589 fprintf(ski->of, "\n/* Array of parent IDs */\nstatic nomID nomParentClasses%s[]=\n{\n", id);
1590 /* The following traverses the whole parent tree but not the parents
1591 from multiple inheritace
1592
1593 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_voyager_parent_ids, ski);
1594 */
1595 fprintf(ski->of, " &nomIdString_Parent_%s,\n", id2);
1596 g_free(id2);
1597 fprintf(ski->of, "};\n\n");
1598 }
1599 cbe_ski_do_voyager_classinfo_structure(ski, id);
1600
1601 break;
1602 }
1603 case PASS_VOYAGER_STATICMETHODS:
1604 {
1605 fprintf(ski->of, "/* Description of the static methods introduced by this class */\n");
1606 fprintf(ski->of, "static nomStaticMethodDesc nomStaticMethods%s[] = {\n", id);
1607
1608 subski.tree = IDL_INTERFACE(ski->tree).body;
1609 cbe_ski_do_list(&subski);
1610 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1611
1612 fprintf(ski->of, "};\n");
1613
1614 break;
1615 }
1616 case PASS_VOYAGER_GETDATA:
1617 {
1618 CBESkelImplInfo sski;
1619 IDL_tree curitem;
1620 gboolean bFlag=FALSE;
1621
1622 /* Make sure we only create this struct for objects which do have instance vars */
1623 for(curitem = IDL_INTERFACE(ski->tree).body; curitem; curitem = IDL_LIST(curitem).next) {
1624 sski.tree = IDL_LIST(curitem).data;
1625 if(IDL_NODE_TYPE(sski.tree)==IDLN_ATTR_DCL)
1626 bFlag=TRUE;
1627 }
1628
1629 if(bFlag){
1630 /* protect with #ifdef block */
1631 fprintf(ski->of, "/* These macros are created in %s() (%s) */\n", __FUNCTION__, __FILE__);
1632 fprintf(ski->of, "#if !defined(_getmacros_%s_Data)\n", id);
1633 fprintf(ski->of, "#define _getmacros_%s_Data 1\n", id);
1634
1635 /* Get data macro */
1636 fprintf(ski->of, "\n/*\n * Get data macros for %s\n */\n", id);
1637 fprintf(ski->of, "typedef %sData* NOMLINK nomTP_%s_DataThunk(void*);\n", id, id);
1638 fprintf(ski->of, "typedef nomTP_%s_DataThunk *nomTD_%s_DataThunk;\n", id, id);
1639 fprintf(ski->of, "#define %sGetData(nomSelf) \\\n", id);
1640 fprintf(ski->of, " (((nomTD_%s_DataThunk)(%sCClassData.instanceDataToken))(nomSelf))", id, id);
1641 /* Now do macros for each var */
1642
1643 subski.tree = IDL_INTERFACE(ski->tree).body;
1644 cbe_ski_do_list(&subski);
1645 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1646
1647 fprintf(ski->of, "#endif /* _getmacros_%s_Data */\n\n", id); /* end of protective #ifdef block */
1648 }
1649 break;
1650 }
1651
1652 case PASS_VOYAGER_INSTANCE:
1653 {
1654 CBESkelImplInfo sski;
1655 IDL_tree curitem;
1656 gboolean bFlag=FALSE;
1657
1658 /* Make sure we only create this struct for objects which do have instance vars */
1659 for(curitem = IDL_INTERFACE(ski->tree).body; curitem; curitem = IDL_LIST(curitem).next) {
1660 sski.tree = IDL_LIST(curitem).data;
1661 if(IDL_NODE_TYPE(sski.tree)==IDLN_ATTR_DCL)
1662 bFlag=TRUE;
1663 }
1664
1665 if(bFlag){
1666 /* protect with #ifdef block */
1667 fprintf(ski->of, "/* This structure is created in %s() (%s) */\n", __FUNCTION__, __FILE__);
1668 fprintf(ski->of, "#if !defined(_typedef_%s_Data)\n", id);
1669 fprintf(ski->of, "#define _typedef_%s_Data 1\n", id);
1670
1671 /* Instance data struct */
1672 fprintf(ski->of, "\n/*\n * Instance variables for %s\n */\n", id);
1673 fprintf(ski->of, "typedef struct {\n");
1674 subski.tree = IDL_INTERFACE(ski->tree).body;
1675 cbe_ski_do_list(&subski);
1676 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1677 fprintf(ski->of, "} %sData;\n", id);
1678
1679 fprintf(ski->of, "#endif /* _typedef_%s_Data*/\n\n", id); /* end of protective #ifdef block */
1680 }
1681 break;
1682 }
1683 case PASS_SERVANTS:
1684#ifdef USE_LIBIDL_CODE
1685 /* protect with #ifdef block */
1686 fprintf(ski->of, "#if !defined(_typedef_impl_POA_%s_)\n", id);
1687 fprintf(ski->of, "#define _typedef_impl_POA_%s_ 1\n", id);
1688 fprintf(ski->of, "typedef struct {\nPOA_%s servant;\nPortableServer_POA poa;\n", id);
1689 subski.tree = IDL_INTERFACE(ski->tree).body;
1690 cbe_ski_do_list(&subski);
1691 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1692 fprintf(ski->of, " /* ------ add private attributes here ------ */\n");
1693 fprintf(ski->of, " /* ------ ---------- end ------------ ------ */\n");
1694 fprintf(ski->of, "} impl_POA_%s;\n", id);
1695 fprintf(ski->of, "#endif\n\n"); /* end of protective #ifdef block */
1696#endif
1697 break;
1698 case PASS_EPVS:
1699#ifdef USE_LIBIDL_CODE
1700 /* protect with #ifdef block */
1701 fprintf(ski->of, "#if !defined(_impl_%s_base_epv_)\n", id);
1702 fprintf(ski->of, "#define _impl_%s_base_epv_ 1\n", id);
1703 fprintf(ski->of, "static PortableServer_ServantBase__epv impl_%s_base_epv = {\n", id);
1704 fprintf(ski->of, "NULL, /* _private data */\n");
1705 fprintf(ski->of, "(gpointer) & impl_%s__destroy, /* finalize routine */\n", id);
1706 fprintf(ski->of, "NULL, /* default_POA routine */\n");
1707 fprintf(ski->of, "};\n");
1708 fprintf(ski->of, "#endif\n\n"); /* end of protective #ifdef block */
1709
1710 /* protect with #ifdef block */
1711 fprintf(ski->of, "#if !defined(_impl_%s_epv_)\n", id);
1712 fprintf(ski->of, "#define _impl_%s_epv_ 1\n", id);
1713 fprintf(ski->of, "static POA_%s__epv impl_%s_epv = {\nNULL, /* _private */\n", id, id);
1714 subski.tree = IDL_INTERFACE(ski->tree).body;
1715 cbe_ski_do_list(&subski);
1716 fprintf(ski->of, "};\n");
1717 fprintf(ski->of, "#endif\n\n"); /* end of protective #ifdef block */
1718
1719 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1720#endif
1721 break;
1722 case PASS_VEPVS:
1723#if USE_LIBIDL_CODE
1724 /* protect with #ifdef block */
1725 fprintf(ski->of, "#if !defined(_impl_%s_vepv_)\n", id);
1726 fprintf(ski->of, "#define _impl_%s_vepv_ 1\n", id);
1727
1728 fprintf(ski->of, "static POA_%s__vepv impl_%s_vepv = {\n", id, id);
1729 fprintf(ski->of, "&impl_%s_base_epv,\n", id);
1730 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_interface_vepv_entry, ski);
1731 fprintf(ski->of, "};\n");
1732
1733 fprintf(ski->of, "#endif\n\n"); /* end of protective #ifdef block */
1734#endif
1735 break;
1736 case PASS_IMPLSTUBS:
1737#if USE_LIBIDL_CODE
1738 /* protect __create with #ifdef block */
1739 fprintf(ski->of, "#if !defined(_impl_%s__create_)\n", id);
1740 fprintf(ski->of, "#define _impl_%s__create_ 1\n", id);
1741 fprintf(ski->of, "static %s impl_%s__create(PortableServer_POA poa, CORBA_Environment *ev)\n", id, id);
1742 fprintf(ski->of, "{\n%s retval;\nimpl_POA_%s *newservant;\nPortableServer_ObjectId *objid;\n\n", id, id);
1743 fprintf(ski->of, "newservant = g_new0(impl_POA_%s, 1);\n", id);
1744 fprintf(ski->of, "newservant->servant.vepv = &impl_%s_vepv;\n", id);
1745 fprintf(ski->of, "newservant->poa = (PortableServer_POA) CORBA_Object_duplicate((CORBA_Object)poa, ev);\n");
1746 fprintf(ski->of, "POA_%s__init((PortableServer_Servant)newservant, ev);\n", id);
1747 fprintf(ski->of, " /* Before servant is going to be activated all\n");
1748 fprintf(ski->of, " * private attributes must be initialized. */\n");
1749 fprintf(ski->of, "\n");
1750 fprintf(ski->of, " /* ------ init private attributes here ------ */\n");
1751 fprintf(ski->of, " /* ------ ---------- end ------------- ------ */\n");
1752 fprintf(ski->of, "\n");
1753 fprintf(ski->of, "objid = PortableServer_POA_activate_object(poa, newservant, ev);\n");
1754 fprintf(ski->of, "CORBA_free(objid);\n");
1755 fprintf(ski->of, "retval = PortableServer_POA_servant_to_reference(poa, newservant, ev);\n");
1756 fprintf(ski->of, "\nreturn retval;\n}\n");
1757 fprintf(ski->of, "#endif\n\n"); /* end of protective #ifdef block */
1758
1759 /* protect __destroy with #ifdef block */
1760 fprintf(ski->of, "#if !defined(_impl_%s__destroy_)\n", id);
1761 fprintf(ski->of, "#define _impl_%s__destroy_ 1\n", id);
1762 fprintf(ski->of, "static void\nimpl_%s__destroy(impl_POA_%s *servant, CORBA_Environment *ev)\n{\n", id, id);
1763 fprintf(ski->of, " CORBA_Object_release ((CORBA_Object) servant->poa, ev);\n\n");
1764 fprintf(ski->of, " /* No further remote method calls are delegated to \n");
1765 fprintf(ski->of, " * servant and you may free your private attributes. */\n");
1766 fprintf(ski->of, " /* ------ free private attributes here ------ */\n");
1767 fprintf(ski->of, " /* ------ ---------- end ------------- ------ */\n");
1768 fprintf(ski->of, "\nPOA_%s__fini((PortableServer_Servant)servant, ev);\n", id);
1769 fprintf(ski->of, "\ng_free (servant);\n");
1770 fprintf(ski->of, "}\n");
1771 fprintf(ski->of, "#endif\n\n"); /* end of protective #ifdef block */
1772#endif
1773 subski.tree = IDL_INTERFACE(ski->tree).body;
1774 cbe_ski_do_list(&subski);
1775 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1776 break;
1777 case PASS_PROTOS:
1778#if USE_LIBIDL_CODE
1779 /* protect __destroy declaration with #ifdef block */
1780 fprintf(ski->of, "#if !defined(_decl_impl_%s__destroy_)\n", id);
1781 fprintf(ski->of, "#define _decl_impl_%s__destroy_ 1\n", id);
1782 fprintf(ski->of, "static void impl_%s__destroy(impl_POA_%s *servant,\nCORBA_Environment *ev);\n", id, id);
1783 fprintf(ski->of, "#endif\n\n"); /* end of protective #ifdef block */
1784#endif
1785 subski.tree = IDL_INTERFACE(ski->tree).body;
1786 cbe_ski_do_list(&subski);
1787 IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
1788
1789 break;
1790 default:
1791 break;
1792 }
1793
1794 g_free(id);
1795}
Note: See TracBrowser for help on using the repository browser.