1 ###################################################
2 # Samba4 NDR info tree generator
3 # Copyright tridge@samba.org 2000-2003
4 # Copyright tpot@samba.org 2001
5 # Copyright jelmer@samba.org 2004-2006
6 # released under the GNU GPL
12 Parse::Pidl::NDR - NDR parsing information generator
16 Return a table describing the order in which the parts of an element
27 Jelmer Vernooij <jelmer@samba.org>
31 package Parse::Pidl::NDR;
34 use vars qw($VERSION);
37 @EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString);
38 @EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType can_contain_deferred);
41 use Parse::Pidl qw(warning fatal);
42 use Parse::Pidl::Typelist qw(hasType getType expandAlias);
43 use Parse::Pidl::Util qw(has_property property_matches);
45 # Alignment of the built-in scalar types
46 my $scalar_alignment = {
62 'string_array' => 4, #???
71 'wrepl_nbt_name' => 4,
75 sub GetElementLevelTable($)
81 my @bracket_array = ();
86 if (has_property($e, "size_is")) {
87 @size_is = split /,/, has_property($e, "size_is");
90 if (has_property($e, "length_is")) {
91 @length_is = split /,/, has_property($e, "length_is");
94 if (defined($e->{ARRAY_LEN})) {
95 @bracket_array = @{$e->{ARRAY_LEN}};
98 if (has_property($e, "out")) {
101 if (has_property($e, "string")) { $needptrs++; }
102 if ($#bracket_array >= 0) { $needptrs = 0; }
104 warning($e, "[out] argument `$e->{NAME}' not a pointer") if ($needptrs > $e->{POINTERS});
107 # Parse the [][][][] style array stuff
108 for my $i (0 .. $#bracket_array) {
109 my $d = $bracket_array[$#bracket_array - $i];
112 my $is_surrounding = 0;
114 my $is_conformant = 0;
121 if ($size = shift @size_is) {
122 } elsif ((scalar(@size_is) == 0) and has_property($e, "string")) {
124 delete($e->{PROPERTIES}->{string});
126 fatal($e, "Must specify size_is() for conformant array!")
129 if (($length = shift @length_is) or $is_string) {
135 if ($e == $e->{PARENT}->{ELEMENTS}[-1]
136 and $e->{PARENT}->{TYPE} ne "FUNCTION") {
141 $is_fixed = 1 if (not $is_conformant and Parse::Pidl::Util::is_constant($size));
142 $is_inline = 1 if (not $is_conformant and not Parse::Pidl::Util::is_constant($size));
147 LENGTH_IS => $length,
148 IS_DEFERRED => $is_deferred,
149 IS_SURROUNDING => $is_surrounding,
150 IS_ZERO_TERMINATED => $is_string,
151 IS_VARYING => $is_varying,
152 IS_CONFORMANT => $is_conformant,
153 IS_FIXED => $is_fixed,
154 IS_INLINE => $is_inline
158 # Next, all the pointers
159 foreach my $i (1..$e->{POINTERS}) {
160 my $pt = pointer_type($e);
162 my $level = "EMBEDDED";
163 # Top level "ref" pointers do not have a referrent identifier
164 $level = "TOP" if ( defined($pt)
166 and $e->{PARENT}->{TYPE} eq "FUNCTION");
170 # for now, there can only be one pointer type per element
171 POINTER_TYPE => pointer_type($e),
172 POINTER_INDEX => $pointer_idx,
173 IS_DEFERRED => "$is_deferred",
177 warning($e, "top-level \[out\] pointer `$e->{NAME}' is not a \[ref\] pointer")
178 if ($i == 1 and pointer_type($e) ne "ref" and
179 $e->{PARENT}->{TYPE} eq "FUNCTION" and
180 not has_property($e, "in"));
184 # everything that follows will be deferred
185 $is_deferred = 1 if ($e->{PARENT}->{TYPE} ne "FUNCTION");
187 my $array_size = shift @size_is;
194 if ($array_length = shift @length_is) {
197 $array_length = $array_size;
202 if (scalar(@size_is) == 0 and has_property($e, "string") and
203 $i == $e->{POINTERS}) {
205 $is_varying = $is_conformant = has_property($e, "noheader")?0:1;
206 delete($e->{PROPERTIES}->{string});
209 if ($array_size or $is_string) {
212 SIZE_IS => $array_size,
213 LENGTH_IS => $array_length,
214 IS_DEFERRED => $is_deferred,
216 IS_ZERO_TERMINATED => $is_string,
217 IS_VARYING => $is_varying,
218 IS_CONFORMANT => $is_conformant,
227 if (defined(has_property($e, "subcontext"))) {
228 my $hdr_size = has_property($e, "subcontext");
229 my $subsize = has_property($e, "subcontext_size");
230 if (not defined($subsize)) {
235 TYPE => "SUBCONTEXT",
236 HEADER_SIZE => $hdr_size,
237 SUBCONTEXT_SIZE => $subsize,
238 IS_DEFERRED => $is_deferred,
239 COMPRESSION => has_property($e, "compression"),
243 if (my $switch = has_property($e, "switch_is")) {
246 SWITCH_IS => $switch,
247 IS_DEFERRED => $is_deferred
251 if (scalar(@size_is) > 0) {
252 fatal($e, "size_is() on non-array element");
255 if (scalar(@length_is) > 0) {
256 fatal($e, "length_is() on non-array element");
259 if (has_property($e, "string")) {
260 fatal($e, "string() attribute on non-array element");
265 DATA_TYPE => $e->{TYPE},
266 IS_DEFERRED => $is_deferred,
267 CONTAINS_DEFERRED => can_contain_deferred($e->{TYPE}),
268 IS_SURROUNDING => 0 #FIXME
272 foreach (@$order) { $_->{LEVEL_INDEX} = $i; $i+=1; }
277 #####################################################################
278 # see if a type contains any deferred data
279 sub can_contain_deferred($)
281 sub can_contain_deferred($);
284 return 1 unless (hasType($type)); # assume the worst
286 $type = getType($type);
288 return 0 if (Parse::Pidl::Typelist::is_scalar($type));
290 return can_contain_deferred($type->{DATA}) if ($type->{TYPE} eq "TYPEDEF");
292 return 0 unless defined($type->{ELEMENTS});
294 foreach (@{$type->{ELEMENTS}}) {
295 return 1 if ($_->{POINTERS});
296 return 1 if (can_contain_deferred ($_->{TYPE}));
306 return undef unless $e->{POINTERS};
308 return "ref" if (has_property($e, "ref"));
309 return "full" if (has_property($e, "ptr"));
310 return "sptr" if (has_property($e, "sptr"));
311 return "unique" if (has_property($e, "unique"));
312 return "relative" if (has_property($e, "relative"));
313 return "ignore" if (has_property($e, "ignore"));
318 #####################################################################
319 # work out the correct alignment for a structure or union
320 sub find_largest_alignment($)
325 for my $e (@{$s->{ELEMENTS}}) {
328 if ($e->{POINTERS}) {
330 } elsif (has_property($e, "subcontext")) {
332 } elsif (has_property($e, "transmit_as")) {
333 $a = align_type($e->{PROPERTIES}->{transmit_as});
335 $a = align_type($e->{TYPE});
338 $align = $a if ($align < $a);
344 #####################################################################
351 if (ref($e) eq "HASH" and $e->{TYPE} eq "SCALAR") {
352 return $scalar_alignment->{$e->{NAME}};
355 return 0 if ($e eq "EMPTY");
357 unless (hasType($e)) {
358 # it must be an external type - all we can do is guess
359 # warning($e, "assuming alignment of unknown type '$e' is 4");
363 my $dt = getType($e);
365 if ($dt->{TYPE} eq "TYPEDEF") {
366 return align_type($dt->{DATA});
367 } elsif ($dt->{TYPE} eq "ENUM") {
368 return align_type(Parse::Pidl::Typelist::enum_type_fn($dt));
369 } elsif ($dt->{TYPE} eq "BITMAP") {
370 return align_type(Parse::Pidl::Typelist::bitmap_type_fn($dt));
371 } elsif (($dt->{TYPE} eq "STRUCT") or ($dt->{TYPE} eq "UNION")) {
372 # Struct/union without body: assume 4
373 return 4 unless (defined($dt->{ELEMENTS}));
374 return find_largest_alignment($dt);
377 die("Unknown data type type $dt->{TYPE}");
382 my ($e, $pointer_default) = @_;
384 $e->{TYPE} = expandAlias($e->{TYPE});
386 if (ref($e->{TYPE}) eq "HASH") {
387 $e->{TYPE} = ParseType($e->{TYPE}, $pointer_default);
393 PROPERTIES => $e->{PROPERTIES},
394 LEVELS => GetElementLevelTable($e),
395 REPRESENTATION_TYPE => ($e->{PROPERTIES}->{represent_as} or $e->{TYPE}),
396 ALIGN => align_type($e->{TYPE}),
403 my ($struct, $pointer_default) = @_;
405 my $surrounding = undef;
409 NAME => $struct->{NAME},
410 SURROUNDING_ELEMENT => undef,
412 PROPERTIES => $struct->{PROPERTIES},
415 } unless defined($struct->{ELEMENTS});
417 CheckPointerTypes($struct, $pointer_default);
419 foreach my $x (@{$struct->{ELEMENTS}})
421 my $e = ParseElement($x, $pointer_default);
422 if ($x != $struct->{ELEMENTS}[-1] and
423 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
424 fatal($x, "conformant member not at end of struct");
429 my $e = $elements[-1];
430 if (defined($e) and defined($e->{LEVELS}[0]->{IS_SURROUNDING}) and
431 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
435 if (defined $e->{TYPE} && $e->{TYPE} eq "string"
436 && property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
437 $surrounding = $struct->{ELEMENTS}[-1];
441 if ($struct->{NAME}) {
442 $align = align_type($struct->{NAME});
447 NAME => $struct->{NAME},
448 SURROUNDING_ELEMENT => $surrounding,
449 ELEMENTS => \@elements,
450 PROPERTIES => $struct->{PROPERTIES},
458 my ($e, $pointer_default) = @_;
461 my $switch_type = has_property($e, "switch_type");
462 unless (defined($switch_type)) { $switch_type = "uint32"; }
463 if (has_property($e, "nodiscriminant")) { $switch_type = undef; }
468 SWITCH_TYPE => $switch_type,
470 PROPERTIES => $e->{PROPERTIES},
471 HAS_DEFAULT => $hasdefault,
473 } unless defined($e->{ELEMENTS});
475 CheckPointerTypes($e, $pointer_default);
477 foreach my $x (@{$e->{ELEMENTS}})
480 if ($x->{TYPE} eq "EMPTY") {
481 $t = { TYPE => "EMPTY" };
483 $t = ParseElement($x, $pointer_default);
485 if (has_property($x, "default")) {
486 $t->{CASE} = "default";
488 } elsif (defined($x->{PROPERTIES}->{case})) {
489 $t->{CASE} = "case $x->{PROPERTIES}->{case}";
491 die("Union element $x->{NAME} has neither default nor case property");
499 SWITCH_TYPE => $switch_type,
500 ELEMENTS => \@elements,
501 PROPERTIES => $e->{PROPERTIES},
502 HAS_DEFAULT => $hasdefault,
509 my ($e, $pointer_default) = @_;
514 BASE_TYPE => Parse::Pidl::Typelist::enum_type_fn($e),
515 ELEMENTS => $e->{ELEMENTS},
516 PROPERTIES => $e->{PROPERTIES},
523 my ($e, $pointer_default) = @_;
528 BASE_TYPE => Parse::Pidl::Typelist::bitmap_type_fn($e),
529 ELEMENTS => $e->{ELEMENTS},
530 PROPERTIES => $e->{PROPERTIES},
537 my ($d, $pointer_default) = @_;
540 STRUCT => \&ParseStruct,
541 UNION => \&ParseUnion,
543 BITMAP => \&ParseBitmap,
544 TYPEDEF => \&ParseTypedef,
545 }->{$d->{TYPE}}->($d, $pointer_default);
552 my ($d, $pointer_default) = @_;
554 if (defined($d->{DATA}->{PROPERTIES}) && !defined($d->{PROPERTIES})) {
555 $d->{PROPERTIES} = $d->{DATA}->{PROPERTIES};
558 my $data = ParseType($d->{DATA}, $pointer_default);
559 $data->{ALIGN} = align_type($d->{NAME});
564 PROPERTIES => $d->{PROPERTIES},
577 sub ParseFunction($$$)
579 my ($ndr,$d,$opnum) = @_;
582 my $thisopnum = undef;
584 CheckPointerTypes($d, $ndr->{PROPERTIES}->{pointer_default_top});
586 if (not defined($d->{PROPERTIES}{noopnum})) {
587 $thisopnum = ${$opnum};
591 foreach my $x (@{$d->{ELEMENTS}}) {
592 my $e = ParseElement($x, $ndr->{PROPERTIES}->{pointer_default});
593 push (@{$e->{DIRECTION}}, "in") if (has_property($x, "in"));
594 push (@{$e->{DIRECTION}}, "out") if (has_property($x, "out"));
596 push (@elements, $e);
599 if ($d->{RETURN_TYPE} ne "void") {
600 $rettype = expandAlias($d->{RETURN_TYPE});
604 if (has_property($d, "async")) { $async = 1; }
611 RETURN_TYPE => $rettype,
612 PROPERTIES => $d->{PROPERTIES},
613 ELEMENTS => \@elements,
618 sub CheckPointerTypes($$)
620 my ($s,$default) = @_;
622 return unless defined($s->{ELEMENTS});
624 foreach my $e (@{$s->{ELEMENTS}}) {
625 if ($e->{POINTERS} and not defined(pointer_type($e))) {
626 $e->{PROPERTIES}->{$default} = 1;
631 sub FindNestedTypes($$)
633 sub FindNestedTypes($$);
636 return if not defined($t->{ELEMENTS});
637 return if ($t->{TYPE} eq "ENUM");
638 return if ($t->{TYPE} eq "BITMAP");
640 foreach (@{$t->{ELEMENTS}}) {
641 if (ref($_->{TYPE}) eq "HASH") {
642 push (@$l, $_->{TYPE}) if (defined($_->{TYPE}->{NAME}));
643 FindNestedTypes($l, $_->{TYPE});
648 sub ParseInterface($)
658 if (not has_property($idl, "pointer_default")) {
659 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
660 # and "unique" in Microsoft Extensions mode (default)
661 $idl->{PROPERTIES}->{pointer_default} = "unique";
664 if (not has_property($idl, "pointer_default_top")) {
665 $idl->{PROPERTIES}->{pointer_default_top} = "ref";
667 warning($idl, "pointer_default_top() is a pidl extension and should not be used");
670 foreach my $d (@{$idl->{DATA}}) {
671 if ($d->{TYPE} eq "FUNCTION") {
672 push (@functions, ParseFunction($idl, $d, \$opnum));
673 } elsif ($d->{TYPE} eq "CONST") {
674 push (@consts, ParseConst($idl, $d));
676 push (@types, ParseType($d, $idl->{PROPERTIES}->{pointer_default}));
677 FindNestedTypes(\@types, $d);
683 if(defined $idl->{PROPERTIES}->{version}) {
684 $version = $idl->{PROPERTIES}->{version};
687 # If no endpoint is set, default to the interface name as a named pipe
688 if (!defined $idl->{PROPERTIES}->{endpoint}) {
689 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME} . "]\"";
691 @endpoints = split / /, $idl->{PROPERTIES}->{endpoint};
695 NAME => $idl->{NAME},
696 UUID => lc(has_property($idl, "uuid")),
699 PROPERTIES => $idl->{PROPERTIES},
700 FUNCTIONS => \@functions,
703 ENDPOINTS => \@endpoints
707 # Convert a IDL tree to a NDR tree
708 # Gives a result tree describing all that's necessary for easily generating
709 # NDR parsers / generators
714 return undef unless (defined($idl));
716 Parse::Pidl::NDR::Validate($idl);
721 ($_->{TYPE} eq "CPP_QUOTE") && push(@ndr, $_);
722 ($_->{TYPE} eq "INTERFACE") && push(@ndr, ParseInterface($_));
723 ($_->{TYPE} eq "IMPORT") && push(@ndr, $_);
736 foreach my $l (@{$e->{LEVELS}}) {
737 return $l if ($seen);
738 ($seen = 1) if ($l == $fl);
749 foreach my $l (@{$e->{LEVELS}}) {
750 (return $prev) if ($l == $fl);
757 sub ContainsString($)
761 foreach my $l (@{$e->{LEVELS}}) {
762 return 1 if ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED});
768 sub ContainsDeferred($$)
772 return 1 if ($l->{CONTAINS_DEFERRED});
774 while ($l = GetNextLevel($e,$l))
776 return 1 if ($l->{IS_DEFERRED});
777 return 1 if ($l->{CONTAINS_DEFERRED});
787 if ($e->{PARENT} && $e->{PARENT}->{NAME}) {
788 return "$e->{PARENT}->{NAME}.$e->{NAME}";
791 if ($e->{PARENT} && $e->{PARENT}->{PARENT}->{NAME}) {
792 return "$e->{PARENT}->{PARENT}->{NAME}.$e->{NAME}";
796 return "$e->{PARENT}->{NAME}.$e->{NAME}";
802 ###################################
803 # find a sibling var in a structure
807 my($fn) = $e->{PARENT};
809 if ($name =~ /\*(.*)/) {
813 for my $e2 (@{$fn->{ELEMENTS}}) {
814 return $e2 if ($e2->{NAME} eq $name);
820 my %property_list = (
822 "helpstring" => ["INTERFACE", "FUNCTION"],
823 "version" => ["INTERFACE"],
824 "uuid" => ["INTERFACE"],
825 "endpoint" => ["INTERFACE"],
826 "pointer_default" => ["INTERFACE"],
827 "pointer_default_top" => ["INTERFACE"],
828 "helper" => ["INTERFACE"],
829 "authservice" => ["INTERFACE"],
832 "object" => ["INTERFACE"],
833 "local" => ["INTERFACE", "FUNCTION"],
834 "iid_is" => ["ELEMENT"],
835 "call_as" => ["FUNCTION"],
836 "idempotent" => ["FUNCTION"],
839 "noopnum" => ["FUNCTION"],
841 "out" => ["ELEMENT"],
842 "async" => ["FUNCTION"],
845 "ref" => ["ELEMENT"],
846 "ptr" => ["ELEMENT"],
847 "unique" => ["ELEMENT"],
848 "ignore" => ["ELEMENT"],
849 "relative" => ["ELEMENT"],
850 "relative_base" => ["TYPEDEF"],
852 "gensize" => ["TYPEDEF"],
853 "value" => ["ELEMENT"],
854 "flag" => ["ELEMENT", "TYPEDEF"],
857 "public" => ["FUNCTION", "TYPEDEF"],
858 "nopush" => ["FUNCTION", "TYPEDEF"],
859 "nopull" => ["FUNCTION", "TYPEDEF"],
860 "nosize" => ["FUNCTION", "TYPEDEF"],
861 "noprint" => ["FUNCTION", "TYPEDEF"],
862 "noejs" => ["FUNCTION", "TYPEDEF"],
865 "switch_is" => ["ELEMENT"],
866 "switch_type" => ["ELEMENT", "TYPEDEF"],
867 "nodiscriminant" => ["TYPEDEF"],
868 "case" => ["ELEMENT"],
869 "default" => ["ELEMENT"],
871 "represent_as" => ["ELEMENT"],
872 "transmit_as" => ["ELEMENT"],
875 "subcontext" => ["ELEMENT"],
876 "subcontext_size" => ["ELEMENT"],
877 "compression" => ["ELEMENT"],
880 "enum8bit" => ["TYPEDEF"],
881 "enum16bit" => ["TYPEDEF"],
882 "v1_enum" => ["TYPEDEF"],
885 "bitmap8bit" => ["TYPEDEF"],
886 "bitmap16bit" => ["TYPEDEF"],
887 "bitmap32bit" => ["TYPEDEF"],
888 "bitmap64bit" => ["TYPEDEF"],
891 "range" => ["ELEMENT"],
892 "size_is" => ["ELEMENT"],
893 "string" => ["ELEMENT"],
894 "noheader" => ["ELEMENT"],
895 "charset" => ["ELEMENT"],
896 "length_is" => ["ELEMENT"],
899 #####################################################################
900 # check for unknown properties
901 sub ValidProperties($$)
905 return unless defined $e->{PROPERTIES};
907 foreach my $key (keys %{$e->{PROPERTIES}}) {
908 warning($e, el_name($e) . ": unknown property '$key'")
909 unless defined($property_list{$key});
911 fatal($e, el_name($e) . ": property '$key' not allowed on '$t'")
912 unless grep($t, @{$property_list{$key}});
920 return $t->{NAME} if (ref($t) eq "HASH" and $t->{TYPE} eq "SCALAR");
921 my $ti = getType($t);
923 if (not defined ($ti)) {
925 } elsif ($ti->{TYPE} eq "TYPEDEF") {
926 return mapToScalar($ti->{DATA});
927 } elsif ($ti->{TYPE} eq "ENUM") {
928 return Parse::Pidl::Typelist::enum_type_fn($ti);
929 } elsif ($ti->{TYPE} eq "BITMAP") {
930 return Parse::Pidl::Typelist::bitmap_type_fn($ti);
936 #####################################################################
937 # validate an element
942 ValidProperties($e,"ELEMENT");
944 # Check whether switches are used correctly.
945 if (my $switch = has_property($e, "switch_is")) {
946 my $e2 = find_sibling($e, $switch);
947 my $type = getType($e->{TYPE});
949 if (defined($type) and $type->{DATA}->{TYPE} ne "UNION") {
950 fatal($e, el_name($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
953 if (not has_property($type->{DATA}, "nodiscriminant") and defined($e2)) {
954 my $discriminator_type = has_property($type->{DATA}, "switch_type");
955 $discriminator_type = "uint32" unless defined ($discriminator_type);
957 my $t1 = mapToScalar($discriminator_type);
959 if (not defined($t1)) {
960 fatal($e, el_name($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
963 my $t2 = mapToScalar($e2->{TYPE});
964 if (not defined($t2)) {
965 fatal($e, el_name($e) . ": unable to map variable used for switch_is() to scalar");
969 warning($e, el_name($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
974 if (has_property($e, "subcontext") and has_property($e, "represent_as")) {
975 fatal($e, el_name($e) . " : subcontext() and represent_as() can not be used on the same element");
978 if (has_property($e, "subcontext") and has_property($e, "transmit_as")) {
979 fatal($e, el_name($e) . " : subcontext() and transmit_as() can not be used on the same element");
982 if (has_property($e, "represent_as") and has_property($e, "transmit_as")) {
983 fatal($e, el_name($e) . " : represent_as() and transmit_as() can not be used on the same element");
986 if (has_property($e, "represent_as") and has_property($e, "value")) {
987 fatal($e, el_name($e) . " : represent_as() and value() can not be used on the same element");
990 if (has_property($e, "subcontext")) {
991 warning($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
994 if (defined (has_property($e, "subcontext_size")) and not defined(has_property($e, "subcontext"))) {
995 fatal($e, el_name($e) . " : subcontext_size() on non-subcontext element");
998 if (defined (has_property($e, "compression")) and not defined(has_property($e, "subcontext"))) {
999 fatal($e, el_name($e) . " : compression() on non-subcontext element");
1002 if (!$e->{POINTERS} && (
1003 has_property($e, "ptr") or
1004 has_property($e, "unique") or
1005 has_property($e, "relative") or
1006 has_property($e, "ref"))) {
1007 fatal($e, el_name($e) . " : pointer properties on non-pointer element\n");
1011 #####################################################################
1017 ValidProperties($enum, "ENUM");
1020 #####################################################################
1026 ValidProperties($bitmap, "BITMAP");
1029 #####################################################################
1033 my($struct) = shift;
1035 ValidProperties($struct, "STRUCT");
1037 return unless defined($struct->{ELEMENTS});
1039 foreach my $e (@{$struct->{ELEMENTS}}) {
1040 $e->{PARENT} = $struct;
1045 #####################################################################
1051 ValidProperties($union,"UNION");
1053 if (has_property($union->{PARENT}, "nodiscriminant") and has_property($union->{PARENT}, "switch_type")) {
1054 fatal($union->{PARENT}, $union->{PARENT}->{NAME} . ": switch_type() on union without discriminant");
1057 return unless defined($union->{ELEMENTS});
1059 foreach my $e (@{$union->{ELEMENTS}}) {
1060 $e->{PARENT} = $union;
1062 if (defined($e->{PROPERTIES}->{default}) and
1063 defined($e->{PROPERTIES}->{case})) {
1064 fatal($e, "Union member $e->{NAME} can not have both default and case properties!");
1067 unless (defined ($e->{PROPERTIES}->{default}) or
1068 defined ($e->{PROPERTIES}->{case})) {
1069 fatal($e, "Union member $e->{NAME} must have default or case property");
1072 if (has_property($e, "ref")) {
1073 fatal($e, el_name($e) . " : embedded ref pointers are not supported yet\n");
1081 #####################################################################
1085 my($typedef) = shift;
1086 my $data = $typedef->{DATA};
1088 ValidProperties($typedef, "TYPEDEF");
1090 $data->{PARENT} = $typedef;
1092 ValidType($data) if (ref($data) eq "HASH");
1095 #####################################################################
1096 # validate a function
1097 sub ValidFunction($)
1101 ValidProperties($fn,"FUNCTION");
1103 foreach my $e (@{$fn->{ELEMENTS}}) {
1105 if (has_property($e, "ref") && !$e->{POINTERS}) {
1106 fatal($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1112 #####################################################################
1119 TYPEDEF => \&ValidTypedef,
1120 STRUCT => \&ValidStruct,
1121 UNION => \&ValidUnion,
1122 ENUM => \&ValidEnum,
1123 BITMAP => \&ValidBitmap
1124 }->{$t->{TYPE}}->($t);
1127 #####################################################################
1128 # parse the interface definitions
1129 sub ValidInterface($)
1131 my($interface) = shift;
1132 my($data) = $interface->{DATA};
1134 if (has_property($interface, "helper")) {
1135 warning($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1138 ValidProperties($interface,"INTERFACE");
1140 if (has_property($interface, "pointer_default")) {
1141 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1142 ("ref", "unique", "ptr"))) {
1143 fatal($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1147 if (has_property($interface, "object")) {
1148 if (has_property($interface, "version") &&
1149 $interface->{PROPERTIES}->{version} != 0) {
1150 fatal($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1153 if (!defined($interface->{BASE}) &&
1154 not ($interface->{NAME} eq "IUnknown")) {
1155 fatal($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1159 foreach my $d (@{$data}) {
1160 ($d->{TYPE} eq "FUNCTION") && ValidFunction($d);
1161 ($d->{TYPE} eq "TYPEDEF" or
1162 $d->{TYPE} eq "STRUCT" or
1163 $d->{TYPE} eq "UNION" or
1164 $d->{TYPE} eq "ENUM" or
1165 $d->{TYPE} eq "BITMAP") && ValidType($d);
1170 #####################################################################
1171 # Validate an IDL structure
1176 foreach my $x (@{$idl}) {
1177 ($x->{TYPE} eq "INTERFACE") &&
1179 ($x->{TYPE} eq "IMPORTLIB") &&
1180 fatal($x, "importlib() not supported");