File Coverage

blib/lib/CORBA/Cplusplus/IncludeVisitor.pm
Criterion Covered Total %
statement 12 921 1.3
branch 0 138 0.0
condition 0 86 0.0
subroutine 4 54 7.4
pod 0 47 0.0
total 16 1246 1.2


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::Cplusplus::IncludeVisitor;
9            
10 1     1   6 use strict;
  1         1  
  1         29  
11 1     1   5 use warnings;
  1         1  
  1         41  
12            
13             our $VERSION = '0.41';
14            
15             # needs $node->{repos_id} (repositoryIdVisitor), $node->{cpp_name} (CplusplusNameVisitor)
16             # $node->{cpp_arg} ??? (CtypeVisitor) and $node->{cpp_literal} (CplusplusLiteralVisitor)
17            
18 1     1   7 use File::Basename;
  1         2  
  1         125  
19 1     1   971 use POSIX qw(ctime);
  1         7163  
  1         5  
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') . '.hpp';
35 0           $self->open_stream($filename);
36 0           $self->{filename} = $filename;
37 0           $self->{done_hash} = {};
38 0           $self->{num_key} = 'num_cpp_inc';
39 0           return $self;
40             }
41            
42             sub open_stream {
43 0     0 0   my $self = shift;
44 0           my ($filename) = @_;
45 0 0         open $self->{out}, '>', $filename
46             or die "can't open $filename ($!).\n";
47 0           $self->{filename} = $filename;
48             }
49            
50             sub _insert_inc {
51 0     0     my $self = shift;
52 0           my ($filename) = @_;
53 0           my $FH = $self->{out};
54 0 0         unless (exists $self->{inc}->{$filename}) {
55 0           $self->{inc}->{$filename} = 1;
56 0           $filename = basename($filename, '.idl') . '.hpp';
57 0           print $FH "#include \"",$self->{prefix},$filename,"\"\n";
58             }
59             }
60            
61             sub _no_mapping {
62 0     0     my $self = shift;
63 0           my ($node) = @_;
64 0           my $FH = $self->{out};
65 0 0         if ($self->{srcname} eq $node->{filename}) {
66 0           my $class = ref $node;
67 0           $class = substr $class, rindex($class, ':') + 1;
68 0 0         if ($class =~ /^Forward/) {
69 0           $node = $self->{symbtab}->Lookup($node->{full});
70             }
71 0           print $FH "\n";
72 0           print $FH "/* no mapping for ",$node->{cpp_name}," */\n";
73 0           print $FH "\n";
74             }
75             else {
76 0           $self->_insert_inc($node->{filename});
77             }
78             }
79            
80             sub _get_defn {
81 0     0     my $self = shift;
82 0           my ($defn) = @_;
83 0 0         if (ref $defn) {
84 0           return $defn;
85             }
86             else {
87 0           return $self->{symbtab}->Lookup($defn);
88             }
89             }
90            
91             #
92             # 3.5 OMG IDL Specification
93             #
94            
95             sub visitSpecification {
96 0     0 0   my $self = shift;
97 0           my ($node) = @_;
98 0           my $FH = $self->{out};
99 0           print $FH "// This file was generated (by ",$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 "#include <",$self->{incpath},"corba.hpp>\n";
103             # print $FH "#include \"corba.hpp\"\n";
104 0           print $FH "\n";
105 0 0         if (exists $node->{list_import}) {
106 0           foreach (@{$node->{list_import}}) {
  0            
107 0           my $basename = $_->{value};
108 0           $basename =~ s/^:://;
109 0           $basename =~ s/::/_/g;
110 0           print $FH "#include \"",$basename,".h\"\n";
111             }
112 0           print $FH "\n";
113             }
114 0           foreach (@{$node->{list_decl}}) {
  0            
115 0           $self->_get_defn($_)->visit($self);
116             }
117 0           print $FH "\n";
118 0           print $FH "// end of file : ",$self->{filename},"\n";
119 0           close $FH;
120             }
121            
122             #
123             # 3.7 Module Declaration
124             #
125             # See 1.2 Mapping for Modules
126             #
127            
128             sub visitModules {
129 0     0 0   my $self = shift;
130 0           my ($node) = @_;
131 0 0         unless (exists $node->{$self->{num_key}}) {
132 0           $node->{$self->{num_key}} = 0;
133             }
134 0           my $module = ${$node->{list_decl}}[$node->{$self->{num_key}}];
  0            
135 0           $module->visit($self);
136 0           $node->{$self->{num_key}} ++;
137             }
138            
139             sub visitModule {
140 0     0 0   my $self = shift;
141 0           my ($node) = @_;
142 0           my $FH = $self->{out};
143 0 0         if ($self->{srcname} eq $node->{filename}) {
144 0           my $defn = $self->{symbtab}->Lookup($node->{full});
145 0           print $FH "#ifndef _",$self->{prefix},$defn->{cpp_name},"_defined\n";
146 0           print $FH "#define _",$self->{prefix},$defn->{cpp_name},"_defined\n";
147 0           print $FH "\n";
148 0           print $FH "namespace ",$defn->{cpp_name}," {\n";
149 0           print $FH "\n";
150 0           foreach (@{$node->{list_decl}}) {
  0            
151 0           $self->_get_defn($_)->visit($self);
152             }
153 0           print $FH "\n";
154 0           print $FH "} // end of module ",$defn->{cpp_name},"\n";
155 0           print $FH "\n";
156 0           print $FH "#endif\n";
157             }
158             else {
159 0           $self->_insert_inc($node->{filename});
160             }
161             }
162            
163             #
164             # 3.8 Interface Declaration
165             #
166             # See 1.3 Mapping for Interfaces
167             #
168            
169             sub visitRegularInterface {
170 0     0 0   my $self = shift;
171 0           my ($node) = @_;
172 0           my $FH = $self->{out};
173 0           $self->{itf} = $node->{cpp_name};
174 0 0         if ($self->{srcname} eq $node->{filename}) {
175 0           print $FH "#ifndef _",$self->{prefix},$node->{cpp_name},"_defined\n";
176 0           print $FH "#define _",$self->{prefix},$node->{cpp_name},"_defined\n";
177 0           print $FH "\n";
178 0           print $FH "// begin of interface ",$node->{cpp_name},"\n";
179 0           print $FH "\n";
180 0           print $FH "class ",$node->{cpp_name},";\n";
181 0           print $FH "typedef ",$node->{cpp_name}," *",$node->{cpp_name},"_ptr;\n";
182 0           print $FH "class ",$node->{cpp_name},"_var;\n";
183 0           print $FH "\n";
184 0           print $FH "class ",$node->{cpp_name}," : public virtual CORBA::Object {\n";
185 0           print $FH "\tpublic:\n";
186 0           print $FH "\t\ttypedef ",$node->{cpp_name},"_ptr _ptr_type;\n";
187 0           print $FH "\t\ttypedef ",$node->{cpp_name},"_var _var_type;\n";
188 0           print $FH "\n";
189 0           print $FH "\t\tstatic ",$node->{cpp_name},"_ptr _duplicate(",$node->{cpp_name},"_ptr obj);\n";
190 0           print $FH "\t\tstatic ",$node->{cpp_name},"_ptr _narrow(CORBA::Object_ptr obj);\n";
191 0           print $FH "\t\tstatic ",$node->{cpp_name},"_ptr _nil();\n";
192 0           print $FH "\n";
193 0           foreach (@{$node->{list_decl}}) {
  0            
194 0           my $defn = $self->_get_defn($_);
195 0 0 0       if ( $defn->isa('Operation')
196             or $defn->isa('Attributes') ) {
197 0           next;
198             }
199 0           $defn->visit($self);
200             }
201 0           print $FH "\n";
202 0 0         if (keys %{$node->{hash_attribute_operation}}) {
  0            
203 0           print $FH "\t\t// operations\n";
204 0           print $FH "\n";
205 0           foreach (values %{$node->{hash_attribute_operation}}) {
  0            
206 0           my $defn = $self->_get_defn($_);
207 0 0         next if ($defn->isa('Attribute'));
208 0           $defn->visit($self);
209             }
210 0           print $FH "\n";
211             }
212 0           print $FH "\tprotected:\n";
213 0           print $FH "\t\t",$node->{cpp_name},"();\n";
214 0           print $FH "\t\tvirtual ~",$node->{cpp_name},"();\n";
215 0           print $FH "\n";
216 0           print $FH "\tprivate:\n";
217 0           print $FH "\t\t",$node->{cpp_name},"(const ",$node->{cpp_name},"&);\n";
218 0           print $FH "\t\tvoid operator=(const ",$node->{cpp_name},"&);\n";
219 0           print $FH "}\n";
220 0           print $FH "\n";
221 0           print $FH "class ",$node->{cpp_name},"_var : public _var {\n";
222 0           print $FH "\tpublic:\n";
223 0           print $FH "\t\t",$node->{cpp_name},"_var() : ptr_(",$node->{cpp_name},"::_nil()) {}\n";
224 0           print $FH "\t\t",$node->{cpp_name},"_var(",$node->{cpp_name},"_ptr p) : ptr_(p) {}\n";
225 0           print $FH "\t\t",$node->{cpp_name},"_var(const ",$node->{cpp_name},"_var &a) : ptr_(",$node->{cpp_name},"::_duplicate(",$node->{cpp_name},"_ptr(a)));\n";
226 0           print $FH "\t\t~",$node->{cpp_name},"_var() { free(); }\n";
227 0           print $FH "\n";
228 0           print $FH "\t\t",$node->{cpp_name},"_var &operator=(",$node->{cpp_name},"_ptr p) {\n";
229 0           print $FH "\t\t\treset(p); return *this;\n";
230 0           print $FH "\t\t}\n";
231 0           print $FH "\t\t",$node->{cpp_name},"_var &operator=(const ",$node->{cpp_name},"_var& a) {\n";
232 0           print $FH "\t\t\tif (this != &a) {\n";
233 0           print $FH "\t\t\t\tfree();\n";
234 0           print $FH "\t\t\t\tptr_ = ",$node->{cpp_name},"::_duplicate(",$node->{cpp_name},"_ptr(a));\n";
235 0           print $FH "\t\t\t}\n";
236 0           print $FH "\t\treturn *this;\n";
237 0           print $FH "\t\t}\n";
238 0           print $FH "\t\t",$node->{cpp_name},"_ptr in() const { return ptr_; }\n";
239 0           print $FH "\t\t",$node->{cpp_name},"_ptr inout() { return ptr_; }\n";
240 0           print $FH "\t\t",$node->{cpp_name},"_ptr& out() {\n";
241 0           print $FH "\t\t\treset(",$node->{cpp_name},"::_nil());\n";
242 0           print $FH "\t\t\treturn ptr_;\n";
243 0           print $FH "\t\t}\n";
244 0           print $FH "\t\t",$node->{cpp_name},"_ptr& _retn() {\n";
245 0           print $FH "\t\t\t",$node->{cpp_name},"_ptr val = ptr_;\n";
246 0           print $FH "\t\t\tptr_ = ",$node->{cpp_name},"::_nil();\n";
247 0           print $FH "\t\t\treturn val;\n";
248 0           print $FH "\t\t}\n";
249 0           print $FH "\n";
250 0           print $FH "\t\toperator const ",$node->{cpp_name},"_ptr&() const { return ptr_; }\n";
251 0           print $FH "\t\toperator ",$node->{cpp_name},"_ptr&() const { return ptr_; }\n";
252 0           print $FH "\t\t",$node->{cpp_name},"_ptr operator->() const { return ptr_; }\n";
253 0           print $FH "\n";
254 0           print $FH "\tprotected:\n";
255 0           print $FH "\t\t",$node->{cpp_name},"_ptr ptr_;\n";
256 0           print $FH "\t\tvoid free() { release(ptr_); }\n";
257 0           print $FH "\t\tvoid reset(",$node->{cpp_name},"_ptr p) { free(); ptr_ = p; }\n";
258 0           print $FH "\n";
259 0           print $FH "\tprivate:\n";
260 0           print $FH "\t\t// hidden assignment operators for var types\n";
261 0           print $FH "\t\tvoid operator=(const _var &);\n";
262 0           print $FH "}\n";
263 0           print $FH "\n";
264 0           print $FH "class ",$node->{cpp_name},"_out {\n";
265 0           print $FH "\tpublic:\n";
266 0           print $FH "\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_ptr& p) : ptr_(p) { ptr_ = ",$node->{cpp_name},"::_nil(); }\n";
267 0           print $FH "\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"var& p) : ptr_(p.ptr) { release(ptr_); ptr_ = ",$node->{cpp_name},"::_nil(); }\n";
268 0           print $FH "\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_out& a) : ptr_(a.ptr) { }\n";
269 0           print $FH "\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"_out& a) { ptr_ = a.ptr; return *this; }\n";
270 0           print $FH "\t\t",$node->{cpp_name},"_out& operator=(const ",$node->{cpp_name},"_var& a) { ptr_ = ",$node->{cpp_name},"::_duplicate(",$node->{cpp_name},"_ptr(a)); return *this; }\n";
271 0           print $FH "\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"_ptr p) { ptr_ = p; return *this; }\n";
272 0           print $FH "\t\toperator ",$node->{cpp_name},"_ptr&() { return ptr_; }\n";
273 0           print $FH "\t\t",$node->{cpp_name},"_ptr& ptr() { return ptr_; }\n";
274 0           print $FH "\t\t",$node->{cpp_name},"_ptr operator->() { return ptr_; }\n";
275 0           print $FH "\n";
276 0           print $FH "\tprivate:\n";
277 0           print $FH "\t\t",$node->{cpp_name},"_ptr& ptr_;\n";
278 0           print $FH "}\n";
279 0           print $FH "#endif\n";
280 0           print $FH "// end of interface ",$node->{cpp_name},"\n";
281 0           print $FH "\n";
282 0           $node->{cpp_has_var} = 1;
283 0           $node->{cpp_has_ptr} = 1;
284             }
285             else {
286 0           $self->_insert_inc($node->{filename});
287             }
288             }
289            
290             sub visitAbstractInterface {
291 0     0 0   my $self = shift;
292 0           my ($node) = @_;
293 0           my $FH = $self->{out};
294 0           $self->{itf} = $node->{cpp_name};
295 0 0         if ($self->{srcname} eq $node->{filename}) {
296 0           print $FH "#ifndef _",$self->{prefix},$node->{cpp_name},"_defined\n";
297 0           print $FH "#define _",$self->{prefix},$node->{cpp_name},"_defined\n";
298 0           print $FH "\n";
299 0           print $FH "// begin of abstract interface ",$node->{cpp_name},"\n";
300 0           print $FH "\n";
301 0           print $FH "class ",$node->{cpp_name},";\n";
302 0           print $FH "typedef ",$node->{cpp_name}," *",$node->{cpp_name},"_ptr;\n";
303 0           print $FH "class ",$node->{cpp_name},"_var;\n";
304 0           print $FH "\n";
305 0           print $FH "class ",$node->{cpp_name}," : public virtual CORBA::AbstractBase {\n";
306 0           print $FH "\tpublic:\n";
307 0           print $FH "\t\ttypedef ",$node->{cpp_name},"_ptr _ptr_type;\n";
308 0           print $FH "\t\ttypedef ",$node->{cpp_name},"_var _var_type;\n";
309 0           print $FH "\n";
310 0           print $FH "\t\tstatic ",$node->{cpp_name},"_ptr _duplicate(",$node->{cpp_name},"_ptr obj);\n";
311 0           print $FH "\t\tstatic ",$node->{cpp_name},"_ptr _narrow(CORBA::AbstractBase_ptr obj);\n";
312 0           print $FH "\t\tstatic ",$node->{cpp_name},"_ptr _nil();\n";
313 0           print $FH "\n";
314 0           foreach (@{$node->{list_decl}}) {
  0            
315 0           my $defn = $self->_get_defn($_);
316 0 0 0       if ( $defn->isa('Operation')
317             or $defn->isa('Attributes') ) {
318 0           next;
319             }
320 0           $defn->visit($self);
321             }
322 0           print $FH "\n";
323 0 0         if (keys %{$node->{hash_attribute_operation}}) {
  0            
324 0           print $FH "\t\t// operations\n";
325 0           print $FH "\n";
326 0           foreach (values %{$node->{hash_attribute_operation}}) {
  0            
327 0           my $defn = $self->_get_defn($_);
328 0 0         next if ($defn->isa('Attribute'));
329 0           $defn->visit($self);
330             }
331 0           print $FH "\n";
332             }
333 0           print $FH "\tprotected:\n";
334 0           print $FH "\t\t",$node->{cpp_name},"();\n";
335 0           print $FH "\t\tvirtual ~",$node->{cpp_name},"();\n";
336 0           print $FH "\n";
337 0           print $FH "\tprivate:\n";
338 0           print $FH "\t\t",$node->{cpp_name},"(const ",$node->{cpp_name},"&);\n";
339 0           print $FH "\t\tvoid operator=(const ",$node->{cpp_name},"&);\n";
340 0           print $FH "}\n";
341 0           print $FH "\n";
342 0           print $FH "class ",$node->{cpp_name},"_var : public _var {\n";
343 0           print $FH "\tpublic:\n";
344 0           print $FH "\t\t",$node->{cpp_name},"_var() : ptr_(",$node->{cpp_name},"::_nil()) {}\n";
345 0           print $FH "\t\t",$node->{cpp_name},"_var(",$node->{cpp_name},"_ptr p) : ptr_(p) {}\n";
346 0           print $FH "\t\t",$node->{cpp_name},"_var(const ",$node->{cpp_name},"_var &a) : ptr_(",$node->{cpp_name},"::_duplicate(",$node->{cpp_name},"_ptr(a)));\n";
347 0           print $FH "\t\t~",$node->{cpp_name},"_var() { free(); }\n";
348 0           print $FH "\n";
349 0           print $FH "\t\t",$node->{cpp_name},"_var &operator=(",$node->{cpp_name},"_ptr p) {\n";
350 0           print $FH "\t\t\treset(p); return *this;\n";
351 0           print $FH "\t\t}\n";
352 0           print $FH "\t\t",$node->{cpp_name},"_var &operator=(const ",$node->{cpp_name},"_var& a) {\n";
353 0           print $FH "\t\t\tif (this != &a) {\n";
354 0           print $FH "\t\t\t\tfree();\n";
355 0           print $FH "\t\t\t\tptr_ = ",$node->{cpp_name},"::_duplicate(",$node->{cpp_name},"_ptr(a));\n";
356 0           print $FH "\t\t\t}\n";
357 0           print $FH "\t\treturn *this;\n";
358 0           print $FH "\t\t}\n";
359 0           print $FH "\t\t",$node->{cpp_name},"_ptr in() const { return ptr_; }\n";
360 0           print $FH "\t\t",$node->{cpp_name},"_ptr inout() { return ptr_; }\n";
361 0           print $FH "\t\t",$node->{cpp_name},"_ptr& out() {\n";
362 0           print $FH "\t\t\treset(",$node->{cpp_name},"::_nil());\n";
363 0           print $FH "\t\t\treturn ptr_;\n";
364 0           print $FH "\t\t}\n";
365 0           print $FH "\t\t",$node->{cpp_name},"_ptr& _retn() {\n";
366 0           print $FH "\t\t\t",$node->{cpp_name},"_ptr val = ptr_;\n";
367 0           print $FH "\t\t\tptr_ = ",$node->{cpp_name},"::_nil();\n";
368 0           print $FH "\t\t\treturn val;\n";
369 0           print $FH "\t\t}\n";
370 0           print $FH "\n";
371 0           print $FH "\t\toperator const ",$node->{cpp_name},"_ptr&() const { return ptr_; }\n";
372 0           print $FH "\t\toperator ",$node->{cpp_name},"_ptr&() const { return ptr_; }\n";
373 0           print $FH "\t\t",$node->{cpp_name},"_ptr operator->() const { return ptr_; }\n";
374 0           print $FH "\n";
375 0           print $FH "\tprotected:\n";
376 0           print $FH "\t\t",$node->{cpp_name},"_ptr ptr_;\n";
377 0           print $FH "\t\tvoid free() { release(ptr_); }\n";
378 0           print $FH "\t\tvoid reset(",$node->{cpp_name},"_ptr p) { free(); ptr_ = p; }\n";
379 0           print $FH "\n";
380 0           print $FH "\tprivate:\n";
381 0           print $FH "\t\t// hidden assignment operators for var types\n";
382 0           print $FH "\t\tvoid operator=(const _var &);\n";
383 0           print $FH "}\n";
384 0           print $FH "\n";
385 0           print $FH "class ",$node->{cpp_name},"_out {\n";
386 0           print $FH "\tpublic:\n";
387 0           print $FH "\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_ptr& p) : ptr_(p) { ptr_ = ",$node->{cpp_name},"::_nil(); }\n";
388 0           print $FH "\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"var& p) : ptr_(p.ptr) { release(ptr_); ptr_ = ",$node->{cpp_name},"::_nil(); }\n";
389 0           print $FH "\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_out& a) : ptr_(a.ptr) { }\n";
390 0           print $FH "\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"_out& a) { ptr_ = a.ptr; return *this; }\n";
391 0           print $FH "\t\t",$node->{cpp_name},"_out& operator=(const ",$node->{cpp_name},"_var& a) { ptr_ = ",$node->{cpp_name},"::_duplicate(",$node->{cpp_name},"_ptr(a)); return *this; }\n";
392 0           print $FH "\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"_ptr p) { ptr_ = p; return *this; }\n";
393 0           print $FH "\t\toperator ",$node->{cpp_name},"_ptr&() { return ptr_; }\n";
394 0           print $FH "\t\t",$node->{cpp_name},"_ptr& ptr() { return ptr_; }\n";
395 0           print $FH "\t\t",$node->{cpp_name},"_ptr operator->() { return ptr_; }\n";
396 0           print $FH "\n";
397 0           print $FH "\tprivate:\n";
398 0           print $FH "\t\t",$node->{cpp_name},"_ptr& ptr_;\n";
399 0           print $FH "}\n";
400 0           print $FH "#endif\n";
401 0           print $FH "// end of abstract interface ",$node->{cpp_name},"\n";
402 0           print $FH "\n";
403 0           $node->{cpp_has_var} = 1;
404 0           $node->{cpp_has_ptr} = 1;
405             }
406             else {
407 0           $self->_insert_inc($node->{filename});
408             }
409             }
410            
411             sub visitLocalInterface {
412             # C++ mapping is aligned with CORBA 2.3
413 0     0 0   shift->_no_mapping(@_);
414             }
415            
416             sub visitForwardRegularInterface {
417 0     0 0   my $self = shift;
418 0           my ($node) = @_;
419 0           my $FH = $self->{out};
420 0 0         if ($self->{srcname} eq $node->{filename}) {
421 0           my $defn = $self->{symbtab}->Lookup($node->{full});
422 0           print $FH "\n";
423 0           print $FH "\t\tclass ",$defn->{cpp_name},";\n";
424 0           print $FH "\t\ttypedef ",$defn->{cpp_name},"_ptr;\n";
425 0           print $FH "\t\tclass ",$defn->{cpp_name},"_var;\n";
426 0           print $FH "\n";
427             }
428             else {
429 0           $self->_insert_inc($node->{filename});
430             }
431             }
432            
433             sub visitForwardAbstractInterface {
434 0     0 0   my $self = shift;
435 0           my ($node) = @_;
436 0           my $FH = $self->{out};
437 0 0         if ($self->{srcname} eq $node->{filename}) {
438 0           my $defn = $self->{symbtab}->Lookup($node->{full});
439 0           print $FH "\n";
440 0           print $FH "\t\tclass ",$defn->{cpp_name},";\n";
441 0           print $FH "\t\ttypedef ",$defn->{cpp_name},"_ptr;\n";
442 0           print $FH "\t\tclass ",$defn->{cpp_name},"_var;\n";
443 0           print $FH "\n";
444             }
445             else {
446 0           $self->_insert_inc($node->{filename});
447             }
448             }
449            
450             sub visitForwardLocalInterface {
451             # C++ mapping is aligned with CORBA 2.3
452 0     0 0   shift->_no_mapping(@_);
453             }
454            
455             #
456             # 3.9 Value Declaration
457             #
458             # 3.9.1 Regular Value Type
459             #
460            
461             sub visitRegularValue {
462 0     0 0   my $self = shift;
463 0           my ($node) = @_;
464 0           my $FH = $self->{out};
465 0           $self->{itf} = $node->{cpp_name};
466 0 0         if ($self->{srcname} eq $node->{filename}) {
467             # TODO
468 0           print $FH "#ifndef _",$self->{prefix},$node->{cpp_name},"_defined\n";
469 0           print $FH "#define _",$self->{prefix},$node->{cpp_name},"_defined\n";
470 0           print $FH "\n";
471 0           print $FH "// begin of value type ",$node->{cpp_name},"\n";
472 0           print $FH "\n";
473 0           print $FH "class ",$node->{cpp_name},";\n";
474 0           print $FH "typedef ",$node->{cpp_name}," *",$node->{cpp_name},"_ptr;\n";
475 0           print $FH "class ",$node->{cpp_name},"_var;\n";
476 0           print $FH "\n";
477 0           print $FH "class ",$node->{cpp_name}," : public virtual CORBA::ValueBase {\n";
478 0           print $FH "}\n";
479 0           print $FH "\n";
480 0           print $FH "class ",$node->{cpp_name},"_var : public _var {\n";
481 0           print $FH "}\n";
482 0           print $FH "\n";
483 0           print $FH "class ",$node->{cpp_name},"_out {\n";
484 0           print $FH "}\n";
485 0           print $FH "\n";
486 0           print $FH "class OBV_",$node->{cpp_name}," : public virtual ",$node->{cpp_name}," {\n";
487 0           print $FH "}\n";
488 0           print $FH "\n";
489 0           print $FH "#endif\n";
490 0           print $FH "// end of value type ",$node->{cpp_name},"\n";
491 0           print $FH "\n";
492 0           $node->{cpp_has_var} = 1;
493 0           $node->{cpp_has_ptr} = 1;
494             }
495             else {
496 0           $self->_insert_inc($node->{filename});
497             }
498             }
499            
500             #
501             # 3.9.2 Boxed Value Type
502             #
503            
504             sub visitBoxedValue {
505 0     0 0   my $self = shift;
506 0           my ($node) = @_;
507 0           my $FH = $self->{out};
508 0           $self->{itf} = $node->{cpp_name};
509 0 0         if ($self->{srcname} eq $node->{filename}) {
510             # TODO
511 0           print $FH "#ifndef _",$self->{prefix},$node->{cpp_name},"_defined\n";
512 0           print $FH "#define _",$self->{prefix},$node->{cpp_name},"_defined\n";
513 0           print $FH "\n";
514 0           print $FH "// begin of boxed value ",$node->{cpp_name},"\n";
515 0           print $FH "\n";
516 0           print $FH "class ",$node->{cpp_name},";\n";
517 0           print $FH "typedef ",$node->{cpp_name}," *",$node->{cpp_name},"_ptr;\n";
518 0           print $FH "class ",$node->{cpp_name},"_var;\n";
519 0           print $FH "\n";
520 0           print $FH "class ",$node->{cpp_name}," : public CORBA::DefaultValueRefCountBase {\n";
521 0           print $FH "}\n";
522 0           print $FH "\n";
523 0           print $FH "class ",$node->{cpp_name},"_var : public _var {\n";
524 0           print $FH "}\n";
525 0           print $FH "\n";
526 0           print $FH "class ",$node->{cpp_name},"_out {\n";
527 0           print $FH "}\n";
528 0           print $FH "\n";
529 0           print $FH "class OBV_",$node->{cpp_name}," : public virtual ",$node->{cpp_name}," {\n";
530 0           print $FH "}\n";
531 0           print $FH "\n";
532 0           print $FH "#endif\n";
533 0           print $FH "// end of boxed type ",$node->{cpp_name},"\n";
534 0           print $FH "\n";
535 0           $node->{cpp_has_var} = 1;
536 0           $node->{cpp_has_ptr} = 1;
537             }
538             else {
539 0           $self->_insert_inc($node->{filename});
540             }
541             }
542            
543             #
544             # 3.9.3 Abstract Value Type
545             #
546            
547             sub visitAbstractValue {
548 0     0 0   my $self = shift;
549 0           my ($node) = @_;
550 0           my $FH = $self->{out};
551 0           $self->{itf} = $node->{cpp_name};
552 0 0         if ($self->{srcname} eq $node->{filename}) {
553             # TODO
554 0           print $FH "#ifndef _",$self->{prefix},$node->{cpp_name},"_defined\n";
555 0           print $FH "#define _",$self->{prefix},$node->{cpp_name},"_defined\n";
556 0           print $FH "\n";
557 0           print $FH "// begin of abstract value ",$node->{cpp_name},"\n";
558 0           print $FH "\n";
559 0           print $FH "class ",$node->{cpp_name},";\n";
560 0           print $FH "typedef ",$node->{cpp_name}," *",$node->{cpp_name},"_ptr;\n";
561 0           print $FH "class ",$node->{cpp_name},"_var;\n";
562 0           print $FH "\n";
563 0           print $FH "class ",$node->{cpp_name}," : public virtual CORBA::ValueBase {\n";
564 0           print $FH "}\n";
565 0           print $FH "\n";
566 0           print $FH "class ",$node->{cpp_name},"_var : public _var {\n";
567 0           print $FH "}\n";
568 0           print $FH "\n";
569 0           print $FH "class ",$node->{cpp_name},"_out {\n";
570 0           print $FH "}\n";
571 0           print $FH "#endif\n";
572 0           print $FH "// end of abstract value ",$node->{cpp_name},"\n";
573 0           print $FH "\n";
574 0           $node->{cpp_has_var} = 1;
575 0           $node->{cpp_has_ptr} = 1;
576             }
577             else {
578 0           $self->_insert_inc($node->{filename});
579             }
580             }
581            
582             #
583             # 3.9.4 Value Forward Declaration
584             #
585            
586             sub visitForwardRegularValue {
587 0     0 0   my $self = shift;
588 0           my ($node) = @_;
589 0           my $FH = $self->{out};
590 0 0         if ($self->{srcname} eq $node->{filename}) {
591 0           my $defn = $self->{symbtab}->Lookup($node->{full});
592 0           print $FH "\n";
593 0           print $FH "\t\tclass ",$defn->{cpp_name},";\n";
594 0           print $FH "\t\ttypedef ",$defn->{cpp_name},"_ptr;\n";
595 0           print $FH "\t\tclass ",$defn->{cpp_name},"_var;\n";
596 0           print $FH "\t\tclass OBV_",$defn->{cpp_name},";\n";
597 0           print $FH "\n";
598             }
599             else {
600 0           $self->_insert_inc($node->{filename});
601             }
602             }
603            
604             sub visitForwardAbstractValue {
605 0     0 0   my $self = shift;
606 0           my ($node) = @_;
607 0           my $FH = $self->{out};
608 0 0         if ($self->{srcname} eq $node->{filename}) {
609 0           my $defn = $self->{symbtab}->Lookup($node->{full});
610 0           print $FH "\n";
611 0           print $FH "\t\tclass ",$defn->{cpp_name},";\n";
612 0           print $FH "\t\ttypedef ",$defn->{cpp_name},"_ptr;\n";
613 0           print $FH "\t\tclass ",$defn->{cpp_name},"_var;\n";
614 0           print $FH "\n";
615             }
616             else {
617 0           $self->_insert_inc($node->{filename});
618             }
619             }
620            
621             #
622             # 3.10 Constant Declaration
623             #
624             # See 1.4 Mapping for Constants
625             #
626            
627             sub visitConstant {
628 0     0 0   my $self = shift;
629 0           my ($node) = @_;
630 0           my $FH = $self->{out};
631 0 0         if ($self->{srcname} eq $node->{filename}) {
632 0           my $defn;
633 0           my $type = $self->_get_defn($node->{type});
634 0           my $type_decl = $type->{cpp_ns} . '::' . $type->{cpp_name};
635 0 0         if ($type->isa('StringType')) {
    0          
636 0           $type_decl = 'CORBA::Char *const';
637             }
638             elsif ($type->isa('WideStringType')) {
639 0           $type_decl = 'CORBA::WChar *const';
640             }
641 0           my $pkg = $node->{full};
642 0           $pkg =~ s/::[0-9A-Z_a-z]+$//;
643 0 0         $defn = $self->{symbtab}->Lookup($pkg) if ($pkg);
644 0 0 0       if ( defined $defn and $defn->isa('BaseInterface') ) {
645 0           print $FH "\t\tstatic const ",$type_decl," ";
646 0           print $FH $node->{cpp_name},"; // ",$node->{value}->{cpp_literal},"\n";
647             }
648             else {
649 0           print $FH "\t\tstatic const ",$type_decl," ";
650 0           print $FH $node->{cpp_name}," = ",$node->{value}->{cpp_literal},";\n";
651             }
652             }
653             else {
654 0           $self->_insert_inc($node->{filename});
655             }
656             }
657            
658             #
659             # 3.11 Type Declaration
660             #
661            
662             sub visitTypeDeclarators {
663 0     0 0   my $self = shift;
664 0           my ($node) = @_;
665 0           foreach (@{$node->{list_decl}}) {
  0            
666 0           $self->_get_defn($_)->visit($self);
667             }
668             }
669            
670             sub visitTypeDeclarator {
671 0     0 0   my $self = shift;
672 0           my ($node) = @_;
673 0           my $type = $self->_get_defn($node->{type});
674 0 0 0       if ( $type->isa('StructType')
      0        
      0        
      0        
      0        
      0        
675             or $type->isa('UnionType')
676             or $type->isa('EnumType')
677             or $type->isa('SequenceType')
678             or $type->isa('StringType')
679             or $type->isa('WideStringType')
680             or $type->isa('FixedPtType') ) {
681 0           $type->visit($self);
682             }
683 0 0         if ($self->{srcname} eq $node->{filename}) {
684 0           my $FH = $self->{out};
685 0 0         if (exists $node->{array_size}) {
686             #
687             # See 1.14 Mapping for Array Types
688             #
689 0           warn __PACKAGE__,"::visitTypeDecalarator $node->{idf} : empty array_size.\n"
690 0 0         unless (@{$node->{array_size}});
691 0           print $FH "\t\ttypedef ",$type->{cpp_name}," ",$node->{cpp_name};
692 0           foreach (@{$node->{array_size}}) {
  0            
693 0           print $FH "[",$_->{value},"]";
694             }
695 0           print $FH ";\n";
696 0           my @list = @{$node->{array_size}};
  0            
697 0           shift @list;
698 0           print $FH "\t\ttypedef ",$type->{cpp_name}," ",$node->{cpp_name},"_slice";
699 0           foreach (@list) {
700 0           print $FH "[",$_->{value},"]";
701             }
702 0           print $FH ";\n";
703 0           print $FH "\n";
704 0           print $FH "\t\tclass ",$node->{cpp_name},"_var {\n";
705 0           print $FH "\t\t\tpublic:\n";
706 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var();\n";
707 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var(",$node->{cpp_name},"_slice *);\n";
708 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var(const ",$node->{cpp_name},"_var &);\n";
709 0           print $FH "\t\t\t\t~",$node->{cpp_name},"_var();\n";
710 0           print $FH "\n";
711 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var &operator=(",$node->{cpp_name},"_slice *);\n";
712 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var &operator=(const ",$node->{cpp_name},"_var &);\n";
713 0           print $FH "\t\t\t\t",$node->{cpp_name},"_slice &operator[](CORBA::ULong index);\n";
714 0           print $FH "\t\t\t\tconst ",$node->{cpp_name},"_slice &operator[](CORBA::ULong index) const;\n";
715 0           print $FH "\n";
716 0           print $FH "\t\t\t\tconst ",$node->{cpp_name},"_slice* in() const;\n";
717 0           print $FH "\t\t\t\t",$node->{cpp_name},"_slice* inout();\n";
718 0           print $FH "\t\t\t\t",$node->{cpp_name},"_slice* out();\n";
719 0           print $FH "\t\t\t\t",$node->{cpp_name},"_slice* _retn();\n";
720 0           print $FH "\n";
721             # print $FH "\t\t\t\toperator const ",$node->{cpp_name},"*&() const { return ptr_; }\n";
722             # print $FH "\t\t\t\toperator ",$node->{cpp_name},"*&() const { return ptr_; }\n";
723             # print $FH "\t\t\t\t",$node->{cpp_name},"* operator->() const { return ptr_; }\n";
724             # print $FH "\n";
725             # print $FH "\t\t\tprotected:\n";
726             # print $FH "\t\t\t\t",$node->{cpp_name},"* ptr_;\n";
727 0           print $FH "\t\t};\n";
728 0           print $FH "\n";
729 0           print $FH "\t\tclass ",$node->{cpp_name},"_forany {\n";
730 0           print $FH "\t\t\tpublic:\n";
731 0           print $FH "\t\t\t\t",$node->{cpp_name},"_forany(",$node->{cpp_name},"_slice *, CORBA::Boolean nocopy = false);\n";
732 0           print $FH "\t\t};\n";
733 0           print $FH "\n";
734 0           print $FH "\t\tclass ",$node->{cpp_name},"_out {\n";
735 0           print $FH "\t\t\tpublic:\n";
736 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"*& p) : ptr_(p) { ptr_ = 0; }\n";
737 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_var& p) : ptr_(p.ptr_) { delete ptr_; ptr_ = 0; }\n";
738 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_out& p) : ptr_(p.ptr_) {}\n";
739 0           print $FH "\n";
740 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"_out& p) { ptr_ = p.ptr_; return *this; }\n";
741 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"* p) { ptr_ = p; return *this; }\n";
742 0           print $FH "\t\t\t\toperator ",$node->{cpp_name},"*&() { return ptr_; }\n";
743 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& ptr() { return ptr_; }\n";
744 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->() { return ptr_; }\n";
745 0           print $FH "\n";
746             # print $FH "\t\t\tprivate:\n";
747             # print $FH "\t\t\t\t",$node->{cpp_name},"*& ptr_;\n";
748             # print $FH "\n";
749             # print $FH "\t\t\t\t// assignment from ",$node->{cpp_name},"_var not allowed\n";
750             # print $FH "\t\t\t\tvoid operator=(const ",$node->{cpp_name},"_var&);\n";
751 0           print $FH "\t\t};\n";
752 0           print $FH "\n";
753 0           $node->{cpp_has_slice} = 1;
754 0           $node->{cpp_has_var} = 1;
755 0           $node->{cpp_has_forany} = 1;
756             }
757             else {
758 0 0         unless ($type->isa('SequenceType')) {
759             #
760             # See 1.15 Mapping for Typedefs
761             #
762 0           print $FH "\t\ttypedef ",$type->{cpp_name}," ",$node->{cpp_name},";\n";
763 0           print $FH "\t\ttypedef ",$type->{cpp_name},"_out ",$node->{cpp_name},"_out;\n";
764 0 0         print $FH "\t\ttypedef ",$type->{cpp_name},"_ptr ",$node->{cpp_name},"_ptr;\n"
765             if (exists $type->{cpp_has_ptr});
766 0 0         print $FH "\t\ttypedef ",$type->{cpp_name},"_var ",$node->{cpp_name},"_var;\n"
767             if (exists $type->{cpp_has_var});
768 0 0         print $FH "\t\ttypedef ",$type->{cpp_name},"_slice ",$node->{cpp_name},"_slice;\n"
769             if (exists $type->{cpp_has_slice});
770 0 0         print $FH "\t\ttypedef ",$type->{cpp_name},"_forany ",$node->{cpp_name},"_forany;\n"
771             if (exists $type->{cpp_has_forany});
772 0 0         if (exists $type->{cpp_has_slice}) {
773 0           print $FH "\n";
774 0           print $FH "\t\tinline ",$node->{cpp_name},"_slice *",$node->{cpp_name},"_alloc() { return ",$type->{cpp_name},"_alloc(); }\n";
775 0           print $FH "\t\tinline ",$node->{cpp_name},"_slice* ",$node->{cpp_name},"_dup(",$node->{cpp_name},"_slice *a) { return ",$type->{cpp_name},"_dup(a); }\n";
776 0           print $FH "\t\tinline void ",$node->{cpp_name},"_copy(",$node->{cpp_name},"_slice* to, const ",$node->{cpp_name},"_slice* from) { ",$type->{cpp_name},"_copy(to, from); }\n";
777 0           print $FH "\t\tinline void ",$node->{cpp_name},"_free(",$node->{cpp_name},"_slice *a) { ",$type->{cpp_name},"_free(a); }\n";
778             }
779 0           print $FH "\n";
780             }
781             }
782             }
783             }
784            
785 0     0 0   sub visitNativeType {
786             # empty
787             }
788            
789             #
790             # 3.11.2 Constructed Types
791             #
792             # 3.11.2.1 Structures
793             #
794             # See 1.10 Mapping for Structure Types
795             #
796            
797             sub visitStructType {
798 0     0 0   my $self = shift;
799 0           my ($node) = @_;
800 0 0         return if (exists $self->{done_hash}->{$node->{cpp_name}});
801 0           $self->{done_hash}->{$node->{cpp_name}} = 1;
802 0           foreach (@{$node->{list_expr}}) {
  0            
803 0           my $type = $self->_get_defn($_->{type});
804 0 0 0       if ( $type->isa('StructType')
      0        
      0        
      0        
      0        
805             or $type->isa('UnionType')
806             or $type->isa('SequenceType')
807             or $type->isa('StringType')
808             or $type->isa('WideStringType')
809             or $type->isa('FixedPtType') ) {
810 0           $type->visit($self);
811             }
812             }
813 0           my $FH = $self->{out};
814 0 0         if ($self->{srcname} eq $node->{filename}) {
815 0           print $FH "\t\tstruct ",$node->{cpp_name}," {\n";
816 0           foreach (@{$node->{list_expr}}) {
  0            
817 0           $_->visit($self); # members
818             }
819 0           print $FH "\t\t};\n";
820 0           print $FH "\n";
821 0           print $FH "\t\tclass ",$node->{cpp_name},"_var {\n";
822 0           print $FH "\t\t\tpublic:\n";
823 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var();\n";
824 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var(",$node->{cpp_name}," *);\n";
825 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var(const ",$node->{cpp_name},"_var &);\n";
826 0           print $FH "\t\t\t\t~",$node->{cpp_name},"_var();\n";
827 0           print $FH "\n";
828 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var &operator=(",$node->{cpp_name}," *);\n";
829 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var &operator=(const ",$node->{cpp_name},"_var &);\n";
830 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->();\n";
831 0           print $FH "\t\t\t\tconst ",$node->{cpp_name},"* operator->() const;\n";
832 0           print $FH "\n";
833 0           print $FH "\t\t\t\t",$node->{cpp_name},"* in() const { return ptr_; }\n";
834 0           print $FH "\t\t\t\t",$node->{cpp_name},"* inout() { return ptr_; }\n";
835 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& out() { delete ptr_; ptr_ = 0; ptr_; }\n";
836 0           print $FH "\t\t\t\t",$node->{cpp_name},"* _retn() { ",$node->{cpp_name},"* tmp = ptr_; ptr_ = 0; return tmp; }\n";
837 0           print $FH "\n";
838 0           print $FH "\t\t\t\toperator const ",$node->{cpp_name},"*&() const { return ptr_; }\n";
839 0           print $FH "\t\t\t\toperator ",$node->{cpp_name},"*&() const { return ptr_; }\n";
840 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->() const { return ptr_; }\n";
841 0           print $FH "\n";
842 0           print $FH "\t\t\tprotected:\n";
843 0           print $FH "\t\t\t\t",$node->{cpp_name},"* ptr_;\n";
844 0           print $FH "\t\t};\n";
845 0           print $FH "\n";
846 0           print $FH "\t\tclass ",$node->{cpp_name},"_out {\n";
847 0           print $FH "\t\t\tpublic:\n";
848 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"*& p) : ptr_(p) { ptr_ = 0; }\n";
849 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_var& p) : ptr_(p.ptr_) { delete ptr_; ptr_ = 0; }\n";
850 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_out& p) : ptr_(p.ptr_) {}\n";
851 0           print $FH "\n";
852 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"_out& p) { ptr_ = p.ptr_; return *this; }\n";
853 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"* p) { ptr_ = p; return *this; }\n";
854 0           print $FH "\t\t\t\toperator ",$node->{cpp_name},"*&() { return ptr_; }\n";
855 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& ptr() { return ptr_; }\n";
856 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->() { return ptr_; }\n";
857 0           print $FH "\n";
858 0           print $FH "\t\t\tprivate:\n";
859 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& ptr_;\n";
860 0           print $FH "\n";
861 0           print $FH "\t\t\t\t// assignment from ",$node->{cpp_name},"_var not allowed\n";
862 0           print $FH "\t\t\t\tvoid operator=(const ",$node->{cpp_name},"_var&);\n";
863 0           print $FH "\t\t};\n";
864 0           print $FH "\n";
865 0           $node->{cpp_has_var} = 1;
866             }
867             else {
868 0           $self->_insert_inc($node->{filename});
869             }
870             }
871            
872             sub visitMembers {
873 0     0 0   my $self = shift;
874 0           my ($node) = @_;
875 0           my $FH = $self->{out};
876 0           my $type = $self->_get_defn($node->{type});
877 0 0         if ($type->isa('SequenceType')) {
878 0           my $value = $self->_get_defn(${$node->{list_member}}[0]);
  0            
879 0           print $FH "\t\t\ttypedef ",$type->{cpp_name}," _",$value->{cpp_name},"_seq;\n";
880 0           print $FH "\t\t\t_",$value->{cpp_name},"_seq";
881             }
882             else {
883 0           print $FH "\t\t\t",$type->{cpp_ns},"::",$type->{cpp_name};
884             }
885 0           my $first = 1;
886 0           foreach (@{$node->{list_member}}) {
  0            
887 0 0         if ($first) {
888 0           $first = 0;
889             }
890             else {
891 0           print $FH ",";
892             }
893 0           $self->_get_defn($_)->visit($self); # member
894             }
895 0           print $FH ";\n";
896             }
897            
898             sub visitMember {
899 0     0 0   my $self = shift;
900 0           my ($node) = @_;
901 0           my $FH = $self->{out};
902 0           print $FH " ",$node->{cpp_name};
903 0 0         if (exists $node->{array_size}) {
904 0           foreach (@{$node->{array_size}}) {
  0            
905 0           print $FH "[",$_->{cpp_literal},"]";
906             }
907             }
908             }
909            
910             # 3.11.2.2 Discriminated Unions
911             #
912             # See 1.12 Mapping for Union Types
913             #
914            
915             sub visitUnionType {
916 0     0 0   my $self = shift;
917 0           my ($node) = @_;
918 0 0         return if (exists $self->{done_hash}->{$node->{cpp_name}});
919 0           $self->{done_hash}->{$node->{cpp_name}} = 1;
920 0           foreach (@{$node->{list_expr}}) {
  0            
921 0           my $type = $self->_get_defn($_->{element}->{type});
922 0 0 0       if ( $type->isa('StructType')
      0        
      0        
      0        
      0        
923             or $type->isa('UnionType')
924             or $type->isa('SequenceType')
925             or $type->isa('StringType')
926             or $type->isa('WideStringType')
927             or $type->isa('FixedPtType') ) {
928 0           $type->visit($self);
929             }
930             }
931 0           my $type = $self->_get_defn($node->{type});
932 0 0         if ($type->isa('EnumType')) {
933 0           $type->visit($self);
934             }
935 0           my $FH = $self->{out};
936 0 0         if ($self->{srcname} eq $node->{filename}) {
937 0           print $FH "\t\tclass ",$node->{cpp_name}," {\n";
938 0           print $FH "\t\t\tpublic:\n";
939 0           print $FH "\t\t\t\t",$node->{cpp_name},"();\n";
940 0           print $FH "\t\t\t\t",$node->{cpp_name},"(const ",$node->{cpp_name}," &);\n";
941 0           print $FH "\t\t\t\t~",$node->{cpp_name},"();\n";
942 0           print $FH "\t\t\t\t",$node->{cpp_name}," &operator=(const ",$node->{cpp_name},"&);\n";
943 0           print $FH "\n";
944 0           print $FH "\t\t\t\tvoid _d(",$type->{cpp_name},");\n";
945 0           print $FH "\t\t\t\t",$type->{cpp_name}," _d() const;\n";
946 0           print $FH "\n";
947             # TODO
948             # foreach (@{$node->{list_expr}}) {
949             # $_->visit($self); # case
950             # }
951 0           print $FH "\t\t};\n";
952 0           print $FH "\n";
953 0           print $FH "\t\tclass ",$node->{cpp_name},"_var {\n";
954 0           print $FH "\t\t\tpublic:\n";
955 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var();\n";
956 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var(",$node->{cpp_name}," *);\n";
957 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var(const ",$node->{cpp_name},"_var &);\n";
958 0           print $FH "\t\t\t\t~",$node->{cpp_name},"_var();\n";
959 0           print $FH "\n";
960 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var &operator=(",$node->{cpp_name}," *);\n";
961 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var &operator=(const ",$node->{cpp_name},"_var &);\n";
962 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->();\n";
963 0           print $FH "\t\t\t\tconst ",$node->{cpp_name},"* operator->() const;\n";
964 0           print $FH "\n";
965 0           print $FH "\t\t\t\t",$node->{cpp_name},"* in() const { return ptr_; }\n";
966 0           print $FH "\t\t\t\t",$node->{cpp_name},"* inout() { return ptr_; }\n";
967 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& out() { delete ptr_; ptr_ = 0; ptr_; }\n";
968 0           print $FH "\t\t\t\t",$node->{cpp_name},"* _retn() { ",$node->{cpp_name},"* tmp = ptr_; ptr_ = 0; return tmp; }\n";
969 0           print $FH "\n";
970 0           print $FH "\t\t\t\toperator const ",$node->{cpp_name},"*&() const { return ptr_; }\n";
971 0           print $FH "\t\t\t\toperator ",$node->{cpp_name},"*&() const { return ptr_; }\n";
972 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->() const { return ptr_; }\n";
973 0           print $FH "\n";
974 0           print $FH "\t\t\tprotected:\n";
975 0           print $FH "\t\t\t\t",$node->{cpp_name},"* ptr_;\n";
976 0           print $FH "\t\t};\n";
977 0           print $FH "\n";
978 0           print $FH "\t\tclass ",$node->{cpp_name},"_out {\n";
979 0           print $FH "\t\t\tpublic:\n";
980 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"*& p) : ptr_(p) { ptr_ = 0; }\n";
981 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_var& p) : ptr_(p.ptr_) { delete ptr_; ptr_ = 0; }\n";
982 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_out& p) : ptr_(p.ptr_) {}\n";
983 0           print $FH "\n";
984 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"_out& p) { ptr_ = p.ptr_; return *this; }\n";
985 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"* p) { ptr_ = p; return *this; }\n";
986 0           print $FH "\t\t\t\toperator ",$node->{cpp_name},"*&() { return ptr_; }\n";
987 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& ptr() { return ptr_; }\n";
988 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->() { return ptr_; }\n";
989 0           print $FH "\n";
990 0           print $FH "\t\t\tprivate:\n";
991 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& ptr_;\n";
992 0           print $FH "\n";
993 0           print $FH "\t\t\t\t// assignment from ",$node->{cpp_name},"_var not allowed\n";
994 0           print $FH "\t\t\t\tvoid operator=(const ",$node->{cpp_name},"_var&);\n";
995 0           print $FH "\t\t};\n";
996 0           print $FH "\n";
997 0           $node->{cpp_has_var} = 1;
998             }
999             else {
1000 0           $self->_insert_inc($node->{filename});
1001             }
1002             }
1003            
1004             sub visitCase {
1005 0     0 0   my $self = shift;
1006 0           my ($node) = @_;
1007 0           $node->{element}->visit($self);
1008             }
1009            
1010             sub visitElement {
1011 0     0 0   my $self = shift;
1012 0           my ($node) = @_;
1013 0           my $FH = $self->{out};
1014 0           my $type = $self->_get_defn($node->{type});
1015 0           print $FH "\t\t",$type->{cpp_name};
1016 0           $self->_get_defn($node->{value})->visit($self); # member
1017 0           print $FH ";\n";
1018             }
1019            
1020             #
1021             # 3.11.2.3 Constructed Recursive Types and Forward Declarations
1022             #
1023            
1024             sub visitForwardStructType {
1025 0     0 0   my $self = shift;
1026 0           my ($node) = @_;
1027 0           my $FH = $self->{out};
1028 0 0         if ($self->{srcname} eq $node->{filename}) {
1029 0           my $defn = $self->{symbtab}->Lookup($node->{full});
1030 0           print $FH "struct ",$defn->{cpp_name},";\n";
1031 0           print $FH "class ",$defn->{cpp_name},"_var;\n";
1032 0           print $FH "class ",$defn->{cpp_name},"_out;\n";
1033 0           $node->{cpp_has_var} = 1;
1034             }
1035             else {
1036 0           $self->_insert_inc($node->{filename});
1037             }
1038             }
1039            
1040             sub visitForwardUnionType {
1041 0     0 0   my $self = shift;
1042 0           my ($node) = @_;
1043 0           my $FH = $self->{out};
1044 0 0         if ($self->{srcname} eq $node->{filename}) {
1045 0           my $defn = $self->{symbtab}->Lookup($node->{full});
1046 0           print $FH "class ",$defn->{cpp_name},";\n";
1047 0           print $FH "class ",$defn->{cpp_name},"_var;\n";
1048 0           print $FH "class ",$defn->{cpp_name},"_out;\n";
1049 0           $node->{cpp_has_var} = 1;
1050             }
1051             else {
1052 0           $self->_insert_inc($node->{filename});
1053             }
1054             }
1055            
1056             # 3.11.2.4 Enumerations
1057             #
1058             # See 1.6 Mapping for Enums
1059             #
1060            
1061             sub visitEnumType {
1062 0     0 0   my $self = shift;
1063 0           my ($node) = @_;
1064 0 0         return if (exists $self->{done_hash}->{$node->{cpp_name}});
1065 0           $self->{done_hash}->{$node->{idf}} = 1;
1066 0           my $FH = $self->{out};
1067 0 0         if ($self->{srcname} eq $node->{filename}) {
1068 0           print $FH "enum ",$node->{cpp_name}," {";
1069 0           my $first = 1;
1070 0           foreach (@{$node->{list_expr}}) { # enum
  0            
1071 0 0         print $FH "," unless ($first);
1072 0           print $FH " ",$_->{cpp_name};
1073 0           $first = 0;
1074             }
1075 0           print $FH "};\n";
1076 0           print $FH "typedef ",$node->{cpp_name},"& ",$node->{cpp_name},"_out;\n";
1077             }
1078             else {
1079 0           $self->_insert_inc($node->{filename});
1080             }
1081             }
1082            
1083             #
1084             # 3.11.3 Template Types
1085             #
1086             # See 1.13 Mapping for Sequence Types
1087             #
1088            
1089             sub visitSequenceType {
1090 0     0 0   my $self = shift;
1091 0           my ($node) = @_;
1092 0 0         return if (exists $self->{done_hash}->{$node->{cpp_name}});
1093 0           $self->{done_hash}->{$node->{cpp_name}} = 1;
1094 0           my $FH = $self->{out};
1095 0 0         if ($self->{srcname} eq $node->{filename}) {
1096 0           my $type = $self->_get_defn($node->{type});
1097 0 0 0       if ( $type->isa('SequenceType')
      0        
      0        
1098             or $type->isa('StringType')
1099             or $type->isa('WideStringType')
1100             or $type->isa('FixedPtType') ) {
1101 0           $type->visit($self);
1102             }
1103 0           print $FH "\t\tclass ",$node->{cpp_name}," {\n";
1104 0           print $FH "\t\t\tpublic:\n";
1105 0           print $FH "\t\t\t\t",$node->{cpp_name},"();\n";
1106 0 0         if (exists $node->{max}) {
1107 0           print $FH "\t\t\t\t",$node->{cpp_name},"(CORBA::ULong length, ",$type->{cpp_ns},"::",$type->{cpp_name}," *data, CORBA::Boolean release = false);\n";
1108             }
1109             else {
1110 0           print $FH "\t\t\t\t",$node->{cpp_name},"(CORBA::ULong max);\n";
1111 0           print $FH "\t\t\t\t",$node->{cpp_name},"(CORBA::ULong max, CORBA::ULong length, ",$type->{cpp_ns},"::",$type->{cpp_name}," *data, CORBA::Boolean release = false);\n";
1112             }
1113 0           print $FH "\t\t\t\t",$node->{cpp_name},"(const ",$node->{cpp_name}," &);\n";
1114 0           print $FH "\t\t\t\t~",$node->{cpp_name},"();\n";
1115 0           print $FH "\t\t\t\t",$node->{cpp_name}," &operator=(const ",$node->{cpp_name},"&);\n";
1116 0           print $FH "\n";
1117 0           print $FH "\t\t\t\tCORBA::ULong maximum() const;\n";
1118 0           print $FH "\n";
1119 0           print $FH "\t\t\t\tvoid length (CORBA::ULong len);\n";
1120 0           print $FH "\t\t\t\tCORBA::ULong length() const;\n";
1121 0           print $FH "\n";
1122 0           print $FH "\t\t\t\t",$type->{cpp_ns},"::",$type->{cpp_name}," &operator[](CORBA::ULong index);\n";
1123 0           print $FH "\t\t\t\tconst ",$type->{cpp_ns},"::",$type->{cpp_name}," &operator[](CORBA::ULong index) const;\n";
1124 0           print $FH "\n";
1125 0           print $FH "\t\t\t\tCORBA::Boolean release() const;\n";
1126 0           print $FH "\n";
1127 0 0         if (exists $node->{max}) {
1128 0           print $FH "\t\t\t\tvoid replace(CORBA::ULong length, ",$type->{cpp_ns},"::",$type->{cpp_name}," *data, CORBA::Boolean release = false);\n";
1129             }
1130             else {
1131 0           print $FH "\t\t\t\tvoid replace(CORBA::ULong max, CORBA::ULong length, ",$type->{cpp_ns},"::",$type->{cpp_name}," *data, CORBA::Boolean release = false);\n";
1132             }
1133 0           print $FH "\n";
1134 0           print $FH "\t\t\t\t",$type->{cpp_ns},"::",$type->{cpp_name},"* get_buffer(CORBA::Boolean orphan = false);\n";
1135 0           print $FH "\t\t\t\tconst ",$type->{cpp_ns},"::",$type->{cpp_name},"* get_buffer() const;\n";
1136 0           print $FH "\t\t};\n";
1137 0           print $FH "\n";
1138 0           print $FH "\t\tclass ",$node->{cpp_name},"_var {\n";
1139 0           print $FH "\t\t\tpublic:\n";
1140 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var();\n";
1141 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var(",$node->{cpp_name}," *);\n";
1142 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var(const ",$node->{cpp_name},"_var &);\n";
1143 0           print $FH "\t\t\t\t~",$node->{cpp_name},"_var();\n";
1144 0           print $FH "\n";
1145 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var &operator=(",$node->{cpp_name}," *);\n";
1146 0           print $FH "\t\t\t\t",$node->{cpp_name},"_var &operator=(const ",$node->{cpp_name},"_var &);\n";
1147 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->();\n";
1148 0           print $FH "\t\t\t\tconst ",$node->{cpp_name},"* operator->() const;\n";
1149 0           print $FH "\n";
1150 0           print $FH "\t\t\t\t",$node->{cpp_name},"* in() const { return ptr_; }\n";
1151 0           print $FH "\t\t\t\t",$node->{cpp_name},"* inout() { return ptr_; }\n";
1152 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& out() { delete ptr_; ptr_ = 0; ptr_; }\n";
1153 0           print $FH "\t\t\t\t",$node->{cpp_name},"* _retn() { ",$node->{cpp_name},"* tmp = ptr_; ptr_ = 0; return tmp; }\n";
1154 0           print $FH "\n";
1155 0           print $FH "\t\t\t\toperator const ",$node->{cpp_name},"*&() const { return ptr_; }\n";
1156 0           print $FH "\t\t\t\toperator ",$node->{cpp_name},"*&() const { return ptr_; }\n";
1157 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->() const { return ptr_; }\n";
1158             # TODO operator[]
1159 0           print $FH "\n";
1160 0           print $FH "\t\t\tprotected:\n";
1161 0           print $FH "\t\t\t\t",$node->{cpp_name},"* ptr_;\n";
1162 0           print $FH "\t\t};\n";
1163 0           print $FH "\n";
1164 0           print $FH "\t\tclass ",$node->{cpp_name},"_out {\n";
1165 0           print $FH "\t\t\tpublic:\n";
1166 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"*& p) : ptr_(p) { ptr_ = 0; }\n";
1167 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_var& p) : ptr_(p.ptr_) { delete ptr_; ptr_ = 0; }\n";
1168 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out(",$node->{cpp_name},"_out& p) : ptr_(p.ptr_) {}\n";
1169 0           print $FH "\n";
1170 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"_out& p) { ptr_ = p.ptr_; return *this; }\n";
1171 0           print $FH "\t\t\t\t",$node->{cpp_name},"_out& operator=(",$node->{cpp_name},"* p) { ptr_ = p; return *this; }\n";
1172 0           print $FH "\t\t\t\toperator ",$node->{cpp_name},"*&() { return ptr_; }\n";
1173 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& ptr() { return ptr_; }\n";
1174 0           print $FH "\t\t\t\t",$node->{cpp_name},"* operator->() { return ptr_; }\n";
1175             # TODO operator[]
1176 0           print $FH "\n";
1177 0           print $FH "\t\t\tprivate:\n";
1178 0           print $FH "\t\t\t\t",$node->{cpp_name},"*& ptr_;\n";
1179 0           print $FH "\n";
1180 0           print $FH "\t\t\t\t// assignment from ",$node->{cpp_name},"_var not allowed\n";
1181 0           print $FH "\t\t\t\tvoid operator=(const ",$node->{cpp_name},"_var&);\n";
1182 0           print $FH "\t\t};\n";
1183 0           print $FH "\n";
1184 0           $node->{cpp_has_var} = 1;
1185             }
1186             }
1187            
1188             #
1189             # See 1.12 Mapping for Strings
1190             #
1191            
1192 0     0 0   sub visitStringType {
1193             # empty
1194             }
1195            
1196             #
1197             # See 1.13 Mapping for Wide Strings
1198             #
1199            
1200 0     0 0   sub visitWideStringType {
1201             # empty
1202             }
1203            
1204             #
1205             # See 1.14 Mapping for Fixed
1206             #
1207            
1208 0     0 0   sub visitFixedPtType {
1209             # empty
1210             }
1211            
1212 0     0 0   sub visitFixedPtConstType {
1213             # empty
1214             }
1215            
1216             #
1217             # 3.12 Exception Declaration
1218             #
1219             # See 1.19 Mapping for Exception Types
1220             #
1221            
1222             sub visitException {
1223 0     0 0   my $self = shift;
1224 0           my ($node) = @_;
1225 0 0         if (exists $node->{list_expr}) {
1226 0           warn __PACKAGE__,"::visitException $node->{idf} : empty list_expr.\n"
1227 0 0         unless (@{$node->{list_expr}});
1228 0           foreach (@{$node->{list_expr}}) {
  0            
1229 0           my $type = $self->_get_defn($_->{type});
1230 0 0 0       if ( $type->isa('StructType')
      0        
      0        
      0        
      0        
1231             or $type->isa('UnionType')
1232             or $type->isa('SequenceType')
1233             or $type->isa('StringType')
1234             or $type->isa('WideStringType')
1235             or $type->isa('FixedPtType') ) {
1236 0           $type->visit($self);
1237             }
1238             }
1239             }
1240 0           my $FH = $self->{out};
1241 0 0         if ($self->{srcname} eq $node->{filename}) {
1242 0           print $FH "\t\tclass ",$node->{cpp_name}," : public UserException {\n";
1243             # TODO
1244             # if (exists $node->{list_expr}) {
1245             # foreach (@{$node->{list_expr}}) {
1246             # $_->visit($self); # members
1247             # }
1248             # }
1249 0           print $FH "\t\t};\n";
1250 0           print $FH "\n";
1251             }
1252             else {
1253 0           $self->_insert_inc($node->{filename});
1254             }
1255             }
1256            
1257             #
1258             # 3.13 Operation Declaration
1259             #
1260             # See 1.20 Mapping for Operations and Attributes
1261             #
1262            
1263             sub visitOperation {
1264 0     0 0   my $self = shift;
1265 0           my ($node) = @_;
1266 0           my $FH = $self->{out};
1267 0           print $FH "\t\tvirtual ",$node->{cpp_arg}," ",$self->{prefix},$node->{cpp_name},"(";
1268 0           my $first = 1;
1269 0           my $comment = q{};
1270 0           foreach (@{$node->{list_param}}) {
  0            
1271 0           my $type = $self->_get_defn($_->{type});
1272 0 0         print $FH ", // ",$comment unless($first);
1273 0           print $FH "\n";
1274 0           print $FH "\t\t\t",$_->{cpp_arg};
1275 0           $first = 0;
1276 0           $comment = $_->{attr};
1277 0 0         $comment .= ' (variable length)' if (defined $type->{length});
1278 0 0         $comment .= ' (fixed length)' unless (defined $type->{length});
1279             }
1280 0 0         if (exists $node->{list_context}) {
1281 0 0         print $FH ", // ",$comment unless($first);
1282 0           print $FH "\n";
1283 0           print $FH "\t\t\tCORBA::Context_ptr _ctx\n";
1284             }
1285             else {
1286 0 0         print $FH " // ",$comment unless($first);
1287 0           print $FH "\n";
1288             }
1289 0           print $FH "\t\t) = 0;\n";
1290             }
1291            
1292             #
1293             # 3.14 Attribute Declaration
1294             #
1295            
1296             sub visitAttribute {
1297 0     0 0   my $self = shift;
1298 0           my ($node) = @_;
1299 0           $node->{_get}->visit($self);
1300 0 0         $node->{_set}->visit($self) if (exists $node->{_set});
1301             }
1302            
1303             #
1304             # 3.15 Repository Identity Related Declarations
1305             #
1306            
1307 0     0 0   sub visitTypeId {
1308             # empty
1309             }
1310            
1311 0     0 0   sub visitTypePrefix {
1312             # empty
1313             }
1314            
1315             #
1316             # 3.16 Event Declaration
1317             #
1318            
1319             sub visitRegularEvent {
1320             # C++ mapping is aligned with CORBA 2.3
1321 0     0 0   shift->_no_mapping(@_);
1322             }
1323            
1324             sub visitAbstractEvent {
1325             # C++ mapping is aligned with CORBA 2.3
1326 0     0 0   shift->_no_mapping(@_);
1327             }
1328            
1329             sub visitForwardRegularEvent {
1330             # C++ mapping is aligned with CORBA 2.3
1331 0     0 0   shift->_no_mapping(@_);
1332             }
1333            
1334             sub visitForwardAbstractEvent {
1335             # C++ mapping is aligned with CORBA 2.3
1336 0     0 0   shift->_no_mapping(@_);
1337             }
1338            
1339             #
1340             # 3.17 Component Declaration
1341             #
1342            
1343             sub visitComponent {
1344             # C++ mapping is aligned with CORBA 2.3
1345 0     0 0   shift->_no_mapping(@_);
1346             }
1347            
1348             sub visitForwardComponent {
1349             # C++ mapping is aligned with CORBA 2.3
1350 0     0 0   shift->_no_mapping(@_);
1351             }
1352            
1353             #
1354             # 3.18 Home Declaration
1355             #
1356            
1357             sub visitHome {
1358             # C++ mapping is aligned with CORBA 2.3
1359 0     0 0   shift->_no_mapping(@_);
1360             }
1361            
1362             #
1363             # XPIDL
1364             #
1365            
1366 0     0 0   sub visitCodeFragment {
1367             # empty
1368             }
1369            
1370             1;
1371