1 ###################################################
2 # Samba4 NDR info tree generator
3 # Copyright tridge@samba.org 2000-2003
4 # Copyright tpot@samba.org 2001
5 # Copyright jelmer@samba.org 2004-2006
6 # released under the GNU GPL
12 Parse::Pidl::NDR - NDR parsing information generator
16 Return a table describing the order in which the parts of an element
27 Jelmer Vernooij <jelmer@samba.org>
31 package Parse
::Pidl
::NDR
;
34 use vars
qw($VERSION);
37 @EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString);
38 @EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement);
41 use Parse
::Pidl
qw(warning fatal);
42 use Parse
::Pidl
::Typelist
qw(hasType getType expandAlias);
43 use Parse
::Pidl
::Util
qw(has_property property_matches);
45 # Alignment of the built-in scalar types
46 my $scalar_alignment = {
62 'string_array' => 4, #???
71 'wrepl_nbt_name' => 4,
75 sub GetElementLevelTable
($)
81 my @bracket_array = ();
86 if (has_property
($e, "size_is")) {
87 @size_is = split /,/, has_property
($e, "size_is");
90 if (has_property
($e, "length_is")) {
91 @length_is = split /,/, has_property
($e, "length_is");
94 if (defined($e->{ARRAY_LEN
})) {
95 @bracket_array = @
{$e->{ARRAY_LEN
}};
98 if (has_property
($e, "out")) {
101 if (has_property
($e, "string")) { $needptrs++; }
102 if ($#bracket_array >= 0) { $needptrs = 0; }
104 warning
($e, "[out] argument `$e->{NAME}' not a pointer") if ($needptrs > $e->{POINTERS
});
107 # Parse the [][][][] style array stuff
108 for my $i (0 .. $#bracket_array) {
109 my $d = $bracket_array[$#bracket_array - $i];
112 my $is_surrounding = 0;
114 my $is_conformant = 0;
119 if ($size = shift @size_is) {
120 } elsif ((scalar(@size_is) == 0) and has_property
($e, "string")) {
122 delete($e->{PROPERTIES
}->{string
});
124 fatal
($e, "Must specify size_is() for conformant array!")
127 if (($length = shift @length_is) or $is_string) {
133 if ($e == $e->{PARENT
}->{ELEMENTS
}[-1]
134 and $e->{PARENT
}->{TYPE
} ne "FUNCTION") {
142 LENGTH_IS
=> $length,
143 IS_DEFERRED
=> "$is_deferred",
144 IS_SURROUNDING
=> "$is_surrounding",
145 IS_ZERO_TERMINATED
=> "$is_string",
146 IS_VARYING
=> "$is_varying",
147 IS_CONFORMANT
=> "$is_conformant",
148 IS_FIXED
=> (not $is_conformant and Parse
::Pidl
::Util
::is_constant
($size)),
149 IS_INLINE
=> (not $is_conformant and not Parse
::Pidl
::Util
::is_constant
($size))
153 # Next, all the pointers
154 foreach my $i (1..$e->{POINTERS
}) {
155 my $pt = pointer_type
($e);
157 my $level = "EMBEDDED";
158 # Top level "ref" pointers do not have a referrent identifier
159 $level = "TOP" if ( defined($pt)
161 and $e->{PARENT
}->{TYPE
} eq "FUNCTION");
165 # for now, there can only be one pointer type per element
166 POINTER_TYPE
=> pointer_type
($e),
167 POINTER_INDEX
=> $pointer_idx,
168 IS_DEFERRED
=> "$is_deferred",
172 warning
($e, "top-level \[out\] pointer `$e->{NAME}' is not a \[ref\] pointer")
173 if ($i == 1 and pointer_type
($e) ne "ref" and
174 $e->{PARENT
}->{TYPE
} eq "FUNCTION" and
175 not has_property
($e, "in"));
179 # everything that follows will be deferred
180 $is_deferred = 1 if ($e->{PARENT
}->{TYPE
} ne "FUNCTION");
182 my $array_size = shift @size_is;
189 if ($array_length = shift @length_is) {
192 $array_length = $array_size;
197 if (scalar(@size_is) == 0 and has_property
($e, "string") and
198 $i == $e->{POINTERS
}) {
200 $is_varying = $is_conformant = has_property
($e, "noheader")?
0:1;
201 delete($e->{PROPERTIES
}->{string
});
204 if ($array_size or $is_string) {
207 IS_ZERO_TERMINATED
=> "$is_string",
208 SIZE_IS
=> $array_size,
209 LENGTH_IS
=> $array_length,
210 IS_DEFERRED
=> "$is_deferred",
212 IS_VARYING
=> "$is_varying",
213 IS_CONFORMANT
=> "$is_conformant",
222 if (defined(has_property
($e, "subcontext"))) {
223 my $hdr_size = has_property
($e, "subcontext");
224 my $subsize = has_property
($e, "subcontext_size");
225 if (not defined($subsize)) {
230 TYPE
=> "SUBCONTEXT",
231 HEADER_SIZE
=> $hdr_size,
232 SUBCONTEXT_SIZE
=> $subsize,
233 IS_DEFERRED
=> $is_deferred,
234 COMPRESSION
=> has_property
($e, "compression"),
238 if (my $switch = has_property
($e, "switch_is")) {
241 SWITCH_IS
=> $switch,
242 IS_DEFERRED
=> $is_deferred
246 if (scalar(@size_is) > 0) {
247 warning
($e, "size_is() on non-array element");
250 if (scalar(@length_is) > 0) {
251 warning
($e, "length_is() on non-array element");
254 if (has_property
($e, "string")) {
255 warning
($e, "string() attribute on non-array element");
260 DATA_TYPE
=> $e->{TYPE
},
261 IS_DEFERRED
=> $is_deferred,
262 CONTAINS_DEFERRED
=> can_contain_deferred
($e),
263 IS_SURROUNDING
=> 0 #FIXME
267 foreach (@
$order) { $_->{LEVEL_INDEX
} = $i; $i+=1; }
272 #####################################################################
273 # see if a type contains any deferred data
274 sub can_contain_deferred
278 return 0 if (Parse
::Pidl
::Typelist
::is_scalar
($e->{TYPE
}));
279 return 1 unless (hasType
($e->{TYPE
})); # assume the worst
281 my $type = getType
($e->{TYPE
});
283 foreach my $x (@
{$type->{DATA
}->{ELEMENTS
}}) {
284 return 1 if ($x->{POINTERS
});
285 return 1 if (can_contain_deferred
($x));
295 return undef unless $e->{POINTERS
};
297 return "ref" if (has_property
($e, "ref"));
298 return "full" if (has_property
($e, "ptr"));
299 return "sptr" if (has_property
($e, "sptr"));
300 return "unique" if (has_property
($e, "unique"));
301 return "relative" if (has_property
($e, "relative"));
302 return "ignore" if (has_property
($e, "ignore"));
307 #####################################################################
308 # work out the correct alignment for a structure or union
309 sub find_largest_alignment
($)
314 for my $e (@
{$s->{ELEMENTS
}}) {
317 if ($e->{POINTERS
}) {
319 } elsif (has_property
($e, "subcontext")) {
321 } elsif (has_property
($e, "transmit_as")) {
322 $a = align_type
($e->{PROPERTIES
}->{transmit_as
});
324 $a = align_type
($e->{TYPE
});
327 $align = $a if ($align < $a);
333 #####################################################################
340 unless (hasType
($e)) {
341 # it must be an external type - all we can do is guess
342 # print "Warning: assuming alignment of unknown type '$e' is 4\n";
346 my $dt = getType
($e)->{DATA
};
348 if ($dt->{TYPE
} eq "ENUM") {
349 return align_type
(Parse
::Pidl
::Typelist
::enum_type_fn
($dt));
350 } elsif ($dt->{TYPE
} eq "BITMAP") {
351 return align_type
(Parse
::Pidl
::Typelist
::bitmap_type_fn
($dt));
352 } elsif (($dt->{TYPE
} eq "STRUCT") or ($dt->{TYPE
} eq "UNION")) {
353 return find_largest_alignment
($dt);
354 } elsif ($dt->{TYPE
} eq "SCALAR") {
355 return $scalar_alignment->{$dt->{NAME
}};
358 die("Unknown data type type $dt->{TYPE}");
363 my ($e, $pointer_default) = @_;
365 $e->{TYPE
} = expandAlias
($e->{TYPE
});
367 if (ref($e->{TYPE
}) eq "HASH") {
368 $e->{TYPE
} = ParseType
($e->{TYPE
}, $pointer_default);
374 PROPERTIES
=> $e->{PROPERTIES
},
375 LEVELS
=> GetElementLevelTable
($e),
376 REPRESENTATION_TYPE
=> ($e->{PROPERTIES
}->{represent_as
} or $e->{TYPE
}),
377 ALIGN
=> align_type
($e->{TYPE
}),
384 my ($struct, $pointer_default) = @_;
386 my $surrounding = undef;
388 foreach my $x (@
{$struct->{ELEMENTS
}})
390 my $e = ParseElement
($x, $pointer_default);
391 if ($x != $struct->{ELEMENTS
}[-1] and
392 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
393 fatal
($x, "conformant member not at end of struct");
398 my $e = $elements[-1];
399 if (defined($e) and defined($e->{LEVELS
}[0]->{IS_SURROUNDING
}) and
400 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
404 if (defined $e->{TYPE
} && $e->{TYPE
} eq "string"
405 && property_matches
($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
406 $surrounding = $struct->{ELEMENTS
}[-1];
410 if ($struct->{NAME
}) {
411 $align = align_type
($struct->{NAME
});
416 NAME
=> $struct->{NAME
},
417 SURROUNDING_ELEMENT
=> $surrounding,
418 ELEMENTS
=> \
@elements,
419 PROPERTIES
=> $struct->{PROPERTIES
},
427 my ($e, $pointer_default) = @_;
429 my $switch_type = has_property
($e, "switch_type");
430 unless (defined($switch_type)) { $switch_type = "uint32"; }
432 if (has_property
($e, "nodiscriminant")) { $switch_type = undef; }
435 foreach my $x (@
{$e->{ELEMENTS
}})
438 if ($x->{TYPE
} eq "EMPTY") {
439 $t = { TYPE
=> "EMPTY" };
441 $t = ParseElement
($x, $pointer_default);
443 if (has_property
($x, "default")) {
444 $t->{CASE
} = "default";
446 } elsif (defined($x->{PROPERTIES
}->{case
})) {
447 $t->{CASE
} = "case $x->{PROPERTIES}->{case}";
449 die("Union element $x->{NAME} has neither default nor case property");
457 SWITCH_TYPE
=> $switch_type,
458 ELEMENTS
=> \
@elements,
459 PROPERTIES
=> $e->{PROPERTIES
},
460 HAS_DEFAULT
=> $hasdefault,
467 my ($e, $pointer_default) = @_;
472 BASE_TYPE
=> Parse
::Pidl
::Typelist
::enum_type_fn
($e),
473 ELEMENTS
=> $e->{ELEMENTS
},
474 PROPERTIES
=> $e->{PROPERTIES
},
481 my ($e, $pointer_default) = @_;
486 BASE_TYPE
=> Parse
::Pidl
::Typelist
::bitmap_type_fn
($e),
487 ELEMENTS
=> $e->{ELEMENTS
},
488 PROPERTIES
=> $e->{PROPERTIES
},
495 my ($d, $pointer_default) = @_;
497 if ($d->{TYPE
} eq "STRUCT" or $d->{TYPE
} eq "UNION") {
498 CheckPointerTypes
($d, $pointer_default);
502 STRUCT
=> \
&ParseStruct
,
503 UNION
=> \
&ParseUnion
,
505 BITMAP
=> \
&ParseBitmap
,
506 TYPEDEF
=> \
&ParseTypedef
,
507 }->{$d->{TYPE
}}->($d, $pointer_default);
514 my ($d, $pointer_default) = @_;
516 if (defined($d->{DATA
}->{PROPERTIES
}) && !defined($d->{PROPERTIES
})) {
517 $d->{PROPERTIES
} = $d->{DATA
}->{PROPERTIES
};
520 my $data = ParseType
($d->{DATA
}, $pointer_default);
521 $data->{ALIGN
} = align_type
($d->{NAME
});
526 PROPERTIES
=> $d->{PROPERTIES
},
539 sub ParseFunction
($$$)
541 my ($ndr,$d,$opnum) = @_;
544 my $thisopnum = undef;
546 CheckPointerTypes
($d, $ndr->{PROPERTIES
}->{pointer_default_top
});
548 if (not defined($d->{PROPERTIES
}{noopnum
})) {
549 $thisopnum = ${$opnum};
553 foreach my $x (@
{$d->{ELEMENTS
}}) {
554 my $e = ParseElement
($x, $ndr->{PROPERTIES
}->{pointer_default
});
555 push (@
{$e->{DIRECTION
}}, "in") if (has_property
($x, "in"));
556 push (@
{$e->{DIRECTION
}}, "out") if (has_property
($x, "out"));
558 push (@elements, $e);
561 if ($d->{RETURN_TYPE
} ne "void") {
562 $rettype = expandAlias
($d->{RETURN_TYPE
});
566 if (has_property
($d, "async")) { $async = 1; }
573 RETURN_TYPE
=> $rettype,
574 PROPERTIES
=> $d->{PROPERTIES
},
575 ELEMENTS
=> \
@elements,
580 sub CheckPointerTypes
($$)
582 my ($s,$default) = @_;
584 foreach my $e (@
{$s->{ELEMENTS
}}) {
585 if ($e->{POINTERS
} and not defined(pointer_type
($e))) {
586 $e->{PROPERTIES
}->{$default} = 1;
591 sub ParseInterface
($)
602 if (not has_property
($idl, "pointer_default")) {
603 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
604 # and "unique" in Microsoft Extensions mode (default)
605 $idl->{PROPERTIES
}->{pointer_default
} = "unique";
608 if (not has_property
($idl, "pointer_default_top")) {
609 $idl->{PROPERTIES
}->{pointer_default_top
} = "ref";
611 warning
($idl, "pointer_default_top() is a pidl extension and should not be used");
614 foreach my $d (@
{$idl->{DATA
}}) {
615 if ($d->{TYPE
} eq "DECLARE") {
616 push (@declares, $d);
617 } elsif ($d->{TYPE
} eq "FUNCTION") {
618 push (@functions, ParseFunction
($idl, $d, \
$opnum));
619 } elsif ($d->{TYPE
} eq "CONST") {
620 push (@consts, ParseConst
($idl, $d));
622 push (@types, ParseType
($d, $idl->{PROPERTIES
}->{pointer_default
}));
628 if(defined $idl->{PROPERTIES
}->{version
}) {
629 $version = $idl->{PROPERTIES
}->{version
};
632 # If no endpoint is set, default to the interface name as a named pipe
633 if (!defined $idl->{PROPERTIES
}->{endpoint
}) {
634 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME
} . "]\"";
636 @endpoints = split / /, $idl->{PROPERTIES
}->{endpoint
};
640 NAME
=> $idl->{NAME
},
641 UUID
=> lc(has_property
($idl, "uuid")),
644 PROPERTIES
=> $idl->{PROPERTIES
},
645 FUNCTIONS
=> \
@functions,
648 DECLARES
=> \
@declares,
649 ENDPOINTS
=> \
@endpoints
653 # Convert a IDL tree to a NDR tree
654 # Gives a result tree describing all that's necessary for easily generating
655 # NDR parsers / generators
660 return undef unless (defined($idl));
662 Parse
::Pidl
::NDR
::Validate
($idl);
667 ($_->{TYPE
} eq "INTERFACE") && push(@ndr, ParseInterface
($_));
668 ($_->{TYPE
} eq "IMPORT") && push(@ndr, $_);
681 foreach my $l (@
{$e->{LEVELS
}}) {
682 return $l if ($seen);
683 ($seen = 1) if ($l == $fl);
694 foreach my $l (@
{$e->{LEVELS
}}) {
695 (return $prev) if ($l == $fl);
702 sub ContainsString
($)
706 foreach my $l (@
{$e->{LEVELS
}}) {
707 return 1 if ($l->{TYPE
} eq "ARRAY" and $l->{IS_ZERO_TERMINATED
});
713 sub ContainsDeferred
($$)
717 return 1 if ($l->{CONTAINS_DEFERRED
});
719 while ($l = GetNextLevel
($e,$l))
721 return 1 if ($l->{IS_DEFERRED
});
722 return 1 if ($l->{CONTAINS_DEFERRED
});
732 if ($e->{PARENT
} && $e->{PARENT
}->{NAME
}) {
733 return "$e->{PARENT}->{NAME}.$e->{NAME}";
736 if ($e->{PARENT
} && $e->{PARENT
}->{PARENT
}->{NAME
}) {
737 return "$e->{PARENT}->{PARENT}->{NAME}.$e->{NAME}";
741 return "$e->{PARENT}->{NAME}.$e->{NAME}";
747 ###################################
748 # find a sibling var in a structure
752 my($fn) = $e->{PARENT
};
754 if ($name =~ /\*(.*)/) {
758 for my $e2 (@
{$fn->{ELEMENTS
}}) {
759 return $e2 if ($e2->{NAME
} eq $name);
765 my %property_list = (
767 "helpstring" => ["INTERFACE", "FUNCTION"],
768 "version" => ["INTERFACE"],
769 "uuid" => ["INTERFACE"],
770 "endpoint" => ["INTERFACE"],
771 "pointer_default" => ["INTERFACE"],
772 "pointer_default_top" => ["INTERFACE"],
773 "helper" => ["INTERFACE"],
774 "authservice" => ["INTERFACE"],
777 "object" => ["INTERFACE"],
778 "local" => ["INTERFACE", "FUNCTION"],
779 "iid_is" => ["ELEMENT"],
780 "call_as" => ["FUNCTION"],
781 "idempotent" => ["FUNCTION"],
784 "noopnum" => ["FUNCTION"],
786 "out" => ["ELEMENT"],
787 "async" => ["FUNCTION"],
790 "ref" => ["ELEMENT"],
791 "ptr" => ["ELEMENT"],
792 "unique" => ["ELEMENT"],
793 "ignore" => ["ELEMENT"],
794 "relative" => ["ELEMENT"],
795 "relative_base" => ["TYPEDEF"],
797 "gensize" => ["TYPEDEF"],
798 "value" => ["ELEMENT"],
799 "flag" => ["ELEMENT", "TYPEDEF"],
802 "public" => ["FUNCTION", "TYPEDEF"],
803 "nopush" => ["FUNCTION", "TYPEDEF"],
804 "nopull" => ["FUNCTION", "TYPEDEF"],
805 "nosize" => ["FUNCTION", "TYPEDEF"],
806 "noprint" => ["FUNCTION", "TYPEDEF"],
807 "noejs" => ["FUNCTION", "TYPEDEF"],
810 "switch_is" => ["ELEMENT"],
811 "switch_type" => ["ELEMENT", "TYPEDEF"],
812 "nodiscriminant" => ["TYPEDEF"],
813 "case" => ["ELEMENT"],
814 "default" => ["ELEMENT"],
816 "represent_as" => ["ELEMENT"],
817 "transmit_as" => ["ELEMENT"],
820 "subcontext" => ["ELEMENT"],
821 "subcontext_size" => ["ELEMENT"],
822 "compression" => ["ELEMENT"],
825 "enum8bit" => ["TYPEDEF"],
826 "enum16bit" => ["TYPEDEF"],
827 "v1_enum" => ["TYPEDEF"],
830 "bitmap8bit" => ["TYPEDEF"],
831 "bitmap16bit" => ["TYPEDEF"],
832 "bitmap32bit" => ["TYPEDEF"],
833 "bitmap64bit" => ["TYPEDEF"],
836 "range" => ["ELEMENT"],
837 "size_is" => ["ELEMENT"],
838 "string" => ["ELEMENT"],
839 "noheader" => ["ELEMENT"],
840 "charset" => ["ELEMENT"],
841 "length_is" => ["ELEMENT"],
844 #####################################################################
845 # check for unknown properties
846 sub ValidProperties
($$)
850 return unless defined $e->{PROPERTIES
};
852 foreach my $key (keys %{$e->{PROPERTIES
}}) {
853 warning
($e, el_name
($e) . ": unknown property '$key'")
854 unless defined($property_list{$key});
856 fatal
($e, el_name
($e) . ": property '$key' not allowed on '$t'")
857 unless grep($t, @
{$property_list{$key}});
864 my $ti = getType
($t);
866 if (not defined ($ti)) {
868 } elsif ($ti->{DATA
}->{TYPE
} eq "ENUM") {
869 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti->{DATA
});
870 } elsif ($ti->{DATA
}->{TYPE
} eq "BITMAP") {
871 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti->{DATA
});
872 } elsif ($ti->{DATA
}->{TYPE
} eq "SCALAR") {
879 #####################################################################
880 # validate an element
885 ValidProperties
($e,"ELEMENT");
887 # Check whether switches are used correctly.
888 if (my $switch = has_property
($e, "switch_is")) {
889 my $e2 = find_sibling
($e, $switch);
890 my $type = getType
($e->{TYPE
});
892 if (defined($type) and $type->{DATA
}->{TYPE
} ne "UNION") {
893 fatal
($e, el_name
($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
896 if (not has_property
($type->{DATA
}, "nodiscriminant") and defined($e2)) {
897 my $discriminator_type = has_property
($type->{DATA
}, "switch_type");
898 $discriminator_type = "uint32" unless defined ($discriminator_type);
900 my $t1 = mapToScalar
($discriminator_type);
902 if (not defined($t1)) {
903 fatal
($e, el_name
($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
906 my $t2 = mapToScalar
($e2->{TYPE
});
907 if (not defined($t2)) {
908 fatal
($e, el_name
($e) . ": unable to map variable used for switch_is() to scalar");
912 warning
($e, el_name
($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
917 if (has_property
($e, "subcontext") and has_property
($e, "represent_as")) {
918 fatal
($e, el_name
($e) . " : subcontext() and represent_as() can not be used on the same element");
921 if (has_property
($e, "subcontext") and has_property
($e, "transmit_as")) {
922 fatal
($e, el_name
($e) . " : subcontext() and transmit_as() can not be used on the same element");
925 if (has_property
($e, "represent_as") and has_property
($e, "transmit_as")) {
926 fatal
($e, el_name
($e) . " : represent_as() and transmit_as() can not be used on the same element");
929 if (has_property
($e, "represent_as") and has_property
($e, "value")) {
930 fatal
($e, el_name
($e) . " : represent_as() and value() can not be used on the same element");
933 if (has_property
($e, "subcontext")) {
934 warning
($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
937 if (defined (has_property
($e, "subcontext_size")) and not defined(has_property
($e, "subcontext"))) {
938 fatal
($e, el_name
($e) . " : subcontext_size() on non-subcontext element");
941 if (defined (has_property
($e, "compression")) and not defined(has_property
($e, "subcontext"))) {
942 fatal
($e, el_name
($e) . " : compression() on non-subcontext element");
945 if (!$e->{POINTERS
} && (
946 has_property
($e, "ptr") or
947 has_property
($e, "unique") or
948 has_property
($e, "relative") or
949 has_property
($e, "ref"))) {
950 fatal
($e, el_name
($e) . " : pointer properties on non-pointer element\n");
954 #####################################################################
960 ValidProperties
($enum, "ENUM");
963 #####################################################################
969 ValidProperties
($bitmap, "BITMAP");
972 #####################################################################
978 ValidProperties
($struct, "STRUCT");
980 foreach my $e (@
{$struct->{ELEMENTS
}}) {
981 $e->{PARENT
} = $struct;
986 #####################################################################
992 ValidProperties
($union,"UNION");
994 if (has_property
($union->{PARENT
}, "nodiscriminant") and has_property
($union->{PARENT
}, "switch_type")) {
995 fatal
($union->{PARENT
}, $union->{PARENT
}->{NAME
} . ": switch_type() on union without discriminant");
998 foreach my $e (@
{$union->{ELEMENTS
}}) {
999 $e->{PARENT
} = $union;
1001 if (defined($e->{PROPERTIES
}->{default}) and
1002 defined($e->{PROPERTIES
}->{case
})) {
1003 fatal
($e, "Union member $e->{NAME} can not have both default and case properties!");
1006 unless (defined ($e->{PROPERTIES
}->{default}) or
1007 defined ($e->{PROPERTIES
}->{case
})) {
1008 fatal
($e, "Union member $e->{NAME} must have default or case property");
1011 if (has_property
($e, "ref")) {
1012 fatal
($e, el_name
($e) . " : embedded ref pointers are not supported yet\n");
1020 #####################################################################
1024 my($typedef) = shift;
1025 my $data = $typedef->{DATA
};
1027 ValidProperties
($typedef, "TYPEDEF");
1029 $data->{PARENT
} = $typedef;
1031 ValidType
($data) if (ref($data) eq "HASH");
1034 #####################################################################
1035 # validate a function
1036 sub ValidFunction
($)
1040 ValidProperties
($fn,"FUNCTION");
1042 foreach my $e (@
{$fn->{ELEMENTS
}}) {
1044 if (has_property
($e, "ref") && !$e->{POINTERS
}) {
1045 fatal
($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1051 #####################################################################
1058 TYPEDEF
=> \
&ValidTypedef
,
1059 STRUCT
=> \
&ValidStruct
,
1060 UNION
=> \
&ValidUnion
,
1061 ENUM
=> \
&ValidEnum
,
1062 BITMAP
=> \
&ValidBitmap
1063 }->{$t->{TYPE
}}->($t);
1066 #####################################################################
1067 # parse the interface definitions
1068 sub ValidInterface
($)
1070 my($interface) = shift;
1071 my($data) = $interface->{DATA
};
1073 if (has_property
($interface, "helper")) {
1074 warning
($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1077 ValidProperties
($interface,"INTERFACE");
1079 if (has_property
($interface, "pointer_default")) {
1080 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1081 ("ref", "unique", "ptr"))) {
1082 fatal
($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1086 if (has_property
($interface, "object")) {
1087 if (has_property
($interface, "version") &&
1088 $interface->{PROPERTIES
}->{version
} != 0) {
1089 fatal
($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1092 if (!defined($interface->{BASE
}) &&
1093 not ($interface->{NAME
} eq "IUnknown")) {
1094 fatal
($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1098 foreach my $d (@
{$data}) {
1099 ($d->{TYPE
} eq "FUNCTION") && ValidFunction
($d);
1100 ($d->{TYPE
} eq "TYPEDEF" or
1101 $d->{TYPE
} eq "STRUCT" or
1102 $d->{TYPE
} eq "UNION" or
1103 $d->{TYPE
} eq "ENUM" or
1104 $d->{TYPE
} eq "BITMAP") && ValidType
($d);
1109 #####################################################################
1110 # Validate an IDL structure
1115 foreach my $x (@
{$idl}) {
1116 ($x->{TYPE
} eq "INTERFACE") &&
1118 ($x->{TYPE
} eq "IMPORTLIB") &&
1119 warning
($x, "importlib() not supported");