diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-10-04 17:21:31 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:39:23 -0500 |
commit | 81c306472a9c6bf6238e916e49076525d4920ed8 (patch) | |
tree | 84b7bdadea99d6136ed73e7fcca1a4b779e7eba4 /source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | |
parent | 55065d27cede4e2cdc0e1240b1b5952fa5697391 (diff) | |
download | samba-81c306472a9c6bf6238e916e49076525d4920ed8.tar.gz samba-81c306472a9c6bf6238e916e49076525d4920ed8.tar.bz2 samba-81c306472a9c6bf6238e916e49076525d4920ed8.zip |
r10715: More Samba3 parser generator improvements:
- Actually generate parsers for unions and structs.
- Support some more builtin types.
- Some more work on supporting arrays.
- Several other small fixes.
I've updated the example output at http://samba.org/~jelmer/
(This used to be commit b229c033ebc7ec972b32f1b75b60a9c68a36db97)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm')
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm index 5caab5da0c..57ee1543ff 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/Parser.pm @@ -23,8 +23,7 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{FILE}:$e->{LINE}: $s\n"); } #TODO: # - Different scalars / buffers functions for arrays + unions -# - Register own types with Types::AddType() -# - Find external types somehow? +# - Memory allocation for arrays? sub DeclareArrayVariables($) { @@ -78,7 +77,7 @@ sub ParseElementLevelPtr($$$$$) fatal($e, "relative pointers not supported for Samba 3"); } - pidl "if (!prs_uint32(\"ptr_$e->{NAME}\",ps,depth,&" . ParseExpr("ptr_$e->{NAME}", $env) . ", ps, depth))"; + pidl "if (!prs_uint32(\"ptr_$e->{NAME}\", ps, depth, &" . ParseExpr("ptr_$e->{NAME}", $env) . ", ps, depth))"; pidl "\treturn False;"; pidl ""; @@ -138,7 +137,7 @@ sub InitLevel($$$$) deindent; pidl "}"; } elsif ($l->{TYPE} eq "DATA") { - pidl InitType($e, $l, $varname, $varname); + pidl InitType($e, $l, ParseExpr($e->{NAME}, $env), $varname); } elsif ($l->{TYPE} eq "SWITCH") { InitLevel($e, GetNextLevel($e,$l), $varname, $env); } @@ -149,20 +148,22 @@ sub CreateStruct($$$$) my ($fn,$s,$es,$a) = @_; my $args = ""; - foreach my $e (@$es) { + foreach (@$es) { $args .= ", " . DeclLong($_); } - my $env = {}; + my $env = { "this" => "v" }; foreach my $e (@$es) { foreach my $l (@{$e->{LEVELS}}) { if ($l->{TYPE} eq "DATA") { - $env->{"$e->{NAME}"} = $e->{"v->$e->{NAME}"}; + $env->{$e->{NAME}} = "v->$e->{NAME}"; } elsif ($l->{TYPE} eq "POINTER") { - $env->{"ptr_$e->{NAME}"} = $e->{"v->ptr_$e->{NAME}"}; + $env->{"ptr_$e->{NAME}"} = "v->ptr_$e->{NAME}"; } elsif ($l->{TYPE} eq "SWITCH") { - $env->{"level_$e->{NAME}"} = $e->{"v->level_$e->{NAME}"}; - } + $env->{"level_$e->{NAME}"} = "v->level_$e->{NAME}"; + } elsif ($l->{TYPE} eq "ARRAY") { + $env->{"length_$e->{NAME}"} = "v->length_$e->{NAME}"; + } } } @@ -173,7 +174,7 @@ sub CreateStruct($$$$) pidl ""; # Call init for all arguments foreach (@$es) { - InitLevel($_, $_->{LEVELS}[0], ParseExpr($_->{NAME}, $env), $env); + InitLevel($_, $_->{LEVELS}[0], $_->{NAME}, $env); pidl ""; } pidl "return True;"; @@ -238,11 +239,13 @@ sub ParseUnion($$$) foreach (@{$u->{ELEMENTS}}) { pidl "$_->{CASE}:"; indent; - pidl "depth++;"; - ParseElement($_, {}); + if ($_->{TYPE} ne "EMPTY") { + pidl "depth++;"; + ParseElement($_, {}); + pidl "depth--;"; + } + pidl "break;"; deindent; - pidl "depth--;"; - pidl "break"; pidl ""; } @@ -290,8 +293,8 @@ sub ParseInterface($) # Structures first pidl "/* $if->{NAME} structures */"; foreach (@{$if->{TYPEDEFS}}) { - ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "STRUCT"); - ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{TYPE} eq "UNION"); + ParseStruct($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "STRUCT"); + ParseUnion($if, $_->{DATA}, $_->{NAME}) if ($_->{DATA}->{TYPE} eq "UNION"); } pidl "/* $if->{NAME} functions */"; |