1 ###################################################
2 # dump function for IDL structures
3 # Copyright tridge@samba.org 2000
4 # released under the GNU GPL
6 package Parse::Pidl::Dump;
11 @EXPORT_OK = qw(DumpTypedef DumpStruct DumpEnum DumpBitmap DumpUnion DumpFunction);
14 use Parse::Pidl::Util qw(has_property);
18 #####################################################################
19 # dump a properties list
25 foreach my $d ($props) {
26 foreach my $k (keys %{$d}) {
39 $res .= "[$k($d->{$k})] ";
45 #####################################################################
46 # dump a structure element
52 (defined $element->{PROPERTIES}) &&
53 ($res .= DumpProperties($element->{PROPERTIES}));
54 $res .= DumpType($element->{TYPE});
56 for my $i (1..$element->{POINTERS}) {
59 $res .= "$element->{NAME}";
60 foreach (@{$element->{ARRAY_LEN}}) {
67 #####################################################################
75 if (defined $struct->{ELEMENTS}) {
76 foreach my $e (@{$struct->{ELEMENTS}}) {
77 $res .= "\t" . DumpElement($e);
87 #####################################################################
96 foreach (@{$enum->{ELEMENTS}}) {
97 if (/^([A-Za-z0-9_]+)[ \t]*\((.*)\)$/) {
98 $res .= "\t$1 = $2,\n";
109 #####################################################################
116 $res .= "bitmap {\n";
118 foreach (@{$bitmap->{ELEMENTS}}) {
119 if (/^([A-Za-z0-9_]+)[ \t]*\((.*)\)$/) {
120 $res .= "\t$1 = $2,\n";
122 die ("Bitmap $bitmap->{NAME} has field $_ without proper value");
132 #####################################################################
133 # dump a union element
134 sub DumpUnionElement($)
136 my($element) = shift;
139 if (has_property($element, "default")) {
140 $res .= "[default] ;\n";
142 $res .= "[case($element->{PROPERTIES}->{case})] ";
143 $res .= DumpElement($element), if defined($element);
150 #####################################################################
157 (defined $union->{PROPERTIES}) &&
158 ($res .= DumpProperties($union->{PROPERTIES}));
160 foreach my $e (@{$union->{ELEMENTS}}) {
161 $res .= DumpUnionElement($e);
168 #####################################################################
175 if (ref($data) eq "HASH") {
176 ($data->{TYPE} eq "STRUCT") && ($res .= DumpStruct($data));
177 ($data->{TYPE} eq "UNION") && ($res .= DumpUnion($data));
178 ($data->{TYPE} eq "ENUM") && ($res .= DumpEnum($data));
179 ($data->{TYPE} eq "BITMAP") && ($res .= DumpBitmap($data));
187 #####################################################################
191 my($typedef) = shift;
195 $res .= DumpType($typedef->{DATA});
196 $res .= " $typedef->{NAME};\n\n";
201 #####################################################################
205 my($function) = shift;
209 $res .= DumpType($function->{RETURN_TYPE});
210 $res .= " $function->{NAME}(\n";
211 for my $d (@{$function->{DATA}}) {
212 $first || ($res .= ",\n"); $first = 0;
213 $res .= DumpElement($d);
220 #####################################################################
221 # dump a module header
222 sub DumpInterfaceProperties($)
225 my($data) = $header->{DATA};
230 foreach my $k (keys %{$data}) {
231 $first || ($res .= ",\n"); $first = 0;
232 $res .= "$k($data->{$k})";
239 #####################################################################
240 # dump the interface definitions
243 my($interface) = shift;
244 my($data) = $interface->{DATA};
247 $res .= DumpInterfaceProperties($interface->{PROPERTIES});
249 $res .= "interface $interface->{NAME}\n{\n";
250 foreach my $d (@{$data}) {
251 ($d->{TYPE} eq "TYPEDEF") &&
252 ($res .= DumpTypedef($d));
253 ($d->{TYPE} eq "FUNCTION") &&
254 ($res .= DumpFunction($d));
262 #####################################################################
263 # dump a parsed IDL structure back into an IDL file
269 $res = "/* Dumped by pidl */\n\n";
270 foreach my $x (@{$idl}) {
271 ($x->{TYPE} eq "INTERFACE") &&
272 ($res .= DumpInterface($x));