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 CONVERT_TO
=> has_property
($e, ""),
261 CONVERT_FROM
=> has_property
($e, ""),
262 DATA_TYPE
=> $e->{TYPE
},
263 IS_DEFERRED
=> $is_deferred,
264 CONTAINS_DEFERRED
=> can_contain_deferred
($e),
265 IS_SURROUNDING
=> 0 #FIXME
269 foreach (@
$order) { $_->{LEVEL_INDEX
} = $i; $i+=1; }
274 #####################################################################
275 # see if a type contains any deferred data
276 sub can_contain_deferred
280 return 0 if (Parse
::Pidl
::Typelist
::is_scalar
($e->{TYPE
}));
281 return 1 unless (hasType
($e->{TYPE
})); # assume the worst
283 my $type = getType
($e->{TYPE
});
285 foreach my $x (@
{$type->{DATA
}->{ELEMENTS
}}) {
286 return 1 if ($x->{POINTERS
});
287 return 1 if (can_contain_deferred
($x));
297 return undef unless $e->{POINTERS
};
299 return "ref" if (has_property
($e, "ref"));
300 return "full" if (has_property
($e, "ptr"));
301 return "sptr" if (has_property
($e, "sptr"));
302 return "unique" if (has_property
($e, "unique"));
303 return "relative" if (has_property
($e, "relative"));
304 return "ignore" if (has_property
($e, "ignore"));
309 #####################################################################
310 # work out the correct alignment for a structure or union
311 sub find_largest_alignment
($)
316 for my $e (@
{$s->{ELEMENTS
}}) {
319 if ($e->{POINTERS
}) {
321 } elsif (has_property
($e, "subcontext")) {
323 } elsif (has_property
($e, "transmit_as")) {
324 $a = align_type
($e->{PROPERTIES
}->{transmit_as
});
326 $a = align_type
($e->{TYPE
});
329 $align = $a if ($align < $a);
335 #####################################################################
342 unless (hasType
($e)) {
343 # it must be an external type - all we can do is guess
344 # print "Warning: assuming alignment of unknown type '$e' is 4\n";
348 my $dt = getType
($e)->{DATA
};
350 if ($dt->{TYPE
} eq "ENUM") {
351 return align_type
(Parse
::Pidl
::Typelist
::enum_type_fn
($dt));
352 } elsif ($dt->{TYPE
} eq "BITMAP") {
353 return align_type
(Parse
::Pidl
::Typelist
::bitmap_type_fn
($dt));
354 } elsif (($dt->{TYPE
} eq "STRUCT") or ($dt->{TYPE
} eq "UNION")) {
355 return find_largest_alignment
($dt);
356 } elsif ($dt->{TYPE
} eq "SCALAR") {
357 return $scalar_alignment->{$dt->{NAME
}};
360 die("Unknown data type type $dt->{TYPE}");
367 $e->{TYPE
} = expandAlias
($e->{TYPE
});
372 PROPERTIES
=> $e->{PROPERTIES
},
373 LEVELS
=> GetElementLevelTable
($e),
374 REPRESENTATION_TYPE
=> ($e->{PROPERTIES
}->{represent_as
} or $e->{TYPE
}),
375 ALIGN
=> align_type
($e->{TYPE
}),
382 my ($ndr,$struct) = @_;
384 my $surrounding = undef;
387 foreach my $x (@
{$struct->{ELEMENTS
}})
389 my $e = ParseElement
($x);
390 if ($x != $struct->{ELEMENTS
}[-1] and
391 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
392 fatal
($x, "conformant member not at end of struct");
397 my $e = $elements[-1];
398 if (defined($e) and defined($e->{LEVELS
}[0]->{IS_SURROUNDING
}) and
399 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
403 if (defined $e->{TYPE
} && $e->{TYPE
} eq "string"
404 && property_matches
($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
405 $surrounding = $struct->{ELEMENTS
}[-1];
409 if ($struct->{NAME
}) {
410 $align = align_type
($struct->{NAME
});
415 NAME
=> $struct->{NAME
},
416 SURROUNDING_ELEMENT
=> $surrounding,
417 ELEMENTS
=> \
@elements,
418 PROPERTIES
=> $struct->{PROPERTIES
},
428 my $switch_type = has_property
($e, "switch_type");
429 unless (defined($switch_type)) { $switch_type = "uint32"; }
431 if (has_property
($e, "nodiscriminant")) { $switch_type = undef; }
434 foreach my $x (@
{$e->{ELEMENTS
}})
437 if ($x->{TYPE
} eq "EMPTY") {
438 $t = { TYPE
=> "EMPTY" };
440 $t = ParseElement
($x);
442 if (has_property
($x, "default")) {
443 $t->{CASE
} = "default";
445 } elsif (defined($x->{PROPERTIES
}->{case
})) {
446 $t->{CASE
} = "case $x->{PROPERTIES}->{case}";
448 die("Union element $x->{NAME} has neither default nor case property");
456 SWITCH_TYPE
=> $switch_type,
457 ELEMENTS
=> \
@elements,
458 PROPERTIES
=> $e->{PROPERTIES
},
459 HAS_DEFAULT
=> $hasdefault,
471 BASE_TYPE
=> Parse
::Pidl
::Typelist
::enum_type_fn
($e),
472 ELEMENTS
=> $e->{ELEMENTS
},
473 PROPERTIES
=> $e->{PROPERTIES
},
485 BASE_TYPE
=> Parse
::Pidl
::Typelist
::bitmap_type_fn
($e),
486 ELEMENTS
=> $e->{ELEMENTS
},
487 PROPERTIES
=> $e->{PROPERTIES
},
496 if ($d->{TYPE
} eq "STRUCT" or $d->{TYPE
} eq "UNION") {
497 CheckPointerTypes
($d, $ndr->{PROPERTIES
}->{pointer_default
});
501 STRUCT
=> \
&ParseStruct
,
502 UNION
=> \
&ParseUnion
,
504 BITMAP
=> \
&ParseBitmap
,
505 TYPEDEF
=> \
&ParseTypedef
,
506 }->{$d->{TYPE
}}->($ndr, $d);
515 if (defined($d->{DATA
}->{PROPERTIES
}) && !defined($d->{PROPERTIES
})) {
516 $d->{PROPERTIES
} = $d->{DATA
}->{PROPERTIES
};
519 my $data = ParseType
($ndr, $d->{DATA
});
520 $data->{ALIGN
} = align_type
($d->{NAME
});
525 PROPERTIES
=> $d->{PROPERTIES
},
538 sub ParseFunction
($$$)
540 my ($ndr,$d,$opnum) = @_;
543 my $thisopnum = undef;
545 CheckPointerTypes
($d, $ndr->{PROPERTIES
}->{pointer_default_top
});
547 if (not defined($d->{PROPERTIES
}{noopnum
})) {
548 $thisopnum = ${$opnum};
552 foreach my $x (@
{$d->{ELEMENTS
}}) {
553 my $e = ParseElement
($x);
554 push (@
{$e->{DIRECTION
}}, "in") if (has_property
($x, "in"));
555 push (@
{$e->{DIRECTION
}}, "out") if (has_property
($x, "out"));
557 push (@elements, $e);
560 if ($d->{RETURN_TYPE
} ne "void") {
561 $rettype = expandAlias
($d->{RETURN_TYPE
});
565 if (has_property
($d, "async")) { $async = 1; }
572 RETURN_TYPE
=> $rettype,
573 PROPERTIES
=> $d->{PROPERTIES
},
574 ELEMENTS
=> \
@elements,
579 sub CheckPointerTypes
($$)
581 my ($s,$default) = @_;
583 foreach my $e (@
{$s->{ELEMENTS
}}) {
584 if ($e->{POINTERS
} and not defined(pointer_type
($e))) {
585 $e->{PROPERTIES
}->{$default} = 1;
590 sub ParseInterface
($)
601 if (not has_property
($idl, "pointer_default")) {
602 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
603 # and "unique" in Microsoft Extensions mode (default)
604 $idl->{PROPERTIES
}->{pointer_default
} = "unique";
607 if (not has_property
($idl, "pointer_default_top")) {
608 $idl->{PROPERTIES
}->{pointer_default_top
} = "ref";
610 warning
($idl, "pointer_default_top() is a pidl extension and should not be used");
613 foreach my $d (@
{$idl->{DATA
}}) {
614 if ($d->{TYPE
} eq "DECLARE") {
615 push (@declares, $d);
616 } elsif ($d->{TYPE
} eq "FUNCTION") {
617 push (@functions, ParseFunction
($idl, $d, \
$opnum));
618 } elsif ($d->{TYPE
} eq "CONST") {
619 push (@consts, ParseConst
($idl, $d));
621 push (@types, ParseType
($idl, $d));
627 if(defined $idl->{PROPERTIES
}->{version
}) {
628 $version = $idl->{PROPERTIES
}->{version
};
631 # If no endpoint is set, default to the interface name as a named pipe
632 if (!defined $idl->{PROPERTIES
}->{endpoint
}) {
633 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME
} . "]\"";
635 @endpoints = split / /, $idl->{PROPERTIES
}->{endpoint
};
639 NAME
=> $idl->{NAME
},
640 UUID
=> lc(has_property
($idl, "uuid")),
643 PROPERTIES
=> $idl->{PROPERTIES
},
644 FUNCTIONS
=> \
@functions,
647 DECLARES
=> \
@declares,
648 ENDPOINTS
=> \
@endpoints
652 # Convert a IDL tree to a NDR tree
653 # Gives a result tree describing all that's necessary for easily generating
654 # NDR parsers / generators
659 return undef unless (defined($idl));
661 Parse
::Pidl
::NDR
::Validate
($idl);
666 ($_->{TYPE
} eq "INTERFACE") && push(@ndr, ParseInterface
($_));
667 ($_->{TYPE
} eq "IMPORT") && push(@ndr, $_);
680 foreach my $l (@
{$e->{LEVELS
}}) {
681 return $l if ($seen);
682 ($seen = 1) if ($l == $fl);
693 foreach my $l (@
{$e->{LEVELS
}}) {
694 (return $prev) if ($l == $fl);
701 sub ContainsString
($)
705 foreach my $l (@
{$e->{LEVELS
}}) {
706 return 1 if ($l->{TYPE
} eq "ARRAY" and $l->{IS_ZERO_TERMINATED
});
712 sub ContainsDeferred
($$)
716 return 1 if ($l->{CONTAINS_DEFERRED
});
718 while ($l = GetNextLevel
($e,$l))
720 return 1 if ($l->{IS_DEFERRED
});
721 return 1 if ($l->{CONTAINS_DEFERRED
});
731 if ($e->{PARENT
} && $e->{PARENT
}->{NAME
}) {
732 return "$e->{PARENT}->{NAME}.$e->{NAME}";
735 if ($e->{PARENT
} && $e->{PARENT
}->{PARENT
}->{NAME
}) {
736 return "$e->{PARENT}->{PARENT}->{NAME}.$e->{NAME}";
740 return "$e->{PARENT}->{NAME}.$e->{NAME}";
746 ###################################
747 # find a sibling var in a structure
751 my($fn) = $e->{PARENT
};
753 if ($name =~ /\*(.*)/) {
757 for my $e2 (@
{$fn->{ELEMENTS
}}) {
758 return $e2 if ($e2->{NAME
} eq $name);
764 my %property_list = (
766 "helpstring" => ["INTERFACE", "FUNCTION"],
767 "version" => ["INTERFACE"],
768 "uuid" => ["INTERFACE"],
769 "endpoint" => ["INTERFACE"],
770 "pointer_default" => ["INTERFACE"],
771 "pointer_default_top" => ["INTERFACE"],
772 "helper" => ["INTERFACE"],
773 "authservice" => ["INTERFACE"],
776 "object" => ["INTERFACE"],
777 "local" => ["INTERFACE", "FUNCTION"],
778 "iid_is" => ["ELEMENT"],
779 "call_as" => ["FUNCTION"],
780 "idempotent" => ["FUNCTION"],
783 "noopnum" => ["FUNCTION"],
785 "out" => ["ELEMENT"],
786 "async" => ["FUNCTION"],
789 "ref" => ["ELEMENT"],
790 "ptr" => ["ELEMENT"],
791 "unique" => ["ELEMENT"],
792 "ignore" => ["ELEMENT"],
793 "relative" => ["ELEMENT"],
794 "relative_base" => ["TYPEDEF"],
796 "gensize" => ["TYPEDEF"],
797 "value" => ["ELEMENT"],
798 "flag" => ["ELEMENT", "TYPEDEF"],
801 "public" => ["FUNCTION", "TYPEDEF"],
802 "nopush" => ["FUNCTION", "TYPEDEF"],
803 "nopull" => ["FUNCTION", "TYPEDEF"],
804 "nosize" => ["FUNCTION", "TYPEDEF"],
805 "noprint" => ["FUNCTION", "TYPEDEF"],
806 "noejs" => ["FUNCTION", "TYPEDEF"],
809 "switch_is" => ["ELEMENT"],
810 "switch_type" => ["ELEMENT", "TYPEDEF"],
811 "nodiscriminant" => ["TYPEDEF"],
812 "case" => ["ELEMENT"],
813 "default" => ["ELEMENT"],
815 "represent_as" => ["ELEMENT"],
816 "transmit_as" => ["ELEMENT"],
819 "subcontext" => ["ELEMENT"],
820 "subcontext_size" => ["ELEMENT"],
821 "compression" => ["ELEMENT"],
824 "enum8bit" => ["TYPEDEF"],
825 "enum16bit" => ["TYPEDEF"],
826 "v1_enum" => ["TYPEDEF"],
829 "bitmap8bit" => ["TYPEDEF"],
830 "bitmap16bit" => ["TYPEDEF"],
831 "bitmap32bit" => ["TYPEDEF"],
832 "bitmap64bit" => ["TYPEDEF"],
835 "range" => ["ELEMENT"],
836 "size_is" => ["ELEMENT"],
837 "string" => ["ELEMENT"],
838 "noheader" => ["ELEMENT"],
839 "charset" => ["ELEMENT"],
840 "length_is" => ["ELEMENT"],
843 #####################################################################
844 # check for unknown properties
845 sub ValidProperties
($$)
849 return unless defined $e->{PROPERTIES
};
851 foreach my $key (keys %{$e->{PROPERTIES
}}) {
852 warning
($e, el_name
($e) . ": unknown property '$key'")
853 unless defined($property_list{$key});
855 fatal
($e, el_name
($e) . ": property '$key' not allowed on '$t'")
856 unless grep($t, @
{$property_list{$key}});
863 my $ti = getType
($t);
865 if (not defined ($ti)) {
867 } elsif ($ti->{DATA
}->{TYPE
} eq "ENUM") {
868 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti->{DATA
});
869 } elsif ($ti->{DATA
}->{TYPE
} eq "BITMAP") {
870 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti->{DATA
});
871 } elsif ($ti->{DATA
}->{TYPE
} eq "SCALAR") {
878 #####################################################################
879 # validate an element
884 ValidProperties
($e,"ELEMENT");
886 # Check whether switches are used correctly.
887 if (my $switch = has_property
($e, "switch_is")) {
888 my $e2 = find_sibling
($e, $switch);
889 my $type = getType
($e->{TYPE
});
891 if (defined($type) and $type->{DATA
}->{TYPE
} ne "UNION") {
892 fatal
($e, el_name
($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
895 if (not has_property
($type->{DATA
}, "nodiscriminant") and defined($e2)) {
896 my $discriminator_type = has_property
($type->{DATA
}, "switch_type");
897 $discriminator_type = "uint32" unless defined ($discriminator_type);
899 my $t1 = mapToScalar
($discriminator_type);
901 if (not defined($t1)) {
902 fatal
($e, el_name
($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
905 my $t2 = mapToScalar
($e2->{TYPE
});
906 if (not defined($t2)) {
907 fatal
($e, el_name
($e) . ": unable to map variable used for switch_is() to scalar");
911 warning
($e, el_name
($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
916 if (has_property
($e, "subcontext") and has_property
($e, "represent_as")) {
917 fatal
($e, el_name
($e) . " : subcontext() and represent_as() can not be used on the same element");
920 if (has_property
($e, "subcontext") and has_property
($e, "transmit_as")) {
921 fatal
($e, el_name
($e) . " : subcontext() and transmit_as() can not be used on the same element");
924 if (has_property
($e, "represent_as") and has_property
($e, "transmit_as")) {
925 fatal
($e, el_name
($e) . " : represent_as() and transmit_as() can not be used on the same element");
928 if (has_property
($e, "represent_as") and has_property
($e, "value")) {
929 fatal
($e, el_name
($e) . " : represent_as() and value() can not be used on the same element");
932 if (has_property
($e, "subcontext")) {
933 warning
($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
936 if (defined (has_property
($e, "subcontext_size")) and not defined(has_property
($e, "subcontext"))) {
937 fatal
($e, el_name
($e) . " : subcontext_size() on non-subcontext element");
940 if (defined (has_property
($e, "compression")) and not defined(has_property
($e, "subcontext"))) {
941 fatal
($e, el_name
($e) . " : compression() on non-subcontext element");
944 if (!$e->{POINTERS
} && (
945 has_property
($e, "ptr") or
946 has_property
($e, "unique") or
947 has_property
($e, "relative") or
948 has_property
($e, "ref"))) {
949 fatal
($e, el_name
($e) . " : pointer properties on non-pointer element\n");
953 #####################################################################
959 ValidProperties
($enum, "ENUM");
962 #####################################################################
968 ValidProperties
($bitmap, "BITMAP");
971 #####################################################################
977 ValidProperties
($struct, "STRUCT");
979 foreach my $e (@
{$struct->{ELEMENTS
}}) {
980 $e->{PARENT
} = $struct;
985 #####################################################################
991 ValidProperties
($union,"UNION");
993 if (has_property
($union->{PARENT
}, "nodiscriminant") and has_property
($union->{PARENT
}, "switch_type")) {
994 fatal
($union->{PARENT
}, $union->{PARENT
}->{NAME
} . ": switch_type() on union without discriminant");
997 foreach my $e (@
{$union->{ELEMENTS
}}) {
998 $e->{PARENT
} = $union;
1000 if (defined($e->{PROPERTIES
}->{default}) and
1001 defined($e->{PROPERTIES
}->{case
})) {
1002 fatal
($e, "Union member $e->{NAME} can not have both default and case properties!");
1005 unless (defined ($e->{PROPERTIES
}->{default}) or
1006 defined ($e->{PROPERTIES
}->{case
})) {
1007 fatal
($e, "Union member $e->{NAME} must have default or case property");
1010 if (has_property
($e, "ref")) {
1011 fatal
($e, el_name
($e) . " : embedded ref pointers are not supported yet\n");
1019 #####################################################################
1023 my($typedef) = shift;
1024 my $data = $typedef->{DATA
};
1026 ValidProperties
($typedef, "TYPEDEF");
1028 $data->{PARENT
} = $typedef;
1030 ValidType
($data) if (ref($data) eq "HASH");
1033 #####################################################################
1034 # validate a function
1035 sub ValidFunction
($)
1039 ValidProperties
($fn,"FUNCTION");
1041 foreach my $e (@
{$fn->{ELEMENTS
}}) {
1043 if (has_property
($e, "ref") && !$e->{POINTERS
}) {
1044 fatal
($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1050 #####################################################################
1057 TYPEDEF
=> \
&ValidTypedef
,
1058 STRUCT
=> \
&ValidStruct
,
1059 UNION
=> \
&ValidUnion
,
1060 ENUM
=> \
&ValidEnum
,
1061 BITMAP
=> \
&ValidBitmap
1062 }->{$t->{TYPE
}}->($t);
1065 #####################################################################
1066 # parse the interface definitions
1067 sub ValidInterface
($)
1069 my($interface) = shift;
1070 my($data) = $interface->{DATA
};
1072 if (has_property
($interface, "helper")) {
1073 warning
($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1076 ValidProperties
($interface,"INTERFACE");
1078 if (has_property
($interface, "pointer_default")) {
1079 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1080 ("ref", "unique", "ptr"))) {
1081 fatal
($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1085 if (has_property
($interface, "object")) {
1086 if (has_property
($interface, "version") &&
1087 $interface->{PROPERTIES
}->{version
} != 0) {
1088 fatal
($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1091 if (!defined($interface->{BASE
}) &&
1092 not ($interface->{NAME
} eq "IUnknown")) {
1093 fatal
($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1097 foreach my $d (@
{$data}) {
1098 ($d->{TYPE
} eq "FUNCTION") && ValidFunction
($d);
1099 ($d->{TYPE
} eq "TYPEDEF" or
1100 $d->{TYPE
} eq "STRUCT" or
1101 $d->{TYPE
} eq "UNION" or
1102 $d->{TYPE
} eq "ENUM" or
1103 $d->{TYPE
} eq "BITMAP") && ValidType
($d);
1108 #####################################################################
1109 # Validate an IDL structure
1114 foreach my $x (@
{$idl}) {
1115 ($x->{TYPE
} eq "INTERFACE") &&
1117 ($x->{TYPE
} eq "IMPORTLIB") &&
1118 warning
($x, "importlib() not supported");