1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

r5466: Put the type information list in a seperate module

(require for some of the COM stuff)
(This used to be commit fbce7464b2)
This commit is contained in:
Jelmer Vernooij 2005-02-20 12:17:33 +00:00 committed by Gerald (Jerry) Carter
parent 64112074e9
commit c33c4569e5
4 changed files with 79 additions and 38 deletions

View File

@ -7,6 +7,7 @@ package IdlHeader;
use strict;
use needed;
use typelist;
my($res);
my($tab_depth);
@ -195,7 +196,7 @@ sub HeaderType($$$)
}
my $dt;
if (my $t = NdrParser::get_typedef($e->{TYPE})) {
if (my $t = typelist::getType($e->{TYPE})) {
$dt = $t->{DATA};
}

View File

@ -9,27 +9,19 @@ package NdrParser;
use strict;
use needed;
use typelist;
# list of known types
my %typedefs;
my %typefamily;
sub get_typedef($)
{
my $n = shift;
return $typedefs{$n};
}
sub get_typefamily($)
{
my $n = shift;
return $typefamily{$n};
}
sub RegisterPrimitives()
{
my %type_alignments =
(
my %scalar_alignments =
(
"char" => 1,
"int8" => 1,
"uint8" => 1,
@ -55,25 +47,22 @@ sub RegisterPrimitives()
"ipv4address" => 4,
"hyper" => 8,
"NTTIME_hyper" => 8
);
);
foreach my $k (keys %type_alignments) {
$typedefs{$k} = {
NAME => $k,
TYPE => "TYPEDEF",
DATA => {
TYPE => "SCALAR",
ALIGN => $type_alignments{$k}
}
};
$typefamily{SCALAR} = {
ALIGN => sub {
my $t = shift;
return $scalar_alignments{$t->{NAME}};
}
}
};
sub is_scalar_type($)
{
my $type = shift;
if (my $dt = $typedefs{$type}->{DATA}->{TYPE}) {
return 0 unless typelist::hasType($type);
if (my $dt = typelist::getType($type)->{DATA}->{TYPE}) {
return 1 if ($dt eq "SCALAR" or $dt eq "ENUM" or $dt eq "BITMAP");
}
@ -430,16 +419,16 @@ sub align_type
{
my $e = shift;
unless (defined($typedefs{$e}) && defined($typedefs{$e}->{DATA}->{TYPE})) {
unless (typelist::hasType($e)) {
# it must be an external type - all we can do is guess
# print "Warning: assuming alignment of unknown type '$e' is 4\n";
return 4;
}
my $dt = $typedefs{$e}->{DATA};
my $dt = typelist::getType($e)->{DATA};
return $dt->{ALIGN} if ($dt->{ALIGN});
return $typefamily{$dt->{TYPE}}->{ALIGN}->($dt);
my $tmp = $typefamily{$dt->{TYPE}}->{ALIGN}->($dt);
return $tmp;
}
#####################################################################
@ -657,7 +646,6 @@ sub ParseElementPushPtr($$$)
pidl "NDR_CHECK(ndr_push_unique_ptr(ndr, $var_prefix$e->{NAME}));";
}
#####################################################################
# print scalars in a structure element
sub ParseElementPrint($$)
@ -721,7 +709,7 @@ sub ParseElementPullSwitch($$$$)
my $cprefix = c_pull_prefix($e);
my $utype = $typedefs{$e->{TYPE}};
my $utype = typelist::getType($e->{TYPE});
check_null_pointer($switch_var);
@ -731,9 +719,9 @@ sub ParseElementPullSwitch($$$$)
my $type_decl = util::map_type($e2->{TYPE});
pidl "if (($ndr_flags) & NDR_SCALARS) {";
indent;
if ($typedefs{$e2->{TYPE}}->{DATA}->{TYPE} eq "ENUM") {
if (typelist::getType($e2->{TYPE})->{DATA}->{TYPE} eq "ENUM") {
$type_decl = util::enum_type_decl($e2);
} elsif ($typedefs{$e2->{TYPE}}->{DATA}->{TYPE} eq "BITMAP") {
} elsif (typelist::getType($e2->{TYPE})->{DATA}->{TYPE} eq "BITMAP") {
$type_decl = util::bitmap_type_decl($e2);
}
pidl "$type_decl _level;";
@ -783,7 +771,7 @@ sub ParseElementPushSwitch($$$$)
check_null_pointer($switch_var);
my $utype = $typedefs{$e->{TYPE}};
my $utype = typelist::getType($e->{TYPE});
if (!defined $utype ||
!util::has_property($utype, "nodiscriminant")) {
my $e2 = find_sibling($e, $switch);
@ -2104,7 +2092,7 @@ sub LoadInterface($)
foreach my $d (@{$x->{DATA}}) {
if (($d->{TYPE} eq "DECLARE") or ($d->{TYPE} eq "TYPEDEF")) {
$typedefs{$d->{NAME}} = $d;
typelist::addType($d);
if ($d->{DATA}->{TYPE} eq "STRUCT" or $d->{DATA}->{TYPE} eq "UNION") {
CheckPointerTypes($d->{DATA}, $x->{PROPERTIES}->{pointer_default});
}
@ -2190,7 +2178,4 @@ sub Parse($$)
return $res;
}
RegisterPrimitives();
1;

View File

@ -0,0 +1,56 @@
###################################################
# Samba4 parser generator for IDL structures
# Copyright jelmer@samba.org 2005
# released under the GNU GPL
package typelist;
use strict;
my %typedefs;
sub addType($)
{
my $t = shift;
$typedefs{$t->{NAME}} = $t;
}
sub getType($)
{
my $t = shift;
return undef unless(defined($typedefs{$t}));
return $typedefs{$t};
}
sub hasType($)
{
my $t = shift;
return 1 if defined($typedefs{$t});
return 0;
}
sub RegisterPrimitives()
{
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",
DATA => {
TYPE => "SCALAR",
NAME => $k
}
};
}
}
RegisterPrimitives();
1;

View File

@ -322,4 +322,3 @@ sub map_type($)
}
1;