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);
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;
119 if ($size = shift @size_is) {
120 } elsif ((scalar(@size_is) == 0) and has_property($e, "string")) {
122 delete($e->{PROPERTIES}->{string});
124 fatal($e, "Must specify size_is() for conformant array!")
127 if (($length = shift @length_is) or $is_string) {
133 if ($e == $e->{PARENT}->{ELEMENTS}[-1]
134 and $e->{PARENT}->{TYPE} ne "FUNCTION") {
142 LENGTH_IS => $length,
143 IS_DEFERRED => "$is_deferred",
144 IS_SURROUNDING => "$is_surrounding",
145 IS_ZERO_TERMINATED => "$is_string",
146 IS_VARYING => "$is_varying",
147 IS_CONFORMANT => "$is_conformant",
148 IS_FIXED => (not $is_conformant and Parse::Pidl::Util::is_constant($size)),
149 IS_INLINE => (not $is_conformant and not Parse::Pidl::Util::is_constant($size))
153 # Next, all the pointers
154 foreach my $i (1..$e->{POINTERS}) {
155 my $pt = pointer_type($e);
157 my $level = "EMBEDDED";
158 # Top level "ref" pointers do not have a referrent identifier
159 $level = "TOP" if ( defined($pt)
161 and $e->{PARENT}->{TYPE} eq "FUNCTION");
165 # for now, there can only be one pointer type per element
166 POINTER_TYPE => pointer_type($e),
167 POINTER_INDEX => $pointer_idx,
168 IS_DEFERRED => "$is_deferred",
172 warning($e, "top-level \[out\] pointer `$e->{NAME}' is not a \[ref\] pointer")
173 if ($i == 1 and pointer_type($e) ne "ref" and
174 $e->{PARENT}->{TYPE} eq "FUNCTION" and
175 not has_property($e, "in"));
179 # everything that follows will be deferred
180 $is_deferred = 1 if ($e->{PARENT}->{TYPE} ne "FUNCTION");
182 my $array_size = shift @size_is;
189 if ($array_length = shift @length_is) {
192 $array_length = $array_size;
197 if (scalar(@size_is) == 0 and has_property($e, "string") and
198 $i == $e->{POINTERS}) {
200 $is_varying = $is_conformant = has_property($e, "noheader")?0:1;
201 delete($e->{PROPERTIES}->{string});
204 if ($array_size or $is_string) {
207 IS_ZERO_TERMINATED => "$is_string",
208 SIZE_IS => $array_size,
209 LENGTH_IS => $array_length,
210 IS_DEFERRED => "$is_deferred",
212 IS_VARYING => "$is_varying",
213 IS_CONFORMANT => "$is_conformant",
222 if (defined(has_property($e, "subcontext"))) {
223 my $hdr_size = has_property($e, "subcontext");
224 my $subsize = has_property($e, "subcontext_size");
225 if (not defined($subsize)) {
230 TYPE => "SUBCONTEXT",
231 HEADER_SIZE => $hdr_size,
232 SUBCONTEXT_SIZE => $subsize,
233 IS_DEFERRED => $is_deferred,
234 COMPRESSION => has_property($e, "compression"),
238 if (my $switch = has_property($e, "switch_is")) {
241 SWITCH_IS => $switch,
242 IS_DEFERRED => $is_deferred
246 if (scalar(@size_is) > 0) {
247 warning($e, "size_is() on non-array element");
250 if (scalar(@length_is) > 0) {
251 warning($e, "length_is() on non-array element");
254 if (has_property($e, "string")) {
255 warning($e, "string() attribute on non-array element");
260 DATA_TYPE => $e->{TYPE},
261 IS_DEFERRED => $is_deferred,
262 CONTAINS_DEFERRED => can_contain_deferred($e),
263 IS_SURROUNDING => 0 #FIXME
267 foreach (@$order) { $_->{LEVEL_INDEX} = $i; $i+=1; }
272 #####################################################################
273 # see if a type contains any deferred data
274 sub can_contain_deferred
278 return 0 if (Parse::Pidl::Typelist::is_scalar($e->{TYPE}));
279 return 1 unless (hasType($e->{TYPE})); # assume the worst
281 my $type = getType($e->{TYPE});
283 foreach my $x (@{$type->{DATA}->{ELEMENTS}}) {
284 return 1 if ($x->{POINTERS});
285 return 1 if (can_contain_deferred ($x));
295 return undef unless $e->{POINTERS};
297 return "ref" if (has_property($e, "ref"));
298 return "full" if (has_property($e, "ptr"));
299 return "sptr" if (has_property($e, "sptr"));
300 return "unique" if (has_property($e, "unique"));
301 return "relative" if (has_property($e, "relative"));
302 return "ignore" if (has_property($e, "ignore"));
307 #####################################################################
308 # work out the correct alignment for a structure or union
309 sub find_largest_alignment($)
314 for my $e (@{$s->{ELEMENTS}}) {
317 if ($e->{POINTERS}) {
319 } elsif (has_property($e, "subcontext")) {
321 } elsif (has_property($e, "transmit_as")) {
322 $a = align_type($e->{PROPERTIES}->{transmit_as});
324 $a = align_type($e->{TYPE});
327 $align = $a if ($align < $a);
333 #####################################################################
340 unless (hasType($e)) {
341 # it must be an external type - all we can do is guess
342 # print "Warning: assuming alignment of unknown type '$e' is 4\n";
346 my $dt = getType($e)->{DATA};
348 if ($dt->{TYPE} eq "ENUM") {
349 return align_type(Parse::Pidl::Typelist::enum_type_fn($dt));
350 } elsif ($dt->{TYPE} eq "BITMAP") {
351 return align_type(Parse::Pidl::Typelist::bitmap_type_fn($dt));
352 } elsif (($dt->{TYPE} eq "STRUCT") or ($dt->{TYPE} eq "UNION")) {
353 return find_largest_alignment($dt);
354 } elsif ($dt->{TYPE} eq "SCALAR") {
355 return $scalar_alignment->{$dt->{NAME}};
358 die("Unknown data type type $dt->{TYPE}");
363 my ($e, $pointer_default) = @_;
365 $e->{TYPE} = expandAlias($e->{TYPE});
367 if (ref($e->{TYPE}) eq "HASH") {
368 $e->{TYPE} = ParseType($e->{TYPE}, $pointer_default);
374 PROPERTIES => $e->{PROPERTIES},
375 LEVELS => GetElementLevelTable($e),
376 REPRESENTATION_TYPE => ($e->{PROPERTIES}->{represent_as} or $e->{TYPE}),
377 ALIGN => align_type($e->{TYPE}),
384 my ($struct, $pointer_default) = @_;
386 my $surrounding = undef;
388 foreach my $x (@{$struct->{ELEMENTS}})
390 my $e = ParseElement($x, $pointer_default);
391 if ($x != $struct->{ELEMENTS}[-1] and
392 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
393 fatal($x, "conformant member not at end of struct");
398 my $e = $elements[-1];
399 if (defined($e) and defined($e->{LEVELS}[0]->{IS_SURROUNDING}) and
400 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
404 if (defined $e->{TYPE} && $e->{TYPE} eq "string"
405 && property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
406 $surrounding = $struct->{ELEMENTS}[-1];
410 if ($struct->{NAME}) {
411 $align = align_type($struct->{NAME});
416 NAME => $struct->{NAME},
417 SURROUNDING_ELEMENT => $surrounding,
418 ELEMENTS => \@elements,
419 PROPERTIES => $struct->{PROPERTIES},
427 my ($e, $pointer_default) = @_;
429 my $switch_type = has_property($e, "switch_type");
430 unless (defined($switch_type)) { $switch_type = "uint32"; }
432 if (has_property($e, "nodiscriminant")) { $switch_type = undef; }
435 foreach my $x (@{$e->{ELEMENTS}})
438 if ($x->{TYPE} eq "EMPTY") {
439 $t = { TYPE => "EMPTY" };
441 $t = ParseElement($x, $pointer_default);
443 if (has_property($x, "default")) {
444 $t->{CASE} = "default";
446 } elsif (defined($x->{PROPERTIES}->{case})) {
447 $t->{CASE} = "case $x->{PROPERTIES}->{case}";
449 die("Union element $x->{NAME} has neither default nor case property");
457 SWITCH_TYPE => $switch_type,
458 ELEMENTS => \@elements,
459 PROPERTIES => $e->{PROPERTIES},
460 HAS_DEFAULT => $hasdefault,
467 my ($e, $pointer_default) = @_;
472 BASE_TYPE => Parse::Pidl::Typelist::enum_type_fn($e),
473 ELEMENTS => $e->{ELEMENTS},
474 PROPERTIES => $e->{PROPERTIES},
481 my ($e, $pointer_default) = @_;
486 BASE_TYPE => Parse::Pidl::Typelist::bitmap_type_fn($e),
487 ELEMENTS => $e->{ELEMENTS},
488 PROPERTIES => $e->{PROPERTIES},
495 my ($d, $pointer_default) = @_;
497 if ($d->{TYPE} eq "STRUCT" or $d->{TYPE} eq "UNION") {
498 CheckPointerTypes($d, $pointer_default);
502 STRUCT => \&ParseStruct,
503 UNION => \&ParseUnion,
505 BITMAP => \&ParseBitmap,
506 TYPEDEF => \&ParseTypedef,
507 }->{$d->{TYPE}}->($d, $pointer_default);
514 my ($d, $pointer_default) = @_;
516 if (defined($d->{DATA}->{PROPERTIES}) && !defined($d->{PROPERTIES})) {
517 $d->{PROPERTIES} = $d->{DATA}->{PROPERTIES};
520 my $data = ParseType($d->{DATA}, $pointer_default);
521 $data->{ALIGN} = align_type($d->{NAME});
526 PROPERTIES => $d->{PROPERTIES},
539 sub ParseFunction($$$)
541 my ($ndr,$d,$opnum) = @_;
544 my $thisopnum = undef;
546 CheckPointerTypes($d, $ndr->{PROPERTIES}->{pointer_default_top});
548 if (not defined($d->{PROPERTIES}{noopnum})) {
549 $thisopnum = ${$opnum};
553 foreach my $x (@{$d->{ELEMENTS}}) {
554 my $e = ParseElement($x, $ndr->{PROPERTIES}->{pointer_default});
555 push (@{$e->{DIRECTION}}, "in") if (has_property($x, "in"));
556 push (@{$e->{DIRECTION}}, "out") if (has_property($x, "out"));
558 push (@elements, $e);
561 if ($d->{RETURN_TYPE} ne "void") {
562 $rettype = expandAlias($d->{RETURN_TYPE});
566 if (has_property($d, "async")) { $async = 1; }
573 RETURN_TYPE => $rettype,
574 PROPERTIES => $d->{PROPERTIES},
575 ELEMENTS => \@elements,
580 sub CheckPointerTypes($$)
582 my ($s,$default) = @_;
584 foreach my $e (@{$s->{ELEMENTS}}) {
585 if ($e->{POINTERS} and not defined(pointer_type($e))) {
586 $e->{PROPERTIES}->{$default} = 1;
591 sub FindNestedTypes($$)
593 sub FindNestedTypes($$);
596 return if not defined($t->{ELEMENTS});
598 foreach (@{$t->{ELEMENTS}}) {
599 if (ref($_->{TYPE}) eq "HASH") {
600 push (@$l, $_->{TYPE}) if (defined($_->{TYPE}->{NAME}));
601 FindNestedTypes($l, $_->{TYPE});
606 sub ParseInterface($)
617 if (not has_property($idl, "pointer_default")) {
618 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
619 # and "unique" in Microsoft Extensions mode (default)
620 $idl->{PROPERTIES}->{pointer_default} = "unique";
623 if (not has_property($idl, "pointer_default_top")) {
624 $idl->{PROPERTIES}->{pointer_default_top} = "ref";
626 warning($idl, "pointer_default_top() is a pidl extension and should not be used");
629 foreach my $d (@{$idl->{DATA}}) {
630 if ($d->{TYPE} eq "DECLARE") {
631 push (@declares, $d);
632 } elsif ($d->{TYPE} eq "FUNCTION") {
633 push (@functions, ParseFunction($idl, $d, \$opnum));
634 } elsif ($d->{TYPE} eq "CONST") {
635 push (@consts, ParseConst($idl, $d));
637 push (@types, ParseType($d, $idl->{PROPERTIES}->{pointer_default}));
638 FindNestedTypes(\@types, $d);
644 if(defined $idl->{PROPERTIES}->{version}) {
645 $version = $idl->{PROPERTIES}->{version};
648 # If no endpoint is set, default to the interface name as a named pipe
649 if (!defined $idl->{PROPERTIES}->{endpoint}) {
650 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME} . "]\"";
652 @endpoints = split / /, $idl->{PROPERTIES}->{endpoint};
656 NAME => $idl->{NAME},
657 UUID => lc(has_property($idl, "uuid")),
660 PROPERTIES => $idl->{PROPERTIES},
661 FUNCTIONS => \@functions,
664 DECLARES => \@declares,
665 ENDPOINTS => \@endpoints
669 # Convert a IDL tree to a NDR tree
670 # Gives a result tree describing all that's necessary for easily generating
671 # NDR parsers / generators
676 return undef unless (defined($idl));
678 Parse::Pidl::NDR::Validate($idl);
683 ($_->{TYPE} eq "INTERFACE") && push(@ndr, ParseInterface($_));
684 ($_->{TYPE} eq "IMPORT") && push(@ndr, $_);
697 foreach my $l (@{$e->{LEVELS}}) {
698 return $l if ($seen);
699 ($seen = 1) if ($l == $fl);
710 foreach my $l (@{$e->{LEVELS}}) {
711 (return $prev) if ($l == $fl);
718 sub ContainsString($)
722 foreach my $l (@{$e->{LEVELS}}) {
723 return 1 if ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED});
729 sub ContainsDeferred($$)
733 return 1 if ($l->{CONTAINS_DEFERRED});
735 while ($l = GetNextLevel($e,$l))
737 return 1 if ($l->{IS_DEFERRED});
738 return 1 if ($l->{CONTAINS_DEFERRED});
748 if ($e->{PARENT} && $e->{PARENT}->{NAME}) {
749 return "$e->{PARENT}->{NAME}.$e->{NAME}";
752 if ($e->{PARENT} && $e->{PARENT}->{PARENT}->{NAME}) {
753 return "$e->{PARENT}->{PARENT}->{NAME}.$e->{NAME}";
757 return "$e->{PARENT}->{NAME}.$e->{NAME}";
763 ###################################
764 # find a sibling var in a structure
768 my($fn) = $e->{PARENT};
770 if ($name =~ /\*(.*)/) {
774 for my $e2 (@{$fn->{ELEMENTS}}) {
775 return $e2 if ($e2->{NAME} eq $name);
781 my %property_list = (
783 "helpstring" => ["INTERFACE", "FUNCTION"],
784 "version" => ["INTERFACE"],
785 "uuid" => ["INTERFACE"],
786 "endpoint" => ["INTERFACE"],
787 "pointer_default" => ["INTERFACE"],
788 "pointer_default_top" => ["INTERFACE"],
789 "helper" => ["INTERFACE"],
790 "authservice" => ["INTERFACE"],
793 "object" => ["INTERFACE"],
794 "local" => ["INTERFACE", "FUNCTION"],
795 "iid_is" => ["ELEMENT"],
796 "call_as" => ["FUNCTION"],
797 "idempotent" => ["FUNCTION"],
800 "noopnum" => ["FUNCTION"],
802 "out" => ["ELEMENT"],
803 "async" => ["FUNCTION"],
806 "ref" => ["ELEMENT"],
807 "ptr" => ["ELEMENT"],
808 "unique" => ["ELEMENT"],
809 "ignore" => ["ELEMENT"],
810 "relative" => ["ELEMENT"],
811 "relative_base" => ["TYPEDEF"],
813 "gensize" => ["TYPEDEF"],
814 "value" => ["ELEMENT"],
815 "flag" => ["ELEMENT", "TYPEDEF"],
818 "public" => ["FUNCTION", "TYPEDEF"],
819 "nopush" => ["FUNCTION", "TYPEDEF"],
820 "nopull" => ["FUNCTION", "TYPEDEF"],
821 "nosize" => ["FUNCTION", "TYPEDEF"],
822 "noprint" => ["FUNCTION", "TYPEDEF"],
823 "noejs" => ["FUNCTION", "TYPEDEF"],
826 "switch_is" => ["ELEMENT"],
827 "switch_type" => ["ELEMENT", "TYPEDEF"],
828 "nodiscriminant" => ["TYPEDEF"],
829 "case" => ["ELEMENT"],
830 "default" => ["ELEMENT"],
832 "represent_as" => ["ELEMENT"],
833 "transmit_as" => ["ELEMENT"],
836 "subcontext" => ["ELEMENT"],
837 "subcontext_size" => ["ELEMENT"],
838 "compression" => ["ELEMENT"],
841 "enum8bit" => ["TYPEDEF"],
842 "enum16bit" => ["TYPEDEF"],
843 "v1_enum" => ["TYPEDEF"],
846 "bitmap8bit" => ["TYPEDEF"],
847 "bitmap16bit" => ["TYPEDEF"],
848 "bitmap32bit" => ["TYPEDEF"],
849 "bitmap64bit" => ["TYPEDEF"],
852 "range" => ["ELEMENT"],
853 "size_is" => ["ELEMENT"],
854 "string" => ["ELEMENT"],
855 "noheader" => ["ELEMENT"],
856 "charset" => ["ELEMENT"],
857 "length_is" => ["ELEMENT"],
860 #####################################################################
861 # check for unknown properties
862 sub ValidProperties($$)
866 return unless defined $e->{PROPERTIES};
868 foreach my $key (keys %{$e->{PROPERTIES}}) {
869 warning($e, el_name($e) . ": unknown property '$key'")
870 unless defined($property_list{$key});
872 fatal($e, el_name($e) . ": property '$key' not allowed on '$t'")
873 unless grep($t, @{$property_list{$key}});
880 my $ti = getType($t);
882 if (not defined ($ti)) {
884 } elsif ($ti->{DATA}->{TYPE} eq "ENUM") {
885 return Parse::Pidl::Typelist::enum_type_fn($ti->{DATA});
886 } elsif ($ti->{DATA}->{TYPE} eq "BITMAP") {
887 return Parse::Pidl::Typelist::enum_type_fn($ti->{DATA});
888 } elsif ($ti->{DATA}->{TYPE} eq "SCALAR") {
895 #####################################################################
896 # validate an element
901 ValidProperties($e,"ELEMENT");
903 # Check whether switches are used correctly.
904 if (my $switch = has_property($e, "switch_is")) {
905 my $e2 = find_sibling($e, $switch);
906 my $type = getType($e->{TYPE});
908 if (defined($type) and $type->{DATA}->{TYPE} ne "UNION") {
909 fatal($e, el_name($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
912 if (not has_property($type->{DATA}, "nodiscriminant") and defined($e2)) {
913 my $discriminator_type = has_property($type->{DATA}, "switch_type");
914 $discriminator_type = "uint32" unless defined ($discriminator_type);
916 my $t1 = mapToScalar($discriminator_type);
918 if (not defined($t1)) {
919 fatal($e, el_name($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
922 my $t2 = mapToScalar($e2->{TYPE});
923 if (not defined($t2)) {
924 fatal($e, el_name($e) . ": unable to map variable used for switch_is() to scalar");
928 warning($e, el_name($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
933 if (has_property($e, "subcontext") and has_property($e, "represent_as")) {
934 fatal($e, el_name($e) . " : subcontext() and represent_as() can not be used on the same element");
937 if (has_property($e, "subcontext") and has_property($e, "transmit_as")) {
938 fatal($e, el_name($e) . " : subcontext() and transmit_as() can not be used on the same element");
941 if (has_property($e, "represent_as") and has_property($e, "transmit_as")) {
942 fatal($e, el_name($e) . " : represent_as() and transmit_as() can not be used on the same element");
945 if (has_property($e, "represent_as") and has_property($e, "value")) {
946 fatal($e, el_name($e) . " : represent_as() and value() can not be used on the same element");
949 if (has_property($e, "subcontext")) {
950 warning($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
953 if (defined (has_property($e, "subcontext_size")) and not defined(has_property($e, "subcontext"))) {
954 fatal($e, el_name($e) . " : subcontext_size() on non-subcontext element");
957 if (defined (has_property($e, "compression")) and not defined(has_property($e, "subcontext"))) {
958 fatal($e, el_name($e) . " : compression() on non-subcontext element");
961 if (!$e->{POINTERS} && (
962 has_property($e, "ptr") or
963 has_property($e, "unique") or
964 has_property($e, "relative") or
965 has_property($e, "ref"))) {
966 fatal($e, el_name($e) . " : pointer properties on non-pointer element\n");
970 #####################################################################
976 ValidProperties($enum, "ENUM");
979 #####################################################################
985 ValidProperties($bitmap, "BITMAP");
988 #####################################################################
994 ValidProperties($struct, "STRUCT");
996 foreach my $e (@{$struct->{ELEMENTS}}) {
997 $e->{PARENT} = $struct;
1002 #####################################################################
1008 ValidProperties($union,"UNION");
1010 if (has_property($union->{PARENT}, "nodiscriminant") and has_property($union->{PARENT}, "switch_type")) {
1011 fatal($union->{PARENT}, $union->{PARENT}->{NAME} . ": switch_type() on union without discriminant");
1014 foreach my $e (@{$union->{ELEMENTS}}) {
1015 $e->{PARENT} = $union;
1017 if (defined($e->{PROPERTIES}->{default}) and
1018 defined($e->{PROPERTIES}->{case})) {
1019 fatal($e, "Union member $e->{NAME} can not have both default and case properties!");
1022 unless (defined ($e->{PROPERTIES}->{default}) or
1023 defined ($e->{PROPERTIES}->{case})) {
1024 fatal($e, "Union member $e->{NAME} must have default or case property");
1027 if (has_property($e, "ref")) {
1028 fatal($e, el_name($e) . " : embedded ref pointers are not supported yet\n");
1036 #####################################################################
1040 my($typedef) = shift;
1041 my $data = $typedef->{DATA};
1043 ValidProperties($typedef, "TYPEDEF");
1045 $data->{PARENT} = $typedef;
1047 ValidType($data) if (ref($data) eq "HASH");
1050 #####################################################################
1051 # validate a function
1052 sub ValidFunction($)
1056 ValidProperties($fn,"FUNCTION");
1058 foreach my $e (@{$fn->{ELEMENTS}}) {
1060 if (has_property($e, "ref") && !$e->{POINTERS}) {
1061 fatal($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1067 #####################################################################
1074 TYPEDEF => \&ValidTypedef,
1075 STRUCT => \&ValidStruct,
1076 UNION => \&ValidUnion,
1077 ENUM => \&ValidEnum,
1078 BITMAP => \&ValidBitmap
1079 }->{$t->{TYPE}}->($t);
1082 #####################################################################
1083 # parse the interface definitions
1084 sub ValidInterface($)
1086 my($interface) = shift;
1087 my($data) = $interface->{DATA};
1089 if (has_property($interface, "helper")) {
1090 warning($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1093 ValidProperties($interface,"INTERFACE");
1095 if (has_property($interface, "pointer_default")) {
1096 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1097 ("ref", "unique", "ptr"))) {
1098 fatal($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1102 if (has_property($interface, "object")) {
1103 if (has_property($interface, "version") &&
1104 $interface->{PROPERTIES}->{version} != 0) {
1105 fatal($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1108 if (!defined($interface->{BASE}) &&
1109 not ($interface->{NAME} eq "IUnknown")) {
1110 fatal($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1114 foreach my $d (@{$data}) {
1115 ($d->{TYPE} eq "FUNCTION") && ValidFunction($d);
1116 ($d->{TYPE} eq "TYPEDEF" or
1117 $d->{TYPE} eq "STRUCT" or
1118 $d->{TYPE} eq "UNION" or
1119 $d->{TYPE} eq "ENUM" or
1120 $d->{TYPE} eq "BITMAP") && ValidType($d);
1125 #####################################################################
1126 # Validate an IDL structure
1131 foreach my $x (@{$idl}) {
1132 ($x->{TYPE} eq "INTERFACE") &&
1134 ($x->{TYPE} eq "IMPORTLIB") &&
1135 warning($x, "importlib() not supported");