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 = {
63 'string_array' => 4, #???
72 'wrepl_nbt_name' => 4,
76 sub GetElementLevelTable($$)
78 my ($e, $pointer_default) = @_;
82 my @bracket_array = ();
87 if (has_property($e, "size_is")) {
88 @size_is = split /,/, has_property($e, "size_is");
91 if (has_property($e, "length_is")) {
92 @length_is = split /,/, has_property($e, "length_is");
95 if (defined($e->{ARRAY_LEN})) {
96 @bracket_array = @{$e->{ARRAY_LEN}};
99 if (has_property($e, "out")) {
102 if (has_property($e, "string")) { $needptrs++; }
103 if ($#bracket_array >= 0) { $needptrs = 0; }
105 warning($e, "[out] argument `$e->{NAME}' not a pointer") if ($needptrs > $e->{POINTERS});
108 # Parse the [][][][] style array stuff
109 for my $i (0 .. $#bracket_array) {
110 my $d = $bracket_array[$#bracket_array - $i];
113 my $is_surrounding = 0;
115 my $is_conformant = 0;
122 if ($size = shift @size_is) {
123 } elsif ((scalar(@size_is) == 0) and has_property($e, "string")) {
125 delete($e->{PROPERTIES}->{string});
127 fatal($e, "Must specify size_is() for conformant array!")
130 if (($length = shift @length_is) or $is_string) {
136 if ($e == $e->{PARENT}->{ELEMENTS}[-1]
137 and $e->{PARENT}->{TYPE} ne "FUNCTION") {
142 $is_fixed = 1 if (not $is_conformant and Parse::Pidl::Util::is_constant($size));
143 $is_inline = 1 if (not $is_conformant and not Parse::Pidl::Util::is_constant($size));
145 if ($i == 0 and $is_fixed and has_property($e, "string")) {
149 delete($e->{PROPERTIES}->{string});
155 LENGTH_IS => $length,
156 IS_DEFERRED => $is_deferred,
157 IS_SURROUNDING => $is_surrounding,
158 IS_ZERO_TERMINATED => $is_string,
159 IS_VARYING => $is_varying,
160 IS_CONFORMANT => $is_conformant,
161 IS_FIXED => $is_fixed,
162 IS_INLINE => $is_inline
166 # Next, all the pointers
167 foreach my $i (1..$e->{POINTERS}) {
168 my $level = "EMBEDDED";
169 # Top level "ref" pointers do not have a referrent identifier
170 $level = "TOP" if ($i == 1 and $e->{PARENT}->{TYPE} eq "FUNCTION");
174 # Only the first level gets the pointer type from the
175 # pointer property, the others get them from
176 # the pointer_default() interface property
178 # see http://msdn2.microsoft.com/en-us/library/aa378984(VS.85).aspx
179 # (Here they talk about the rightmost pointer, but testing shows
180 # they mean the leftmost pointer.)
184 $pt = pointer_type($e);
186 $is_deferred = 1 if ($pt ne "ref" and $e->{PARENT}->{TYPE} eq "FUNCTION");
187 $pt = $pointer_default;
193 POINTER_INDEX => $pointer_idx,
194 IS_DEFERRED => "$is_deferred",
198 warning($e, "top-level \[out\] pointer `$e->{NAME}' is not a \[ref\] pointer")
199 if ($i == 1 and $pt ne "ref" and
200 $e->{PARENT}->{TYPE} eq "FUNCTION" and
201 not has_property($e, "in"));
205 # everything that follows will be deferred
206 $is_deferred = 1 if ($level ne "TOP");
208 my $array_size = shift @size_is;
215 if ($array_length = shift @length_is) {
218 $array_length = $array_size;
223 if (scalar(@size_is) == 0 and has_property($e, "string") and
224 $i == $e->{POINTERS}) {
226 $is_varying = $is_conformant = has_property($e, "noheader")?0:1;
227 delete($e->{PROPERTIES}->{string});
230 if ($array_size or $is_string) {
233 SIZE_IS => $array_size,
234 LENGTH_IS => $array_length,
235 IS_DEFERRED => $is_deferred,
237 IS_ZERO_TERMINATED => $is_string,
238 IS_VARYING => $is_varying,
239 IS_CONFORMANT => $is_conformant,
248 if (defined(has_property($e, "subcontext"))) {
249 my $hdr_size = has_property($e, "subcontext");
250 my $subsize = has_property($e, "subcontext_size");
251 if (not defined($subsize)) {
256 TYPE => "SUBCONTEXT",
257 HEADER_SIZE => $hdr_size,
258 SUBCONTEXT_SIZE => $subsize,
259 IS_DEFERRED => $is_deferred,
260 COMPRESSION => has_property($e, "compression"),
264 if (my $switch = has_property($e, "switch_is")) {
267 SWITCH_IS => $switch,
268 IS_DEFERRED => $is_deferred
272 if (scalar(@size_is) > 0) {
273 fatal($e, "size_is() on non-array element");
276 if (scalar(@length_is) > 0) {
277 fatal($e, "length_is() on non-array element");
280 if (has_property($e, "string")) {
281 fatal($e, "string() attribute on non-array element");
286 DATA_TYPE => $e->{TYPE},
287 IS_DEFERRED => $is_deferred,
288 CONTAINS_DEFERRED => can_contain_deferred($e->{TYPE}),
289 IS_SURROUNDING => 0 #FIXME
293 foreach (@$order) { $_->{LEVEL_INDEX} = $i; $i+=1; }
298 sub GetTypedefLevelTable($$$)
300 my ($e, $data, $pointer_default) = @_;
309 foreach (@$order) { $_->{LEVEL_INDEX} = $i; $i+=1; }
314 #####################################################################
315 # see if a type contains any deferred data
316 sub can_contain_deferred($)
318 sub can_contain_deferred($);
321 return 1 unless (hasType($type)); # assume the worst
323 $type = getType($type);
325 return 0 if (Parse::Pidl::Typelist::is_scalar($type));
327 return can_contain_deferred($type->{DATA}) if ($type->{TYPE} eq "TYPEDEF");
329 return 0 unless defined($type->{ELEMENTS});
331 foreach (@{$type->{ELEMENTS}}) {
332 return 1 if ($_->{POINTERS});
333 return 1 if (can_contain_deferred ($_->{TYPE}));
343 return undef unless $e->{POINTERS};
345 return "ref" if (has_property($e, "ref"));
346 return "full" if (has_property($e, "ptr"));
347 return "sptr" if (has_property($e, "sptr"));
348 return "unique" if (has_property($e, "unique"));
349 return "relative" if (has_property($e, "relative"));
350 return "ignore" if (has_property($e, "ignore"));
355 #####################################################################
356 # work out the correct alignment for a structure or union
357 sub find_largest_alignment($)
362 for my $e (@{$s->{ELEMENTS}}) {
365 if ($e->{POINTERS}) {
367 } elsif (has_property($e, "subcontext")) {
369 } elsif (has_property($e, "transmit_as")) {
370 $a = align_type($e->{PROPERTIES}->{transmit_as});
372 $a = align_type($e->{TYPE});
375 $align = $a if ($align < $a);
381 #####################################################################
388 if (ref($e) eq "HASH" and $e->{TYPE} eq "SCALAR") {
389 return $scalar_alignment->{$e->{NAME}};
392 return 0 if ($e eq "EMPTY");
394 unless (hasType($e)) {
395 # it must be an external type - all we can do is guess
396 # warning($e, "assuming alignment of unknown type '$e' is 4");
400 my $dt = getType($e);
402 if ($dt->{TYPE} eq "TYPEDEF") {
403 return align_type($dt->{DATA});
404 } elsif ($dt->{TYPE} eq "ENUM") {
405 return align_type(Parse::Pidl::Typelist::enum_type_fn($dt));
406 } elsif ($dt->{TYPE} eq "BITMAP") {
407 return align_type(Parse::Pidl::Typelist::bitmap_type_fn($dt));
408 } elsif (($dt->{TYPE} eq "STRUCT") or ($dt->{TYPE} eq "UNION")) {
409 # Struct/union without body: assume 4
410 return 4 unless (defined($dt->{ELEMENTS}));
411 return find_largest_alignment($dt);
414 die("Unknown data type type $dt->{TYPE}");
419 my ($e, $pointer_default) = @_;
421 $e->{TYPE} = expandAlias($e->{TYPE});
423 if (ref($e->{TYPE}) eq "HASH") {
424 $e->{TYPE} = ParseType($e->{TYPE}, $pointer_default);
430 PROPERTIES => $e->{PROPERTIES},
431 LEVELS => GetElementLevelTable($e, $pointer_default),
432 REPRESENTATION_TYPE => ($e->{PROPERTIES}->{represent_as} or $e->{TYPE}),
433 ALIGN => align_type($e->{TYPE}),
440 my ($struct, $pointer_default) = @_;
442 my $surrounding = undef;
446 NAME => $struct->{NAME},
447 SURROUNDING_ELEMENT => undef,
449 PROPERTIES => $struct->{PROPERTIES},
452 } unless defined($struct->{ELEMENTS});
454 CheckPointerTypes($struct, $pointer_default);
456 foreach my $x (@{$struct->{ELEMENTS}})
458 my $e = ParseElement($x, $pointer_default);
459 if ($x != $struct->{ELEMENTS}[-1] and
460 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
461 fatal($x, "conformant member not at end of struct");
466 my $e = $elements[-1];
467 if (defined($e) and defined($e->{LEVELS}[0]->{IS_SURROUNDING}) and
468 $e->{LEVELS}[0]->{IS_SURROUNDING}) {
472 if (defined $e->{TYPE} && $e->{TYPE} eq "string"
473 && property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
474 $surrounding = $struct->{ELEMENTS}[-1];
478 if ($struct->{NAME}) {
479 $align = align_type($struct->{NAME});
484 NAME => $struct->{NAME},
485 SURROUNDING_ELEMENT => $surrounding,
486 ELEMENTS => \@elements,
487 PROPERTIES => $struct->{PROPERTIES},
495 my ($e, $pointer_default) = @_;
498 my $switch_type = has_property($e, "switch_type");
499 unless (defined($switch_type)) { $switch_type = "uint32"; }
500 if (has_property($e, "nodiscriminant")) { $switch_type = undef; }
505 SWITCH_TYPE => $switch_type,
507 PROPERTIES => $e->{PROPERTIES},
508 HAS_DEFAULT => $hasdefault,
510 } unless defined($e->{ELEMENTS});
512 CheckPointerTypes($e, $pointer_default);
514 foreach my $x (@{$e->{ELEMENTS}})
517 if ($x->{TYPE} eq "EMPTY") {
518 $t = { TYPE => "EMPTY" };
520 $t = ParseElement($x, $pointer_default);
522 if (has_property($x, "default")) {
523 $t->{CASE} = "default";
525 } elsif (defined($x->{PROPERTIES}->{case})) {
526 $t->{CASE} = "case $x->{PROPERTIES}->{case}";
528 die("Union element $x->{NAME} has neither default nor case property");
536 SWITCH_TYPE => $switch_type,
537 ELEMENTS => \@elements,
538 PROPERTIES => $e->{PROPERTIES},
539 HAS_DEFAULT => $hasdefault,
546 my ($e, $pointer_default) = @_;
551 BASE_TYPE => Parse::Pidl::Typelist::enum_type_fn($e),
552 ELEMENTS => $e->{ELEMENTS},
553 PROPERTIES => $e->{PROPERTIES},
560 my ($e, $pointer_default) = @_;
565 BASE_TYPE => Parse::Pidl::Typelist::bitmap_type_fn($e),
566 ELEMENTS => $e->{ELEMENTS},
567 PROPERTIES => $e->{PROPERTIES},
574 my ($d, $pointer_default) = @_;
577 STRUCT => \&ParseStruct,
578 UNION => \&ParseUnion,
580 BITMAP => \&ParseBitmap,
581 TYPEDEF => \&ParseTypedef,
582 }->{$d->{TYPE}}->($d, $pointer_default);
589 my ($d, $pointer_default) = @_;
591 if (defined($d->{DATA}->{PROPERTIES}) && !defined($d->{PROPERTIES})) {
592 $d->{PROPERTIES} = $d->{DATA}->{PROPERTIES};
595 my $data = ParseType($d->{DATA}, $pointer_default);
596 $data->{ALIGN} = align_type($d->{NAME});
601 PROPERTIES => $d->{PROPERTIES},
602 LEVELS => GetTypedefLevelTable($d, $data, $pointer_default),
615 sub ParseFunction($$$)
617 my ($ndr,$d,$opnum) = @_;
620 my $thisopnum = undef;
622 CheckPointerTypes($d, "ref");
624 if (not defined($d->{PROPERTIES}{noopnum})) {
625 $thisopnum = ${$opnum};
629 foreach my $x (@{$d->{ELEMENTS}}) {
630 my $e = ParseElement($x, $ndr->{PROPERTIES}->{pointer_default});
631 push (@{$e->{DIRECTION}}, "in") if (has_property($x, "in"));
632 push (@{$e->{DIRECTION}}, "out") if (has_property($x, "out"));
634 push (@elements, $e);
637 if ($d->{RETURN_TYPE} ne "void") {
638 $rettype = expandAlias($d->{RETURN_TYPE});
642 if (has_property($d, "async")) { $async = 1; }
649 RETURN_TYPE => $rettype,
650 PROPERTIES => $d->{PROPERTIES},
651 ELEMENTS => \@elements,
656 sub CheckPointerTypes($$)
658 my ($s,$default) = @_;
660 return unless defined($s->{ELEMENTS});
662 foreach my $e (@{$s->{ELEMENTS}}) {
663 if ($e->{POINTERS} and not defined(pointer_type($e))) {
664 $e->{PROPERTIES}->{$default} = '1';
669 sub FindNestedTypes($$)
671 sub FindNestedTypes($$);
674 return unless defined($t->{ELEMENTS});
675 return if ($t->{TYPE} eq "ENUM");
676 return if ($t->{TYPE} eq "BITMAP");
678 foreach (@{$t->{ELEMENTS}}) {
679 if (ref($_->{TYPE}) eq "HASH") {
680 push (@$l, $_->{TYPE}) if (defined($_->{TYPE}->{NAME}));
681 FindNestedTypes($l, $_->{TYPE});
686 sub ParseInterface($)
696 if (not has_property($idl, "pointer_default")) {
697 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
698 # and "unique" in Microsoft Extensions mode (default)
699 $idl->{PROPERTIES}->{pointer_default} = "unique";
702 foreach my $d (@{$idl->{DATA}}) {
703 if ($d->{TYPE} eq "FUNCTION") {
704 push (@functions, ParseFunction($idl, $d, \$opnum));
705 } elsif ($d->{TYPE} eq "CONST") {
706 push (@consts, ParseConst($idl, $d));
708 push (@types, ParseType($d, $idl->{PROPERTIES}->{pointer_default}));
709 FindNestedTypes(\@types, $d);
715 if(defined $idl->{PROPERTIES}->{version}) {
716 my @if_version = split(/\./, $idl->{PROPERTIES}->{version});
717 if ($if_version[0] == $idl->{PROPERTIES}->{version}) {
718 $version = $idl->{PROPERTIES}->{version};
720 $version = $if_version[1] << 16 | $if_version[0];
724 # If no endpoint is set, default to the interface name as a named pipe
725 if (!defined $idl->{PROPERTIES}->{endpoint}) {
726 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME} . "]\"";
728 @endpoints = split /,/, $idl->{PROPERTIES}->{endpoint};
732 NAME => $idl->{NAME},
733 UUID => lc(has_property($idl, "uuid")),
736 PROPERTIES => $idl->{PROPERTIES},
737 FUNCTIONS => \@functions,
740 ENDPOINTS => \@endpoints
744 # Convert a IDL tree to a NDR tree
745 # Gives a result tree describing all that's necessary for easily generating
746 # NDR parsers / generators
751 return undef unless (defined($idl));
753 Parse::Pidl::NDR::Validate($idl);
758 ($_->{TYPE} eq "CPP_QUOTE") && push(@ndr, $_);
759 ($_->{TYPE} eq "INTERFACE") && push(@ndr, ParseInterface($_));
760 ($_->{TYPE} eq "IMPORT") && push(@ndr, $_);
773 foreach my $l (@{$e->{LEVELS}}) {
774 return $l if ($seen);
775 ($seen = 1) if ($l == $fl);
786 foreach my $l (@{$e->{LEVELS}}) {
787 (return $prev) if ($l == $fl);
794 sub ContainsString($)
798 foreach my $l (@{$e->{LEVELS}}) {
799 return 1 if ($l->{TYPE} eq "ARRAY" and $l->{IS_ZERO_TERMINATED});
805 sub ContainsDeferred($$)
809 return 1 if ($l->{CONTAINS_DEFERRED});
811 while ($l = GetNextLevel($e,$l))
813 return 1 if ($l->{IS_DEFERRED});
814 return 1 if ($l->{CONTAINS_DEFERRED});
823 my $name = "<ANONYMOUS>";
825 $name = $e->{NAME} if defined($e->{NAME});
827 if (defined($e->{PARENT}) and defined($e->{PARENT}->{NAME})) {
828 return "$e->{PARENT}->{NAME}.$name";
831 if (defined($e->{PARENT}) and
832 defined($e->{PARENT}->{PARENT}) and
833 defined($e->{PARENT}->{PARENT}->{NAME})) {
834 return "$e->{PARENT}->{PARENT}->{NAME}.$name";
840 ###################################
841 # find a sibling var in a structure
845 my($fn) = $e->{PARENT};
847 if ($name =~ /\*(.*)/) {
851 for my $e2 (@{$fn->{ELEMENTS}}) {
852 return $e2 if ($e2->{NAME} eq $name);
858 my %property_list = (
860 "helpstring" => ["INTERFACE", "FUNCTION"],
861 "version" => ["INTERFACE"],
862 "uuid" => ["INTERFACE"],
863 "endpoint" => ["INTERFACE"],
864 "pointer_default" => ["INTERFACE"],
865 "helper" => ["INTERFACE"],
866 "pyhelper" => ["INTERFACE"],
867 "authservice" => ["INTERFACE"],
868 "restricted" => ["INTERFACE"],
871 "object" => ["INTERFACE"],
872 "local" => ["INTERFACE", "FUNCTION"],
873 "iid_is" => ["ELEMENT"],
874 "call_as" => ["FUNCTION"],
875 "idempotent" => ["FUNCTION"],
878 "noopnum" => ["FUNCTION"],
880 "out" => ["ELEMENT"],
881 "async" => ["FUNCTION"],
884 "ref" => ["ELEMENT"],
885 "ptr" => ["ELEMENT"],
886 "unique" => ["ELEMENT"],
887 "ignore" => ["ELEMENT"],
888 "relative" => ["ELEMENT"],
889 "null_is_ffffffff" => ["ELEMENT"],
890 "relative_base" => ["TYPEDEF", "STRUCT", "UNION"],
892 "gensize" => ["TYPEDEF", "STRUCT", "UNION"],
893 "value" => ["ELEMENT"],
894 "flag" => ["ELEMENT", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
897 "public" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
898 "nopush" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
899 "nopull" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
900 "nosize" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
901 "noprint" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "ELEMENT"],
902 "todo" => ["FUNCTION"],
905 "switch_is" => ["ELEMENT"],
906 "switch_type" => ["ELEMENT", "UNION"],
907 "nodiscriminant" => ["UNION"],
908 "case" => ["ELEMENT"],
909 "default" => ["ELEMENT"],
911 "represent_as" => ["ELEMENT"],
912 "transmit_as" => ["ELEMENT"],
915 "subcontext" => ["ELEMENT"],
916 "subcontext_size" => ["ELEMENT"],
917 "compression" => ["ELEMENT"],
920 "enum8bit" => ["ENUM"],
921 "enum16bit" => ["ENUM"],
922 "v1_enum" => ["ENUM"],
925 "bitmap8bit" => ["BITMAP"],
926 "bitmap16bit" => ["BITMAP"],
927 "bitmap32bit" => ["BITMAP"],
928 "bitmap64bit" => ["BITMAP"],
931 "range" => ["ELEMENT", "PIPE"],
932 "size_is" => ["ELEMENT"],
933 "string" => ["ELEMENT"],
934 "noheader" => ["ELEMENT"],
935 "charset" => ["ELEMENT"],
936 "length_is" => ["ELEMENT"],
939 #####################################################################
940 # check for unknown properties
941 sub ValidProperties($$)
945 return unless defined $e->{PROPERTIES};
947 foreach my $key (keys %{$e->{PROPERTIES}}) {
948 warning($e, el_name($e) . ": unknown property '$key'")
949 unless defined($property_list{$key});
951 fatal($e, el_name($e) . ": property '$key' not allowed on '$t'")
952 unless grep(/^$t$/, @{$property_list{$key}});
960 return $t->{NAME} if (ref($t) eq "HASH" and $t->{TYPE} eq "SCALAR");
961 my $ti = getType($t);
963 if (not defined ($ti)) {
965 } elsif ($ti->{TYPE} eq "TYPEDEF") {
966 return mapToScalar($ti->{DATA});
967 } elsif ($ti->{TYPE} eq "ENUM") {
968 return Parse::Pidl::Typelist::enum_type_fn($ti);
969 } elsif ($ti->{TYPE} eq "BITMAP") {
970 return Parse::Pidl::Typelist::bitmap_type_fn($ti);
976 #####################################################################
977 # validate an element
982 ValidProperties($e,"ELEMENT");
984 # Check whether switches are used correctly.
985 if (my $switch = has_property($e, "switch_is")) {
986 my $e2 = find_sibling($e, $switch);
987 my $type = getType($e->{TYPE});
989 if (defined($type) and $type->{DATA}->{TYPE} ne "UNION") {
990 fatal($e, el_name($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
993 if (not has_property($type->{DATA}, "nodiscriminant") and defined($e2)) {
994 my $discriminator_type = has_property($type->{DATA}, "switch_type");
995 $discriminator_type = "uint32" unless defined ($discriminator_type);
997 my $t1 = mapToScalar($discriminator_type);
999 if (not defined($t1)) {
1000 fatal($e, el_name($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
1003 my $t2 = mapToScalar($e2->{TYPE});
1004 if (not defined($t2)) {
1005 fatal($e, el_name($e) . ": unable to map variable used for switch_is() to scalar");
1009 warning($e, el_name($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
1014 if (has_property($e, "subcontext") and has_property($e, "represent_as")) {
1015 fatal($e, el_name($e) . " : subcontext() and represent_as() can not be used on the same element");
1018 if (has_property($e, "subcontext") and has_property($e, "transmit_as")) {
1019 fatal($e, el_name($e) . " : subcontext() and transmit_as() can not be used on the same element");
1022 if (has_property($e, "represent_as") and has_property($e, "transmit_as")) {
1023 fatal($e, el_name($e) . " : represent_as() and transmit_as() can not be used on the same element");
1026 if (has_property($e, "represent_as") and has_property($e, "value")) {
1027 fatal($e, el_name($e) . " : represent_as() and value() can not be used on the same element");
1030 if (has_property($e, "subcontext")) {
1031 warning($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
1034 if (defined (has_property($e, "subcontext_size")) and not defined(has_property($e, "subcontext"))) {
1035 fatal($e, el_name($e) . " : subcontext_size() on non-subcontext element");
1038 if (defined (has_property($e, "compression")) and not defined(has_property($e, "subcontext"))) {
1039 fatal($e, el_name($e) . " : compression() on non-subcontext element");
1042 if (!$e->{POINTERS} && (
1043 has_property($e, "ptr") or
1044 has_property($e, "unique") or
1045 has_property($e, "relative") or
1046 has_property($e, "ref"))) {
1047 fatal($e, el_name($e) . " : pointer properties on non-pointer element\n");
1051 #####################################################################
1057 ValidProperties($enum, "ENUM");
1060 #####################################################################
1066 ValidProperties($bitmap, "BITMAP");
1069 #####################################################################
1073 my($struct) = shift;
1075 ValidProperties($struct, "STRUCT");
1077 return unless defined($struct->{ELEMENTS});
1079 foreach my $e (@{$struct->{ELEMENTS}}) {
1080 $e->{PARENT} = $struct;
1085 #####################################################################
1091 ValidProperties($union,"UNION");
1093 if (has_property($union->{PARENT}, "nodiscriminant") and
1094 has_property($union->{PARENT}, "switch_type")) {
1095 fatal($union->{PARENT}, $union->{PARENT}->{NAME} . ": switch_type(" . $union->{PARENT}->{PROPERTIES}->{switch_type} . ") on union without discriminant");
1098 return unless defined($union->{ELEMENTS});
1100 foreach my $e (@{$union->{ELEMENTS}}) {
1101 $e->{PARENT} = $union;
1103 if (defined($e->{PROPERTIES}->{default}) and
1104 defined($e->{PROPERTIES}->{case})) {
1105 fatal($e, "Union member $e->{NAME} can not have both default and case properties!");
1108 unless (defined ($e->{PROPERTIES}->{default}) or
1109 defined ($e->{PROPERTIES}->{case})) {
1110 fatal($e, "Union member $e->{NAME} must have default or case property");
1113 if (has_property($e, "ref")) {
1114 fatal($e, el_name($e) . ": embedded ref pointers are not supported yet\n");
1122 #####################################################################
1127 my $data = $pipe->{DATA};
1129 ValidProperties($pipe, "PIPE");
1131 fatal($pipe, $pipe->{NAME} . ": 'pipe' is not yet supported by pidl");
1134 #####################################################################
1138 my($typedef) = shift;
1139 my $data = $typedef->{DATA};
1141 ValidProperties($typedef, "TYPEDEF");
1143 $data->{PARENT} = $typedef;
1145 $data->{FILE} = $typedef->{FILE} unless defined($data->{FILE});
1146 $data->{LINE} = $typedef->{LINE} unless defined($data->{LINE});
1148 ValidType($data) if (ref($data) eq "HASH");
1151 #####################################################################
1152 # validate a function
1153 sub ValidFunction($)
1157 ValidProperties($fn,"FUNCTION");
1159 foreach my $e (@{$fn->{ELEMENTS}}) {
1161 if (has_property($e, "ref") && !$e->{POINTERS}) {
1162 fatal($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1168 #####################################################################
1175 TYPEDEF => \&ValidTypedef,
1176 STRUCT => \&ValidStruct,
1177 UNION => \&ValidUnion,
1178 ENUM => \&ValidEnum,
1179 BITMAP => \&ValidBitmap,
1181 }->{$t->{TYPE}}->($t);
1184 #####################################################################
1185 # parse the interface definitions
1186 sub ValidInterface($)
1188 my($interface) = shift;
1189 my($data) = $interface->{DATA};
1191 if (has_property($interface, "helper")) {
1192 warning($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1195 ValidProperties($interface,"INTERFACE");
1197 if (has_property($interface, "pointer_default")) {
1198 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1199 ("ref", "unique", "ptr"))) {
1200 fatal($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1204 if (has_property($interface, "object")) {
1205 if (has_property($interface, "version") &&
1206 $interface->{PROPERTIES}->{version} != 0) {
1207 fatal($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1210 if (!defined($interface->{BASE}) &&
1211 not ($interface->{NAME} eq "IUnknown")) {
1212 fatal($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1216 foreach my $d (@{$data}) {
1217 ($d->{TYPE} eq "FUNCTION") && ValidFunction($d);
1218 ($d->{TYPE} eq "TYPEDEF" or
1219 $d->{TYPE} eq "STRUCT" or
1220 $d->{TYPE} eq "UNION" or
1221 $d->{TYPE} eq "ENUM" or
1222 $d->{TYPE} eq "BITMAP" or
1223 $d->{TYPE} eq "PIPE") && ValidType($d);
1228 #####################################################################
1229 # Validate an IDL structure
1234 foreach my $x (@{$idl}) {
1235 ($x->{TYPE} eq "INTERFACE") &&
1237 ($x->{TYPE} eq "IMPORTLIB") &&
1238 fatal($x, "importlib() not supported");
1242 sub is_charset_array($$)
1246 return 0 if ($l->{TYPE} ne "ARRAY");
1248 my $nl = GetNextLevel($e,$l);
1250 return 0 unless ($nl->{TYPE} eq "DATA");
1252 return has_property($e, "charset");