File Coverage

blib/lib/CORBA/C/IncludeVisitor.pm
Criterion Covered Total %
statement 24 502 4.7
branch 0 136 0.0
condition 0 91 0.0
subroutine 8 49 16.3
pod 0 37 0.0
total 32 815 3.9


line stmt bran cond sub pod time code
1            
2             #
3             # Interface Definition Language (OMG IDL CORBA v3.0)
4             #
5             # C Language Mapping Specification, New Edition June 1999
6             #
7            
8             package CORBA::C::IncludeVisitor;
9            
10 1     1   4 use strict;
  1         1  
  1         36  
11 1     1   5 use warnings;
  1         1  
  1         36  
12            
13             our $VERSION = '2.62';
14            
15 1     1   11 use File::Basename;
  1         7  
  1         125  
16 1     1   861 use POSIX qw(ctime);
  1         6390  
  1         7  
17            
18             # needs $node->{repos_id} (repositoryIdVisitor), $node->{c_name} (CnameVisitor)
19             # $node->{c_arg} (CtypeVisitor) and $node->{c_literal} (CliteralVisitor)
20            
21             sub new {
22 0     0 0   my $proto = shift;
23 0   0       my $class = ref($proto) || $proto;
24 0           my $self = {};
25 0           bless $self, $class;
26 0           my ($parser, $incpath) = @_;
27 0   0       $self->{incpath} = $incpath || q{};
28 0           $self->{prefix} = q{}; # provision for incskel
29 0           $self->{srcname} = $parser->YYData->{srcname};
30 0           $self->{srcname_size} = $parser->YYData->{srcname_size};
31 0           $self->{srcname_mtime} = $parser->YYData->{srcname_mtime};
32 0           $self->{symbtab} = $parser->YYData->{symbtab};
33 0           $self->{inc} = {};
34 0           my $filename = basename($self->{srcname}, '.idl') . '.h';
35 0           $self->open_stream($filename);
36 0           $self->{done_hash} = {};
37 0           $self->{num_key} = 'num_inc_c';
38 0           return $self;
39             }
40            
41             sub open_stream {
42 0     0 0   my $self = shift;
43 0           my ($filename) = @_;
44 0 0         open $self->{out}, '>', $filename
45             or die "can't open $filename ($!).\n";
46 0           $self->{filename} = $filename;
47             }
48            
49             sub _insert_inc {
50 0     0     my $self = shift;
51 0           my ($filename) = @_;
52 0           my $FH = $self->{out};
53 0 0         unless (exists $self->{inc}->{$filename}) {
54 0           $self->{inc}->{$filename} = 1;
55 0           $filename = basename($filename, '.idl') . '.h';
56 0           print $FH "#include \"",$self->{prefix},$filename,"\"\n";
57             }
58             }
59            
60             sub _no_mapping {
61 0     0     my $self = shift;
62 0           my ($node) = @_;
63 0           my $FH = $self->{out};
64 0 0         if ($self->{srcname} eq $node->{filename}) {
65 0           my $class = ref $node;
66 0           $class = substr $class, rindex($class, ':') + 1;
67 0 0         if ($class =~ /^Forward/) {
68 0           $node = $self->{symbtab}->Lookup($node->{full});
69             }
70 0           print $FH "\n";
71 0           print $FH "/* no mapping for ",$node->{c_name}," */\n";
72 0           print $FH "\n";
73             }
74             else {
75 0           $self->_insert_inc($node->{filename});
76             }
77             }
78            
79             sub _get_defn {
80 0     0     my $self = shift;
81 0           my ($defn) = @_;
82 0 0         if (ref $defn) {
83 0           return $defn;
84             }
85             else {
86 0           return $self->{symbtab}->Lookup($defn);
87             }
88             }
89            
90             #
91             # 3.5 OMG IDL Specification
92             #
93            
94             sub visitSpecification {
95 0     0 0   my $self = shift;
96 0           my ($node) = @_;
97 0           my $FH = $self->{out};
98 0           print $FH "/* ex: set ro: */\n";
99 0           print $FH "/* This file was generated (by ",basename($0),"). DO NOT modify it */\n";
100 0           print $FH "/* From file : ",$self->{srcname},", ",$self->{srcname_size}," octets, ",POSIX::ctime($self->{srcname_mtime});
101 0           print $FH " */\n";
102 0           print $FH "\n";
103 0           print $FH "#include <",$self->{incpath},"corba.h>\n";
104             # print $FH "#include \"corba.h\"\n";
105 0           print $FH "\n";
106 0 0         if (exists $node->{list_import}) {
107 0           foreach (@{$node->{list_import}}) {
  0            
108 0           my $basename = $_->{value};
109 0           $basename =~ s/^:://;
110 0           $basename =~ s/::/_/g;
111 0           print $FH "#include \"",$basename,".h\"\n";
112             }
113 0           print $FH "\n";
114             }
115 0           foreach (@{$node->{list_decl}}) {
  0            
116 0           $self->_get_defn($_)->visit($self);
117             }
118 0           print $FH "\n";
119 0           print $FH "/* end of file : ",$self->{filename}," */\n";
120 0           print $FH "\n";
121 0           print $FH "/*\n";
122 0           print $FH " * Local variables:\n";
123 0           print $FH " * buffer-read-only: t\n";
124 0           print $FH " * End:\n";
125 0           print $FH " */\n";
126 0           close $FH;
127             }
128            
129             #
130             # 3.7 Module Declaration
131             #
132            
133             sub visitModules {
134 0     0 0   my $self = shift;
135 0           my ($node) = @_;
136 0 0         unless (exists $node->{$self->{num_key}}) {
137 0           $node->{$self->{num_key}} = 0;
138             }
139 0           my $module = ${$node->{list_decl}}[$node->{$self->{num_key}}];
  0            
140 0           $module->visit($self);
141 0           $node->{$self->{num_key}} ++;
142             }
143            
144             sub visitModule {
145 0     0 0   my $self = shift;
146 0           my ($node) = @_;
147 0           my $FH = $self->{out};
148 0 0         if ($self->{srcname} eq $node->{filename}) {
149 0           my $filename = basename($self->{srcname}, '.idl') . '.h';
150 0           $filename =~ s/\./_/g;
151 0           my $defn = $self->{symbtab}->Lookup($node->{full});
152 0           print $FH "/*\n";
153 0           print $FH " * begin of module ",$defn->{c_name},"\n";
154 0           print $FH " */\n";
155 0           print $FH "#ifndef _",$self->{prefix},$defn->{c_name},"_",$filename,"_defined\n";
156 0           print $FH "#define _",$self->{prefix},$defn->{c_name},"_",$filename,"_defined\n";
157 0           print $FH "\n";
158 0           foreach (@{$node->{list_decl}}) {
  0            
159 0           $self->_get_defn($_)->visit($self);
160             }
161 0           print $FH "#endif\n";
162 0           print $FH "/*\n";
163 0           print $FH " * end of module ",$defn->{c_name},"\n";
164 0           print $FH " */\n";
165             }
166             else {
167 0           $self->_insert_inc($node->{filename});
168             }
169             }
170            
171             #
172             # 3.8 Interface Declaration
173             #
174             # See 1.3 Mapping for Interfaces
175             #
176            
177             sub visitRegularInterface {
178 0     0 0   my $self = shift;
179 0           my ($node) = @_;
180 0           my $FH = $self->{out};
181 0           $self->{itf} = $node->{c_name};
182 0 0         if ($self->{srcname} eq $node->{filename}) {
183 0           print $FH "/*\n";
184 0           print $FH " * begin of interface ",$node->{c_name},"\n";
185 0           print $FH " */\n";
186 0           print $FH "#ifndef _",$self->{prefix},$node->{c_name},"_defined\n";
187 0           print $FH "#define _",$self->{prefix},$node->{c_name},"_defined\n";
188 0           print $FH "\n";
189 0 0         if (exists $self->{reposit}) {
190 0           print $FH "#define id_",$node->{c_name}," \"",$node->{repos_id},"\"\n";
191             }
192 0           print $FH "typedef CORBA_Object ",$node->{c_name},";\n";
193 0           print $FH "\n";
194 0           foreach (@{$node->{list_decl}}) {
  0            
195 0           my $defn = $self->_get_defn($_);
196 0 0 0       if ( $defn->isa('Operation')
197             or $defn->isa('Attributes') ) {
198 0           next;
199             }
200 0           $defn->visit($self);
201             }
202 0           print $FH "#endif\n";
203 0           print $FH "\n";
204 0 0         if (keys %{$node->{hash_attribute_operation}}) {
  0            
205 0           print $FH "#ifndef _proto_",$self->{prefix},$node->{c_name},"_defined\n";
206 0           print $FH "#define _proto_",$self->{prefix},$node->{c_name},"_defined\n";
207 0           print $FH "\n";
208 0           $self->{itf} = $node->{c_name};
209 0           foreach (values %{$node->{hash_attribute_operation}}) {
  0            
210 0           $self->_get_defn($_)->visit($self);
211             }
212 0           delete $self->{itf};
213 0           print $FH "#endif\n";
214             }
215 0           print $FH "/*\n";
216 0           print $FH " * end of interface ",$node->{c_name},"\n";
217 0           print $FH " */\n";
218             }
219             else {
220 0           $self->_insert_inc($node->{filename});
221             }
222             }
223            
224             sub visitAbstractInterface {
225             # C mapping is aligned with CORBA 2.1
226 0     0 0   my $self = shift;
227 0           my ($node) = @_;
228 0           my $FH = $self->{out};
229 0           $self->{itf} = $node->{c_name};
230 0 0         if ($self->{srcname} eq $node->{filename}) {
231 0           print $FH "/*\n";
232 0           print $FH " * begin of abstract interface ",$node->{c_name},"\n";
233 0           print $FH " */\n";
234 0           print $FH "#ifndef _",$self->{prefix},$node->{c_name},"_defined\n";
235 0           print $FH "#define _",$self->{prefix},$node->{c_name},"_defined\n";
236 0           print $FH "\n";
237 0           print $FH "typedef CORBA_Object ",$node->{c_name},";\n";
238 0           print $FH "\n";
239 0           foreach (@{$node->{list_decl}}) {
  0            
240 0           my $defn = $self->_get_defn($_);
241 0 0 0       if ( $defn->isa('Operation')
242             or $defn->isa('Attributes') ) {
243 0           next;
244             }
245 0           $defn->visit($self);
246             }
247 0           print $FH "#endif\n";
248 0           print $FH "\n";
249 0           print $FH "/*\n";
250 0           print $FH " * end of abstract interface ",$node->{c_name},"\n";
251 0           print $FH " */\n";
252             }
253             else {
254 0           $self->_insert_inc($node->{filename});
255             }
256             }
257            
258             sub visitForwardRegularInterface {
259 0     0 0   my $self = shift;
260 0           my ($node) = @_;
261 0           my $FH = $self->{out};
262 0 0         if ($self->{srcname} eq $node->{filename}) {
263 0           my $defn = $self->{symbtab}->Lookup($node->{full});
264 0           print $FH "\n";
265 0           print $FH "typedef ",$defn->{c_name},";\n";
266 0           print $FH "\n";
267             }
268             else {
269 0           $self->_insert_inc($node->{filename});
270             }
271             }
272            
273             sub visitForwardAbstractInterface {
274             # C mapping is aligned with CORBA 2.1
275 0     0 0   my $self = shift;
276 0           my ($node) = @_;
277 0           my $FH = $self->{out};
278 0 0         if ($self->{srcname} eq $node->{filename}) {
279 0           my $defn = $self->{symbtab}->Lookup($node->{full});
280 0           print $FH "\n";
281 0           print $FH "typedef ",$defn->{c_name},";\n";
282 0           print $FH "\n";
283             }
284             else {
285 0           $self->_insert_inc($node->{filename});
286             }
287             }
288            
289             sub visitBaseInterface {
290             # C mapping is aligned with CORBA 2.1
291 0     0 0   shift->_no_mapping(@_);
292             }
293            
294             sub visitForwardBaseInterface {
295             # C mapping is aligned with CORBA 2.1
296 0     0 0   shift->_no_mapping(@_);
297             }
298            
299             #
300             # 3.10 Constant Declaration
301             #
302             # See 1.6 Mapping for Constants
303             #
304            
305             sub visitConstant {
306 0     0 0   my $self = shift;
307 0           my ($node) = @_;
308 0           my $FH = $self->{out};
309 0 0         if ($self->{srcname} eq $node->{filename}) {
310 0           print $FH "#define ",$node->{c_name},"\t",$node->{value}->{c_literal},"\n";
311             }
312             else {
313 0           $self->_insert_inc($node->{filename});
314             }
315             }
316            
317             #
318             # 3.11 Type Declaration
319             #
320            
321             sub visitTypeDeclarators {
322 0     0 0   my $self = shift;
323 0           my ($node) = @_;
324 0           foreach (@{$node->{list_decl}}) {
  0            
325 0           $self->_get_defn($_)->visit($self);
326             }
327             }
328            
329             sub visitTypeDeclarator {
330 0     0 0   my $self = shift;
331 0           my ($node) = @_;
332 0           my $type = $self->_get_defn($node->{type});
333 0 0 0       if ( $type->isa('StructType')
      0        
      0        
      0        
      0        
      0        
334             or $type->isa('UnionType')
335             or $type->isa('EnumType')
336             or $type->isa('SequenceType')
337             or $type->isa('StringType')
338             or $type->isa('WideStringType')
339             or $type->isa('FixedPtType') ) {
340 0           $type->visit($self);
341             }
342 0 0         if ($self->{srcname} eq $node->{filename}) {
343 0           my $FH = $self->{out};
344 0 0         if (exists $self->{reposit}) {
345 0           print $FH "#define id_",$node->{c_name}," \"",$node->{repos_id},"\"\n";
346 0 0         print $FH "#define uid_",$node->{c_name}," 0x",$node->{serial_uid},"ULL\n"
347             if (exists $node->{serial_uid});
348             }
349 0 0         if (exists $node->{array_size}) {
350             #
351             # See 1.15 Mapping for Array
352             #
353 0           warn __PACKAGE__,"::visitTypeDecalarator $node->{idf} : empty array_size.\n"
354 0 0         unless (@{$node->{array_size}});
355 0           print $FH "typedef ",
356             $type->{c_name},
357             " ",$node->{c_name};
358 0           foreach (@{$node->{array_size}}) {
  0            
359 0           print $FH "[",$_->{c_literal},"]";
360             }
361 0           print $FH ";\n";
362 0           my @list = @{$node->{array_size}};
  0            
363 0           shift @list;
364 0           print $FH "typedef ",
365             $type->{c_name},
366             " ",$node->{c_name},"_slice";
367 0           foreach (@list) {
368 0           print $FH "[",$_->{c_literal},"]";
369             }
370 0           print $FH ";\n";
371 0 0         if (defined $type->{length}) {
372 0 0         if (exists $self->{use_define}) {
373 0           print $FH "#define ",$node->{c_name},"__alloc(nb)\t(",$node->{c_name},"_slice *)CORBA_alloc((nb) * sizeof(",$node->{c_name},"_slice))\n";
374             }
375             else {
376 0           print $FH "extern ",$node->{c_name},"_slice * ",$node->{c_name},"__alloc(CORBA_unsigned_long nb);\n";
377             }
378             }
379             }
380             else {
381 0           print $FH "typedef ",
382             $type->{c_name},
383             " ",$node->{c_name},";\n";
384             }
385             }
386             }
387            
388 0     0 0   sub visitNativeType {
389             # empty
390             }
391            
392             #
393             # 3.11.2 Constructed Types
394             #
395             # 3.11.2.1 Structures
396             #
397             # See 1.9 Mapping for Structure Types
398             #
399            
400             sub visitStructType {
401 0     0 0   my $self = shift;
402 0           my ($node) = @_;
403 0 0         return if (exists $self->{done_hash}->{$node->{c_name}});
404 0           $self->{done_hash}->{$node->{c_name}} = 1;
405 0           foreach (@{$node->{list_expr}}) {
  0            
406 0           my $type = $self->_get_defn($_->{type});
407 0 0 0       if ( $type->isa('StructType')
      0        
      0        
      0        
      0        
408             or $type->isa('UnionType')
409             or $type->isa('SequenceType')
410             or $type->isa('StringType')
411             or $type->isa('WideStringType')
412             or $type->isa('FixedPtType') ) {
413 0           $type->visit($self);
414             }
415             }
416 0           my $FH = $self->{out};
417 0 0         if ($self->{srcname} eq $node->{filename}) {
418 0 0         if (exists $self->{reposit}) {
419 0           print $FH "#define id_",$node->{c_name}," \"",$node->{repos_id},"\"\n";
420 0 0         print $FH "#define uid_",$node->{c_name}," 0x",$node->{serial_uid},"ULL\n"
421             if (exists $node->{serial_uid});
422             }
423 0           print $FH "typedef struct {\n";
424 0           foreach (@{$node->{list_expr}}) {
  0            
425 0           $_->visit($self); # members
426             }
427 0           print $FH "} ",$node->{c_name},";\n";
428 0 0         if (defined $node->{length}) {
429 0 0         if (exists $self->{use_define}) {
430 0           print $FH "#define ",$node->{c_name},"__alloc(nb)\t(",$node->{c_name}," *)CORBA_alloc((nb) * sizeof(",$node->{c_name},"))\n"
431             }
432             else {
433 0           print $FH "extern ",$node->{c_name}," * ",$node->{c_name},"__alloc(CORBA_unsigned_long nb);\n";
434             }
435             }
436             }
437             else {
438 0           $self->_insert_inc($node->{filename});
439             }
440             }
441            
442             sub visitMembers {
443 0     0 0   my $self = shift;
444 0           my ($node) = @_;
445 0           my $FH = $self->{out};
446 0           my $type = $self->_get_defn($node->{type});
447 0           print $FH "\t",$type->{c_name};
448 0           my $first = 1;
449 0           foreach (@{$node->{list_member}}) {
  0            
450 0 0         if ($first) {
451 0           $first = 0;
452             }
453             else {
454 0           print $FH ",";
455             }
456 0           $self->_get_defn($_)->visit($self); # member
457             }
458 0           print $FH ";\n";
459             }
460            
461             sub visitMember {
462 0     0 0   my $self = shift;
463 0           my ($node) = @_;
464 0           my $FH = $self->{out};
465 0           print $FH " ",$node->{c_name};
466 0 0         if (exists $node->{array_size}) {
467 0           foreach (@{$node->{array_size}}) {
  0            
468 0           print $FH "[",$_->{c_literal},"]";
469             }
470             }
471             }
472            
473             # 3.11.2.2 Discriminated Unions
474             #
475             # See 1.10 Mapping for Union Types
476             #
477            
478             sub visitUnionType {
479 0     0 0   my $self = shift;
480 0           my ($node) = @_;
481 0 0         return if (exists $self->{done_hash}->{$node->{c_name}});
482 0           $self->{done_hash}->{$node->{c_name}} = 1;
483 0           foreach (@{$node->{list_expr}}) {
  0            
484 0           my $type = $self->_get_defn($_->{element}->{type});
485 0 0 0       if ( $type->isa('StructType')
      0        
      0        
      0        
      0        
486             or $type->isa('UnionType')
487             or $type->isa('SequenceType')
488             or $type->isa('StringType')
489             or $type->isa('WideStringType')
490             or $type->isa('FixedPtType') ) {
491 0           $type->visit($self);
492             }
493             }
494 0           my $type = $self->_get_defn($node->{type});
495 0 0         if ($type->isa('EnumType')) {
496 0           $type->visit($self);
497             }
498 0           my $FH = $self->{out};
499 0 0         if ($self->{srcname} eq $node->{filename}) {
500 0 0         if (exists $self->{reposit}) {
501 0           print $FH "#define id_",$node->{c_name}," \"",$node->{repos_id},"\"\n";
502 0 0         print $FH "#define uid_",$node->{c_name}," 0x",$node->{serial_uid},"ULL\n"
503             if (exists $node->{serial_uid});
504             }
505 0           print $FH "typedef struct {\n";
506 0           print $FH "\t",$type->{c_name}," _d; /* discriminator */\n";
507 0           print $FH "\tunion {\n";
508 0           foreach (@{$node->{list_expr}}) {
  0            
509 0           $_->visit($self); # case
510             }
511 0           print $FH "\t} _u;\n";
512 0           print $FH "} ",$node->{c_name},";\n";
513 0 0         if (defined $type->{length}) {
514 0 0         if (exists $self->{use_define}) {
515 0           print $FH "#define ",$node->{c_name},"__alloc(nb)\t(",$node->{c_name}," *)CORBA_alloc((nb) * sizeof(",$node->{c_name},"))\n"
516             }
517             else {
518 0           print $FH "extern ",$node->{c_name}," * ",$node->{c_name},"__alloc(CORBA_unsigned_long nb);\n";
519             }
520             }
521             }
522             else {
523 0           $self->_insert_inc($node->{filename});
524             }
525             }
526            
527             sub visitCase {
528 0     0 0   my $self = shift;
529 0           my ($node) = @_;
530 0           $node->{element}->visit($self);
531             }
532            
533             sub visitElement {
534 0     0 0   my $self = shift;
535 0           my ($node) = @_;
536 0           my $FH = $self->{out};
537 0           my $type = $self->_get_defn($node->{type});
538 0           print $FH "\t\t",$type->{c_name};
539 0           $self->_get_defn($node->{value})->visit($self); # member
540 0           print $FH ";\n";
541             }
542            
543             # 3.11.2.3 Constructed Recursive Types and Forward Declarations
544             #
545            
546             sub visitForwardStructType {
547 0     0 0   my $self = shift;
548 0           my ($node) = @_;
549 0           my $FH = $self->{out};
550 0 0         if ($self->{srcname} eq $node->{filename}) {
551 0           my $defn = $self->{symbtab}->Lookup($node->{full});
552 0           print $FH "typedef ",$defn->{c_name},";\n";
553             }
554             else {
555 0           $self->_insert_inc($node->{filename});
556             }
557             }
558            
559             sub visitForwardUnionType {
560 0     0 0   my $self = shift;
561 0           my ($node) = @_;
562 0           my $FH = $self->{out};
563 0 0         if ($self->{srcname} eq $node->{filename}) {
564 0           my $defn = $self->{symbtab}->Lookup($node->{full});
565 0           print $FH "typedef ",$defn->{c_name},";\n";
566             }
567             else {
568 0           $self->_insert_inc($node->{filename});
569             }
570             }
571            
572             # 3.11.2.4 Enumerations
573             #
574            
575             sub visitEnumType {
576 0     0 0   my $self = shift;
577 0           my ($node) = @_;
578 0 0         return if (exists $self->{done_hash}->{$node->{c_name}});
579 0           $self->{done_hash}->{$node->{c_name}} = 1;
580 0           my $FH = $self->{out};
581 0 0         if ($self->{srcname} eq $node->{filename}) {
582 0           print $FH "/* enum ",$node->{c_name}," */\n";
583 0           print $FH "#define ",$node->{c_name}," CORBA_unsigned_long\n";
584 0 0         if (exists $self->{reposit}) {
585 0           print $FH "#define id_",$node->{c_name}," \"",$node->{repos_id},"\"\n";
586 0 0         print $FH "#define uid_",$node->{c_name}," 0x",$node->{serial_uid},"ULL\n"
587             if (exists $node->{serial_uid});
588             }
589 0           foreach (@{$node->{list_expr}}) {
  0            
590 0           $_->visit($self); # enum
591             }
592 0           print $FH "\n";
593             }
594             else {
595 0           $self->_insert_inc($node->{filename});
596             }
597             }
598            
599             sub visitEnum {
600 0     0 0   my $self = shift;
601 0           my ($node) = @_;
602 0           my $FH = $self->{out};
603 0           print $FH "#define ",$node->{c_name},"\t",$node->{c_literal},"\n";
604             }
605            
606             #
607             # 3.11.3 Template Types
608             #
609             # See 1.11 Mapping for Sequence Types
610             #
611            
612             sub visitSequenceType {
613 0     0 0   my $self = shift;
614 0           my ($node) = @_;
615 0 0         return if (exists $self->{done_hash}->{$node->{c_name}});
616 0           $self->{done_hash}->{$node->{c_name}} = 1;
617 0           my $FH = $self->{out};
618 0 0         if ($self->{srcname} eq $node->{filename}) {
619 0           my $type = $self->_get_defn($node->{type});
620 0 0 0       if ( $type->isa('SequenceType')
      0        
      0        
621             or $type->isa('StringType')
622             or $type->isa('WideStringType')
623             or $type->isa('FixedPtType') ) {
624 0           $type->visit($self);
625             }
626 0           print $FH "#ifndef _",$node->{c_name},"_defined\n";
627 0           print $FH "#define _",$node->{c_name},"_defined\n";
628 0           print $FH "typedef struct {\n";
629 0           print $FH "\tCORBA_unsigned_long _maximum;\n";
630 0           print $FH "\tCORBA_unsigned_long _length;\n";
631 0           print $FH "\t",$type->{c_name}," * _buffer;\n";
632 0           print $FH "} ",$node->{c_name},";\n";
633 0 0         if (exists $self->{use_define}) {
634 0           print $FH "#define ",$node->{c_name},"__alloc(nb)\t(",$node->{c_name}," *)CORBA_alloc((nb) * sizeof(",$node->{c_name},"))\n";
635 0           print $FH "#define ",$node->{c_name},"__allocbuf(len)\t(",$type->{c_name}," *)CORBA_alloc((len) * sizeof(",$type->{c_name},"))\n";
636             }
637             else {
638 0           print $FH "extern ",$node->{c_name}," * ",$node->{c_name},"__alloc(CORBA_unsigned_long nb);\n";
639 0           print $FH "extern ",$type->{c_name}," * ",$node->{c_name},"__allocbuf(CORBA_unsigned_long len);\n";
640             }
641 0           print $FH "#endif\n";
642             }
643             }
644            
645             #
646             # See 1.12 Mapping for Strings
647             #
648            
649             sub visitStringType {
650 0     0 0   my $self = shift;
651 0           my ($node) = @_;
652 0 0         return if (exists $self->{done_hash}->{$node->{c_name}});
653 0           $self->{done_hash}->{$node->{c_name}} = 1;
654 0           my $FH = $self->{out};
655 0           print $FH "#ifndef _",$node->{c_name},"_defined\n";
656 0           print $FH "#define _",$node->{c_name},"_defined\n";
657 0           print $FH "typedef CORBA_char * ",$node->{c_name},";\n";
658 0           print $FH "#endif\n";
659             }
660            
661             #
662             # See 1.13 Mapping for Wide Strings
663             #
664            
665             sub visitWideStringType {
666 0     0 0   my $self = shift;
667 0           my ($node) = @_;
668 0 0         return if (exists $self->{done_hash}->{$node->{c_name}});
669 0           $self->{done_hash}->{$node->{c_name}} = 1;
670 0           my $FH = $self->{out};
671 0           print $FH "#ifndef _",$node->{c_name},"_defined\n";
672 0           print $FH "#define _",$node->{c_name},"_defined\n";
673 0           print $FH "typedef CORBA_wchar * ",$node->{c_name},";\n";
674 0           print $FH "#endif\n";
675             }
676            
677             #
678             # See 1.14 Mapping for Fixed
679             #
680            
681             sub visitFixedPtType {
682 0     0 0   my $self = shift;
683 0           my ($node) = @_;
684 0           my $FH = $self->{out};
685 0 0         if ($self->{srcname} eq $node->{filename}) {
686 0           print $FH "#ifndef _",$node->{c_name},"_defined\n";
687 0           print $FH "#define _",$node->{c_name},"_defined\n";
688 0           print $FH "typedef struct {\n";
689 0           print $FH "\tCORBA_unsigned_short _digits;\n";
690 0           print $FH "\tCORBA_short _scale;\n";
691 0           print $FH "\tCORBA_char _value [(",
692             $node->{d}->{value}, "+",
693             $node->{s}->{value}, ")/2];\n";
694 0           print $FH "} ",$node->{c_name},";\n";
695             # alloc : TODO
696 0           print $FH "#endif\n";
697             }
698             }
699            
700 0     0 0   sub visitFixedPtConstType {
701             # empty
702             }
703            
704             #
705             # 3.12 Exception Declaration
706             #
707             # See 1.16 Mapping for Exception Types
708             #
709            
710             sub visitException {
711 0     0 0   my $self = shift;
712 0           my ($node) = @_;
713 0 0         if (exists $node->{list_expr}) {
714 0           warn __PACKAGE__,"::visitException $node->{idf} : empty list_expr.\n"
715 0 0         unless (@{$node->{list_expr}});
716 0           foreach (@{$node->{list_expr}}) {
  0            
717 0           my $type = $self->_get_defn($_->{type});
718 0 0 0       if ( $type->isa('StructType')
      0        
      0        
      0        
      0        
719             or $type->isa('UnionType')
720             or $type->isa('SequenceType')
721             or $type->isa('StringType')
722             or $type->isa('WideStringType')
723             or $type->isa('FixedPtType') ) {
724 0           $type->visit($self);
725             }
726             }
727             }
728 0           my $FH = $self->{out};
729 0 0         if ($self->{srcname} eq $node->{filename}) {
730 0           print $FH "/* exception ",$node->{c_name}," */\n";
731 0           print $FH "typedef struct ",$node->{c_name}," {\n";
732 0 0         if (exists $node->{list_expr}) {
733 0           foreach (@{$node->{list_expr}}) {
  0            
734 0           $_->visit($self); # members
735             }
736             }
737             else {
738 0           print $FH "\tCORBA_long _dummy;\n";
739             }
740 0           print $FH "} ",$node->{c_name},";\n";
741 0           print $FH "#define ex_",$node->{c_name}," \"",$node->{repos_id},"\"\n";
742 0 0         if (exists $self->{reposit}) {
743 0 0         print $FH "#define uid_",$node->{c_name}," 0x",$node->{serial_uid},"ULL\n"
744             if (exists $node->{serial_uid});
745             }
746 0 0         if (exists $self->{use_define}) {
747 0           print $FH "#define ",$node->{c_name},"__alloc(nb)\t(",$node->{c_name}," *)CORBA_alloc((nb) * sizeof(",$node->{c_name},"))\n";
748             }
749             else {
750 0           print $FH "extern ",$node->{c_name}," * ",$node->{c_name},"__alloc(CORBA_unsigned_long nb);\n";
751             }
752 0           print $FH "\n";
753             }
754             else {
755 0           $self->_insert_inc($node->{filename});
756             }
757             }
758            
759             #
760             # 3.13 Operation Declaration
761             #
762            
763             sub visitOperation {
764 0     0 0   my $self = shift;
765 0           my ($node) = @_;
766 0           foreach (@{$node->{list_param}}) {
  0            
767 0           my $type = $self->_get_defn($_->{type});
768 0 0 0       if ( $type->isa('StringType')
769             or $type->isa('WideStringType') ) {
770 0           $type->visit($self);
771             }
772             }
773 0           my $FH = $self->{out};
774 0           print $FH "extern ",$node->{c_arg}," ",$self->{prefix},$self->{itf},"_",$node->{c_name},"(\n";
775 0           print $FH "\t",$self->{itf}," _o,\n";
776 0           foreach (@{$node->{list_param}}) {
  0            
777 0           $_->visit($self); # parameter
778             }
779 0 0         print $FH "\tCORBA_Context _ctx,\n"
780             if (exists $node->{list_context});
781 0           print $FH "\tCORBA_Environment * _ev\n";
782 0           print $FH ");\n";
783             }
784            
785             sub visitParameter {
786 0     0 0   my $self = shift;
787 0           my ($node) = @_;
788 0           my $FH = $self->{out};
789 0           my $type = $self->_get_defn($node->{type});
790 0           print $FH "\t",$node->{c_arg},", /* ",$node->{attr};
791 0 0         print $FH " (variable length) */\n" if (defined $type->{length});
792 0 0         print $FH " (fixed length) */\n" unless (defined $type->{length});
793             }
794            
795             #
796             # 3.14 Attribute Declaration
797             #
798            
799             sub visitAttribute {
800 0     0 0   my $self = shift;
801 0           my ($node) = @_;
802 0           $node->{_get}->visit($self);
803 0 0         $node->{_set}->visit($self) if (exists $node->{_set});
804             }
805            
806             #
807             # 3.15 Repository Identity Related Declarations
808             #
809            
810 0     0 0   sub visitTypeId {
811             # empty
812             }
813            
814 0     0 0   sub visitTypePrefix {
815             # empty
816             }
817            
818             #
819             # XPIDL
820             #
821            
822 0     0 0   sub visitCodeFragment {
823             # empty
824             }
825            
826             ##############################################################################
827            
828             package CORBA::C::IncDefVisitor;
829            
830 1     1   8217 use strict;
  1         2  
  1         55  
831 1     1   6 use warnings;
  1         2  
  1         49  
832            
833 1     1   5 use base qw(CORBA::C::IncludeVisitor);
  1         3  
  1         158  
834            
835 1     1   7 use File::Basename;
  1         2  
  1         361  
836            
837             sub new {
838 0     0     my $proto = shift;
839 0   0       my $class = ref($proto) || $proto;
840 0           my $self = {};
841 0           bless $self, $class;
842 0           my ($parser, $incpath) = @_;
843 0   0       $self->{incpath} = $incpath || q{};
844 0           $self->{prefix} = q{};
845 0           $self->{srcname} = $parser->YYData->{srcname};
846 0           $self->{srcname_size} = $parser->YYData->{srcname_size};
847 0           $self->{srcname_mtime} = $parser->YYData->{srcname_mtime};
848 0           $self->{symbtab} = $parser->YYData->{symbtab};
849 0           $self->{inc} = {};
850 0           $self->{use_define} = 1;
851 0           $self->{reposit} = 1;
852 0           my $filename = basename($self->{srcname}, '.idl') . '.h';
853 0           $self->open_stream($filename);
854 0           $self->{done_hash} = {};
855 0           $self->{num_key} = 'num_inc_c';
856 0           return $self;
857             }
858            
859             1;
860