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);
40 use Parse
::Pidl
::Typelist
qw(hasType getType expandAlias);
41 use Parse
::Pidl
::Util
qw(has_property property_matches);
43 # Alignment of the built-in scalar types
44 my $scalar_alignment = {
60 'string_array' => 4, #???
69 'wrepl_nbt_name' => 4,
78 warn ("$e->{FILE}:$e->{LINE}: Warning: $s\n");
81 #####################################################################
82 # signal a fatal validation error
86 die("$pos->{FILE}:$pos->{LINE}:$s\n");
89 sub GetElementLevelTable
($)
95 my @bracket_array = ();
100 if (has_property
($e, "size_is")) {
101 @size_is = split /,/, has_property
($e, "size_is");
104 if (has_property
($e, "length_is")) {
105 @length_is = split /,/, has_property
($e, "length_is");
108 if (defined($e->{ARRAY_LEN
})) {
109 @bracket_array = @
{$e->{ARRAY_LEN
}};
112 # Parse the [][][][] style array stuff
113 for my $i (0 .. $#bracket_array) {
114 my $d = $bracket_array[$#bracket_array - $i];
117 my $is_surrounding = 0;
119 my $is_conformant = 0;
124 if ($size = shift @size_is) {
125 } elsif ((scalar(@size_is) == 0) and has_property
($e, "string")) {
127 delete($e->{PROPERTIES
}->{string
});
129 print "$e->{FILE}:$e->{LINE}: Must specify size_is() for conformant array!\n";
133 if (($length = shift @length_is) or $is_string) {
139 if ($e == $e->{PARENT
}->{ELEMENTS
}[-1]
140 and $e->{PARENT
}->{TYPE
} ne "FUNCTION") {
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
=> (not $is_conformant and Parse
::Pidl
::Util
::is_constant
($size)),
155 IS_INLINE
=> (not $is_conformant and not Parse
::Pidl
::Util
::is_constant
($size))
159 # Next, all the pointers
160 foreach my $i (1..$e->{POINTERS
}) {
161 my $pt = pointer_type
($e);
163 my $level = "EMBEDDED";
164 # Top level "ref" pointers do not have a referrent identifier
165 $level = "TOP" if ( defined($pt)
167 and $e->{PARENT
}->{TYPE
} eq "FUNCTION");
171 # for now, there can only be one pointer type per element
172 POINTER_TYPE
=> pointer_type
($e),
173 POINTER_INDEX
=> $pointer_idx,
174 IS_DEFERRED
=> "$is_deferred",
180 # everything that follows will be deferred
181 $is_deferred = 1 if ($e->{PARENT
}->{TYPE
} ne "FUNCTION");
183 my $array_size = shift @size_is;
190 if ($array_length = shift @length_is) {
193 $array_length = $array_size;
198 if (scalar(@size_is) == 0 and has_property
($e, "string")) {
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 nonfatal
($e, "size_is() on non-array element");
250 if (scalar(@length_is) > 0) {
251 nonfatal
($e, "length_is() on non-array element");
254 if (has_property
($e, "string")) {
255 nonfatal
($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 "ptr" 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
},
375 ALIGN
=> align_type
($e->{TYPE
}),
382 my ($ndr,$struct) = @_;
384 my $surrounding = undef;
386 foreach my $x (@
{$struct->{ELEMENTS
}})
388 my $e = ParseElement
($x);
389 if ($x != $struct->{ELEMENTS
}[-1] and
390 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
391 print "$x->{FILE}:$x->{LINE}: error: conformant member not at end of struct\n";
396 my $e = $elements[-1];
397 if (defined($e) and defined($e->{LEVELS
}[0]->{IS_SURROUNDING
}) and
398 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
402 if (defined $e->{TYPE
} && $e->{TYPE
} eq "string"
403 && property_matches
($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
404 $surrounding = $struct->{ELEMENTS
}[-1];
409 SURROUNDING_ELEMENT
=> $surrounding,
410 ELEMENTS
=> \
@elements,
411 PROPERTIES
=> $struct->{PROPERTIES
},
420 my $switch_type = has_property
($e, "switch_type");
421 unless (defined($switch_type)) { $switch_type = "uint32"; }
423 if (has_property
($e, "nodiscriminant")) { $switch_type = undef; }
426 foreach my $x (@
{$e->{ELEMENTS
}})
429 if ($x->{TYPE
} eq "EMPTY") {
430 $t = { TYPE
=> "EMPTY" };
432 $t = ParseElement
($x);
434 if (has_property
($x, "default")) {
435 $t->{CASE
} = "default";
437 } elsif (defined($x->{PROPERTIES
}->{case
})) {
438 $t->{CASE
} = "case $x->{PROPERTIES}->{case}";
440 die("Union element $x->{NAME} has neither default nor case property");
447 SWITCH_TYPE
=> $switch_type,
448 ELEMENTS
=> \
@elements,
449 PROPERTIES
=> $e->{PROPERTIES
},
450 HAS_DEFAULT
=> $hasdefault,
461 BASE_TYPE
=> Parse
::Pidl
::Typelist
::enum_type_fn
($e),
462 ELEMENTS
=> $e->{ELEMENTS
},
463 PROPERTIES
=> $e->{PROPERTIES
},
474 BASE_TYPE
=> Parse
::Pidl
::Typelist
::bitmap_type_fn
($e),
475 ELEMENTS
=> $e->{ELEMENTS
},
476 PROPERTIES
=> $e->{PROPERTIES
},
485 if ($d->{TYPE
} eq "STRUCT" or $d->{TYPE
} eq "UNION") {
486 CheckPointerTypes
($d, $ndr->{PROPERTIES
}->{pointer_default
});
490 STRUCT
=> \
&ParseStruct
,
491 UNION
=> \
&ParseUnion
,
493 BITMAP
=> \
&ParseBitmap
,
494 TYPEDEF
=> \
&ParseTypedef
,
495 }->{$d->{TYPE
}}->($ndr, $d);
504 if (defined($d->{PROPERTIES
}) && !defined($d->{DATA
}->{PROPERTIES
})) {
505 $d->{DATA
}->{PROPERTIES
} = $d->{PROPERTIES
};
508 my $data = ParseType
($ndr, $d->{DATA
});
509 $data->{ALIGN
} = align_type
($d->{NAME
});
514 PROPERTIES
=> $d->{PROPERTIES
},
527 sub ParseFunction
($$$)
529 my ($ndr,$d,$opnum) = @_;
532 my $thisopnum = undef;
534 CheckPointerTypes
($d, $ndr->{PROPERTIES
}->{pointer_default_top
});
536 if (not defined($d->{PROPERTIES
}{noopnum
})) {
537 $thisopnum = ${$opnum};
541 foreach my $x (@
{$d->{ELEMENTS
}}) {
542 my $e = ParseElement
($x);
543 push (@
{$e->{DIRECTION
}}, "in") if (has_property
($x, "in"));
544 push (@
{$e->{DIRECTION
}}, "out") if (has_property
($x, "out"));
546 nonfatal
($x, "`$e->{NAME}' is [out] argument but not a pointer or array")
547 if ($e->{LEVELS
}[0]->{TYPE
} ne "POINTER" and
548 $e->{LEVELS
}[0]->{TYPE
} ne "ARRAY" and
549 grep(/out/, @
{$e->{DIRECTION
}}));
551 push (@elements, $e);
554 if ($d->{RETURN_TYPE
} ne "void") {
555 $rettype = expandAlias
($d->{RETURN_TYPE
});
559 if (has_property
($d, "async")) { $async = 1; }
566 RETURN_TYPE
=> $rettype,
567 PROPERTIES
=> $d->{PROPERTIES
},
568 ELEMENTS
=> \
@elements,
573 sub CheckPointerTypes
($$)
575 my ($s,$default) = @_;
577 foreach my $e (@
{$s->{ELEMENTS
}}) {
578 if ($e->{POINTERS
} and not defined(pointer_type
($e))) {
579 $e->{PROPERTIES
}->{$default} = 1;
584 #FIXME: Remove when ref handling in Samba4 is fixed
589 if ($d->{TYPE
} eq "FUNCTION") {
590 foreach (@
{$d->{ELEMENTS
}}) {
591 $_->{PROPERTIES
}->{keepref
} = 1;
593 } elsif ($d->{TYPE
} eq "TYPEDEF" and ($d->{DATA
}->{TYPE
} eq "STRUCT"
594 or $d->{DATA
}->{TYPE
} eq "UNION")) {
595 foreach (@
{$d->{DATA
}->{ELEMENTS
}}) {
596 $_->{PROPERTIES
}->{keepref
} = 1;
601 sub ParseInterface
($)
612 if (not has_property
($idl, "pointer_default")) {
613 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
614 # and "unique" in Microsoft Extensions mode (default)
615 $idl->{PROPERTIES
}->{pointer_default
} = "unique";
618 if (not has_property
($idl, "pointer_default_top")) {
619 $idl->{PROPERTIES
}->{pointer_default_top
} = "ref";
622 foreach my $d (@
{$idl->{DATA
}}) {
623 if ($d->{TYPE
} eq "DECLARE") {
624 push (@declares, $d);
625 } elsif ($d->{TYPE
} eq "FUNCTION") {
626 AddKeepRef
($d) if (has_property
($idl, "keepref"));
627 push (@functions, ParseFunction
($idl, $d, \
$opnum));
628 } elsif ($d->{TYPE
} eq "CONST") {
629 push (@consts, ParseConst
($idl, $d));
631 AddKeepRef
($d) if (has_property
($idl, "keepref"));
632 push (@types, ParseType
($idl, $d));
638 if(defined $idl->{PROPERTIES
}->{version
}) {
639 $version = $idl->{PROPERTIES
}->{version
};
642 # If no endpoint is set, default to the interface name as a named pipe
643 if (!defined $idl->{PROPERTIES
}->{endpoint
}) {
644 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME
} . "]\"";
646 @endpoints = split / /, $idl->{PROPERTIES
}->{endpoint
};
650 NAME
=> $idl->{NAME
},
651 UUID
=> lc(has_property
($idl, "uuid")),
654 PROPERTIES
=> $idl->{PROPERTIES
},
655 FUNCTIONS
=> \
@functions,
658 DECLARES
=> \
@declares,
659 ENDPOINTS
=> \
@endpoints
663 # Convert a IDL tree to a NDR tree
664 # Gives a result tree describing all that's necessary for easily generating
665 # NDR parsers / generators
670 return undef unless (defined($idl));
672 Parse
::Pidl
::NDR
::Validate
($idl);
677 ($_->{TYPE
} eq "INTERFACE") && push(@ndr, ParseInterface
($_));
690 foreach my $l (@
{$e->{LEVELS
}}) {
691 return $l if ($seen);
692 ($seen = 1) if ($l == $fl);
703 foreach my $l (@
{$e->{LEVELS
}}) {
704 (return $prev) if ($l == $fl);
711 sub ContainsString
($)
715 foreach my $l (@
{$e->{LEVELS
}}) {
716 return 1 if ($l->{TYPE
} eq "ARRAY" and $l->{IS_ZERO_TERMINATED
});
722 sub ContainsDeferred
($$)
726 return 1 if ($l->{CONTAINS_DEFERRED
});
728 while ($l = GetNextLevel
($e,$l))
730 return 1 if ($l->{IS_DEFERRED
});
731 return 1 if ($l->{CONTAINS_DEFERRED
});
741 if ($e->{PARENT
} && $e->{PARENT
}->{NAME
}) {
742 return "$e->{PARENT}->{NAME}.$e->{NAME}";
745 if ($e->{PARENT
} && $e->{PARENT
}->{PARENT
}->{NAME
}) {
746 return "$e->{PARENT}->{PARENT}->{NAME}.$e->{NAME}";
750 return "$e->{PARENT}->{NAME}.$e->{NAME}";
756 ###################################
757 # find a sibling var in a structure
761 my($fn) = $e->{PARENT
};
763 if ($name =~ /\*(.*)/) {
767 for my $e2 (@
{$fn->{ELEMENTS
}}) {
768 return $e2 if ($e2->{NAME
} eq $name);
774 my %property_list = (
776 "helpstring" => ["INTERFACE", "FUNCTION"],
777 "version" => ["INTERFACE"],
778 "uuid" => ["INTERFACE"],
779 "endpoint" => ["INTERFACE"],
780 "pointer_default" => ["INTERFACE"],
781 "pointer_default_top" => ["INTERFACE"],
782 "depends" => ["INTERFACE"],
783 "helper" => ["INTERFACE"],
784 "authservice" => ["INTERFACE"],
787 "object" => ["INTERFACE"],
788 "local" => ["INTERFACE", "FUNCTION"],
789 "iid_is" => ["ELEMENT"],
790 "call_as" => ["FUNCTION"],
791 "idempotent" => ["FUNCTION"],
794 "noopnum" => ["FUNCTION"],
796 "out" => ["ELEMENT"],
797 "async" => ["FUNCTION"],
800 "ref" => ["ELEMENT"],
801 "ptr" => ["ELEMENT"],
802 "sptr" => ["ELEMENT"],
803 "unique" => ["ELEMENT"],
804 "ignore" => ["ELEMENT"],
805 "relative" => ["ELEMENT"],
806 "relative_base" => ["TYPEDEF"],
808 "gensize" => ["TYPEDEF"],
809 "value" => ["ELEMENT"],
810 "flag" => ["ELEMENT", "TYPEDEF"],
813 "public" => ["FUNCTION", "TYPEDEF"],
814 "nopush" => ["FUNCTION", "TYPEDEF"],
815 "nopull" => ["FUNCTION", "TYPEDEF"],
816 "nosize" => ["FUNCTION", "TYPEDEF"],
817 "noprint" => ["FUNCTION", "TYPEDEF"],
818 "noejs" => ["FUNCTION", "TYPEDEF"],
821 "switch_is" => ["ELEMENT"],
822 "switch_type" => ["ELEMENT", "TYPEDEF"],
823 "nodiscriminant" => ["TYPEDEF"],
824 "case" => ["ELEMENT"],
825 "default" => ["ELEMENT"],
827 "represent_as" => ["ELEMENT"],
828 "transmit_as" => ["ELEMENT"],
831 "subcontext" => ["ELEMENT"],
832 "subcontext_size" => ["ELEMENT"],
833 "compression" => ["ELEMENT"],
836 "enum8bit" => ["TYPEDEF"],
837 "enum16bit" => ["TYPEDEF"],
838 "v1_enum" => ["TYPEDEF"],
841 "bitmap8bit" => ["TYPEDEF"],
842 "bitmap16bit" => ["TYPEDEF"],
843 "bitmap32bit" => ["TYPEDEF"],
844 "bitmap64bit" => ["TYPEDEF"],
847 "range" => ["ELEMENT"],
848 "size_is" => ["ELEMENT"],
849 "string" => ["ELEMENT"],
850 "noheader" => ["ELEMENT"],
851 "charset" => ["ELEMENT"],
852 "length_is" => ["ELEMENT"],
854 # temporary (should be removed once we've migrated away from
855 # relying on ref pointers being there in Samba4's code)
856 "keepref" => ["ELEMENT","INTERFACE"],
859 #####################################################################
860 # check for unknown properties
861 sub ValidProperties
($$)
865 return unless defined $e->{PROPERTIES
};
867 foreach my $key (keys %{$e->{PROPERTIES
}}) {
868 fatal
($e, el_name
($e) . ": unknown property '$key'\n")
869 unless defined($property_list{$key});
871 fatal
($e, el_name
($e) . ": property '$key' not allowed on '$t'\n")
872 unless grep($t, @
{$property_list{$key}});
879 my $ti = getType
($t);
881 if (not defined ($ti)) {
883 } elsif ($ti->{DATA
}->{TYPE
} eq "ENUM") {
884 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti->{DATA
});
885 } elsif ($ti->{DATA
}->{TYPE
} eq "BITMAP") {
886 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti->{DATA
});
887 } elsif ($ti->{DATA
}->{TYPE
} eq "SCALAR") {
894 #####################################################################
900 ValidProperties
($e,"ELEMENT");
902 if (has_property
($e, "ptr")) {
903 fatal
($e, el_name
($e) . " : pidl does not support full NDR pointers yet\n");
906 # Check whether switches are used correctly.
907 if (my $switch = has_property
($e, "switch_is")) {
908 my $e2 = find_sibling
($e, $switch);
909 my $type = getType
($e->{TYPE
});
911 if (defined($type) and $type->{DATA
}->{TYPE
} ne "UNION") {
912 fatal
($e, el_name
($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
915 if (!has_property
($type, "nodiscriminant") and defined($e2)) {
916 my $discriminator_type = has_property
($type, "switch_type");
917 $discriminator_type = "uint32" unless defined ($discriminator_type);
919 my $t1 = mapToScalar
($discriminator_type);
921 if (not defined($t1)) {
922 fatal
($e, el_name
($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
925 my $t2 = mapToScalar
($e2->{TYPE
});
926 if (not defined($t2)) {
927 fatal
($e, el_name
($e) . ": unable to map variable used for switch_is() to scalar");
931 nonfatal
($e, el_name
($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
937 if (has_property
($e, "subcontext") and has_property
($e, "represent_as")) {
938 fatal
($e, el_name
($e) . " : subcontext() and represent_as() can not be used on the same element");
941 if (has_property
($e, "subcontext") and has_property
($e, "transmit_as")) {
942 fatal
($e, el_name
($e) . " : subcontext() and transmit_as() can not be used on the same element");
945 if (has_property
($e, "represent_as") and has_property
($e, "transmit_as")) {
946 fatal
($e, el_name
($e) . " : represent_as() and transmit_as() can not be used on the same element");
949 if (has_property
($e, "represent_as") and has_property
($e, "value")) {
950 fatal
($e, el_name
($e) . " : represent_as() and value() can not be used on the same element");
953 if (defined (has_property
($e, "subcontext_size")) and not defined(has_property
($e, "subcontext"))) {
954 fatal
($e, el_name
($e) . " : subcontext_size() on non-subcontext element");
957 if (defined (has_property
($e, "compression")) and not defined(has_property
($e, "subcontext"))) {
958 fatal
($e, el_name
($e) . " : compression() on non-subcontext element");
961 if (!$e->{POINTERS
} && (
962 has_property
($e, "ptr") or
963 has_property
($e, "sptr") or
964 has_property
($e, "unique") or
965 has_property
($e, "relative") or
966 has_property
($e, "ref"))) {
967 fatal
($e, el_name
($e) . " : pointer properties on non-pointer element\n");
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!\n";
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\n";
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 if (ref($data) eq "HASH") {
1031 if ($data->{TYPE
} eq "STRUCT") {
1035 if ($data->{TYPE
} eq "UNION") {
1041 #####################################################################
1043 sub ValidFunction
($)
1047 ValidProperties
($fn,"FUNCTION");
1049 foreach my $e (@
{$fn->{ELEMENTS
}}) {
1051 if (has_property
($e, "ref") && !$e->{POINTERS
}) {
1052 fatal
$e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})\n";
1058 #####################################################################
1059 # parse the interface definitions
1060 sub ValidInterface
($)
1062 my($interface) = shift;
1063 my($data) = $interface->{DATA
};
1065 ValidProperties
($interface,"INTERFACE");
1067 if (has_property
($interface, "pointer_default") &&
1068 $interface->{PROPERTIES
}->{pointer_default
} eq "ptr") {
1069 fatal
$interface, "Full pointers are not supported yet\n";
1072 if (has_property
($interface, "object")) {
1073 if (has_property
($interface, "version") &&
1074 $interface->{PROPERTIES
}->{version
} != 0) {
1075 fatal
$interface, "Object interfaces must have version 0.0 ($interface->{NAME})\n";
1078 if (!defined($interface->{BASE
}) &&
1079 not ($interface->{NAME
} eq "IUnknown")) {
1080 fatal
$interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})\n";
1084 foreach my $d (@
{$data}) {
1085 ($d->{TYPE
} eq "TYPEDEF") &&
1087 ($d->{TYPE
} eq "FUNCTION") &&
1093 #####################################################################
1094 # Validate an IDL structure
1099 foreach my $x (@
{$idl}) {
1100 ($x->{TYPE
} eq "INTERFACE") &&