summaryrefslogtreecommitdiff
path: root/source4/build/pidl
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-02-13 13:55:22 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:09:49 -0500
commitff0e9d44bf2de825a9f9e20ef4ff01dbffd988fb (patch)
tree281c6a8fe1013a374008d662b0fbea9f35c2e39c /source4/build/pidl
parentff6e58a7c4da70880276aad482820b0d17be635b (diff)
downloadsamba-ff0e9d44bf2de825a9f9e20ef4ff01dbffd988fb.tar.gz
samba-ff0e9d44bf2de825a9f9e20ef4ff01dbffd988fb.tar.bz2
samba-ff0e9d44bf2de825a9f9e20ef4ff01dbffd988fb.zip
r5377: Put push/pull/print functions for the various types in a hash.
(This used to be commit afadd172981c8753b7e974154a843c36ef73df3a)
Diffstat (limited to 'source4/build/pidl')
-rw-r--r--source4/build/pidl/ndr.pm181
1 files changed, 54 insertions, 127 deletions
diff --git a/source4/build/pidl/ndr.pm b/source4/build/pidl/ndr.pm
index f3f40fb784..ae9f5b2292 100644
--- a/source4/build/pidl/ndr.pm
+++ b/source4/build/pidl/ndr.pm
@@ -2,7 +2,7 @@
# Samba4 NDR parser generator for IDL structures
# Copyright tridge@samba.org 2000-2003
# Copyright tpot@samba.org 2001
-# Copyright jelmer@samba.org 2004
+# Copyright jelmer@samba.org 2004-2005
# released under the GNU GPL
package NdrParser;
@@ -13,7 +13,9 @@ use needed;
# list of known types
our %typedefs;
-my %type_alignments =
+sub RegisterPrimitives()
+{
+ my %type_alignments =
(
"char" => 1,
"int8" => 1,
@@ -40,15 +42,16 @@ my %type_alignments =
"NTTIME_hyper" => 8
);
-foreach my $k (keys %type_alignments) {
- $typedefs{$k} = {
- NAME => $k,
- TYPE => "TYPEDEF",
- DATA => {
- TYPE => "SCALAR",
- ALIGN => $type_alignments{$k}
- }
- };
+ foreach my $k (keys %type_alignments) {
+ $typedefs{$k} = {
+ NAME => $k,
+ TYPE => "TYPEDEF",
+ DATA => {
+ TYPE => "SCALAR",
+ ALIGN => $type_alignments{$k}
+ }
+ };
+ }
}
sub is_scalar_type($)
@@ -56,9 +59,7 @@ sub is_scalar_type($)
my $type = shift;
if (my $dt = $typedefs{$type}->{DATA}->{TYPE}) {
- return 1 if ($dt eq "SCALAR");
- return 1 if ($dt eq "ENUM");
- return 1 if ($dt eq "BITMAP");
+ return 1 if ($dt eq "SCALAR" or $dt eq "ENUM" or $dt eq "BITMAP");
}
return 0;
@@ -173,22 +174,6 @@ sub pidl($)
$res .= shift;
}
-#####################################################################
-# parse a properties list
-sub ParseProperties($)
-{
- my($props) = shift;
- foreach my $d (@{$props}) {
- if (ref($d) ne "HASH") {
- pidl "[$d] ";
- } else {
- foreach my $k (keys %{$d}) {
- pidl "[$k($d->{$k})] ";
- }
- }
- }
-}
-
###################################
# find a sibling var in a structure
sub find_sibling($$)
@@ -328,7 +313,6 @@ sub end_flags($)
}
}
-
#####################################################################
# work out the correct alignment for a structure or union
sub struct_alignment
@@ -460,7 +444,6 @@ sub CheckArraySizes($$)
}
}
-
#####################################################################
# parse an array - pull side
sub ParseArrayPull($$$)
@@ -1320,55 +1303,29 @@ sub ParseUnionPull($)
end_flags($e);
}
-
-#####################################################################
-# parse a type
-sub ParseTypePush($)
-{
- my($data) = shift;
-
- ($data->{TYPE} eq "STRUCT") &&
- ParseStructPush($data);
- ($data->{TYPE} eq "UNION") &&
- ParseUnionPush($data);
- ($data->{TYPE} eq "ENUM") &&
- ParseEnumPush($data);
- ($data->{TYPE} eq "BITMAP") &&
- ParseBitmapPush($data);
-}
-
-#####################################################################
-# generate a print function for a type
-sub ParseTypePrint($)
-{
- my($data) = shift;
-
- ($data->{TYPE} eq "STRUCT") &&
- ParseStructPrint($data);
- ($data->{TYPE} eq "UNION") &&
- ParseUnionPrint($data);
- ($data->{TYPE} eq "ENUM") &&
- ParseEnumPrint($data);
- ($data->{TYPE} eq "BITMAP") &&
- ParseBitmapPrint($data);
-}
-
-#####################################################################
-# parse a type
-sub ParseTypePull($)
-{
- my($data) = shift;
-
- ($data->{TYPE} eq "STRUCT") &&
- ParseStructPull($data);
- ($data->{TYPE} eq "UNION") &&
- ParseUnionPull($data);
- ($data->{TYPE} eq "ENUM") &&
- ParseEnumPull($data);
- ($data->{TYPE} eq "BITMAP") &&
- ParseBitmapPull($data);
-}
-
+my %typefamily = (
+ STRUCT => {
+ PUSH_FN_BODY => \&ParseStructPush,
+ PULL_FN_BODY => \&ParseStructPull,
+ PRINT_FN_BODY => \&ParseStructPrint
+ },
+ UNION => {
+ PUSH_FN_BODY => \&ParseUnionPush,
+ PULL_FN_BODY => \&ParseUnionPull,
+ PRINT_FN_BODY => \&ParseUnionPrint
+ },
+ ENUM => {
+ PUSH_FN_BODY => \&ParseEnumPush,
+ PULL_FN_BODY => \&ParseEnumPull,
+ PRINT_FN_BODY => \&ParseEnumPrint
+ },
+ BITMAP => {
+ PUSH_FN_BODY => \&ParseBitmapPush,
+ PULL_FN_BODY => \&ParseBitmapPull,
+ PRINT_FN_BODY => \&ParseBitmapPrint
+ }
+);
+
#####################################################################
# parse a typedef - push side
sub ParseTypedefPush($)
@@ -1387,38 +1344,26 @@ sub ParseTypedefPush($)
if ($e->{DATA}->{TYPE} eq "STRUCT") {
pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, struct $e->{NAME} *r)";
- pidl "\n{\n";
- ParseTypePush($e->{DATA});
- pidl "\treturn NT_STATUS_OK;\n";
- pidl "}\n\n";
}
if ($e->{DATA}->{TYPE} eq "UNION") {
pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, int level, union $e->{NAME} *r)";
- pidl "\n{\n";
- ParseTypePush($e->{DATA});
- pidl "\treturn NT_STATUS_OK;\n";
- pidl "}\n\n";
}
if ($e->{DATA}->{TYPE} eq "ENUM") {
pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, enum $e->{NAME} r)";
- pidl "\n{\n";
- ParseTypePush($e->{DATA});
- pidl "\treturn NT_STATUS_OK;\n";
- pidl "}\n\n";
}
if ($e->{DATA}->{TYPE} eq "BITMAP") {
my $type_decl = util::bitmap_type_decl($e->{DATA});
pidl $static . "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $type_decl r)";
- pidl "\n{\n";
- ParseTypePush($e->{DATA});
- pidl "\treturn NT_STATUS_OK;\n";
- pidl "}\n\n";
}
-}
+ pidl "\n{\n";
+ $typefamily{$e->{DATA}->{TYPE}}->{PUSH_FN_BODY}($e->{DATA});
+ pidl "\treturn NT_STATUS_OK;\n";
+ pidl "}\n\n";
+}
#####################################################################
# parse a typedef - pull side
@@ -1438,38 +1383,26 @@ sub ParseTypedefPull($)
if ($e->{DATA}->{TYPE} eq "STRUCT") {
pidl $static . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, struct $e->{NAME} *r)";
- pidl "\n{\n";
- ParseTypePull($e->{DATA});
- pidl "\treturn NT_STATUS_OK;\n";
- pidl "}\n\n";
}
if ($e->{DATA}->{TYPE} eq "UNION") {
pidl $static . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, int level, union $e->{NAME} *r)";
- pidl "\n{\n";
- ParseTypePull($e->{DATA});
- pidl "\treturn NT_STATUS_OK;\n";
- pidl "}\n\n";
- }
+ }
if ($e->{DATA}->{TYPE} eq "ENUM") {
pidl $static . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, enum $e->{NAME} *r)";
- pidl "\n{\n";
- ParseTypePull($e->{DATA});
- pidl "\treturn NT_STATUS_OK;\n";
- pidl "}\n\n";
}
if ($e->{DATA}->{TYPE} eq "BITMAP") {
my $type_decl = util::bitmap_type_decl($e->{DATA});
pidl $static . "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $type_decl *r)";
- pidl "\n{\n";
- ParseTypePull($e->{DATA});
- pidl "\treturn NT_STATUS_OK;\n";
- pidl "}\n\n";
}
-}
+ pidl "\n{\n";
+ $typefamily{$e->{DATA}->{TYPE}}->{PULL_FN_BODY}($e->{DATA});
+ pidl "\treturn NT_STATUS_OK;\n";
+ pidl "}\n\n";
+}
#####################################################################
# parse a typedef - print side
@@ -1485,32 +1418,27 @@ sub ParseTypedefPrint($)
pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, struct $e->{NAME} *r)";
pidl "\n{\n";
pidl "\tndr_print_struct(ndr, name, \"$e->{NAME}\");\n";
- ParseTypePrint($e->{DATA});
- pidl "}\n\n";
}
if ($e->{DATA}->{TYPE} eq "UNION") {
pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, int level, union $e->{NAME} *r)";
pidl "\n{\n";
pidl "\tndr_print_union(ndr, name, level, \"$e->{NAME}\");\n";
- ParseTypePrint($e->{DATA});
- pidl "}\n\n";
}
if ($e->{DATA}->{TYPE} eq "ENUM") {
pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, enum $e->{NAME} r)";
pidl "\n{\n";
- ParseTypePrint($e->{DATA});
- pidl "}\n\n";
}
if ($e->{DATA}->{TYPE} eq "BITMAP") {
my $type_decl = util::bitmap_type_decl($e->{DATA});
pidl "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $type_decl r)";
pidl "\n{\n";
- ParseTypePrint($e->{DATA});
- pidl "}\n\n";
}
+
+ $typefamily{$e->{DATA}->{TYPE}}->{PRINT_FN_BODY}($e->{DATA});
+ pidl "}\n\n";
}
#####################################################################
@@ -1576,7 +1504,6 @@ sub ParseFunctionPrint($)
pidl "}\n\n";
}
-
#####################################################################
# parse a function element
sub ParseFunctionElementPush($$)
@@ -1672,7 +1599,6 @@ sub ParseFunctionElementPull($$)
}
}
-
############################################################
# allocate ref variables
sub AllocateRefVars($)
@@ -1706,7 +1632,6 @@ sub AllocateRefVars($)
}
}
-
#####################################################################
# parse a function
sub ParseFunctionPull($)
@@ -2024,4 +1949,6 @@ sub Parse($$)
return $res;
}
+RegisterPrimitives();
+
1;