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 unless (hasType($e)) {
356 # it must be an external type - all we can do is guess
357 # print "Warning: assuming alignment of unknown type '$e' is 4\n";
361 my $dt = getType($e);
363 if ($dt->{TYPE} eq "TYPEDEF") {
364 return align_type($dt->{DATA});
365 } elsif ($dt->{TYPE} eq "ENUM") {
366 return align_type(Parse::Pidl::Typelist::enum_type_fn($dt));
367 } elsif ($dt->{TYPE} eq "BITMAP") {
368 return align_type(Parse::Pidl::Typelist::bitmap_type_fn($dt));
369 } elsif (($dt->{TYPE} eq "STRUCT") or ($dt->{TYPE} eq "UNION")) {
370 return find_largest_alignment($dt);
373 die("Unknown data type type $dt->{TYPE}");
378 my ($e, $pointer_default) = @_;
380 $e->{TYPE} = expandAlias($e->{TYPE});
382 if (ref($e->{TYPE}) eq "HASH") {
383 $e->{TYPE} = ParseType($e->{TYPE}, $pointer_default);
389 PROPERTIES => $e->{PROPERTIES},
390 LEVELS => GetElementLevelTable($e),
391 REPRESENTATION_TYPE => ($e->{PROPERTIES}->{represent_as} or $e->{TYPE}),
392 ALIGN => align_type($e->{TYPE}),
399 my ($struct, $pointer_default) = @_;
401 my $surrounding = undef;
405 NAME => $struct->{NAME},
406 SURROUNDING_ELEMENT => undef,
408 PROPERTIES => $struct->{PROPERTIES},
411 } unless defined($struct->{ELEMENTS});
413 CheckPointerTypes($struct, $pointer_default);
415 foreach my $x (@{$struct->{ELEMENTS}})
417 my $e = ParseElement($x, $pointer_default);
418 if ($x != $struct->{ELEMENTS}[-1] and
419 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
420 fatal($x, "conformant member not at end of struct");
425 my $e = $elements[-1];
426 if (defined($e) and defined($e->{LEVELS}[0]->{IS_SURROUNDING}) and
427 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
431 if (defined $e->{TYPE} && $e->{TYPE} eq "string"
432 && property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
433 $surrounding = $struct->{ELEMENTS}[-1];
437 if ($struct->{NAME}) {
438 $align = align_type($struct->{NAME});
443 NAME => $struct->{NAME},
444 SURROUNDING_ELEMENT => $surrounding,
445 ELEMENTS => \@elements,
446 PROPERTIES => $struct->{PROPERTIES},
454 my ($e, $pointer_default) = @_;
457 my $switch_type = has_property($e, "switch_type");
458 unless (defined($switch_type)) { $switch_type = "uint32"; }
459 if (has_property($e, "nodiscriminant")) { $switch_type = undef; }
464 SWITCH_TYPE => $switch_type,
466 PROPERTIES => $e->{PROPERTIES},
467 HAS_DEFAULT => $hasdefault,
469 } unless defined($e->{ELEMENTS});
471 CheckPointerTypes($e, $pointer_default);
473 foreach my $x (@{$e->{ELEMENTS}})
476 if ($x->{TYPE} eq "EMPTY") {
477 $t = { TYPE => "EMPTY" };
479 $t = ParseElement($x, $pointer_default);
481 if (has_property($x, "default")) {
482 $t->{CASE} = "default";
484 } elsif (defined($x->{PROPERTIES}->{case})) {
485 $t->{CASE} = "case $x->{PROPERTIES}->{case}";
487 die("Union element $x->{NAME} has neither default nor case property");
495 SWITCH_TYPE => $switch_type,
496 ELEMENTS => \@elements,
497 PROPERTIES => $e->{PROPERTIES},
498 HAS_DEFAULT => $hasdefault,
505 my ($e, $pointer_default) = @_;
510 BASE_TYPE => Parse::Pidl::Typelist::enum_type_fn($e),
511 ELEMENTS => $e->{ELEMENTS},
512 PROPERTIES => $e->{PROPERTIES},
519 my ($e, $pointer_default) = @_;
524 BASE_TYPE => Parse::Pidl::Typelist::bitmap_type_fn($e),
525 ELEMENTS => $e->{ELEMENTS},
526 PROPERTIES => $e->{PROPERTIES},
533 my ($d, $pointer_default) = @_;
536 STRUCT => \&ParseStruct,
537 UNION => \&ParseUnion,
539 BITMAP => \&ParseBitmap,
540 TYPEDEF => \&ParseTypedef,
541 }->{$d->{TYPE}}->($d, $pointer_default);
548 my ($d, $pointer_default) = @_;
550 if (defined($d->{DATA}->{PROPERTIES}) && !defined($d->{PROPERTIES})) {
551 $d->{PROPERTIES} = $d->{DATA}->{PROPERTIES};
554 my $data = ParseType($d->{DATA}, $pointer_default);
555 $data->{ALIGN} = align_type($d->{NAME});
560 PROPERTIES => $d->{PROPERTIES},
573 sub ParseFunction($$$)
575 my ($ndr,$d,$opnum) = @_;
578 my $thisopnum = undef;
580 CheckPointerTypes($d, $ndr->{PROPERTIES}->{pointer_default_top});
582 if (not defined($d->{PROPERTIES}{noopnum})) {
583 $thisopnum = ${$opnum};
587 foreach my $x (@{$d->{ELEMENTS}}) {
588 my $e = ParseElement($x, $ndr->{PROPERTIES}->{pointer_default});
589 push (@{$e->{DIRECTION}}, "in") if (has_property($x, "in"));
590 push (@{$e->{DIRECTION}}, "out") if (has_property($x, "out"));
592 push (@elements, $e);
595 if ($d->{RETURN_TYPE} ne "void") {
596 $rettype = expandAlias($d->{RETURN_TYPE});
600 if (has_property($d, "async")) { $async = 1; }
607 RETURN_TYPE => $rettype,
608 PROPERTIES => $d->{PROPERTIES},
609 ELEMENTS => \@elements,
614 sub CheckPointerTypes($$)
616 my ($s,$default) = @_;
618 return unless defined($s->{ELEMENTS});
620 foreach my $e (@{$s->{ELEMENTS}}) {
621 if ($e->{POINTERS} and not defined(pointer_type($e))) {
622 $e->{PROPERTIES}->{$default} = 1;
627 sub FindNestedTypes($$)
629 sub FindNestedTypes($$);
632 return if not defined($t->{ELEMENTS});
633 return if ($t->{TYPE} eq "ENUM");
634 return if ($t->{TYPE} eq "BITMAP");
636 foreach (@{$t->{ELEMENTS}}) {
637 if (ref($_->{TYPE}) eq "HASH") {
638 push (@$l, $_->{TYPE}) if (defined($_->{TYPE}->{NAME}));
639 FindNestedTypes($l, $_->{TYPE});
644 sub ParseInterface($)
654 if (not has_property($idl, "pointer_default")) {
655 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
656 # and "unique" in Microsoft Extensions mode (default)
657 $idl->{PROPERTIES}->{pointer_default} = "unique";
660 if (not has_property($idl, "pointer_default_top")) {
661 $idl->{PROPERTIES}->{pointer_default_top} = "ref";
663 warning($idl, "pointer_default_top() is a pidl extension and should not be used");
666 foreach my $d (@{$idl->{DATA}}) {
667 if ($d->{TYPE} eq "FUNCTION") {
668 push (@functions, ParseFunction($idl, $d, \$opnum));
669 } elsif ($d->{TYPE} eq "CONST") {
670 push (@consts, ParseConst($idl, $d));
672 push (@types, ParseType($d, $idl->{PROPERTIES}->{pointer_default}));
673 FindNestedTypes(\@types, $d);
679 if(defined $idl->{PROPERTIES}->{version}) {
680 $version = $idl->{PROPERTIES}->{version};
683 # If no endpoint is set, default to the interface name as a named pipe
684 if (!defined $idl->{PROPERTIES}->{endpoint}) {
685 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME} . "]\"";
687 @endpoints = split / /, $idl->{PROPERTIES}->{endpoint};
691 NAME => $idl->{NAME},
692 UUID => lc(has_property($idl, "uuid")),
695 PROPERTIES => $idl->{PROPERTIES},
696 FUNCTIONS => \@functions,
699 ENDPOINTS => \@endpoints
703 # Convert a IDL tree to a NDR tree
704 # Gives a result tree describing all that's necessary for easily generating
705 # NDR parsers / generators
710 return undef unless (defined($idl));
712 Parse::Pidl::NDR::Validate($idl);
717 ($_->{TYPE} eq "CPP_QUOTE") && push(@ndr, $_);
718 ($_->{TYPE} eq "INTERFACE") && push(@ndr, ParseInterface($_));
719 ($_->{TYPE} eq "IMPORT") && push(@ndr, $_);
732 foreach my $l (@{$e->{LEVELS}}) {
733 return $l if ($seen);
734 ($seen = 1) if ($l == $fl);
745 foreach my $l (@{$e->{LEVELS}}) {
746 (return $prev) if ($l == $fl);
753 sub ContainsString($)
757 foreach my $l (@{$e->{LEVELS}}) {
758 return 1 if ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED});
764 sub ContainsDeferred($$)
768 return 1 if ($l->{CONTAINS_DEFERRED});
770 while ($l = GetNextLevel($e,$l))
772 return 1 if ($l->{IS_DEFERRED});
773 return 1 if ($l->{CONTAINS_DEFERRED});
783 if ($e->{PARENT} && $e->{PARENT}->{NAME}) {
784 return "$e->{PARENT}->{NAME}.$e->{NAME}";
787 if ($e->{PARENT} && $e->{PARENT}->{PARENT}->{NAME}) {
788 return "$e->{PARENT}->{PARENT}->{NAME}.$e->{NAME}";
792 return "$e->{PARENT}->{NAME}.$e->{NAME}";
798 ###################################
799 # find a sibling var in a structure
803 my($fn) = $e->{PARENT};
805 if ($name =~ /\*(.*)/) {
809 for my $e2 (@{$fn->{ELEMENTS}}) {
810 return $e2 if ($e2->{NAME} eq $name);
816 my %property_list = (
818 "helpstring" => ["INTERFACE", "FUNCTION"],
819 "version" => ["INTERFACE"],
820 "uuid" => ["INTERFACE"],
821 "endpoint" => ["INTERFACE"],
822 "pointer_default" => ["INTERFACE"],
823 "pointer_default_top" => ["INTERFACE"],
824 "helper" => ["INTERFACE"],
825 "authservice" => ["INTERFACE"],
828 "object" => ["INTERFACE"],
829 "local" => ["INTERFACE", "FUNCTION"],
830 "iid_is" => ["ELEMENT"],
831 "call_as" => ["FUNCTION"],
832 "idempotent" => ["FUNCTION"],
835 "noopnum" => ["FUNCTION"],
837 "out" => ["ELEMENT"],
838 "async" => ["FUNCTION"],
841 "ref" => ["ELEMENT"],
842 "ptr" => ["ELEMENT"],
843 "unique" => ["ELEMENT"],
844 "ignore" => ["ELEMENT"],
845 "relative" => ["ELEMENT"],
846 "relative_base" => ["TYPEDEF"],
848 "gensize" => ["TYPEDEF"],
849 "value" => ["ELEMENT"],
850 "flag" => ["ELEMENT", "TYPEDEF"],
853 "public" => ["FUNCTION", "TYPEDEF"],
854 "nopush" => ["FUNCTION", "TYPEDEF"],
855 "nopull" => ["FUNCTION", "TYPEDEF"],
856 "nosize" => ["FUNCTION", "TYPEDEF"],
857 "noprint" => ["FUNCTION", "TYPEDEF"],
858 "noejs" => ["FUNCTION", "TYPEDEF"],
861 "switch_is" => ["ELEMENT"],
862 "switch_type" => ["ELEMENT", "TYPEDEF"],
863 "nodiscriminant" => ["TYPEDEF"],
864 "case" => ["ELEMENT"],
865 "default" => ["ELEMENT"],
867 "represent_as" => ["ELEMENT"],
868 "transmit_as" => ["ELEMENT"],
871 "subcontext" => ["ELEMENT"],
872 "subcontext_size" => ["ELEMENT"],
873 "compression" => ["ELEMENT"],
876 "enum8bit" => ["TYPEDEF"],
877 "enum16bit" => ["TYPEDEF"],
878 "v1_enum" => ["TYPEDEF"],
881 "bitmap8bit" => ["TYPEDEF"],
882 "bitmap16bit" => ["TYPEDEF"],
883 "bitmap32bit" => ["TYPEDEF"],
884 "bitmap64bit" => ["TYPEDEF"],
887 "range" => ["ELEMENT"],
888 "size_is" => ["ELEMENT"],
889 "string" => ["ELEMENT"],
890 "noheader" => ["ELEMENT"],
891 "charset" => ["ELEMENT"],
892 "length_is" => ["ELEMENT"],
895 #####################################################################
896 # check for unknown properties
897 sub ValidProperties($$)
901 return unless defined $e->{PROPERTIES};
903 foreach my $key (keys %{$e->{PROPERTIES}}) {
904 warning($e, el_name($e) . ": unknown property '$key'")
905 unless defined($property_list{$key});
907 fatal($e, el_name($e) . ": property '$key' not allowed on '$t'")
908 unless grep($t, @{$property_list{$key}});
916 return $t->{NAME} if (ref($t) eq "HASH" and $t->{TYPE} eq "SCALAR");
917 my $ti = getType($t);
919 if (not defined ($ti)) {
921 } elsif ($ti->{TYPE} eq "TYPEDEF") {
922 return mapToScalar($ti->{DATA});
923 } elsif ($ti->{TYPE} eq "ENUM") {
924 return Parse::Pidl::Typelist::enum_type_fn($ti);
925 } elsif ($ti->{TYPE} eq "BITMAP") {
926 return Parse::Pidl::Typelist::bitmap_type_fn($ti);
932 #####################################################################
933 # validate an element
938 ValidProperties($e,"ELEMENT");
940 # Check whether switches are used correctly.
941 if (my $switch = has_property($e, "switch_is")) {
942 my $e2 = find_sibling($e, $switch);
943 my $type = getType($e->{TYPE});
945 if (defined($type) and $type->{DATA}->{TYPE} ne "UNION") {
946 fatal($e, el_name($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
949 if (not has_property($type->{DATA}, "nodiscriminant") and defined($e2)) {
950 my $discriminator_type = has_property($type->{DATA}, "switch_type");
951 $discriminator_type = "uint32" unless defined ($discriminator_type);
953 my $t1 = mapToScalar($discriminator_type);
955 if (not defined($t1)) {
956 fatal($e, el_name($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
959 my $t2 = mapToScalar($e2->{TYPE});
960 if (not defined($t2)) {
961 fatal($e, el_name($e) . ": unable to map variable used for switch_is() to scalar");
965 warning($e, el_name($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
970 if (has_property($e, "subcontext") and has_property($e, "represent_as")) {
971 fatal($e, el_name($e) . " : subcontext() and represent_as() can not be used on the same element");
974 if (has_property($e, "subcontext") and has_property($e, "transmit_as")) {
975 fatal($e, el_name($e) . " : subcontext() and transmit_as() can not be used on the same element");
978 if (has_property($e, "represent_as") and has_property($e, "transmit_as")) {
979 fatal($e, el_name($e) . " : represent_as() and transmit_as() can not be used on the same element");
982 if (has_property($e, "represent_as") and has_property($e, "value")) {
983 fatal($e, el_name($e) . " : represent_as() and value() can not be used on the same element");
986 if (has_property($e, "subcontext")) {
987 warning($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
990 if (defined (has_property($e, "subcontext_size")) and not defined(has_property($e, "subcontext"))) {
991 fatal($e, el_name($e) . " : subcontext_size() on non-subcontext element");
994 if (defined (has_property($e, "compression")) and not defined(has_property($e, "subcontext"))) {
995 fatal($e, el_name($e) . " : compression() on non-subcontext element");
998 if (!$e->{POINTERS} && (
999 has_property($e, "ptr") or
1000 has_property($e, "unique") or
1001 has_property($e, "relative") or
1002 has_property($e, "ref"))) {
1003 fatal($e, el_name($e) . " : pointer properties on non-pointer element\n");
1007 #####################################################################
1013 ValidProperties($enum, "ENUM");
1016 #####################################################################
1022 ValidProperties($bitmap, "BITMAP");
1025 #####################################################################
1029 my($struct) = shift;
1031 ValidProperties($struct, "STRUCT");
1033 return unless defined($struct->{ELEMENTS});
1035 foreach my $e (@{$struct->{ELEMENTS}}) {
1036 $e->{PARENT} = $struct;
1041 #####################################################################
1047 ValidProperties($union,"UNION");
1049 if (has_property($union->{PARENT}, "nodiscriminant") and has_property($union->{PARENT}, "switch_type")) {
1050 fatal($union->{PARENT}, $union->{PARENT}->{NAME} . ": switch_type() on union without discriminant");
1053 return unless defined($union->{ELEMENTS});
1055 foreach my $e (@{$union->{ELEMENTS}}) {
1056 $e->{PARENT} = $union;
1058 if (defined($e->{PROPERTIES}->{default}) and
1059 defined($e->{PROPERTIES}->{case})) {
1060 fatal($e, "Union member $e->{NAME} can not have both default and case properties!");
1063 unless (defined ($e->{PROPERTIES}->{default}) or
1064 defined ($e->{PROPERTIES}->{case})) {
1065 fatal($e, "Union member $e->{NAME} must have default or case property");
1068 if (has_property($e, "ref")) {
1069 fatal($e, el_name($e) . " : embedded ref pointers are not supported yet\n");
1077 #####################################################################
1081 my($typedef) = shift;
1082 my $data = $typedef->{DATA};
1084 ValidProperties($typedef, "TYPEDEF");
1086 $data->{PARENT} = $typedef;
1088 ValidType($data) if (ref($data) eq "HASH");
1091 #####################################################################
1092 # validate a function
1093 sub ValidFunction($)
1097 ValidProperties($fn,"FUNCTION");
1099 foreach my $e (@{$fn->{ELEMENTS}}) {
1101 if (has_property($e, "ref") && !$e->{POINTERS}) {
1102 fatal($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1108 #####################################################################
1115 TYPEDEF => \&ValidTypedef,
1116 STRUCT => \&ValidStruct,
1117 UNION => \&ValidUnion,
1118 ENUM => \&ValidEnum,
1119 BITMAP => \&ValidBitmap
1120 }->{$t->{TYPE}}->($t);
1123 #####################################################################
1124 # parse the interface definitions
1125 sub ValidInterface($)
1127 my($interface) = shift;
1128 my($data) = $interface->{DATA};
1130 if (has_property($interface, "helper")) {
1131 warning($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1134 ValidProperties($interface,"INTERFACE");
1136 if (has_property($interface, "pointer_default")) {
1137 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1138 ("ref", "unique", "ptr"))) {
1139 fatal($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1143 if (has_property($interface, "object")) {
1144 if (has_property($interface, "version") &&
1145 $interface->{PROPERTIES}->{version} != 0) {
1146 fatal($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1149 if (!defined($interface->{BASE}) &&
1150 not ($interface->{NAME} eq "IUnknown")) {
1151 fatal($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1155 foreach my $d (@{$data}) {
1156 ($d->{TYPE} eq "FUNCTION") && ValidFunction($d);
1157 ($d->{TYPE} eq "TYPEDEF" or
1158 $d->{TYPE} eq "STRUCT" or
1159 $d->{TYPE} eq "UNION" or
1160 $d->{TYPE} eq "ENUM" or
1161 $d->{TYPE} eq "BITMAP") && ValidType($d);
1166 #####################################################################
1167 # Validate an IDL structure
1172 foreach my $x (@{$idl}) {
1173 ($x->{TYPE} eq "INTERFACE") &&
1175 ($x->{TYPE} eq "IMPORTLIB") &&
1176 fatal($x, "importlib() not supported");