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));
148 LENGTH_IS
=> $length,
149 IS_DEFERRED
=> $is_deferred,
150 IS_SURROUNDING
=> $is_surrounding,
151 IS_ZERO_TERMINATED
=> $is_string,
152 IS_VARYING
=> $is_varying,
153 IS_CONFORMANT
=> $is_conformant,
154 IS_FIXED
=> $is_fixed,
155 IS_INLINE
=> $is_inline
159 # Next, all the pointers
160 foreach my $i (1..$e->{POINTERS
}) {
161 my $level = "EMBEDDED";
162 # Top level "ref" pointers do not have a referrent identifier
163 $level = "TOP" if ($i == 1 and $e->{PARENT
}->{TYPE
} eq "FUNCTION");
167 # Only the first level gets the pointer type from the
168 # pointer property, the others get them from
169 # the pointer_default() interface property
171 # see http://msdn2.microsoft.com/en-us/library/aa378984(VS.85).aspx
172 # (Here they talk about the rightmost pointer, but testing shows
173 # they mean the leftmost pointer.)
177 $pt = pointer_type
($e);
179 $is_deferred = 1 if ($pt ne "ref" and $e->{PARENT
}->{TYPE
} eq "FUNCTION");
180 $pt = $pointer_default;
186 POINTER_INDEX
=> $pointer_idx,
187 IS_DEFERRED
=> "$is_deferred",
191 warning
($e, "top-level \[out\] pointer `$e->{NAME}' is not a \[ref\] pointer")
192 if ($i == 1 and $pt ne "ref" and
193 $e->{PARENT
}->{TYPE
} eq "FUNCTION" and
194 not has_property
($e, "in"));
198 # everything that follows will be deferred
199 $is_deferred = 1 if ($level ne "TOP");
201 my $array_size = shift @size_is;
208 if ($array_length = shift @length_is) {
211 $array_length = $array_size;
216 if (scalar(@size_is) == 0 and has_property
($e, "string") and
217 $i == $e->{POINTERS
}) {
219 $is_varying = $is_conformant = has_property
($e, "noheader")?
0:1;
220 delete($e->{PROPERTIES
}->{string
});
223 if ($array_size or $is_string) {
226 SIZE_IS
=> $array_size,
227 LENGTH_IS
=> $array_length,
228 IS_DEFERRED
=> $is_deferred,
230 IS_ZERO_TERMINATED
=> $is_string,
231 IS_VARYING
=> $is_varying,
232 IS_CONFORMANT
=> $is_conformant,
241 if (defined(has_property
($e, "subcontext"))) {
242 my $hdr_size = has_property
($e, "subcontext");
243 my $subsize = has_property
($e, "subcontext_size");
244 if (not defined($subsize)) {
249 TYPE
=> "SUBCONTEXT",
250 HEADER_SIZE
=> $hdr_size,
251 SUBCONTEXT_SIZE
=> $subsize,
252 IS_DEFERRED
=> $is_deferred,
253 COMPRESSION
=> has_property
($e, "compression"),
257 if (my $switch = has_property
($e, "switch_is")) {
260 SWITCH_IS
=> $switch,
261 IS_DEFERRED
=> $is_deferred
265 if (scalar(@size_is) > 0) {
266 fatal
($e, "size_is() on non-array element");
269 if (scalar(@length_is) > 0) {
270 fatal
($e, "length_is() on non-array element");
273 if (has_property
($e, "string")) {
274 fatal
($e, "string() attribute on non-array element");
279 DATA_TYPE
=> $e->{TYPE
},
280 IS_DEFERRED
=> $is_deferred,
281 CONTAINS_DEFERRED
=> can_contain_deferred
($e->{TYPE
}),
282 IS_SURROUNDING
=> 0 #FIXME
286 foreach (@
$order) { $_->{LEVEL_INDEX
} = $i; $i+=1; }
291 sub GetTypedefLevelTable
($$$)
293 my ($e, $data, $pointer_default) = @_;
302 foreach (@
$order) { $_->{LEVEL_INDEX
} = $i; $i+=1; }
307 #####################################################################
308 # see if a type contains any deferred data
309 sub can_contain_deferred
($)
311 sub can_contain_deferred
($);
314 return 1 unless (hasType
($type)); # assume the worst
316 $type = getType
($type);
318 return 0 if (Parse
::Pidl
::Typelist
::is_scalar
($type));
320 return can_contain_deferred
($type->{DATA
}) if ($type->{TYPE
} eq "TYPEDEF");
322 return 0 unless defined($type->{ELEMENTS
});
324 foreach (@
{$type->{ELEMENTS
}}) {
325 return 1 if ($_->{POINTERS
});
326 return 1 if (can_contain_deferred
($_->{TYPE
}));
336 return undef unless $e->{POINTERS
};
338 return "ref" if (has_property
($e, "ref"));
339 return "full" if (has_property
($e, "ptr"));
340 return "sptr" if (has_property
($e, "sptr"));
341 return "unique" if (has_property
($e, "unique"));
342 return "relative" if (has_property
($e, "relative"));
343 return "ignore" if (has_property
($e, "ignore"));
348 #####################################################################
349 # work out the correct alignment for a structure or union
350 sub find_largest_alignment
($)
355 for my $e (@
{$s->{ELEMENTS
}}) {
358 if ($e->{POINTERS
}) {
360 } elsif (has_property
($e, "subcontext")) {
362 } elsif (has_property
($e, "transmit_as")) {
363 $a = align_type
($e->{PROPERTIES
}->{transmit_as
});
365 $a = align_type
($e->{TYPE
});
368 $align = $a if ($align < $a);
374 #####################################################################
381 if (ref($e) eq "HASH" and $e->{TYPE
} eq "SCALAR") {
382 return $scalar_alignment->{$e->{NAME
}};
385 return 0 if ($e eq "EMPTY");
387 unless (hasType
($e)) {
388 # it must be an external type - all we can do is guess
389 # warning($e, "assuming alignment of unknown type '$e' is 4");
393 my $dt = getType
($e);
395 if ($dt->{TYPE
} eq "TYPEDEF") {
396 return align_type
($dt->{DATA
});
397 } elsif ($dt->{TYPE
} eq "ENUM") {
398 return align_type
(Parse
::Pidl
::Typelist
::enum_type_fn
($dt));
399 } elsif ($dt->{TYPE
} eq "BITMAP") {
400 return align_type
(Parse
::Pidl
::Typelist
::bitmap_type_fn
($dt));
401 } elsif (($dt->{TYPE
} eq "STRUCT") or ($dt->{TYPE
} eq "UNION")) {
402 # Struct/union without body: assume 4
403 return 4 unless (defined($dt->{ELEMENTS
}));
404 return find_largest_alignment
($dt);
407 die("Unknown data type type $dt->{TYPE}");
412 my ($e, $pointer_default) = @_;
414 $e->{TYPE
} = expandAlias
($e->{TYPE
});
416 if (ref($e->{TYPE
}) eq "HASH") {
417 $e->{TYPE
} = ParseType
($e->{TYPE
}, $pointer_default);
423 PROPERTIES
=> $e->{PROPERTIES
},
424 LEVELS
=> GetElementLevelTable
($e, $pointer_default),
425 REPRESENTATION_TYPE
=> ($e->{PROPERTIES
}->{represent_as
} or $e->{TYPE
}),
426 ALIGN
=> align_type
($e->{TYPE
}),
433 my ($struct, $pointer_default) = @_;
435 my $surrounding = undef;
439 NAME
=> $struct->{NAME
},
440 SURROUNDING_ELEMENT
=> undef,
442 PROPERTIES
=> $struct->{PROPERTIES
},
445 } unless defined($struct->{ELEMENTS
});
447 CheckPointerTypes
($struct, $pointer_default);
449 foreach my $x (@
{$struct->{ELEMENTS
}})
451 my $e = ParseElement
($x, $pointer_default);
452 if ($x != $struct->{ELEMENTS
}[-1] and
453 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
454 fatal
($x, "conformant member not at end of struct");
459 my $e = $elements[-1];
460 if (defined($e) and defined($e->{LEVELS
}[0]->{IS_SURROUNDING
}) and
461 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
465 if (defined $e->{TYPE
} && $e->{TYPE
} eq "string"
466 && property_matches
($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
467 $surrounding = $struct->{ELEMENTS
}[-1];
471 if ($struct->{NAME
}) {
472 $align = align_type
($struct->{NAME
});
477 NAME
=> $struct->{NAME
},
478 SURROUNDING_ELEMENT
=> $surrounding,
479 ELEMENTS
=> \
@elements,
480 PROPERTIES
=> $struct->{PROPERTIES
},
488 my ($e, $pointer_default) = @_;
491 my $switch_type = has_property
($e, "switch_type");
492 unless (defined($switch_type)) { $switch_type = "uint32"; }
493 if (has_property
($e, "nodiscriminant")) { $switch_type = undef; }
498 SWITCH_TYPE
=> $switch_type,
500 PROPERTIES
=> $e->{PROPERTIES
},
501 HAS_DEFAULT
=> $hasdefault,
503 } unless defined($e->{ELEMENTS
});
505 CheckPointerTypes
($e, $pointer_default);
507 foreach my $x (@
{$e->{ELEMENTS
}})
510 if ($x->{TYPE
} eq "EMPTY") {
511 $t = { TYPE
=> "EMPTY" };
513 $t = ParseElement
($x, $pointer_default);
515 if (has_property
($x, "default")) {
516 $t->{CASE
} = "default";
518 } elsif (defined($x->{PROPERTIES
}->{case
})) {
519 $t->{CASE
} = "case $x->{PROPERTIES}->{case}";
521 die("Union element $x->{NAME} has neither default nor case property");
529 SWITCH_TYPE
=> $switch_type,
530 ELEMENTS
=> \
@elements,
531 PROPERTIES
=> $e->{PROPERTIES
},
532 HAS_DEFAULT
=> $hasdefault,
539 my ($e, $pointer_default) = @_;
544 BASE_TYPE
=> Parse
::Pidl
::Typelist
::enum_type_fn
($e),
545 ELEMENTS
=> $e->{ELEMENTS
},
546 PROPERTIES
=> $e->{PROPERTIES
},
553 my ($e, $pointer_default) = @_;
558 BASE_TYPE
=> Parse
::Pidl
::Typelist
::bitmap_type_fn
($e),
559 ELEMENTS
=> $e->{ELEMENTS
},
560 PROPERTIES
=> $e->{PROPERTIES
},
567 my ($d, $pointer_default) = @_;
570 STRUCT
=> \
&ParseStruct
,
571 UNION
=> \
&ParseUnion
,
573 BITMAP
=> \
&ParseBitmap
,
574 TYPEDEF
=> \
&ParseTypedef
,
575 }->{$d->{TYPE
}}->($d, $pointer_default);
582 my ($d, $pointer_default) = @_;
584 if (defined($d->{DATA
}->{PROPERTIES
}) && !defined($d->{PROPERTIES
})) {
585 $d->{PROPERTIES
} = $d->{DATA
}->{PROPERTIES
};
588 my $data = ParseType
($d->{DATA
}, $pointer_default);
589 $data->{ALIGN
} = align_type
($d->{NAME
});
594 PROPERTIES
=> $d->{PROPERTIES
},
595 LEVELS
=> GetTypedefLevelTable
($d, $data, $pointer_default),
608 sub ParseFunction
($$$)
610 my ($ndr,$d,$opnum) = @_;
613 my $thisopnum = undef;
615 CheckPointerTypes
($d, "ref");
617 if (not defined($d->{PROPERTIES
}{noopnum
})) {
618 $thisopnum = ${$opnum};
622 foreach my $x (@
{$d->{ELEMENTS
}}) {
623 my $e = ParseElement
($x, $ndr->{PROPERTIES
}->{pointer_default
});
624 push (@
{$e->{DIRECTION
}}, "in") if (has_property
($x, "in"));
625 push (@
{$e->{DIRECTION
}}, "out") if (has_property
($x, "out"));
627 push (@elements, $e);
630 if ($d->{RETURN_TYPE
} ne "void") {
631 $rettype = expandAlias
($d->{RETURN_TYPE
});
635 if (has_property
($d, "async")) { $async = 1; }
642 RETURN_TYPE
=> $rettype,
643 PROPERTIES
=> $d->{PROPERTIES
},
644 ELEMENTS
=> \
@elements,
649 sub CheckPointerTypes
($$)
651 my ($s,$default) = @_;
653 return unless defined($s->{ELEMENTS
});
655 foreach my $e (@
{$s->{ELEMENTS
}}) {
656 if ($e->{POINTERS
} and not defined(pointer_type
($e))) {
657 $e->{PROPERTIES
}->{$default} = '1';
662 sub FindNestedTypes
($$)
664 sub FindNestedTypes
($$);
667 return unless defined($t->{ELEMENTS
});
668 return if ($t->{TYPE
} eq "ENUM");
669 return if ($t->{TYPE
} eq "BITMAP");
671 foreach (@
{$t->{ELEMENTS
}}) {
672 if (ref($_->{TYPE
}) eq "HASH") {
673 push (@
$l, $_->{TYPE
}) if (defined($_->{TYPE
}->{NAME
}));
674 FindNestedTypes
($l, $_->{TYPE
});
679 sub ParseInterface
($)
689 if (not has_property
($idl, "pointer_default")) {
690 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
691 # and "unique" in Microsoft Extensions mode (default)
692 $idl->{PROPERTIES
}->{pointer_default
} = "unique";
695 foreach my $d (@
{$idl->{DATA
}}) {
696 if ($d->{TYPE
} eq "FUNCTION") {
697 push (@functions, ParseFunction
($idl, $d, \
$opnum));
698 } elsif ($d->{TYPE
} eq "CONST") {
699 push (@consts, ParseConst
($idl, $d));
701 push (@types, ParseType
($d, $idl->{PROPERTIES
}->{pointer_default
}));
702 FindNestedTypes
(\
@types, $d);
708 if(defined $idl->{PROPERTIES
}->{version
}) {
709 my @if_version = split(/\./, $idl->{PROPERTIES
}->{version
});
710 if ($if_version[0] == $idl->{PROPERTIES
}->{version
}) {
711 $version = $idl->{PROPERTIES
}->{version
};
713 $version = $if_version[1] << 16 | $if_version[0];
717 # If no endpoint is set, default to the interface name as a named pipe
718 if (!defined $idl->{PROPERTIES
}->{endpoint
}) {
719 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME
} . "]\"";
721 @endpoints = split /,/, $idl->{PROPERTIES
}->{endpoint
};
725 NAME
=> $idl->{NAME
},
726 UUID
=> lc(has_property
($idl, "uuid")),
729 PROPERTIES
=> $idl->{PROPERTIES
},
730 FUNCTIONS
=> \
@functions,
733 ENDPOINTS
=> \
@endpoints
737 # Convert a IDL tree to a NDR tree
738 # Gives a result tree describing all that's necessary for easily generating
739 # NDR parsers / generators
744 return undef unless (defined($idl));
746 Parse
::Pidl
::NDR
::Validate
($idl);
751 ($_->{TYPE
} eq "CPP_QUOTE") && push(@ndr, $_);
752 ($_->{TYPE
} eq "INTERFACE") && push(@ndr, ParseInterface
($_));
753 ($_->{TYPE
} eq "IMPORT") && push(@ndr, $_);
766 foreach my $l (@
{$e->{LEVELS
}}) {
767 return $l if ($seen);
768 ($seen = 1) if ($l == $fl);
779 foreach my $l (@
{$e->{LEVELS
}}) {
780 (return $prev) if ($l == $fl);
787 sub ContainsString
($)
791 foreach my $l (@
{$e->{LEVELS
}}) {
792 return 1 if ($l->{TYPE
} eq "ARRAY" and $l->{IS_ZERO_TERMINATED
});
798 sub ContainsDeferred
($$)
802 return 1 if ($l->{CONTAINS_DEFERRED
});
804 while ($l = GetNextLevel
($e,$l))
806 return 1 if ($l->{IS_DEFERRED
});
807 return 1 if ($l->{CONTAINS_DEFERRED
});
816 my $name = "<ANONYMOUS>";
818 $name = $e->{NAME
} if defined($e->{NAME
});
820 if (defined($e->{PARENT
}) and defined($e->{PARENT
}->{NAME
})) {
821 return "$e->{PARENT}->{NAME}.$name";
824 if (defined($e->{PARENT
}) and
825 defined($e->{PARENT
}->{PARENT
}) and
826 defined($e->{PARENT
}->{PARENT
}->{NAME
})) {
827 return "$e->{PARENT}->{PARENT}->{NAME}.$name";
833 ###################################
834 # find a sibling var in a structure
838 my($fn) = $e->{PARENT
};
840 if ($name =~ /\*(.*)/) {
844 for my $e2 (@
{$fn->{ELEMENTS
}}) {
845 return $e2 if ($e2->{NAME
} eq $name);
851 my %property_list = (
853 "helpstring" => ["INTERFACE", "FUNCTION"],
854 "version" => ["INTERFACE"],
855 "uuid" => ["INTERFACE"],
856 "endpoint" => ["INTERFACE"],
857 "pointer_default" => ["INTERFACE"],
858 "helper" => ["INTERFACE"],
859 "pyhelper" => ["INTERFACE"],
860 "authservice" => ["INTERFACE"],
861 "restricted" => ["INTERFACE"],
864 "object" => ["INTERFACE"],
865 "local" => ["INTERFACE", "FUNCTION"],
866 "iid_is" => ["ELEMENT"],
867 "call_as" => ["FUNCTION"],
868 "idempotent" => ["FUNCTION"],
871 "noopnum" => ["FUNCTION"],
873 "out" => ["ELEMENT"],
874 "async" => ["FUNCTION"],
877 "ref" => ["ELEMENT"],
878 "ptr" => ["ELEMENT"],
879 "unique" => ["ELEMENT"],
880 "ignore" => ["ELEMENT"],
881 "relative" => ["ELEMENT"],
882 "null_is_ffffffff" => ["ELEMENT"],
883 "relative_base" => ["TYPEDEF", "STRUCT", "UNION"],
885 "gensize" => ["TYPEDEF", "STRUCT", "UNION"],
886 "value" => ["ELEMENT"],
887 "flag" => ["ELEMENT", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
890 "public" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
891 "nopush" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
892 "nopull" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
893 "nosize" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
894 "noprint" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "ELEMENT"],
895 "todo" => ["FUNCTION"],
898 "switch_is" => ["ELEMENT"],
899 "switch_type" => ["ELEMENT", "UNION"],
900 "nodiscriminant" => ["UNION"],
901 "case" => ["ELEMENT"],
902 "default" => ["ELEMENT"],
904 "represent_as" => ["ELEMENT"],
905 "transmit_as" => ["ELEMENT"],
908 "subcontext" => ["ELEMENT"],
909 "subcontext_size" => ["ELEMENT"],
910 "compression" => ["ELEMENT"],
913 "enum8bit" => ["ENUM"],
914 "enum16bit" => ["ENUM"],
915 "v1_enum" => ["ENUM"],
918 "bitmap8bit" => ["BITMAP"],
919 "bitmap16bit" => ["BITMAP"],
920 "bitmap32bit" => ["BITMAP"],
921 "bitmap64bit" => ["BITMAP"],
924 "range" => ["ELEMENT"],
925 "size_is" => ["ELEMENT"],
926 "string" => ["ELEMENT"],
927 "noheader" => ["ELEMENT"],
928 "charset" => ["ELEMENT"],
929 "length_is" => ["ELEMENT"],
932 #####################################################################
933 # check for unknown properties
934 sub ValidProperties
($$)
938 return unless defined $e->{PROPERTIES
};
940 foreach my $key (keys %{$e->{PROPERTIES
}}) {
941 warning
($e, el_name
($e) . ": unknown property '$key'")
942 unless defined($property_list{$key});
944 fatal
($e, el_name
($e) . ": property '$key' not allowed on '$t'")
945 unless grep(/^$t$/, @
{$property_list{$key}});
953 return $t->{NAME
} if (ref($t) eq "HASH" and $t->{TYPE
} eq "SCALAR");
954 my $ti = getType
($t);
956 if (not defined ($ti)) {
958 } elsif ($ti->{TYPE
} eq "TYPEDEF") {
959 return mapToScalar
($ti->{DATA
});
960 } elsif ($ti->{TYPE
} eq "ENUM") {
961 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti);
962 } elsif ($ti->{TYPE
} eq "BITMAP") {
963 return Parse
::Pidl
::Typelist
::bitmap_type_fn
($ti);
969 #####################################################################
970 # validate an element
975 ValidProperties
($e,"ELEMENT");
977 # Check whether switches are used correctly.
978 if (my $switch = has_property
($e, "switch_is")) {
979 my $e2 = find_sibling
($e, $switch);
980 my $type = getType
($e->{TYPE
});
982 if (defined($type) and $type->{DATA
}->{TYPE
} ne "UNION") {
983 fatal
($e, el_name
($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
986 if (not has_property
($type->{DATA
}, "nodiscriminant") and defined($e2)) {
987 my $discriminator_type = has_property
($type->{DATA
}, "switch_type");
988 $discriminator_type = "uint32" unless defined ($discriminator_type);
990 my $t1 = mapToScalar
($discriminator_type);
992 if (not defined($t1)) {
993 fatal
($e, el_name
($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
996 my $t2 = mapToScalar
($e2->{TYPE
});
997 if (not defined($t2)) {
998 fatal
($e, el_name
($e) . ": unable to map variable used for switch_is() to scalar");
1002 warning
($e, el_name
($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
1007 if (has_property
($e, "subcontext") and has_property
($e, "represent_as")) {
1008 fatal
($e, el_name
($e) . " : subcontext() and represent_as() can not be used on the same element");
1011 if (has_property
($e, "subcontext") and has_property
($e, "transmit_as")) {
1012 fatal
($e, el_name
($e) . " : subcontext() and transmit_as() can not be used on the same element");
1015 if (has_property
($e, "represent_as") and has_property
($e, "transmit_as")) {
1016 fatal
($e, el_name
($e) . " : represent_as() and transmit_as() can not be used on the same element");
1019 if (has_property
($e, "represent_as") and has_property
($e, "value")) {
1020 fatal
($e, el_name
($e) . " : represent_as() and value() can not be used on the same element");
1023 if (has_property
($e, "subcontext")) {
1024 warning
($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
1027 if (defined (has_property
($e, "subcontext_size")) and not defined(has_property
($e, "subcontext"))) {
1028 fatal
($e, el_name
($e) . " : subcontext_size() on non-subcontext element");
1031 if (defined (has_property
($e, "compression")) and not defined(has_property
($e, "subcontext"))) {
1032 fatal
($e, el_name
($e) . " : compression() on non-subcontext element");
1035 if (!$e->{POINTERS
} && (
1036 has_property
($e, "ptr") or
1037 has_property
($e, "unique") or
1038 has_property
($e, "relative") or
1039 has_property
($e, "ref"))) {
1040 fatal
($e, el_name
($e) . " : pointer properties on non-pointer element\n");
1044 #####################################################################
1050 ValidProperties
($enum, "ENUM");
1053 #####################################################################
1059 ValidProperties
($bitmap, "BITMAP");
1062 #####################################################################
1066 my($struct) = shift;
1068 ValidProperties
($struct, "STRUCT");
1070 return unless defined($struct->{ELEMENTS
});
1072 foreach my $e (@
{$struct->{ELEMENTS
}}) {
1073 $e->{PARENT
} = $struct;
1078 #####################################################################
1084 ValidProperties
($union,"UNION");
1086 if (has_property
($union->{PARENT
}, "nodiscriminant") and
1087 has_property
($union->{PARENT
}, "switch_type")) {
1088 fatal
($union->{PARENT
}, $union->{PARENT
}->{NAME
} . ": switch_type(" . $union->{PARENT
}->{PROPERTIES
}->{switch_type
} . ") on union without discriminant");
1091 return unless defined($union->{ELEMENTS
});
1093 foreach my $e (@
{$union->{ELEMENTS
}}) {
1094 $e->{PARENT
} = $union;
1096 if (defined($e->{PROPERTIES
}->{default}) and
1097 defined($e->{PROPERTIES
}->{case
})) {
1098 fatal
($e, "Union member $e->{NAME} can not have both default and case properties!");
1101 unless (defined ($e->{PROPERTIES
}->{default}) or
1102 defined ($e->{PROPERTIES
}->{case
})) {
1103 fatal
($e, "Union member $e->{NAME} must have default or case property");
1106 if (has_property
($e, "ref")) {
1107 fatal
($e, el_name
($e) . ": embedded ref pointers are not supported yet\n");
1115 #####################################################################
1119 my($typedef) = shift;
1120 my $data = $typedef->{DATA
};
1122 ValidProperties
($typedef, "TYPEDEF");
1124 $data->{PARENT
} = $typedef;
1126 $data->{FILE
} = $typedef->{FILE
} unless defined($data->{FILE
});
1127 $data->{LINE
} = $typedef->{LINE
} unless defined($data->{LINE
});
1129 ValidType
($data) if (ref($data) eq "HASH");
1132 #####################################################################
1133 # validate a function
1134 sub ValidFunction
($)
1138 ValidProperties
($fn,"FUNCTION");
1140 foreach my $e (@
{$fn->{ELEMENTS
}}) {
1142 if (has_property
($e, "ref") && !$e->{POINTERS
}) {
1143 fatal
($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1149 #####################################################################
1156 TYPEDEF
=> \
&ValidTypedef
,
1157 STRUCT
=> \
&ValidStruct
,
1158 UNION
=> \
&ValidUnion
,
1159 ENUM
=> \
&ValidEnum
,
1160 BITMAP
=> \
&ValidBitmap
1161 }->{$t->{TYPE
}}->($t);
1164 #####################################################################
1165 # parse the interface definitions
1166 sub ValidInterface
($)
1168 my($interface) = shift;
1169 my($data) = $interface->{DATA
};
1171 if (has_property
($interface, "helper")) {
1172 warning
($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1175 ValidProperties
($interface,"INTERFACE");
1177 if (has_property
($interface, "pointer_default")) {
1178 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1179 ("ref", "unique", "ptr"))) {
1180 fatal
($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1184 if (has_property
($interface, "object")) {
1185 if (has_property
($interface, "version") &&
1186 $interface->{PROPERTIES
}->{version
} != 0) {
1187 fatal
($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1190 if (!defined($interface->{BASE
}) &&
1191 not ($interface->{NAME
} eq "IUnknown")) {
1192 fatal
($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1196 foreach my $d (@
{$data}) {
1197 ($d->{TYPE
} eq "FUNCTION") && ValidFunction
($d);
1198 ($d->{TYPE
} eq "TYPEDEF" or
1199 $d->{TYPE
} eq "STRUCT" or
1200 $d->{TYPE
} eq "UNION" or
1201 $d->{TYPE
} eq "ENUM" or
1202 $d->{TYPE
} eq "BITMAP") && ValidType
($d);
1207 #####################################################################
1208 # Validate an IDL structure
1213 foreach my $x (@
{$idl}) {
1214 ($x->{TYPE
} eq "INTERFACE") &&
1216 ($x->{TYPE
} eq "IMPORTLIB") &&
1217 fatal
($x, "importlib() not supported");
1221 sub is_charset_array
($$)
1225 return 0 if ($l->{TYPE
} ne "ARRAY");
1227 my $nl = GetNextLevel
($e,$l);
1229 return 0 unless ($nl->{TYPE
} eq "DATA");
1231 return has_property
($e, "charset");