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 = {
62 'string_array' => 4, #???
71 'wrepl_nbt_name' => 4,
75 sub GetElementLevelTable
($$)
77 my ($e, $pointer_default) = @_;
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;
121 if ($size = shift @size_is) {
122 } elsif ((scalar(@size_is) == 0) and has_property
($e, "string")) {
124 delete($e->{PROPERTIES
}->{string
});
126 fatal
($e, "Must specify size_is() for conformant array!")
129 if (($length = shift @length_is) or $is_string) {
135 if ($e == $e->{PARENT
}->{ELEMENTS
}[-1]
136 and $e->{PARENT
}->{TYPE
} ne "FUNCTION") {
141 $is_fixed = 1 if (not $is_conformant and Parse
::Pidl
::Util
::is_constant
($size));
142 $is_inline = 1 if (not $is_conformant and not Parse
::Pidl
::Util
::is_constant
($size));
147 LENGTH_IS
=> $length,
148 IS_DEFERRED
=> $is_deferred,
149 IS_SURROUNDING
=> $is_surrounding,
150 IS_ZERO_TERMINATED
=> $is_string,
151 IS_VARYING
=> $is_varying,
152 IS_CONFORMANT
=> $is_conformant,
153 IS_FIXED
=> $is_fixed,
154 IS_INLINE
=> $is_inline
158 # Next, all the pointers
159 foreach my $i (1..$e->{POINTERS
}) {
160 my $level = "EMBEDDED";
161 # Top level "ref" pointers do not have a referrent identifier
162 $level = "TOP" if ($i == 1 and $e->{PARENT
}->{TYPE
} eq "FUNCTION");
166 # Only the first level gets the pointer type from the
167 # pointer property, the others get them from
168 # the pointer_default() interface property
170 # see http://msdn2.microsoft.com/en-us/library/aa378984(VS.85).aspx
171 # (Here they talk about the rightmost pointer, but testing shows
172 # they mean the leftmost pointer.)
176 $pt = pointer_type
($e);
178 $is_deferred = 1 if ($pt ne "ref" and $e->{PARENT
}->{TYPE
} eq "FUNCTION");
179 $pt = $pointer_default;
185 POINTER_INDEX
=> $pointer_idx,
186 IS_DEFERRED
=> "$is_deferred",
190 warning
($e, "top-level \[out\] pointer `$e->{NAME}' is not a \[ref\] pointer")
191 if ($i == 1 and $pt ne "ref" and
192 $e->{PARENT
}->{TYPE
} eq "FUNCTION" and
193 not has_property
($e, "in"));
197 # everything that follows will be deferred
198 $is_deferred = 1 if ($level ne "TOP");
200 my $array_size = shift @size_is;
207 if ($array_length = shift @length_is) {
210 $array_length = $array_size;
215 if (scalar(@size_is) == 0 and has_property
($e, "string") and
216 $i == $e->{POINTERS
}) {
218 $is_varying = $is_conformant = has_property
($e, "noheader")?
0:1;
219 delete($e->{PROPERTIES
}->{string
});
222 if ($array_size or $is_string) {
225 SIZE_IS
=> $array_size,
226 LENGTH_IS
=> $array_length,
227 IS_DEFERRED
=> $is_deferred,
229 IS_ZERO_TERMINATED
=> $is_string,
230 IS_VARYING
=> $is_varying,
231 IS_CONFORMANT
=> $is_conformant,
240 if (defined(has_property
($e, "subcontext"))) {
241 my $hdr_size = has_property
($e, "subcontext");
242 my $subsize = has_property
($e, "subcontext_size");
243 if (not defined($subsize)) {
248 TYPE
=> "SUBCONTEXT",
249 HEADER_SIZE
=> $hdr_size,
250 SUBCONTEXT_SIZE
=> $subsize,
251 IS_DEFERRED
=> $is_deferred,
252 COMPRESSION
=> has_property
($e, "compression"),
256 if (my $switch = has_property
($e, "switch_is")) {
259 SWITCH_IS
=> $switch,
260 IS_DEFERRED
=> $is_deferred
264 if (scalar(@size_is) > 0) {
265 fatal
($e, "size_is() on non-array element");
268 if (scalar(@length_is) > 0) {
269 fatal
($e, "length_is() on non-array element");
272 if (has_property
($e, "string")) {
273 fatal
($e, "string() attribute on non-array element");
278 DATA_TYPE
=> $e->{TYPE
},
279 IS_DEFERRED
=> $is_deferred,
280 CONTAINS_DEFERRED
=> can_contain_deferred
($e->{TYPE
}),
281 IS_SURROUNDING
=> 0 #FIXME
285 foreach (@
$order) { $_->{LEVEL_INDEX
} = $i; $i+=1; }
290 #####################################################################
291 # see if a type contains any deferred data
292 sub can_contain_deferred
($)
294 sub can_contain_deferred
($);
297 return 1 unless (hasType
($type)); # assume the worst
299 $type = getType
($type);
301 return 0 if (Parse
::Pidl
::Typelist
::is_scalar
($type));
303 return can_contain_deferred
($type->{DATA
}) if ($type->{TYPE
} eq "TYPEDEF");
305 return 0 unless defined($type->{ELEMENTS
});
307 foreach (@
{$type->{ELEMENTS
}}) {
308 return 1 if ($_->{POINTERS
});
309 return 1 if (can_contain_deferred
($_->{TYPE
}));
319 return undef unless $e->{POINTERS
};
321 return "ref" if (has_property
($e, "ref"));
322 return "full" if (has_property
($e, "ptr"));
323 return "sptr" if (has_property
($e, "sptr"));
324 return "unique" if (has_property
($e, "unique"));
325 return "relative" if (has_property
($e, "relative"));
326 return "ignore" if (has_property
($e, "ignore"));
331 #####################################################################
332 # work out the correct alignment for a structure or union
333 sub find_largest_alignment
($)
338 for my $e (@
{$s->{ELEMENTS
}}) {
341 if ($e->{POINTERS
}) {
343 } elsif (has_property
($e, "subcontext")) {
345 } elsif (has_property
($e, "transmit_as")) {
346 $a = align_type
($e->{PROPERTIES
}->{transmit_as
});
348 $a = align_type
($e->{TYPE
});
351 $align = $a if ($align < $a);
357 #####################################################################
364 if (ref($e) eq "HASH" and $e->{TYPE
} eq "SCALAR") {
365 return $scalar_alignment->{$e->{NAME
}};
368 return 0 if ($e eq "EMPTY");
370 unless (hasType
($e)) {
371 # it must be an external type - all we can do is guess
372 # warning($e, "assuming alignment of unknown type '$e' is 4");
376 my $dt = getType
($e);
378 if ($dt->{TYPE
} eq "TYPEDEF") {
379 return align_type
($dt->{DATA
});
380 } elsif ($dt->{TYPE
} eq "ENUM") {
381 return align_type
(Parse
::Pidl
::Typelist
::enum_type_fn
($dt));
382 } elsif ($dt->{TYPE
} eq "BITMAP") {
383 return align_type
(Parse
::Pidl
::Typelist
::bitmap_type_fn
($dt));
384 } elsif (($dt->{TYPE
} eq "STRUCT") or ($dt->{TYPE
} eq "UNION")) {
385 # Struct/union without body: assume 4
386 return 4 unless (defined($dt->{ELEMENTS
}));
387 return find_largest_alignment
($dt);
390 die("Unknown data type type $dt->{TYPE}");
395 my ($e, $pointer_default) = @_;
397 $e->{TYPE
} = expandAlias
($e->{TYPE
});
399 if (ref($e->{TYPE
}) eq "HASH") {
400 $e->{TYPE
} = ParseType
($e->{TYPE
}, $pointer_default);
406 PROPERTIES
=> $e->{PROPERTIES
},
407 LEVELS
=> GetElementLevelTable
($e, $pointer_default),
408 REPRESENTATION_TYPE
=> ($e->{PROPERTIES
}->{represent_as
} or $e->{TYPE
}),
409 ALIGN
=> align_type
($e->{TYPE
}),
416 my ($struct, $pointer_default) = @_;
418 my $surrounding = undef;
422 NAME
=> $struct->{NAME
},
423 SURROUNDING_ELEMENT
=> undef,
425 PROPERTIES
=> $struct->{PROPERTIES
},
428 } unless defined($struct->{ELEMENTS
});
430 CheckPointerTypes
($struct, $pointer_default);
432 foreach my $x (@
{$struct->{ELEMENTS
}})
434 my $e = ParseElement
($x, $pointer_default);
435 if ($x != $struct->{ELEMENTS
}[-1] and
436 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
437 fatal
($x, "conformant member not at end of struct");
442 my $e = $elements[-1];
443 if (defined($e) and defined($e->{LEVELS
}[0]->{IS_SURROUNDING
}) and
444 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
448 if (defined $e->{TYPE
} && $e->{TYPE
} eq "string"
449 && property_matches
($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
450 $surrounding = $struct->{ELEMENTS
}[-1];
454 if ($struct->{NAME
}) {
455 $align = align_type
($struct->{NAME
});
460 NAME
=> $struct->{NAME
},
461 SURROUNDING_ELEMENT
=> $surrounding,
462 ELEMENTS
=> \
@elements,
463 PROPERTIES
=> $struct->{PROPERTIES
},
471 my ($e, $pointer_default) = @_;
474 my $switch_type = has_property
($e, "switch_type");
475 unless (defined($switch_type)) { $switch_type = "uint32"; }
476 if (has_property
($e, "nodiscriminant")) { $switch_type = undef; }
481 SWITCH_TYPE
=> $switch_type,
483 PROPERTIES
=> $e->{PROPERTIES
},
484 HAS_DEFAULT
=> $hasdefault,
486 } unless defined($e->{ELEMENTS
});
488 CheckPointerTypes
($e, $pointer_default);
490 foreach my $x (@
{$e->{ELEMENTS
}})
493 if ($x->{TYPE
} eq "EMPTY") {
494 $t = { TYPE
=> "EMPTY" };
496 $t = ParseElement
($x, $pointer_default);
498 if (has_property
($x, "default")) {
499 $t->{CASE
} = "default";
501 } elsif (defined($x->{PROPERTIES
}->{case
})) {
502 $t->{CASE
} = "case $x->{PROPERTIES}->{case}";
504 die("Union element $x->{NAME} has neither default nor case property");
512 SWITCH_TYPE
=> $switch_type,
513 ELEMENTS
=> \
@elements,
514 PROPERTIES
=> $e->{PROPERTIES
},
515 HAS_DEFAULT
=> $hasdefault,
522 my ($e, $pointer_default) = @_;
527 BASE_TYPE
=> Parse
::Pidl
::Typelist
::enum_type_fn
($e),
528 ELEMENTS
=> $e->{ELEMENTS
},
529 PROPERTIES
=> $e->{PROPERTIES
},
536 my ($e, $pointer_default) = @_;
541 BASE_TYPE
=> Parse
::Pidl
::Typelist
::bitmap_type_fn
($e),
542 ELEMENTS
=> $e->{ELEMENTS
},
543 PROPERTIES
=> $e->{PROPERTIES
},
550 my ($d, $pointer_default) = @_;
553 STRUCT
=> \
&ParseStruct
,
554 UNION
=> \
&ParseUnion
,
556 BITMAP
=> \
&ParseBitmap
,
557 TYPEDEF
=> \
&ParseTypedef
,
558 }->{$d->{TYPE
}}->($d, $pointer_default);
565 my ($d, $pointer_default) = @_;
567 if (defined($d->{DATA
}->{PROPERTIES
}) && !defined($d->{PROPERTIES
})) {
568 $d->{PROPERTIES
} = $d->{DATA
}->{PROPERTIES
};
571 my $data = ParseType
($d->{DATA
}, $pointer_default);
572 $data->{ALIGN
} = align_type
($d->{NAME
});
577 PROPERTIES
=> $d->{PROPERTIES
},
590 sub ParseFunction
($$$)
592 my ($ndr,$d,$opnum) = @_;
595 my $thisopnum = undef;
597 CheckPointerTypes
($d, "ref");
599 if (not defined($d->{PROPERTIES
}{noopnum
})) {
600 $thisopnum = ${$opnum};
604 foreach my $x (@
{$d->{ELEMENTS
}}) {
605 my $e = ParseElement
($x, $ndr->{PROPERTIES
}->{pointer_default
});
606 push (@
{$e->{DIRECTION
}}, "in") if (has_property
($x, "in"));
607 push (@
{$e->{DIRECTION
}}, "out") if (has_property
($x, "out"));
609 push (@elements, $e);
612 if ($d->{RETURN_TYPE
} ne "void") {
613 $rettype = expandAlias
($d->{RETURN_TYPE
});
617 if (has_property
($d, "async")) { $async = 1; }
624 RETURN_TYPE
=> $rettype,
625 PROPERTIES
=> $d->{PROPERTIES
},
626 ELEMENTS
=> \
@elements,
631 sub CheckPointerTypes
($$)
633 my ($s,$default) = @_;
635 return unless defined($s->{ELEMENTS
});
637 foreach my $e (@
{$s->{ELEMENTS
}}) {
638 if ($e->{POINTERS
} and not defined(pointer_type
($e))) {
639 $e->{PROPERTIES
}->{$default} = '1';
644 sub FindNestedTypes
($$)
646 sub FindNestedTypes
($$);
649 return unless defined($t->{ELEMENTS
});
650 return if ($t->{TYPE
} eq "ENUM");
651 return if ($t->{TYPE
} eq "BITMAP");
653 foreach (@
{$t->{ELEMENTS
}}) {
654 if (ref($_->{TYPE
}) eq "HASH") {
655 push (@
$l, $_->{TYPE
}) if (defined($_->{TYPE
}->{NAME
}));
656 FindNestedTypes
($l, $_->{TYPE
});
661 sub ParseInterface
($)
671 if (not has_property
($idl, "pointer_default")) {
672 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
673 # and "unique" in Microsoft Extensions mode (default)
674 $idl->{PROPERTIES
}->{pointer_default
} = "unique";
677 foreach my $d (@
{$idl->{DATA
}}) {
678 if ($d->{TYPE
} eq "FUNCTION") {
679 push (@functions, ParseFunction
($idl, $d, \
$opnum));
680 } elsif ($d->{TYPE
} eq "CONST") {
681 push (@consts, ParseConst
($idl, $d));
683 push (@types, ParseType
($d, $idl->{PROPERTIES
}->{pointer_default
}));
684 FindNestedTypes
(\
@types, $d);
690 if(defined $idl->{PROPERTIES
}->{version
}) {
691 my @if_version = split(/\./, $idl->{PROPERTIES
}->{version
});
692 if ($if_version[0] == $idl->{PROPERTIES
}->{version
}) {
693 $version = $idl->{PROPERTIES
}->{version
};
695 $version = $if_version[1] << 16 | $if_version[0];
699 # If no endpoint is set, default to the interface name as a named pipe
700 if (!defined $idl->{PROPERTIES
}->{endpoint
}) {
701 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME
} . "]\"";
703 @endpoints = split /,/, $idl->{PROPERTIES
}->{endpoint
};
707 NAME
=> $idl->{NAME
},
708 UUID
=> lc(has_property
($idl, "uuid")),
711 PROPERTIES
=> $idl->{PROPERTIES
},
712 FUNCTIONS
=> \
@functions,
715 ENDPOINTS
=> \
@endpoints
719 # Convert a IDL tree to a NDR tree
720 # Gives a result tree describing all that's necessary for easily generating
721 # NDR parsers / generators
726 return undef unless (defined($idl));
728 Parse
::Pidl
::NDR
::Validate
($idl);
733 ($_->{TYPE
} eq "CPP_QUOTE") && push(@ndr, $_);
734 ($_->{TYPE
} eq "INTERFACE") && push(@ndr, ParseInterface
($_));
735 ($_->{TYPE
} eq "IMPORT") && push(@ndr, $_);
748 foreach my $l (@
{$e->{LEVELS
}}) {
749 return $l if ($seen);
750 ($seen = 1) if ($l == $fl);
761 foreach my $l (@
{$e->{LEVELS
}}) {
762 (return $prev) if ($l == $fl);
769 sub ContainsString
($)
773 foreach my $l (@
{$e->{LEVELS
}}) {
774 return 1 if ($l->{TYPE
} eq "ARRAY" and $l->{IS_ZERO_TERMINATED
});
780 sub ContainsDeferred
($$)
784 return 1 if ($l->{CONTAINS_DEFERRED
});
786 while ($l = GetNextLevel
($e,$l))
788 return 1 if ($l->{IS_DEFERRED
});
789 return 1 if ($l->{CONTAINS_DEFERRED
});
798 my $name = "<ANONYMOUS>";
800 $name = $e->{NAME
} if defined($e->{NAME
});
802 if (defined($e->{PARENT
}) and defined($e->{PARENT
}->{NAME
})) {
803 return "$e->{PARENT}->{NAME}.$name";
806 if (defined($e->{PARENT
}) and
807 defined($e->{PARENT
}->{PARENT
}) and
808 defined($e->{PARENT
}->{PARENT
}->{NAME
})) {
809 return "$e->{PARENT}->{PARENT}->{NAME}.$name";
815 ###################################
816 # find a sibling var in a structure
820 my($fn) = $e->{PARENT
};
822 if ($name =~ /\*(.*)/) {
826 for my $e2 (@
{$fn->{ELEMENTS
}}) {
827 return $e2 if ($e2->{NAME
} eq $name);
833 my %property_list = (
835 "helpstring" => ["INTERFACE", "FUNCTION"],
836 "version" => ["INTERFACE"],
837 "uuid" => ["INTERFACE"],
838 "endpoint" => ["INTERFACE"],
839 "pointer_default" => ["INTERFACE"],
840 "helper" => ["INTERFACE"],
841 "authservice" => ["INTERFACE"],
844 "object" => ["INTERFACE"],
845 "local" => ["INTERFACE", "FUNCTION"],
846 "iid_is" => ["ELEMENT"],
847 "call_as" => ["FUNCTION"],
848 "idempotent" => ["FUNCTION"],
851 "noopnum" => ["FUNCTION"],
853 "out" => ["ELEMENT"],
854 "async" => ["FUNCTION"],
857 "ref" => ["ELEMENT"],
858 "ptr" => ["ELEMENT"],
859 "unique" => ["ELEMENT"],
860 "ignore" => ["ELEMENT"],
861 "relative" => ["ELEMENT"],
862 "relative_base" => ["TYPEDEF", "STRUCT", "UNION"],
864 "gensize" => ["TYPEDEF", "STRUCT", "UNION"],
865 "value" => ["ELEMENT"],
866 "flag" => ["ELEMENT", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
869 "public" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
870 "nopush" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
871 "nopull" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
872 "nosize" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
873 "noprint" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "ELEMENT"],
874 "noejs" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
875 "todo" => ["FUNCTION"],
878 "switch_is" => ["ELEMENT"],
879 "switch_type" => ["ELEMENT", "UNION"],
880 "nodiscriminant" => ["UNION"],
881 "case" => ["ELEMENT"],
882 "default" => ["ELEMENT"],
884 "represent_as" => ["ELEMENT"],
885 "transmit_as" => ["ELEMENT"],
888 "subcontext" => ["ELEMENT"],
889 "subcontext_size" => ["ELEMENT"],
890 "compression" => ["ELEMENT"],
893 "enum8bit" => ["ENUM"],
894 "enum16bit" => ["ENUM"],
895 "v1_enum" => ["ENUM"],
898 "bitmap8bit" => ["BITMAP"],
899 "bitmap16bit" => ["BITMAP"],
900 "bitmap32bit" => ["BITMAP"],
901 "bitmap64bit" => ["BITMAP"],
904 "range" => ["ELEMENT"],
905 "size_is" => ["ELEMENT"],
906 "string" => ["ELEMENT"],
907 "noheader" => ["ELEMENT"],
908 "charset" => ["ELEMENT"],
909 "length_is" => ["ELEMENT"],
912 #####################################################################
913 # check for unknown properties
914 sub ValidProperties
($$)
918 return unless defined $e->{PROPERTIES
};
920 foreach my $key (keys %{$e->{PROPERTIES
}}) {
921 warning
($e, el_name
($e) . ": unknown property '$key'")
922 unless defined($property_list{$key});
924 fatal
($e, el_name
($e) . ": property '$key' not allowed on '$t'")
925 unless grep(/^$t$/, @
{$property_list{$key}});
933 return $t->{NAME
} if (ref($t) eq "HASH" and $t->{TYPE
} eq "SCALAR");
934 my $ti = getType
($t);
936 if (not defined ($ti)) {
938 } elsif ($ti->{TYPE
} eq "TYPEDEF") {
939 return mapToScalar
($ti->{DATA
});
940 } elsif ($ti->{TYPE
} eq "ENUM") {
941 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti);
942 } elsif ($ti->{TYPE
} eq "BITMAP") {
943 return Parse
::Pidl
::Typelist
::bitmap_type_fn
($ti);
949 #####################################################################
950 # validate an element
955 ValidProperties
($e,"ELEMENT");
957 # Check whether switches are used correctly.
958 if (my $switch = has_property
($e, "switch_is")) {
959 my $e2 = find_sibling
($e, $switch);
960 my $type = getType
($e->{TYPE
});
962 if (defined($type) and $type->{DATA
}->{TYPE
} ne "UNION") {
963 fatal
($e, el_name
($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
966 if (not has_property
($type->{DATA
}, "nodiscriminant") and defined($e2)) {
967 my $discriminator_type = has_property
($type->{DATA
}, "switch_type");
968 $discriminator_type = "uint32" unless defined ($discriminator_type);
970 my $t1 = mapToScalar
($discriminator_type);
972 if (not defined($t1)) {
973 fatal
($e, el_name
($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
976 my $t2 = mapToScalar
($e2->{TYPE
});
977 if (not defined($t2)) {
978 fatal
($e, el_name
($e) . ": unable to map variable used for switch_is() to scalar");
982 warning
($e, el_name
($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
987 if (has_property
($e, "subcontext") and has_property
($e, "represent_as")) {
988 fatal
($e, el_name
($e) . " : subcontext() and represent_as() can not be used on the same element");
991 if (has_property
($e, "subcontext") and has_property
($e, "transmit_as")) {
992 fatal
($e, el_name
($e) . " : subcontext() and transmit_as() can not be used on the same element");
995 if (has_property
($e, "represent_as") and has_property
($e, "transmit_as")) {
996 fatal
($e, el_name
($e) . " : represent_as() and transmit_as() can not be used on the same element");
999 if (has_property
($e, "represent_as") and has_property
($e, "value")) {
1000 fatal
($e, el_name
($e) . " : represent_as() and value() can not be used on the same element");
1003 if (has_property
($e, "subcontext")) {
1004 warning
($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
1007 if (defined (has_property
($e, "subcontext_size")) and not defined(has_property
($e, "subcontext"))) {
1008 fatal
($e, el_name
($e) . " : subcontext_size() on non-subcontext element");
1011 if (defined (has_property
($e, "compression")) and not defined(has_property
($e, "subcontext"))) {
1012 fatal
($e, el_name
($e) . " : compression() on non-subcontext element");
1015 if (!$e->{POINTERS
} && (
1016 has_property
($e, "ptr") or
1017 has_property
($e, "unique") or
1018 has_property
($e, "relative") or
1019 has_property
($e, "ref"))) {
1020 fatal
($e, el_name
($e) . " : pointer properties on non-pointer element\n");
1024 #####################################################################
1030 ValidProperties
($enum, "ENUM");
1033 #####################################################################
1039 ValidProperties
($bitmap, "BITMAP");
1042 #####################################################################
1046 my($struct) = shift;
1048 ValidProperties
($struct, "STRUCT");
1050 return unless defined($struct->{ELEMENTS
});
1052 foreach my $e (@
{$struct->{ELEMENTS
}}) {
1053 $e->{PARENT
} = $struct;
1058 #####################################################################
1064 ValidProperties
($union,"UNION");
1066 if (has_property
($union->{PARENT
}, "nodiscriminant") and has_property
($union->{PARENT
}, "switch_type")) {
1067 fatal
($union->{PARENT
}, $union->{PARENT
}->{NAME
} . ": switch_type() on union without discriminant");
1070 return unless defined($union->{ELEMENTS
});
1072 foreach my $e (@
{$union->{ELEMENTS
}}) {
1073 $e->{PARENT
} = $union;
1075 if (defined($e->{PROPERTIES
}->{default}) and
1076 defined($e->{PROPERTIES
}->{case
})) {
1077 fatal
($e, "Union member $e->{NAME} can not have both default and case properties!");
1080 unless (defined ($e->{PROPERTIES
}->{default}) or
1081 defined ($e->{PROPERTIES
}->{case
})) {
1082 fatal
($e, "Union member $e->{NAME} must have default or case property");
1085 if (has_property
($e, "ref")) {
1086 fatal
($e, el_name
($e) . " : embedded ref pointers are not supported yet\n");
1094 #####################################################################
1098 my($typedef) = shift;
1099 my $data = $typedef->{DATA
};
1101 ValidProperties
($typedef, "TYPEDEF");
1103 $data->{PARENT
} = $typedef;
1105 $data->{FILE
} = $typedef->{FILE
} unless defined($data->{FILE
});
1106 $data->{LINE
} = $typedef->{LINE
} unless defined($data->{LINE
});
1108 ValidType
($data) if (ref($data) eq "HASH");
1111 #####################################################################
1112 # validate a function
1113 sub ValidFunction
($)
1117 ValidProperties
($fn,"FUNCTION");
1119 foreach my $e (@
{$fn->{ELEMENTS
}}) {
1121 if (has_property
($e, "ref") && !$e->{POINTERS
}) {
1122 fatal
($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1128 #####################################################################
1135 TYPEDEF
=> \
&ValidTypedef
,
1136 STRUCT
=> \
&ValidStruct
,
1137 UNION
=> \
&ValidUnion
,
1138 ENUM
=> \
&ValidEnum
,
1139 BITMAP
=> \
&ValidBitmap
1140 }->{$t->{TYPE
}}->($t);
1143 #####################################################################
1144 # parse the interface definitions
1145 sub ValidInterface
($)
1147 my($interface) = shift;
1148 my($data) = $interface->{DATA
};
1150 if (has_property
($interface, "helper")) {
1151 warning
($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1154 ValidProperties
($interface,"INTERFACE");
1156 if (has_property
($interface, "pointer_default")) {
1157 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1158 ("ref", "unique", "ptr"))) {
1159 fatal
($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1163 if (has_property
($interface, "object")) {
1164 if (has_property
($interface, "version") &&
1165 $interface->{PROPERTIES
}->{version
} != 0) {
1166 fatal
($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1169 if (!defined($interface->{BASE
}) &&
1170 not ($interface->{NAME
} eq "IUnknown")) {
1171 fatal
($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1175 foreach my $d (@
{$data}) {
1176 ($d->{TYPE
} eq "FUNCTION") && ValidFunction
($d);
1177 ($d->{TYPE
} eq "TYPEDEF" or
1178 $d->{TYPE
} eq "STRUCT" or
1179 $d->{TYPE
} eq "UNION" or
1180 $d->{TYPE
} eq "ENUM" or
1181 $d->{TYPE
} eq "BITMAP") && ValidType
($d);
1186 #####################################################################
1187 # Validate an IDL structure
1192 foreach my $x (@
{$idl}) {
1193 ($x->{TYPE
} eq "INTERFACE") &&
1195 ($x->{TYPE
} eq "IMPORTLIB") &&
1196 fatal
($x, "importlib() not supported");
1200 sub is_charset_array
($$)
1204 return 0 if ($l->{TYPE
} ne "ARRAY");
1206 my $nl = GetNextLevel
($e,$l);
1208 return 0 unless ($nl->{TYPE
} eq "DATA");
1210 return has_property
($e, "charset");