From 59b13f9a1d684a632c2c73352f0ec08a63bc0913 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 21 Aug 2005 23:30:17 +0000 Subject: r9460: - Move pidl to lib/. This fixes standalone installation of pidl. - Update the README - Allow building the docs stand-alone (This used to be commit b56084ce251ab7a35dd1422f38de258e8e1e1477) --- source4/pidl/lib/Parse/Pidl/Util.pm | 149 ++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 source4/pidl/lib/Parse/Pidl/Util.pm (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm new file mode 100644 index 0000000000..8854be9d74 --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -0,0 +1,149 @@ +################################################### +# utility functions to support pidl +# Copyright tridge@samba.org 2000 +# released under the GNU GPL +package Parse::Pidl::Util; + +require Exporter; +@ISA = qw(Exporter); +@EXPORT = qw(has_property property_matches ParseExpr is_constant); + +use strict; + +##################################################################### +# flatten an array of arrays into a single array +sub FlattenArray2($) +{ + my $a = shift; + my @b; + for my $d (@{$a}) { + for my $d1 (@{$d}) { + push(@b, $d1); + } + } + return \@b; +} + +##################################################################### +# flatten an array of arrays into a single array +sub FlattenArray($) +{ + my $a = shift; + my @b; + for my $d (@{$a}) { + for my $d1 (@{$d}) { + push(@b, $d1); + } + } + return \@b; +} + +##################################################################### +# flatten an array of hashes into a single hash +sub FlattenHash($) +{ + my $a = shift; + my %b; + for my $d (@{$a}) { + for my $k (keys %{$d}) { + $b{$k} = $d->{$k}; + } + } + return \%b; +} + +##################################################################### +# a dumper wrapper to prevent dependence on the Data::Dumper module +# unless we actually need it +sub MyDumper($) +{ + require Data::Dumper; + my $s = shift; + return Data::Dumper::Dumper($s); +} + +##################################################################### +# see if a pidl property list contains a given property +sub has_property($$) +{ + my($e) = shift; + my($p) = shift; + + if (!defined $e->{PROPERTIES}) { + return undef; + } + + return $e->{PROPERTIES}->{$p}; +} + +##################################################################### +# see if a pidl property matches a value +sub property_matches($$$) +{ + my($e) = shift; + my($p) = shift; + my($v) = shift; + + if (!defined has_property($e, $p)) { + return undef; + } + + if ($e->{PROPERTIES}->{$p} =~ /$v/) { + return 1; + } + + return undef; +} + +# return 1 if the string is a C constant +sub is_constant($) +{ + my $s = shift; + if (defined $s && $s =~ /^\d/) { + return 1; + } + return 0; +} + +# return a "" quoted string, unless already quoted +sub make_str($) +{ + my $str = shift; + if (substr($str, 0, 1) eq "\"") { + return $str; + } + return "\"" . $str . "\""; +} + +# a hack to build on platforms that don't like negative enum values +my $useUintEnums = 0; +sub setUseUintEnums($) +{ + $useUintEnums = shift; +} +sub useUintEnums() +{ + return $useUintEnums; +} + +sub ParseExpr($$) +{ + my($expr,$varlist) = @_; + + die("Undefined value in ParseExpr") if not defined($expr); + + my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+))/, $expr; + my $ret = ""; + + foreach my $t (@tokens) { + if (defined($varlist->{$t})) { + $ret .= $varlist->{$t}; + } else { + $ret .= $t; + } + } + + return $ret; +} + +1; -- cgit From 5d6706e0775b6c9a9920966f6ef9fcd4a8d34345 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 9 Sep 2005 18:21:59 +0000 Subject: r10123: Add more warnings. Support quotes in conformance command arguments (This used to be commit e6842fcc9809bcf8de678199a6f28fbbde6c0b83) --- source4/pidl/lib/Parse/Pidl/Util.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 8854be9d74..572df0dc09 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -6,7 +6,7 @@ package Parse::Pidl::Util; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(has_property property_matches ParseExpr is_constant); +@EXPORT = qw(has_property property_matches ParseExpr is_constant make_str); use strict; -- cgit From 58a399d76699792f48fa6d121895a688d5987c80 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Sep 2005 12:57:18 +0000 Subject: r10388: Add version numbers (required for CPAN) (This used to be commit 786329576bf14ae774f9d5a24268e46b7dcb634a) --- source4/pidl/lib/Parse/Pidl/Util.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 572df0dc09..fec1301a59 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -7,6 +7,8 @@ package Parse::Pidl::Util; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(has_property property_matches ParseExpr is_constant make_str); +use vars qw($VERSION); +$VERSION = '0.01'; use strict; -- cgit From a4fe56c06a95bf5278a4a0efdd976febc2b9866b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 Dec 2005 14:59:21 +0000 Subject: r12481: Move parser-specific utility functions to idl.yp, remove some unused functions Allow the use of non-typedef structs and unions when declaring variables. Allow the use of the 'signed' and 'unsigned' qualifiers for integer types (This used to be commit bc6b45e242c8d7b2ef1a6e6d3eb172c27afd952d) --- source4/pidl/lib/Parse/Pidl/Util.pm | 42 ------------------------------------- 1 file changed, 42 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index fec1301a59..ec6a1420ab 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -12,48 +12,6 @@ $VERSION = '0.01'; use strict; -##################################################################### -# flatten an array of arrays into a single array -sub FlattenArray2($) -{ - my $a = shift; - my @b; - for my $d (@{$a}) { - for my $d1 (@{$d}) { - push(@b, $d1); - } - } - return \@b; -} - -##################################################################### -# flatten an array of arrays into a single array -sub FlattenArray($) -{ - my $a = shift; - my @b; - for my $d (@{$a}) { - for my $d1 (@{$d}) { - push(@b, $d1); - } - } - return \@b; -} - -##################################################################### -# flatten an array of hashes into a single hash -sub FlattenHash($) -{ - my $a = shift; - my %b; - for my $d (@{$a}) { - for my $k (keys %{$d}) { - $b{$k} = $d->{$k}; - } - } - return \%b; -} - ##################################################################### # a dumper wrapper to prevent dependence on the Data::Dumper module # unless we actually need it -- cgit From d658de65d32e6746ac51aeb4da7aa74b3da40c2b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 Dec 2005 16:22:35 +0000 Subject: r12512: Use GUID structs in API functions everywhere rather then converting back and forth between GUID structs and strings in several places. (This used to be commit 3564e2f967ef72d6301b4f7e9a311cebcded4d75) --- source4/pidl/lib/Parse/Pidl/Util.pm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index ec6a1420ab..ff615a21ba 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -6,7 +6,7 @@ package Parse::Pidl::Util; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(has_property property_matches ParseExpr is_constant make_str); +@EXPORT = qw(has_property property_matches ParseExpr is_constant make_str print_uuid); use vars qw($VERSION); $VERSION = '0.01'; @@ -75,6 +75,20 @@ sub make_str($) return "\"" . $str . "\""; } +sub print_uuid($) +{ + my ($uuid) = @_; + $uuid =~ s/"//g; + my ($time_low,$time_mid,$time_hi,$clock_seq,$node) = split /-/, $uuid; + + my @clock_seq = $clock_seq =~ /(..)/g; + my @node = $node =~ /(..)/g; + + return "{0x$time_low,0x$time_mid,0x$time_hi," . + "{".join(',', map {"0x$_"} @clock_seq)."}," . + "{".join(',', map {"0x$_"} @node)."}}"; +} + # a hack to build on platforms that don't like negative enum values my $useUintEnums = 0; sub setUseUintEnums($) -- cgit From 362d4b14aecb32aac5c7c4f6beb3b9a979bf9d5a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 5 Jan 2007 12:56:15 +0000 Subject: r20543: Merge some pidl bug fixes: * C expressions that just started with a constant were erroneously flagged as being a constant. * 1-length variable names in expressions were broken. (This used to be commit 44775a6ac456247fe7ab4da75498bb550c74c854) --- source4/pidl/lib/Parse/Pidl/Util.pm | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index ff615a21ba..f1a97693a7 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -26,12 +26,9 @@ sub MyDumper($) # see if a pidl property list contains a given property sub has_property($$) { - my($e) = shift; - my($p) = shift; + my($e, $p) = @_; - if (!defined $e->{PROPERTIES}) { - return undef; - } + return undef if (not defined($e->{PROPERTIES})); return $e->{PROPERTIES}->{$p}; } @@ -40,9 +37,7 @@ sub has_property($$) # see if a pidl property matches a value sub property_matches($$$) { - my($e) = shift; - my($p) = shift; - my($v) = shift; + my($e,$p,$v) = @_; if (!defined has_property($e, $p)) { return undef; @@ -59,7 +54,7 @@ sub property_matches($$$) sub is_constant($) { my $s = shift; - if (defined $s && $s =~ /^\d/) { + if (defined $s && $s =~ /^\d$/) { return 1; } return 0; @@ -72,7 +67,7 @@ sub make_str($) if (substr($str, 0, 1) eq "\"") { return $str; } - return "\"" . $str . "\""; + return "\"$str\""; } sub print_uuid($) @@ -80,6 +75,7 @@ sub print_uuid($) my ($uuid) = @_; $uuid =~ s/"//g; my ($time_low,$time_mid,$time_hi,$clock_seq,$node) = split /-/, $uuid; + return undef if not defined($node); my @clock_seq = $clock_seq =~ /(..)/g; my @node = $node =~ /(..)/g; @@ -106,7 +102,7 @@ sub ParseExpr($$) die("Undefined value in ParseExpr") if not defined($expr); - my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+))/, $expr; + my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+)?)/, $expr; my $ret = ""; foreach my $t (@tokens) { -- cgit From 306dc32687e68dbf388187ec927444fb4a139158 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 5 Jan 2007 14:25:21 +0000 Subject: r20545: Fix is_constant(). (This used to be commit ae9b0895e8b7fd98335ece82aae3e391b94d2ec9) --- source4/pidl/lib/Parse/Pidl/Util.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index f1a97693a7..064862b7c5 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -54,9 +54,8 @@ sub property_matches($$$) sub is_constant($) { my $s = shift; - if (defined $s && $s =~ /^\d$/) { - return 1; - } + return 1 if (defined $s && $s =~ /^\d+$/); + return 1 if (defined $s && $s =~ /^0x[0-9A-Fa-f]+$/); return 0; } -- cgit From 74239c2e944fdbe1ff137e91d80576b87c59d478 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 5 Jan 2007 20:18:33 +0000 Subject: r20563: Start using the new parser in ParseExpr(). It's now trivial to use this to check for NULL pointers when pointers are being dereferenced (#4218). There are exactly 500 tests for pidl now :-) (This used to be commit d3146f3bcd4541f890d6c1b072ff34853e9239d2) --- source4/pidl/lib/Parse/Pidl/Util.pm | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 064862b7c5..2f3547bbb5 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -12,6 +12,8 @@ $VERSION = '0.01'; use strict; +use Parse::Pidl::Expr; + ##################################################################### # a dumper wrapper to prevent dependence on the Data::Dumper module # unless we actually need it @@ -97,22 +99,19 @@ sub useUintEnums() sub ParseExpr($$) { - my($expr,$varlist) = @_; + my($expr, $varlist) = @_; die("Undefined value in ParseExpr") if not defined($expr); - my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+)?)/, $expr; - my $ret = ""; - - foreach my $t (@tokens) { - if (defined($varlist->{$t})) { - $ret .= $varlist->{$t}; - } else { - $ret .= $t; - } - } - - return $ret; + my $x = new Parse::Pidl::Expr(); + + return $x->Run($expr, sub { my $x = shift; die(MyDumper($x)); }, + # Lookup fn + sub { my $x = shift; + return($varlist->{$x}) if (defined($varlist->{$x})); + return $x; + }, + undef); } 1; -- cgit From a7bc3801f94891880a90b2974dfbadc9e9f8c2ee Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 5 Jan 2007 20:52:12 +0000 Subject: r20567: Print proper errors with filename and line numbers in ParseExpr() (This used to be commit f5dc1b47ecf18068a47f8f68016463ef4a55dc03) --- source4/pidl/lib/Parse/Pidl/Util.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 2f3547bbb5..11e738fd13 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -13,6 +13,7 @@ $VERSION = '0.01'; use strict; use Parse::Pidl::Expr; +use Parse::Pidl qw(error); ##################################################################### # a dumper wrapper to prevent dependence on the Data::Dumper module @@ -97,15 +98,15 @@ sub useUintEnums() return $useUintEnums; } -sub ParseExpr($$) +sub ParseExpr($$$) { - my($expr, $varlist) = @_; + my($expr, $varlist, $e) = @_; die("Undefined value in ParseExpr") if not defined($expr); my $x = new Parse::Pidl::Expr(); - return $x->Run($expr, sub { my $x = shift; die(MyDumper($x)); }, + return $x->Run($expr, sub { my $x = shift; error($e, $x); }, # Lookup fn sub { my $x = shift; return($varlist->{$x}) if (defined($varlist->{$x})); -- cgit From bf39b5e5929449b7ef8685b6c7737efd3a31843b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 9 Jan 2007 15:50:36 +0000 Subject: r20631: Add some tests for the ndr parser. (This used to be commit ded25eca701b8e3e0e13e7ef64d5511d8953eb0d) --- source4/pidl/lib/Parse/Pidl/Util.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 11e738fd13..35338492dd 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -6,7 +6,7 @@ package Parse::Pidl::Util; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(has_property property_matches ParseExpr is_constant make_str print_uuid); +@EXPORT = qw(has_property property_matches ParseExpr is_constant make_str print_uuid MyDumper); use vars qw($VERSION); $VERSION = '0.01'; -- cgit From 95f7f4d001684d447ce8e0f880200cfac89f011a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 9 Jan 2007 23:41:25 +0000 Subject: r20637: Don't check for NULL pointers when the pointer is guaranteed to not be NULL (if it is a ref pointer). (This used to be commit 419547df76c38fde1f54b06dc633832523ad3394) --- source4/pidl/lib/Parse/Pidl/Util.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 35338492dd..35e25286f5 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -6,7 +6,7 @@ package Parse::Pidl::Util; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(has_property property_matches ParseExpr is_constant make_str print_uuid MyDumper); +@EXPORT = qw(has_property property_matches ParseExpr ParseExprExt is_constant make_str print_uuid MyDumper); use vars qw($VERSION); $VERSION = '0.01'; @@ -115,4 +115,21 @@ sub ParseExpr($$$) undef); } +sub ParseExprExt($$$$) +{ + my($expr, $varlist, $e, $deref) = @_; + + die("Undefined value in ParseExpr") if not defined($expr); + + my $x = new Parse::Pidl::Expr(); + + return $x->Run($expr, sub { my $x = shift; error($e, $x); }, + # Lookup fn + sub { my $x = shift; + return($varlist->{$x}) if (defined($varlist->{$x})); + return $x; + }, + $deref); +} + 1; -- cgit From 30bfba96d3b7007aa47e037328ea0f2b8e7d1d6e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 22 Jan 2007 00:04:59 +0000 Subject: r20942: Simplify handling of systems that don't support negative enum values by using an ifdef rather than a pidl argument. (This used to be commit 6bada0dcf0c7915d366c7917189375dbabecdd4f) --- source4/pidl/lib/Parse/Pidl/Util.pm | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 35e25286f5..3ca79b6c1c 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -87,17 +87,6 @@ sub print_uuid($) "{".join(',', map {"0x$_"} @node)."}}"; } -# a hack to build on platforms that don't like negative enum values -my $useUintEnums = 0; -sub setUseUintEnums($) -{ - $useUintEnums = shift; -} -sub useUintEnums() -{ - return $useUintEnums; -} - sub ParseExpr($$$) { my($expr, $varlist, $e) = @_; -- cgit From ecf2c1effb778a95fd863a5e87ec7e378d228b57 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 7 Feb 2007 19:03:19 +0000 Subject: r21222: Merge a couple of pidl fixes: * Pidl will now warn when trying to use pointers as integers in expressions. * "subcontext()" is now marked as deprecated. The alternatives, transmit_as() / represent_as() should be available soon. * More tests. * Remove some unused code in smbtorture. (This used to be commit 37c0da541e3962164d5af3e3c9560803a733f3b7) --- source4/pidl/lib/Parse/Pidl/Util.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 3ca79b6c1c..00185fbef7 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -101,12 +101,12 @@ sub ParseExpr($$$) return($varlist->{$x}) if (defined($varlist->{$x})); return $x; }, - undef); + undef, undef); } -sub ParseExprExt($$$$) +sub ParseExprExt($$$$$) { - my($expr, $varlist, $e, $deref) = @_; + my($expr, $varlist, $e, $deref, $use) = @_; die("Undefined value in ParseExpr") if not defined($expr); @@ -118,7 +118,7 @@ sub ParseExprExt($$$$) return($varlist->{$x}) if (defined($varlist->{$x})); return $x; }, - $deref); + $deref, $use); } 1; -- cgit From 45db1030651e69896fdb9e78aa2e2495a7ce7ff5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 8 Feb 2007 23:54:31 +0000 Subject: r21253: Merge some pidl fixes: * Add tests for wireshark dissector generator * Add tests for the header code * Some cleanups * Fix handling of elements without [in] or [out] (This used to be commit 1aecba7100685ed291ea13b0ae47fb0cf9e6a6c8) --- source4/pidl/lib/Parse/Pidl/Util.pm | 75 +++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 15 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 00185fbef7..8716094abd 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -15,9 +15,31 @@ use strict; use Parse::Pidl::Expr; use Parse::Pidl qw(error); -##################################################################### -# a dumper wrapper to prevent dependence on the Data::Dumper module -# unless we actually need it +=head1 NAME + +Parse::Pidl::Util - Generic utility functions for pidl + +=head1 SYNOPSIS + +use Parse::Pidl::Util; + +=head1 DESCRIPTION + +Simple module that contains a couple of trivial helper functions +used throughout the various pidl modules. + +=head1 FUNCTIONS + +=over 4 + +=cut + +=item B +a dumper wrapper to prevent dependence on the Data::Dumper module +unless we actually need it + +=cut + sub MyDumper($) { require Data::Dumper; @@ -25,8 +47,10 @@ sub MyDumper($) return Data::Dumper::Dumper($s); } -##################################################################### -# see if a pidl property list contains a given property +=item B +see if a pidl property list contains a given property + +=cut sub has_property($$) { my($e, $p) = @_; @@ -36,8 +60,10 @@ sub has_property($$) return $e->{PROPERTIES}->{$p}; } -##################################################################### -# see if a pidl property matches a value +=item B +see if a pidl property matches a value + +=cut sub property_matches($$$) { my($e,$p,$v) = @_; @@ -53,16 +79,22 @@ sub property_matches($$$) return undef; } -# return 1 if the string is a C constant +=item B +return 1 if the string is a C constant + +=cut sub is_constant($) { my $s = shift; - return 1 if (defined $s && $s =~ /^\d+$/); - return 1 if (defined $s && $s =~ /^0x[0-9A-Fa-f]+$/); + return 1 if ($s =~ /^\d+$/); + return 1 if ($s =~ /^0x[0-9A-Fa-f]+$/); return 0; } -# return a "" quoted string, unless already quoted +=item B +return a "" quoted string, unless already quoted + +=cut sub make_str($) { my $str = shift; @@ -72,6 +104,10 @@ sub make_str($) return "\"$str\""; } +=item B +Print C representation of a UUID. + +=cut sub print_uuid($) { my ($uuid) = @_; @@ -87,12 +123,14 @@ sub print_uuid($) "{".join(',', map {"0x$_"} @node)."}}"; } +=item B +Interpret an IDL expression, substituting particular variables. + +=cut sub ParseExpr($$$) { my($expr, $varlist, $e) = @_; - die("Undefined value in ParseExpr") if not defined($expr); - my $x = new Parse::Pidl::Expr(); return $x->Run($expr, sub { my $x = shift; error($e, $x); }, @@ -104,12 +142,15 @@ sub ParseExpr($$$) undef, undef); } +=item B +Interpret an IDL expression, substituting particular variables. Can call +callbacks when pointers are being dereferenced or variables are being used. + +=cut sub ParseExprExt($$$$$) { my($expr, $varlist, $e, $deref, $use) = @_; - die("Undefined value in ParseExpr") if not defined($expr); - my $x = new Parse::Pidl::Expr(); return $x->Run($expr, sub { my $x = shift; error($e, $x); }, @@ -121,4 +162,8 @@ sub ParseExprExt($$$$$) $deref, $use); } +=back + +=cut + 1; -- cgit From 8d182d881d189e9855165b3a423f2d545a97fae8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 31 Aug 2007 00:31:32 +0000 Subject: r24816: Move the rest of the contents of core.h to more appropriate places. include/ now only contains build system related headers, all other headers are now near the source code they're related to. (This used to be commit 6890a01dbfc6d8041a88ef5c6be52dfcd046fe80) --- source4/pidl/lib/Parse/Pidl/Util.pm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm') diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm index 8716094abd..006718d139 100644 --- a/source4/pidl/lib/Parse/Pidl/Util.pm +++ b/source4/pidl/lib/Parse/Pidl/Util.pm @@ -6,7 +6,7 @@ package Parse::Pidl::Util; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(has_property property_matches ParseExpr ParseExprExt is_constant make_str print_uuid MyDumper); +@EXPORT = qw(has_property property_matches ParseExpr ParseExprExt is_constant make_str unmake_str print_uuid MyDumper); use vars qw($VERSION); $VERSION = '0.01'; @@ -104,6 +104,19 @@ sub make_str($) return "\"$str\""; } +=item B +unquote a "" quoted string + +=cut +sub unmake_str($) +{ + my $str = shift; + + $str =~ s/^\"(.*)\"$/$1/; + + return $str; +} + =item B Print C representation of a UUID. -- cgit