diff options
author | Stefan Metzmacher <metze@samba.org> | 2005-05-30 00:19:58 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:17:14 -0500 |
commit | 89a17e60a14783e8560d3babc8a9a328adc3c94c (patch) | |
tree | 7aaa93cd78bb26f76618eab8cf79a04e1fc28633 /source4/build/pidl/typelist.pm | |
parent | 4f1a5b716972bc2af916a528399c9dc0c2f18c35 (diff) | |
download | samba-89a17e60a14783e8560d3babc8a9a328adc3c94c.tar.gz samba-89a17e60a14783e8560d3babc8a9a328adc3c94c.tar.bz2 samba-89a17e60a14783e8560d3babc8a9a328adc3c94c.zip |
r7084: - readd the work from rev 6516,6517,6572
- use a single list of scalars
- let "string" not be so special anymore
- fix support for "string_array"
metze
(This used to be commit e1fa7ae6c8420dc582578e084b9c0d641bcfbd73)
Diffstat (limited to 'source4/build/pidl/typelist.pm')
-rw-r--r-- | source4/build/pidl/typelist.pm | 237 |
1 files changed, 184 insertions, 53 deletions
diff --git a/source4/build/pidl/typelist.pm b/source4/build/pidl/typelist.pm index f5a0650006..a8600cedbe 100644 --- a/source4/build/pidl/typelist.pm +++ b/source4/build/pidl/typelist.pm @@ -9,6 +9,166 @@ use strict; my %typedefs = (); +# a list of known scalar types +my $scalars = { + # 0 byte types + "void" => { + C_TYPE => "void", + IS_REFERENCE => 0, + NDR_ALIGN => 0 + }, + + # 1 byte types + "char" => { + C_TYPE => "char", + IS_REFERENCE => 0, + NDR_ALIGN => 1 + }, + "int8" => { + C_TYPE => "int8_t", + IS_REFERENCE => 0, + NDR_ALIGN => 1 + }, + "uint8" => { + C_TYPE => "uint8_t", + IS_REFERENCE => 0, + NDR_ALIGN => 1 + }, + + # 2 byte types + "int16" => { + C_TYPE => "int16_t", + IS_REFERENCE => 0, + NDR_ALIGN => 2 + }, + "uint16" => { C_TYPE => "uint16_t", + IS_REFERENCE => 0, + NDR_ALIGN => 2 + }, + + # 4 byte types + "int32" => { + C_TYPE => "int32_t", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + "uint32" => { C_TYPE => "uint32_t", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + + # 8 byte types + "hyper" => { + C_TYPE => "uint64_t", + IS_REFERENCE => 0, + NDR_ALIGN => 8 + }, + "dlong" => { + C_TYPE => "int64_t", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + "udlong" => { + C_TYPE => "uint64_t", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + "udlongr" => { + C_TYPE => "uint64_t", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + + # DATA_BLOB types + "DATA_BLOB" => { + C_TYPE => "DATA_BLOB", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + + # string types + "string" => { + C_TYPE => "const char *", + IS_REFERENCE => 1, + NDR_ALIGN => 4 #??? + }, + "string_array" => { + C_TYPE => "const char **", + IS_REFERENCE => 1, + NDR_ALIGN => 4 #??? + }, + + # time types + "time_t" => { + C_TYPE => "time_t", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + "NTTIME" => { + C_TYPE => "NTTIME", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + "NTTIME_1sec" => { + C_TYPE => "NTTIME", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + "NTTIME_hyper" => { + C_TYPE => "NTTIME", + IS_REFERENCE => 0, + NDR_ALIGN => 8 + }, + + + # error code types + "WERROR" => { + C_TYPE => "WERROR", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + "NTSTATUS" => { + C_TYPE => "NTSTATUS", + IS_REFERENCE => 0, + NDR_ALIGN => 4 + }, + + # special types + "nbt_string" => { + C_TYPE => "const char *", + IS_REFERENCE => 1, + NDR_ALIGN => 4 #??? + }, + "ipv4address" => { + C_TYPE => "const char *", + IS_REFERENCE => 1, + NDR_ALIGN => 4 + } +}; + +# map from a IDL type to a C header type +sub mapScalarType($) +{ + my $name = shift; + + # it's a bug when a type is not in the list + # of known scalars or has no mapping + return $scalars->{$name}{C_TYPE} if defined($scalars->{$name}) and defined($scalars->{$name}{C_TYPE}); + + die("Unknown scalar type $name"); +} + +sub getScalarAlignment($) +{ + my $name = shift; + + # it's a bug when a type is not in the list + # of known scalars or has no mapping + return $scalars->{$name}{NDR_ALIGN} if defined($scalars->{$name}) and defined($scalars->{$name}{NDR_ALIGN}); + + die("Unknown scalar type $name"); +} + sub addType($) { my $t = shift; @@ -38,17 +198,30 @@ sub hasType($) return 0; } -sub RegisterPrimitives() +sub is_scalar($) { - my @primitives = ( - "char", "int8", "uint8", "short", "wchar_t", - "int16", "uint16", "long", "int32", "uint32", - "dlong", "udlong", "udlongr", "NTTIME", "NTTIME_1sec", - "time_t", "DATA_BLOB", "error_status_t", "WERROR", - "NTSTATUS", "boolean32", "unsigned32", "ipv4address", - "hyper", "NTTIME_hyper"); - - foreach my $k (@primitives) { + my $type = shift; + + return 0 unless(hasType($type)); + + if (my $dt = getType($type)->{DATA}->{TYPE}) { + return 1 if ($dt eq "SCALAR" or $dt eq "ENUM" or $dt eq "BITMAP"); + } + + return 0; +} + +sub scalar_is_reference($) +{ + my $name = shift; + + return $scalars->{$name}{IS_REFERENCE} if defined($scalars->{$name}) and defined($scalars->{$name}{IS_REFERENCE}); + return 0; +} + +sub RegisterScalars() +{ + foreach my $k (keys %{$scalars}) { $typedefs{$k} = { NAME => $k, TYPE => "TYPEDEF", @@ -85,53 +258,12 @@ sub bitmap_type_fn($) return "uint32"; } -# provide mappings between IDL base types and types in our headers -my %scalar_type_mappings = - ( - "int8" => "int8_t", - "uint8" => "uint8_t", - "short" => "int16_t", - "wchar_t" => "uint16_t", - "int16" => "int16_t", - "uint16" => "uint16_t", - "int32" => "int32_t", - "uint32" => "uint32_t", - "int64" => "int64_t", - "dlong" => "int64_t", - "udlong" => "uint64_t", - "udlongr" => "uint64_t", - "hyper" => "uint64_t", - "NTTIME" => "NTTIME", - "NTTIME_1sec" => "NTTIME", - "time_t" => "time_t", - "NTTIME_hyper" => "NTTIME", - "NTSTATUS" => "NTSTATUS", - "WERROR" => "WERROR", - "DATA_BLOB" => "DATA_BLOB", - "ipv4address" => "const char *", - "nbt_string" => "const char *" - ); - -# map from a IDL type to a C header type -sub mapScalarType($) -{ - my $name = shift; - die("Undef passed to mapScalarType") unless defined($name); - if (defined($scalar_type_mappings{$name})) { - return $scalar_type_mappings{$name}; - } - die("Tried to map non-scalar type $name"); -} - sub mapType($) { my $t = shift; die("Undef passed to mapType") unless defined($t); my $dt; - return "void" if ($t eq "void"); - return "const char *" if ($t =~ "string"); - unless ($dt or ($dt = getType($t))) { # Best guess return "struct $t"; @@ -171,7 +303,6 @@ sub LoadIdl($) } } -RegisterPrimitives(); - +RegisterScalars(); 1; |