diff options
Diffstat (limited to 'source4/pidl')
30 files changed, 2268 insertions, 3126 deletions
diff --git a/source4/pidl/MANIFEST b/source4/pidl/MANIFEST index 7f30c3ab54..051c5d2b19 100644 --- a/source4/pidl/MANIFEST +++ b/source4/pidl/MANIFEST @@ -40,4 +40,4 @@ idl.yp TODO README pidl -META.yml Module meta-data (added by MakeMaker) +META.yml diff --git a/source4/pidl/META.yml b/source4/pidl/META.yml new file mode 100644 index 0000000000..4822b50f09 --- /dev/null +++ b/source4/pidl/META.yml @@ -0,0 +1,18 @@ +name: Parse-Pidl +abstract: Generate parsers / DCE/RPC-clients from IDL +author: + - Andrew Tridgell <tridge@samba.org> + - Jelmer Vernooij <jelmer@samba.org> + - Stefan Metzmacher <metze@samba.org> + - Tim Potter <tpot@samba.org> +license: gplv3 +installdirs: site +homepage: http://www.samba.org/ +bugtracker: http://bugzilla.samba.org/ +requires: + Parse::Yapp: 0 +recommends: + Data::Dumper: 0 +meta-spec: + version: 1.3 + url: http://module-build.sourceforge.net/META-spec-v1.3.html diff --git a/source4/pidl/README b/source4/pidl/README index 5bf7752da9..d678387282 100644 --- a/source4/pidl/README +++ b/source4/pidl/README @@ -40,6 +40,7 @@ Parse::Pidl::Samba4::NDR::Server - Generates server side implementation in C Parse::Pidl::Samba4::TDR - Parser generator for the "Trivial Data Representation" Parse::Pidl::Samba4::Template - Generates stubs in C for server implementation Parse::Pidl::Samba4::EJS - Generates bindings for Embedded JavaScript (EJS) +Parse::Pidl::Samba4::Python - Generates bindings for Python -- Samba COM / DCOM -- Parse::Pidl::Samba4::COM::Proxy - Generates proxy object for DCOM (client-side) diff --git a/source4/pidl/TODO b/source4/pidl/TODO index 487d51d11e..f1cca0ab23 100644 --- a/source4/pidl/TODO +++ b/source4/pidl/TODO @@ -6,7 +6,6 @@ - compatibility mode for generating MIDL-readable data: - strip out pidl-specific properties -- remove declare in favor of typedef - make bitmap an optional attribute on enum - support nested elements - support typedefs properly (e.g. allow "typedef void **bla;") diff --git a/source4/pidl/idl.yp b/source4/pidl/idl.yp index c372569a75..d2543c580c 100644 --- a/source4/pidl/idl.yp +++ b/source4/pidl/idl.yp @@ -93,7 +93,7 @@ definitions: ; -definition: function | const | typedef | declare | typedecl +definition: function | const | typedef | typedecl ; const: 'const' identifier pointers identifier '=' anytext ';' @@ -132,40 +132,6 @@ function: property_list type identifier '(' element_list2 ')' ';' }} ; -declare: 'declare' decl_type identifier';' - {{ - "TYPE" => "DECLARE", - "NAME" => $_[3], - "DATA" => $_[2], - "FILE" => $_[0]->YYData->{FILE}, - "LINE" => $_[0]->YYData->{LINE}, - }} -; - -decl_type: decl_enum | decl_bitmap | decl_union -; - -decl_enum: property_list 'enum' - {{ - "TYPE" => "ENUM", - "PROPERTIES" => $_[1] - }} -; - -decl_bitmap: property_list 'bitmap' - {{ - "TYPE" => "BITMAP", - "PROPERTIES" => $_[1] - }} -; - -decl_union: property_list 'union' - {{ - "TYPE" => "UNION", - "PROPERTIES" => $_[1] - }} -; - typedef: property_list 'typedef' type identifier array_len ';' {{ "TYPE" => "TYPEDEF", @@ -476,7 +442,7 @@ again: if (s/^([\w_]+)//) { $parser->YYData->{LAST_TOKEN} = $1; if ($1 =~ - /^(coclass|interface|const|typedef|declare|union|cpp_quote + /^(coclass|interface|const|typedef|union|cpp_quote |struct|enum|bitmap|void|unsigned|signed|import|include |importlib)$/x) { return $1; diff --git a/source4/pidl/lib/Parse/Pidl.pm b/source4/pidl/lib/Parse/Pidl.pm index 0c6e0e5727..c2c9463d03 100644 --- a/source4/pidl/lib/Parse/Pidl.pm +++ b/source4/pidl/lib/Parse/Pidl.pm @@ -9,7 +9,7 @@ package Parse::Pidl; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(warning error fatal); +@EXPORT_OK = qw(warning error fatal $VERSION); use strict; diff --git a/source4/pidl/lib/Parse/Pidl/CUtil.pm b/source4/pidl/lib/Parse/Pidl/CUtil.pm new file mode 100644 index 0000000000..bd7b16812c --- /dev/null +++ b/source4/pidl/lib/Parse/Pidl/CUtil.pm @@ -0,0 +1,39 @@ +################################################### +# C utility functions for pidl +# Copyright jelmer@samba.org 2005-2007 +# released under the GNU GPL +package Parse::Pidl::CUtil; + +require Exporter; +@ISA = qw(Exporter); +@EXPORT = qw(get_pointer_to get_value_of); +use vars qw($VERSION); +$VERSION = '0.01'; + +use strict; + +sub get_pointer_to($) +{ + my $var_name = shift; + + if ($var_name =~ /^\*(.*)$/) { + return $1; + } elsif ($var_name =~ /^\&(.*)$/) { + return "&($var_name)"; + } else { + return "&$var_name"; + } +} + +sub get_value_of($) +{ + my $var_name = shift; + + if ($var_name =~ /^\&(.*)$/) { + return $1; + } else { + return "*$var_name"; + } +} + +1; diff --git a/source4/pidl/lib/Parse/Pidl/Compat.pm b/source4/pidl/lib/Parse/Pidl/Compat.pm index f1241ef341..7939bb2df2 100644 --- a/source4/pidl/lib/Parse/Pidl/Compat.pm +++ b/source4/pidl/lib/Parse/Pidl/Compat.pm @@ -152,13 +152,6 @@ sub CheckInterface($) $if->{PROPERTIES}->{pointer_default_top} ne "ref") { warning($if, "pointer_default_top() is pidl-specific"); } - - foreach my $x (@{$if->{DATA}}) { - if ($x->{TYPE} eq "DECLARE") { - warning($if, "the declare keyword is pidl-specific"); - next; - } - } } sub Check($) diff --git a/source4/pidl/lib/Parse/Pidl/IDL.pm b/source4/pidl/lib/Parse/Pidl/IDL.pm index e9155e4e00..35e1d7bcd7 100644 --- a/source4/pidl/lib/Parse/Pidl/IDL.pm +++ b/source4/pidl/lib/Parse/Pidl/IDL.pm @@ -38,7 +38,7 @@ sub new { "import" => 7, "include" => 13 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { 'cpp_quote' => 11, 'importlib' => 10, @@ -124,7 +124,7 @@ sub new { } }, {#State 16 - DEFAULT => -124 + DEFAULT => -116 }, {#State 17 DEFAULT => -11 @@ -184,7 +184,7 @@ sub new { } }, {#State 26 - DEFAULT => -120 + DEFAULT => -112 }, {#State 27 ACTIONS => { @@ -206,10 +206,10 @@ sub new { ACTIONS => { "(" => 40 }, - DEFAULT => -95 + DEFAULT => -87 }, {#State 31 - DEFAULT => -93 + DEFAULT => -85 }, {#State 32 DEFAULT => -8 @@ -231,10 +231,9 @@ sub new { }, {#State 37 ACTIONS => { - "declare" => 49, - "const" => 53 + "const" => 51 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { 'typedecl' => 42, 'function' => 43, @@ -243,12 +242,11 @@ sub new { 'definition' => 48, 'property_list' => 47, 'usertype' => 46, - 'const' => 52, - 'declare' => 51, - 'struct' => 50, - 'typedef' => 55, - 'enum' => 54, - 'union' => 56 + 'const' => 50, + 'struct' => 49, + 'typedef' => 53, + 'enum' => 52, + 'union' => 54 } }, {#State 38 @@ -257,1539 +255,1482 @@ sub new { }, GOTOS => { 'identifier' => 30, - 'property' => 57 + 'property' => 55 } }, {#State 39 - DEFAULT => -92 + DEFAULT => -84 }, {#State 40 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'text' => 63, - 'listtext' => 59, - 'anytext' => 58, - 'constant' => 60 + 'identifier' => 60, + 'text' => 61, + 'listtext' => 57, + 'anytext' => 56, + 'constant' => 58 } }, {#State 41 ACTIONS => { - "}" => 64, - "interface" => 65 + "}" => 62, + "interface" => 63 } }, {#State 42 - DEFAULT => -24 + DEFAULT => -23 }, {#State 43 DEFAULT => -20 }, {#State 44 - DEFAULT => -39 + DEFAULT => -31 }, {#State 45 ACTIONS => { - "}" => 66, - "declare" => 49, - "const" => 53 + "}" => 64, + "const" => 51 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { 'typedecl' => 42, 'function' => 43, 'bitmap' => 44, - 'definition' => 67, + 'definition' => 65, 'property_list' => 47, 'usertype' => 46, - 'const' => 52, - 'struct' => 50, - 'declare' => 51, - 'typedef' => 55, - 'enum' => 54, - 'union' => 56 + 'struct' => 49, + 'const' => 50, + 'typedef' => 53, + 'enum' => 52, + 'union' => 54 } }, {#State 46 ACTIONS => { - ";" => 68 + ";" => 66 } }, {#State 47 ACTIONS => { - "typedef" => 69, + "typedef" => 67, 'IDENTIFIER' => 26, - "signed" => 77, - "union" => 70, - "enum" => 79, - "bitmap" => 80, - 'void' => 71, - "unsigned" => 81, + "signed" => 75, + "union" => 68, + "enum" => 77, + "bitmap" => 78, + 'void' => 69, + "unsigned" => 79, "[" => 20, - "struct" => 76 + "struct" => 74 }, GOTOS => { - 'existingtype' => 78, + 'existingtype' => 76, 'bitmap' => 44, - 'usertype' => 73, - 'property_list' => 72, - 'identifier' => 74, - 'struct' => 50, - 'enum' => 54, - 'type' => 82, - 'union' => 56, - 'sign' => 75 + 'usertype' => 71, + 'property_list' => 70, + 'identifier' => 72, + 'struct' => 49, + 'enum' => 52, + 'type' => 80, + 'union' => 54, + 'sign' => 73 } }, {#State 48 DEFAULT => -18 }, {#State 49 - DEFAULT => -91, - GOTOS => { - 'decl_enum' => 84, - 'decl_bitmap' => 85, - 'decl_type' => 87, - 'decl_union' => 86, - 'property_list' => 83 - } + DEFAULT => -28 }, {#State 50 - DEFAULT => -36 - }, - {#State 51 - DEFAULT => -23 - }, - {#State 52 DEFAULT => -21 }, - {#State 53 + {#State 51 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 88 + 'identifier' => 81 } }, + {#State 52 + DEFAULT => -30 + }, + {#State 53 + DEFAULT => -22 + }, {#State 54 - DEFAULT => -38 + DEFAULT => -29 }, {#State 55 - DEFAULT => -22 + DEFAULT => -86 }, {#State 56 - DEFAULT => -37 + ACTIONS => { + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 + }, + DEFAULT => -89 }, {#State 57 - DEFAULT => -94 + ACTIONS => { + "," => 97, + ")" => 98 + } }, {#State 58 - ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 - }, - DEFAULT => -97 + DEFAULT => -95 }, {#State 59 - ACTIONS => { - "," => 104, - ")" => 105 - } + DEFAULT => -115 }, {#State 60 - DEFAULT => -103 + DEFAULT => -94 }, {#State 61 - DEFAULT => -123 + DEFAULT => -96 }, {#State 62 - DEFAULT => -102 - }, - {#State 63 - DEFAULT => -104 - }, - {#State 64 ACTIONS => { - ";" => 106 + ";" => 99 }, - DEFAULT => -125, + DEFAULT => -117, GOTOS => { - 'optional_semicolon' => 107 + 'optional_semicolon' => 100 } }, - {#State 65 + {#State 63 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 108 + 'identifier' => 101 } }, - {#State 66 + {#State 64 ACTIONS => { - ";" => 106 + ";" => 99 }, - DEFAULT => -125, + DEFAULT => -117, GOTOS => { - 'optional_semicolon' => 109 + 'optional_semicolon' => 102 } }, - {#State 67 + {#State 65 DEFAULT => -19 }, - {#State 68 - DEFAULT => -40 + {#State 66 + DEFAULT => -32 }, - {#State 69 + {#State 67 ACTIONS => { 'IDENTIFIER' => 26, - "signed" => 77, - 'void' => 71, - "unsigned" => 81 + "signed" => 75, + 'void' => 69, + "unsigned" => 79 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'existingtype' => 78, + 'existingtype' => 76, 'bitmap' => 44, - 'usertype' => 73, - 'property_list' => 72, - 'identifier' => 74, - 'struct' => 50, - 'enum' => 54, - 'type' => 110, - 'union' => 56, - 'sign' => 75 + 'usertype' => 71, + 'property_list' => 70, + 'identifier' => 72, + 'struct' => 49, + 'enum' => 52, + 'type' => 103, + 'union' => 54, + 'sign' => 73 } }, - {#State 70 + {#State 68 ACTIONS => { - 'IDENTIFIER' => 111 + 'IDENTIFIER' => 104 }, - DEFAULT => -122, + DEFAULT => -114, GOTOS => { - 'optional_identifier' => 112 + 'optional_identifier' => 105 } }, - {#State 71 - DEFAULT => -47 + {#State 69 + DEFAULT => -39 }, - {#State 72 + {#State 70 ACTIONS => { - "union" => 70, - "enum" => 79, - "bitmap" => 80, + "union" => 68, + "enum" => 77, + "bitmap" => 78, "[" => 20, - "struct" => 76 + "struct" => 74 } }, - {#State 73 - DEFAULT => -45 + {#State 71 + DEFAULT => -37 }, - {#State 74 - DEFAULT => -44 + {#State 72 + DEFAULT => -36 }, - {#State 75 + {#State 73 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 113 + 'identifier' => 106 } }, - {#State 76 + {#State 74 ACTIONS => { - 'IDENTIFIER' => 111 + 'IDENTIFIER' => 104 }, - DEFAULT => -122, + DEFAULT => -114, GOTOS => { - 'optional_identifier' => 114 + 'optional_identifier' => 107 } }, - {#State 77 - DEFAULT => -41 - }, - {#State 78 - DEFAULT => -46 + {#State 75 + DEFAULT => -33 }, - {#State 79 - ACTIONS => { - 'IDENTIFIER' => 111 - }, - DEFAULT => -122, - GOTOS => { - 'optional_identifier' => 115 - } + {#State 76 + DEFAULT => -38 }, - {#State 80 + {#State 77 ACTIONS => { - 'IDENTIFIER' => 111 + 'IDENTIFIER' => 104 }, - DEFAULT => -122, + DEFAULT => -114, GOTOS => { - 'optional_identifier' => 116 + 'optional_identifier' => 108 } }, - {#State 81 - DEFAULT => -42 - }, - {#State 82 + {#State 78 ACTIONS => { - 'IDENTIFIER' => 26 + 'IDENTIFIER' => 104 }, + DEFAULT => -114, GOTOS => { - 'identifier' => 117 - } - }, - {#State 83 - ACTIONS => { - "union" => 118, - "enum" => 119, - "bitmap" => 120, - "[" => 20 + 'optional_identifier' => 109 } }, - {#State 84 - DEFAULT => -29 - }, - {#State 85 - DEFAULT => -30 - }, - {#State 86 - DEFAULT => -31 + {#State 79 + DEFAULT => -34 }, - {#State 87 + {#State 80 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 121 + 'identifier' => 110 } }, - {#State 88 - DEFAULT => -80, + {#State 81 + DEFAULT => -72, GOTOS => { - 'pointers' => 122 + 'pointers' => 111 } }, - {#State 89 + {#State 82 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 123, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 112, + 'text' => 61, + 'constant' => 58 } }, - {#State 90 + {#State 83 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 124, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 113, + 'text' => 61, + 'constant' => 58 } }, - {#State 91 + {#State 84 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 125, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 114, + 'text' => 61, + 'constant' => 58 } }, - {#State 92 + {#State 85 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 126, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 115, + 'text' => 61, + 'constant' => 58 } }, - {#State 93 + {#State 86 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 127, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 116, + 'text' => 61, + 'constant' => 58 } }, - {#State 94 + {#State 87 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 128, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 117, + 'text' => 61, + 'constant' => 58 } }, - {#State 95 + {#State 88 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 129, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 118, + 'text' => 61, + 'constant' => 58 } }, - {#State 96 + {#State 89 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 130, - 'text' => 63, - 'constant' => 60, - 'commalisttext' => 131 + 'identifier' => 60, + 'anytext' => 119, + 'text' => 61, + 'constant' => 58, + 'commalisttext' => 120 } }, - {#State 97 + {#State 90 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 132, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 121, + 'text' => 61, + 'constant' => 58 } }, - {#State 98 + {#State 91 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 133, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 122, + 'text' => 61, + 'constant' => 58 } }, - {#State 99 + {#State 92 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 134, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 123, + 'text' => 61, + 'constant' => 58 } }, - {#State 100 + {#State 93 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 130, - 'text' => 63, - 'constant' => 60, - 'commalisttext' => 135 + 'identifier' => 60, + 'anytext' => 119, + 'text' => 61, + 'constant' => 58, + 'commalisttext' => 124 } }, - {#State 101 + {#State 94 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 136, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 125, + 'text' => 61, + 'constant' => 58 } }, - {#State 102 + {#State 95 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 137, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 126, + 'text' => 61, + 'constant' => 58 } }, - {#State 103 + {#State 96 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 138, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 127, + 'text' => 61, + 'constant' => 58 } }, - {#State 104 + {#State 97 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 139, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 128, + 'text' => 61, + 'constant' => 58 } }, - {#State 105 - DEFAULT => -96 + {#State 98 + DEFAULT => -88 }, - {#State 106 - DEFAULT => -126 + {#State 99 + DEFAULT => -118 }, - {#State 107 + {#State 100 DEFAULT => -13 }, - {#State 108 + {#State 101 ACTIONS => { - ";" => 140 + ";" => 129 } }, - {#State 109 + {#State 102 DEFAULT => -16 }, - {#State 110 + {#State 103 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 141 + 'identifier' => 130 } }, - {#State 111 - DEFAULT => -121 + {#State 104 + DEFAULT => -113 }, - {#State 112 + {#State 105 ACTIONS => { - "{" => 143 + "{" => 132 }, - DEFAULT => -76, + DEFAULT => -68, GOTOS => { - 'union_body' => 144, - 'opt_union_body' => 142 + 'union_body' => 133, + 'opt_union_body' => 131 } }, - {#State 113 - DEFAULT => -43 + {#State 106 + DEFAULT => -35 }, - {#State 114 + {#State 107 ACTIONS => { - "{" => 146 + "{" => 135 }, - DEFAULT => -66, + DEFAULT => -58, GOTOS => { - 'struct_body' => 145, - 'opt_struct_body' => 147 + 'struct_body' => 134, + 'opt_struct_body' => 136 } }, - {#State 115 + {#State 108 ACTIONS => { - "{" => 148 + "{" => 137 }, - DEFAULT => -49, + DEFAULT => -41, GOTOS => { - 'opt_enum_body' => 150, - 'enum_body' => 149 + 'opt_enum_body' => 139, + 'enum_body' => 138 } }, - {#State 116 + {#State 109 ACTIONS => { - "{" => 152 + "{" => 141 }, - DEFAULT => -57, + DEFAULT => -49, GOTOS => { - 'bitmap_body' => 153, - 'opt_bitmap_body' => 151 + 'bitmap_body' => 142, + 'opt_bitmap_body' => 140 } }, - {#State 117 - ACTIONS => { - "(" => 154 - } - }, - {#State 118 - DEFAULT => -34 - }, - {#State 119 - DEFAULT => -32 - }, - {#State 120 - DEFAULT => -33 - }, - {#State 121 + {#State 110 ACTIONS => { - ";" => 155 + "(" => 143 } }, - {#State 122 + {#State 111 ACTIONS => { 'IDENTIFIER' => 26, - "*" => 157 + "*" => 145 }, GOTOS => { - 'identifier' => 156 + 'identifier' => 144 } }, - {#State 123 - ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 - }, - DEFAULT => -114 - }, - {#State 124 + {#State 112 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -105 + DEFAULT => -106 }, - {#State 125 + {#State 113 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -109 + DEFAULT => -97 }, - {#State 126 + {#State 114 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 - }, - DEFAULT => -117 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 + }, + DEFAULT => -101 }, - {#State 127 + {#State 115 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -116 + DEFAULT => -109 }, - {#State 128 + {#State 116 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -107 + DEFAULT => -108 }, - {#State 129 + {#State 117 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -113 + DEFAULT => -99 }, - {#State 130 + {#State 118 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -99 + DEFAULT => -105 }, - {#State 131 + {#State 119 ACTIONS => { - "}" => 158, - "," => 159 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 + }, + DEFAULT => -91 + }, + {#State 120 + ACTIONS => { + "}" => 146, + "," => 147 } }, - {#State 132 + {#State 121 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -111 + DEFAULT => -103 }, - {#State 133 + {#State 122 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -112 + DEFAULT => -104 }, - {#State 134 + {#State 123 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -115 + DEFAULT => -107 }, - {#State 135 + {#State 124 ACTIONS => { - "," => 159, - ")" => 160 + "," => 147, + ")" => 148 } }, - {#State 136 + {#State 125 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -110 + DEFAULT => -102 }, - {#State 137 + {#State 126 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -106 + DEFAULT => -98 }, - {#State 138 + {#State 127 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -108 + DEFAULT => -100 }, - {#State 139 + {#State 128 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -98 + DEFAULT => -90 }, - {#State 140 + {#State 129 DEFAULT => -15 }, - {#State 141 + {#State 130 ACTIONS => { - "[" => 161 + "[" => 149 }, - DEFAULT => -88, + DEFAULT => -80, GOTOS => { - 'array_len' => 162 + 'array_len' => 150 } }, - {#State 142 - DEFAULT => -78 + {#State 131 + DEFAULT => -70 }, - {#State 143 - DEFAULT => -73, + {#State 132 + DEFAULT => -65, GOTOS => { - 'union_elements' => 163 + 'union_elements' => 151 } }, - {#State 144 - DEFAULT => -77 + {#State 133 + DEFAULT => -69 }, - {#State 145 - DEFAULT => -67 + {#State 134 + DEFAULT => -59 }, - {#State 146 - DEFAULT => -82, + {#State 135 + DEFAULT => -74, GOTOS => { - 'element_list1' => 164 + 'element_list1' => 152 } }, - {#State 147 - DEFAULT => -68 + {#State 136 + DEFAULT => -60 }, - {#State 148 + {#State 137 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 165, - 'enum_element' => 166, - 'enum_elements' => 167 + 'identifier' => 153, + 'enum_element' => 154, + 'enum_elements' => 155 } }, - {#State 149 - DEFAULT => -50 + {#State 138 + DEFAULT => -42 }, - {#State 150 - DEFAULT => -51 + {#State 139 + DEFAULT => -43 }, - {#State 151 - DEFAULT => -59 + {#State 140 + DEFAULT => -51 }, - {#State 152 + {#State 141 ACTIONS => { 'IDENTIFIER' => 26 }, - DEFAULT => -62, + DEFAULT => -54, GOTOS => { - 'identifier' => 170, - 'bitmap_element' => 169, - 'bitmap_elements' => 168, - 'opt_bitmap_elements' => 171 + 'identifier' => 158, + 'bitmap_element' => 157, + 'bitmap_elements' => 156, + 'opt_bitmap_elements' => 159 } }, - {#State 153 - DEFAULT => -58 + {#State 142 + DEFAULT => -50 }, - {#State 154 + {#State 143 ACTIONS => { - "," => -84, - "void" => 175, - ")" => -84 + "," => -76, + "void" => 163, + ")" => -76 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'base_element' => 172, - 'element_list2' => 174, - 'property_list' => 173 + 'base_element' => 160, + 'element_list2' => 162, + 'property_list' => 161 } }, - {#State 155 - DEFAULT => -28 - }, - {#State 156 + {#State 144 ACTIONS => { - "[" => 161, - "=" => 177 + "[" => 149, + "=" => 165 }, GOTOS => { - 'array_len' => 176 + 'array_len' => 164 } }, - {#State 157 - DEFAULT => -81 + {#State 145 + DEFAULT => -73 }, - {#State 158 + {#State 146 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 178, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 166, + 'text' => 61, + 'constant' => 58 } }, - {#State 159 + {#State 147 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 179, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 167, + 'text' => 61, + 'constant' => 58 } }, - {#State 160 + {#State 148 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 180, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 168, + 'text' => 61, + 'constant' => 58 } }, - {#State 161 + {#State 149 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, - "]" => 181, + "]" => 169, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 182, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 170, + 'text' => 61, + 'constant' => 58 } }, - {#State 162 + {#State 150 ACTIONS => { - ";" => 183 + ";" => 171 } }, - {#State 163 + {#State 151 ACTIONS => { - "}" => 184 + "}" => 172 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'optional_base_element' => 186, - 'property_list' => 185 + 'optional_base_element' => 174, + 'property_list' => 173 } }, - {#State 164 + {#State 152 ACTIONS => { - "}" => 187 + "}" => 175 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'base_element' => 188, - 'property_list' => 173 + 'base_element' => 176, + 'property_list' => 161 } }, - {#State 165 + {#State 153 ACTIONS => { - "=" => 189 + "=" => 177 }, - DEFAULT => -54 + DEFAULT => -46 }, - {#State 166 - DEFAULT => -52 + {#State 154 + DEFAULT => -44 }, - {#State 167 + {#State 155 ACTIONS => { - "}" => 190, - "," => 191 + "}" => 178, + "," => 179 } }, - {#State 168 + {#State 156 ACTIONS => { - "," => 192 + "," => 180 }, - DEFAULT => -63 + DEFAULT => -55 }, - {#State 169 - DEFAULT => -60 + {#State 157 + DEFAULT => -52 }, - {#State 170 + {#State 158 ACTIONS => { - "=" => 193 + "=" => 181 } }, - {#State 171 + {#State 159 ACTIONS => { - "}" => 194 + "}" => 182 } }, - {#State 172 - DEFAULT => -86 + {#State 160 + DEFAULT => -78 }, - {#State 173 + {#State 161 ACTIONS => { 'IDENTIFIER' => 26, - "signed" => 77, - 'void' => 71, - "unsigned" => 81, + "signed" => 75, + 'void' => 69, + "unsigned" => 79, "[" => 20 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'existingtype' => 78, + 'existingtype' => 76, 'bitmap' => 44, - 'usertype' => 73, - 'property_list' => 72, - 'identifier' => 74, - 'struct' => 50, - 'enum' => 54, - 'type' => 195, - 'union' => 56, - 'sign' => 75 + 'usertype' => 71, + 'property_list' => 70, + 'identifier' => 72, + 'struct' => 49, + 'enum' => 52, + 'type' => 183, + 'union' => 54, + 'sign' => 73 } }, - {#State 174 + {#State 162 ACTIONS => { - "," => 196, - ")" => 197 + "," => 184, + ")" => 185 } }, - {#State 175 - DEFAULT => -85 + {#State 163 + DEFAULT => -77 }, - {#State 176 + {#State 164 ACTIONS => { - "=" => 198 + "=" => 186 } }, - {#State 177 + {#State 165 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 199, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 187, + 'text' => 61, + 'constant' => 58 } }, - {#State 178 + {#State 166 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 - }, - DEFAULT => -119 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 + }, + DEFAULT => -111 }, - {#State 179 + {#State 167 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -100 + DEFAULT => -92 }, - {#State 180 + {#State 168 ACTIONS => { - ":" => 89, - "<" => 91, - "~" => 92, - "?" => 95, - "{" => 96, - "=" => 99 + ":" => 82, + "<" => 84, + "~" => 85, + "?" => 88, + "{" => 89, + "=" => 92 }, - DEFAULT => -118 + DEFAULT => -110 }, - {#State 181 + {#State 169 ACTIONS => { - "[" => 161 + "[" => 149 }, - DEFAULT => -88, + DEFAULT => -80, GOTOS => { - 'array_len' => 200 + 'array_len' => 188 } }, - {#State 182 + {#State 170 ACTIONS => { - "-" => 90, - ":" => 89, - "?" => 95, - "<" => 91, - "+" => 93, - "~" => 92, - "&" => 97, - "{" => 96, - "/" => 98, - "=" => 99, - "|" => 101, - "(" => 100, - "*" => 94, - "." => 102, - "]" => 201, - ">" => 103 + "-" => 83, + ":" => 82, + "?" => 88, + "<" => 84, + "+" => 86, + "~" => 85, + "&" => 90, + "{" => 89, + "/" => 91, + "=" => 92, + "|" => 94, + "(" => 93, + "*" => 87, + "." => 95, + "]" => 189, + ">" => 96 } }, - {#State 183 - DEFAULT => -35 + {#State 171 + DEFAULT => -27 }, - {#State 184 - DEFAULT => -75 + {#State 172 + DEFAULT => -67 }, - {#State 185 + {#State 173 ACTIONS => { "[" => 20 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'base_or_empty' => 202, - 'base_element' => 203, - 'empty_element' => 204, - 'property_list' => 205 + 'base_or_empty' => 190, + 'base_element' => 191, + 'empty_element' => 192, + 'property_list' => 193 } }, - {#State 186 - DEFAULT => -74 + {#State 174 + DEFAULT => -66 }, - {#State 187 - DEFAULT => -65 + {#State 175 + DEFAULT => -57 }, - {#State 188 + {#State 176 ACTIONS => { - ";" => 206 + ";" => 194 } }, - {#State 189 + {#State 177 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 207, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 195, + 'text' => 61, + 'constant' => 58 } }, - {#State 190 - DEFAULT => -48 + {#State 178 + DEFAULT => -40 }, - {#State 191 + {#State 179 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 165, - 'enum_element' => 208 + 'identifier' => 153, + 'enum_element' => 196 } }, - {#State 192 + {#State 180 ACTIONS => { 'IDENTIFIER' => 26 }, GOTOS => { - 'identifier' => 170, - 'bitmap_element' => 209 + 'identifier' => 158, + 'bitmap_element' => 197 } }, - {#State 193 + {#State 181 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 210, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 198, + 'text' => 61, + 'constant' => 58 } }, - {#State 194 - DEFAULT => -56 + {#State 182 + DEFAULT => -48 }, - {#State 195 - DEFAULT => -80, + {#State 183 + DEFAULT => -72, GOTOS => { - 'pointers' => 211 + 'pointers' => 199 } }, - {#State 196 - DEFAULT => -91, + {#State 184 + DEFAULT => -83, GOTOS => { - 'base_element' => 212, - 'property_list' => 173 + 'base_element' => 200, + 'property_list' => 161 } }, - {#State 197 + {#State 185 ACTIONS => { - ";" => 213 + ";" => 201 } }, - {#State 198 + {#State 186 ACTIONS => { - 'CONSTANT' => 61, + 'CONSTANT' => 59, 'TEXT' => 16, 'IDENTIFIER' => 26 }, - DEFAULT => -101, + DEFAULT => -93, GOTOS => { - 'identifier' => 62, - 'anytext' => 214, - 'text' => 63, - 'constant' => 60 + 'identifier' => 60, + 'anytext' => 202, + 'text' => 61, + 'constant' => 58 } }, - {#State 199 + {#State 187 ACTIONS => { - "-" => 90, - ":" => 89, - "?" => 95, - "<" => 91, - ";" => 215, - "+" => 93, - "~" => 92, - "&" => 97, - "{" => 96, - "/" => 98, - "=" => 99, - "|" => 101, - "(" => 100, - "*" => 94, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "?" => 88, + "<" => 84, + ";" => 203, + "+" => 86, + "~" => 85, + "&" => 90, + "{" => 89, + "/" => 91, + "=" => 92, + "|" => 94, + "(" => 93, + "*" => 87, + "." => 95, + ">" => 96 } }, - {#State 200 - DEFAULT => -89 + {#State 188 + DEFAULT => -81 }, - {#State 201 + {#State 189 ACTIONS => { - "[" => 161 + "[" => 149 }, - DEFAULT => -88, + DEFAULT => -80, GOTOS => { - 'array_len' => 216 + 'array_len' => 204 } }, - {#State 202 - DEFAULT => -72 + {#State 190 + DEFAULT => -64 }, - {#State 203 + {#State 191 ACTIONS => { - ";" => 217 + ";" => 205 } }, - {#State 204 - DEFAULT => -71 + {#State 192 + DEFAULT => -63 }, - {#State 205 + {#State 193 ACTIONS => { 'IDENTIFIER' => 26, - "signed" => 77, - ";" => 218, - 'void' => 71, - "unsigned" => 81, + "signed" => 75, + ";" => 206, + 'void' => 69, + "unsigned" => 79, "[" => 20 }, - DEFAULT => -91, + DEFAULT => -83, GOTOS => { - 'existingtype' => 78, + 'existingtype' => 76, 'bitmap' => 44, - 'usertype' => 73, - 'property_list' => 72, - 'identifier' => 74, - 'struct' => 50, - 'enum' => 54, - 'type' => 195, - 'union' => 56, - 'sign' => 75 + 'usertype' => 71, + 'property_list' => 70, + 'identifier' => 72, + 'struct' => 49, + 'enum' => 52, + 'type' => 183, + 'union' => 54, + 'sign' => 73 } }, - {#State 206 - DEFAULT => -83 + {#State 194 + DEFAULT => -75 }, - {#State 207 + {#State 195 ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -55 + DEFAULT => -47 }, - {#State 208 - DEFAULT => -53 + {#State 196 + DEFAULT => -45 }, - {#State 209 - DEFAULT => -61 + {#State 197 + DEFAULT => -53 }, - {#State 210 - ACTIONS => { - "-" => 90, - ":" => 89, - "<" => 91, - "+" => 93, - "~" => 92, - "*" => 94, - "?" => 95, - "{" => 96, - "&" => 97, - "/" => 98, - "=" => 99, - "(" => 100, - "|" => 101, - "." => 102, - ">" => 103 + {#State 198 + ACTIONS => { + "-" => 83, + ":" => 82, + "<" => 84, + "+" => 86, + "~" => 85, + "*" => 87, + "?" => 88, + "{" => 89, + "&" => 90, + "/" => 91, + "=" => 92, + "(" => 93, + "|" => 94, + "." => 95, + ">" => 96 }, - DEFAULT => -64 + DEFAULT => -56 }, - {#State 211 + {#State 199 ACTIONS => { 'IDENTIFIER' => 26, - "*" => 157 + "*" => 145 }, GOTOS => { - 'identifier' => 219 + 'identifier' => 207 } }, - {#State 212 - DEFAULT => -87 + {#State 200 + DEFAULT => -79 }, - {#State 213 - DEFAULT => -27 + {#State 201 + DEFAULT => -26 }, - {#State 214 - ACTIONS => { - "-" => 90, - ":" => 89, - "?" => 95, - "<" => 91, - ";" => 220, - "+" => 93, - "~" => 92, - "&" => 97, - "{" => 96, - "/" => 98, - "=" => 99, - "|" => 101, - "(" => 100, - "*" => 94, - "." => 102, - ">" => 103 - } - }, - {#State 215 - DEFAULT => -25 + {#State 202 + ACTIONS => { + "-" => 83, + ":" => 82, + "?" => 88, + "<" => 84, + ";" => 208, + "+" => 86, + "~" => 85, + "&" => 90, + "{" => 89, + "/" => 91, + "=" => 92, + "|" => 94, + "(" => 93, + "*" => 87, + "." => 95, + ">" => 96 + } }, - {#State 216 - DEFAULT => -90 + {#State 203 + DEFAULT => -24 }, - {#State 217 - DEFAULT => -70 + {#State 204 + DEFAULT => -82 }, - {#State 218 - DEFAULT => -69 + {#State 205 + DEFAULT => -62 + }, + {#State 206 + DEFAULT => -61 }, - {#State 219 + {#State 207 ACTIONS => { - "[" => 161 + "[" => 149 }, - DEFAULT => -88, + DEFAULT => -80, GOTOS => { - 'array_len' => 221 + 'array_len' => 209 } }, - {#State 220 - DEFAULT => -26 + {#State 208 + DEFAULT => -25 }, - {#State 221 - DEFAULT => -79 + {#State 209 + DEFAULT => -71 } ], yyrules => @@ -1952,9 +1893,6 @@ sub 'definition', 1, undef ], [#Rule 24 - 'definition', 1, undef - ], - [#Rule 25 'const', 7, sub #line 100 "idl.yp" @@ -1968,7 +1906,7 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 26 + [#Rule 25 'const', 8, sub #line 110 "idl.yp" @@ -1983,7 +1921,7 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 27 + [#Rule 26 'function', 7, sub #line 124 "idl.yp" @@ -1997,58 +1935,10 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 28 - 'declare', 4, -sub -#line 136 "idl.yp" -{{ - "TYPE" => "DECLARE", - "NAME" => $_[3], - "DATA" => $_[2], - "FILE" => $_[0]->YYData->{FILE}, - "LINE" => $_[0]->YYData->{LINE}, - }} - ], - [#Rule 29 - 'decl_type', 1, undef - ], - [#Rule 30 - 'decl_type', 1, undef - ], - [#Rule 31 - 'decl_type', 1, undef - ], - [#Rule 32 - 'decl_enum', 2, -sub -#line 149 "idl.yp" -{{ - "TYPE" => "ENUM", - "PROPERTIES" => $_[1] - }} - ], - [#Rule 33 - 'decl_bitmap', 2, -sub -#line 156 "idl.yp" -{{ - "TYPE" => "BITMAP", - "PROPERTIES" => $_[1] - }} - ], - [#Rule 34 - 'decl_union', 2, -sub -#line 163 "idl.yp" -{{ - "TYPE" => "UNION", - "PROPERTIES" => $_[1] - }} - ], - [#Rule 35 + [#Rule 27 'typedef', 6, sub -#line 170 "idl.yp" +#line 136 "idl.yp" {{ "TYPE" => "TYPEDEF", "PROPERTIES" => $_[1], @@ -2059,67 +1949,67 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 36 + [#Rule 28 'usertype', 1, undef ], - [#Rule 37 + [#Rule 29 'usertype', 1, undef ], - [#Rule 38 + [#Rule 30 'usertype', 1, undef ], - [#Rule 39 + [#Rule 31 'usertype', 1, undef ], - [#Rule 40 + [#Rule 32 'typedecl', 2, sub -#line 183 "idl.yp" +#line 149 "idl.yp" { $_[1] } ], - [#Rule 41 + [#Rule 33 'sign', 1, undef ], - [#Rule 42 + [#Rule 34 'sign', 1, undef ], - [#Rule 43 + [#Rule 35 'existingtype', 2, sub -#line 188 "idl.yp" +#line 154 "idl.yp" { ($_[1]?$_[1]:"signed") ." $_[2]" } ], - [#Rule 44 + [#Rule 36 'existingtype', 1, undef ], - [#Rule 45 + [#Rule 37 'type', 1, undef ], - [#Rule 46 + [#Rule 38 'type', 1, undef ], - [#Rule 47 + [#Rule 39 'type', 1, sub -#line 192 "idl.yp" +#line 158 "idl.yp" { "void" } ], - [#Rule 48 + [#Rule 40 'enum_body', 3, sub -#line 194 "idl.yp" +#line 160 "idl.yp" { $_[2] } ], - [#Rule 49 + [#Rule 41 'opt_enum_body', 0, undef ], - [#Rule 50 + [#Rule 42 'opt_enum_body', 1, undef ], - [#Rule 51 + [#Rule 43 'enum', 4, sub -#line 197 "idl.yp" +#line 163 "idl.yp" {{ "TYPE" => "ENUM", "PROPERTIES" => $_[1], @@ -2127,43 +2017,43 @@ sub "ELEMENTS" => $_[4] }} ], - [#Rule 52 + [#Rule 44 'enum_elements', 1, sub -#line 206 "idl.yp" +#line 172 "idl.yp" { [ $_[1] ] } ], - [#Rule 53 + [#Rule 45 'enum_elements', 3, sub -#line 207 "idl.yp" +#line 173 "idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], - [#Rule 54 + [#Rule 46 'enum_element', 1, undef ], - [#Rule 55 + [#Rule 47 'enum_element', 3, sub -#line 211 "idl.yp" +#line 177 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 56 + [#Rule 48 'bitmap_body', 3, sub -#line 214 "idl.yp" +#line 180 "idl.yp" { $_[2] } ], - [#Rule 57 + [#Rule 49 'opt_bitmap_body', 0, undef ], - [#Rule 58 + [#Rule 50 'opt_bitmap_body', 1, undef ], - [#Rule 59 + [#Rule 51 'bitmap', 4, sub -#line 217 "idl.yp" +#line 183 "idl.yp" {{ "TYPE" => "BITMAP", "PROPERTIES" => $_[1], @@ -2171,46 +2061,46 @@ sub "ELEMENTS" => $_[4] }} ], - [#Rule 60 + [#Rule 52 'bitmap_elements', 1, sub -#line 226 "idl.yp" +#line 192 "idl.yp" { [ $_[1] ] } ], - [#Rule 61 + [#Rule 53 'bitmap_elements', 3, sub -#line 227 "idl.yp" +#line 193 "idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], - [#Rule 62 + [#Rule 54 'opt_bitmap_elements', 0, undef ], - [#Rule 63 + [#Rule 55 'opt_bitmap_elements', 1, undef ], - [#Rule 64 + [#Rule 56 'bitmap_element', 3, sub -#line 232 "idl.yp" +#line 198 "idl.yp" { "$_[1] ( $_[3] )" } ], - [#Rule 65 + [#Rule 57 'struct_body', 3, sub -#line 235 "idl.yp" +#line 201 "idl.yp" { $_[2] } ], - [#Rule 66 + [#Rule 58 'opt_struct_body', 0, undef ], - [#Rule 67 + [#Rule 59 'opt_struct_body', 1, undef ], - [#Rule 68 + [#Rule 60 'struct', 4, sub -#line 239 "idl.yp" +#line 205 "idl.yp" {{ "TYPE" => "STRUCT", "PROPERTIES" => $_[1], @@ -2218,10 +2108,10 @@ sub "ELEMENTS" => $_[4] }} ], - [#Rule 69 + [#Rule 61 'empty_element', 2, sub -#line 248 "idl.yp" +#line 214 "idl.yp" {{ "NAME" => "", "TYPE" => "EMPTY", @@ -2232,43 +2122,43 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 70 + [#Rule 62 'base_or_empty', 2, undef ], - [#Rule 71 + [#Rule 63 'base_or_empty', 1, undef ], - [#Rule 72 + [#Rule 64 'optional_base_element', 2, sub -#line 262 "idl.yp" +#line 228 "idl.yp" { $_[2]->{PROPERTIES} = FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] } ], - [#Rule 73 + [#Rule 65 'union_elements', 0, undef ], - [#Rule 74 + [#Rule 66 'union_elements', 2, sub -#line 267 "idl.yp" +#line 233 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], - [#Rule 75 + [#Rule 67 'union_body', 3, sub -#line 270 "idl.yp" +#line 236 "idl.yp" { $_[2] } ], - [#Rule 76 + [#Rule 68 'opt_union_body', 0, undef ], - [#Rule 77 + [#Rule 69 'opt_union_body', 1, undef ], - [#Rule 78 + [#Rule 70 'union', 4, sub -#line 274 "idl.yp" +#line 240 "idl.yp" {{ "TYPE" => "UNION", "PROPERTIES" => $_[1], @@ -2276,10 +2166,10 @@ sub "ELEMENTS" => $_[4] }} ], - [#Rule 79 + [#Rule 71 'base_element', 5, sub -#line 283 "idl.yp" +#line 249 "idl.yp" {{ "NAME" => $_[4], "TYPE" => $_[2], @@ -2290,241 +2180,241 @@ sub "LINE" => $_[0]->YYData->{LINE}, }} ], - [#Rule 80 + [#Rule 72 'pointers', 0, sub -#line 297 "idl.yp" +#line 263 "idl.yp" { 0 } ], - [#Rule 81 + [#Rule 73 'pointers', 2, sub -#line 298 "idl.yp" +#line 264 "idl.yp" { $_[1]+1 } ], - [#Rule 82 + [#Rule 74 'element_list1', 0, sub -#line 302 "idl.yp" +#line 268 "idl.yp" { [] } ], - [#Rule 83 + [#Rule 75 'element_list1', 3, sub -#line 303 "idl.yp" +#line 269 "idl.yp" { push(@{$_[1]}, $_[2]); $_[1] } ], - [#Rule 84 + [#Rule 76 'element_list2', 0, undef ], - [#Rule 85 + [#Rule 77 'element_list2', 1, undef ], - [#Rule 86 + [#Rule 78 'element_list2', 1, sub -#line 309 "idl.yp" +#line 275 "idl.yp" { [ $_[1] ] } ], - [#Rule 87 + [#Rule 79 'element_list2', 3, sub -#line 310 "idl.yp" +#line 276 "idl.yp" { push(@{$_[1]}, $_[3]); $_[1] } ], - [#Rule 88 + [#Rule 80 'array_len', 0, undef ], - [#Rule 89 + [#Rule 81 'array_len', 3, sub -#line 315 "idl.yp" +#line 281 "idl.yp" { push(@{$_[3]}, "*"); $_[3] } ], - [#Rule 90 + [#Rule 82 'array_len', 4, sub -#line 316 "idl.yp" +#line 282 "idl.yp" { push(@{$_[4]}, "$_[2]"); $_[4] } ], - [#Rule 91 + [#Rule 83 'property_list', 0, undef ], - [#Rule 92 + [#Rule 84 'property_list', 4, sub -#line 322 "idl.yp" +#line 288 "idl.yp" { FlattenHash([$_[1],$_[3]]); } ], - [#Rule 93 + [#Rule 85 'properties', 1, sub -#line 325 "idl.yp" +#line 291 "idl.yp" { $_[1] } ], - [#Rule 94 + [#Rule 86 'properties', 3, sub -#line 326 "idl.yp" +#line 292 "idl.yp" { FlattenHash([$_[1], $_[3]]); } ], - [#Rule 95 + [#Rule 87 'property', 1, sub -#line 329 "idl.yp" +#line 295 "idl.yp" {{ "$_[1]" => "1" }} ], - [#Rule 96 + [#Rule 88 'property', 4, sub -#line 330 "idl.yp" +#line 296 "idl.yp" {{ "$_[1]" => "$_[3]" }} ], - [#Rule 97 + [#Rule 89 'listtext', 1, undef ], - [#Rule 98 + [#Rule 90 'listtext', 3, sub -#line 335 "idl.yp" +#line 301 "idl.yp" { "$_[1] $_[3]" } ], - [#Rule 99 + [#Rule 91 'commalisttext', 1, undef ], - [#Rule 100 + [#Rule 92 'commalisttext', 3, sub -#line 340 "idl.yp" +#line 306 "idl.yp" { "$_[1],$_[3]" } ], - [#Rule 101 + [#Rule 93 'anytext', 0, sub -#line 344 "idl.yp" +#line 310 "idl.yp" { "" } ], - [#Rule 102 + [#Rule 94 'anytext', 1, undef ], - [#Rule 103 + [#Rule 95 'anytext', 1, undef ], - [#Rule 104 + [#Rule 96 'anytext', 1, undef ], - [#Rule 105 + [#Rule 97 'anytext', 3, sub -#line 346 "idl.yp" +#line 312 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 106 + [#Rule 98 'anytext', 3, sub -#line 347 "idl.yp" +#line 313 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 107 + [#Rule 99 'anytext', 3, sub -#line 348 "idl.yp" +#line 314 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 108 + [#Rule 100 'anytext', 3, sub -#line 349 "idl.yp" +#line 315 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 109 + [#Rule 101 'anytext', 3, sub -#line 350 "idl.yp" +#line 316 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 110 + [#Rule 102 'anytext', 3, sub -#line 351 "idl.yp" +#line 317 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 111 + [#Rule 103 'anytext', 3, sub -#line 352 "idl.yp" +#line 318 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 112 + [#Rule 104 'anytext', 3, sub -#line 353 "idl.yp" +#line 319 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 113 + [#Rule 105 'anytext', 3, sub -#line 354 "idl.yp" +#line 320 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 114 + [#Rule 106 'anytext', 3, sub -#line 355 "idl.yp" +#line 321 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 115 + [#Rule 107 'anytext', 3, sub -#line 356 "idl.yp" +#line 322 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 116 + [#Rule 108 'anytext', 3, sub -#line 357 "idl.yp" +#line 323 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 117 + [#Rule 109 'anytext', 3, sub -#line 358 "idl.yp" +#line 324 "idl.yp" { "$_[1]$_[2]$_[3]" } ], - [#Rule 118 + [#Rule 110 'anytext', 5, sub -#line 359 "idl.yp" +#line 325 "idl.yp" { "$_[1]$_[2]$_[3]$_[4]$_[5]" } ], - [#Rule 119 + [#Rule 111 'anytext', 5, sub -#line 360 "idl.yp" +#line 326 "idl.yp" { "$_[1]$_[2]$_[3]$_[4]$_[5]" } ], - [#Rule 120 + [#Rule 112 'identifier', 1, undef ], - [#Rule 121 + [#Rule 113 'optional_identifier', 1, undef ], - [#Rule 122 + [#Rule 114 'optional_identifier', 0, undef ], - [#Rule 123 + [#Rule 115 'constant', 1, undef ], - [#Rule 124 + [#Rule 116 'text', 1, sub -#line 374 "idl.yp" +#line 340 "idl.yp" { "\"$_[1]\"" } ], - [#Rule 125 + [#Rule 117 'optional_semicolon', 0, undef ], - [#Rule 126 + [#Rule 118 'optional_semicolon', 1, undef ] ], @@ -2532,7 +2422,7 @@ sub bless($self,$class); } -#line 385 "idl.yp" +#line 351 "idl.yp" use Parse::Pidl qw(error); @@ -2627,7 +2517,7 @@ again: if (s/^([\w_]+)//) { $parser->YYData->{LAST_TOKEN} = $1; if ($1 =~ - /^(coclass|interface|const|typedef|declare|union|cpp_quote + /^(coclass|interface|const|typedef|union|cpp_quote |struct|enum|bitmap|void|unsigned|signed|import|include |importlib)$/x) { return $1; diff --git a/source4/pidl/lib/Parse/Pidl/NDR.pm b/source4/pidl/lib/Parse/Pidl/NDR.pm index f624d2bdc0..fc6bfe4c96 100644 --- a/source4/pidl/lib/Parse/Pidl/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/NDR.pm @@ -35,7 +35,7 @@ use vars qw($VERSION); $VERSION = '0.01'; @ISA = qw(Exporter); @EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsString); -@EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType can_contain_deferred); +@EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType can_contain_deferred is_charset_array); use strict; use Parse::Pidl qw(warning fatal); @@ -287,8 +287,6 @@ sub can_contain_deferred($) return 0 if (Parse::Pidl::Typelist::is_scalar($type)); - return 1 if ($type->{TYPE} eq "DECLARE"); # assume the worst - return can_contain_deferred($type->{DATA}) if ($type->{TYPE} eq "TYPEDEF"); return 0 unless defined($type->{ELEMENTS}); @@ -354,21 +352,25 @@ sub align_type($) return $scalar_alignment->{$e->{NAME}}; } + return 0 if ($e eq "EMPTY"); + unless (hasType($e)) { # it must be an external type - all we can do is guess - # print "Warning: assuming alignment of unknown type '$e' is 4\n"; + # warning($e, "assuming alignment of unknown type '$e' is 4"); return 4; } my $dt = getType($e); - if ($dt->{TYPE} eq "TYPEDEF" or $dt->{TYPE} eq "DECLARE") { + if ($dt->{TYPE} eq "TYPEDEF") { return align_type($dt->{DATA}); } elsif ($dt->{TYPE} eq "ENUM") { return align_type(Parse::Pidl::Typelist::enum_type_fn($dt)); } elsif ($dt->{TYPE} eq "BITMAP") { return align_type(Parse::Pidl::Typelist::bitmap_type_fn($dt)); } elsif (($dt->{TYPE} eq "STRUCT") or ($dt->{TYPE} eq "UNION")) { + # Struct/union without body: assume 4 + return 4 unless (defined($dt->{ELEMENTS})); return find_largest_alignment($dt); } @@ -631,7 +633,7 @@ sub FindNestedTypes($$) sub FindNestedTypes($$); my ($l, $t) = @_; - return if not defined($t->{ELEMENTS}); + return unless defined($t->{ELEMENTS}); return if ($t->{TYPE} eq "ENUM"); return if ($t->{TYPE} eq "BITMAP"); @@ -650,7 +652,6 @@ sub ParseInterface($) my @consts = (); my @functions = (); my @endpoints; - my @declares = (); my $opnum = 0; my $version; @@ -667,9 +668,7 @@ sub ParseInterface($) } foreach my $d (@{$idl->{DATA}}) { - if ($d->{TYPE} eq "DECLARE") { - push (@declares, $d); - } elsif ($d->{TYPE} eq "FUNCTION") { + if ($d->{TYPE} eq "FUNCTION") { push (@functions, ParseFunction($idl, $d, \$opnum)); } elsif ($d->{TYPE} eq "CONST") { push (@consts, ParseConst($idl, $d)); @@ -701,7 +700,6 @@ sub ParseInterface($) FUNCTIONS => \@functions, CONSTS => \@consts, TYPES => \@types, - DECLARES => \@declares, ENDPOINTS => \@endpoints }; } @@ -1183,4 +1181,19 @@ sub Validate($) } } +sub is_charset_array($$) +{ + my ($e,$l) = @_; + + return 0 if ($l->{TYPE} ne "ARRAY"); + + my $nl = GetNextLevel($e,$l); + + return 0 unless ($nl->{TYPE} eq "DATA"); + + return has_property($e, "charset"); +} + + + 1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index b7372a802a..86b8951026 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 Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(GenerateFunctionInEnv ParseFunction $res $res_hdr); +@EXPORT_OK = qw(ParseFunction $res $res_hdr); use strict; use Parse::Pidl qw(fatal warning); @@ -17,7 +17,7 @@ use Parse::Pidl::Typelist qw(hasType getType mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(has_property is_constant ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); use Parse::Pidl::Samba4 qw(DeclLong); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionInEnv); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv); use vars qw($VERSION); $VERSION = '0.01'; diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index 47312bc83d..ca9e7d15db 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -6,13 +6,17 @@ package Parse::Pidl::Samba3::ServerNDR; +use Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(DeclLevel); + use strict; use Parse::Pidl qw(warning fatal); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); use Parse::Pidl::Util qw(ParseExpr has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Samba4 qw(ElementStars DeclLong); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionOutEnv); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionOutEnv); use vars qw($VERSION); $VERSION = '0.01'; diff --git a/source4/pidl/lib/Parse/Pidl/Samba4.pm b/source4/pidl/lib/Parse/Pidl/Samba4.pm index 5848543a60..d42e01cdb0 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4.pm @@ -12,6 +12,7 @@ require Exporter; use Parse::Pidl::Util qw(has_property is_constant); use Parse::Pidl::NDR qw(GetNextLevel); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); +use Parse::Pidl qw(fatal); use strict; use vars qw($VERSION); diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm index 2e9bc0953c..efb3f2858d 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/EJS.pm @@ -8,13 +8,14 @@ package Parse::Pidl::Samba4::EJS; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(get_pointer_to get_value_of check_null_pointer fn_declare TypeFunctionName); +@EXPORT_OK = qw(check_null_pointer fn_declare TypeFunctionName); use strict; -use Parse::Pidl::Typelist; +use Parse::Pidl::Typelist qw(typeHasBody); +use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); use Parse::Pidl::Util qw(has_property ParseExpr); use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateStructEnv GenerateFunctionInEnv +use Parse::Pidl::Samba4::Header qw(GenerateStructEnv GenerateFunctionInEnv GenerateFunctionOutEnv); use vars qw($VERSION); @@ -54,30 +55,6 @@ sub deindent($) $self->{tabs} = substr($self->{tabs}, 0, -1); } -sub get_pointer_to($) -{ - my $var_name = shift; - - if ($var_name =~ /^\*(.*)$/) { - return $1; - } elsif ($var_name =~ /^\&(.*)$/) { - return "&($var_name)"; - } else { - return "&$var_name"; - } -} - -sub get_value_of($) -{ - my $var_name = shift; - - if ($var_name =~ /^\&(.*)$/) { - return $1; - } else { - return "*$var_name"; - } -} - ##################################################################### # check that a variable we get from ParseExpr isn't a null pointer sub check_null_pointer($$) @@ -297,6 +274,7 @@ sub EjsUnionPull($$$) sub EjsEnumConstant($$) { my ($self, $d) = @_; + return unless (defined($d->{ELEMENTS})); my $v = 0; foreach my $e (@{$d->{ELEMENTS}}) { my $el = $e; @@ -595,6 +573,7 @@ sub EjsEnumPush($$$) sub EjsBitmapPush($$$) { my ($self, $d, $varname) = @_; + return unless (defined($d->{ELEMENTS})); my $type_fn = $d->{BASE_TYPE}; # put the bitmap elements in the constants array foreach my $e (@{$d->{ELEMENTS}}) { @@ -733,6 +712,7 @@ sub EjsInterface($$$) $self->pidl_hdr("\n"); foreach my $d (@{$interface->{TYPES}}) { + next unless (typeHasBody($d)); ($needed->{TypeFunctionName("ejs_push", $d)}) && $self->EjsTypePushFunction($d, $d->{NAME}); ($needed->{TypeFunctionName("ejs_pull", $d)}) && $self->EjsTypePullFunction($d, $d->{NAME}); } @@ -846,8 +826,9 @@ sub NeededType($$$) NeededType($t->{DATA}, $needed, $req) if ($t->{TYPE} eq "TYPEDEF"); - return if (($t->{TYPE} ne "STRUCT") and - ($t->{TYPE} ne "UNION")); + return unless (($t->{TYPE} eq "STRUCT") or ($t->{TYPE} eq "UNION")); + + return unless(typeHasBody($t)); foreach (@{$t->{ELEMENTS}}) { next if (has_property($_, "subcontext")); #FIXME: Support subcontexts @@ -883,7 +864,7 @@ sub TypeFunctionName($$) my ($prefix, $t) = @_; return "$prefix\_$t->{NAME}" if (ref($t) eq "HASH" and - ($t->{TYPE} eq "TYPEDEF" or $t->{TYPE} eq "DECLARE")); + $t->{TYPE} eq "TYPEDEF"); return "$prefix\_$t->{TYPE}_$t->{NAME}" if (ref($t) eq "HASH"); return "$prefix\_$t"; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm index 7a6ffa46d6..2b3a9df80f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Header.pm @@ -6,10 +6,15 @@ package Parse::Pidl::Samba4::Header; +require Exporter; + +@ISA = qw(Exporter); +@EXPORT_OK = qw(GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv); + use strict; use Parse::Pidl qw(fatal); use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference); -use Parse::Pidl::Util qw(has_property is_constant unmake_str); +use Parse::Pidl::Util qw(has_property is_constant unmake_str ParseExpr); use Parse::Pidl::Samba4 qw(is_intree ElementStars ArrayBrackets choose_header); use vars qw($VERSION); @@ -107,47 +112,49 @@ sub HeaderEnum($$) my($enum,$name) = @_; my $first = 1; - pidl "#ifndef USE_UINT_ENUMS\n"; - pidl "enum $name {\n"; - $tab_depth++; + pidl "enum $name"; if (defined($enum->{ELEMENTS})) { + pidl "\n#ifndef USE_UINT_ENUMS\n"; + pidl " {\n"; + $tab_depth++; foreach my $e (@{$enum->{ELEMENTS}}) { unless ($first) { pidl ",\n"; } $first = 0; pidl tabs(); pidl $e; } - } - pidl "\n"; - $tab_depth--; - pidl "}\n"; - pidl "#else\n"; - my $count = 0; - pidl "enum $name { __donnot_use_enum_$name=0x7FFFFFFF}\n"; - my $with_val = 0; - my $without_val = 0; - if (defined($enum->{ELEMENTS})) { - foreach my $e (@{$enum->{ELEMENTS}}) { - my $t = "$e"; - my $name; - my $value; - if ($t =~ /(.*)=(.*)/) { - $name = $1; - $value = $2; - $with_val = 1; - fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!") - unless ($without_val == 0); - } else { - $name = $t; - $value = $count++; - $without_val = 1; - fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!") - unless ($with_val == 0); + pidl "\n"; + $tab_depth--; + pidl "}"; + pidl "\n"; + pidl "#else\n"; + my $count = 0; + my $with_val = 0; + my $without_val = 0; + if (defined($enum->{ELEMENTS})) { + pidl " { __donnot_use_enum_$name=0x7FFFFFFF}\n"; + foreach my $e (@{$enum->{ELEMENTS}}) { + my $t = "$e"; + my $name; + my $value; + if ($t =~ /(.*)=(.*)/) { + $name = $1; + $value = $2; + $with_val = 1; + fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!") + unless ($without_val == 0); + } else { + $name = $t; + $value = $count++; + $without_val = 1; + fatal($e->{ORIGINAL}, "you can't mix enum member with values and without values!") + unless ($with_val == 0); + } + pidl "#define $name ( $value )\n"; } - pidl "#define $name ( $value )\n"; } + pidl "#endif\n"; } - pidl "#endif\n"; } ##################################################################### @@ -215,7 +222,7 @@ sub HeaderType($$$) sub HeaderTypedef($) { my($typedef) = shift; - HeaderType($typedef, $typedef->{DATA}, $typedef->{NAME}); + HeaderType($typedef, $typedef->{DATA}, $typedef->{NAME}) if defined ($typedef->{DATA}); } ##################################################################### @@ -404,4 +411,66 @@ sub Parse($) return $res; } +sub GenerateStructEnv($$) +{ + my ($x, $v) = @_; + my %env; + + foreach my $e (@{$x->{ELEMENTS}}) { + $env{$e->{NAME}} = "$v->$e->{NAME}"; + } + + $env{"this"} = $v; + + return \%env; +} + +sub EnvSubstituteValue($$) +{ + my ($env,$s) = @_; + + # Substitute the value() values in the env + foreach my $e (@{$s->{ELEMENTS}}) { + next unless (defined(my $v = has_property($e, "value"))); + + $env->{$e->{NAME}} = ParseExpr($v, $env, $e); + } + + return $env; +} + +sub GenerateFunctionInEnv($;$) +{ + my ($fn, $base) = @_; + my %env; + + $base = "r->" unless defined($base); + + foreach my $e (@{$fn->{ELEMENTS}}) { + if (grep (/in/, @{$e->{DIRECTION}})) { + $env{$e->{NAME}} = $base."in.$e->{NAME}"; + } + } + + return \%env; +} + +sub GenerateFunctionOutEnv($;$) +{ + my ($fn, $base) = @_; + my %env; + + $base = "r->" unless defined($base); + + foreach my $e (@{$fn->{ELEMENTS}}) { + if (grep (/out/, @{$e->{DIRECTION}})) { + $env{$e->{NAME}} = $base."out.$e->{NAME}"; + } elsif (grep (/in/, @{$e->{DIRECTION}})) { + $env{$e->{NAME}} = $base."in.$e->{NAME}"; + } + } + + return \%env; +} + 1; diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index c9b48b017c..02d3a80992 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -9,13 +9,15 @@ package Parse::Pidl::Samba4::NDR::Parser; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv NeededFunction NeededElement NeededType $res NeededInterface TypeFunctionName ParseElementPrint); +@EXPORT_OK = qw(check_null_pointer NeededFunction NeededElement NeededType $res NeededInterface TypeFunctionName ParseElementPrint); use strict; -use Parse::Pidl::Typelist qw(hasType getType mapTypeName); +use Parse::Pidl::Typelist qw(hasType getType mapTypeName typeHasBody); use Parse::Pidl::Util qw(has_property ParseExpr ParseExprExt print_uuid); -use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred); +use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred is_charset_array); use Parse::Pidl::Samba4 qw(is_intree choose_header); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv); use Parse::Pidl qw(warning); use vars qw($VERSION); @@ -76,42 +78,6 @@ sub has_fast_array($$) return ($t->{NAME} eq "uint8") or ($t->{NAME} eq "string"); } -sub is_charset_array($$) -{ - my ($e,$l) = @_; - - return 0 if ($l->{TYPE} ne "ARRAY"); - - my $nl = GetNextLevel($e,$l); - - return 0 unless ($nl->{TYPE} eq "DATA"); - - return has_property($e, "charset"); -} - -sub get_pointer_to($) -{ - my $var_name = shift; - - if ($var_name =~ /^\*(.*)$/) { - return $1; - } elsif ($var_name =~ /^\&(.*)$/) { - return "&($var_name)"; - } else { - return "&$var_name"; - } -} - -sub get_value_of($) -{ - my $var_name = shift; - - if ($var_name =~ /^\&(.*)$/) { - return $1; - } else { - return "*$var_name"; - } -} #################################### # pidl() is our basic output routine @@ -215,68 +181,6 @@ sub end_flags($$) } } -sub GenerateStructEnv($$) -{ - my ($x, $v) = @_; - my %env; - - foreach my $e (@{$x->{ELEMENTS}}) { - $env{$e->{NAME}} = "$v->$e->{NAME}"; - } - - $env{"this"} = $v; - - return \%env; -} - -sub EnvSubstituteValue($$) -{ - my ($env,$s) = @_; - - # Substitute the value() values in the env - foreach my $e (@{$s->{ELEMENTS}}) { - next unless (defined(my $v = has_property($e, "value"))); - - $env->{$e->{NAME}} = ParseExpr($v, $env, $e); - } - - return $env; -} - -sub GenerateFunctionInEnv($;$) -{ - my ($fn, $base) = @_; - my %env; - - $base = "r->" unless defined($base); - - foreach my $e (@{$fn->{ELEMENTS}}) { - if (grep (/in/, @{$e->{DIRECTION}})) { - $env{$e->{NAME}} = $base."in.$e->{NAME}"; - } - } - - return \%env; -} - -sub GenerateFunctionOutEnv($;$) -{ - my ($fn, $base) = @_; - my %env; - - $base = "r->" unless defined($base); - - foreach my $e (@{$fn->{ELEMENTS}}) { - if (grep (/out/, @{$e->{DIRECTION}})) { - $env{$e->{NAME}} = $base."out.$e->{NAME}"; - } elsif (grep (/in/, @{$e->{DIRECTION}})) { - $env{$e->{NAME}} = $base."in.$e->{NAME}"; - } - } - - return \%env; -} - ##################################################################### # parse the data of an array - push side sub ParseArrayPushHeader($$$$$$) @@ -2565,6 +2469,8 @@ sub ParseInterface($$$) # Typedefs foreach my $d (@{$interface->{TYPES}}) { + next unless(typeHasBody($d)); + ($needed->{TypeFunctionName("ndr_push", $d)}) && $self->ParseTypePushFunction($d, "r"); ($needed->{TypeFunctionName("ndr_pull", $d)}) && $self->ParseTypePullFunction($d, "r"); ($needed->{TypeFunctionName("ndr_print", $d)}) && $self->ParseTypePrintFunction($d, "r"); @@ -2708,6 +2614,7 @@ sub NeededType($$$) NeededType($t->{DATA}, $needed, $req) if ($t->{TYPE} eq "TYPEDEF"); if ($t->{TYPE} eq "STRUCT" or $t->{TYPE} eq "UNION") { + return unless defined($t->{ELEMENTS}); for my $e (@{$t->{ELEMENTS}}) { $e->{PARENT} = $t; if (has_property($e, "compression")) { @@ -2745,7 +2652,7 @@ sub TypeFunctionName($$) my ($prefix, $t) = @_; return "$prefix\_$t->{NAME}" if (ref($t) eq "HASH" and - ($t->{TYPE} eq "TYPEDEF" or $t->{TYPE} eq "DECLARE")); + $t->{TYPE} eq "TYPEDEF"); return "$prefix\_$t->{TYPE}_$t->{NAME}" if (ref($t) eq "HASH"); return "$prefix\_$t"; } diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 8effff9d5e..2475925377 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -1,6 +1,6 @@ ################################################### # Python function wrapper generator -# Copyright jelmer@samba.org 2007 +# Copyright jelmer@samba.org 2007-2008 # released under the GNU GPL package Parse::Pidl::Samba4::Python; @@ -9,15 +9,19 @@ use Exporter; @ISA = qw(Exporter); use strict; -use Parse::Pidl::Typelist; +use Parse::Pidl::Typelist qw(hasType resolveType getType mapTypeName expandAlias); use Parse::Pidl::Util qw(has_property ParseExpr); +use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred is_charset_array); +use Parse::Pidl::CUtil qw(get_value_of get_pointer_to); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv); use vars qw($VERSION); $VERSION = '0.01'; sub new($) { my ($class) = @_; - my $self = { res => "", res_hdr => "", tabs => "", constants => {}}; + my $self = { res => "", res_hdr => "", tabs => "", constants => {}, + module_methods => []}; bless($self, $class); } @@ -63,121 +67,371 @@ sub Import sub Const($$) { my ($self, $const) = @_; - $self->{constants}->{$const->{NAME}} = [$const->{DATA}->{TYPE}, $const->{VALUE}]; + $self->register_constant($const->{NAME}, $const->{DTYPE}, $const->{VALUE}); } -sub FromTypeToPythonFunction($$) +sub register_constant($$$$) { - my ($self, $type) = @_; + my ($self, $name, $type, $value) = @_; - #FIXME + $self->{constants}->{$name} = [$type, $value]; } -sub FromPythonToTypeFunction($$) +sub EnumAndBitmapConsts($$$) { - my ($self, $type) = @_; + my ($self, $name, $d) = @_; - #FIXME + return unless (defined($d->{ELEMENTS})); + + foreach my $e (@{$d->{ELEMENTS}}) { + $e =~ /^([A-Za-z0-9_]+)/; + my $cname = $1; + + $self->register_constant($cname, $d, $cname); + } } -sub TypeConstructor($$) +sub FromUnionToPythonFunction($$$$) { - my ($self, $type) = @_; + my ($self, $mem_ctx, $type, $switch, $name) = @_; + + $self->pidl("PyObject *ret;"); + $self->pidl(""); - $self->pidl("staticforward PyTypeObject $type->{NAME}_ObjectType;"); - $self->pidl("typedef struct {"); + $self->pidl("switch ($switch) {"); $self->indent; - $self->pidl("PyObject_HEAD"); - $self->pidl("void *object;"); # FIXME: Use real type rather than void + + foreach my $e (@{$type->{ELEMENTS}}) { + $self->pidl("$e->{CASE}:"); + + $self->indent; + + if ($e->{NAME}) { + $self->ConvertObjectToPython($mem_ctx, {}, $e, "$name->$e->{NAME}", "ret"); + } else { + $self->pidl("ret = Py_None;"); + } + + $self->pidl("return ret;"); + $self->pidl(""); + + $self->deindent; + } + $self->deindent; - $self->pidl("} $type->{NAME}_Object;"); + $self->pidl("}"); - $self->pidl(""); + $self->pidl("PyErr_SetString(PyExc_TypeError, \"unknown union level\");"); + $self->pidl("return NULL;"); +} - $self->pidl("static PyObject *py_$type->{NAME}_getattr(PyTypeObject *obj, char *name)"); - $self->pidl("{"); +sub FromPythonToUnionFunction($$$$$) +{ + my ($self, $type, $typename, $switch, $mem_ctx, $name) = @_; + + my $has_default = 0; + + $self->pidl("$typename *ret = talloc_zero($mem_ctx, $typename);"); + + $self->pidl("switch ($switch) {"); $self->indent; - $self->pidl("return Py_None;"); + + foreach my $e (@{$type->{ELEMENTS}}) { + $self->pidl("$e->{CASE}:"); + if ($e->{CASE} eq "default") { $has_default = 1; } + $self->indent; + if ($e->{NAME}) { + $self->ConvertObjectFromPython({}, $mem_ctx, $e, $name, "ret->$e->{NAME}", "talloc_free(ret); return NULL;"); + } + $self->pidl("break;"); + $self->deindent; + $self->pidl(""); + } + + if (!$has_default) { + $self->pidl("default:"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_TypeError, \"invalid union level value\");"); + $self->pidl("talloc_free(ret);"); + $self->pidl("ret = NULL;"); + $self->deindent; + } + $self->deindent; $self->pidl("}"); $self->pidl(""); + $self->pidl("return ret;"); +} + +sub PythonStruct($$$$) +{ + my ($self, $name, $cname, $d) = @_; + + my $env = GenerateStructEnv($d, "object"); + + $self->pidl(""); - $self->pidl("static void py_$type->{NAME}_dealloc(PyObject* self)"); + $self->pidl("static PyObject *py_$name\_getattr(PyObject *obj, char *name)"); $self->pidl("{"); $self->indent; - $self->pidl("$type->{NAME}_Object *obj = ($type->{NAME}_Object *)self;"); - $self->pidl("talloc_free(obj->object);"); - $self->pidl("PyObject_Del(self);"); + if ($#{$d->{ELEMENTS}} > -1) { + $self->pidl("$cname *object = py_talloc_get_ptr(obj);"); + foreach my $e (@{$d->{ELEMENTS}}) { + $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); + my $varname = "object->$e->{NAME}"; + $self->indent; + $self->pidl("PyObject *py_$e->{NAME};"); + $self->ConvertObjectToPython("py_talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}"); + $self->pidl("return py_$e->{NAME};"); + $self->deindent; + $self->pidl("}"); + } + } + $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); + $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *py_$type->{NAME}_setattr(PyTypeObject *obj, char *name, PyObject *value)"); + $self->pidl("static int py_$name\_setattr(PyObject *py_obj, char *name, PyObject *value)"); $self->pidl("{"); $self->indent; - $self->pidl("return Py_None;"); + if ($#{$d->{ELEMENTS}} > -1) { + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); + my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)"; + foreach my $e (@{$d->{ELEMENTS}}) { + $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); + my $varname = "object->$e->{NAME}"; + $self->indent; + my $l = $e->{LEVELS}[0]; + my $nl = GetNextLevel($e, $l); + if ($l->{TYPE} eq "POINTER" and + not ($nl->{TYPE} eq "ARRAY" and ($nl->{IS_FIXED} or is_charset_array($e, $nl))) and + not ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE}))) { + $self->pidl("talloc_free($varname);"); + } + $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); + $self->pidl("return 0;"); + $self->deindent; + $self->pidl("}"); + } + } + $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); + $self->pidl("return -1;"); $self->deindent; $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyTypeObject $type->{NAME}_ObjectType = {"); + $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $name\_Type;\n"); + $self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n"); + $self->pidl_hdr("#define $name\_CheckExact(op) ((op)->ob_type == &$name\_Type)\n"); + $self->pidl_hdr("\n"); + $self->pidl("PyTypeObject $name\_Type = {"); $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); - $self->pidl(".tp_name = \"$type->{NAME}\","); - $self->pidl(".tp_basicsize = sizeof($type->{NAME}_Object),"); - $self->pidl(".tp_dealloc = (destructor)py_$type->{NAME}_dealloc,"); - $self->pidl(".tp_getattr = (getattrfunc)py_$type->{NAME}_getattr,"); - $self->pidl(".tp_setattr = (setattrfunc)py_$type->{NAME}_setattr,"); + $self->pidl(".tp_name = \"$name\","); + $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),"); + $self->pidl(".tp_dealloc = py_talloc_dealloc,"); + $self->pidl(".tp_getattr = py_$name\_getattr,"); + $self->pidl(".tp_setattr = py_$name\_setattr,"); + $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->deindent; $self->pidl("};"); $self->pidl(""); - $self->pidl("static PyObject *py_$type->{NAME}(PyObject *self, PyObject *args)"); + my $py_fnname = "py_$name"; + $self->pidl("static PyObject *$py_fnname(PyObject *self, PyObject *args)"); $self->pidl("{"); $self->indent; - $self->pidl("$type->{NAME}\_Object *ret;"); - $self->pidl("ret = PyObject_New($type->{NAME}_Object, &$type->{NAME}_ObjectType);"); - $self->pidl("return (PyObject *) ret;"); + $self->pidl("$cname *ret = talloc_zero(NULL, $cname);"); + $self->pidl("return py_talloc_import(&$name\_Type, ret);"); $self->deindent; $self->pidl("}"); $self->pidl(""); + + return $py_fnname; } sub PythonFunction($$$) { my ($self, $fn, $iface) = @_; - $self->pidl("static PyObject *py_$fn->{NAME}(PyObject *self, PyObject *args)"); + $self->pidl("static PyObject *py_$fn->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); $self->pidl("NTSTATUS status;"); + $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); + $self->pidl("struct $fn->{NAME} *r = talloc_zero(mem_ctx, struct $fn->{NAME});"); + $self->pidl("PyObject *result = Py_None;"); + + my $env = GenerateFunctionInEnv($fn, "r->"); + my $result_size = 0; + + my $args_format = ""; + my $args_string = ""; + my $args_names = ""; + + foreach my $e (@{$fn->{ELEMENTS}}) { + $self->pidl("PyObject *py_$e->{NAME};"); + if (grep(/out/,@{$e->{DIRECTION}})) { + $result_size++; + } + if (grep(/in/,@{$e->{DIRECTION}})) { + $args_format .= "O"; + $args_string .= ", &py_$e->{NAME}"; + $args_names .= "\"$e->{NAME}\", "; + } + } + $self->pidl("const char *kwnames[] = {"); + $self->indent; + $self->pidl($args_names . "NULL"); + $self->deindent; + $self->pidl("};"); + $self->pidl(""); - # FIXME - $self->handle_ntstatus("status", "NULL"); - $self->pidl("return Py_None;"); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"$args_format:$fn->{NAME}\", discard_const_p(char *, kwnames)$args_string)) {"); + $self->indent; + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + + if ($fn->{RETURN_TYPE}) { + $result_size++ unless ($fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "NTSTATUS"); + } + + foreach my $e (@{$fn->{ELEMENTS}}) { + if (grep(/in/,@{$e->{DIRECTION}})) { + $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); + } + } + $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, r);"); + $self->handle_ntstatus("status", "NULL", "mem_ctx"); + + $env = GenerateFunctionOutEnv($fn, "r->"); + my $i = 0; + + if ($result_size > 1) { + $self->pidl("result = PyTuple_New($result_size);"); + } + + foreach my $e (@{$fn->{ELEMENTS}}) { + my $py_name = "py_$e->{NAME}"; + if (grep(/out/,@{$e->{DIRECTION}})) { + $self->ConvertObjectToPython("r", $env, $e, "r->out.$e->{NAME}", $py_name); + if ($result_size > 1) { + $self->pidl("PyTuple_SetItem(result, $i, $py_name);"); + $i++; + } else { + $self->pidl("result = $py_name;"); + } + } + } + + if (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "NTSTATUS") { + $self->handle_ntstatus("r->out.result", "NULL", "mem_ctx"); + } elsif (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "WERROR") { + $self->handle_werror("r->out.result", "NULL", "mem_ctx"); + } elsif (defined($fn->{RETURN_TYPE})) { + my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result"); + if ($result_size > 1) { + $self->pidl("PyTuple_SetItem(result, $i, $conv);"); + } else { + $self->pidl("result = $conv;"); + } + } + + $self->pidl("talloc_free(mem_ctx);"); + $self->pidl("return result;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); +} + +sub handle_werror($$$$) +{ + my ($self, $var, $retval, $mem_ctx) = @_; + + $self->pidl("if (!W_ERROR_IS_OK($var)) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, win_errstr($var));"); + $self->pidl("talloc_free($mem_ctx);") if ($mem_ctx); + $self->pidl("return $retval;"); $self->deindent; $self->pidl("}"); $self->pidl(""); } -sub handle_ntstatus($$$) +sub handle_ntstatus($$$$) { - my ($self, $var, $retval) = @_; + my ($self, $var, $retval, $mem_ctx) = @_; $self->pidl("if (NT_STATUS_IS_ERR($var)) {"); $self->indent; $self->pidl("PyErr_SetString(PyExc_RuntimeError, nt_errstr($var));"); + $self->pidl("talloc_free($mem_ctx);") if ($mem_ctx); $self->pidl("return $retval;"); $self->deindent; $self->pidl("}"); $self->pidl(""); } -sub Interface($$) +sub PythonType($$$) { - my($self,$interface) = @_; + my ($self, $d, $interface, $basename) = @_; + + my $actual_ctype = $d; + if ($actual_ctype->{TYPE} eq "TYPEDEF") { + $actual_ctype = $actual_ctype->{DATA}; + } + + if ($actual_ctype->{TYPE} eq "STRUCT") { + my $py_fnname; + if ($d->{TYPE} eq "STRUCT") { + $py_fnname = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d); + } else { + $py_fnname = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d->{DATA}); + } + + my $fn_name = $d->{NAME}; + + $fn_name =~ s/^$interface->{NAME}_//; + $fn_name =~ s/^$basename\_//; + + $self->register_module_method($fn_name, $py_fnname, "METH_NOARGS", "NULL"); + } + + if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP") { + $self->EnumAndBitmapConsts($d->{NAME}, $d); + } + + if ($d->{TYPE} eq "TYPEDEF" and ($d->{DATA}->{TYPE} eq "ENUM" or $d->{DATA}->{TYPE} eq "BITMAP")) { + $self->EnumAndBitmapConsts($d->{NAME}, $d->{DATA}); + } + + if ($actual_ctype->{TYPE} eq "UNION" and defined($actual_ctype->{ELEMENTS})) { + $self->pidl("PyObject *py_import_$d->{NAME}(TALLOC_CTX *mem_ctx, int level, " .mapTypeName($d) . " *in)"); + $self->pidl("{"); + $self->indent; + $self->FromUnionToPythonFunction("mem_ctx", $actual_ctype, "level", "in") if ($actual_ctype->{TYPE} eq "UNION"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + + $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, int level, PyObject *in)"); + $self->pidl("{"); + $self->indent; + $self->FromPythonToUnionFunction($actual_ctype, mapTypeName($d), "level", "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + } +} + +sub Interface($$$) +{ + my($self,$interface,$basename) = @_; $self->pidl_hdr("#ifndef _HEADER_PYTHON_$interface->{NAME}\n"); $self->pidl_hdr("#define _HEADER_PYTHON_$interface->{NAME}\n\n"); @@ -186,108 +440,454 @@ sub Interface($$) $self->Const($_) foreach (@{$interface->{CONSTS}}); - foreach (@{$interface->{TYPES}}) { - $self->FromTypeToPythonFunction($_); - $self->FromPythonToTypeFunction($_); - $self->TypeConstructor($_); + foreach my $d (@{$interface->{TYPES}}) { + next if has_property($d, "nopython"); + + $self->PythonType($d, $interface, $basename); } - $self->pidl("staticforward PyTypeObject $interface->{NAME}_InterfaceType;"); - $self->pidl("typedef struct {"); - $self->indent; - $self->pidl("PyObject_HEAD"); - $self->pidl("struct dcerpc_pipe *pipe;"); - $self->deindent; - $self->pidl("} $interface->{NAME}_InterfaceObject;"); + if (defined $interface->{PROPERTIES}->{uuid}) { + $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $interface->{NAME}_InterfaceType;\n"); + $self->pidl("typedef struct {"); + $self->indent; + $self->pidl("PyObject_HEAD"); + $self->pidl("struct dcerpc_pipe *pipe;"); + $self->deindent; + $self->pidl("} $interface->{NAME}_InterfaceObject;"); - $self->pidl(""); + $self->pidl(""); - foreach my $d (@{$interface->{FUNCTIONS}}) { - next if not defined($d->{OPNUM}); - next if has_property($d, "nopython"); + foreach my $d (@{$interface->{FUNCTIONS}}) { + next if not defined($d->{OPNUM}); + next if has_property($d, "nopython"); + + $self->PythonFunction($d, $interface->{NAME}); + } + + $self->pidl("static PyMethodDef interface_$interface->{NAME}\_methods[] = {"); + $self->indent; + foreach my $d (@{$interface->{FUNCTIONS}}) { + next if not defined($d->{OPNUM}); + next if has_property($d, "nopython"); - $self->PythonFunction($d, $interface->{NAME}); + my $fn_name = $d->{NAME}; + + $fn_name =~ s/^$interface->{NAME}_//; + $fn_name =~ s/^$basename\_//; + + $self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); + } + $self->pidl("{ NULL, NULL, 0, NULL }"); + $self->deindent; + $self->pidl("};"); + $self->pidl(""); + + $self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$interface->{NAME}_InterfaceObject *interface = ($interface->{NAME}_InterfaceObject *)self;"); + $self->pidl("talloc_free(interface->pipe);"); + $self->pidl("PyObject_Del(self);"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + + $self->pidl("static PyObject *interface_$interface->{NAME}_getattr(PyObject *obj, char *name)"); + $self->pidl("{"); + $self->indent; + $self->pidl("return Py_FindMethod(interface_$interface->{NAME}\_methods, obj, name);"); + $self->deindent; + $self->pidl("}"); + + $self->pidl(""); + + $self->pidl("PyTypeObject $interface->{NAME}_InterfaceType = {"); + $self->indent; + $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); + $self->pidl(".tp_name = \"$interface->{NAME}\","); + $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); + $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); + $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,"); + $self->deindent; + $self->pidl("};"); + + $self->pidl(""); + + $self->register_module_method($interface->{NAME}, "interface_$interface->{NAME}", "METH_VARARGS|METH_KEYWORDS", "NULL"); + $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); + $self->pidl("const char *binding_string;"); + $self->pidl("struct cli_credentials *credentials;"); + $self->pidl("struct loadparm_context *lp_ctx = NULL;"); + $self->pidl("PyObject *py_lp_ctx = NULL, *py_credentials = Py_None;"); + $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); + $self->pidl("NTSTATUS status;"); + $self->pidl(""); + $self->pidl("const char *kwnames[] = {"); + $self->indent; + $self->pidl("\"binding\", \"lp_ctx\", \"credentials\", NULL"); + $self->deindent; + $self->pidl("};"); + $self->pidl("extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);"); + $self->pidl("extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);"); + $self->pidl(""); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"sO|O:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {"); + $self->indent; + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("if (py_lp_ctx != NULL) {"); + $self->indent; + $self->pidl("lp_ctx = lp_from_py_object(py_lp_ctx);"); + $self->pidl("if (lp_ctx == NULL) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected loadparm context\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + + $self->pidl("credentials = cli_credentials_from_py_object(py_credentials);"); + $self->pidl("if (credentials == NULL) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_TypeError, \"Expected credentials\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + + $self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);"); + $self->pidl(""); + + $self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, "); + $self->pidl(" &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);"); + $self->handle_ntstatus("status", "NULL", "mem_ctx"); + + $self->pidl("ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;"); + + $self->pidl("return (PyObject *)ret;"); + $self->deindent; + $self->pidl("}"); + + $self->pidl(""); } - $self->pidl("static PyMethodDef interface_$interface->{NAME}\_methods[] = {"); - $self->indent; - foreach my $d (@{$interface->{FUNCTIONS}}) { - next if not defined($d->{OPNUM}); - next if has_property($d, "nopython"); + $self->pidl_hdr("\n"); + $self->pidl_hdr("#endif /* _HEADER_NDR_$interface->{NAME} */\n"); +} - my $fn_name = $d->{NAME}; +sub register_module_method($$$$$) +{ + my ($self, $fn_name, $pyfn_name, $flags, $doc) = @_; - $fn_name =~ s/^$interface->{NAME}_//; + push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) +} - $self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); +sub assign($$$) +{ + my ($self, $dest, $src) = @_; + if ($dest =~ /^\&/) { + $self->pidl("memcpy($dest, $src, sizeof(" . get_value_of($dest) . "));"); + } else { + $self->pidl("$dest = $src;"); } - $self->pidl("{ NULL, NULL, 0, NULL }"); - $self->deindent; - $self->pidl("};"); - $self->pidl(""); +} - $self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)"); - $self->pidl("{"); - $self->indent; - $self->pidl("$interface->{NAME}_InterfaceObject *interface = ($interface->{NAME}_InterfaceObject *)self;"); - $self->pidl("talloc_free(interface->pipe);"); - $self->pidl("PyObject_Del(self);"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); +sub ConvertObjectFromPythonData($$$$$$) +{ + my ($self, $mem_ctx, $cvar, $ctype, $target, $fail) = @_; - $self->pidl("static PyObject *interface_$interface->{NAME}_getattr(PyTypeObject *obj, char *name)"); - $self->pidl("{"); - $self->indent; - $self->pidl("return Py_FindMethod(interface_$interface->{NAME}\_methods, (PyObject *)obj, name);"); - $self->deindent; - $self->pidl("}"); + die("undef type for $cvar") unless(defined($ctype)); - $self->pidl(""); + $ctype = resolveType($ctype); - $self->pidl("static PyTypeObject $interface->{NAME}_InterfaceType = {"); - $self->indent; - $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); - $self->pidl(".tp_name = \"$interface->{NAME}\","); - $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); - $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); - $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,"); - $self->deindent; - $self->pidl("};"); + my $actual_ctype = $ctype; + if ($ctype->{TYPE} eq "TYPEDEF") { + $actual_ctype = $ctype->{DATA}; + } - $self->pidl(""); + if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or + $actual_ctype->{TYPE} eq "SCALAR" and ( + expandAlias($actual_ctype->{NAME}) =~ /^(u?int[0-9]*|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong|udlongr)$/)) { + $self->pidl("PY_CHECK_TYPE(PyInt, $cvar, $fail);"); + $self->pidl("$target = PyInt_AsLong($cvar);"); + return; + } - $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args)"); - $self->pidl("{"); - $self->indent; - $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); - $self->pidl("const char *binding_string;"); - $self->pidl("struct cli_credentials *credentials;"); - $self->pidl("struct loadparm_context *lp_ctx;"); - $self->pidl("NTSTATUS status;"); - $self->pidl(""); + if ($actual_ctype->{TYPE} eq "STRUCT") { + $self->pidl("PY_CHECK_TYPE($ctype->{NAME}, $cvar, $fail);"); + $self->assign($target, "py_talloc_get_ptr($cvar)"); + return; + } - # FIXME: Arguments: binding string, credentials, loadparm context - $self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);"); - $self->pidl(""); + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "DATA_BLOB") { + $self->pidl("$target = data_blob_talloc($mem_ctx, PyString_AsString($cvar), PyString_Size($cvar));"); + return; + } - $self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, "); - $self->pidl(" &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);"); - $self->handle_ntstatus("status", "NULL"); + if ($actual_ctype->{TYPE} eq "SCALAR" and + ($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string" or $actual_ctype->{NAME} eq "nbt_name" or $actual_ctype->{NAME} eq "wrepl_nbt_name")) { + $self->pidl("$target = talloc_strdup($mem_ctx, PyString_AsString($cvar));"); + return; + } - $self->pidl("return (PyObject *)ret;"); - $self->deindent; - $self->pidl("}"); + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") { + $self->pidl("$target = PyString_AsString($cvar);"); + return; + } + + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "NTSTATUS") { + $self->pidl("$target = NT_STATUS(PyInt_AsLong($cvar));"); + return; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "WERROR") { + $self->pidl("$target = W_ERROR(PyInt_AsLong($cvar));"); + return; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "string_array") { + $self->pidl("$target = PyCObject_AsVoidPtr($cvar);"); + return; + } + + if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "pointer") { + $self->assign($target, "PyCObject_AsVoidPtr($cvar)"); + return; + } + + die("unknown type ".mapTypeName($ctype) . ": $cvar"); + +} + +sub ConvertObjectFromPythonLevel($$$$$$$$) +{ + my ($self, $env, $mem_ctx, $py_var, $e, $l, $var_name, $fail) = @_; + my $nl = GetNextLevel($e, $l); + + if ($l->{TYPE} eq "POINTER") { + if ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) { + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, $nl, $var_name, $fail); + return; + } + if ($l->{POINTER_TYPE} ne "ref") { + $self->pidl("if ($py_var == Py_None) {"); + $self->indent; + $self->pidl("$var_name = NULL;"); + $self->deindent; + $self->pidl("} else {"); + $self->indent; + } + $self->pidl("$var_name = talloc_ptrtype($mem_ctx, $var_name);"); + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, $nl, get_value_of($var_name), $fail); + if ($l->{POINTER_TYPE} ne "ref") { + $self->deindent; + $self->pidl("}"); + } + } elsif ($l->{TYPE} eq "ARRAY") { + my $pl = GetPrevLevel($e, $l); + if ($pl && $pl->{TYPE} eq "POINTER") { + $var_name = get_pointer_to($var_name); + } + + if (is_charset_array($e, $l)) { + $self->pidl("PY_CHECK_TYPE(PyUnicode, $py_var, $fail);"); + # FIXME: Use Unix charset setting rather than utf-8 + $self->pidl($var_name . " = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));"); + } else { + my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; + $self->pidl("PY_CHECK_TYPE(PyList, $py_var, $fail);"); + $self->pidl("{"); + $self->indent; + $self->pidl("int $counter;"); + if (!$l->{IS_FIXED}) { + $self->pidl("$var_name = talloc_array_ptrtype($mem_ctx, $var_name, PyList_Size($py_var));"); + } + $self->pidl("for ($counter = 0; $counter < PyList_Size($py_var); $counter++) {"); + $self->indent; + $self->ConvertObjectFromPythonLevel($env, $var_name, "PyList_GetItem($py_var, $counter)", $e, GetNextLevel($e, $l), $var_name."[$counter]", $fail); + $self->deindent; + $self->pidl("}"); + $self->deindent; + $self->pidl("}"); + } + } elsif ($l->{TYPE} eq "DATA") { + + if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) { + $var_name = get_pointer_to($var_name); + } + $self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail); + } elsif ($l->{TYPE} eq "SWITCH") { + $var_name = get_pointer_to($var_name); + my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); + $self->assign($var_name, "py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var)"); + } elsif ($l->{TYPE} eq "SUBCONTEXT") { + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), $var_name, $fail); + } else { + die("unknown level type $l->{TYPE}"); + } +} + +sub ConvertObjectFromPython($$$$$$$) +{ + my ($self, $env, $mem_ctx, $ctype, $cvar, $target, $fail) = @_; + + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $cvar, $ctype, $ctype->{LEVELS}[0], $target, $fail); +} + +sub ConvertScalarToPython($$$) +{ + my ($self, $ctypename, $cvar) = @_; + + die("expected string for $cvar, not $ctypename") if (ref($ctypename) eq "HASH"); + + $ctypename = expandAlias($ctypename); + + if ($ctypename =~ /^(char|u?int[0-9]*|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) { + return "PyInt_FromLong($cvar)"; + } + + if ($ctypename eq "DATA_BLOB") { + return "PyString_FromStringAndSize((char *)($cvar).data, ($cvar).length)"; + } + + if ($ctypename eq "NTSTATUS") { + return "PyInt_FromLong(NT_STATUS_V($cvar))"; + } + + if ($ctypename eq "WERROR") { + return "PyInt_FromLong(W_ERROR_V($cvar))"; + } + + if (($ctypename eq "string" or $ctypename eq "nbt_string" or $ctypename eq "nbt_name" or $ctypename eq "wrepl_nbt_name")) { + return "PyString_FromString($cvar)"; + } + + # Not yet supported + if ($ctypename eq "string_array") { return "PyCObject_FromVoidPtr($cvar)"; } + if ($ctypename eq "ipv4address") { return "PyString_FromString($cvar)"; } + if ($ctypename eq "pointer") { + return "PyCObject_FromVoidPtr($cvar, talloc_free)"; + } + + die("Unknown scalar type $ctypename"); +} + +sub ConvertObjectToPythonData($$$$$) +{ + my ($self, $mem_ctx, $ctype, $cvar) = @_; + + die("undef type for $cvar") unless(defined($ctype)); + + $ctype = resolveType($ctype); + + my $actual_ctype = $ctype; + if ($ctype->{TYPE} eq "TYPEDEF") { + $actual_ctype = $ctype->{DATA}; + } - $self->pidl(""); + if ($actual_ctype->{TYPE} eq "ENUM") { + return $self->ConvertScalarToPython(Parse::Pidl::Typelist::enum_type_fn($actual_ctype), $cvar); + } elsif ($actual_ctype->{TYPE} eq "BITMAP") { + return $self->ConvertScalarToPython(Parse::Pidl::Typelist::bitmap_type_fn($actual_ctype), $cvar); + } elsif ($actual_ctype->{TYPE} eq "SCALAR") { + return $self->ConvertScalarToPython($actual_ctype->{NAME}, $cvar); + } elsif ($actual_ctype->{TYPE} eq "STRUCT") { + return "py_talloc_import_ex(&$ctype->{NAME}_Type, $mem_ctx, $cvar)"; + } - $self->pidl_hdr("\n"); - $self->pidl_hdr("#endif /* _HEADER_NDR_$interface->{NAME} */\n"); + die("unknown type ".mapTypeName($ctype) . ": $cvar"); } -sub Parse($$$$) +sub ConvertObjectToPythonLevel($$$$$) { - my($self,$basename,$ndr,$hdr) = @_; + my ($self, $mem_ctx, $env, $e, $l, $var_name, $py_var) = @_; + my $nl = GetNextLevel($e, $l); + + if ($l->{TYPE} eq "POINTER") { + if ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) { + $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, $var_name, $py_var); + return; + } + if ($l->{POINTER_TYPE} ne "ref") { + $self->pidl("if ($var_name == NULL) {"); + $self->indent; + $self->pidl("$py_var = Py_None;"); + $self->deindent; + $self->pidl("} else {"); + $self->indent; + } + $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, get_value_of($var_name), $py_var); + if ($l->{POINTER_TYPE} ne "ref") { + $self->deindent; + $self->pidl("}"); + } + } elsif ($l->{TYPE} eq "ARRAY") { + if (is_charset_array($e, $l)) { + $var_name = get_pointer_to($var_name); + # FIXME: Use Unix charset setting rather than utf-8 + $self->pidl("$py_var = PyUnicode_Decode($var_name, strlen($var_name), \"utf-8\", \"ignore\");"); + } else { + my $pl = GetPrevLevel($e, $l); + if ($pl && $pl->{TYPE} eq "POINTER") { + $var_name = get_pointer_to($var_name); + } + + die("No SIZE_IS for array $var_name") unless (defined($l->{SIZE_IS})); + my $length = $l->{SIZE_IS}; + if (defined($l->{LENGTH_IS})) { + $length = $l->{LENGTH_IS}; + } + + $length = ParseExpr($length, $env, $e); + $self->pidl("$py_var = PyList_New($length);"); + $self->pidl("{"); + $self->indent; + my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; + $self->pidl("int $counter;"); + $self->pidl("for ($counter = 0; $counter < $length; $counter++) {"); + $self->indent; + my $member_var = "py_$e->{NAME}_$l->{LEVEL_INDEX}"; + $self->pidl("PyObject *$member_var;"); + $self->ConvertObjectToPythonLevel($var_name, $env, $e, GetNextLevel($e, $l), $var_name."[$counter]", $member_var); + $self->pidl("PyList_SetItem($py_var, $counter, $member_var);"); + $self->deindent; + $self->pidl("}"); + $self->deindent; + $self->pidl("}"); + } + } elsif ($l->{TYPE} eq "SWITCH") { + $var_name = get_pointer_to($var_name); + my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); + $self->pidl("$py_var = py_import_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $var_name);"); + } elsif ($l->{TYPE} eq "DATA") { + if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) { + $var_name = get_pointer_to($var_name); + } + my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name); + $self->pidl("$py_var = $conv;"); + } elsif ($l->{TYPE} eq "SUBCONTEXT") { + $self->ConvertObjectToPythonLevel($mem_ctx, $env, $e, GetNextLevel($e, $l), $var_name, $py_var); + } else { + die("Unknown level type $l->{TYPE} $var_name"); + } +} + +sub ConvertObjectToPython($$$$$$) +{ + my ($self, $mem_ctx, $env, $ctype, $cvar, $py_var) = @_; + + $self->ConvertObjectToPythonLevel($mem_ctx, $env, $ctype, $ctype->{LEVELS}[0], $cvar, $py_var); +} + +sub Parse($$$$$) +{ + my($self,$basename,$ndr,$ndr_hdr,$hdr) = @_; my $py_hdr = $hdr; $py_hdr =~ s/ndr_([^\/]+)$/py_$1/g; @@ -299,33 +899,24 @@ sub Parse($$$$) #include \"includes.h\" #include <Python.h> #include \"librpc/rpc/dcerpc.h\" +#include \"scripting/python/pytalloc.h\" +#include \"scripting/python/pyrpc.h\" #include \"$hdr\" +#include \"$ndr_hdr\" #include \"$py_hdr\" "); foreach my $x (@$ndr) { - ($x->{TYPE} eq "INTERFACE") && $self->Interface($x); ($x->{TYPE} eq "IMPORT") && $self->Import(@{$x->{PATHS}}); + ($x->{TYPE} eq "INTERFACE") && $self->Interface($x, $basename); } $self->pidl("static PyMethodDef $basename\_methods[] = {"); $self->indent; - foreach my $x (@$ndr) { - next if ($x->{TYPE} ne "INTERFACE"); - $self->pidl("{ \"$x->{NAME}\", (PyCFunction)interface_$x->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); - - foreach my $d (@{$x->{TYPES}}) { - next if has_property($d, "nopython"); - next if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP"); - - my $fn_name = $d->{NAME}; - - $fn_name =~ s/^$x->{NAME}_//; - $fn_name =~ s/^$basename\_//; - - $self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); - } + foreach (@{$self->{module_methods}}) { + my ($fn_name, $pyfn_name, $flags, $doc) = @$_; + $self->pidl("{ \"$fn_name\", (PyCFunction)$pyfn_name, $flags, $doc },"); } $self->pidl("{ NULL, NULL, 0, NULL }"); @@ -339,9 +930,18 @@ sub Parse($$$$) $self->indent; $self->pidl("PyObject *m;"); $self->pidl("m = Py_InitModule(\"$basename\", $basename\_methods);"); - foreach (keys %{$self->{constants}}) { - # FIXME: Handle non-string constants - $self->pidl("PyModule_AddObject(m, \"$_\", PyString_FromString(" . $self->{constants}->{$_}->[1] . "));"); + foreach my $name (keys %{$self->{constants}}) { + my $py_obj; + my ($ctype, $cvar) = @{$self->{constants}->{$name}}; + if ($cvar =~ /^[0-9]+$/ or $cvar =~ /^0x[0-9a-fA-F]+$/) { + $py_obj = "PyInt_FromLong($cvar)"; + } elsif ($cvar =~ /^".*"$/) { + $py_obj = "PyString_FromString($cvar)"; + } else { + $py_obj = $self->ConvertObjectToPythonData("NULL", expandAlias($ctype), $cvar); + } + + $self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);"); } $self->deindent; $self->pidl("}"); diff --git a/source4/pidl/lib/Parse/Pidl/Typelist.pm b/source4/pidl/lib/Parse/Pidl/Typelist.pm index b2069c784b..8ba1ae47af 100644 --- a/source4/pidl/lib/Parse/Pidl/Typelist.pm +++ b/source4/pidl/lib/Parse/Pidl/Typelist.pm @@ -7,9 +7,9 @@ package Parse::Pidl::Typelist; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(hasType getType mapTypeName scalar_is_reference expandAlias +@EXPORT_OK = qw(hasType getType resolveType mapTypeName scalar_is_reference expandAlias mapScalarType addType typeIs is_scalar enum_type_fn - bitmap_type_fn mapType + bitmap_type_fn mapType typeHasBody ); use vars qw($VERSION); $VERSION = '0.01'; @@ -59,6 +59,7 @@ my %aliases = ( "boolean8" => "uint8", "boolean32" => "uint32", "DWORD" => "uint32", + "uint" => "uint32", "int" => "int32", "WORD" => "uint16", "char" => "uint8", @@ -95,6 +96,20 @@ sub addType($) $types{$t->{NAME}} = $t; } +sub resolveType($) +{ + my ($ctype) = @_; + + if (not hasType($ctype)) { + # assume struct typedef + return { TYPE => "TYPEDEF", NAME => $ctype, DATA => { TYPE => "STRUCT" } }; + } else { + return getType($ctype); + } + + return $ctype; +} + sub getType($) { my $t = shift; @@ -135,11 +150,12 @@ sub is_scalar($) sub is_scalar($); my $type = shift; - return 1 if (ref($type) eq "HASH" and $type->{TYPE} eq "SCALAR"); + return 1 if (ref($type) eq "HASH" and + ($type->{TYPE} eq "SCALAR" or $type->{TYPE} eq "ENUM" or + $type->{TYPE} eq "BITMAP")); if (my $dt = getType($type)) { - return is_scalar($dt->{DATA}) if ($dt->{TYPE} eq "TYPEDEF" or - $dt->{TYPE} eq "DECLARE"); + return is_scalar($dt->{DATA}) if ($dt->{TYPE} eq "TYPEDEF"); return 1 if ($dt->{TYPE} eq "SCALAR" or $dt->{TYPE} eq "ENUM" or $dt->{TYPE} eq "BITMAP"); } @@ -150,7 +166,7 @@ sub is_scalar($) sub scalar_is_reference($) { my $name = shift; - + return 1 if (grep(/^$name$/, @reference_scalars)); return 0; } @@ -208,13 +224,25 @@ sub bitmap_type_fn($) return "uint32"; } +sub typeHasBody($) +{ + sub typeHasBody($); + my ($e) = @_; + + if ($e->{TYPE} eq "TYPEDEF") { + return 0 unless(defined($e->{DATA})); + return typeHasBody($e->{DATA}); + } + + return defined($e->{ELEMENTS}); +} + sub mapType($$) { sub mapType($$); my ($t, $n) = @_; return mapType($t->{DATA}, $n) if ($t->{TYPE} eq "TYPEDEF"); - return mapType($t->{DATA}, $n) if ($t->{TYPE} eq "DECLARE"); return mapScalarType($n) if ($t->{TYPE} eq "SCALAR"); return "enum $n" if ($t->{TYPE} eq "ENUM"); return "struct $n" if ($t->{TYPE} eq "STRUCT"); @@ -240,7 +268,7 @@ sub mapTypeName($) sub LoadIdl($) { - my $idl = shift; + my ($idl) = @_; foreach my $x (@{$idl}) { next if $x->{TYPE} ne "INTERFACE"; @@ -248,7 +276,6 @@ sub LoadIdl($) foreach my $y (@{$x->{DATA}}) { addType($y) if ( $y->{TYPE} eq "TYPEDEF" - or $y->{TYPE} eq "DECLARE" or $y->{TYPE} eq "UNION" or $y->{TYPE} eq "STRUCT" or $y->{TYPE} eq "ENUM" @@ -257,6 +284,11 @@ sub LoadIdl($) } } +sub GenerateTypeLib() +{ + return Parse::Pidl::Util::MyDumper(\%types); +} + RegisterScalars(); 1; diff --git a/source4/pidl/pidl b/source4/pidl/pidl index 4395df2020..220d62cd71 100755 --- a/source4/pidl/pidl +++ b/source4/pidl/pidl @@ -17,7 +17,7 @@ pidl - An IDL compiler written in Perl pidl --help -pidl [--outputdir[=OUTNAME]] [--includedir DIR...] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--python[=OUTPUT]] [--swig[=OUTPUT]] [--ndr-parser[=OUTPUT]] [--client] [--server] [--warn-compat] [--quiet] [--verbose] [--template] [--ws-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-parser[=OUTPUT]] [--samba3-ndr-client[=OUTPUT]] [--samba3-ndr-server[=OUTPUT]] [<idlfile>.idl]... +pidl [--outputdir[=OUTNAME]] [--includedir DIR...] [--parse-idl-tree] [--dump-idl-tree] [--dump-ndr-tree] [--header[=OUTPUT]] [--ejs[=OUTPUT]] [--python[=OUTPUT]] [--swig[=OUTPUT]] [--ndr-parser[=OUTPUT]] [--client] [--server] [--warn-compat] [--quiet] [--verbose] [--template] [--ws-parser[=OUTPUT]] [--diff] [--dump-idl] [--tdr-parser[=OUTPUT]] [--samba3-ndr-client[=OUTPUT]] [--samba3-ndr-server[=OUTPUT]] [--typelib=[OUTPUT]] [<idlfile>.idl]... =head1 DESCRIPTION @@ -52,6 +52,10 @@ both marshalling/unmarshalling and debugging purposes). =item I<--help> Show list of available options. + +=item I<--version> + +Show pidl version =item I<--outputdir OUTNAME> @@ -88,6 +92,10 @@ Generate a C file and C header containing TDR parsers. The filename for the parser defaults to tdr_OUTNAME.c. The header filename will be the parser filename with the extension changed from .c to .h. +=item I<--typelib> + +Write type information to the specified file. + =item I<--server> Generate boilerplate for the RPC server that implements @@ -399,7 +407,7 @@ use lib "$RealBin"; use lib "$RealBin/lib"; use Getopt::Long; use File::Basename; -use Parse::Pidl; +use Parse::Pidl qw ( $VERSION ); use Parse::Pidl::Util; ##################################################################### @@ -449,6 +457,7 @@ sub FileSave($$) my(@opt_incdirs) = (); my($opt_help) = 0; +my($opt_version) = 0; my($opt_parse_idl_tree) = 0; my($opt_dump_idl_tree); my($opt_dump_ndr_tree); @@ -462,6 +471,7 @@ my($opt_samba3_ndr_client); my($opt_samba3_ndr_server); my($opt_template) = 0; my($opt_client); +my($opt_typelib); my($opt_server); my($opt_ndr_parser); my($opt_tdr_parser); @@ -478,7 +488,9 @@ my($opt_warn_compat) = 0; # display help text sub ShowHelp() { -print "perl IDL parser and code generator +print "perl IDL parser and code generator\n"; +ShowVersion(); +print" Copyright (C) Andrew Tridgell <tridge\@samba.org> Copyright (C) Jelmer Vernooij <jelmer\@samba.org> @@ -486,6 +498,7 @@ Usage: $Script [options] [--] <idlfile> [<idlfile>...] Generic Options: --help this help page + --version show pidl version --outputdir=OUTDIR put output in OUTDIR/ [.] --warn-compat warn about incompatibility with other compilers --quiet be quiet @@ -498,6 +511,7 @@ Debugging: --dump-ndr-tree[=FILE] dump internal NDR data tree to file [BASENAME.ndr] --dump-idl regenerate IDL file --diff run diff on original IDL and dumped output + --typelib print type information Samba 4 output: --header[=OUTFILE] create generic header file [BASENAME.h] @@ -522,9 +536,17 @@ Wireshark parsers: exit(0); } +######################################### +# Display version +sub ShowVersion() +{ + print "perl IDL version $VERSION\n"; +} + # main program my $result = GetOptions ( 'help|h|?' => \$opt_help, + 'version' => \$opt_version, 'outputdir=s' => \$opt_outputdir, 'dump-idl' => \$opt_dump_idl, 'dump-idl-tree:s' => \$opt_dump_idl_tree, @@ -534,6 +556,7 @@ my $result = GetOptions ( 'samba3-ndr-server:s' => \$opt_samba3_ndr_server, 'header:s' => \$opt_header, 'server:s' => \$opt_server, + 'typelib:s' => \$opt_typelib, 'tdr-parser:s' => \$opt_tdr_parser, 'template' => \$opt_template, 'ndr-parser:s' => \$opt_ndr_parser, @@ -558,6 +581,11 @@ if ($opt_help) { exit(0); } +if ($opt_version) { + ShowVersion(); + exit(0); +} + sub process_file($) { my $idl_file = shift; @@ -664,7 +692,8 @@ sub process_file($) if (defined($opt_python)) { require Parse::Pidl::Samba4::Python; my $generator = new Parse::Pidl::Samba4::Python(); - my ($hdr,$prsr) = $generator->Parse($basename, $ndr, $h_filename); + my ($hdr,$prsr) = $generator->Parse($basename, $ndr, + "$outputdir/ndr_$basename\_c.h", $h_filename); FileSave("$outputdir/py_$basename.c", $prsr); FileSave("$outputdir/py_$basename.h", $hdr); } @@ -711,6 +740,12 @@ sub process_file($) FileSave($tdr_header, $hdr); } + if (defined($opt_typelib)) { + my $typelib = ($opt_typelib or "$outputdir/$basename.tlb"); + require Parse::Pidl::Typelist; + FileSave($typelib, Parse::Pidl::Typelist::GenerateTypeLib()); + } + if ($opt_template) { require Parse::Pidl::Samba4::Template; print Parse::Pidl::Samba4::Template::Parse($pidl); diff --git a/source4/pidl/smb_interfaces.pm b/source4/pidl/smb_interfaces.pm deleted file mode 100644 index c9cc4495b1..0000000000 --- a/source4/pidl/smb_interfaces.pm +++ /dev/null @@ -1,1272 +0,0 @@ -#################################################################### -# -# This file was generated using Parse::Yapp version 1.05. -# -# Don't edit this file, use source file instead. -# -# ANY CHANGE MADE HERE WILL BE LOST ! -# -#################################################################### -package smb_interfaces; -use vars qw ( @ISA ); -use strict; - -@ISA= qw ( Parse::Yapp::Driver ); -#Included Parse/Yapp/Driver.pm file---------------------------------------- -{ -# -# Module Parse::Yapp::Driver -# -# This module is part of the Parse::Yapp package available on your -# nearest CPAN -# -# Any use of this module in a standalone parser make the included -# text under the same copyright as the Parse::Yapp module itself. -# -# This notice should remain unchanged. -# -# (c) Copyright 1998-2001 Francois Desarmenien, all rights reserved. -# (see the pod text in Parse::Yapp module for use and distribution rights) -# - -package Parse::Yapp::Driver; - -require 5.004; - -use strict; - -use vars qw ( $VERSION $COMPATIBLE $FILENAME ); - -$VERSION = '1.05'; -$COMPATIBLE = '0.07'; -$FILENAME=__FILE__; - -use Carp; - -#Known parameters, all starting with YY (leading YY will be discarded) -my(%params)=(YYLEX => 'CODE', 'YYERROR' => 'CODE', YYVERSION => '', - YYRULES => 'ARRAY', YYSTATES => 'ARRAY', YYDEBUG => ''); -#Mandatory parameters -my(@params)=('LEX','RULES','STATES'); - -sub new { - my($class)=shift; - my($errst,$nberr,$token,$value,$check,$dotpos); - my($self)={ ERROR => \&_Error, - ERRST => \$errst, - NBERR => \$nberr, - TOKEN => \$token, - VALUE => \$value, - DOTPOS => \$dotpos, - STACK => [], - DEBUG => 0, - CHECK => \$check }; - - _CheckParams( [], \%params, \@_, $self ); - - exists($$self{VERSION}) - and $$self{VERSION} < $COMPATIBLE - and croak "Yapp driver version $VERSION ". - "incompatible with version $$self{VERSION}:\n". - "Please recompile parser module."; - - ref($class) - and $class=ref($class); - - bless($self,$class); -} - -sub YYParse { - my($self)=shift; - my($retval); - - _CheckParams( \@params, \%params, \@_, $self ); - - if($$self{DEBUG}) { - _DBLoad(); - $retval = eval '$self->_DBParse()';#Do not create stab entry on compile - $@ and die $@; - } - else { - $retval = $self->_Parse(); - } - $retval -} - -sub YYData { - my($self)=shift; - - exists($$self{USER}) - or $$self{USER}={}; - - $$self{USER}; - -} - -sub YYErrok { - my($self)=shift; - - ${$$self{ERRST}}=0; - undef; -} - -sub YYNberr { - my($self)=shift; - - ${$$self{NBERR}}; -} - -sub YYRecovering { - my($self)=shift; - - ${$$self{ERRST}} != 0; -} - -sub YYAbort { - my($self)=shift; - - ${$$self{CHECK}}='ABORT'; - undef; -} - -sub YYAccept { - my($self)=shift; - - ${$$self{CHECK}}='ACCEPT'; - undef; -} - -sub YYError { - my($self)=shift; - - ${$$self{CHECK}}='ERROR'; - undef; -} - -sub YYSemval { - my($self)=shift; - my($index)= $_[0] - ${$$self{DOTPOS}} - 1; - - $index < 0 - and -$index <= @{$$self{STACK}} - and return $$self{STACK}[$index][1]; - - undef; #Invalid index -} - -sub YYCurtok { - my($self)=shift; - - @_ - and ${$$self{TOKEN}}=$_[0]; - ${$$self{TOKEN}}; -} - -sub YYCurval { - my($self)=shift; - - @_ - and ${$$self{VALUE}}=$_[0]; - ${$$self{VALUE}}; -} - -sub YYExpect { - my($self)=shift; - - keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}} -} - -sub YYLexer { - my($self)=shift; - - $$self{LEX}; -} - - -################# -# Private stuff # -################# - - -sub _CheckParams { - my($mandatory,$checklist,$inarray,$outhash)=@_; - my($prm,$value); - my($prmlst)={}; - - while(($prm,$value)=splice(@$inarray,0,2)) { - $prm=uc($prm); - exists($$checklist{$prm}) - or croak("Unknow parameter '$prm'"); - ref($value) eq $$checklist{$prm} - or croak("Invalid value for parameter '$prm'"); - $prm=unpack('@2A*',$prm); - $$outhash{$prm}=$value; - } - for (@$mandatory) { - exists($$outhash{$_}) - or croak("Missing mandatory parameter '".lc($_)."'"); - } -} - -sub _Error { - print "Parse error.\n"; -} - -sub _DBLoad { - { - no strict 'refs'; - - exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ? - and return; - } - my($fname)=__FILE__; - my(@drv); - open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname"; - while(<DRV>) { - /^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/ - and do { - s/^#DBG>//; - push(@drv,$_); - } - } - close(DRV); - - $drv[0]=~s/_P/_DBP/; - eval join('',@drv); -} - -#Note that for loading debugging version of the driver, -#this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive. -#So, DO NOT remove comment at end of sub !!! -sub _Parse { - my($self)=shift; - - my($rules,$states,$lex,$error) - = @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' }; - my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos) - = @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' }; - -#DBG> my($debug)=$$self{DEBUG}; -#DBG> my($dbgerror)=0; - -#DBG> my($ShowCurToken) = sub { -#DBG> my($tok)='>'; -#DBG> for (split('',$$token)) { -#DBG> $tok.= (ord($_) < 32 or ord($_) > 126) -#DBG> ? sprintf('<%02X>',ord($_)) -#DBG> : $_; -#DBG> } -#DBG> $tok.='<'; -#DBG> }; - - $$errstatus=0; - $$nberror=0; - ($$token,$$value)=(undef,undef); - @$stack=( [ 0, undef ] ); - $$check=''; - - while(1) { - my($actions,$act,$stateno); - - $stateno=$$stack[-1][0]; - $actions=$$states[$stateno]; - -#DBG> print STDERR ('-' x 40),"\n"; -#DBG> $debug & 0x2 -#DBG> and print STDERR "In state $stateno:\n"; -#DBG> $debug & 0x08 -#DBG> and print STDERR "Stack:[". -#DBG> join(',',map { $$_[0] } @$stack). -#DBG> "]\n"; - - - if (exists($$actions{ACTIONS})) { - - defined($$token) - or do { - ($$token,$$value)=&$lex($self); -#DBG> $debug & 0x01 -#DBG> and print STDERR "Need token. Got ".&$ShowCurToken."\n"; - }; - - $act= exists($$actions{ACTIONS}{$$token}) - ? $$actions{ACTIONS}{$$token} - : exists($$actions{DEFAULT}) - ? $$actions{DEFAULT} - : undef; - } - else { - $act=$$actions{DEFAULT}; -#DBG> $debug & 0x01 -#DBG> and print STDERR "Don't need token.\n"; - } - - defined($act) - and do { - - $act > 0 - and do { #shift - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Shift and go to state $act.\n"; - - $$errstatus - and do { - --$$errstatus; - -#DBG> $debug & 0x10 -#DBG> and $dbgerror -#DBG> and $$errstatus == 0 -#DBG> and do { -#DBG> print STDERR "**End of Error recovery.\n"; -#DBG> $dbgerror=0; -#DBG> }; - }; - - - push(@$stack,[ $act, $$value ]); - - $$token ne '' #Don't eat the eof - and $$token=$$value=undef; - next; - }; - - #reduce - my($lhs,$len,$code,@sempar,$semval); - ($lhs,$len,$code)=@{$$rules[-$act]}; - -#DBG> $debug & 0x04 -#DBG> and $act -#DBG> and print STDERR "Reduce using rule ".-$act." ($lhs,$len): "; - - $act - or $self->YYAccept(); - - $$dotpos=$len; - - unpack('A1',$lhs) eq '@' #In line rule - and do { - $lhs =~ /^\@[0-9]+\-([0-9]+)$/ - or die "In line rule name '$lhs' ill formed: ". - "report it as a BUG.\n"; - $$dotpos = $1; - }; - - @sempar = $$dotpos - ? map { $$_[1] } @$stack[ -$$dotpos .. -1 ] - : (); - - $semval = $code ? &$code( $self, @sempar ) - : @sempar ? $sempar[0] : undef; - - splice(@$stack,-$len,$len); - - $$check eq 'ACCEPT' - and do { - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Accept.\n"; - - return($semval); - }; - - $$check eq 'ABORT' - and do { - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Abort.\n"; - - return(undef); - - }; - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Back to state $$stack[-1][0], then "; - - $$check eq 'ERROR' - or do { -#DBG> $debug & 0x04 -#DBG> and print STDERR -#DBG> "go to state $$states[$$stack[-1][0]]{GOTOS}{$lhs}.\n"; - -#DBG> $debug & 0x10 -#DBG> and $dbgerror -#DBG> and $$errstatus == 0 -#DBG> and do { -#DBG> print STDERR "**End of Error recovery.\n"; -#DBG> $dbgerror=0; -#DBG> }; - - push(@$stack, - [ $$states[$$stack[-1][0]]{GOTOS}{$lhs}, $semval ]); - $$check=''; - next; - }; - -#DBG> $debug & 0x04 -#DBG> and print STDERR "Forced Error recovery.\n"; - - $$check=''; - - }; - - #Error - $$errstatus - or do { - - $$errstatus = 1; - &$error($self); - $$errstatus # if 0, then YYErrok has been called - or next; # so continue parsing - -#DBG> $debug & 0x10 -#DBG> and do { -#DBG> print STDERR "**Entering Error recovery.\n"; -#DBG> ++$dbgerror; -#DBG> }; - - ++$$nberror; - - }; - - $$errstatus == 3 #The next token is not valid: discard it - and do { - $$token eq '' # End of input: no hope - and do { -#DBG> $debug & 0x10 -#DBG> and print STDERR "**At eof: aborting.\n"; - return(undef); - }; - -#DBG> $debug & 0x10 -#DBG> and print STDERR "**Dicard invalid token ".&$ShowCurToken.".\n"; - - $$token=$$value=undef; - }; - - $$errstatus=3; - - while( @$stack - and ( not exists($$states[$$stack[-1][0]]{ACTIONS}) - or not exists($$states[$$stack[-1][0]]{ACTIONS}{error}) - or $$states[$$stack[-1][0]]{ACTIONS}{error} <= 0)) { - -#DBG> $debug & 0x10 -#DBG> and print STDERR "**Pop state $$stack[-1][0].\n"; - - pop(@$stack); - } - - @$stack - or do { - -#DBG> $debug & 0x10 -#DBG> and print STDERR "**No state left on stack: aborting.\n"; - - return(undef); - }; - - #shift the error token - -#DBG> $debug & 0x10 -#DBG> and print STDERR "**Shift \$error token and go to state ". -#DBG> $$states[$$stack[-1][0]]{ACTIONS}{error}. -#DBG> ".\n"; - - push(@$stack, [ $$states[$$stack[-1][0]]{ACTIONS}{error}, undef ]); - - } - - #never reached - croak("Error in driver logic. Please, report it as a BUG"); - -}#_Parse -#DO NOT remove comment - -1; - -} -#End of include-------------------------------------------------- - - - - -sub new { - my($class)=shift; - ref($class) - and $class=ref($class); - - my($self)=$class->SUPER::new( yyversion => '1.05', - yystates => -[ - {#State 0 - ACTIONS => { - 'UNION' => 5, - 'ENUM' => 1, - 'TYPEDEF' => 7, - 'STRUCT' => 2 - }, - GOTOS => { - 'struct' => 6, - 'enum' => 9, - 'typedef' => 8, - 'union' => 10, - 'definitions' => 3, - 'definition' => 4 - } - }, - {#State 1 - ACTIONS => { - 'IDENTIFIER' => 11 - } - }, - {#State 2 - ACTIONS => { - 'IDENTIFIER' => 12 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 13 - } - }, - {#State 3 - ACTIONS => { - '' => 14, - 'UNION' => 5, - 'ENUM' => 1, - 'TYPEDEF' => 7, - 'STRUCT' => 2 - }, - GOTOS => { - 'struct' => 6, - 'typedef' => 8, - 'enum' => 9, - 'union' => 10, - 'definition' => 15 - } - }, - {#State 4 - DEFAULT => -1 - }, - {#State 5 - ACTIONS => { - 'IDENTIFIER' => 12 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 16 - } - }, - {#State 6 - DEFAULT => -3 - }, - {#State 7 - ACTIONS => { - 'STRUCT' => 17 - } - }, - {#State 8 - DEFAULT => -5 - }, - {#State 9 - DEFAULT => -6 - }, - {#State 10 - DEFAULT => -4 - }, - {#State 11 - ACTIONS => { - "{" => 18 - } - }, - {#State 12 - DEFAULT => -32 - }, - {#State 13 - ACTIONS => { - "{" => 19 - } - }, - {#State 14 - DEFAULT => 0 - }, - {#State 15 - DEFAULT => -2 - }, - {#State 16 - ACTIONS => { - "{" => 20 - } - }, - {#State 17 - ACTIONS => { - "{" => 21 - } - }, - {#State 18 - ACTIONS => { - 'IDENTIFIER' => 22 - }, - GOTOS => { - 'enum_identifiers' => 23, - 'enum_identifier' => 24 - } - }, - {#State 19 - DEFAULT => -15, - GOTOS => { - 'elements' => 25 - } - }, - {#State 20 - DEFAULT => -15, - GOTOS => { - 'elements' => 26 - } - }, - {#State 21 - DEFAULT => -15, - GOTOS => { - 'elements' => 27 - } - }, - {#State 22 - ACTIONS => { - "=" => 28 - }, - DEFAULT => -13 - }, - {#State 23 - ACTIONS => { - "}" => 29, - "," => 30 - } - }, - {#State 24 - DEFAULT => -11 - }, - {#State 25 - ACTIONS => { - "}" => 31, - 'UNION' => 37, - 'IDENTIFIER' => 33, - 'ENUM' => 32, - 'STRUCT' => 35, - 'CONST' => 34 - }, - GOTOS => { - 'struct' => 38, - 'type' => 39, - 'union' => 40, - 'element' => 36 - } - }, - {#State 26 - ACTIONS => { - "}" => 41, - 'UNION' => 37, - 'IDENTIFIER' => 33, - 'ENUM' => 32, - 'STRUCT' => 35, - 'CONST' => 34 - }, - GOTOS => { - 'struct' => 38, - 'type' => 39, - 'union' => 40, - 'element' => 36 - } - }, - {#State 27 - ACTIONS => { - "}" => 42, - 'UNION' => 37, - 'IDENTIFIER' => 33, - 'ENUM' => 32, - 'STRUCT' => 35, - 'CONST' => 34 - }, - GOTOS => { - 'struct' => 38, - 'type' => 39, - 'union' => 40, - 'element' => 36 - } - }, - {#State 28 - ACTIONS => { - 'IDENTIFIER' => 43 - } - }, - {#State 29 - ACTIONS => { - ";" => 44 - } - }, - {#State 30 - ACTIONS => { - 'IDENTIFIER' => 22 - }, - GOTOS => { - 'enum_identifier' => 45 - } - }, - {#State 31 - DEFAULT => -28, - GOTOS => { - 'pointers' => 46 - } - }, - {#State 32 - ACTIONS => { - 'IDENTIFIER' => 47 - } - }, - {#State 33 - DEFAULT => -26 - }, - {#State 34 - ACTIONS => { - 'IDENTIFIER' => 33, - 'ENUM' => 32 - }, - GOTOS => { - 'type' => 48 - } - }, - {#State 35 - ACTIONS => { - 'IDENTIFIER' => 49 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 13 - } - }, - {#State 36 - DEFAULT => -16 - }, - {#State 37 - ACTIONS => { - 'IDENTIFIER' => 50 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 16 - } - }, - {#State 38 - DEFAULT => -18 - }, - {#State 39 - DEFAULT => -28, - GOTOS => { - 'pointers' => 51 - } - }, - {#State 40 - DEFAULT => -19 - }, - {#State 41 - DEFAULT => -28, - GOTOS => { - 'pointers' => 52 - } - }, - {#State 42 - ACTIONS => { - 'IDENTIFIER' => 12 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 53 - } - }, - {#State 43 - DEFAULT => -14 - }, - {#State 44 - DEFAULT => -10 - }, - {#State 45 - DEFAULT => -12 - }, - {#State 46 - ACTIONS => { - 'IDENTIFIER' => 12, - "*" => 55 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 54, - 'optional_identifiers' => 56 - } - }, - {#State 47 - DEFAULT => -27 - }, - {#State 48 - DEFAULT => -28, - GOTOS => { - 'pointers' => 57 - } - }, - {#State 49 - ACTIONS => { - "{" => -32 - }, - DEFAULT => -28, - GOTOS => { - 'pointers' => 58 - } - }, - {#State 50 - ACTIONS => { - "{" => -32 - }, - DEFAULT => -28, - GOTOS => { - 'pointers' => 59 - } - }, - {#State 51 - ACTIONS => { - 'IDENTIFIER' => 60, - "*" => 55 - } - }, - {#State 52 - ACTIONS => { - 'IDENTIFIER' => 12, - "*" => 55 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 61 - } - }, - {#State 53 - ACTIONS => { - ";" => 62 - } - }, - {#State 54 - DEFAULT => -30 - }, - {#State 55 - DEFAULT => -29 - }, - {#State 56 - ACTIONS => { - ";" => 63, - "," => 64 - } - }, - {#State 57 - ACTIONS => { - 'IDENTIFIER' => 65, - "*" => 55 - } - }, - {#State 58 - ACTIONS => { - 'IDENTIFIER' => 66, - "*" => 55 - } - }, - {#State 59 - ACTIONS => { - 'IDENTIFIER' => 67, - "*" => 55 - } - }, - {#State 60 - ACTIONS => { - "[" => 69 - }, - DEFAULT => -24, - GOTOS => { - 'array' => 68 - } - }, - {#State 61 - ACTIONS => { - ";" => 70 - } - }, - {#State 62 - DEFAULT => -9 - }, - {#State 63 - DEFAULT => -7 - }, - {#State 64 - ACTIONS => { - 'IDENTIFIER' => 12 - }, - DEFAULT => -33, - GOTOS => { - 'optional_identifier' => 71 - } - }, - {#State 65 - ACTIONS => { - "[" => 69 - }, - DEFAULT => -24, - GOTOS => { - 'array' => 72 - } - }, - {#State 66 - ACTIONS => { - ";" => 73 - } - }, - {#State 67 - ACTIONS => { - ";" => 74 - } - }, - {#State 68 - ACTIONS => { - ";" => 75 - } - }, - {#State 69 - ACTIONS => { - 'CONSTANT' => 76 - } - }, - {#State 70 - DEFAULT => -8 - }, - {#State 71 - DEFAULT => -31 - }, - {#State 72 - ACTIONS => { - ";" => 77 - } - }, - {#State 73 - DEFAULT => -20 - }, - {#State 74 - DEFAULT => -21 - }, - {#State 75 - DEFAULT => -23 - }, - {#State 76 - ACTIONS => { - "]" => 78 - } - }, - {#State 77 - DEFAULT => -22 - }, - {#State 78 - DEFAULT => -25 - } -], - yyrules => -[ - [#Rule 0 - '$start', 2, undef - ], - [#Rule 1 - 'definitions', 1, -sub -#line 14 "build/pidl/smb_interfaces.yp" -{ [$_[1]] } - ], - [#Rule 2 - 'definitions', 2, -sub -#line 15 "build/pidl/smb_interfaces.yp" -{ push(@{$_[1]}, $_[2]); $_[1] } - ], - [#Rule 3 - 'definition', 1, undef - ], - [#Rule 4 - 'definition', 1, undef - ], - [#Rule 5 - 'definition', 1, undef - ], - [#Rule 6 - 'definition', 1, undef - ], - [#Rule 7 - 'struct', 8, -sub -#line 26 "build/pidl/smb_interfaces.yp" -{ - { - "NAME" => $_[7], - "STRUCT_NAME" => $_[2], - "TYPE" => "struct", - "DATA" => $_[4], - } - } - ], - [#Rule 8 - 'union', 8, -sub -#line 38 "build/pidl/smb_interfaces.yp" -{ - { - "NAME" => $_[7], - "UNION_NAME" => $_[2], - "TYPE" => "union", - "DATA" => $_[4], - } - } - ], - [#Rule 9 - 'typedef', 7, undef - ], - [#Rule 10 - 'enum', 6, undef - ], - [#Rule 11 - 'enum_identifiers', 1, undef - ], - [#Rule 12 - 'enum_identifiers', 3, undef - ], - [#Rule 13 - 'enum_identifier', 1, undef - ], - [#Rule 14 - 'enum_identifier', 3, undef - ], - [#Rule 15 - 'elements', 0, undef - ], - [#Rule 16 - 'elements', 2, -sub -#line 65 "build/pidl/smb_interfaces.yp" -{ push(@{$_[1]}, $_[2]); $_[1] } - ], - [#Rule 17 - 'element', 0, undef - ], - [#Rule 18 - 'element', 1, undef - ], - [#Rule 19 - 'element', 1, undef - ], - [#Rule 20 - 'element', 5, -sub -#line 72 "build/pidl/smb_interfaces.yp" -{{ - "NAME" => [$_[2]], - "POINTERS" => $_[3], - "TYPE" => "struct $_[2]", - }} - ], - [#Rule 21 - 'element', 5, -sub -#line 78 "build/pidl/smb_interfaces.yp" -{{ - "NAME" => $_[2], - "POINTERS" => $_[3], - "TYPE" => "union $_[2]", - }} - ], - [#Rule 22 - 'element', 6, -sub -#line 84 "build/pidl/smb_interfaces.yp" -{{ - "NAME" => [$_[4]], - "TYPE" => $_[2], - "POINTERS" => $_[3], - }} - ], - [#Rule 23 - 'element', 5, -sub -#line 90 "build/pidl/smb_interfaces.yp" -{{ - "NAME" => [$_[3]], - "TYPE" => $_[1], - "POINTERS" => $_[2], - "ARRAY_LENGTH" => $_[4] - }} - ], - [#Rule 24 - 'array', 0, undef - ], - [#Rule 25 - 'array', 3, -sub -#line 99 "build/pidl/smb_interfaces.yp" -{ int($_[2]) } - ], - [#Rule 26 - 'type', 1, undef - ], - [#Rule 27 - 'type', 2, -sub -#line 104 "build/pidl/smb_interfaces.yp" -{ "enum $_[2]" } - ], - [#Rule 28 - 'pointers', 0, undef - ], - [#Rule 29 - 'pointers', 2, -sub -#line 109 "build/pidl/smb_interfaces.yp" -{ $_[1]+1 } - ], - [#Rule 30 - 'optional_identifiers', 1, -sub -#line 112 "build/pidl/smb_interfaces.yp" -{ [$_[1]] } - ], - [#Rule 31 - 'optional_identifiers', 3, -sub -#line 113 "build/pidl/smb_interfaces.yp" -{ push(@{$_[1]}, $_[3]); $_[1] } - ], - [#Rule 32 - 'optional_identifier', 1, undef - ], - [#Rule 33 - 'optional_identifier', 0, undef - ] -], - @_); - bless($self,$class); -} - -#line 119 "build/pidl/smb_interfaces.yp" - - -##################################################################### -# traverse a perl data structure removing any empty arrays or -# hashes and any hash elements that map to undef -sub CleanData($) -{ - sub CleanData($); - my($v) = shift; - if (ref($v) eq "ARRAY") { - foreach my $i (0 .. $#{$v}) { - CleanData($v->[$i]); - if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) { - $v->[$i] = undef; - next; - } - } - # this removes any undefined elements from the array - @{$v} = grep { defined $_ } @{$v}; - } elsif (ref($v) eq "HASH") { - foreach my $x (keys %{$v}) { - CleanData($v->{$x}); - if (!defined $v->{$x}) { delete($v->{$x}); next; } - if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; } - } - } - return $v; -} - -sub _Error { - if (exists $_[0]->YYData->{ERRMSG}) { - print $_[0]->YYData->{ERRMSG}; - delete $_[0]->YYData->{ERRMSG}; - return; - }; - my $line = $_[0]->YYData->{LINE}; - my $last_token = $_[0]->YYData->{LAST_TOKEN}; - my $file = $_[0]->YYData->{INPUT_FILENAME}; - - print "$file:$line: Syntax error near '$last_token'\n"; -} - -sub _Lexer($) -{ - my($parser)=shift; - - $parser->YYData->{INPUT} or return('',undef); - -again: - $parser->YYData->{INPUT} =~ s/^[ \t]*//; - - for ($parser->YYData->{INPUT}) { - if (/^\#/) { - if (s/^\# (\d+) \"(.*?)\"( \d+|)//) { - $parser->YYData->{LINE} = $1-1; - $parser->YYData->{INPUT_FILENAME} = $2; - goto again; - } - if (s/^\#line (\d+) \"(.*?)\"( \d+|)//) { - $parser->YYData->{LINE} = $1-1; - $parser->YYData->{INPUT_FILENAME} = $2; - goto again; - } - if (s/^(\#.*)$//m) { - goto again; - } - } - if (s/^(\n)//) { - $parser->YYData->{LINE}++; - goto again; - } - if (s/^\"(.*?)\"//) { - $parser->YYData->{LAST_TOKEN} = $1; - return('TEXT',$1); - } - if (s/^(\d+)(\W|$)/$2/) { - $parser->YYData->{LAST_TOKEN} = $1; - return('CONSTANT',$1); - } - if (s/^([\w_]+)//) { - $parser->YYData->{LAST_TOKEN} = $1; - if ($1 =~ - /^(const|typedef|union|struct|enum)$/x) { - return uc($1); - } - return('IDENTIFIER',$1); - } - if (s/^(.)//s) { - $parser->YYData->{LAST_TOKEN} = $1; - return($1,$1); - } - } -} - -sub parse($$) -{ - my ($self,$filename) = @_; - - my $saved_delim = $/; - undef $/; - my $cpp = $ENV{CPP}; - if (! defined $cpp) { - $cpp = "cpp" - } - my $data = `$cpp -D__PIDL__ -xc $filename`; - $/ = $saved_delim; - - $self->YYData->{INPUT} = $data; - $self->YYData->{LINE} = 0; - $self->YYData->{LAST_TOKEN} = "NONE"; - - my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error ); - - return CleanData($idl); -} - -1; diff --git a/source4/pidl/smb_interfaces.yp b/source4/pidl/smb_interfaces.yp deleted file mode 100644 index f8c34eacdc..0000000000 --- a/source4/pidl/smb_interfaces.yp +++ /dev/null @@ -1,233 +0,0 @@ -######################## -# Parse::Yapp parser for a C header file that contains only structures -# or unions. - -# Copyright (C) 2005, Tim Potter <tpot@samba.org> released under the -# GNU GPL version 2 or later - -################ -# grammar - -%% - -definitions: - definition { [$_[1]] } - | definitions definition { push(@{$_[1]}, $_[2]); $_[1] } -; - -definition: - struct - | union - | typedef - | enum -; - -struct: STRUCT optional_identifier '{' elements '}' pointers optional_identifiers ';' - { - { - "NAME" => $_[7], - "STRUCT_NAME" => $_[2], - "TYPE" => "struct", - "DATA" => $_[4], - } - } -; - -union: - UNION optional_identifier '{' elements '}' pointers optional_identifier ';' - { - { - "NAME" => $_[7], - "UNION_NAME" => $_[2], - "TYPE" => "union", - "DATA" => $_[4], - } - } -; - -typedef: - TYPEDEF STRUCT '{' elements '}' optional_identifier ';' -; - -enum: - ENUM IDENTIFIER '{' enum_identifiers '}' ';' -; - -enum_identifiers: enum_identifier - | enum_identifiers ',' enum_identifier -; - -enum_identifier: IDENTIFIER - | IDENTIFIER '=' IDENTIFIER -; - -elements: #empty - | elements element { push(@{$_[1]}, $_[2]); $_[1] } -; - -element: - | struct - | union - | STRUCT IDENTIFIER pointers IDENTIFIER ';' - {{ - "NAME" => [$_[2]], - "POINTERS" => $_[3], - "TYPE" => "struct $_[2]", - }} - | UNION IDENTIFIER pointers IDENTIFIER ';' - {{ - "NAME" => $_[2], - "POINTERS" => $_[3], - "TYPE" => "union $_[2]", - }} - | CONST type pointers IDENTIFIER array ';' - {{ - "NAME" => [$_[4]], - "TYPE" => $_[2], - "POINTERS" => $_[3], - }} - | type pointers IDENTIFIER array ';' - {{ - "NAME" => [$_[3]], - "TYPE" => $_[1], - "POINTERS" => $_[2], - "ARRAY_LENGTH" => $_[4] - }} -; - -array: #empty - | '[' CONSTANT ']' { int($_[2]) } -; - -type: IDENTIFIER - | ENUM IDENTIFIER - { "enum $_[2]" } -; - -pointers: - #empty { 0 } - | pointers '*' { $_[1]+1 } -; - -optional_identifiers: optional_identifier { [$_[1]] } - | optional_identifiers ',' optional_identifier { push(@{$_[1]}, $_[3]); $_[1] } -; - -optional_identifier: IDENTIFIER | #empty { undef } -; - -%% - -##################################################################### -# traverse a perl data structure removing any empty arrays or -# hashes and any hash elements that map to undef -sub CleanData($) -{ - sub CleanData($); - my($v) = shift; - if (ref($v) eq "ARRAY") { - foreach my $i (0 .. $#{$v}) { - CleanData($v->[$i]); - if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) { - $v->[$i] = undef; - next; - } - } - # this removes any undefined elements from the array - @{$v} = grep { defined $_ } @{$v}; - } elsif (ref($v) eq "HASH") { - foreach my $x (keys %{$v}) { - CleanData($v->{$x}); - if (!defined $v->{$x}) { delete($v->{$x}); next; } - if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; } - } - } - return $v; -} - -sub _Error { - if (exists $_[0]->YYData->{ERRMSG}) { - print $_[0]->YYData->{ERRMSG}; - delete $_[0]->YYData->{ERRMSG}; - return; - }; - my $line = $_[0]->YYData->{LINE}; - my $last_token = $_[0]->YYData->{LAST_TOKEN}; - my $file = $_[0]->YYData->{INPUT_FILENAME}; - - print "$file:$line: Syntax error near '$last_token'\n"; -} - -sub _Lexer($) -{ - my($parser)=shift; - - $parser->YYData->{INPUT} or return('',undef); - -again: - $parser->YYData->{INPUT} =~ s/^[ \t]*//; - - for ($parser->YYData->{INPUT}) { - if (/^\#/) { - if (s/^\# (\d+) \"(.*?)\"( \d+|)//) { - $parser->YYData->{LINE} = $1-1; - $parser->YYData->{INPUT_FILENAME} = $2; - goto again; - } - if (s/^\#line (\d+) \"(.*?)\"( \d+|)//) { - $parser->YYData->{LINE} = $1-1; - $parser->YYData->{INPUT_FILENAME} = $2; - goto again; - } - if (s/^(\#.*)$//m) { - goto again; - } - } - if (s/^(\n)//) { - $parser->YYData->{LINE}++; - goto again; - } - if (s/^\"(.*?)\"//) { - $parser->YYData->{LAST_TOKEN} = $1; - return('TEXT',$1); - } - if (s/^(\d+)(\W|$)/$2/) { - $parser->YYData->{LAST_TOKEN} = $1; - return('CONSTANT',$1); - } - if (s/^([\w_]+)//) { - $parser->YYData->{LAST_TOKEN} = $1; - if ($1 =~ - /^(const|typedef|union|struct|enum)$/x) { - return uc($1); - } - return('IDENTIFIER',$1); - } - if (s/^(.)//s) { - $parser->YYData->{LAST_TOKEN} = $1; - return($1,$1); - } - } -} - -sub parse($$) -{ - my ($self,$filename) = @_; - - my $saved_delim = $/; - undef $/; - my $cpp = $ENV{CPP}; - if (! defined $cpp) { - $cpp = "cpp" - } - my $data = `$cpp -D__PIDL__ -xc $filename`; - $/ = $saved_delim; - - $self->YYData->{INPUT} = $data; - $self->YYData->{LINE} = 0; - $self->YYData->{LAST_TOKEN} = "NONE"; - - my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error ); - - return CleanData($idl); -} diff --git a/source4/pidl/tests/cutil.pl b/source4/pidl/tests/cutil.pl new file mode 100755 index 0000000000..78c8bce45e --- /dev/null +++ b/source4/pidl/tests/cutil.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +# (C) 2007 Jelmer Vernooij <jelmer@samba.org> +# Published under the GNU General Public License +use strict; +use warnings; + +use Test::More tests => 7; +use FindBin qw($RealBin); +use lib "$RealBin"; +use Util; +use Parse::Pidl::Util qw(MyDumper); +use Parse::Pidl::CUtil qw(get_pointer_to get_value_of); + +is("&foo", get_pointer_to("foo")); +is("&(&foo)", get_pointer_to(get_pointer_to("foo"))); +is("*foo", get_pointer_to("**foo")); +is("foo", get_pointer_to("*foo")); + +is("foo", get_value_of("&foo")); +is("*foo", get_value_of("foo")); +is("**foo", get_value_of("*foo")); diff --git a/source4/pidl/tests/header.pl b/source4/pidl/tests/header.pl index 8d0dccf507..db59484444 100755 --- a/source4/pidl/tests/header.pl +++ b/source4/pidl/tests/header.pl @@ -4,12 +4,14 @@ use strict; use warnings; -use Test::More tests => 16; +use Test::More tests => 27; use FindBin qw($RealBin); use lib "$RealBin"; use Util; use Parse::Pidl::Util qw(MyDumper); -use Parse::Pidl::Samba4::Header; +use Parse::Pidl::Samba4::Header qw( + GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv + EnvSubstituteValue); use Parse::Pidl::IDL qw(parse_string); use Parse::Pidl::NDR; @@ -56,3 +58,51 @@ like(parse_idl("interface p { typedef struct x { int p; } x; };"), like(parse_idl("cpp_quote(\"some-foo\")"), qr/some-foo/sm, "cpp quote"); + +# Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work +my $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] }; +is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn)); + +$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] }; +is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn)); + +$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] }; +is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn)); + +$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] }; +is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn)); + +$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] }; +is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionOutEnv($fn)); + +$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] }; +is_deeply({ }, GenerateFunctionInEnv($fn)); + +$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; +is_deeply({ foo => "r->foo", bar => "r->bar", this => "r" }, + GenerateStructEnv($fn, "r")); + +$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; +is_deeply({ foo => "some->complex.variable->foo", + bar => "some->complex.variable->bar", + this => "some->complex.variable" }, + GenerateStructEnv($fn, "some->complex.variable")); + +$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 3 }} ] }; + +my $env = GenerateStructEnv($fn, "r"); +EnvSubstituteValue($env, $fn); +is_deeply($env, { foo => 3, this => "r" }); + +$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; +$env = GenerateStructEnv($fn, "r"); +EnvSubstituteValue($env, $fn); +is_deeply($env, { foo => 'r->foo', bar => 'r->bar', this => "r" }); + +$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 0 }} ] }; + +$env = GenerateStructEnv($fn, "r"); +EnvSubstituteValue($env, $fn); +is_deeply($env, { foo => 0, this => "r" }); + + diff --git a/source4/pidl/tests/ndr.pl b/source4/pidl/tests/ndr.pl index 1512f19d52..7fcc7ef40e 100755 --- a/source4/pidl/tests/ndr.pl +++ b/source4/pidl/tests/ndr.pl @@ -4,7 +4,7 @@ use strict; use warnings; -use Test::More tests => 34; +use Test::More tests => 40; use FindBin qw($RealBin); use lib "$RealBin"; use Util; @@ -212,9 +212,16 @@ is(align_type({ TYPE => "STRUCT", "NAME" => "bla", ELEMENTS => [ { TYPE => "uint16" } ] }), 4); is(align_type({ TYPE => "STRUCT", ELEMENTS => [ { TYPE => "hyper" } ] }), 8); -is(align_type({ TYPE => "DECLARE", DATA => { +is(align_type({ TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT", ELEMENTS => [ { TYPE => "hyper" } ] }}), 8); +# typedef of struct without body +is(align_type({ TYPE => "TYPEDEF", DATA => { + TYPE => "STRUCT", ELEMENTS => undef }}), 4); +# struct without body +is(align_type({ TYPE => "STRUCT", ELEMENTS => undef }), 4); +# empty struct +is(align_type({ TYPE => "STRUCT", ELEMENTS => [] }), 1); is(align_type({ TYPE => "STRUCT", "NAME" => "bla", ELEMENTS => [ { TYPE => "uint8" } ] }), 4); @@ -268,3 +275,9 @@ ok(not can_contain_deferred({ TYPE => "TYPEDEF", ELEMENTS => [ { TYPE => "uint32" } ]}})); ok(can_contain_deferred({ TYPE => "STRUCT", ELEMENTS => [ { TYPE => "someunknowntype" } ]})); +# Make sure the elements for a enum without body aren't filled in +ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, "ref")->{ELEMENTS})); +# Make sure the elements for a bitmap without body aren't filled in +ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, "ref")->{ELEMENTS})); +# Make sure the elements for a union without body aren't filled in +ok(not defined(ParseType({TYPE => "UNION", NAME => "foo" }, "ref")->{ELEMENTS})); diff --git a/source4/pidl/tests/parse_idl.pl b/source4/pidl/tests/parse_idl.pl index 96c7b2adc8..9d43ddccc7 100755 --- a/source4/pidl/tests/parse_idl.pl +++ b/source4/pidl/tests/parse_idl.pl @@ -4,7 +4,7 @@ # Published under the GNU General Public License use strict; -use Test::More tests => 65 * 2 + 3; +use Test::More tests => 65 * 2 + 7; use FindBin qw($RealBin); use lib "$RealBin"; use Util qw(test_errors); @@ -129,4 +129,36 @@ is_deeply($x, [ { 'FILE' => '<quote>', 'DATA' => '"foobar"', 'TYPE' => 'CPP_QUOTE', 'LINE' => 0 } ]); +# A typedef of a struct without body +$x = Parse::Pidl::IDL::parse_string("interface foo { typedef struct x y; }", "<foo>"); +is_deeply($x, + [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [ + { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { + TYPE => 'STRUCT', NAME => 'x' } } ], + 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); + +# A typedef of a struct with empty body +$x = Parse::Pidl::IDL::parse_string("interface foo { typedef struct {} y; }", "<foo>"); + +is_deeply($x, + [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [ + { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'STRUCT', ELEMENTS => [] } } ], + 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); + +# A typedef of a bitmap with no body +$x = Parse::Pidl::IDL::parse_string("interface foo { typedef bitmap x y; }", "<foo>"); + +is_deeply($x, + [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [ + { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'BITMAP', NAME => 'x' } } ], + 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); + + +# A typedef of a union with no body +$x = Parse::Pidl::IDL::parse_string("interface foo { typedef union x y; }", "<foo>"); + +is_deeply($x, + [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [ + { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'UNION', NAME => 'x' } } ], + 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); diff --git a/source4/pidl/tests/samba-ejs.pl b/source4/pidl/tests/samba-ejs.pl index adc00e224f..094d37a103 100755 --- a/source4/pidl/tests/samba-ejs.pl +++ b/source4/pidl/tests/samba-ejs.pl @@ -4,23 +4,14 @@ use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 10; use FindBin qw($RealBin); use lib "$RealBin"; use Util; use Parse::Pidl::Util qw(MyDumper); -use Parse::Pidl::Samba4::EJS qw(get_pointer_to get_value_of check_null_pointer +use Parse::Pidl::Samba4::EJS qw(check_null_pointer fn_declare TypeFunctionName); -is("&foo", get_pointer_to("foo")); -is("&(&foo)", get_pointer_to(get_pointer_to("foo"))); -is("*foo", get_pointer_to("**foo")); -is("foo", get_pointer_to("*foo")); - -is("foo", get_value_of("&foo")); -is("*foo", get_value_of("foo")); -is("**foo", get_value_of("*foo")); - my $ejs = new Parse::Pidl::Samba4::EJS(); $ejs->check_null_pointer("bla"); diff --git a/source4/pidl/tests/samba-ndr.pl b/source4/pidl/tests/samba-ndr.pl index 05c3c1c0df..a14111961f 100755 --- a/source4/pidl/tests/samba-ndr.pl +++ b/source4/pidl/tests/samba-ndr.pl @@ -4,15 +4,14 @@ use strict; use warnings; -use Test::More tests => 41; +use Test::More tests => 30; use FindBin qw($RealBin); use lib "$RealBin"; use Util; use strict; use Parse::Pidl::Util qw(MyDumper); use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer - GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv - EnvSubstituteValue NeededFunction NeededElement NeededType + NeededFunction NeededElement NeededType NeededInterface TypeFunctionName ParseElementPrint); my $output; @@ -138,52 +137,6 @@ test_warnings("nofile:2: unknown dereferenced expression `r->in.bla'\n", is($output, "if (r->in.bla == NULL) return;"); -# Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work -$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] }; -is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn)); - -$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] }; -is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn)); - -$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] }; -is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionInEnv($fn)); - -$fn = { ELEMENTS => [ { DIRECTION => ["out", "in"], NAME => "foo" } ] }; -is_deeply({ "foo" => "r->out.foo" }, GenerateFunctionOutEnv($fn)); - -$fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] }; -is_deeply({ "foo" => "r->in.foo" }, GenerateFunctionOutEnv($fn)); - -$fn = { ELEMENTS => [ { DIRECTION => ["out"], NAME => "foo" } ] }; -is_deeply({ }, GenerateFunctionInEnv($fn)); - -$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; -is_deeply({ foo => "r->foo", bar => "r->bar", this => "r" }, - GenerateStructEnv($fn, "r")); - -$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; -is_deeply({ foo => "some->complex.variable->foo", - bar => "some->complex.variable->bar", - this => "some->complex.variable" }, - GenerateStructEnv($fn, "some->complex.variable")); - -$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 3 }} ] }; - -my $env = GenerateStructEnv($fn, "r"); -EnvSubstituteValue($env, $fn); -is_deeply($env, { foo => 3, this => "r" }); - -$fn = { ELEMENTS => [ { NAME => "foo" }, { NAME => "bar" } ] }; -$env = GenerateStructEnv($fn, "r"); -EnvSubstituteValue($env, $fn); -is_deeply($env, { foo => 'r->foo', bar => 'r->bar', this => "r" }); - -$fn = { ELEMENTS => [ { NAME => "foo", PROPERTIES => { value => 0 }} ] }; - -$env = GenerateStructEnv($fn, "r"); -EnvSubstituteValue($env, $fn); -is_deeply($env, { foo => 0, this => "r" }); - my $needed = {}; NeededElement({ TYPE => "foo", REPRESENTATION_TYPE => "foo" }, "pull", $needed); is_deeply($needed, { ndr_pull_foo => 1 }); diff --git a/source4/pidl/tests/samba3-cli.pl b/source4/pidl/tests/samba3-cli.pl index 5086300e46..f5b51b7d34 100755 --- a/source4/pidl/tests/samba3-cli.pl +++ b/source4/pidl/tests/samba3-cli.pl @@ -10,7 +10,7 @@ use lib "$RealBin"; use Util; use Parse::Pidl::Util qw(MyDumper); use Parse::Pidl::Samba3::ClientNDR qw(ParseFunction); -use Parse::Pidl::Samba4::NDR::Parser qw(GenerateFunctionInEnv GenerateFunctionOutEnv); +use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv GenerateFunctionOutEnv); # Make sure GenerateFunctionInEnv and GenerateFunctionOutEnv work my $fn = { ELEMENTS => [ { DIRECTION => ["in"], NAME => "foo" } ] }; @@ -29,31 +29,40 @@ my $x = new Parse::Pidl::Samba3::ClientNDR(); $fn = { NAME => "bar", ELEMENTS => [ ] }; $x->ParseFunction("foo", $fn); -is($x->{res}, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx) +is($x->{res}, +"NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx) { \tstruct bar r; \tNTSTATUS status; -\t + \t/* In parameters */ -\t -\tif (DEBUGLEVEL >= 10) + +\tif (DEBUGLEVEL >= 10) { \t\tNDR_PRINT_IN_DEBUG(bar, &r); -\t -\tstatus = cli_do_rpc_ndr(cli, mem_ctx, PI_FOO, &ndr_table_foo, NDR_BAR, &r); -\t +\t} + + status = cli_do_rpc_ndr(cli, + mem_ctx, + PI_FOO, + &ndr_table_foo, + NDR_BAR, + &r); + \tif (!NT_STATUS_IS_OK(status)) { \t\treturn status; \t} -\t -\tif (DEBUGLEVEL >= 10) + +\tif (DEBUGLEVEL >= 10) { \t\tNDR_PRINT_OUT_DEBUG(bar, &r); -\t +\t} + \tif (NT_STATUS_IS_ERR(status)) { \t\treturn status; \t} -\t + \t/* Return variables */ -\t + \t/* Return result */ \treturn NT_STATUS_OK; } @@ -64,36 +73,46 @@ $x = new Parse::Pidl::Samba3::ClientNDR(); $fn = { NAME => "bar", ELEMENTS => [ ], RETURN_TYPE => "WERROR" }; $x->ParseFunction("foo", $fn); -is($x->{res}, "NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, WERROR *werror) +is($x->{res}, +"NTSTATUS rpccli_bar(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + WERROR *werror) { \tstruct bar r; \tNTSTATUS status; -\t + \t/* In parameters */ -\t -\tif (DEBUGLEVEL >= 10) + +\tif (DEBUGLEVEL >= 10) { \t\tNDR_PRINT_IN_DEBUG(bar, &r); -\t -\tstatus = cli_do_rpc_ndr(cli, mem_ctx, PI_FOO, &ndr_table_foo, NDR_BAR, &r); -\t +\t} + + status = cli_do_rpc_ndr(cli, + mem_ctx, + PI_FOO, + &ndr_table_foo, + NDR_BAR, + &r); + \tif (!NT_STATUS_IS_OK(status)) { \t\treturn status; \t} -\t -\tif (DEBUGLEVEL >= 10) + +\tif (DEBUGLEVEL >= 10) { \t\tNDR_PRINT_OUT_DEBUG(bar, &r); -\t +\t} + \tif (NT_STATUS_IS_ERR(status)) { \t\treturn status; \t} -\t + \t/* Return variables */ -\t + \t/* Return result */ \tif (werror) { \t\t*werror = r.out.result; \t} -\t + \treturn werror_to_ntstatus(r.out.result); } diff --git a/source4/pidl/tests/samba3-srv.pl b/source4/pidl/tests/samba3-srv.pl new file mode 100644 index 0000000000..d1e2bc9545 --- /dev/null +++ b/source4/pidl/tests/samba3-srv.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +# (C) 2008 Jelmer Vernooij <jelmer@samba.org> +# Published under the GNU General Public License +use strict; +use warnings; + +use Test::More tests => 1; +use FindBin qw($RealBin); +use lib "$RealBin"; +use Util; +use Parse::Pidl::Util qw(MyDumper has_property); +use Parse::Pidl::Samba3::ServerNDR qw(DeclLevel); + +my $l = { TYPE => "DATA", DATA_TYPE => "uint32" }; +my $e = { FILE => "foo", LINE => 0, PROPERTIES => { }, TYPE => "uint32", + LEVELS => [ $l ] }; + +is("uint32_t", DeclLevel($e, 0)); diff --git a/source4/pidl/tests/typelist.pl b/source4/pidl/tests/typelist.pl index c5c409a525..54f4d34586 100755 --- a/source4/pidl/tests/typelist.pl +++ b/source4/pidl/tests/typelist.pl @@ -4,11 +4,11 @@ use strict; use warnings; -use Test::More tests => 53; +use Test::More tests => 54; use FindBin qw($RealBin); use lib "$RealBin"; use Util; -use Parse::Pidl::Typelist qw(hasType getType mapTypeName expandAlias +use Parse::Pidl::Typelist qw(hasType typeHasBody getType mapTypeName expandAlias mapScalarType addType typeIs is_scalar scalar_is_reference enum_type_fn bitmap_type_fn mapType); @@ -56,7 +56,6 @@ is(1, is_scalar({TYPE => "ENUM"})); is(0, is_scalar({TYPE => "STRUCT"})); is(1, is_scalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM" }})); is(1, is_scalar("mytypedef")); -is(1, is_scalar({TYPE => "DECLARE", DATA => {TYPE => "ENUM" }})); is(1, scalar_is_reference("string")); is(0, scalar_is_reference("uint32")); @@ -81,3 +80,6 @@ is("uint32_t", mapType({TYPE => "TYPEDEF", DATA => {TYPE => "SCALAR"}}, "uint32" is("void", mapTypeName(undef)); is("uint32_t", mapTypeName("uint32")); is("int32_t", mapTypeName("int")); + +ok(not typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT" }})); +ok(typeHasBody({TYPE => "TYPEDEF", DATA => { TYPE => "STRUCT", ELEMENTS => [] }})); |