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 is_charset_array);
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 = {
65 'string_array' => 4, #???
74 'wrepl_nbt_name' => 4,
78 sub GetElementLevelTable($$)
80 my ($e, $pointer_default) = @_;
84 my @bracket_array = ();
89 if (has_property($e, "size_is")) {
90 @size_is = split /,/, has_property($e, "size_is");
93 if (has_property($e, "length_is")) {
94 @length_is = split /,/, has_property($e, "length_is");
97 if (defined($e->{ARRAY_LEN})) {
98 @bracket_array = @{$e->{ARRAY_LEN}};
101 if (has_property($e, "out")) {
104 if (has_property($e, "string")) { $needptrs++; }
105 if ($#bracket_array >= 0) { $needptrs = 0; }
107 warning($e, "[out] argument `$e->{NAME}' not a pointer") if ($needptrs > $e->{POINTERS});
110 # Parse the [][][][] style array stuff
111 for my $i (0 .. $#bracket_array) {
112 my $d = $bracket_array[$#bracket_array - $i];
115 my $is_surrounding = 0;
117 my $is_conformant = 0;
124 if ($size = shift @size_is) {
125 } elsif ((scalar(@size_is) == 0) and has_property($e, "string")) {
127 delete($e->{PROPERTIES}->{string});
129 fatal($e, "Must specify size_is() for conformant array!")
132 if (($length = shift @length_is) or $is_string) {
138 if ($e == $e->{PARENT}->{ELEMENTS}[-1]
139 and $e->{PARENT}->{TYPE} ne "FUNCTION") {
144 $is_fixed = 1 if (not $is_conformant and Parse::Pidl::Util::is_constant($size));
145 $is_inline = 1 if (not $is_conformant and not Parse::Pidl::Util::is_constant($size));
147 if ($i == 0 and $is_fixed and has_property($e, "string")) {
151 delete($e->{PROPERTIES}->{string});
157 LENGTH_IS => $length,
158 IS_DEFERRED => $is_deferred,
159 IS_SURROUNDING => $is_surrounding,
160 IS_ZERO_TERMINATED => $is_string,
161 IS_VARYING => $is_varying,
162 IS_CONFORMANT => $is_conformant,
163 IS_FIXED => $is_fixed,
164 IS_INLINE => $is_inline
168 # Next, all the pointers
169 foreach my $i (1..$e->{POINTERS}) {
170 my $level = "EMBEDDED";
171 # Top level "ref" pointers do not have a referrent identifier
172 $level = "TOP" if ($i == 1 and $e->{PARENT}->{TYPE} eq "FUNCTION");
176 # Only the first level gets the pointer type from the
177 # pointer property, the others get them from
178 # the pointer_default() interface property
180 # see http://msdn2.microsoft.com/en-us/library/aa378984(VS.85).aspx
181 # (Here they talk about the rightmost pointer, but testing shows
182 # they mean the leftmost pointer.)
186 $pt = pointer_type($e);
188 $is_deferred = 1 if ($pt ne "ref" and $e->{PARENT}->{TYPE} eq "FUNCTION");
189 $pt = $pointer_default;
195 POINTER_INDEX => $pointer_idx,
196 IS_DEFERRED => "$is_deferred",
200 warning($e, "top-level \[out\] pointer `$e->{NAME}' is not a \[ref\] pointer")
201 if ($i == 1 and $pt ne "ref" and
202 $e->{PARENT}->{TYPE} eq "FUNCTION" and
203 not has_property($e, "in"));
207 # everything that follows will be deferred
208 $is_deferred = 1 if ($level ne "TOP");
210 my $array_size = shift @size_is;
217 if ($array_length = shift @length_is) {
220 $array_length = $array_size;
225 if (scalar(@size_is) == 0 and has_property($e, "string") and
226 $i == $e->{POINTERS}) {
228 $is_varying = $is_conformant = has_property($e, "noheader")?0:1;
229 delete($e->{PROPERTIES}->{string});
232 if ($array_size or $is_string) {
235 SIZE_IS => $array_size,
236 LENGTH_IS => $array_length,
237 IS_DEFERRED => $is_deferred,
239 IS_ZERO_TERMINATED => $is_string,
240 IS_VARYING => $is_varying,
241 IS_CONFORMANT => $is_conformant,
250 if (defined(has_property($e, "subcontext"))) {
251 my $hdr_size = has_property($e, "subcontext");
252 my $subsize = has_property($e, "subcontext_size");
253 if (not defined($subsize)) {
258 TYPE => "SUBCONTEXT",
259 HEADER_SIZE => $hdr_size,
260 SUBCONTEXT_SIZE => $subsize,
261 IS_DEFERRED => $is_deferred,
262 COMPRESSION => has_property($e, "compression"),
266 if (my $switch = has_property($e, "switch_is")) {
269 SWITCH_IS => $switch,
270 IS_DEFERRED => $is_deferred
274 if (scalar(@size_is) > 0) {
275 fatal($e, "size_is() on non-array element");
278 if (scalar(@length_is) > 0) {
279 fatal($e, "length_is() on non-array element");
282 if (has_property($e, "string")) {
283 fatal($e, "string() attribute on non-array element");
288 DATA_TYPE => $e->{TYPE},
289 IS_DEFERRED => $is_deferred,
290 CONTAINS_DEFERRED => can_contain_deferred($e->{TYPE}),
291 IS_SURROUNDING => 0 #FIXME
295 foreach (@$order) { $_->{LEVEL_INDEX} = $i; $i+=1; }
300 sub GetTypedefLevelTable($$$)
302 my ($e, $data, $pointer_default) = @_;
311 foreach (@$order) { $_->{LEVEL_INDEX} = $i; $i+=1; }
316 #####################################################################
317 # see if a type contains any deferred data
318 sub can_contain_deferred($)
320 sub can_contain_deferred($);
323 return 1 unless (hasType($type)); # assume the worst
325 $type = getType($type);
327 return 0 if (Parse::Pidl::Typelist::is_scalar($type));
329 return can_contain_deferred($type->{DATA}) if ($type->{TYPE} eq "TYPEDEF");
331 return 0 unless defined($type->{ELEMENTS});
333 foreach (@{$type->{ELEMENTS}}) {
334 return 1 if ($_->{POINTERS});
335 return 1 if (can_contain_deferred ($_->{TYPE}));
345 return undef unless $e->{POINTERS};
347 return "ref" if (has_property($e, "ref"));
348 return "full" if (has_property($e, "ptr"));
349 return "sptr" if (has_property($e, "sptr"));
350 return "unique" if (has_property($e, "unique"));
351 return "relative" if (has_property($e, "relative"));
352 return "ignore" if (has_property($e, "ignore"));
357 #####################################################################
358 # work out the correct alignment for a structure or union
359 sub find_largest_alignment($)
364 for my $e (@{$s->{ELEMENTS}}) {
367 if ($e->{POINTERS}) {
368 # this is a hack for NDR64
369 # the NDR layer translates this into
370 # an alignment of 4 for NDR and 8 for NDR64
372 } elsif (has_property($e, "subcontext")) {
374 } elsif (has_property($e, "transmit_as")) {
375 $a = align_type($e->{PROPERTIES}->{transmit_as});
377 $a = align_type($e->{TYPE});
380 $align = $a if ($align < $a);
386 #####################################################################
393 if (ref($e) eq "HASH" and $e->{TYPE} eq "SCALAR") {
394 return $scalar_alignment->{$e->{NAME}};
397 return 0 if ($e eq "EMPTY");
399 unless (hasType($e)) {
400 # it must be an external type - all we can do is guess
401 # warning($e, "assuming alignment of unknown type '$e' is 4");
405 my $dt = getType($e);
407 if ($dt->{TYPE} eq "TYPEDEF") {
408 return align_type($dt->{DATA});
409 } elsif ($dt->{TYPE} eq "CONFORMANCE") {
410 return $dt->{DATA}->{ALIGN};
411 } elsif ($dt->{TYPE} eq "ENUM") {
412 return align_type(Parse::Pidl::Typelist::enum_type_fn($dt));
413 } elsif ($dt->{TYPE} eq "BITMAP") {
414 return align_type(Parse::Pidl::Typelist::bitmap_type_fn($dt));
415 } elsif (($dt->{TYPE} eq "STRUCT") or ($dt->{TYPE} eq "UNION")) {
416 # Struct/union without body: assume 4
417 return 4 unless (defined($dt->{ELEMENTS}));
418 return find_largest_alignment($dt);
421 die("Unknown data type type $dt->{TYPE}");
426 my ($e, $pointer_default) = @_;
428 $e->{TYPE} = expandAlias($e->{TYPE});
430 if (ref($e->{TYPE}) eq "HASH") {
431 $e->{TYPE} = ParseType($e->{TYPE}, $pointer_default);
437 PROPERTIES => $e->{PROPERTIES},
438 LEVELS => GetElementLevelTable($e, $pointer_default),
439 REPRESENTATION_TYPE => ($e->{PROPERTIES}->{represent_as} or $e->{TYPE}),
440 ALIGN => align_type($e->{TYPE}),
447 my ($struct, $pointer_default) = @_;
449 my $surrounding = undef;
453 NAME => $struct->{NAME},
454 SURROUNDING_ELEMENT => undef,
456 PROPERTIES => $struct->{PROPERTIES},
459 } unless defined($struct->{ELEMENTS});
461 CheckPointerTypes($struct, $pointer_default);
463 foreach my $x (@{$struct->{ELEMENTS}})
465 my $e = ParseElement($x, $pointer_default);
466 if ($x != $struct->{ELEMENTS}[-1] and
467 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
468 fatal($x, "conformant member not at end of struct");
473 my $e = $elements[-1];
474 if (defined($e) and defined($e->{LEVELS}[0]->{IS_SURROUNDING}) and
475 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
479 if (defined $e->{TYPE} && $e->{TYPE} eq "string"
480 && property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
481 $surrounding = $struct->{ELEMENTS}[-1];
485 if ($struct->{NAME}) {
486 $align = align_type($struct->{NAME});
491 NAME => $struct->{NAME},
492 SURROUNDING_ELEMENT => $surrounding,
493 ELEMENTS => \@elements,
494 PROPERTIES => $struct->{PROPERTIES},
502 my ($e, $pointer_default) = @_;
505 my $switch_type = has_property($e, "switch_type");
506 unless (defined($switch_type)) { $switch_type = "uint32"; }
507 if (has_property($e, "nodiscriminant")) { $switch_type = undef; }
512 SWITCH_TYPE => $switch_type,
514 PROPERTIES => $e->{PROPERTIES},
515 HAS_DEFAULT => $hasdefault,
518 } unless defined($e->{ELEMENTS});
520 CheckPointerTypes($e, $pointer_default);
522 foreach my $x (@{$e->{ELEMENTS}})
525 if ($x->{TYPE} eq "EMPTY") {
526 $t = { TYPE => "EMPTY" };
528 $t = ParseElement($x, $pointer_default);
530 if (has_property($x, "default")) {
531 $t->{CASE} = "default";
533 } elsif (defined($x->{PROPERTIES}->{case})) {
534 $t->{CASE} = "case $x->{PROPERTIES}->{case}";
536 die("Union element $x->{NAME} has neither default nor case property");
543 $align = align_type($e->{NAME});
549 SWITCH_TYPE => $switch_type,
550 ELEMENTS => \@elements,
551 PROPERTIES => $e->{PROPERTIES},
552 HAS_DEFAULT => $hasdefault,
560 my ($e, $pointer_default) = @_;
565 BASE_TYPE => Parse::Pidl::Typelist::enum_type_fn($e),
566 ELEMENTS => $e->{ELEMENTS},
567 PROPERTIES => $e->{PROPERTIES},
574 my ($e, $pointer_default) = @_;
579 BASE_TYPE => Parse::Pidl::Typelist::bitmap_type_fn($e),
580 ELEMENTS => $e->{ELEMENTS},
581 PROPERTIES => $e->{PROPERTIES},
588 my ($d, $pointer_default) = @_;
591 STRUCT => \&ParseStruct,
592 UNION => \&ParseUnion,
594 BITMAP => \&ParseBitmap,
595 TYPEDEF => \&ParseTypedef,
596 }->{$d->{TYPE}}->($d, $pointer_default);
603 my ($d, $pointer_default) = @_;
605 if (defined($d->{DATA}->{PROPERTIES}) && !defined($d->{PROPERTIES})) {
606 $d->{PROPERTIES} = $d->{DATA}->{PROPERTIES};
609 my $data = ParseType($d->{DATA}, $pointer_default);
610 $data->{ALIGN} = align_type($d->{NAME});
615 PROPERTIES => $d->{PROPERTIES},
616 LEVELS => GetTypedefLevelTable($d, $data, $pointer_default),
629 sub ParseFunction($$$)
631 my ($ndr,$d,$opnum) = @_;
634 my $thisopnum = undef;
636 CheckPointerTypes($d, "ref");
638 if (not defined($d->{PROPERTIES}{noopnum})) {
639 $thisopnum = ${$opnum};
643 foreach my $x (@{$d->{ELEMENTS}}) {
644 my $e = ParseElement($x, $ndr->{PROPERTIES}->{pointer_default});
645 push (@{$e->{DIRECTION}}, "in") if (has_property($x, "in"));
646 push (@{$e->{DIRECTION}}, "out") if (has_property($x, "out"));
648 push (@elements, $e);
651 if ($d->{RETURN_TYPE} ne "void") {
652 $rettype = expandAlias($d->{RETURN_TYPE});
656 if (has_property($d, "async")) { $async = 1; }
663 RETURN_TYPE => $rettype,
664 PROPERTIES => $d->{PROPERTIES},
665 ELEMENTS => \@elements,
670 sub CheckPointerTypes($$)
672 my ($s,$default) = @_;
674 return unless defined($s->{ELEMENTS});
676 foreach my $e (@{$s->{ELEMENTS}}) {
677 if ($e->{POINTERS} and not defined(pointer_type($e))) {
678 $e->{PROPERTIES}->{$default} = '1';
683 sub FindNestedTypes($$)
685 sub FindNestedTypes($$);
688 return unless defined($t->{ELEMENTS});
689 return if ($t->{TYPE} eq "ENUM");
690 return if ($t->{TYPE} eq "BITMAP");
692 foreach (@{$t->{ELEMENTS}}) {
693 if (ref($_->{TYPE}) eq "HASH") {
694 push (@$l, $_->{TYPE}) if (defined($_->{TYPE}->{NAME}));
695 FindNestedTypes($l, $_->{TYPE});
700 sub ParseInterface($)
710 if (not has_property($idl, "pointer_default")) {
711 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
712 # and "unique" in Microsoft Extensions mode (default)
713 $idl->{PROPERTIES}->{pointer_default} = "unique";
716 foreach my $d (@{$idl->{DATA}}) {
717 if ($d->{TYPE} eq "FUNCTION") {
718 push (@functions, ParseFunction($idl, $d, \$opnum));
719 } elsif ($d->{TYPE} eq "CONST") {
720 push (@consts, ParseConst($idl, $d));
722 push (@types, ParseType($d, $idl->{PROPERTIES}->{pointer_default}));
723 FindNestedTypes(\@types, $d);
729 if(defined $idl->{PROPERTIES}->{version}) {
730 my @if_version = split(/\./, $idl->{PROPERTIES}->{version});
731 if ($if_version[0] == $idl->{PROPERTIES}->{version}) {
732 $version = $idl->{PROPERTIES}->{version};
734 $version = $if_version[1] << 16 | $if_version[0];
738 # If no endpoint is set, default to the interface name as a named pipe
739 if (!defined $idl->{PROPERTIES}->{endpoint}) {
740 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME} . "]\"";
742 @endpoints = split /,/, $idl->{PROPERTIES}->{endpoint};
746 NAME => $idl->{NAME},
747 UUID => lc(has_property($idl, "uuid")),
750 PROPERTIES => $idl->{PROPERTIES},
751 FUNCTIONS => \@functions,
754 ENDPOINTS => \@endpoints
758 # Convert a IDL tree to a NDR tree
759 # Gives a result tree describing all that's necessary for easily generating
760 # NDR parsers / generators
765 return undef unless (defined($idl));
767 Parse::Pidl::NDR::Validate($idl);
772 ($_->{TYPE} eq "CPP_QUOTE") && push(@ndr, $_);
773 ($_->{TYPE} eq "INTERFACE") && push(@ndr, ParseInterface($_));
774 ($_->{TYPE} eq "IMPORT") && push(@ndr, $_);
787 foreach my $l (@{$e->{LEVELS}}) {
788 return $l if ($seen);
789 ($seen = 1) if ($l == $fl);
800 foreach my $l (@{$e->{LEVELS}}) {
801 (return $prev) if ($l == $fl);
808 sub ContainsString($)
812 foreach my $l (@{$e->{LEVELS}}) {
813 return 1 if ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED});
819 sub ContainsDeferred($$)
823 return 1 if ($l->{CONTAINS_DEFERRED});
825 while ($l = GetNextLevel($e,$l))
827 return 1 if ($l->{IS_DEFERRED});
828 return 1 if ($l->{CONTAINS_DEFERRED});
837 my $name = "<ANONYMOUS>";
839 $name = $e->{NAME} if defined($e->{NAME});
841 if (defined($e->{PARENT}) and defined($e->{PARENT}->{NAME})) {
842 return "$e->{PARENT}->{NAME}.$name";
845 if (defined($e->{PARENT}) and
846 defined($e->{PARENT}->{PARENT}) and
847 defined($e->{PARENT}->{PARENT}->{NAME})) {
848 return "$e->{PARENT}->{PARENT}->{NAME}.$name";
854 ###################################
855 # find a sibling var in a structure
859 my($fn) = $e->{PARENT};
861 if ($name =~ /\*(.*)/) {
865 for my $e2 (@{$fn->{ELEMENTS}}) {
866 return $e2 if ($e2->{NAME} eq $name);
872 my %property_list = (
874 "helpstring" => ["INTERFACE", "FUNCTION"],
875 "version" => ["INTERFACE"],
876 "uuid" => ["INTERFACE"],
877 "endpoint" => ["INTERFACE"],
878 "pointer_default" => ["INTERFACE"],
879 "helper" => ["INTERFACE"],
880 "pyhelper" => ["INTERFACE"],
881 "authservice" => ["INTERFACE"],
882 "restricted" => ["INTERFACE"],
885 "object" => ["INTERFACE"],
886 "local" => ["INTERFACE", "FUNCTION"],
887 "iid_is" => ["ELEMENT"],
888 "call_as" => ["FUNCTION"],
889 "idempotent" => ["FUNCTION"],
892 "noopnum" => ["FUNCTION"],
894 "out" => ["ELEMENT"],
895 "async" => ["FUNCTION"],
898 "ref" => ["ELEMENT"],
899 "ptr" => ["ELEMENT"],
900 "unique" => ["ELEMENT"],
901 "ignore" => ["ELEMENT"],
902 "relative" => ["ELEMENT"],
903 "null_is_ffffffff" => ["ELEMENT"],
904 "relative_base" => ["TYPEDEF", "STRUCT", "UNION"],
906 "gensize" => ["TYPEDEF", "STRUCT", "UNION"],
907 "value" => ["ELEMENT"],
908 "flag" => ["ELEMENT", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
911 "public" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
912 "nopush" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
913 "nopull" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
914 "nosize" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
915 "noprint" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "ELEMENT"],
916 "todo" => ["FUNCTION"],
919 "switch_is" => ["ELEMENT"],
920 "switch_type" => ["ELEMENT", "UNION"],
921 "nodiscriminant" => ["UNION"],
922 "case" => ["ELEMENT"],
923 "default" => ["ELEMENT"],
925 "represent_as" => ["ELEMENT"],
926 "transmit_as" => ["ELEMENT"],
929 "subcontext" => ["ELEMENT"],
930 "subcontext_size" => ["ELEMENT"],
931 "compression" => ["ELEMENT"],
934 "enum8bit" => ["ENUM"],
935 "enum16bit" => ["ENUM"],
936 "v1_enum" => ["ENUM"],
939 "bitmap8bit" => ["BITMAP"],
940 "bitmap16bit" => ["BITMAP"],
941 "bitmap32bit" => ["BITMAP"],
942 "bitmap64bit" => ["BITMAP"],
945 "range" => ["ELEMENT", "PIPE"],
946 "size_is" => ["ELEMENT"],
947 "string" => ["ELEMENT"],
948 "noheader" => ["ELEMENT"],
949 "charset" => ["ELEMENT"],
950 "length_is" => ["ELEMENT"],
953 #####################################################################
954 # check for unknown properties
955 sub ValidProperties($$)
959 return unless defined $e->{PROPERTIES};
961 foreach my $key (keys %{$e->{PROPERTIES}}) {
962 warning($e, el_name($e) . ": unknown property '$key'")
963 unless defined($property_list{$key});
965 fatal($e, el_name($e) . ": property '$key' not allowed on '$t'")
966 unless grep(/^$t$/, @{$property_list{$key}});
974 return $t->{NAME} if (ref($t) eq "HASH" and $t->{TYPE} eq "SCALAR");
975 my $ti = getType($t);
977 if (not defined ($ti)) {
979 } elsif ($ti->{TYPE} eq "TYPEDEF") {
980 return mapToScalar($ti->{DATA});
981 } elsif ($ti->{TYPE} eq "ENUM") {
982 return Parse::Pidl::Typelist::enum_type_fn($ti);
983 } elsif ($ti->{TYPE} eq "BITMAP") {
984 return Parse::Pidl::Typelist::bitmap_type_fn($ti);
990 #####################################################################
991 # validate an element
996 ValidProperties($e,"ELEMENT");
998 # Check whether switches are used correctly.
999 if (my $switch = has_property($e, "switch_is")) {
1000 my $e2 = find_sibling($e, $switch);
1001 my $type = getType($e->{TYPE});
1003 if (defined($type) and $type->{DATA}->{TYPE} ne "UNION") {
1004 fatal($e, el_name($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
1007 if (not has_property($type->{DATA}, "nodiscriminant") and defined($e2)) {
1008 my $discriminator_type = has_property($type->{DATA}, "switch_type");
1009 $discriminator_type = "uint32" unless defined ($discriminator_type);
1011 my $t1 = mapToScalar($discriminator_type);
1013 if (not defined($t1)) {
1014 fatal($e, el_name($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
1017 my $t2 = mapToScalar($e2->{TYPE});
1018 if (not defined($t2)) {
1019 fatal($e, el_name($e) . ": unable to map variable used for switch_is() to scalar");
1023 warning($e, el_name($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
1028 if (has_property($e, "subcontext") and has_property($e, "represent_as")) {
1029 fatal($e, el_name($e) . " : subcontext() and represent_as() can not be used on the same element");
1032 if (has_property($e, "subcontext") and has_property($e, "transmit_as")) {
1033 fatal($e, el_name($e) . " : subcontext() and transmit_as() can not be used on the same element");
1036 if (has_property($e, "represent_as") and has_property($e, "transmit_as")) {
1037 fatal($e, el_name($e) . " : represent_as() and transmit_as() can not be used on the same element");
1040 if (has_property($e, "represent_as") and has_property($e, "value")) {
1041 fatal($e, el_name($e) . " : represent_as() and value() can not be used on the same element");
1044 if (has_property($e, "subcontext")) {
1045 warning($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
1048 if (defined (has_property($e, "subcontext_size")) and not defined(has_property($e, "subcontext"))) {
1049 fatal($e, el_name($e) . " : subcontext_size() on non-subcontext element");
1052 if (defined (has_property($e, "compression")) and not defined(has_property($e, "subcontext"))) {
1053 fatal($e, el_name($e) . " : compression() on non-subcontext element");
1056 if (!$e->{POINTERS} && (
1057 has_property($e, "ptr") or
1058 has_property($e, "unique") or
1059 has_property($e, "relative") or
1060 has_property($e, "ref"))) {
1061 fatal($e, el_name($e) . " : pointer properties on non-pointer element\n");
1065 #####################################################################
1071 ValidProperties($enum, "ENUM");
1074 #####################################################################
1080 ValidProperties($bitmap, "BITMAP");
1083 #####################################################################
1087 my($struct) = shift;
1089 ValidProperties($struct, "STRUCT");
1091 return unless defined($struct->{ELEMENTS});
1093 foreach my $e (@{$struct->{ELEMENTS}}) {
1094 $e->{PARENT} = $struct;
1099 #####################################################################
1105 ValidProperties($union,"UNION");
1107 if (has_property($union->{PARENT}, "nodiscriminant") and
1108 has_property($union->{PARENT}, "switch_type")) {
1109 fatal($union->{PARENT}, $union->{PARENT}->{NAME} . ": switch_type(" . $union->{PARENT}->{PROPERTIES}->{switch_type} . ") on union without discriminant");
1112 return unless defined($union->{ELEMENTS});
1114 foreach my $e (@{$union->{ELEMENTS}}) {
1115 $e->{PARENT} = $union;
1117 if (defined($e->{PROPERTIES}->{default}) and
1118 defined($e->{PROPERTIES}->{case})) {
1119 fatal($e, "Union member $e->{NAME} can not have both default and case properties!");
1122 unless (defined ($e->{PROPERTIES}->{default}) or
1123 defined ($e->{PROPERTIES}->{case})) {
1124 fatal($e, "Union member $e->{NAME} must have default or case property");
1127 if (has_property($e, "ref")) {
1128 fatal($e, el_name($e) . ": embedded ref pointers are not supported yet\n");
1136 #####################################################################
1141 my $data = $pipe->{DATA};
1143 ValidProperties($pipe, "PIPE");
1145 fatal($pipe, $pipe->{NAME} . ": 'pipe' is not yet supported by pidl");
1148 #####################################################################
1152 my($typedef) = shift;
1153 my $data = $typedef->{DATA};
1155 ValidProperties($typedef, "TYPEDEF");
1157 $data->{PARENT} = $typedef;
1159 $data->{FILE} = $typedef->{FILE} unless defined($data->{FILE});
1160 $data->{LINE} = $typedef->{LINE} unless defined($data->{LINE});
1162 ValidType($data) if (ref($data) eq "HASH");
1165 #####################################################################
1166 # validate a function
1167 sub ValidFunction($)
1171 ValidProperties($fn,"FUNCTION");
1173 foreach my $e (@{$fn->{ELEMENTS}}) {
1175 if (has_property($e, "ref") && !$e->{POINTERS}) {
1176 fatal($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1182 #####################################################################
1189 TYPEDEF => \&ValidTypedef,
1190 STRUCT => \&ValidStruct,
1191 UNION => \&ValidUnion,
1192 ENUM => \&ValidEnum,
1193 BITMAP => \&ValidBitmap,
1195 }->{$t->{TYPE}}->($t);
1198 #####################################################################
1199 # parse the interface definitions
1200 sub ValidInterface($)
1202 my($interface) = shift;
1203 my($data) = $interface->{DATA};
1205 if (has_property($interface, "helper")) {
1206 warning($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1209 ValidProperties($interface,"INTERFACE");
1211 if (has_property($interface, "pointer_default")) {
1212 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1213 ("ref", "unique", "ptr"))) {
1214 fatal($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1218 if (has_property($interface, "object")) {
1219 if (has_property($interface, "version") &&
1220 $interface->{PROPERTIES}->{version} != 0) {
1221 fatal($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1224 if (!defined($interface->{BASE}) &&
1225 not ($interface->{NAME} eq "IUnknown")) {
1226 fatal($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1230 foreach my $d (@{$data}) {
1231 ($d->{TYPE} eq "FUNCTION") && ValidFunction($d);
1232 ($d->{TYPE} eq "TYPEDEF" or
1233 $d->{TYPE} eq "STRUCT" or
1234 $d->{TYPE} eq "UNION" or
1235 $d->{TYPE} eq "ENUM" or
1236 $d->{TYPE} eq "BITMAP" or
1237 $d->{TYPE} eq "PIPE") && ValidType($d);
1242 #####################################################################
1243 # Validate an IDL structure
1248 foreach my $x (@{$idl}) {
1249 ($x->{TYPE} eq "INTERFACE") &&
1251 ($x->{TYPE} eq "IMPORTLIB") &&
1252 fatal($x, "importlib() not supported");
1256 sub is_charset_array($$)
1260 return 0 if ($l->{TYPE} ne "ARRAY");
1262 my $nl = GetNextLevel($e,$l);
1264 return 0 unless ($nl->{TYPE} eq "DATA");
1266 return has_property($e, "charset");