summaryrefslogtreecommitdiff
path: root/source4/build
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-11-11 04:04:36 +0000
committerAndrew Tridgell <tridge@samba.org>2003-11-11 04:04:36 +0000
commitcecbf0cd8b99f7019a83def88baec889d6a06e6f (patch)
tree108181e24bac1a4fa10a55de40547d9177b488e8 /source4/build
parenta934f89549b3d23199d68b7dc3fc3ad16e86b9ad (diff)
downloadsamba-cecbf0cd8b99f7019a83def88baec889d6a06e6f.tar.gz
samba-cecbf0cd8b99f7019a83def88baec889d6a06e6f.tar.bz2
samba-cecbf0cd8b99f7019a83def88baec889d6a06e6f.zip
automatically generate ndr_print_*() functions for every IDL
structure. This allows easy debug and test tool writing without having to write functions that print every element of complex structures. (This used to be commit 81d6181172e36c6fbae0907550a29511ce708574)
Diffstat (limited to 'source4/build')
-rw-r--r--source4/build/pidl/parser.pm128
1 files changed, 128 insertions, 0 deletions
diff --git a/source4/build/pidl/parser.pm b/source4/build/pidl/parser.pm
index 1b09347052..19e6dc26f4 100644
--- a/source4/build/pidl/parser.pm
+++ b/source4/build/pidl/parser.pm
@@ -71,6 +71,21 @@ sub ParseArrayPush($$)
}
#####################################################################
+# print an array
+sub ParseArrayPrint($$)
+{
+ my $e = shift;
+ my $var_prefix = shift;
+ my $size = find_size_var($e, util::array_size($e));
+
+ if (util::is_scalar_type($e->{TYPE})) {
+ $res .= "\t\tndr_print_array_$e->{TYPE}(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME}, $size);\n";
+ } else {
+ $res .= "\t\tndr_print_array(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME}, sizeof($var_prefix$e->{NAME}\[0]), $size, (ndr_print_fn_t)ndr_print_$e->{TYPE});\n";
+ }
+}
+
+#####################################################################
# parse an array - pull side
sub ParseArrayPull($$)
{
@@ -110,6 +125,30 @@ sub ParseElementPushScalar($$$)
}
#####################################################################
+# print scalars in a structure element
+sub ParseElementPrintScalar($$)
+{
+ my($e) = shift;
+ my($var_prefix) = shift;
+ my $cprefix = util::c_push_prefix($e);
+
+ if (util::has_property($e, "struct_len")) {
+ return;
+ }
+
+ if (defined $e->{VALUE}) {
+ $res .= "\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $e->{VALUE});\n";
+ } elsif (util::need_wire_pointer($e)) {
+ $res .= "\tndr_print_ptr(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME});\n";
+ $res .= "\tndr->depth++;\n";
+ ParseElementPrintBuffer($e, "r->");
+ $res .= "\tndr->depth--;\n";
+ } else {
+ $res .= "\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $cprefix$var_prefix$e->{NAME});\n";
+ }
+}
+
+#####################################################################
# parse scalars in a structure element - pull size
sub ParseElementPullSwitch($$$$)
{
@@ -186,6 +225,33 @@ sub ParseElementPushBuffer($$)
}
}
+#####################################################################
+# print buffers in a structure element
+sub ParseElementPrintBuffer($$)
+{
+ my($e) = shift;
+ my($var_prefix) = shift;
+ my $cprefix = util::c_push_prefix($e);
+
+ if (util::is_pure_scalar($e)) {
+ return;
+ }
+
+ if (util::need_wire_pointer($e)) {
+ $res .= "\tif ($var_prefix$e->{NAME}) {\n";
+ }
+
+ if (util::array_size($e)) {
+ ParseArrayPrint($e, "r->");
+ } else {
+ $res .= "\t\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $cprefix$var_prefix$e->{NAME});\n";
+ }
+
+ if (util::need_wire_pointer($e)) {
+ $res .= "\t}\n";
+ }
+}
+
#####################################################################
# parse buffers in a structure element - pull side
@@ -272,6 +338,25 @@ sub ParseStructPush($)
}
#####################################################################
+# generate a struct print function
+sub ParseStructPrint($)
+{
+ my($struct) = shift;
+
+ $res .= "\tndr_print_struct(ndr, name);\n";
+
+ if (! defined $struct->{ELEMENTS}) {
+ return;
+ }
+
+ $res .= "\tndr->depth++;\n";
+ foreach my $e (@{$struct->{ELEMENTS}}) {
+ ParseElementPrintScalar($e, "r->");
+ }
+ $res .= "\tndr->depth--;\n";
+}
+
+#####################################################################
# parse a struct - pull side
sub ParseStructPull($)
{
@@ -341,6 +426,14 @@ sub ParseUnionPush($)
}
#####################################################################
+# print a union
+sub ParseUnionPrint($)
+{
+ my $e = shift;
+ print "WARNING! union print not done\n";
+}
+
+#####################################################################
# parse a union - pull side
sub ParseUnionPull($)
{
@@ -385,6 +478,20 @@ sub ParseTypePush($)
}
#####################################################################
+# generate a print function for a type
+sub ParseTypePrint($)
+{
+ my($data) = shift;
+
+ if (ref($data) eq "HASH") {
+ ($data->{TYPE} eq "STRUCT") &&
+ ParseStructPrint($data);
+ ($data->{TYPE} eq "UNION") &&
+ ParseUnionPrint($data);
+ }
+}
+
+#####################################################################
# parse a type
sub ParseTypePull($)
{
@@ -456,6 +563,26 @@ sub ParseTypedefPull($)
}
+#####################################################################
+# parse a typedef - push side
+sub ParseTypedefPrint($)
+{
+ my($e) = shift;
+
+ if ($e->{DATA}->{TYPE} eq "STRUCT") {
+ $res .= "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, struct $e->{NAME} *r)";
+ $res .= "\n{\n";
+ ParseTypePrint($e->{DATA});
+ $res .= "}\n\n";
+ }
+
+ if ($e->{DATA}->{TYPE} eq "UNION") {
+ $res .= "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, uint16 level, union $e->{NAME} *r)";
+ $res .= "\n{\n";
+ ParseTypePrint($e->{DATA});
+ $res .= "}\n\n";
+ }
+}
#####################################################################
@@ -537,6 +664,7 @@ sub ParseTypedef($)
my($e) = shift;
ParseTypedefPush($e);
ParseTypedefPull($e);
+ ParseTypedefPrint($e);
}
#####################################################################