/[suikacvs]/messaging/manakai/bin/mkdisdump.pl
Suika

Contents of /messaging/manakai/bin/mkdisdump.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations) (download)
Mon Sep 19 16:17:50 2005 UTC (19 years, 2 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +20 -3 lines
File MIME type: text/plain
++ ./bin/ChangeLog	19 Sep 2005 12:05:15 -0000
2005-09-19  Wakaba  <wakaba@suika.fam.cx>

	* mkdisdump.pl (progress_inc, progress_reset): New functions.

++ ./lib/Message/Util/ChangeLog	19 Sep 2005 12:14:55 -0000
2005-09-19  Wakaba  <wakaba@suika.fam.cx>

	* DIS.dis: Parameter "databaseArg" added to various
	methods to support objects that have no associated
	database.
	(getNamespaceBindingList, getDefaultNamespaceURIRef): New
	methods.
	(NO_RDF_TYPE_ERR): New error type.
	(loadResource): Throws NO_RDF_TYPE_ERR if no rdf:type
	attribute specified for a resource definition.

++ ./lib/Message/Util/Error/ChangeLog	19 Sep 2005 12:21:57 -0000
2005-09-19  Wakaba  <wakaba@suika.fam.cx>

	* Core.dis: Missing rdf:type attribute added to classes.

++ ./lib/Message/Util/DIS/ChangeLog	19 Sep 2005 12:23:54 -0000
2005-09-19  Wakaba  <wakaba@suika.fam.cx>

	* Value.dis (sourceNodePath): New attribute.
	(DVNSValue, DVNSOrderedList): New interfaces and classes.

	* Perl.dis: Some alias definitions moved from ../DIS.dis.
	The "namespaceContext" parameters added to some methods.
	(plCodeFragment): Now Perl'ize new DISCore:Integer typed string.
	(plImplementation): Directly instantiates PCImplementation
	to reduce overheads to find an implementation by ImplementationRegistry.

++ ./lib/Message/DOM/ChangeLog	19 Sep 2005 12:08:55 -0000
2005-09-19  Wakaba  <wakaba@suika.fam.cx>

	* DOMMain.dis (ManakaiDOM:DOMMethod, ManakaiDOM:DOMMethodReturn,
	ManakaiDOM:DOMAttribute, ManakaiDOM:DOMAttrGet,
	ManakaiDOM:DOMAttrSet, ManakaiDOM:DOMMethodParam): Removed.
	(ManakaiDOMTimeStamp): Removed.

	* DOMBoot.dis, DOMMetaImpl.dis, DOMMetaImpl.pm: Removed (they are no
	longer in use).

2005-09-18  Wakaba  <wakaba@suika.fam.cx>

	* DOMMain.dis (StringOutOfBoundsException): New exception.

++ ./lib/manakai/ChangeLog	19 Sep 2005 12:23:20 -0000
2005-09-19  Wakaba  <wakaba@suika.fam.cx>

	* DISCore.dis (DISCore:Boolean): New preferred name
	to dis:Boolean.
	(DISCore:Integer): New type.
	(dis:Value): Default type is changed to DISCore:String.

1 wakaba 1.1 #!/usr/bin/perl -w
2     use strict;
3    
4     =head1 NAME
5    
6 wakaba 1.5 mkdisdump.pl - Generating Perl Module Documentation Source
7 wakaba 1.1
8     =head1 SYNOPSIS
9    
10 wakaba 1.5 perl path/to/mkdisdump.pl input.cdis \
11 wakaba 1.1 {--module-name=ModuleName | --module-uri=module-uri} \
12     [--for=for-uri] [options] > ModuleName.pm
13     perl path/to/cdis2pm.pl --help
14    
15     =head1 DESCRIPTION
16    
17     The C<cdis2pm> script generates a Perl module from a compiled "dis"
18     ("cdis") file. It is intended to be used to generate a manakai
19     DOM Perl module files, although it might be useful for other purpose.
20    
21     This script is part of manakai.
22    
23     =cut
24    
25     use Message::DOM::DOMLS;
26     use Message::Util::DIS::DISDump;
27     use Message::Util::QName::Filter {
28 wakaba 1.3 ddel => q<http://suika.fam.cx/~wakaba/archive/2005/disdoc#>,
29 wakaba 1.1 ddoct => q<http://suika.fam.cx/~wakaba/archive/2005/8/disdump-xslt#>,
30     DIS => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#>,
31     dis => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis-->,
32     dis2pm => q<http://suika.fam.cx/~wakaba/archive/2004/11/8/dis2pm#>,
33     DISCore => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Core#>,
34     DISLang => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Lang#>,
35     DISPerl => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Perl#>,
36     disPerl => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis--Perl-->,
37     DOMCore => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/dom-core#>,
38     DOMEvents => q<http://suika.fam.cx/~wakaba/archive/2004/dom/events#>,
39     DOMLS => q<http://suika.fam.cx/~wakaba/archive/2004/dom/ls#>,
40     DOMMain => q<http://suika.fam.cx/~wakaba/archive/2004/dom/main#>,
41     DOMXML => q<http://suika.fam.cx/~wakaba/archive/2004/dom/xml#>,
42     dump => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#DISDump/>,
43     DX => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/Error/DOMException#>,
44 wakaba 1.5 ecore => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/Error/Core/>,
45 wakaba 1.1 html5 => q<http://www.w3.org/1999/xhtml>,
46 wakaba 1.3 infoset => q<http://www.w3.org/2001/04/infoset#>,
47 wakaba 1.1 lang => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#>,
48     Perl => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#Perl-->,
49     license => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/license#>,
50     ManakaiDOM => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#>,
51     Markup => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Markup#>,
52     MDOMX => q<http://suika.fam.cx/~wakaba/archive/2004/8/4/manakai-dom-exception#>,
53     owl => q<http://www.w3.org/2002/07/owl#>,
54     pc => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/PerlCode#>,
55     rdf => q<http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
56     rdfs => q<http://www.w3.org/2000/01/rdf-schema#>,
57     swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>,
58     TreeCore => q<>,
59     Util => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/>,
60     xhtml1 => q<http://www.w3.org/1999/xhtml>,
61     xhtml2 => q<http://www.w3.org/2002/06/xhtml2>,
62     xml => q<http://www.w3.org/XML/1998/namespace>,
63 wakaba 1.3 xmlns => q<http://www.w3.org/2000/xmlns/>,
64 wakaba 1.1 };
65    
66     =head1 OPTIONS
67    
68     =over 4
69    
70     =item --for=I<for-uri> (Optional)
71    
72     Specifies the "For" URI reference for which the outputed module is.
73     If this parameter is ommitted, the default "For" URI reference
74     for the module, if any, or the C<ManakaiDOM:all> is assumed.
75    
76     =item --help
77    
78     Shows the help message.
79    
80     =item --module-uri=I<module-uri>
81    
82     A URI reference that identifies a module to output. Either
83     C<--module-name> or C<--module-uri> is required.
84    
85 wakaba 1.5 =item --verbose / --noverbose (default)
86 wakaba 1.1
87 wakaba 1.5 Whether a verbose message mode should be selected or not.
88 wakaba 1.1
89 wakaba 1.5 =item --with-implementators-note / --nowith-implementators-note (default)
90 wakaba 1.1
91 wakaba 1.5 Whether the implemetator's notes should also be included
92     in the result or not.
93 wakaba 1.1
94     =back
95    
96     =cut
97    
98     use Getopt::Long;
99     use Pod::Usage;
100     use Storable;
101     use Message::Util::Error;
102 wakaba 1.4 my %Opt = (
103     module_uri => {},
104     );
105 wakaba 1.1 GetOptions (
106     'for=s' => \$Opt{For},
107     'help' => \$Opt{help},
108 wakaba 1.4 'module-uri=s' => sub {
109     shift;
110     $Opt{module_uri}->{+shift} = 1;
111     },
112 wakaba 1.5 'with-implementators-note' => \$Opt{with_impl_note},
113 wakaba 1.1 ) or pod2usage (2);
114     pod2usage ({-exitval => 0, -verbose => 1}) if $Opt{help};
115     $Opt{file_name} = shift;
116     pod2usage ({-exitval => 2, -verbose => 0}) unless $Opt{file_name};
117 wakaba 1.4 pod2usage (2) unless keys %{$Opt{module_uri}};
118 wakaba 1.1
119     sub status_msg ($) {
120     my $s = shift;
121     $s .= "\n" unless $s =~ /\n$/;
122     print STDERR $s;
123     }
124    
125     sub status_msg_ ($) {
126     my $s = shift;
127     print STDERR $s;
128     }
129    
130     sub verbose_msg ($) {
131     my $s = shift;
132     $s .= "\n" unless $s =~ /\n$/;
133     print STDERR $s;
134     }
135    
136     sub verbose_msg_ ($) {
137     my $s = shift;
138     print STDERR $s;
139     }
140    
141 wakaba 1.7 {
142     my $ResourceCount = 0;
143     sub progress_inc () {
144     if ((++$ResourceCount % 10) == 0) {
145     print STDERR "*";
146     print STDERR " " if ($ResourceCount % (10 * 10)) == 0;
147     print STDERR "\n" if ($ResourceCount % (10 * 50)) == 0;
148     }
149     }
150    
151     sub progress_reset () {
152     $ResourceCount = 0;
153     }
154     }
155    
156 wakaba 1.5 my $impl = $Message::DOM::ImplementationRegistry->get_implementation
157 wakaba 1.1 ({
158     ExpandedURI q<ManakaiDOM:Minimum> => '3.0',
159     '+' . ExpandedURI q<DOMLS:LS> => '3.0',
160     '+' . ExpandedURI q<DIS:Doc> => '2.0',
161     ExpandedURI q<DIS:Dump> => '1.0',
162     });
163    
164     ## -- Load input dac database file
165     status_msg_ qq<Opening dac file "$Opt{file_name}"...>;
166 wakaba 1.5 our $db = $impl->get_feature (ExpandedURI q<DIS:Core> => '1.0')
167     ->pl_load_dis_database ($Opt{file_name});
168 wakaba 1.1 status_msg qq<done\n>;
169    
170 wakaba 1.2 our %ReferredResource;
171 wakaba 1.5 our %ClassMembers;
172     our %ClassInheritance;
173     our @ClassInheritance;
174     our %ClassImplements;
175 wakaba 1.2
176 wakaba 1.1 sub append_module_documentation (%) {
177     my %opt = @_;
178     my $section = $opt{result_parent}->create_module ($opt{source_resource}->uri);
179 wakaba 1.2
180     add_uri ($opt{source_resource} => $section);
181 wakaba 1.1
182     my $pl_full_name = $opt{source_resource}->pl_fully_qualified_name;
183     if (defined $pl_full_name) {
184     $section->perl_package_name ($pl_full_name);
185 wakaba 1.5
186     my $path = $opt{source_resource}->get_property_text
187     (ExpandedURI q<dis:FileName>, $pl_full_name);
188 wakaba 1.1 $path =~ s#::#/#g;
189     $section->resource_file_path_stem ($path);
190 wakaba 1.5
191 wakaba 1.1 $section->set_attribute_ns
192     (ExpandedURI q<ddoct:>, 'ddoct:basePath', '../' x ($path =~ tr#/#/#));
193 wakaba 1.2 $pl_full_name =~ s/.*:://g;
194     $section->perl_name ($pl_full_name);
195 wakaba 1.1 }
196    
197     append_description (source_resource => $opt{source_resource},
198     result_parent => $section);
199    
200 wakaba 1.2 if ($opt{is_partial}) {
201     $section->resource_is_partial (1);
202     return;
203     }
204    
205 wakaba 1.1 for my $rres (@{$opt{source_resource}->get_property_resource_list
206     (ExpandedURI q<DIS:resource>)}) {
207 wakaba 1.4 if ($rres->owner_module eq $opt{source_resource} and## Defined in this module
208     not ($ReferredResource{$rres->uri} < 0)) {
209 wakaba 1.1 ## TODO: Modification required to support modplans
210 wakaba 1.7 progress_inc;
211 wakaba 1.1 if ($rres->is_type_uri (ExpandedURI q<ManakaiDOM:Class>)) {
212     append_class_documentation
213     (result_parent => $section,
214     source_resource => $rres);
215     } elsif ($rres->is_type_uri (ExpandedURI q<ManakaiDOM:IF>)) {
216     append_interface_documentation
217     (result_parent => $section,
218     source_resource => $rres);
219 wakaba 1.3 } elsif ($rres->is_type_uri (ExpandedURI q<DISCore:AbstractDataType>)) {
220     append_datatype_documentation
221     (result_parent => $section,
222     source_resource => $rres);
223 wakaba 1.1 }
224     } else { ## Aliases
225     #
226     }
227     }
228 wakaba 1.2 status_msg "";
229 wakaba 1.1 } # append_module_documentation
230    
231 wakaba 1.3 sub append_datatype_documentation (%) {
232     my %opt = @_;
233     my $section = $opt{result_parent}->create_data_type
234     ($opt{source_resource}->uri);
235    
236     add_uri ($opt{source_resource} => $section);
237    
238 wakaba 1.4 my $uri = $opt{source_resource}->name_uri;
239     if ($uri) {
240     my $fu = $opt{source_resource}->for_uri;
241     unless ($fu eq ExpandedURI q<ManakaiDOM:all>) {
242     $fu =~ /([\w.-]+)[^\w.-]*$/;
243     $uri .= '-' . $1;
244     }
245     } else {
246     $opt{source_resource}->uri;
247     }
248     $uri =~ s#\b(\d\d\d\d+)/(\d\d?)/(\d\d?)#sprintf '%04d%02d%02d', $1, $2, $3#ge;
249     my @file = map {s/[^\w-]/_/g; $_} split m{[/:#?]+}, $uri;
250 wakaba 1.3
251     $section->resource_file_path_stem (join '/', @file);
252 wakaba 1.5 $section->set_attribute_ns
253     (ExpandedURI q<ddoct:>, 'ddoct:basePath', '../' x (@file - 1));
254 wakaba 1.3
255     my $docr = $opt{source_resource}->get_feature (ExpandedURI q<DIS:Doc>, '2.0');
256     my $label = $docr->get_label ($section->owner_document);
257     if ($label) {
258     $section->create_label->append_child (transform_disdoc_tree ($label));
259     }
260    
261     append_description (source_resource => $opt{source_resource},
262     result_parent => $section);
263    
264     if ($opt{is_partial}) {
265     $section->resource_is_partial (1);
266     return;
267     }
268    
269 wakaba 1.5 append_subclassof (source_resource => $opt{source_resource},
270     result_parent => $section);
271 wakaba 1.3 } # append_datatype_documentation
272    
273 wakaba 1.1 sub append_interface_documentation (%) {
274     my %opt = @_;
275     my $section = $opt{result_parent}->create_interface
276 wakaba 1.5 (my $class_uri = $opt{source_resource}->uri);
277     push @ClassInheritance, $class_uri;
278 wakaba 1.2
279     add_uri ($opt{source_resource} => $section);
280 wakaba 1.1
281     my $pl_full_name = $opt{source_resource}->pl_fully_qualified_name;
282     if (defined $pl_full_name) {
283     $section->perl_package_name ($pl_full_name);
284 wakaba 1.5
285     my $path = $opt{source_resource}->get_property_text
286     (ExpandedURI q<dis:FileName>, $pl_full_name);
287 wakaba 1.1 $path =~ s#::#/#g;
288     $section->resource_file_path_stem ($path);
289 wakaba 1.5
290 wakaba 1.1 $section->set_attribute_ns
291     (ExpandedURI q<ddoct:>, 'ddoct:basePath',
292     join '', '../' x ($path =~ tr#/#/#));
293 wakaba 1.2 $pl_full_name =~ s/.*:://g;
294     $section->perl_name ($pl_full_name);
295 wakaba 1.1 }
296    
297     $section->is_exception_interface (1)
298     if $opt{source_resource}->is_type_uri
299     (ExpandedURI q<ManakaiDOM:ExceptionIF>);
300    
301     append_description (source_resource => $opt{source_resource},
302     result_parent => $section);
303    
304 wakaba 1.2 if ($opt{is_partial}) {
305     $section->resource_is_partial (1);
306     return;
307     }
308    
309 wakaba 1.1 ## Inheritance
310     append_inheritance (source_resource => $opt{source_resource},
311 wakaba 1.5 result_parent => $section,
312     class_uri => $class_uri);
313 wakaba 1.1
314     for my $memres (@{$opt{source_resource}->get_property_resource_list
315     (ExpandedURI q<DIS:childResource>)}) {
316     if ($memres->is_type_uri (ExpandedURI q<DISLang:Method>)) {
317     append_method_documentation (source_resource => $memres,
318 wakaba 1.5 result_parent => $section,
319     class_uri => $class_uri);
320 wakaba 1.1 } elsif ($memres->is_type_uri (ExpandedURI q<DISLang:Attribute>)) {
321     append_attr_documentation (source_resource => $memres,
322 wakaba 1.5 result_parent => $section,
323     class_uri => $class_uri);
324 wakaba 1.1 } elsif ($memres->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) {
325 wakaba 1.3 append_constgroup_documentation (source_resource => $memres,
326 wakaba 1.5 result_parent => $section,
327     class_uri => $class_uri);
328 wakaba 1.1 }
329     }
330     } # append_interface_documentation
331    
332     sub append_class_documentation (%) {
333     my %opt = @_;
334 wakaba 1.5 my $section = $opt{result_parent}->create_class
335     (my $class_uri = $opt{source_resource}->uri);
336     push @ClassInheritance, $class_uri;
337 wakaba 1.2
338     add_uri ($opt{source_resource} => $section);
339 wakaba 1.1
340     my $pl_full_name = $opt{source_resource}->pl_fully_qualified_name;
341     if (defined $pl_full_name) {
342     $section->perl_package_name ($pl_full_name);
343 wakaba 1.5
344     my $path = $opt{source_resource}->get_property_text
345     (ExpandedURI q<dis:FileName>, $pl_full_name);
346 wakaba 1.1 $path =~ s#::#/#g;
347 wakaba 1.5
348 wakaba 1.1 $section->resource_file_path_stem ($path);
349     $section->set_attribute_ns
350     (ExpandedURI q<ddoct:>, 'ddoct:basePath', '../' x ($path =~ tr#/#/#));
351 wakaba 1.2 $pl_full_name =~ s/.*:://g;
352     $section->perl_name ($pl_full_name);
353 wakaba 1.1 }
354    
355     append_description (source_resource => $opt{source_resource},
356     result_parent => $section);
357    
358 wakaba 1.2 if ($opt{is_partial}) {
359     $section->resource_is_partial (1);
360     return;
361     }
362    
363 wakaba 1.5 my $has_const = 0;
364 wakaba 1.1 for my $memres (@{$opt{source_resource}->get_property_resource_list
365     (ExpandedURI q<DIS:childResource>)}) {
366     if ($memres->is_type_uri (ExpandedURI q<DISLang:Method>)) {
367     append_method_documentation (source_resource => $memres,
368 wakaba 1.5 result_parent => $section,
369     class_uri => $class_uri);
370 wakaba 1.1 } elsif ($memres->is_type_uri (ExpandedURI q<DISLang:Attribute>)) {
371     append_attr_documentation (source_resource => $memres,
372 wakaba 1.5 result_parent => $section,
373     class_uri => $class_uri);
374 wakaba 1.1 } elsif ($memres->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) {
375 wakaba 1.5 $has_const = 1;
376 wakaba 1.3 append_constgroup_documentation
377     (source_resource => $memres,
378 wakaba 1.5 result_parent => $section,
379     class_uri => $class_uri);
380 wakaba 1.1 }
381     }
382 wakaba 1.5
383     ## Inheritance
384     append_inheritance (source_resource => $opt{source_resource},
385     result_parent => $section,
386     append_implements => 1,
387     class_uri => $class_uri,
388     has_const => $has_const,
389     is_class => 1);
390    
391 wakaba 1.1 } # append_class_documentation
392    
393     sub append_method_documentation (%) {
394     my %opt = @_;
395     my $perl_name = $opt{source_resource}->pl_name;
396     my $m;
397     if (defined $perl_name) {
398     $m = $opt{result_parent}->create_method ($perl_name);
399 wakaba 1.5 $ClassMembers{$opt{class_uri}}->{$perl_name}
400     = {
401     resource => $opt{source_resource},
402     type => 'method',
403     };
404 wakaba 1.1
405     } else { ## Anonymous
406     ## TODO
407     return;
408     }
409 wakaba 1.2
410     add_uri ($opt{source_resource} => $m);
411 wakaba 1.1
412     append_description (source_resource => $opt{source_resource},
413 wakaba 1.4 result_parent => $m,
414     method_resource => $opt{source_resource});
415 wakaba 1.1
416     my $ret = $opt{source_resource}->get_child_resource_by_type
417     (ExpandedURI q<DISLang:MethodReturn>);
418     if ($ret) {
419     my $r = $m->dis_return;
420    
421     try {
422 wakaba 1.2 $r->resource_data_type (my $u = $ret->dis_data_type_resource->uri);
423     $ReferredResource{$u} ||= 1;
424     $r->resource_actual_data_type
425     ($u = $ret->dis_actual_data_type_resource->uri);
426     $ReferredResource{$u} ||= 1;
427    
428 wakaba 1.1 ## TODO: Exceptions
429     } catch Message::Util::DIS::ManakaiDISException with {
430    
431     };
432 wakaba 1.4
433     append_description (source_resource => $ret,
434     result_parent => $r,
435     has_case => 1,
436     method_resource => $opt{source_resource});
437 wakaba 1.5
438     append_raises (source_resource => $ret,
439     result_parent => $r,
440     method_resource => $opt{source_resource});
441 wakaba 1.1 }
442    
443     for my $cr (@{$opt{source_resource}->get_property_resource_list
444     (ExpandedURI q<DIS:childResource>)}) {
445     if ($cr->is_type_uri (ExpandedURI q<DISLang:MethodParameter>)) {
446     append_param_documentation (source_resource => $cr,
447 wakaba 1.4 result_parent => $m,
448     method_resource => $opt{source_resource});
449 wakaba 1.1 }
450     }
451    
452     $m->resource_access ('private')
453     if $opt{source_resource}->get_property_boolean
454     (ExpandedURI q<ManakaiDOM:isForInternal>, 0);
455     } # append_method_documentation
456    
457     sub append_attr_documentation (%) {
458     my %opt = @_;
459     my $perl_name = $opt{source_resource}->pl_name;
460     my $m;
461     if (defined $perl_name) {
462     $m = $opt{result_parent}->create_attribute ($perl_name);
463 wakaba 1.5 $ClassMembers{$opt{class_uri}}->{$perl_name}
464     = {
465     resource => $opt{source_resource},
466     type => 'attr',
467     };
468 wakaba 1.1
469     } else { ## Anonymous
470     ## TODO
471     return;
472     }
473 wakaba 1.2
474     add_uri ($opt{source_resource} => $m);
475 wakaba 1.1
476     append_description (source_resource => $opt{source_resource},
477     result_parent => $m,
478     has_case => 1);
479    
480     my $ret = $opt{source_resource}->get_child_resource_by_type
481     (ExpandedURI q<DISLang:AttributeGet>);
482     if ($ret) {
483     my $r = $m->dis_get;
484    
485 wakaba 1.2 $r->resource_data_type (my $u = $ret->dis_data_type_resource->uri);
486     $ReferredResource{$u} ||= 1;
487     $r->resource_actual_data_type
488     ($u = $ret->dis_actual_data_type_resource->uri);
489     $ReferredResource{$u} ||= 1;
490    
491 wakaba 1.1 append_description (source_resource => $ret,
492     result_parent => $r,
493     has_case => 1);
494    
495 wakaba 1.5 append_raises (source_resource => $ret,
496     result_parent => $r);
497 wakaba 1.1 }
498    
499     my $set = $opt{source_resource}->get_child_resource_by_type
500     (ExpandedURI q<DISLang:AttributeSet>);
501     if ($set) {
502     my $r = $m->dis_set;
503    
504 wakaba 1.2 $r->resource_data_type (my $u = $set->dis_data_type_resource->uri);
505     $ReferredResource{$u} ||= 1;
506 wakaba 1.1 $r->resource_actual_data_type ($set->dis_actual_data_type_resource->uri);
507 wakaba 1.2 $ReferredResource{$u} ||= 1;
508 wakaba 1.1
509     append_description (source_resource => $set,
510     result_parent => $r,
511     has_case => 1);
512    
513 wakaba 1.5 append_raises (source_resource => $set,
514     result_parent => $r);
515 wakaba 1.1 } else {
516     $m->is_read_only_attribute (1);
517     }
518    
519     $m->resource_access ('private')
520     if $opt{source_resource}->get_property_boolean
521     (ExpandedURI q<ManakaiDOM:isForInternal>, 0);
522     } # append_attr_documentation
523    
524 wakaba 1.3 sub append_constgroup_documentation (%) {
525     my %opt = @_;
526     my $perl_name = $opt{source_resource}->pl_name;
527     my $m = $opt{result_parent}->create_const_group ($perl_name);
528 wakaba 1.5 $ClassMembers{$opt{class_uri}}->{$perl_name}
529     = {
530     resource => $opt{source_resource},
531     type => 'const-group',
532     };
533 wakaba 1.3
534     add_uri ($opt{source_resource} => $m);
535    
536     append_description (source_resource => $opt{source_resource},
537     result_parent => $m);
538    
539     $m->resource_data_type
540     (my $u = $opt{source_resource}->dis_data_type_resource->uri);
541     $ReferredResource{$u} ||= 1;
542     $m->resource_actual_data_type
543     ($u = $opt{source_resource}->dis_actual_data_type_resource->uri);
544     $ReferredResource{$u} ||= 1;
545    
546 wakaba 1.5 append_subclassof (source_resource => $opt{source_resource},
547     result_parent => $m);
548 wakaba 1.3
549     for my $cr (@{$opt{source_resource}->get_property_resource_list
550     (ExpandedURI q<DIS:childResource>)}) {
551     if ($cr->is_type_uri (ExpandedURI q<ManakaiDOM:Const>)) {
552     append_const_documentation (source_resource => $cr,
553     result_parent => $m);
554     }
555     }
556     } # append_constgroup_documentation
557    
558     sub append_const_documentation (%) {
559     my %opt = @_;
560     my $perl_name = $opt{source_resource}->pl_name;
561     my $m = $opt{result_parent}->create_const ($perl_name);
562    
563     add_uri ($opt{source_resource} => $m);
564    
565     append_description (source_resource => $opt{source_resource},
566     result_parent => $m);
567    
568     $m->resource_data_type
569     (my $u = $opt{source_resource}->dis_data_type_resource->uri);
570     $ReferredResource{$u} ||= 1;
571     $m->resource_actual_data_type
572     ($u = $opt{source_resource}->dis_actual_data_type_resource->uri);
573     $ReferredResource{$u} ||= 1;
574    
575     my $value = $opt{source_resource}->pl_code_fragment;
576     if ($value) {
577     $m->create_value->text_content ($value->stringify);
578     }
579    
580     for my $cr (@{$opt{source_resource}->get_property_resource_list
581     (ExpandedURI q<DIS:childResource>)}) {
582     if ($cr->is_type_uri (ExpandedURI q<ManakaiDOM:ExceptionOrWarningSubType>)) {
583     append_xsubtype_documentation (source_resource => $cr,
584     result_parent => $m);
585     }
586     }
587     ## TODO: xparam
588     } # append_const_documentation
589    
590     sub append_xsubtype_documentation (%) {
591     my %opt = @_;
592     my $m = $opt{result_parent}->create_exception_sub_code
593     ($opt{source_resource}->uri);
594     add_uri ($opt{source_resource} => $m);
595    
596     append_description (source_resource => $opt{source_resource},
597     result_parent => $m);
598    
599     ## TODO: xparam
600     } # append_xsubtype_documentation
601    
602 wakaba 1.1 sub append_param_documentation (%) {
603     my %opt = @_;
604    
605     my $is_named_param = $opt{source_resource}->get_property_boolean
606     (ExpandedURI q<DISPerl:isNamedParameter>, 0);
607    
608     my $perl_name = $is_named_param
609     ? $opt{source_resource}->pl_name
610     : $opt{source_resource}->pl_variable_name;
611    
612     my $p = $opt{result_parent}->create_parameter ($perl_name, $is_named_param);
613    
614 wakaba 1.2 add_uri ($opt{source_resource} => $p);
615    
616 wakaba 1.1 $p->is_nullable_parameter ($opt{source_resource}->pl_is_nullable);
617 wakaba 1.2 $p->resource_data_type
618     (my $u = $opt{source_resource}->dis_data_type_resource->uri);
619     $ReferredResource{$u} ||= 1;
620 wakaba 1.1 $p->resource_actual_data_type
621 wakaba 1.2 ($u = $opt{source_resource}->dis_actual_data_type_resource->uri);
622     $ReferredResource{$u} ||= 1;
623 wakaba 1.1
624     append_description (source_resource => $opt{source_resource},
625     result_parent => $p,
626 wakaba 1.4 has_case => 1,
627     method_resource => $opt{method_resource});
628 wakaba 1.1 } # append_param_documentation
629    
630     sub append_description (%) {
631     my %opt = @_;
632 wakaba 1.2
633 wakaba 1.1 my $od = $opt{result_parent}->owner_document;
634     my $resd = $opt{source_resource}->get_feature (ExpandedURI q<DIS:Doc>, '2.0');
635 wakaba 1.5 my $doc = transform_disdoc_tree
636     ($resd->get_description
637     ($od, undef,
638     $Opt{with_impl_note},
639     parent_element_arg => $opt{source_element}),
640     method_resource => $opt{method_resource});
641 wakaba 1.1 $opt{result_parent}->create_description->append_child ($doc);
642     ## TODO: Negotiation
643    
644 wakaba 1.3 my $fn = $resd->get_full_name ($od);
645     if ($fn) {
646     $opt{result_parent}->create_full_name
647 wakaba 1.4 ->append_child (transform_disdoc_tree
648     ($fn,
649     method_resource => $opt{method_resource}));
650 wakaba 1.3 }
651    
652 wakaba 1.1 if ($opt{has_case}) {
653     for my $caser (@{$opt{source_resource}->get_property_resource_list
654     (ExpandedURI q<DIS:childResource>)}) {
655     if ($caser->is_type_uri (ExpandedURI q<ManakaiDOM:InCase>)) {
656     my $case = $opt{result_parent}->append_case;
657     my $cased = $caser->get_feature (ExpandedURI q<DIS:Doc>, '2.0');
658     my $label = $cased->get_label ($od);
659     if ($label) {
660 wakaba 1.4 $case->create_label->append_child
661     (transform_disdoc_tree ($label,
662     method_resource => $opt{method_resource}));
663 wakaba 1.1 }
664     my $value = $caser->pl_code_fragment;
665     if ($value) {
666     $case->create_value->text_content ($value->stringify);
667     }
668 wakaba 1.3 $case->resource_data_type
669     (my $u = $caser->dis_data_type_resource->uri);
670     $ReferredResource{$u} ||= 1;
671     $case->resource_actual_data_type
672     ($u = $caser->dis_actual_data_type_resource->uri);
673     $ReferredResource{$u} ||= 1;
674    
675 wakaba 1.1 append_description (source_resource => $caser,
676 wakaba 1.4 result_parent => $case,
677     method_resource => $opt{method_resource});
678 wakaba 1.1 }
679     }
680     }
681     } # append_description
682    
683 wakaba 1.3 sub transform_disdoc_tree ($;%) {
684     my ($el, %opt) = @_;
685     my @el = ($el);
686     EL: while (defined (my $el = shift @el)) {
687     if ($el->node_type == $el->ELEMENT_NODE and
688     defined $el->namespace_uri) {
689     my $mmParsed = $el->get_attribute_ns (ExpandedURI q<ddel:>, 'mmParsed');
690     if ($mmParsed) {
691     my $lextype = $el->get_attribute_ns (ExpandedURI q<ddel:>, 'lexType');
692     if ($lextype eq ExpandedURI q<dis:TFQNames>) {
693 wakaba 1.4 my $uri = dd_get_tfqnames_uri ($el);
694     if (defined $uri) {
695     $ReferredResource{$uri} ||= 1;
696     next EL;
697     }
698 wakaba 1.5 } elsif ($lextype eq ExpandedURI q<dis:TypeQName> or
699     $lextype eq ExpandedURI q<DISCore:NCNameOrQName>) {
700     my $uri = dd_get_qname_uri ($el);
701     if (defined $uri) {
702     $ReferredResource{$uri} ||= 1;
703     next EL;
704     }
705     } elsif ($lextype eq ExpandedURI q<DISPerl:MemRef> or
706     $lextype eq ExpandedURI q<DOMMain:XCodeRef>) {
707 wakaba 1.4 my @nm = @{$el->get_elements_by_tag_name_ns
708     (ExpandedURI q<ddel:>, 'name')};
709     if (@nm == 1) {
710 wakaba 1.5 my $uri = dd_get_tfqnames_uri ($nm[0]);
711     if (defined $uri) {
712     $el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:uri', $uri);
713     $ReferredResource{$uri} ||= 1;
714     next EL;
715     }
716     } elsif (@nm == 3) {
717     my $uri = dd_get_tfqnames_uri ($nm[2]);
718 wakaba 1.4 if (defined $uri) {
719 wakaba 1.5 $el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:uri', $uri);
720 wakaba 1.4 $ReferredResource{$uri} ||= 1;
721     next EL;
722     }
723     } elsif (@nm == 2) {
724     my $uri = dd_get_tfqnames_uri ($nm[0]);
725     if (not defined $uri) {
726     #
727     } elsif ($nm[1]->get_elements_by_tag_name_ns
728     (ExpandedURI q<ddel:>, 'prefix')->[0]) {
729     #my $luri = dd_get_qname_uri ($nm[1]);
730     ## QName: Currently not used
731     } else {
732     my $lnel = $nm[1]->get_elements_by_tag_name_ns
733     (ExpandedURI q<ddel:>, 'localName')->[0];
734     my $lname = $lnel ? $lnel->text_content : '';
735 wakaba 1.5 my $res;
736     if ($lextype eq ExpandedURI q<DOMMain:XCodeRef> or
737     {
738     ExpandedURI q<ddel:C> => 1,
739     ExpandedURI q<ddel:X> => 1,
740     }->{$el->namespace_uri . $el->local_name}) {
741     ## NOTE: $db
742     $res = $db->get_resource ($uri)
743     ->get_const_resource_by_name ($lname);
744     } else {
745     ## NOTE: $db
746     $res = $db->get_resource ($uri)
747     ->get_child_resource_by_name_and_type
748 wakaba 1.4 ($lname, ExpandedURI q<DISLang:AnyMethod>);
749 wakaba 1.5 }
750 wakaba 1.4 if ($res) {
751     $el->set_attribute_ns
752     (ExpandedURI q<dump:>, 'dump:uri', $res->uri);
753     $ReferredResource{$res->uri} ||= 1;
754     }
755     next EL;
756     }
757     }
758     } # lextype
759     } # mmParsed
760     elsif ($opt{method_resource} and
761     $el->namespace_uri eq ExpandedURI q<ddel:> and
762     $el->local_name eq 'P') {
763     my $res = $opt{method_resource}
764     ->get_child_resource_by_name_and_type
765     ($el->text_content, ExpandedURI q<DISLang:MethodParameter>);
766     if ($res) {
767     $el->set_attribute_ns
768     (ExpandedURI q<dump:>, 'dump:uri', $res->uri);
769     $ReferredResource{$res->uri} ||= 1;
770 wakaba 1.3 }
771 wakaba 1.4 next EL;
772 wakaba 1.3 }
773 wakaba 1.4 push @el, @{$el->child_nodes};
774 wakaba 1.3 } elsif ($el->node_type == $el->DOCUMENT_FRAGMENT_NODE or
775     $el->node_type == $el->DOCUMENT_NODE) {
776 wakaba 1.4 push @el, @{$el->child_nodes};
777 wakaba 1.3 }
778     } # EL
779     $el;
780     } # transform_disdoc_tree
781    
782 wakaba 1.4 sub dd_get_tfqnames_uri ($;%) {
783     my ($el, %opt) = @_;
784     return '' unless $el;
785     my $turi = dd_get_qname_uri ($el->get_elements_by_tag_name_ns
786     (ExpandedURI q<ddel:>, 'nameQName')->[0]);
787     my $furi = dd_get_qname_uri ($el->get_elements_by_tag_name_ns
788     (ExpandedURI q<ddel:>, 'forQName')->[0]);
789     return undef if not defined $turi or not defined $furi;
790     my $uri = tfuris2uri ($turi, $furi);
791     $el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:uri', $uri);
792     $uri;
793     } # dd_get_tfqnames_uri
794 wakaba 1.3
795     sub dd_get_qname_uri ($;%) {
796     my ($el, %opt) = @_;
797 wakaba 1.4 return undef unless $el;
798 wakaba 1.3 my $plel = $el->get_elements_by_tag_name_ns
799     (ExpandedURI q<ddel:>, 'prefix')->[0];
800     my $lnel = $el->get_elements_by_tag_name_ns
801     (ExpandedURI q<ddel:>, 'localName')->[0];
802     my $nsuri = ($plel ? $plel : $el)->lookup_namespace_uri
803     ($plel ? $plel->text_content : undef);
804     $nsuri = '' unless defined $nsuri;
805     if ($plel and $nsuri eq '') {
806     $plel->remove_attribute_ns
807 wakaba 1.4 (ExpandedURI q<xmlns:>, $plel->text_content);
808     $el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:namespaceURI', $nsuri);
809     return undef;
810     } else {
811     $el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:namespaceURI', $nsuri);
812 wakaba 1.3 }
813     if ($lnel) {
814     $nsuri . $lnel->text_content;
815     } else {
816     $el->get_attribute_ns (ExpandedURI q<ddel:>, 'defaultURI');
817     }
818     } # dd_get_qname_uri
819    
820     sub tfuris2uri ($$) {
821     my ($turi, $furi) = @_;
822     my $uri;
823 wakaba 1.5 if ($furi eq ExpandedURI q<ManakaiDOM:all>) {
824 wakaba 1.3 $uri = $turi;
825     } else {
826     my $__turi = $turi;
827     my $__furi = $furi;
828     for my $__uri ($__turi, $__furi) {
829     $__uri =~ s{([^0-9A-Za-z:;?=_./-])}{sprintf '%%%02X', ord $1}ge;
830     }
831     $uri = qq<data:,200411tf#xmlns(t=data:,200411tf%23)>.
832     qq<t:tf($__turi,$__furi)>;
833     }
834     $uri;
835     } # tfuris2uri
836    
837 wakaba 1.1 sub append_inheritance (%) {
838     my %opt = @_;
839     if (($opt{depth} ||= 0) == 100) {
840     warn "<".$opt{source_resource}->uri.">: Loop in inheritance";
841     return;
842     }
843 wakaba 1.5
844     my $has_isa = 0;
845 wakaba 1.1
846     for my $isa (@{$opt{source_resource}->get_property_resource_list
847     (ExpandedURI q<dis:ISA>,
848     default_media_type => ExpandedURI q<dis:TFQNames>)}) {
849 wakaba 1.5 $has_isa = 1;
850 wakaba 1.1 append_inheritance
851     (source_resource => $isa,
852     result_parent => $opt{result_parent}->append_new_extends ($isa->uri),
853 wakaba 1.5 depth => $opt{depth} + 1,
854     is_class => $opt{is_class});
855     $ReferredResource{$isa->uri} ||= 1;
856     if ($opt{class_uri}) {
857     unshift @ClassInheritance, $isa->uri;
858     push @{$ClassInheritance{$opt{class_uri}} ||= []}, $isa->uri;
859     }
860     }
861    
862     if ($opt{source_resource}->is_defined) {
863     for my $isa_pack (@{$opt{source_resource}->pl_additional_isa_packages}) {
864     my $isa;
865     if ($isa_pack eq 'Message::Util::Error') {
866     ## NOTE: $db
867     $isa = $db->get_resource (ExpandedURI q<ecore:MUError>,
868     for_arg => ExpandedURI q<ManakaiDOM:Perl>);
869     } elsif ($isa_pack eq 'Tie::Array') {
870     ## NOTE: $db
871     $isa = $db->get_resource (ExpandedURI q<DISPerl:TieArray>);
872     } elsif ($isa_pack eq 'Error') {
873     ## NOTE: $db
874     $isa = $db->get_resource (ExpandedURI q<ecore:Error>,
875     for_arg => ExpandedURI q<ManakaiDOM:Perl>);
876     } else {
877     ## TODO: What to do?
878     }
879     if ($isa) {
880     $has_isa = 1;
881     append_inheritance
882     (source_resource => $isa,
883     result_parent => $opt{result_parent}->append_new_extends ($isa->uri),
884     depth => $opt{depth} + 1,
885     is_class => $opt{is_class});
886     $ReferredResource{$isa->uri} ||= 1;
887     if ($opt{class_uri}) {
888     unshift @ClassInheritance, $isa->uri;
889     push @{$ClassInheritance{$opt{class_uri}} ||= []}, $isa->uri;
890     }
891     }
892     }} # AppISA
893    
894     if ($opt{has_const}) {
895     ## NOTE: $db
896     my $isa = $db->get_resource (ExpandedURI q<DISPerl:Exporter>);
897     append_inheritance
898     (source_resource => $isa,
899     result_parent => $opt{result_parent}->append_new_extends ($isa->uri),
900     depth => $opt{depth} + 1,
901     is_class => $opt{is_class});
902     $ReferredResource{$isa->uri} ||= 1;
903     if ($opt{class_uri}) {
904     unshift @ClassInheritance, $isa->uri;
905     push @{$ClassInheritance{$opt{class_uri}} ||= []}, $isa->uri;
906     }
907     }
908    
909     if (not $has_isa and $opt{is_class} and
910     $opt{source_resource}->uri ne ExpandedURI q<DISPerl:UNIVERSAL>) {
911     ## NOTE: $db
912     my $isa = $db->get_resource (ExpandedURI q<DISPerl:UNIVERSAL>);
913     append_inheritance
914     (source_resource => $isa,
915     result_parent => $opt{result_parent}->append_new_extends ($isa->uri),
916     depth => $opt{depth} + 1,
917     is_class => $opt{is_class});
918 wakaba 1.2 $ReferredResource{$isa->uri} ||= 1;
919 wakaba 1.5 if ($opt{class_uri}) {
920     unshift @ClassInheritance, $isa->uri;
921     push @{$ClassInheritance{$opt{class_uri}} ||= []}, $isa->uri;
922     }
923 wakaba 1.1 }
924    
925     if ($opt{append_implements}) {
926 wakaba 1.5 ## NOTE: $db
927     my $u = $db->get_resource (ExpandedURI q<DISPerl:UNIVERSALInterface>);
928 wakaba 1.1 for my $impl (@{$opt{source_resource}->get_property_resource_list
929     (ExpandedURI q<dis:Implement>,
930     default_media_type => ExpandedURI q<dis:TFQNames>,
931 wakaba 1.5 isa_recursive => 1)}, $u) {
932 wakaba 1.1 append_inheritance
933     (source_resource => $impl,
934     result_parent => $opt{result_parent}->append_new_implements
935     ($impl->uri),
936     depth => $opt{depth});
937 wakaba 1.2 $ReferredResource{$impl->uri} ||= 1;
938 wakaba 1.5 $ClassImplements{$opt{class_uri}}->{$impl->uri} = 1
939     if $opt{class_uri};
940 wakaba 1.1 }
941     }
942     } # append_inheritance
943    
944 wakaba 1.5 sub append_subclassof (%) {
945     my %opt = @_;
946    
947     ## NOTE: This subroutine directly access to internal structure
948     ## of ManakaiDISResourceDefinition
949    
950     my $a;
951     $a = sub ($$) {
952     my ($gdb, $s) = @_;
953     my %s = keys %$s;
954     while (my $i = [keys %s]->[0]) {
955     ## Removes itself
956     delete $s->{$i};
957     #warn $i;
958    
959     my $ires = $gdb->get_resource ($i);
960     for my $j (keys %$s) {
961     next if $i eq $j;
962     if ($ires->{subOf}->{$j}) {
963     $s->{$i}->{$j} = $s->{$j};
964     delete $s->{$j};
965     delete $s{$j};
966     }
967     }
968    
969     delete $s{$i};
970     } # %s
971    
972     for my $i (keys %$s) {
973     $a->($s->{$i}) if keys %{$s->{$i}};
974     }
975     };
976    
977     my $b;
978     $b = sub ($$) {
979     my ($s, $p) = @_;
980     for my $i (keys %$s) {
981     my $el = $p->append_new_sub_class_of ($i);
982     $b->($s->{$i}, $el) if keys %{$s->{$i}};
983     }
984     };
985    
986    
987     my $sub = {$opt{source_resource}->uri =>
988     {map {$_ => {}} keys %{$opt{source_resource}->{subOf}}}};
989     ## NOTE: $db
990     $a->($db, $sub);
991     $b->($sub, $opt{result_parent});
992     } # append_subclassof
993    
994 wakaba 1.2 sub add_uri ($$;%) {
995     my ($res, $el, %opt) = @_;
996     my $canon_uri = $res->uri;
997     for my $uri (@{$res->uris}) {
998     $el->add_uri ($uri, $canon_uri eq $uri ? 0 : 1);
999     $ReferredResource{$uri} = -1;
1000     }
1001 wakaba 1.3
1002     my $nsuri = $res->namespace_uri;
1003     $el->resource_namespace_uri ($nsuri) if defined $nsuri;
1004     my $lname = $res->local_name;
1005     $el->resource_local_name ($lname) if defined $lname;
1006 wakaba 1.2 } # add_uri
1007    
1008 wakaba 1.5 sub append_raises (%) {
1009     my %opt = @_;
1010     my $parent = $opt{source_resource}->source_element;
1011     return unless $parent;
1012    
1013     for my $el (@{$parent->dis_child_elements
1014     (for_arg => $opt{source_resource}->for_uri,
1015     forp_arg => $opt{source_resource}->forp_uri)}) {
1016     if ($el->expanded_uri eq ExpandedURI q<ManakaiDOM:raises>) {
1017     ## NOTE: $db is used
1018     my ($a, $b, $c) = @{$db->xcref_to_resource
1019     ($el->value, $el,
1020     for_arg => $opt{source_resource}->for_uri)};
1021    
1022     my $rel = $opt{result_parent}->create_raises
1023     ($a->uri, $b ? $b->uri : undef, $c ? $c->uri : undef);
1024    
1025     append_description (source_resource => $opt{source_resource},
1026     source_element => $el,
1027     result_parent => $rel,
1028     method_resource => $opt{method_resource});
1029     }
1030     }
1031     } # append_raises
1032 wakaba 1.4
1033    
1034 wakaba 1.1 my $doc = $impl->create_disdump_document;
1035    
1036     my $body = $doc->document_element;
1037    
1038    
1039 wakaba 1.4 ## -- Outputs requested modules
1040    
1041     for my $mod_uri (keys %{$Opt{module_uri}}) {
1042 wakaba 1.5 my $mod_for = $Opt{For};
1043     my $mod = $db->get_module ($mod_uri, for_arg => $mod_for);
1044     unless ($mod_for) {
1045 wakaba 1.4 my $el = $mod->source_element;
1046     if ($el) {
1047 wakaba 1.5 $mod_for = $el->default_for_uri;
1048     $mod = $db->get_module ($mod_uri, for_arg => $mod_for);
1049 wakaba 1.4 }
1050     }
1051     unless ($mod->is_defined) {
1052 wakaba 1.5 die qq<$0: Module <$mod_uri> for <$mod_for> is not defined>;
1053 wakaba 1.4 }
1054    
1055 wakaba 1.5 status_msg qq<Module <$mod_uri> for <$mod_for>...>;
1056 wakaba 1.7 progress_reset;
1057 wakaba 1.4
1058     append_module_documentation
1059     (result_parent => $body,
1060     source_resource => $mod);
1061 wakaba 1.5
1062     status_msg qq<done>;
1063 wakaba 1.4 } # mod_uri
1064    
1065     ## -- Outputs referenced resources in external modules
1066 wakaba 1.2
1067 wakaba 1.5 status_msg q<Other modules...>;
1068 wakaba 1.7 progress_reset;
1069 wakaba 1.5
1070 wakaba 1.2 while (my @ruri = grep {$ReferredResource{$_} > 0} keys %ReferredResource) {
1071     U: while (defined (my $uri = shift @ruri)) {
1072     next U if $ReferredResource{$uri} < 0; ## Already done
1073 wakaba 1.7 progress_inc;
1074 wakaba 1.2 my $res = $db->get_resource ($uri);
1075     unless ($res->is_defined) {
1076     $res = $db->get_module ($uri);
1077     unless ($res->is_defined) {
1078     $ReferredResource{$uri} = -1;
1079     next U;
1080     }
1081     append_module_documentation
1082     (result_parent => $body,
1083     source_resource => $res,
1084     is_partial => 1);
1085     } elsif ($res->is_type_uri (ExpandedURI q<ManakaiDOM:Class>)) {
1086     my $mod = $res->owner_module;
1087     unless ($ReferredResource{$mod->uri} < 0) {
1088     unshift @ruri, $uri;
1089     unshift @ruri, $mod->uri;
1090     next U;
1091     }
1092     append_class_documentation
1093     (result_parent => $body->create_module ($mod->uri),
1094     source_resource => $res,
1095     is_partial => 1);
1096     } elsif ($res->is_type_uri (ExpandedURI q<ManakaiDOM:IF>)) {
1097     my $mod = $res->owner_module;
1098     unless ($mod->is_defined) {
1099     $ReferredResource{$uri} = -1;
1100     next U;
1101     } elsif (not ($ReferredResource{$mod->uri} < 0)) {
1102     unshift @ruri, $uri;
1103     unshift @ruri, $mod->uri;
1104     next U;
1105     }
1106     append_interface_documentation
1107     (result_parent => $body->create_module ($mod->uri),
1108     source_resource => $res,
1109     is_partial => 1);
1110 wakaba 1.3 } elsif ($res->is_type_uri (ExpandedURI q<DISCore:AbstractDataType>)) {
1111     my $mod = $res->owner_module;
1112     unless ($mod->is_defined) {
1113     $ReferredResource{$uri} = -1;
1114     next U;
1115     } elsif (not ($ReferredResource{$mod->uri} < 0)) {
1116     unshift @ruri, $uri;
1117     unshift @ruri, $mod->uri;
1118     next U;
1119     }
1120     append_datatype_documentation
1121     (result_parent => $body->create_module ($mod->uri),
1122     source_resource => $res);
1123     } elsif ($res->is_type_uri (ExpandedURI q<DISLang:AnyMethod>) or
1124     $res->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) {
1125 wakaba 1.2 my $cls = $res->get_property_resource
1126     (ExpandedURI q<dis2pm:parentResource>);
1127     if (not ($ReferredResource{$cls->uri} < 0) and
1128     ($cls->is_type_uri (ExpandedURI q<ManakaiDOM:Class>) or
1129     $cls->is_type_uri (ExpandedURI q<ManakaiDOM:IF>))) {
1130     unshift @ruri, $uri;
1131     unshift @ruri, $cls->uri;
1132     next U;
1133     }
1134     my $model = $body->create_module ($cls->owner_module->uri);
1135     my $clsel = $cls->is_type_uri (ExpandedURI q<ManakaiDOM:Class>)
1136     ? $model->create_class ($cls->uri)
1137     : $model->create_interface ($cls->uri);
1138     if ($res->is_type_uri (ExpandedURI q<DISLang:Method>)) {
1139     append_method_documentation
1140     (result_parent => $clsel,
1141     source_resource => $res);
1142 wakaba 1.3 } elsif ($res->is_type_uri (ExpandedURI q<DISLang:Attribute>)) {
1143 wakaba 1.2 append_attr_documentation
1144 wakaba 1.3 (result_parent => $clsel,
1145     source_resource => $res);
1146     } elsif ($res->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) {
1147     append_constgroup_documentation
1148     (result_parent => $clsel,
1149 wakaba 1.2 source_resource => $res);
1150     }
1151     } elsif ($res->is_type_uri (ExpandedURI q<DISLang:MethodParameter>)) {
1152     my $m = $res->get_property_resource
1153     (ExpandedURI q<dis2pm:parentResource>);
1154     if (not ($ReferredResource{$m->uri} < 0) and
1155     $m->is_type_uri (ExpandedURI q<DISLang:Method>)) {
1156     unshift @ruri, $m->uri;
1157 wakaba 1.4 $ReferredResource{$res->uri} = -1;
1158 wakaba 1.2 next U;
1159     }
1160 wakaba 1.3 } elsif ($res->is_type_uri (ExpandedURI q<ManakaiDOM:Const>)) {
1161     my $m = $res->get_property_resource
1162     (ExpandedURI q<dis2pm:parentResource>);
1163     if (not ($ReferredResource{$m->uri} < 0) and
1164     $m->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) {
1165     unshift @ruri, $m->uri;
1166 wakaba 1.4 $ReferredResource{$res->uri} = -1;
1167 wakaba 1.3 next U;
1168     }
1169     } elsif ($res->is_type_uri
1170     (ExpandedURI q<ManakaiDOM:ExceptionOrWarningSubType>)) {
1171     my $m = $res->get_property_resource
1172     (ExpandedURI q<dis2pm:parentResource>);
1173     if (not ($ReferredResource{$m->uri} < 0) and
1174     $m->is_type_uri (ExpandedURI q<ManakaiDOM:Const>)) {
1175     unshift @ruri, $m->uri;
1176 wakaba 1.4 $ReferredResource{$res->uri} = -1;
1177 wakaba 1.3 next U;
1178     }
1179 wakaba 1.2 } else { ## Unsupported type
1180     $ReferredResource{$uri} = -1;
1181     }
1182     } # U
1183     }
1184    
1185 wakaba 1.5 status_msg q<done>;
1186    
1187     ## -- Inheriting methods information
1188 wakaba 1.1
1189 wakaba 1.5 {
1190     verbose_msg_ q<Adding inheritance information...>;
1191     my %class_done;
1192     for my $class_uri (@ClassInheritance) {
1193     next if $class_done{$class_uri};
1194     $class_done{$class_uri};
1195     for my $sclass_uri (@{$ClassInheritance{$class_uri}}) {
1196     for my $scm_name (keys %{$ClassMembers{$sclass_uri}}) {
1197     if ($ClassMembers{$class_uri}->{$scm_name}) {
1198     $ClassMembers{$class_uri}->{$scm_name}->{overrides}
1199     ->{$ClassMembers{$sclass_uri}->{$scm_name}->{resource}->uri} = 1;
1200     } else {
1201     $ClassMembers{$class_uri}->{$scm_name}
1202     = {
1203     %{$ClassMembers{$sclass_uri}->{$scm_name}},
1204     is_inherited => 1,
1205     };
1206     }
1207     }
1208     } # superclasses
1209     } # classes
1210 wakaba 1.1
1211 wakaba 1.5 for my $class_uri (keys %ClassImplements) {
1212     for my $if_uri (keys %{$ClassImplements{$class_uri}||{}}) {
1213     for my $mem_name (keys %{$ClassMembers{$if_uri}}) {
1214     unless ($ClassMembers{$class_uri}->{$mem_name}) {
1215     ## Not defined - error
1216     $ClassMembers{$class_uri}->{$mem_name}
1217     = {
1218     %{$ClassMembers{$if_uri}->{$mem_name}},
1219     is_inherited => 1,
1220     };
1221     }
1222     $ClassMembers{$class_uri}->{$mem_name}->{implements}
1223     ->{$ClassMembers{$if_uri}->{$mem_name}->{resource}->uri} = 1;
1224     }
1225     } # interfaces
1226     } # classes
1227    
1228     for my $class_uri (keys %ClassMembers) {
1229     my $cls_res = $db->get_resource ($class_uri);
1230     next unless $cls_res->is_defined;
1231     verbose_msg_ q<.>;
1232     my $cls_el = $body->create_module ($cls_res->owner_module->uri);
1233     if ($cls_res->is_type_uri (ExpandedURI q<ManakaiDOM:IF>)) {
1234     $cls_el = $cls_el->create_interface ($class_uri);
1235     } else {
1236     $cls_el = $cls_el->create_class ($class_uri);
1237     }
1238     for my $mem_name (keys %{$ClassMembers{$class_uri}}) {
1239     my $mem_info = $ClassMembers{$class_uri}->{$mem_name};
1240     my $el;
1241     if ($mem_info->{type} eq 'const-group') {
1242     $el = $cls_el->create_const_group ($mem_name);
1243     } elsif ($mem_info->{type} eq 'attr') {
1244     $el = $cls_el->create_attribute ($mem_name);
1245     } else {
1246     $el = $cls_el->create_method ($mem_name);
1247     }
1248     if ($mem_info->{is_inherited}) {
1249     $el->ref ($mem_info->{resource}->uri);
1250     }
1251     for my $or (keys %{$mem_info->{overrides}||{}}) {
1252     $el->append_new_overrides ($or);
1253     }
1254     for my $or (keys %{$mem_info->{implements}||{}}) {
1255     $el->append_new_implements ($or);
1256     }
1257     } # members
1258     } # classes
1259    
1260     verbose_msg q<done>;
1261     undef %ClassMembers;
1262     }
1263    
1264     {
1265     status_msg_ qq<Writing file ""...>;
1266    
1267     require Encode;
1268     my $lsimpl = $impl->get_feature (ExpandedURI q<DOMLS:LS> => '3.0');
1269     my $serializer = $lsimpl->create_mls_serializer
1270 wakaba 1.1 ({ExpandedURI q<DOMLS:SerializeDocumentInstance> => ''});
1271 wakaba 1.5 my $serialized = $serializer->write_to_string ($doc);
1272 wakaba 1.6 verbose_msg_ qq< serialized, >;
1273     my $encoded = Encode::encode ('utf8', $serialized);
1274     verbose_msg_ qq<bytenized, and >;
1275     print STDOUT $encoded;
1276 wakaba 1.5 close STDOUT;
1277     status_msg qq<done>;
1278     }
1279 wakaba 1.1
1280     verbose_msg_ qq<Checking undefined resources...>;
1281     $db->check_undefined_resource;
1282     verbose_msg qq<done>;
1283    
1284     verbose_msg_ qq<Closing database...>;
1285 wakaba 1.5 $db->free;
1286 wakaba 1.1 undef $db;
1287     verbose_msg qq<done>;
1288    
1289 wakaba 1.5 END {
1290     $db->free if $db;
1291     }
1292    
1293 wakaba 1.1 =head1 SEE ALSO
1294    
1295     L<lib/manakai/dis.pl> and L<bin/cdis2pm.pl> - Old version of
1296     this script.
1297    
1298 wakaba 1.5 L<lib/Message/Util/DIS.dis> - The I<dis> object implementation.
1299 wakaba 1.1
1300     L<lib/Message/Util/PerlCode.dis> - The Perl code generator.
1301    
1302     L<lib/manakai/DISCore.dis> - The definition for the "dis" format.
1303    
1304     L<lib/manakai/DISPerl.dis> - The definition for the "dis" Perl-specific
1305     vocabulary.
1306    
1307     =head1 LICENSE
1308    
1309     Copyright 2004-2005 Wakaba <w@suika.fam.cx>. All rights reserved.
1310    
1311     This program is free software; you can redistribute it and/or
1312     modify it under the same terms as Perl itself.
1313    
1314     =cut
1315    
1316 wakaba 1.7 1; # $Date: 2005/09/17 15:03:02 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24