summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-01-05 20:52:12 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:37:01 -0500
commita7bc3801f94891880a90b2974dfbadc9e9f8c2ee (patch)
tree2cc690d4b35022398e8062847f70982fd34585e0 /source4
parent38ba8bf8ba75c19ab8d34eb4862b05befc8e1497 (diff)
downloadsamba-a7bc3801f94891880a90b2974dfbadc9e9f8c2ee.tar.gz
samba-a7bc3801f94891880a90b2974dfbadc9e9f8c2ee.tar.bz2
samba-a7bc3801f94891880a90b2974dfbadc9e9f8c2ee.zip
r20567: Print proper errors with filename and line numbers in ParseExpr()
(This used to be commit f5dc1b47ecf18068a47f8f68016463ef4a55dc03)
Diffstat (limited to 'source4')
-rw-r--r--source4/pidl/expr.yp18
-rw-r--r--source4/pidl/lib/Parse/Pidl/Expr.pm86
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm2
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm2
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm14
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm46
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/TDR.pm8
-rw-r--r--source4/pidl/lib/Parse/Pidl/Util.pm7
-rw-r--r--source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm2
-rwxr-xr-xsource4/pidl/tests/util.pl68
10 files changed, 137 insertions, 116 deletions
diff --git a/source4/pidl/expr.yp b/source4/pidl/expr.yp
index 5b248ea5d6..58704ff89e 100644
--- a/source4/pidl/expr.yp
+++ b/source4/pidl/expr.yp
@@ -22,8 +22,8 @@ exp: NUM
| TEXT { "\"$_[1]\"" }
| func
| exp '.' VAR { "$_[1].$_[3]" }
- | VAR { $_[0]->Lookup($_[1]) }
- | '*' exp %prec DEREF { $_[0]->Dereference($_[2]); "*$_[2]" }
+ | VAR { $_[0]->_Lookup($_[1]) }
+ | '*' exp %prec DEREF { $_[0]->_Dereference($_[2]); "*$_[2]" }
| '~' exp %prec INV { "~$_[2]" }
| exp '+' exp { "$_[1] + $_[3]" }
| exp '-' exp { "$_[1] - $_[3]" }
@@ -93,13 +93,13 @@ sub _Lexer {
}
}
-sub Lookup($$)
+sub _Lookup($$)
{
my ($self, $x) = @_;
return $self->YYData->{LOOKUP}->($x);
}
-sub Dereference($$)
+sub _Dereference($$)
{
my ($self, $x) = @_;
if (defined($self->YYData->{DEREFERENCE})) {
@@ -107,10 +107,18 @@ sub Dereference($$)
}
}
+sub _Error($)
+{
+ my ($self) = @_;
+ $self->YYData->{ERROR}->("Parse error in `".$self->YYData->{FULL_INPUT}."' near `". $self->YYData->{LAST_TOKEN} . "'");
+}
+
sub Run {
my($self, $data, $error, $lookup, $deref) = @_;
+ $self->YYData->{FULL_INPUT} = $data;
$self->YYData->{INPUT} = $data;
$self->YYData->{LOOKUP} = $lookup;
$self->YYData->{DEREFERENCE} = $deref;
- return $self->YYParse( yylex => \&_Lexer, yyerror => $error );
+ $self->YYData->{ERROR} = $error;
+ return $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error);
}
diff --git a/source4/pidl/lib/Parse/Pidl/Expr.pm b/source4/pidl/lib/Parse/Pidl/Expr.pm
index 2f1a98f374..fc0a3a92aa 100644
--- a/source4/pidl/lib/Parse/Pidl/Expr.pm
+++ b/source4/pidl/lib/Parse/Pidl/Expr.pm
@@ -1085,7 +1085,7 @@ sub new {
[#Rule 2
'exp', 1,
sub
-#line 22 "pidl/expr.yp"
+#line 22 "expr.yp"
{ "\"$_[1]\"" }
],
[#Rule 3
@@ -1094,187 +1094,187 @@ sub
[#Rule 4
'exp', 3,
sub
-#line 24 "pidl/expr.yp"
+#line 24 "expr.yp"
{ "$_[1].$_[3]" }
],
[#Rule 5
'exp', 1,
sub
-#line 25 "pidl/expr.yp"
-{ $_[0]->Lookup($_[1]) }
+#line 25 "expr.yp"
+{ $_[0]->_Lookup($_[1]) }
],
[#Rule 6
'exp', 2,
sub
-#line 26 "pidl/expr.yp"
-{ $_[0]->Dereference($_[2]); "*$_[2]" }
+#line 26 "expr.yp"
+{ $_[0]->_Dereference($_[2]); "*$_[2]" }
],
[#Rule 7
'exp', 2,
sub
-#line 27 "pidl/expr.yp"
+#line 27 "expr.yp"
{ "~$_[2]" }
],
[#Rule 8
'exp', 3,
sub
-#line 28 "pidl/expr.yp"
+#line 28 "expr.yp"
{ "$_[1] + $_[3]" }
],
[#Rule 9
'exp', 3,
sub
-#line 29 "pidl/expr.yp"
+#line 29 "expr.yp"
{ "$_[1] - $_[3]" }
],
[#Rule 10
'exp', 3,
sub
-#line 30 "pidl/expr.yp"
+#line 30 "expr.yp"
{ "$_[1] * $_[3]" }
],
[#Rule 11
'exp', 3,
sub
-#line 31 "pidl/expr.yp"
+#line 31 "expr.yp"
{ "$_[1] % $_[3]" }
],
[#Rule 12
'exp', 3,
sub
-#line 32 "pidl/expr.yp"
+#line 32 "expr.yp"
{ "$_[1] < $_[3]" }
],
[#Rule 13
'exp', 3,
sub
-#line 33 "pidl/expr.yp"
+#line 33 "expr.yp"
{ "$_[1] > $_[3]" }
],
[#Rule 14
'exp', 3,
sub
-#line 34 "pidl/expr.yp"
+#line 34 "expr.yp"
{ "$_[1] | $_[3]" }
],
[#Rule 15
'exp', 3,
sub
-#line 35 "pidl/expr.yp"
+#line 35 "expr.yp"
{ "$_[1] == $_[3]" }
],
[#Rule 16
'exp', 3,
sub
-#line 36 "pidl/expr.yp"
+#line 36 "expr.yp"
{ "$_[1] <= $_[3]" }
],
[#Rule 17
'exp', 3,
sub
-#line 37 "pidl/expr.yp"
+#line 37 "expr.yp"
{ "$_[1] => $_[3]" }
],
[#Rule 18
'exp', 3,
sub
-#line 38 "pidl/expr.yp"
+#line 38 "expr.yp"
{ "$_[1] << $_[3]" }
],
[#Rule 19
'exp', 3,
sub
-#line 39 "pidl/expr.yp"
+#line 39 "expr.yp"
{ "$_[1] >> $_[3]" }
],
[#Rule 20
'exp', 3,
sub
-#line 40 "pidl/expr.yp"
+#line 40 "expr.yp"
{ "$_[1] != $_[3]" }
],
[#Rule 21
'exp', 3,
sub
-#line 41 "pidl/expr.yp"
+#line 41 "expr.yp"
{ "$_[1] || $_[3]" }
],
[#Rule 22
'exp', 3,
sub
-#line 42 "pidl/expr.yp"
+#line 42 "expr.yp"
{ "$_[1] && $_[3]" }
],
[#Rule 23
'exp', 3,
sub
-#line 43 "pidl/expr.yp"
+#line 43 "expr.yp"
{ "$_[1] & $_[3]" }
],
[#Rule 24
'exp', 3,
sub
-#line 44 "pidl/expr.yp"
+#line 44 "expr.yp"
{ $_[1]."->".$_[3] }
],
[#Rule 25
'exp', 5,
sub
-#line 45 "pidl/expr.yp"
+#line 45 "expr.yp"
{ "$_[1]?$_[3]:$_[5]" }
],
[#Rule 26
'exp', 2,
sub
-#line 46 "pidl/expr.yp"
+#line 46 "expr.yp"
{ "~$_[1]" }
],
[#Rule 27
'exp', 2,
sub
-#line 47 "pidl/expr.yp"
+#line 47 "expr.yp"
{ "not $_[1]" }
],
[#Rule 28
'exp', 3,
sub
-#line 48 "pidl/expr.yp"
+#line 48 "expr.yp"
{ "$_[1] / $_[3]" }
],
[#Rule 29
'exp', 2,
sub
-#line 49 "pidl/expr.yp"
+#line 49 "expr.yp"
{ "-$_[2]" }
],
[#Rule 30
'exp', 2,
sub
-#line 50 "pidl/expr.yp"
+#line 50 "expr.yp"
{ "&$_[2]" }
],
[#Rule 31
'exp', 3,
sub
-#line 51 "pidl/expr.yp"
+#line 51 "expr.yp"
{ "$_[1]^$_[3]" }
],
[#Rule 32
'exp', 3,
sub
-#line 52 "pidl/expr.yp"
+#line 52 "expr.yp"
{ "($_[2])" }
],
[#Rule 33
'func', 4,
sub
-#line 55 "pidl/expr.yp"
+#line 55 "expr.yp"
{ "$_[1]($_[3])" }
],
[#Rule 34
'opt_args', 0,
sub
-#line 56 "pidl/expr.yp"
+#line 56 "expr.yp"
{ "" }
],
[#Rule 35
@@ -1286,7 +1286,7 @@ sub
[#Rule 37
'args', 3,
sub
-#line 57 "pidl/expr.yp"
+#line 57 "expr.yp"
{ "$_[1], $_[3]" }
]
],
@@ -1294,7 +1294,7 @@ sub
bless($self,$class);
}
-#line 59 "pidl/expr.yp"
+#line 59 "expr.yp"
package Parse::Pidl::Expr;
@@ -1332,13 +1332,13 @@ sub _Lexer {
}
}
-sub Lookup($$)
+sub _Lookup($$)
{
my ($self, $x) = @_;
return $self->YYData->{LOOKUP}->($x);
}
-sub Dereference($$)
+sub _Dereference($$)
{
my ($self, $x) = @_;
if (defined($self->YYData->{DEREFERENCE})) {
@@ -1346,12 +1346,20 @@ sub Dereference($$)
}
}
+sub _Error($)
+{
+ my ($self) = @_;
+ $self->YYData->{ERROR}->("Parse error in `".$self->YYData->{FULL_INPUT}."' near `". $self->YYData->{LAST_TOKEN} . "'");
+}
+
sub Run {
my($self, $data, $error, $lookup, $deref) = @_;
+ $self->YYData->{FULL_INPUT} = $data;
$self->YYData->{INPUT} = $data;
$self->YYData->{LOOKUP} = $lookup;
$self->YYData->{DEREFERENCE} = $deref;
- return $self->YYParse( yylex => \&_Lexer, yyerror => $error );
+ $self->YYData->{ERROR} = $error;
+ return $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error);
}
1;
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
index 5c88e3d22f..f6b3a6dcac 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
@@ -9,7 +9,7 @@ package Parse::Pidl::Samba3::ClientNDR;
use strict;
use Parse::Pidl qw(fatal warning);
use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference);
-use Parse::Pidl::Util qw(has_property ParseExpr is_constant);
+use Parse::Pidl::Util qw(has_property is_constant);
use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
use Parse::Pidl::Samba4 qw(DeclLong_cli IsUniqueOut);
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm
index 8d42b483ec..f8ff458275 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm
@@ -36,7 +36,7 @@ sub AllocOutVar($$$$)
}
if ($l->{TYPE} eq "ARRAY") {
- my $size = ParseExpr($l->{SIZE_IS}, $env);
+ my $size = ParseExpr($l->{SIZE_IS}, $env, $e);
pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name) * $size);";
} else {
pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name));";
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm
index f820dbbc5a..c851fafd4b 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm
@@ -198,8 +198,8 @@ sub EjsPullArray($$$$$)
{
my ($e, $l, $var, $name, $env) = @_;
my $nl = Parse::Pidl::NDR::GetNextLevel($e, $l);
- my $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env);
- my $size = Parse::Pidl::Util::ParseExpr($l->{SIZE_IS}, $env);
+ my $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env, $e);
+ my $size = Parse::Pidl::Util::ParseExpr($l->{SIZE_IS}, $env, $e);
my $pl = Parse::Pidl::NDR::GetPrevLevel($e, $l);
if ($pl && $pl->{TYPE} eq "POINTER") {
$var = get_pointer_to($var);
@@ -238,7 +238,7 @@ sub EjsPullArray($$$$$)
sub EjsPullSwitch($$$$$)
{
my ($e, $l, $var, $name, $env) = @_;
- my $switch_var = Parse::Pidl::Util::ParseExpr($l->{SWITCH_IS}, $env);
+ my $switch_var = Parse::Pidl::Util::ParseExpr($l->{SWITCH_IS}, $env, $e);
pidl "ejs_set_switch(ejs, $switch_var);";
EjsPullElement($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $var, $name, $env);
}
@@ -270,7 +270,7 @@ sub EjsPullElementTop($$)
my $e = shift;
my $env = shift;
my $l = $e->{LEVELS}[0];
- my $var = Parse::Pidl::Util::ParseExpr($e->{NAME}, $env);
+ my $var = Parse::Pidl::Util::ParseExpr($e->{NAME}, $env, $e);
my $name = "\"$e->{NAME}\"";
EjsPullElement($e, $l, $var, $name, $env);
}
@@ -488,7 +488,7 @@ sub EjsPushPointer($$$$$)
sub EjsPushSwitch($$$$$)
{
my ($e, $l, $var, $name, $env) = @_;
- my $switch_var = Parse::Pidl::Util::ParseExpr($l->{SWITCH_IS}, $env);
+ my $switch_var = Parse::Pidl::Util::ParseExpr($l->{SWITCH_IS}, $env, $e);
pidl "ejs_set_switch(ejs, $switch_var);";
EjsPushElement($e, Parse::Pidl::NDR::GetNextLevel($e, $l), $var, $name, $env);
}
@@ -500,7 +500,7 @@ sub EjsPushArray($$$$$)
{
my ($e, $l, $var, $name, $env) = @_;
my $nl = Parse::Pidl::NDR::GetNextLevel($e, $l);
- my $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env);
+ my $length = Parse::Pidl::Util::ParseExpr($l->{LENGTH_IS}, $env, $e);
my $pl = Parse::Pidl::NDR::GetPrevLevel($e, $l);
if ($pl && $pl->{TYPE} eq "POINTER") {
$var = get_pointer_to($var);
@@ -553,7 +553,7 @@ sub EjsPushElementTop($$)
my $e = shift;
my $env = shift;
my $l = $e->{LEVELS}[0];
- my $var = Parse::Pidl::Util::ParseExpr($e->{NAME}, $env);
+ my $var = Parse::Pidl::Util::ParseExpr($e->{NAME}, $env, $e);
my $name = "\"$e->{NAME}\"";
EjsPushElement($e, $l, $var, $name, $env);
}
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
index f104ffbad8..debdc8e308 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
@@ -257,7 +257,7 @@ sub EnvSubstituteValue($$)
foreach my $e (@{$s->{ELEMENTS}}) {
next unless (my $v = has_property($e, "value"));
- $env->{$e->{NAME}} = ParseExpr($v, $env);
+ $env->{$e->{NAME}} = ParseExpr($v, $env, $e);
}
return $env;
@@ -309,8 +309,8 @@ sub ParseArrayPushHeader($$$$$)
$size = $length = "ndr_string_length($var_name, sizeof(*$var_name))";
}
} else {
- $size = ParseExpr($l->{SIZE_IS}, $env);
- $length = ParseExpr($l->{LENGTH_IS}, $env);
+ $size = ParseExpr($l->{SIZE_IS}, $env, $e);
+ $length = ParseExpr($l->{LENGTH_IS}, $env, $e);
}
if ((!$l->{IS_SURROUNDING}) and $l->{IS_CONFORMANT}) {
@@ -339,7 +339,7 @@ sub ParseArrayPullHeader($$$$$)
} elsif ($l->{IS_ZERO_TERMINATED}) { # Noheader arrays
$length = $size = "ndr_get_string_size($ndr, sizeof(*$var_name))";
} else {
- $length = $size = ParseExpr($l->{SIZE_IS}, $env);
+ $length = $size = ParseExpr($l->{SIZE_IS}, $env, $e);
}
if ((!$l->{IS_SURROUNDING}) and $l->{IS_CONFORMANT}) {
@@ -363,7 +363,7 @@ sub ParseArrayPullHeader($$$$$)
}
if ($l->{IS_CONFORMANT} and not $l->{IS_ZERO_TERMINATED}) {
- my $size = ParseExpr($l->{SIZE_IS}, $env);
+ my $size = ParseExpr($l->{SIZE_IS}, $env, $e);
defer "if ($var_name) {";
defer_indent;
check_null_pointer_deferred($size);
@@ -373,7 +373,7 @@ sub ParseArrayPullHeader($$$$$)
}
if ($l->{IS_VARYING} and not $l->{IS_ZERO_TERMINATED}) {
- my $length = ParseExpr($l->{LENGTH_IS}, $env);
+ my $length = ParseExpr($l->{LENGTH_IS}, $env, $e);
defer "if ($var_name) {";
defer_indent;
check_null_pointer_deferred($length);
@@ -404,7 +404,7 @@ sub compression_clen($$$)
my $compression = $l->{COMPRESSION};
my ($alg, $clen, $dlen) = split(/ /, $compression);
- return ParseExpr($clen, $env);
+ return ParseExpr($clen, $env, $e);
}
sub compression_dlen($$$)
@@ -413,7 +413,7 @@ sub compression_dlen($$$)
my $compression = $l->{COMPRESSION};
my ($alg, $clen, $dlen) = split(/ /, $compression);
- return ParseExpr($dlen, $env);
+ return ParseExpr($dlen, $env, $e);
}
sub ParseCompressionPushStart($$$$)
@@ -474,7 +474,7 @@ sub ParseSubcontextPushStart($$$$)
{
my ($e,$l,$ndr,$env) = @_;
my $subndr = "_ndr_$e->{NAME}";
- my $subcontext_size = ParseExpr($l->{SUBCONTEXT_SIZE},$env);
+ my $subcontext_size = ParseExpr($l->{SUBCONTEXT_SIZE},$env, $e);
pidl "{";
indent;
@@ -492,7 +492,7 @@ sub ParseSubcontextPushEnd($$$$)
{
my ($e,$l,$ndr,$env) = @_;
my $subndr = "_ndr_$e->{NAME}";
- my $subcontext_size = ParseExpr($l->{SUBCONTEXT_SIZE},$env);
+ my $subcontext_size = ParseExpr($l->{SUBCONTEXT_SIZE},$env, $e);
if (defined $l->{COMPRESSION}) {
ParseCompressionPushEnd($e, $l, $subndr, $env);
@@ -507,7 +507,7 @@ sub ParseSubcontextPullStart($$$$)
{
my ($e,$l,$ndr,$env) = @_;
my $subndr = "_ndr_$e->{NAME}";
- my $subcontext_size = ParseExpr($l->{SUBCONTEXT_SIZE},$env);
+ my $subcontext_size = ParseExpr($l->{SUBCONTEXT_SIZE},$env, $e);
pidl "{";
indent;
@@ -525,7 +525,7 @@ sub ParseSubcontextPullEnd($$$$)
{
my ($e,$l,$ndr,$env) = @_;
my $subndr = "_ndr_$e->{NAME}";
- my $subcontext_size = ParseExpr($l->{SUBCONTEXT_SIZE},$env);
+ my $subcontext_size = ParseExpr($l->{SUBCONTEXT_SIZE},$env, $e);
if (defined $l->{COMPRESSION}) {
ParseCompressionPullEnd($e, $l, $subndr, $env);
@@ -590,7 +590,7 @@ sub ParseElementPushLevel
}
} elsif ($l->{TYPE} eq "ARRAY" and not has_fast_array($e,$l) and
not is_charset_array($e, $l)) {
- my $length = ParseExpr($l->{LENGTH_IS}, $env);
+ my $length = ParseExpr($l->{LENGTH_IS}, $env, $e);
my $counter = "cntr_$e->{NAME}_$l->{LEVEL_INDEX}";
$var_name = $var_name . "[$counter]";
@@ -641,7 +641,7 @@ sub ParseElementPush($$$$$$)
start_flags($e);
if (my $value = has_property($e, "value")) {
- $var_name = ParseExpr($value, $env);
+ $var_name = ParseExpr($value, $env, $e);
}
ParseElementPushLevel($e, $e->{LEVELS}[0], $ndr, $var_name, $env, $primitives, $deferred);
@@ -692,7 +692,7 @@ sub ParseElementPrint($$$)
$var_name = append_prefix($e, $var_name);
if (my $value = has_property($e, "value")) {
- $var_name = "(ndr->flags & LIBNDR_PRINT_SET_VALUES)?" . ParseExpr($value,$env) . ":$var_name";
+ $var_name = "(ndr->flags & LIBNDR_PRINT_SET_VALUES)?" . ParseExpr($value,$env, $e) . ":$var_name";
}
foreach my $l (@{$e->{LEVELS}}) {
@@ -714,7 +714,7 @@ sub ParseElementPrint($$$)
if ($l->{IS_ZERO_TERMINATED}) {
$length = "ndr_string_length($var_name, sizeof(*$var_name))";
} else {
- $length = ParseExpr($l->{LENGTH_IS}, $env);
+ $length = ParseExpr($l->{LENGTH_IS}, $env, $e);
}
if (is_charset_array($e,$l)) {
@@ -744,7 +744,7 @@ sub ParseElementPrint($$$)
}
pidl "ndr_print_$l->{DATA_TYPE}(ndr, \"$e->{NAME}\", $var_name);";
} elsif ($l->{TYPE} eq "SWITCH") {
- my $switch_var = ParseExpr($l->{SWITCH_IS}, $env);
+ my $switch_var = ParseExpr($l->{SWITCH_IS}, $env, $e);
pidl "ndr_print_set_switch_value(ndr, " . get_pointer_to($var_name) . ", $switch_var);";
}
}
@@ -774,7 +774,7 @@ sub ParseElementPrint($$$)
sub ParseSwitchPull($$$$$$)
{
my($e,$l,$ndr,$var_name,$ndr_flags,$env) = @_;
- my $switch_var = ParseExpr($l->{SWITCH_IS}, $env);
+ my $switch_var = ParseExpr($l->{SWITCH_IS}, $env, $e);
check_null_pointer($switch_var);
@@ -787,7 +787,7 @@ sub ParseSwitchPull($$$$$$)
sub ParseSwitchPush($$$$$$)
{
my($e,$l,$ndr,$var_name,$ndr_flags,$env) = @_;
- my $switch_var = ParseExpr($l->{SWITCH_IS}, $env);
+ my $switch_var = ParseExpr($l->{SWITCH_IS}, $env, $e);
check_null_pointer($switch_var);
$var_name = get_pointer_to($var_name);
@@ -986,7 +986,7 @@ sub ParseElementPullLevel
}
} elsif ($l->{TYPE} eq "ARRAY" and
not has_fast_array($e,$l) and not is_charset_array($e, $l)) {
- my $length = ParseExpr($l->{LENGTH_IS}, $env);
+ my $length = ParseExpr($l->{LENGTH_IS}, $env, $e);
my $counter = "cntr_$e->{NAME}_$l->{LEVEL_INDEX}";
my $array_name = $var_name;
@@ -1155,7 +1155,7 @@ sub ParseStructPush($$)
$size = "ndr_string_length(r->$e->{NAME}, sizeof(*r->$e->{NAME}))";
}
} else {
- $size = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env);
+ $size = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env, $e);
}
pidl "NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, $size));";
@@ -2012,7 +2012,7 @@ sub AllocateArrayLevel($$$$$)
{
my ($e,$l,$ndr,$env,$size) = @_;
- my $var = ParseExpr($e->{NAME}, $env);
+ my $var = ParseExpr($e->{NAME}, $env, $e);
check_null_pointer($size);
my $pl = GetPrevLevel($e, $l);
@@ -2093,7 +2093,7 @@ sub ParseFunctionPull($)
and $e->{LEVELS}[1]->{IS_ZERO_TERMINATED});
if ($e->{LEVELS}[1]->{TYPE} eq "ARRAY") {
- my $size = ParseExpr($e->{LEVELS}[1]->{SIZE_IS}, $env);
+ my $size = ParseExpr($e->{LEVELS}[1]->{SIZE_IS}, $env, $e);
check_null_pointer($size);
pidl "NDR_PULL_ALLOC_N(ndr, r->out.$e->{NAME}, $size);";
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/TDR.pm b/source4/pidl/lib/Parse/Pidl/Samba4/TDR.pm
index bc8d27a283..a3e8d3470b 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/TDR.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/TDR.pm
@@ -72,7 +72,7 @@ sub ParserElement($$$)
if (has_property($e, "charset")) {
fatal($e,"charset() on non-array element") unless (defined($e->{ARRAY_LEN}) and scalar(@{$e->{ARRAY_LEN}}) > 0);
- my $len = ParseExpr(@{$e->{ARRAY_LEN}}[0], $env);
+ my $len = ParseExpr(@{$e->{ARRAY_LEN}}[0], $env, $e);
if ($len eq "*") { $len = "-1"; }
$name = ", mem_ctx" if ($t eq "pull");
pidl "TDR_CHECK(tdr_$t\_charset(tdr$name, &v->$e->{NAME}, $len, sizeof($e->{TYPE}_t), CH_$e->{PROPERTIES}->{charset}));";
@@ -80,11 +80,11 @@ sub ParserElement($$$)
}
if (has_property($e, "switch_is")) {
- $switch = ", " . ParseExpr($e->{PROPERTIES}->{switch_is}, $env);
+ $switch = ", " . ParseExpr($e->{PROPERTIES}->{switch_is}, $env, $e);
}
if (defined($e->{ARRAY_LEN}) and scalar(@{$e->{ARRAY_LEN}}) > 0) {
- my $len = ParseExpr($e->{ARRAY_LEN}[0], $env);
+ my $len = ParseExpr($e->{ARRAY_LEN}[0], $env, $e);
if ($t eq "pull" and not is_constant($len)) {
pidl "TDR_ALLOC(mem_ctx, v->$e->{NAME}, $len);";
@@ -101,7 +101,7 @@ sub ParserElement($$$)
}
if (has_property($e, "value") && $t eq "push") {
- pidl "v->$e->{NAME} = ".ParseExpr($e->{PROPERTIES}->{value}, $env).";";
+ pidl "v->$e->{NAME} = ".ParseExpr($e->{PROPERTIES}->{value}, $env, $e).";";
}
pidl "TDR_CHECK(tdr_$t\_$e->{TYPE}(tdr$name$switch, &v->$e->{NAME}$array));";
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}));
diff --git a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm
index 9526d76a37..9415c16652 100644
--- a/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm
+++ b/source4/pidl/lib/Parse/Pidl/Wireshark/NDR.pm
@@ -19,7 +19,7 @@ package Parse::Pidl::Wireshark::NDR;
use strict;
use Parse::Pidl qw(error);
use Parse::Pidl::Typelist qw(getType);
-use Parse::Pidl::Util qw(has_property ParseExpr property_matches make_str);
+use Parse::Pidl::Util qw(has_property property_matches make_str);
use Parse::Pidl::NDR qw(ContainsString GetNextLevel);
use Parse::Pidl::Dump qw(DumpTypedef DumpFunction);
use Parse::Pidl::Wireshark::Conformance qw(ReadConformance);
diff --git a/source4/pidl/tests/util.pl b/source4/pidl/tests/util.pl
index 4c002458ea..1dde97b192 100755
--- a/source4/pidl/tests/util.pl
+++ b/source4/pidl/tests/util.pl
@@ -3,9 +3,10 @@
# Published under the GNU General Public License
use strict;
-use Test::More tests => 53;
+use Test::More tests => 55;
use FindBin qw($RealBin);
-use lib "$RealBin/../lib";
+use lib "$RealBin";
+use Util;
use Parse::Pidl::Util;
# has_property()
@@ -49,38 +50,41 @@ ok(property_matches({PROPERTIES => {x => "data"}}, "x", "^([dat]+)\$"));
# ParseExpr()
#is("", ParseExpr("", {}));
-is("a", ParseExpr("a", {"b" => "2"}));
-is("2", ParseExpr("a", {"a" => "2"}));
-is("2 * 2", ParseExpr("a*a", {"a" => "2"}));
+is("a", ParseExpr("a", {"b" => "2"}, undef));
+is("2", ParseExpr("a", {"a" => "2"}, undef));
+is("2 * 2", ParseExpr("a*a", {"a" => "2"}, undef));
is("r->length + r->length",
- ParseExpr("length+length", {"length" => "r->length"}));
+ ParseExpr("length+length", {"length" => "r->length"}, undef));
is("2 / 2 * (r->length)",
ParseExpr("constant/constant*(len)", {"constant" => "2",
- "len" => "r->length"}));
+ "len" => "r->length"}, undef));
is("2 + 2 - r->length",
ParseExpr("constant+constant-len", {"constant" => "2",
- "len" => "r->length"}));
-is("*r->length", ParseExpr("*len", { "len" => "r->length"}));
-is("**r->length", ParseExpr("**len", { "len" => "r->length"}));
-is("r->length & 2", ParseExpr("len&2", { "len" => "r->length"}));
-is("&r->length", ParseExpr("&len", { "len" => "r->length"}));
-is("calc()", ParseExpr("calc()", { "foo" => "2"}));
-is("calc(2 * 2)", ParseExpr("calc(foo * 2)", { "foo" => "2"}));
-is("strlen(\"data\")", ParseExpr("strlen(foo)", { "foo" => "\"data\""}));
-is("strlen(\"data\", 4)", ParseExpr("strlen(foo, 4)", { "foo" => "\"data\""}));
-is("foo / bar", ParseExpr("foo / bar", { "bla" => "\"data\""}));
-is("r->length % 2", ParseExpr("len%2", { "len" => "r->length"}));
-is("r->length == 2", ParseExpr("len==2", { "len" => "r->length"}));
-is("r->length != 2", ParseExpr("len!=2", { "len" => "r->length"}));
-is("pr->length", ParseExpr("pr->length", { "p" => "r"}));
-is("r->length", ParseExpr("p->length", { "p" => "r"}));
-is("_foo / bla32", ParseExpr("_foo / bla32", { "bla" => "\"data\""}));
-is("foo.bar.blah", ParseExpr("foo.blah", { "foo" => "foo.bar"}));
-is("\"bla\"", ParseExpr("\"bla\"", {}));
-is("1 << 2", ParseExpr("1 << 2", {}));
-is("1 >> 2", ParseExpr("1 >> 2", {}));
-is("0x200", ParseExpr("0x200", {}));
-is("2?3:0", ParseExpr("2?3:0", {}));
-is("~0", ParseExpr("~0", {}));
-is("b->a->a", ParseExpr("a->a->a", {"a" => "b"}));
-is("b.a.a", ParseExpr("a.a.a", {"a" => "b"}));
+ "len" => "r->length"}, undef));
+is("*r->length", ParseExpr("*len", { "len" => "r->length"}, undef));
+is("**r->length", ParseExpr("**len", { "len" => "r->length"}, undef));
+is("r->length & 2", ParseExpr("len&2", { "len" => "r->length"}, undef));
+is("&r->length", ParseExpr("&len", { "len" => "r->length"}, undef));
+is("calc()", ParseExpr("calc()", { "foo" => "2"}, undef));
+is("calc(2 * 2)", ParseExpr("calc(foo * 2)", { "foo" => "2"}, undef));
+is("strlen(\"data\")", ParseExpr("strlen(foo)", { "foo" => "\"data\""}, undef));
+is("strlen(\"data\", 4)", ParseExpr("strlen(foo, 4)", { "foo" => "\"data\""}, undef));
+is("foo / bar", ParseExpr("foo / bar", { "bla" => "\"data\""}, undef));
+is("r->length % 2", ParseExpr("len%2", { "len" => "r->length"}, undef));
+is("r->length == 2", ParseExpr("len==2", { "len" => "r->length"}, undef));
+is("r->length != 2", ParseExpr("len!=2", { "len" => "r->length"}, undef));
+is("pr->length", ParseExpr("pr->length", { "p" => "r"}, undef));
+is("r->length", ParseExpr("p->length", { "p" => "r"}, undef));
+is("_foo / bla32", ParseExpr("_foo / bla32", { "bla" => "\"data\""}, undef));
+is("foo.bar.blah", ParseExpr("foo.blah", { "foo" => "foo.bar"}, undef));
+is("\"bla\"", ParseExpr("\"bla\"", {}, undef));
+is("1 << 2", ParseExpr("1 << 2", {}, undef));
+is("1 >> 2", ParseExpr("1 >> 2", {}, undef));
+is("0x200", ParseExpr("0x200", {}, undef));
+is("2?3:0", ParseExpr("2?3:0", {}, undef));
+is("~0", ParseExpr("~0", {}, undef));
+is("b->a->a", ParseExpr("a->a->a", {"a" => "b"}, undef));
+is("b.a.a", ParseExpr("a.a.a", {"a" => "b"}, undef));
+
+test_errors("nofile:0: Parse error in `~' near `~'\n", sub {
+ is(undef, ParseExpr("~", {}, {FILE => "nofile", LINE => 0})); });