1 ###################################################
2 # Samba4 parser generator for IDL structures
3 # Copyright jelmer@samba.org 2005
4 # released under the GNU GPL
6 package Parse
::Pidl
::Typelist
;
10 @EXPORT_OK = qw(hasType getType mapType scalar_is_reference expandAlias);
11 use vars
qw($VERSION);
14 use Parse::Pidl::Util qw(has_property);
19 my @reference_scalars = (
20 "string", "string_array", "nbt_string",
21 "wrepl_nbt_name", "ipv4address"
24 # a list of known scalar types
31 "uint16" => "uint16_t",
33 "uint32" => "uint32_t",
34 "hyper" => "uint64_t",
36 "udlong" => "uint64_t",
37 "udlongr" => "uint64_t",
39 "DATA_BLOB" => "DATA_BLOB",
40 "string" => "const char *",
41 "string_array" => "const char **",
44 "NTTIME_1sec" => "NTTIME",
45 "NTTIME_hyper" => "NTTIME",
47 "NTSTATUS" => "NTSTATUS",
48 "COMRESULT" => "COMRESULT",
49 "nbt_string" => "const char *",
50 "wrepl_nbt_name"=> "struct nbt_name *",
51 "ipv4address" => "const char *",
55 "error_status_t" => "uint32",
56 "boolean8" => "uint8",
57 "boolean32" => "uint32",
65 "HRESULT" => "COMRESULT",
72 return $aliases{$name} if defined($aliases{$name});
77 # map from a IDL type to a C header type
82 # it's a bug when a type is not in the list
83 # of known scalars or has no mapping
84 return $scalars{$name} if defined($scalars{$name});
86 die("Unknown scalar type $name");
92 $typedefs{$t->{NAME
}} = $t;
98 return undef if not hasType
($t);
106 return 1 if (hasType
($t) and getType
($t)->{DATA
}->{TYPE
} eq $tt);
113 return 1 if defined($typedefs{$t});
121 return 0 unless(hasType
($type));
123 if (my $dt = getType
($type)->{DATA
}->{TYPE
}) {
124 return 1 if ($dt eq "SCALAR" or $dt eq "ENUM" or $dt eq "BITMAP");
130 sub scalar_is_reference
($)
134 return 1 if (grep(/^$name$/, @reference_scalars));
138 sub RegisterScalars
()
140 foreach (keys %scalars) {
156 $enum->{TYPE
} eq "ENUM" or die("not an enum");
157 if (has_property
($enum->{PARENT
}, "enum8bit")) {
159 } elsif (has_property
($enum->{PARENT
}, "v1_enum")) {
165 sub bitmap_type_fn
($)
169 $bitmap->{TYPE
} eq "BITMAP" or die("not an enum");
171 if (has_property
($bitmap, "bitmap8bit")) {
173 } elsif (has_property
($bitmap, "bitmap16bit")) {
175 } elsif (has_property
($bitmap, "bitmap64bit")) {
184 return "void" unless defined($t);
186 $t = expandAlias
($t);
188 unless ($dt or ($dt = getType
($t))) {
192 return mapScalarType
($t) if ($dt->{DATA
}->{TYPE
} eq "SCALAR");
193 return "enum $dt->{NAME}" if ($dt->{DATA
}->{TYPE
} eq "ENUM");
194 return "struct $dt->{NAME}" if ($dt->{DATA
}->{TYPE
} eq "STRUCT");
195 return "struct $dt->{NAME}" if ($dt->{DATA
}->{TYPE
} eq "INTERFACE");
196 return "union $dt->{NAME}" if ($dt->{DATA
}->{TYPE
} eq "UNION");
198 if ($dt->{DATA
}->{TYPE
} eq "BITMAP") {
199 return mapScalarType
(bitmap_type_fn
($dt->{DATA
}));
202 die("Unknown type $dt->{DATA}->{TYPE}");
209 foreach my $x (@
{$idl}) {
210 next if $x->{TYPE
} ne "INTERFACE";
212 # DCOM interfaces can be types as well
217 }) if (has_property
($x, "object"));
219 foreach my $y (@
{$x->{DATA
}}) {
221 $y->{TYPE
} eq "TYPEDEF"
222 or $y->{TYPE
} eq "DECLARE");