From cecbf0cd8b99f7019a83def88baec889d6a06e6f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Nov 2003 04:04:36 +0000 Subject: 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) --- source4/build/pidl/parser.pm | 128 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) (limited to 'source4/build') 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 @@ -70,6 +70,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($$) @@ -109,6 +124,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 @@ -271,6 +337,25 @@ sub ParseStructPush($) $res .= "done:\n"; } +##################################################################### +# 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($) @@ -340,6 +425,14 @@ sub ParseUnionPush($) print "WARNING! union push not done\n"; } +##################################################################### +# print a union +sub ParseUnionPrint($) +{ + my $e = shift; + print "WARNING! union print not done\n"; +} + ##################################################################### # parse a union - pull side sub ParseUnionPull($) @@ -384,6 +477,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); } ##################################################################### -- cgit