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 mapScalarType);
43 use Parse
::Pidl
::Util
qw(has_property property_matches);
45 # Alignment of the built-in scalar types
46 my $scalar_alignment = {
67 'string_array' => 4, #???
76 'wrepl_nbt_name' => 4,
81 sub GetElementLevelTable
($$)
83 my ($e, $pointer_default) = @_;
87 my @bracket_array = ();
92 if (has_property
($e, "size_is")) {
93 @size_is = split /,/, has_property
($e, "size_is");
96 if (has_property
($e, "length_is")) {
97 @length_is = split /,/, has_property
($e, "length_is");
100 if (defined($e->{ARRAY_LEN
})) {
101 @bracket_array = @
{$e->{ARRAY_LEN
}};
104 if (has_property
($e, "out")) {
107 if (has_property
($e, "string") and not has_property
($e, "in")) { $needptrs++; }
108 if ($#bracket_array >= 0) { $needptrs = 0; }
110 warning
($e, "[out] argument `$e->{NAME}' not a pointer") if ($needptrs > $e->{POINTERS
});
113 # Parse the [][][][] style array stuff
114 for my $i (0 .. $#bracket_array) {
115 my $d = $bracket_array[$#bracket_array - $i];
118 my $is_surrounding = 0;
120 my $is_conformant = 0;
127 if ($size = shift @size_is) {
128 if ($e->{POINTERS
} < 1 and has_property
($e, "string")) {
130 delete($e->{PROPERTIES
}->{string
});
132 } elsif ((scalar(@size_is) == 0) and has_property
($e, "string")) {
134 delete($e->{PROPERTIES
}->{string
});
136 fatal
($e, "Must specify size_is() for conformant array!")
139 if (($length = shift @length_is) or $is_string) {
145 if ($e == $e->{PARENT
}->{ELEMENTS
}[-1]
146 and $e->{PARENT
}->{TYPE
} ne "FUNCTION") {
151 $is_fixed = 1 if (not $is_conformant and Parse
::Pidl
::Util
::is_constant
($size));
152 $is_inline = 1 if (not $is_conformant and not Parse
::Pidl
::Util
::is_constant
($size));
154 if ($i == 0 and $is_fixed and has_property
($e, "string")) {
158 delete($e->{PROPERTIES
}->{string
});
164 LENGTH_IS
=> $length,
165 IS_DEFERRED
=> $is_deferred,
166 IS_SURROUNDING
=> $is_surrounding,
167 IS_ZERO_TERMINATED
=> $is_string,
168 IS_VARYING
=> $is_varying,
169 IS_CONFORMANT
=> $is_conformant,
170 IS_FIXED
=> $is_fixed,
171 IS_INLINE
=> $is_inline
175 # Next, all the pointers
176 foreach my $i (1..$e->{POINTERS
}) {
177 my $level = "EMBEDDED";
178 # Top level "ref" pointers do not have a referrent identifier
179 $level = "TOP" if ($i == 1 and $e->{PARENT
}->{TYPE
} eq "FUNCTION");
183 # Only the first level gets the pointer type from the
184 # pointer property, the others get them from
185 # the pointer_default() interface property
187 # see http://msdn2.microsoft.com/en-us/library/aa378984(VS.85).aspx
188 # (Here they talk about the rightmost pointer, but testing shows
189 # they mean the leftmost pointer.)
193 $pt = pointer_type
($e);
195 $is_deferred = 1 if ($pt ne "ref" and $e->{PARENT
}->{TYPE
} eq "FUNCTION");
196 $pt = $pointer_default;
202 POINTER_INDEX
=> $pointer_idx,
203 IS_DEFERRED
=> "$is_deferred",
207 warning
($e, "top-level \[out\] pointer `$e->{NAME}' is not a \[ref\] pointer")
208 if ($i == 1 and $pt ne "ref" and
209 $e->{PARENT
}->{TYPE
} eq "FUNCTION" and
210 not has_property
($e, "in"));
214 # everything that follows will be deferred
215 $is_deferred = 1 if ($level ne "TOP");
217 my $array_size = shift @size_is;
224 if ($array_length = shift @length_is) {
227 $array_length = $array_size;
232 if (scalar(@size_is) == 0 and has_property
($e, "string") and
233 $i == $e->{POINTERS
}) {
235 $is_varying = $is_conformant = has_property
($e, "noheader")?
0:1;
236 delete($e->{PROPERTIES
}->{string
});
239 if ($array_size or $is_string) {
242 SIZE_IS
=> $array_size,
243 LENGTH_IS
=> $array_length,
244 IS_DEFERRED
=> $is_deferred,
246 IS_ZERO_TERMINATED
=> $is_string,
247 IS_VARYING
=> $is_varying,
248 IS_CONFORMANT
=> $is_conformant,
257 if (defined(has_property
($e, "subcontext"))) {
258 my $hdr_size = has_property
($e, "subcontext");
259 my $subsize = has_property
($e, "subcontext_size");
260 if (not defined($subsize)) {
265 TYPE
=> "SUBCONTEXT",
266 HEADER_SIZE
=> $hdr_size,
267 SUBCONTEXT_SIZE
=> $subsize,
268 IS_DEFERRED
=> $is_deferred,
269 COMPRESSION
=> has_property
($e, "compression"),
273 if (my $switch = has_property
($e, "switch_is")) {
276 SWITCH_IS
=> $switch,
277 IS_DEFERRED
=> $is_deferred
281 if (scalar(@size_is) > 0) {
282 fatal
($e, "size_is() on non-array element");
285 if (scalar(@length_is) > 0) {
286 fatal
($e, "length_is() on non-array element");
289 if (has_property
($e, "string")) {
290 fatal
($e, "string() attribute on non-array element");
295 DATA_TYPE
=> $e->{TYPE
},
296 IS_DEFERRED
=> $is_deferred,
297 CONTAINS_DEFERRED
=> can_contain_deferred
($e->{TYPE
}),
298 IS_SURROUNDING
=> 0 #FIXME
302 foreach (@
$order) { $_->{LEVEL_INDEX
} = $i; $i+=1; }
307 sub GetTypedefLevelTable
($$$)
309 my ($e, $data, $pointer_default) = @_;
318 foreach (@
$order) { $_->{LEVEL_INDEX
} = $i; $i+=1; }
323 #####################################################################
324 # see if a type contains any deferred data
325 sub can_contain_deferred
($)
327 sub can_contain_deferred
($);
330 return 1 unless (hasType
($type)); # assume the worst
332 $type = getType
($type);
334 return 0 if (Parse
::Pidl
::Typelist
::is_scalar
($type));
336 return can_contain_deferred
($type->{DATA
}) if ($type->{TYPE
} eq "TYPEDEF");
338 return 0 unless defined($type->{ELEMENTS
});
340 foreach (@
{$type->{ELEMENTS
}}) {
341 return 1 if ($_->{POINTERS
});
342 return 1 if (can_contain_deferred
($_->{TYPE
}));
352 return undef unless $e->{POINTERS
};
354 return "ref" if (has_property
($e, "ref"));
355 return "full" if (has_property
($e, "ptr"));
356 return "sptr" if (has_property
($e, "sptr"));
357 return "unique" if (has_property
($e, "unique"));
358 return "relative" if (has_property
($e, "relative"));
359 return "relative_short" if (has_property
($e, "relative_short"));
360 return "ignore" if (has_property
($e, "ignore"));
365 #####################################################################
366 # work out the correct alignment for a structure or union
367 sub find_largest_alignment
($)
372 for my $e (@
{$s->{ELEMENTS
}}) {
375 if ($e->{POINTERS
}) {
376 # this is a hack for NDR64
377 # the NDR layer translates this into
378 # an alignment of 4 for NDR and 8 for NDR64
380 } elsif (has_property
($e, "subcontext")) {
382 } elsif (has_property
($e, "transmit_as")) {
383 $a = align_type
($e->{PROPERTIES
}->{transmit_as
});
385 $a = align_type
($e->{TYPE
});
388 $align = $a if ($align < $a);
394 #####################################################################
401 if (ref($e) eq "HASH" and $e->{TYPE
} eq "SCALAR") {
402 return $scalar_alignment->{$e->{NAME
}};
405 return 0 if ($e eq "EMPTY");
407 unless (hasType
($e)) {
408 # it must be an external type - all we can do is guess
409 # warning($e, "assuming alignment of unknown type '$e' is 4");
413 my $dt = getType
($e);
415 if ($dt->{TYPE
} eq "TYPEDEF") {
416 return align_type
($dt->{DATA
});
417 } elsif ($dt->{TYPE
} eq "CONFORMANCE") {
418 return $dt->{DATA
}->{ALIGN
};
419 } elsif ($dt->{TYPE
} eq "ENUM") {
420 return align_type
(Parse
::Pidl
::Typelist
::enum_type_fn
($dt));
421 } elsif ($dt->{TYPE
} eq "BITMAP") {
422 return align_type
(Parse
::Pidl
::Typelist
::bitmap_type_fn
($dt));
423 } elsif (($dt->{TYPE
} eq "STRUCT") or ($dt->{TYPE
} eq "UNION")) {
424 # Struct/union without body: assume 4
425 return 4 unless (defined($dt->{ELEMENTS
}));
426 return find_largest_alignment
($dt);
429 die("Unknown data type type $dt->{TYPE}");
434 my ($e, $pointer_default) = @_;
436 $e->{TYPE
} = expandAlias
($e->{TYPE
});
438 if (ref($e->{TYPE
}) eq "HASH") {
439 $e->{TYPE
} = ParseType
($e->{TYPE
}, $pointer_default);
445 PROPERTIES
=> $e->{PROPERTIES
},
446 LEVELS
=> GetElementLevelTable
($e, $pointer_default),
447 REPRESENTATION_TYPE
=> ($e->{PROPERTIES
}->{represent_as
} or $e->{TYPE
}),
448 ALIGN
=> align_type
($e->{TYPE
}),
455 my ($struct, $pointer_default) = @_;
457 my $surrounding = undef;
461 NAME
=> $struct->{NAME
},
462 SURROUNDING_ELEMENT
=> undef,
464 PROPERTIES
=> $struct->{PROPERTIES
},
467 } unless defined($struct->{ELEMENTS
});
469 CheckPointerTypes
($struct, $pointer_default);
471 foreach my $x (@
{$struct->{ELEMENTS
}})
473 my $e = ParseElement
($x, $pointer_default);
474 if ($x != $struct->{ELEMENTS
}[-1] and
475 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
476 fatal
($x, "conformant member not at end of struct");
481 my $e = $elements[-1];
482 if (defined($e) and defined($e->{LEVELS
}[0]->{IS_SURROUNDING
}) and
483 $e->{LEVELS
}[0]->{IS_SURROUNDING
}) {
487 if (defined $e->{TYPE
} && $e->{TYPE
} eq "string"
488 && property_matches
($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
489 $surrounding = $struct->{ELEMENTS
}[-1];
493 if ($struct->{NAME
}) {
494 $align = align_type
($struct->{NAME
});
499 NAME
=> $struct->{NAME
},
500 SURROUNDING_ELEMENT
=> $surrounding,
501 ELEMENTS
=> \
@elements,
502 PROPERTIES
=> $struct->{PROPERTIES
},
510 my ($e, $pointer_default) = @_;
513 my $switch_type = has_property
($e, "switch_type");
514 unless (defined($switch_type)) { $switch_type = "uint32"; }
515 if (has_property
($e, "nodiscriminant")) { $switch_type = undef; }
520 SWITCH_TYPE
=> $switch_type,
522 PROPERTIES
=> $e->{PROPERTIES
},
523 HAS_DEFAULT
=> $hasdefault,
526 } unless defined($e->{ELEMENTS
});
528 CheckPointerTypes
($e, $pointer_default);
530 foreach my $x (@
{$e->{ELEMENTS
}})
533 if ($x->{TYPE
} eq "EMPTY") {
534 $t = { TYPE
=> "EMPTY" };
536 $t = ParseElement
($x, $pointer_default);
538 if (has_property
($x, "default")) {
539 $t->{CASE
} = "default";
541 } elsif (defined($x->{PROPERTIES
}->{case
})) {
542 $t->{CASE
} = "case $x->{PROPERTIES}->{case}";
544 die("Union element $x->{NAME} has neither default nor case property");
551 $align = align_type
($e->{NAME
});
557 SWITCH_TYPE
=> $switch_type,
558 ELEMENTS
=> \
@elements,
559 PROPERTIES
=> $e->{PROPERTIES
},
560 HAS_DEFAULT
=> $hasdefault,
568 my ($e, $pointer_default) = @_;
573 BASE_TYPE
=> Parse
::Pidl
::Typelist
::enum_type_fn
($e),
574 ELEMENTS
=> $e->{ELEMENTS
},
575 PROPERTIES
=> $e->{PROPERTIES
},
582 my ($e, $pointer_default) = @_;
587 BASE_TYPE
=> Parse
::Pidl
::Typelist
::bitmap_type_fn
($e),
588 ELEMENTS
=> $e->{ELEMENTS
},
589 PROPERTIES
=> $e->{PROPERTIES
},
596 my ($d, $pointer_default) = @_;
599 STRUCT
=> \
&ParseStruct
,
600 UNION
=> \
&ParseUnion
,
602 BITMAP
=> \
&ParseBitmap
,
603 TYPEDEF
=> \
&ParseTypedef
,
604 }->{$d->{TYPE
}}->($d, $pointer_default);
611 my ($d, $pointer_default) = @_;
613 if (defined($d->{DATA
}->{PROPERTIES
}) && !defined($d->{PROPERTIES
})) {
614 $d->{PROPERTIES
} = $d->{DATA
}->{PROPERTIES
};
617 my $data = ParseType
($d->{DATA
}, $pointer_default);
618 $data->{ALIGN
} = align_type
($d->{NAME
});
623 PROPERTIES
=> $d->{PROPERTIES
},
624 LEVELS
=> GetTypedefLevelTable
($d, $data, $pointer_default),
637 sub ParseFunction
($$$)
639 my ($ndr,$d,$opnum) = @_;
642 my $thisopnum = undef;
644 CheckPointerTypes
($d, "ref");
646 if (not defined($d->{PROPERTIES
}{noopnum
})) {
647 $thisopnum = ${$opnum};
651 foreach my $x (@
{$d->{ELEMENTS
}}) {
652 my $e = ParseElement
($x, $ndr->{PROPERTIES
}->{pointer_default
});
653 push (@
{$e->{DIRECTION
}}, "in") if (has_property
($x, "in"));
654 push (@
{$e->{DIRECTION
}}, "out") if (has_property
($x, "out"));
656 push (@elements, $e);
659 if ($d->{RETURN_TYPE
} ne "void") {
660 $rettype = expandAlias
($d->{RETURN_TYPE
});
664 if (has_property
($d, "async")) { $async = 1; }
671 RETURN_TYPE
=> $rettype,
672 PROPERTIES
=> $d->{PROPERTIES
},
673 ELEMENTS
=> \
@elements,
678 sub CheckPointerTypes
($$)
680 my ($s,$default) = @_;
682 return unless defined($s->{ELEMENTS
});
684 foreach my $e (@
{$s->{ELEMENTS
}}) {
685 if ($e->{POINTERS
} and not defined(pointer_type
($e))) {
686 $e->{PROPERTIES
}->{$default} = '1';
691 sub FindNestedTypes
($$)
693 sub FindNestedTypes
($$);
696 return unless defined($t->{ELEMENTS
});
697 return if ($t->{TYPE
} eq "ENUM");
698 return if ($t->{TYPE
} eq "BITMAP");
700 foreach (@
{$t->{ELEMENTS
}}) {
701 if (ref($_->{TYPE
}) eq "HASH") {
702 push (@
$l, $_->{TYPE
}) if (defined($_->{TYPE
}->{NAME
}));
703 FindNestedTypes
($l, $_->{TYPE
});
708 sub ParseInterface
($)
718 if (not has_property
($idl, "pointer_default")) {
719 # MIDL defaults to "ptr" in DCE compatible mode (/osf)
720 # and "unique" in Microsoft Extensions mode (default)
721 $idl->{PROPERTIES
}->{pointer_default
} = "unique";
724 foreach my $d (@
{$idl->{DATA
}}) {
725 if ($d->{TYPE
} eq "FUNCTION") {
726 push (@functions, ParseFunction
($idl, $d, \
$opnum));
727 } elsif ($d->{TYPE
} eq "CONST") {
728 push (@consts, ParseConst
($idl, $d));
730 push (@types, ParseType
($d, $idl->{PROPERTIES
}->{pointer_default
}));
731 FindNestedTypes
(\
@types, $d);
737 if(defined $idl->{PROPERTIES
}->{version
}) {
738 my @if_version = split(/\./, $idl->{PROPERTIES
}->{version
});
739 if ($if_version[0] == $idl->{PROPERTIES
}->{version
}) {
740 $version = $idl->{PROPERTIES
}->{version
};
742 $version = $if_version[1] << 16 | $if_version[0];
746 # If no endpoint is set, default to the interface name as a named pipe
747 if (!defined $idl->{PROPERTIES
}->{endpoint
}) {
748 push @endpoints, "\"ncacn_np:[\\\\pipe\\\\" . $idl->{NAME
} . "]\"";
750 @endpoints = split /,/, $idl->{PROPERTIES
}->{endpoint
};
754 NAME
=> $idl->{NAME
},
755 UUID
=> lc(has_property
($idl, "uuid")),
758 PROPERTIES
=> $idl->{PROPERTIES
},
759 FUNCTIONS
=> \
@functions,
762 ENDPOINTS
=> \
@endpoints
766 # Convert a IDL tree to a NDR tree
767 # Gives a result tree describing all that's necessary for easily generating
768 # NDR parsers / generators
773 return undef unless (defined($idl));
775 Parse
::Pidl
::NDR
::Validate
($idl);
780 ($_->{TYPE
} eq "CPP_QUOTE") && push(@ndr, $_);
781 ($_->{TYPE
} eq "INTERFACE") && push(@ndr, ParseInterface
($_));
782 ($_->{TYPE
} eq "IMPORT") && push(@ndr, $_);
795 foreach my $l (@
{$e->{LEVELS
}}) {
796 return $l if ($seen);
797 ($seen = 1) if ($l == $fl);
808 foreach my $l (@
{$e->{LEVELS
}}) {
809 (return $prev) if ($l == $fl);
816 sub ContainsString
($)
820 foreach my $l (@
{$e->{LEVELS
}}) {
821 return 1 if ($l->{TYPE
} eq "ARRAY" and $l->{IS_ZERO_TERMINATED
});
827 sub ContainsDeferred
($$)
831 return 1 if ($l->{CONTAINS_DEFERRED
});
833 while ($l = GetNextLevel
($e,$l))
835 return 1 if ($l->{IS_DEFERRED
});
836 return 1 if ($l->{CONTAINS_DEFERRED
});
845 my $name = "<ANONYMOUS>";
847 $name = $e->{NAME
} if defined($e->{NAME
});
849 if (defined($e->{PARENT
}) and defined($e->{PARENT
}->{NAME
})) {
850 return "$e->{PARENT}->{NAME}.$name";
853 if (defined($e->{PARENT
}) and
854 defined($e->{PARENT
}->{PARENT
}) and
855 defined($e->{PARENT
}->{PARENT
}->{NAME
})) {
856 return "$e->{PARENT}->{PARENT}->{NAME}.$name";
862 ###################################
863 # find a sibling var in a structure
867 my($fn) = $e->{PARENT
};
869 if ($name =~ /\*(.*)/) {
873 for my $e2 (@
{$fn->{ELEMENTS
}}) {
874 return $e2 if ($e2->{NAME
} eq $name);
880 my %property_list = (
882 "helpstring" => ["INTERFACE", "FUNCTION"],
883 "version" => ["INTERFACE"],
884 "uuid" => ["INTERFACE"],
885 "endpoint" => ["INTERFACE"],
886 "pointer_default" => ["INTERFACE"],
887 "helper" => ["INTERFACE"],
888 "pyhelper" => ["INTERFACE"],
889 "authservice" => ["INTERFACE"],
890 "restricted" => ["INTERFACE"],
891 "no_srv_register" => ["INTERFACE"],
894 "object" => ["INTERFACE"],
895 "local" => ["INTERFACE", "FUNCTION"],
896 "iid_is" => ["ELEMENT"],
897 "call_as" => ["FUNCTION"],
898 "idempotent" => ["FUNCTION"],
901 "noopnum" => ["FUNCTION"],
903 "out" => ["ELEMENT"],
904 "async" => ["FUNCTION"],
907 "ref" => ["ELEMENT"],
908 "ptr" => ["ELEMENT"],
909 "unique" => ["ELEMENT"],
910 "ignore" => ["ELEMENT"],
911 "relative" => ["ELEMENT"],
912 "relative_short" => ["ELEMENT"],
913 "null_is_ffffffff" => ["ELEMENT"],
914 "relative_base" => ["TYPEDEF", "STRUCT", "UNION"],
916 "gensize" => ["TYPEDEF", "STRUCT", "UNION"],
917 "value" => ["ELEMENT"],
918 "flag" => ["ELEMENT", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
921 "public" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
922 "nopush" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
923 "nopull" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
924 "nosize" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
925 "noprint" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "ELEMENT"],
926 "nopython" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"],
927 "todo" => ["FUNCTION"],
930 "switch_is" => ["ELEMENT"],
931 "switch_type" => ["ELEMENT", "UNION"],
932 "nodiscriminant" => ["UNION"],
933 "case" => ["ELEMENT"],
934 "default" => ["ELEMENT"],
936 "represent_as" => ["ELEMENT"],
937 "transmit_as" => ["ELEMENT"],
940 "subcontext" => ["ELEMENT"],
941 "subcontext_size" => ["ELEMENT"],
942 "compression" => ["ELEMENT"],
945 "enum8bit" => ["ENUM"],
946 "enum16bit" => ["ENUM"],
947 "v1_enum" => ["ENUM"],
950 "bitmap8bit" => ["BITMAP"],
951 "bitmap16bit" => ["BITMAP"],
952 "bitmap32bit" => ["BITMAP"],
953 "bitmap64bit" => ["BITMAP"],
956 "range" => ["ELEMENT", "PIPE"],
957 "size_is" => ["ELEMENT"],
958 "string" => ["ELEMENT"],
959 "noheader" => ["ELEMENT"],
960 "charset" => ["ELEMENT"],
961 "length_is" => ["ELEMENT"],
964 #####################################################################
965 # check for unknown properties
966 sub ValidProperties
($$)
970 return unless defined $e->{PROPERTIES
};
972 foreach my $key (keys %{$e->{PROPERTIES
}}) {
973 warning
($e, el_name
($e) . ": unknown property '$key'")
974 unless defined($property_list{$key});
976 fatal
($e, el_name
($e) . ": property '$key' not allowed on '$t'")
977 unless grep(/^$t$/, @
{$property_list{$key}});
985 return $t->{NAME
} if (ref($t) eq "HASH" and $t->{TYPE
} eq "SCALAR");
986 my $ti = getType
($t);
988 if (not defined ($ti)) {
990 } elsif ($ti->{TYPE
} eq "TYPEDEF") {
991 return mapToScalar
($ti->{DATA
});
992 } elsif ($ti->{TYPE
} eq "ENUM") {
993 return Parse
::Pidl
::Typelist
::enum_type_fn
($ti);
994 } elsif ($ti->{TYPE
} eq "BITMAP") {
995 return Parse
::Pidl
::Typelist
::bitmap_type_fn
($ti);
1001 #####################################################################
1002 # validate an element
1007 ValidProperties
($e,"ELEMENT");
1009 # Check whether switches are used correctly.
1010 if (my $switch = has_property
($e, "switch_is")) {
1011 my $e2 = find_sibling
($e, $switch);
1012 my $type = getType
($e->{TYPE
});
1014 if (defined($type) and $type->{DATA
}->{TYPE
} ne "UNION") {
1015 fatal
($e, el_name
($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
1018 if (not has_property
($type->{DATA
}, "nodiscriminant") and defined($e2)) {
1019 my $discriminator_type = has_property
($type->{DATA
}, "switch_type");
1020 $discriminator_type = "uint32" unless defined ($discriminator_type);
1022 my $t1 = mapScalarType
(mapToScalar
($discriminator_type));
1024 if (not defined($t1)) {
1025 fatal
($e, el_name
($e) . ": unable to map discriminator type '$discriminator_type' to scalar");
1028 my $t2 = mapScalarType
(mapToScalar
($e2->{TYPE
}));
1029 if (not defined($t2)) {
1030 fatal
($e, el_name
($e) . ": unable to map variable used for switch_is() to scalar");
1034 warning
($e, el_name
($e) . ": switch_is() is of type $e2->{TYPE} ($t2), while discriminator type for union $type->{NAME} is $discriminator_type ($t1)");
1039 if (has_property
($e, "subcontext") and has_property
($e, "represent_as")) {
1040 fatal
($e, el_name
($e) . " : subcontext() and represent_as() can not be used on the same element");
1043 if (has_property
($e, "subcontext") and has_property
($e, "transmit_as")) {
1044 fatal
($e, el_name
($e) . " : subcontext() and transmit_as() can not be used on the same element");
1047 if (has_property
($e, "represent_as") and has_property
($e, "transmit_as")) {
1048 fatal
($e, el_name
($e) . " : represent_as() and transmit_as() can not be used on the same element");
1051 if (has_property
($e, "represent_as") and has_property
($e, "value")) {
1052 fatal
($e, el_name
($e) . " : represent_as() and value() can not be used on the same element");
1055 if (has_property
($e, "subcontext")) {
1056 warning
($e, "subcontext() is deprecated. Use represent_as() or transmit_as() instead");
1059 if (defined (has_property
($e, "subcontext_size")) and not defined(has_property
($e, "subcontext"))) {
1060 fatal
($e, el_name
($e) . " : subcontext_size() on non-subcontext element");
1063 if (defined (has_property
($e, "compression")) and not defined(has_property
($e, "subcontext"))) {
1064 fatal
($e, el_name
($e) . " : compression() on non-subcontext element");
1067 if (!$e->{POINTERS
} && (
1068 has_property
($e, "ptr") or
1069 has_property
($e, "unique") or
1070 has_property
($e, "relative") or
1071 has_property
($e, "relative_short") or
1072 has_property
($e, "ref"))) {
1073 fatal
($e, el_name
($e) . " : pointer properties on non-pointer element\n");
1077 #####################################################################
1083 ValidProperties
($enum, "ENUM");
1086 #####################################################################
1092 ValidProperties
($bitmap, "BITMAP");
1095 #####################################################################
1099 my($struct) = shift;
1101 ValidProperties
($struct, "STRUCT");
1103 return unless defined($struct->{ELEMENTS
});
1105 foreach my $e (@
{$struct->{ELEMENTS
}}) {
1106 $e->{PARENT
} = $struct;
1111 #####################################################################
1117 ValidProperties
($union,"UNION");
1119 if (has_property
($union->{PARENT
}, "nodiscriminant") and
1120 has_property
($union->{PARENT
}, "switch_type")) {
1121 fatal
($union->{PARENT
}, $union->{PARENT
}->{NAME
} . ": switch_type(" . $union->{PARENT
}->{PROPERTIES
}->{switch_type
} . ") on union without discriminant");
1124 return unless defined($union->{ELEMENTS
});
1126 foreach my $e (@
{$union->{ELEMENTS
}}) {
1127 $e->{PARENT
} = $union;
1129 if (defined($e->{PROPERTIES
}->{default}) and
1130 defined($e->{PROPERTIES
}->{case
})) {
1131 fatal
($e, "Union member $e->{NAME} can not have both default and case properties!");
1134 unless (defined ($e->{PROPERTIES
}->{default}) or
1135 defined ($e->{PROPERTIES
}->{case
})) {
1136 fatal
($e, "Union member $e->{NAME} must have default or case property");
1139 if (has_property
($e, "ref")) {
1140 fatal
($e, el_name
($e) . ": embedded ref pointers are not supported yet\n");
1148 #####################################################################
1153 my $data = $pipe->{DATA
};
1155 ValidProperties
($pipe, "PIPE");
1157 fatal
($pipe, $pipe->{NAME
} . ": 'pipe' is not yet supported by pidl");
1160 #####################################################################
1164 my($typedef) = shift;
1165 my $data = $typedef->{DATA
};
1167 ValidProperties
($typedef, "TYPEDEF");
1169 $data->{PARENT
} = $typedef;
1171 $data->{FILE
} = $typedef->{FILE
} unless defined($data->{FILE
});
1172 $data->{LINE
} = $typedef->{LINE
} unless defined($data->{LINE
});
1174 ValidType
($data) if (ref($data) eq "HASH");
1177 #####################################################################
1178 # validate a function
1179 sub ValidFunction
($)
1183 ValidProperties
($fn,"FUNCTION");
1185 foreach my $e (@
{$fn->{ELEMENTS
}}) {
1187 if (has_property
($e, "ref") && !$e->{POINTERS
}) {
1188 fatal
($e, "[ref] variables must be pointers ($fn->{NAME}/$e->{NAME})");
1194 #####################################################################
1201 TYPEDEF
=> \
&ValidTypedef
,
1202 STRUCT
=> \
&ValidStruct
,
1203 UNION
=> \
&ValidUnion
,
1204 ENUM
=> \
&ValidEnum
,
1205 BITMAP
=> \
&ValidBitmap
,
1207 }->{$t->{TYPE
}}->($t);
1210 #####################################################################
1211 # parse the interface definitions
1212 sub ValidInterface
($)
1214 my($interface) = shift;
1215 my($data) = $interface->{DATA
};
1217 if (has_property
($interface, "helper")) {
1218 warning
($interface, "helper() is pidl-specific and deprecated. Use `include' instead");
1221 ValidProperties
($interface,"INTERFACE");
1223 if (has_property
($interface, "pointer_default")) {
1224 if (not grep (/$interface->{PROPERTIES}->{pointer_default}/,
1225 ("ref", "unique", "ptr"))) {
1226 fatal
($interface, "Unknown default pointer type `$interface->{PROPERTIES}->{pointer_default}'");
1230 if (has_property
($interface, "object")) {
1231 if (has_property
($interface, "version") &&
1232 $interface->{PROPERTIES
}->{version
} != 0) {
1233 fatal
($interface, "Object interfaces must have version 0.0 ($interface->{NAME})");
1236 if (!defined($interface->{BASE
}) &&
1237 not ($interface->{NAME
} eq "IUnknown")) {
1238 fatal
($interface, "Object interfaces must all derive from IUnknown ($interface->{NAME})");
1242 foreach my $d (@
{$data}) {
1243 ($d->{TYPE
} eq "FUNCTION") && ValidFunction
($d);
1244 ($d->{TYPE
} eq "TYPEDEF" or
1245 $d->{TYPE
} eq "STRUCT" or
1246 $d->{TYPE
} eq "UNION" or
1247 $d->{TYPE
} eq "ENUM" or
1248 $d->{TYPE
} eq "BITMAP" or
1249 $d->{TYPE
} eq "PIPE") && ValidType
($d);
1254 #####################################################################
1255 # Validate an IDL structure
1260 foreach my $x (@
{$idl}) {
1261 ($x->{TYPE
} eq "INTERFACE") &&
1263 ($x->{TYPE
} eq "IMPORTLIB") &&
1264 fatal
($x, "importlib() not supported");
1268 sub is_charset_array
($$)
1272 return 0 if ($l->{TYPE
} ne "ARRAY");
1274 my $nl = GetNextLevel
($e,$l);
1276 return 0 unless ($nl->{TYPE
} eq "DATA");
1278 return has_property
($e, "charset");