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);
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 if (ref($e) eq "HASH" and $e->{TYPE
} eq "SCALAR") {
341 return $scalar_alignment->{$e->{NAME
}};
344 unless (hasType
($e)) {
345 # it must be an external type - all we can do is guess
346 # print "Warning: assuming alignment of unknown type '$e' is 4\n";
350 my $dt = getType
($e);
352 if ($dt->{TYPE
} eq "TYPEDEF") {
353 return align_type
($dt->{DATA
});
354 } elsif ($dt->{TYPE
} eq "ENUM") {
355 return align_type
(Parse
::Pidl
::Typelist
::enum_type_fn
($dt));
356 } elsif ($dt->{TYPE
} eq "BITMAP") {
357 return align_type
(Parse
::Pidl
::Typelist
::bitmap_type_fn
($dt));
358 } elsif (($dt->{TYPE
} eq "STRUCT") or ($dt->{TYPE
} eq "UNION")) {
359 return find_largest_alignment
($dt);
362 die("Unknown data type type $dt->{TYPE}");
367 my ($e, $pointer_default) = @_;
369 $e->{TYPE
} = expandAlias
($e->{TYPE
});
371 if (ref($e->{TYPE
}) eq "HASH") {
372 $e->{TYPE
} = ParseType
($e->{TYPE
}, $pointer_default);
378 PROPERTIES
=> $e->{PROPERTIES
},
379 LEVELS
=> GetElementLevelTable
($e),
380 REPRESENTATION_TYPE
=> ($e->{PROPERTIES
}->{represent_as
} or $e->{TYPE
}),
381 ALIGN
=> align_type
($e->{TYPE
}),
388 my ($struct, $pointer_default) = @_;
390 my $surrounding = undef;
392 foreach my $x (@
{$struct->{ELEMENTS
}})
394 my $e = ParseElement
($x, $pointer_default);
395 if ($x != $struct->{ELEMENTS
}[-1] and
396 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
397 fatal
($x, "conformant member not at end of struct");
402 my $e = $elements[-1];
403 if (defined($e) and defined($e->{LEVELS
}[0]->{IS_SURROUNDING
}) and
404 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
408 if (defined $e->{TYPE
} && $e->{TYPE
} eq "string"
409 && property_matches
($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
410 $surrounding = $struct->{ELEMENTS
}[-1];
414 if ($struct->{NAME
}) {
415 $align = align_type
($struct->{NAME
});
420 NAME
=> $struct->{NAME
},
421 SURROUNDING_ELEMENT
=> $surrounding,
422 ELEMENTS
=> \
@elements,
423 PROPERTIES
=> $struct->{PROPERTIES
},
431 my ($e, $pointer_default) = @_;
433 my $switch_type = has_property
($e, "switch_type");
434 unless (defined($switch_type)) { $switch_type = "uint32"; }
436 if (has_property
($e, "nodiscriminant")) { $switch_type = undef; }
439 foreach my $x (@
{$e->{ELEMENTS
}})
442 if ($x->{TYPE
} eq "EMPTY") {
443 $t = { TYPE
=> "EMPTY" };
445 $t = ParseElement
($x, $pointer_default);
447 if (has_property
($x, "default")) {
448 $t->{CASE
} = "default";
450 } elsif (defined($x->{PROPERTIES
}->{case
})) {
451 $t->{CASE
} = "case $x->{PROPERTIES}->{case}";
453 die("Union element $x->{NAME} has neither default nor case property");
461 SWITCH_TYPE
=> $switch_type,
462 ELEMENTS
=> \
@elements,
463 PROPERTIES
=> $e->{PROPERTIES
},
464 HAS_DEFAULT
=> $hasdefault,
471 my ($e, $pointer_default) = @_;
476 BASE_TYPE
=> Parse
::Pidl
::Typelist
::enum_type_fn
($e),
477 ELEMENTS
=> $e->{ELEMENTS
},
478 PROPERTIES
=> $e->{PROPERTIES
},
485 my ($e, $pointer_default) = @_;
490 BASE_TYPE
=> Parse
::Pidl
::Typelist
::bitmap_type_fn
($e),
491 ELEMENTS
=> $e->{ELEMENTS
},
492 PROPERTIES
=> $e->{PROPERTIES
},
499 my ($d, $pointer_default) = @_;
501 if ($d->{TYPE
} eq "STRUCT" or $d->{TYPE
} eq "UNION") {
502 CheckPointerTypes
($d, $pointer_default);
506 STRUCT
=> \
&ParseStruct
,
507 UNION
=> \
&ParseUnion
,
509 BITMAP
=> \
&ParseBitmap
,
510 TYPEDEF
=> \
&ParseTypedef
,
511 }->{$d->{TYPE
}}->($d, $pointer_default);
518 my ($d, $pointer_default) = @_;
520 if (defined($d->{DATA
}->{PROPERTIES
}) && !defined($d->{PROPERTIES
})) {
521 $d->{PROPERTIES
} = $d->{DATA
}->{PROPERTIES
};
524 my $data = ParseType
($d->{DATA
}, $pointer_default);
525 $data->{ALIGN
} = align_type
($d->{NAME
});
530 PROPERTIES
=> $d->{PROPERTIES
},
543 sub ParseFunction
($$$)
545 my ($ndr,$d,$opnum) = @_;
548 my $thisopnum = undef;
550 CheckPointerTypes
($d, $ndr->{PROPERTIES
}->{pointer_default_top
});
552 if (not defined($d->{PROPERTIES
}{noopnum
})) {
553 $thisopnum = ${$opnum};
557 foreach my $x (@
{$d->{ELEMENTS
}}) {
558 my $e = ParseElement
($x, $ndr->{PROPERTIES
}->{pointer_default
});
559 push (@
{$e->{DIRECTION
}}, "in") if (has_property
($x, "in"));
560 push (@
{$e->{DIRECTION
}}, "out") if (has_property
($x, "out"));
562 push (@elements, $e);
565 if ($d->{RETURN_TYPE
} ne "void") {
566 $rettype = expandAlias
($d->{RETURN_TYPE
});
570 if (has_property
($d, "async")) { $async = 1; }
577 RETURN_TYPE
=> $rettype,
578 PROPERTIES
=> $d->{PROPERTIES
},
579 ELEMENTS
=> \
@elements,
584 sub CheckPointerTypes
($$)
586 my ($s,$default) = @_;
588 foreach my $e (@
{$s->{ELEMENTS
}}) {
589 if ($e->{POINTERS
} and not defined(pointer_type
($e))) {
590 $e->{PROPERTIES
}->{$default} = 1;
595 sub FindNestedTypes
($$)
597 sub FindNestedTypes
($$);
600 return if not defined($t->{ELEMENTS
});
602 foreach (@
{$t->{ELEMENTS
}}) {
603 if (ref($_->{TYPE
}) eq "HASH") {
604 push (@
$l, $_->{TYPE
}) if (defined($_->{TYPE
}->{NAME
}));
605 FindNestedTypes
($l, $_->{TYPE
});
610 sub ParseInterface
($)
621 if (not has_property
($idl, "pointer_default")) {
622 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
623 # and "unique" in Microsoft Extensions mode (default)
624 $idl->{PROPERTIES
}->{pointer_default
} = "unique";
627 if (not has_property
($idl, "pointer_default_top")) {
628 $idl->{PROPERTIES
}->{pointer_default_top
} = "ref";
630 warning
($idl, "pointer_default_top() is a pidl extension and should not be used");
633 foreach my $d (@
{$idl->{DATA
}}) {
634 if ($d->{TYPE
} eq "DECLARE") {
635 push (@declares, $d);
636 } elsif ($d->{TYPE
} eq "FUNCTION") {
637 push (@functions, ParseFunction
($idl, $d, \
$opnum));
638 } elsif ($d->{TYPE
} eq "CONST") {
639 push (@consts, ParseConst
($idl, $d));
641 push (@types, ParseType
($d, $idl->{PROPERTIES
}->{pointer_default
}));
642 FindNestedTypes
(\
@types, $d);
648 if(defined $idl->{PROPERTIES
}->{version
}) {
649 $version = $idl->{PROPERTIES
}->{version
};
652 # If no endpoint is set, default to the interface name as a named pipe
653 if (!defined $idl->{PROPERTIES
}->{endpoint
}) {
654 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME
} . "]\"";
656 @endpoints = split / /, $idl->{PROPERTIES
}->{endpoint
};
660 NAME
=> $idl->{NAME
},
661 UUID
=> lc(has_property
($idl, "uuid")),
664 PROPERTIES
=> $idl->{PROPERTIES
},
665 FUNCTIONS
=> \
@functions,
668 DECLARES
=> \
@declares,
669 ENDPOINTS
=> \
@endpoints
673 # Convert a IDL tree to a NDR tree
674 # Gives a result tree describing all that's necessary for easily generating
675 # NDR parsers / generators
680 return undef unless (defined($idl));
682 Parse
::Pidl
::NDR
::Validate
($idl);
687 ($_->{TYPE
} eq "INTERFACE") && push(@ndr, ParseInterface
($_));
688 ($_->{TYPE
} eq "IMPORT") && push(@ndr, $_);
701 foreach my $l (@
{$e->{LEVELS
}}) {
702 return $l if ($seen);
703 ($seen = 1) if ($l == $fl);
714 foreach my $l (@
{$e->{LEVELS
}}) {
715 (return $prev) if ($l == $fl);
722 sub ContainsString
($)
726 foreach my $l (@
{$e->{LEVELS
}}) {
727 return 1 if ($l->{TYPE
} eq "ARRAY" and $l->{IS_ZERO_TERMINATED
});
733 sub ContainsDeferred
($$)
737 return 1 if ($l->{CONTAINS_DEFERRED
});
739 while ($l = GetNextLevel
($e,$l))
741 return 1 if ($l->{IS_DEFERRED
});
742 return 1 if ($l->{CONTAINS_DEFERRED
});
752 if ($e->{PARENT
} && $e->{PARENT
}->{NAME
}) {
753 return "$e->{PARENT}->{NAME}.$e->{NAME}";
756 if ($e->{PARENT
} && $e->{PARENT
}->{PARENT
}->{NAME
}) {
757 return "$e->{PARENT}->{PARENT}->{NAME}.$e->{NAME}";
761 return "$e->{PARENT}->{NAME}.$e->{NAME}";
767 ###################################
768 # find a sibling var in a structure
772 my($fn) = $e->{PARENT
};
774 if ($name =~ /\*(.*)/) {
778 for my $e2 (@
{$fn->{ELEMENTS
}}) {
779 return $e2 if ($e2->{NAME
} eq $name);
785 my %property_list = (
787 "helpstring" => ["INTERFACE", "FUNCTION"],
788 "version" => ["INTERFACE"],
789 "uuid" => ["INTERFACE"],
790 "endpoint" => ["INTERFACE"],
791 "pointer_default" => ["INTERFACE"],
792 "pointer_default_top" => ["INTERFACE"],
793 "helper" => ["INTERFACE"],
794 "authservice" => ["INTERFACE"],
797 "object" => ["INTERFACE"],
798 "local" => ["INTERFACE", "FUNCTION"],
799 "iid_is" => ["ELEMENT"],
800 "call_as" => ["FUNCTION"],
801 "idempotent" => ["FUNCTION"],
804 "noopnum" => ["FUNCTION"],
806 "out" => ["ELEMENT"],
807 "async" => ["FUNCTION"],
810 "ref" => ["ELEMENT"],
811 "ptr" => ["ELEMENT"],
812 "unique" => ["ELEMENT"],
813 "ignore" => ["ELEMENT"],
814 "relative" => ["ELEMENT"],
815 "relative_base" => ["TYPEDEF"],
817 "gensize" => ["TYPEDEF"],
818 "value" => ["ELEMENT"],
819 "flag" => ["ELEMENT", "TYPEDEF"],
822 "public" => ["FUNCTION", "TYPEDEF"],
823 "nopush" => ["FUNCTION", "TYPEDEF"],
824 "nopull" => ["FUNCTION", "TYPEDEF"],
825 "nosize" => ["FUNCTION", "TYPEDEF"],
826 "noprint" => ["FUNCTION", "TYPEDEF"],
827 "noejs" => ["FUNCTION", "TYPEDEF"],
830 "switch_is" => ["ELEMENT"],
831 "switch_type" => ["ELEMENT", "TYPEDEF"],
832 "nodiscriminant" => ["TYPEDEF"],
833 "case" => ["ELEMENT"],
834 "default" => ["ELEMENT"],
836 "represent_as" => ["ELEMENT"],
837 "transmit_as" => ["ELEMENT"],
840 "subcontext" => ["ELEMENT"],
841 "subcontext_size" => ["ELEMENT"],
842 "compression" => ["ELEMENT"],
845 "enum8bit" => ["TYPEDEF"],
846 "enum16bit" => ["TYPEDEF"],
847 "v1_enum" => ["TYPEDEF"],
850 "bitmap8bit" => ["TYPEDEF"],
851 "bitmap16bit" => ["TYPEDEF"],
852 "bitmap32bit" => ["TYPEDEF"],
853 "bitmap64bit" => ["TYPEDEF"],
856 "range" => ["ELEMENT"],
857 "size_is" => ["ELEMENT"],
858 "string" => ["ELEMENT"],
859 "noheader" => ["ELEMENT"],
860 "charset" => ["ELEMENT"],
861 "length_is" => ["ELEMENT"],
864 #####################################################################
865 # check for unknown properties
866 sub ValidProperties
($$)
870 return unless defined $e->{PROPERTIES
};
872 foreach my $key (keys %{$e->{PROPERTIES
}}) {
873 warning
($e, el_name
($e) . ": unknown property '$key'")
874 unless defined($property_list{$key});
876 fatal
($e, el_name
($e) . ": property '$key' not allowed on '$t'")
877 unless grep($t, @
{$property_list{$key}});
884 my $ti = getType
($t);
886 if (not defined ($ti)) {
888 } elsif ($ti->{DATA
}->{TYPE
} eq "ENUM") {
889 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti->{DATA
});
890 } elsif ($ti->{DATA
}->{TYPE
} eq "BITMAP") {
891 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti->{DATA
});
892 } elsif ($ti->{DATA
}->{TYPE
} eq "SCALAR") {
899 #####################################################################
900 # validate an element
905 ValidProperties
($e,"ELEMENT");
907 # Check whether switches are used correctly.
908 if (my $switch = has_property
($e, "switch_is")) {
909 my $e2 = find_sibling
($e, $switch);
910 my $type = getType
($e->{TYPE
});
912 if (defined($type) and $type->{DATA
}->{TYPE
} ne "UNION") {
913 fatal
($e, el_name
($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
916 if (not has_property
($type->{DATA
}, "nodiscriminant") and defined($e2)) {
917 my $discriminator_type = has_property
($type->{DATA
}, "switch_type");
918 $discriminator_type = "uint32" unless defined ($discriminator_type);
920 my $t1 = mapToScalar
($discriminator_type);
922 if (not defined($t1)) {
923 fatal
($e, el_name
($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
926 my $t2 = mapToScalar
($e2->{TYPE
});
927 if (not defined($t2)) {
928 fatal
($e, el_name
($e) . ": unable to map variable used for switch_is() to scalar");
932 warning
($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 (has_property
($e, "subcontext")) {
954 warning
($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
957 if (defined (has_property
($e, "subcontext_size")) and not defined(has_property
($e, "subcontext"))) {
958 fatal
($e, el_name
($e) . " : subcontext_size() on non-subcontext element");
961 if (defined (has_property
($e, "compression")) and not defined(has_property
($e, "subcontext"))) {
962 fatal
($e, el_name
($e) . " : compression() on non-subcontext element");
965 if (!$e->{POINTERS
} && (
966 has_property
($e, "ptr") or
967 has_property
($e, "unique") or
968 has_property
($e, "relative") or
969 has_property
($e, "ref"))) {
970 fatal
($e, el_name
($e) . " : pointer properties on non-pointer element\n");
974 #####################################################################
980 ValidProperties
($enum, "ENUM");
983 #####################################################################
989 ValidProperties
($bitmap, "BITMAP");
992 #####################################################################
998 ValidProperties
($struct, "STRUCT");
1000 foreach my $e (@
{$struct->{ELEMENTS
}}) {
1001 $e->{PARENT
} = $struct;
1006 #####################################################################
1012 ValidProperties
($union,"UNION");
1014 if (has_property
($union->{PARENT
}, "nodiscriminant") and has_property
($union->{PARENT
}, "switch_type")) {
1015 fatal
($union->{PARENT
}, $union->{PARENT
}->{NAME
} . ": switch_type() on union without discriminant");
1018 foreach my $e (@
{$union->{ELEMENTS
}}) {
1019 $e->{PARENT
} = $union;
1021 if (defined($e->{PROPERTIES
}->{default}) and
1022 defined($e->{PROPERTIES
}->{case
})) {
1023 fatal
($e, "Union member $e->{NAME} can not have both default and case properties!");
1026 unless (defined ($e->{PROPERTIES
}->{default}) or
1027 defined ($e->{PROPERTIES
}->{case
})) {
1028 fatal
($e, "Union member $e->{NAME} must have default or case property");
1031 if (has_property
($e, "ref")) {
1032 fatal
($e, el_name
($e) . " : embedded ref pointers are not supported yet\n");
1040 #####################################################################
1044 my($typedef) = shift;
1045 my $data = $typedef->{DATA
};
1047 ValidProperties
($typedef, "TYPEDEF");
1049 $data->{PARENT
} = $typedef;
1051 ValidType
($data) if (ref($data) eq "HASH");
1054 #####################################################################
1055 # validate a function
1056 sub ValidFunction
($)
1060 ValidProperties
($fn,"FUNCTION");
1062 foreach my $e (@
{$fn->{ELEMENTS
}}) {
1064 if (has_property
($e, "ref") && !$e->{POINTERS
}) {
1065 fatal
($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1071 #####################################################################
1078 TYPEDEF
=> \
&ValidTypedef
,
1079 STRUCT
=> \
&ValidStruct
,
1080 UNION
=> \
&ValidUnion
,
1081 ENUM
=> \
&ValidEnum
,
1082 BITMAP
=> \
&ValidBitmap
1083 }->{$t->{TYPE
}}->($t);
1086 #####################################################################
1087 # parse the interface definitions
1088 sub ValidInterface
($)
1090 my($interface) = shift;
1091 my($data) = $interface->{DATA
};
1093 if (has_property
($interface, "helper")) {
1094 warning
($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1097 ValidProperties
($interface,"INTERFACE");
1099 if (has_property
($interface, "pointer_default")) {
1100 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1101 ("ref", "unique", "ptr"))) {
1102 fatal
($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1106 if (has_property
($interface, "object")) {
1107 if (has_property
($interface, "version") &&
1108 $interface->{PROPERTIES
}->{version
} != 0) {
1109 fatal
($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1112 if (!defined($interface->{BASE
}) &&
1113 not ($interface->{NAME
} eq "IUnknown")) {
1114 fatal
($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1118 foreach my $d (@
{$data}) {
1119 ($d->{TYPE
} eq "FUNCTION") && ValidFunction
($d);
1120 ($d->{TYPE
} eq "TYPEDEF" or
1121 $d->{TYPE
} eq "STRUCT" or
1122 $d->{TYPE
} eq "UNION" or
1123 $d->{TYPE
} eq "ENUM" or
1124 $d->{TYPE
} eq "BITMAP") && ValidType
($d);
1129 #####################################################################
1130 # Validate an IDL structure
1135 foreach my $x (@
{$idl}) {
1136 ($x->{TYPE
} eq "INTERFACE") &&
1138 ($x->{TYPE
} eq "IMPORTLIB") &&
1139 warning
($x, "importlib() not supported");