diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-05-25 13:50:27 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:17:01 -0500 |
commit | e427f58622e3d88c59953d6c1fb583acfb046213 (patch) | |
tree | 4fe708ec07cdcb85dd3af028e158505e065ca59e /source4/build/pidl/typelist.pm | |
parent | e7b3f91678a27d85791f7a62fc418988edc92214 (diff) | |
download | samba-e427f58622e3d88c59953d6c1fb583acfb046213.tar.gz samba-e427f58622e3d88c59953d6c1fb583acfb046213.tar.bz2 samba-e427f58622e3d88c59953d6c1fb583acfb046213.zip |
r6973: Merge new version of pidl into the main SAMBA_4_0 branch.
The main difference in this new version is the extra data structure generated
between the IDL data structure and the NDR parser:
IDL -> NDR -> { ndr_parser, ndr_header, eparser, etc }
This makes the ndr_parser.pm internals much more sane.
Other changes include:
- Remove unnecessary calls with NDR_BUFFERS (for example, GUID doesn't have any buffers, just scalars) as well as some (unnecessary) nested setting of flags.
- Parse array loops in the C code rather then calling ndr_pull_array(). This allows us to have, for example, arrays of pointers or arrays of pointers to arrays, etc..
- Use if() {} rather then if () goto foo; everywhere
- NDR_IN no longer implies LIBNDR_FLAG_REF_ALLOC
- By default, top level pointers are now "ref" (as is the default in
most other IDL compilers). This can be overridden using the
default_pointer_top() property.
- initial work on new ethereal parser generators by Alan DeKok and me
- pidl now writes errors in the standard format used by compilers, which
is parsable by most editors
- ability to warn about the fact that pidl extension(s) have been used,
useful for making sure IDL files work with other IDL compilers.
oh, and there's probably some other things I can't think of right now..
(This used to be commit 13cf227615f6b9e0e5fa62e59197024410254f01)
Diffstat (limited to 'source4/build/pidl/typelist.pm')
-rw-r--r-- | source4/build/pidl/typelist.pm | 219 |
1 files changed, 64 insertions, 155 deletions
diff --git a/source4/build/pidl/typelist.pm b/source4/build/pidl/typelist.pm index 8559878a69..f5a0650006 100644 --- a/source4/build/pidl/typelist.pm +++ b/source4/build/pidl/typelist.pm @@ -9,147 +9,6 @@ use strict; my %typedefs = (); -# a list of known scalar types -my $scalars = { - # 0 byte types - "void" => { - C_TYPE => "void", - NDR_ALIGN => 0 - }, - - # 1 byte types - "char" => { - C_TYPE => "char", - NDR_ALIGN => 1 - }, - "int8" => { - C_TYPE => "int8_t", - NDR_ALIGN => 1 - }, - "uint8" => { - C_TYPE => "uint8_t", - NDR_ALIGN => 1 - }, - - # 2 byte types - "int16" => { - C_TYPE => "int16_t", - NDR_ALIGN => 2 - }, - "uint16" => { C_TYPE => "uint16_t", - NDR_ALIGN => 2 - }, - - # 4 byte types - "int32" => { - C_TYPE => "int32_t", - NDR_ALIGN => 4 - }, - "uint32" => { C_TYPE => "uint32_t", - NDR_ALIGN => 4 - }, - - # 8 byte types - "int64" => { - C_TYPE => "int64_t", - NDR_ALIGN => 8 - }, - "hyper" => { - C_TYPE => "uint64_t", - NDR_ALIGN => 8 - }, - "dlong" => { - C_TYPE => "int64_t", - NDR_ALIGN => 4 - }, - "udlong" => { - C_TYPE => "uint64_t", - NDR_ALIGN => 4 - }, - "udlongr" => { - C_TYPE => "uint64_t", - NDR_ALIGN => 4 - }, - - # DATA_BLOB types - "DATA_BLOB" => { - C_TYPE => "DATA_BLOB", - NDR_ALIGN => 4 - }, - - # string types - "string" => { - C_TYPE => "const char *", - NDR_ALIGN => 4 #??? - }, - "string_array" => { - C_TYPE => "const char **", - NDR_ALIGN => 4 #??? - }, - - # time types - "time_t" => { - C_TYPE => "time_t", - NDR_ALIGN => 4 - }, - "NTTIME" => { - C_TYPE => "NTTIME", - NDR_ALIGN => 4 - }, - "NTTIME_1sec" => { - C_TYPE => "NTTIME", - NDR_ALIGN => 4 - }, - "NTTIME_hyper" => { - C_TYPE => "NTTIME", - NDR_ALIGN => 8 - }, - - - # error code types - "WERROR" => { - C_TYPE => "WERROR", - NDR_ALIGN => 4 - }, - "NTSTATUS" => { - C_TYPE => "NTSTATUS", - NDR_ALIGN => 4 - }, - - # special types - "nbt_string" => { - C_TYPE => "const char *", - NDR_ALIGN => 4 #??? - }, - "ipv4address" => { - C_TYPE => "const char *", - 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; @@ -159,7 +18,7 @@ sub addType($) sub getType($) { my $t = shift; - return undef unless(defined($typedefs{$t})); + return undef if not hasType($t); return $typedefs{$t}; } @@ -179,9 +38,17 @@ sub hasType($) return 0; } -sub RegisterScalars() +sub RegisterPrimitives() { - foreach my $k (keys %{$scalars}) { + 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) { $typedefs{$k} = { NAME => $k, TYPE => "TYPEDEF", @@ -218,25 +85,66 @@ 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 $e = shift; + my $t = shift; + die("Undef passed to mapType") unless defined($t); my $dt; - if ($e->{TYPE} eq "ENUM" or $e->{TYPE} eq "BITMAP") { - $dt = getType($e->{PARENT}->{NAME}); - } - - unless ($dt or $dt = getType($e->{TYPE})) { + return "void" if ($t eq "void"); + return "const char *" if ($t =~ "string"); + + unless ($dt or ($dt = getType($t))) { # Best guess - return "struct $e->{TYPE}"; + return "struct $t"; } - return mapScalarType($e->{TYPE}) if ($dt->{DATA}->{TYPE} eq "SCALAR"); + return mapScalarType($t) if ($dt->{DATA}->{TYPE} eq "SCALAR"); return "enum $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "ENUM"); return "struct $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "STRUCT"); return "struct $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "INTERFACE"); return "union $dt->{NAME}" if ($dt->{DATA}->{TYPE} eq "UNION"); - return mapScalarType(bitmap_type_fn($dt->{DATA})) if ($dt->{DATA}->{TYPE} eq "BITMAP"); + + if ($dt->{DATA}->{TYPE} eq "BITMAP") { + return mapScalarType(bitmap_type_fn($dt->{DATA})); + } die("Unknown type $dt->{DATA}->{TYPE}"); } @@ -258,11 +166,12 @@ sub LoadIdl($) foreach my $y (@{$x->{DATA}}) { addType($y) if ( $y->{TYPE} eq "TYPEDEF" - or $y->{TYPE} eq "DECLARE"); + or $y->{TYPE} eq "DECLARE"); } } } -RegisterScalars(); +RegisterPrimitives(); + 1; |