1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

r21430: Support tagged types without typedef. This means:

struct foo {
 ...
};

in IDL will now work. This is the first step towards nested types and
using typedefs for partial types (such as "typedef int *bar;"), a requirement
for complex uses of represent_as().
(This used to be commit a716aa70f0)
This commit is contained in:
Jelmer Vernooij 2007-02-18 16:21:28 +00:00 committed by Gerald (Jerry) Carter
parent 069f0cc15b
commit 8cf122c2d2
13 changed files with 1305 additions and 1226 deletions

View File

@ -7,10 +7,11 @@
- strip out pidl-specific properties
- support nested elements
- generate names for anonymous tagged types
- allow non-typedef structs
- generate names for anonymous tagged types. Simple MD5Sum of contents?
- support typedefs properly
- improve represent_as(): allow it to be used for arrays and other complex types
- improve represent_as(): allow it to be used for arrays and other complex
types
- --explain-ndr option that dumps out parse tree ?

View File

@ -160,10 +160,10 @@ decl_union: 'union'
}}
;
typedef: 'typedef' property_list type identifier array_len ';'
typedef: property_list 'typedef' type identifier array_len ';'
{{
"TYPE" => "TYPEDEF",
"PROPERTIES" => $_[2],
"PROPERTIES" => $_[1],
"NAME" => $_[4],
"DATA" => $_[3],
"ARRAY_LEN" => $_[5],
@ -187,11 +187,12 @@ type: usertype | existingtype | void { "void" } ;
enum_body: '{' enum_elements '}' { $_[2] };
opt_enum_body: | enum_body;
enum: 'enum' optional_identifier opt_enum_body
enum: property_list 'enum' optional_identifier opt_enum_body
{{
"TYPE" => "ENUM",
"NAME" => $_[2],
"ELEMENTS" => $_[3]
"PROPERTIES" => $_[1],
"NAME" => $_[3],
"ELEMENTS" => $_[4]
}}
;
@ -206,11 +207,12 @@ enum_element: identifier
bitmap_body: '{' opt_bitmap_elements '}' { $_[2] };
opt_bitmap_body: | bitmap_body;
bitmap: 'bitmap' optional_identifier opt_bitmap_body
bitmap: property_list 'bitmap' optional_identifier opt_bitmap_body
{{
"TYPE" => "BITMAP",
"NAME" => $_[2],
"ELEMENTS" => $_[3]
"PROPERTIES" => $_[1],
"NAME" => $_[3],
"ELEMENTS" => $_[4]
}}
;
@ -227,11 +229,12 @@ bitmap_element: identifier '=' anytext { "$_[1] ( $_[3] )" }
struct_body: '{' element_list1 '}' { $_[2] };
opt_struct_body: | struct_body;
struct: 'struct' optional_identifier opt_struct_body
struct: property_list 'struct' optional_identifier opt_struct_body
{{
"TYPE" => "STRUCT",
"NAME" => $_[2],
"ELEMENTS" => $_[3]
"PROPERTIES" => $_[1],
"NAME" => $_[3],
"ELEMENTS" => $_[4]
}}
;
@ -261,11 +264,12 @@ union_elements:
union_body: '{' union_elements '}' { $_[2] };
opt_union_body: | union_body;
union: 'union' optional_identifier opt_union_body
union: property_list 'union' optional_identifier opt_union_body
{{
"TYPE" => "UNION",
"NAME" => $_[2],
"ELEMENTS" => $_[3]
"PROPERTIES" => $_[1],
"NAME" => $_[3],
"ELEMENTS" => $_[4]
}}
;

View File

@ -1127,7 +1127,7 @@ sub new {
[#Rule 2
'exp', 1,
sub
#line 22 "expr.yp"
#line 22 "pidl/expr.yp"
{ "\"$_[1]\"" }
],
[#Rule 3
@ -1139,199 +1139,199 @@ sub
[#Rule 5
'exp', 2,
sub
#line 25 "expr.yp"
#line 25 "pidl/expr.yp"
{ "~$_[2]" }
],
[#Rule 6
'exp', 3,
sub
#line 26 "expr.yp"
#line 26 "pidl/expr.yp"
{ "$_[1] + $_[3]" }
],
[#Rule 7
'exp', 3,
sub
#line 27 "expr.yp"
#line 27 "pidl/expr.yp"
{ "$_[1] - $_[3]" }
],
[#Rule 8
'exp', 3,
sub
#line 28 "expr.yp"
#line 28 "pidl/expr.yp"
{ "$_[1] * $_[3]" }
],
[#Rule 9
'exp', 3,
sub
#line 29 "expr.yp"
#line 29 "pidl/expr.yp"
{ "$_[1] % $_[3]" }
],
[#Rule 10
'exp', 3,
sub
#line 30 "expr.yp"
#line 30 "pidl/expr.yp"
{ "$_[1] < $_[3]" }
],
[#Rule 11
'exp', 3,
sub
#line 31 "expr.yp"
#line 31 "pidl/expr.yp"
{ "$_[1] > $_[3]" }
],
[#Rule 12
'exp', 3,
sub
#line 32 "expr.yp"
#line 32 "pidl/expr.yp"
{ "$_[1] | $_[3]" }
],
[#Rule 13
'exp', 3,
sub
#line 33 "expr.yp"
#line 33 "pidl/expr.yp"
{ "$_[1] == $_[3]" }
],
[#Rule 14
'exp', 3,
sub
#line 34 "expr.yp"
#line 34 "pidl/expr.yp"
{ "$_[1] <= $_[3]" }
],
[#Rule 15
'exp', 3,
sub
#line 35 "expr.yp"
#line 35 "pidl/expr.yp"
{ "$_[1] => $_[3]" }
],
[#Rule 16
'exp', 3,
sub
#line 36 "expr.yp"
#line 36 "pidl/expr.yp"
{ "$_[1] << $_[3]" }
],
[#Rule 17
'exp', 3,
sub
#line 37 "expr.yp"
#line 37 "pidl/expr.yp"
{ "$_[1] >> $_[3]" }
],
[#Rule 18
'exp', 3,
sub
#line 38 "expr.yp"
#line 38 "pidl/expr.yp"
{ "$_[1] != $_[3]" }
],
[#Rule 19
'exp', 3,
sub
#line 39 "expr.yp"
#line 39 "pidl/expr.yp"
{ "$_[1] || $_[3]" }
],
[#Rule 20
'exp', 3,
sub
#line 40 "expr.yp"
#line 40 "pidl/expr.yp"
{ "$_[1] && $_[3]" }
],
[#Rule 21
'exp', 3,
sub
#line 41 "expr.yp"
#line 41 "pidl/expr.yp"
{ "$_[1] & $_[3]" }
],
[#Rule 22
'exp', 5,
sub
#line 42 "expr.yp"
#line 42 "pidl/expr.yp"
{ "$_[1]?$_[3]:$_[5]" }
],
[#Rule 23
'exp', 2,
sub
#line 43 "expr.yp"
#line 43 "pidl/expr.yp"
{ "~$_[1]" }
],
[#Rule 24
'exp', 2,
sub
#line 44 "expr.yp"
#line 44 "pidl/expr.yp"
{ "not $_[1]" }
],
[#Rule 25
'exp', 3,
sub
#line 45 "expr.yp"
#line 45 "pidl/expr.yp"
{ "$_[1] / $_[3]" }
],
[#Rule 26
'exp', 2,
sub
#line 46 "expr.yp"
#line 46 "pidl/expr.yp"
{ "-$_[2]" }
],
[#Rule 27
'exp', 2,
sub
#line 47 "expr.yp"
#line 47 "pidl/expr.yp"
{ "&$_[2]" }
],
[#Rule 28
'exp', 3,
sub
#line 48 "expr.yp"
#line 48 "pidl/expr.yp"
{ "$_[1]^$_[3]" }
],
[#Rule 29
'exp', 3,
sub
#line 49 "expr.yp"
#line 49 "pidl/expr.yp"
{ "($_[2])" }
],
[#Rule 30
'possible_pointer', 1,
sub
#line 53 "expr.yp"
#line 53 "pidl/expr.yp"
{ $_[0]->_Lookup($_[1]) }
],
[#Rule 31
'possible_pointer', 2,
sub
#line 54 "expr.yp"
#line 54 "pidl/expr.yp"
{ $_[0]->_Dereference($_[2]); "*$_[2]" }
],
[#Rule 32
'var', 1,
sub
#line 57 "expr.yp"
#line 57 "pidl/expr.yp"
{ $_[0]->_Use($_[1]) }
],
[#Rule 33
'var', 3,
sub
#line 58 "expr.yp"
#line 58 "pidl/expr.yp"
{ $_[0]->_Use("$_[1].$_[3]") }
],
[#Rule 34
'var', 3,
sub
#line 59 "expr.yp"
#line 59 "pidl/expr.yp"
{ "($_[2])" }
],
[#Rule 35
'var', 3,
sub
#line 60 "expr.yp"
#line 60 "pidl/expr.yp"
{ $_[0]->_Use("*$_[1]"); $_[1]."->".$_[3] }
],
[#Rule 36
'func', 4,
sub
#line 64 "expr.yp"
#line 64 "pidl/expr.yp"
{ "$_[1]($_[3])" }
],
[#Rule 37
'opt_args', 0,
sub
#line 65 "expr.yp"
#line 65 "pidl/expr.yp"
{ "" }
],
[#Rule 38
@ -1349,7 +1349,7 @@ sub
[#Rule 42
'args', 3,
sub
#line 68 "expr.yp"
#line 68 "pidl/expr.yp"
{ "$_[1], $_[3]" }
]
],
@ -1357,7 +1357,7 @@ sub
bless($self,$class);
}
#line 71 "expr.yp"
#line 71 "pidl/expr.yp"
package Parse::Pidl::Expr;

File diff suppressed because it is too large Load Diff

View File

@ -383,6 +383,7 @@ sub ParseStruct($$)
my @elements = ();
my $surrounding = undef;
foreach my $x (@{$struct->{ELEMENTS}})
{
my $e = ParseElement($x);
@ -403,13 +404,20 @@ sub ParseStruct($$)
&& property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) {
$surrounding = $struct->{ELEMENTS}[-1];
}
my $align = undef;
if ($struct->{NAME}) {
$align = align_type($struct->{NAME});
}
return {
TYPE => "STRUCT",
NAME => $struct->{NAME},
SURROUNDING_ELEMENT => $surrounding,
ELEMENTS => \@elements,
PROPERTIES => $struct->{PROPERTIES},
ORIGINAL => $struct
ORIGINAL => $struct,
ALIGN => $align
};
}
@ -444,6 +452,7 @@ sub ParseUnion($$)
return {
TYPE => "UNION",
NAME => $e->{NAME},
SWITCH_TYPE => $switch_type,
ELEMENTS => \@elements,
PROPERTIES => $e->{PROPERTIES},
@ -458,6 +467,7 @@ sub ParseEnum($$)
return {
TYPE => "ENUM",
NAME => $e->{NAME},
BASE_TYPE => Parse::Pidl::Typelist::enum_type_fn($e),
ELEMENTS => $e->{ELEMENTS},
PROPERTIES => $e->{PROPERTIES},
@ -471,6 +481,7 @@ sub ParseBitmap($$)
return {
TYPE => "BITMAP",
NAME => $e->{NAME},
BASE_TYPE => Parse::Pidl::Typelist::bitmap_type_fn($e),
ELEMENTS => $e->{ELEMENTS},
PROPERTIES => $e->{PROPERTIES},
@ -501,8 +512,8 @@ sub ParseTypedef($$)
{
my ($ndr,$d) = @_;
if (defined($d->{PROPERTIES}) && !defined($d->{DATA}->{PROPERTIES})) {
$d->{DATA}->{PROPERTIES} = $d->{PROPERTIES};
if (defined($d->{DATA}->{PROPERTIES}) && !defined($d->{PROPERTIES})) {
$d->{PROPERTIES} = $d->{DATA}->{PROPERTIES};
}
my $data = ParseType($ndr, $d->{DATA});
@ -865,7 +876,7 @@ sub mapToScalar($)
}
#####################################################################
# parse a struct
# validate an element
sub ValidElement($)
{
my $e = shift;
@ -881,8 +892,8 @@ sub ValidElement($)
fatal($e, el_name($e) . ": switch_is() used on non-union type $e->{TYPE} which is a $type->{DATA}->{TYPE}");
}
if (!has_property($type, "nodiscriminant") and defined($e2)) {
my $discriminator_type = has_property($type, "switch_type");
if (not has_property($type->{DATA}, "nodiscriminant") and defined($e2)) {
my $discriminator_type = has_property($type->{DATA}, "switch_type");
$discriminator_type = "uint32" unless defined ($discriminator_type);
my $t1 = mapToScalar($discriminator_type);
@ -940,12 +951,30 @@ sub ValidElement($)
}
#####################################################################
# parse a struct
# validate an enum
sub ValidEnum($)
{
my ($enum) = @_;
ValidProperties($enum, "ENUM");
}
#####################################################################
# validate a bitmap
sub ValidBitmap($)
{
my ($bitmap) = @_;
ValidProperties($bitmap, "BITMAP");
}
#####################################################################
# validate a struct
sub ValidStruct($)
{
my($struct) = shift;
ValidProperties($struct,"STRUCT");
ValidProperties($struct, "STRUCT");
foreach my $e (@{$struct->{ELEMENTS}}) {
$e->{PARENT} = $struct;
@ -994,23 +1023,15 @@ sub ValidTypedef($)
my($typedef) = shift;
my $data = $typedef->{DATA};
ValidProperties($typedef,"TYPEDEF");
ValidProperties($typedef, "TYPEDEF");
$data->{PARENT} = $typedef;
if (ref($data) eq "HASH") {
if ($data->{TYPE} eq "STRUCT") {
ValidStruct($data);
}
if ($data->{TYPE} eq "UNION") {
ValidUnion($data);
}
}
ValidType($data) if (ref($data) eq "HASH");
}
#####################################################################
# parse a function
# validate a function
sub ValidFunction($)
{
my($fn) = shift;
@ -1026,6 +1047,21 @@ sub ValidFunction($)
}
}
#####################################################################
# validate a type
sub ValidType($)
{
my ($t) = @_;
{
TYPEDEF => \&ValidTypedef,
STRUCT => \&ValidStruct,
UNION => \&ValidUnion,
ENUM => \&ValidEnum,
BITMAP => \&ValidBitmap
}->{$t->{TYPE}}->($t);
}
#####################################################################
# parse the interface definitions
sub ValidInterface($)
@ -1059,10 +1095,12 @@ sub ValidInterface($)
}
foreach my $d (@{$data}) {
($d->{TYPE} eq "TYPEDEF") &&
ValidTypedef($d);
($d->{TYPE} eq "FUNCTION") &&
ValidFunction($d);
($d->{TYPE} eq "FUNCTION") && ValidFunction($d);
($d->{TYPE} eq "TYPEDEF" or
$d->{TYPE} eq "STRUCT" or
$d->{TYPE} eq "UNION" or
$d->{TYPE} eq "ENUM" or
$d->{TYPE} eq "BITMAP") && ValidType($d);
}
}

View File

@ -219,8 +219,6 @@ sub HeaderTypedef($)
{
my($typedef) = shift;
HeaderType($typedef, $typedef->{DATA}, $typedef->{NAME});
pidl ";\n\n" unless ($typedef->{DATA}->{TYPE} eq "BITMAP" or
$typedef->{DATA}->{TYPE} eq "ENUM");
}
#####################################################################
@ -354,8 +352,12 @@ sub HeaderInterface($)
}
foreach my $d (@{$interface->{DATA}}) {
next if ($d->{TYPE} ne "TYPEDEF");
HeaderTypedef($d);
HeaderTypedef($d) if ($d->{TYPE} eq "TYPEDEF");
HeaderStruct($d, $d->{NAME}) if ($d->{TYPE} eq "STRUCT");
HeaderUnion($d, $d->{NAME}) if ($d->{TYPE} eq "UNION");
HeaderEnum($d, $d->{NAME}) if ($d->{TYPE} eq "ENUM");
HeaderBitmap($d, $d->{NAME}) if ($d->{TYPE} eq "BITMAP");
pidl ";\n\n";
}
foreach my $d (@{$interface->{DATA}}) {

View File

@ -12,7 +12,7 @@ require Exporter;
@EXPORT = qw(is_charset_array);
@EXPORT_OK = qw(check_null_pointer GenerateFunctionInEnv
GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv NeededFunction
NeededElement NeededTypedef);
NeededElement NeededType);
use strict;
use Parse::Pidl::Typelist qw(hasType getType mapType);
@ -1335,10 +1335,10 @@ sub ParseEnumPrint($$)
end_flags($enum);
}
sub DeclEnum($)
sub DeclEnum($$$)
{
my ($e,$t) = @_;
return "enum $e->{NAME} " .
my ($e,$t,$name) = @_;
return "enum $name " .
($t eq "pull"?"*":"") . "r";
}
@ -1418,10 +1418,10 @@ sub ParseBitmapPrint($$)
end_flags($bitmap);
}
sub DeclBitmap($$)
sub DeclBitmap($$$)
{
my ($e,$t) = @_;
return mapType(Parse::Pidl::Typelist::bitmap_type_fn($e->{DATA})) .
my ($e,$t,$name) = @_;
return mapType(Parse::Pidl::Typelist::bitmap_type_fn($e)) .
($t eq "pull"?" *":" ") . "r";
}
@ -1581,27 +1581,27 @@ sub ParseStructPull($$)
#####################################################################
# calculate size of ndr struct
sub ParseStructNdrSize($)
sub ParseStructNdrSize($$)
{
my $t = shift;
my ($t, $name) = @_;
my $sizevar;
if (my $flags = has_property($t, "flag")) {
pidl "flags |= $flags;";
}
pidl "return ndr_size_struct(r, flags, (ndr_push_flags_fn_t)ndr_push_$t->{NAME});";
pidl "return ndr_size_struct(r, flags, (ndr_push_flags_fn_t)ndr_push_$name);";
}
sub DeclStruct($)
sub DeclStruct($$$)
{
my ($e,$t) = @_;
return ($t ne "pull"?"const ":"") . "struct $e->{NAME} *r";
my ($e,$t,$name) = @_;
return ($t ne "pull"?"const ":"") . "struct $name *r";
}
sub ArgsStructNdrSize($)
sub ArgsStructNdrSize($$)
{
my $d = shift;
return "const struct $d->{NAME} *r, int flags";
my ($d, $name) = @_;
return "const struct $name *r, int flags";
}
$typefamily{STRUCT} = {
@ -1615,16 +1615,16 @@ $typefamily{STRUCT} = {
#####################################################################
# calculate size of ndr struct
sub ParseUnionNdrSize($)
sub ParseUnionNdrSize($$)
{
my $t = shift;
my ($t, $name) = @_;
my $sizevar;
if (my $flags = has_property($t, "flag")) {
pidl "flags |= $flags;";
}
pidl "return ndr_size_union(r, flags, level, (ndr_push_flags_fn_t)ndr_push_$t->{NAME});";
pidl "return ndr_size_union(r, flags, level, (ndr_push_flags_fn_t)ndr_push_$name);";
}
#####################################################################
@ -1864,16 +1864,16 @@ sub ParseUnionPull($$)
pidl "ndr_pull_restore_relative_base_offset(ndr, _save_relative_base_offset);" if defined($e->{PROPERTIES}{relative_base});
}
sub DeclUnion($$)
sub DeclUnion($$$)
{
my ($e,$t) = @_;
return ($t ne "pull"?"const ":"") . "union $e->{NAME} *r";
my ($e,$t,$name) = @_;
return ($t ne "pull"?"const ":"") . "union $name *r";
}
sub ArgsUnionNdrSize($)
sub ArgsUnionNdrSize($$)
{
my $d = shift;
return "const union $d->{NAME} *r, uint32_t level, int flags";
my ($d,$name) = @_;
return "const union $name *r, uint32_t level, int flags";
}
$typefamily{UNION} = {
@ -1887,81 +1887,62 @@ $typefamily{UNION} = {
#####################################################################
# parse a typedef - push side
sub ParseTypedefPush($)
sub ParseTypedefPush($$)
{
my($e) = shift;
my($e,$name) = @_;
my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"push");
fn_declare("push", $e, "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
$typefamily{$e->{DATA}->{TYPE}}->{PUSH_FN_BODY}->($e->{DATA}, $e->{NAME});
pidl "return NT_STATUS_OK;";
deindent;
pidl "}";
pidl "";;
$typefamily{$e->{DATA}->{TYPE}}->{PUSH_FN_BODY}->($e->{DATA}, $name);
}
#####################################################################
# parse a typedef - pull side
sub ParseTypedefPull($)
sub ParseTypedefPull($$)
{
my($e) = shift;
my($e,$name) = @_;
my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"pull");
fn_declare("pull", $e, "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
$typefamily{$e->{DATA}->{TYPE}}->{PULL_FN_BODY}->($e->{DATA}, $e->{NAME});
pidl "return NT_STATUS_OK;";
deindent;
pidl "}";
pidl "";
$typefamily{$e->{DATA}->{TYPE}}->{PULL_FN_BODY}->($e->{DATA}, $name);
}
#####################################################################
# parse a typedef - print side
sub ParseTypedefPrint($)
sub ParseTypedefPrint($$)
{
my($e) = shift;
my($e,$name) = @_;
my $args = $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e,"print");
pidl_hdr "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args);";
return if (has_property($e, "noprint"));
pidl "_PUBLIC_ void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args)";
pidl "{";
indent;
$typefamily{$e->{DATA}->{TYPE}}->{PRINT_FN_BODY}->($e->{DATA}, $e->{NAME});
deindent;
pidl "}";
pidl "";
$typefamily{$e->{DATA}->{TYPE}}->{PRINT_FN_BODY}->($e->{DATA}, $name);
}
#####################################################################
## calculate the size of a structure
sub ParseTypedefNdrSize($)
sub ParseTypedefNdrSize($$)
{
my($t) = shift;
my($t,$name) = @_;
my $tf = $typefamily{$t->{DATA}->{TYPE}};
my $args = $tf->{SIZE_FN_ARGS}->($t);
fn_declare("size", $t, "size_t ndr_size_$t->{NAME}($args)") or return;
pidl "{";
indent;
$typefamily{$t->{DATA}->{TYPE}}->{SIZE_FN_BODY}->($t);
deindent;
pidl "}";
pidl "";
$typefamily{$t->{DATA}->{TYPE}}->{SIZE_FN_BODY}->($t->{DATA}, $name);
}
sub DeclTypedef($$$)
{
my ($e, $t, $name) = @_;
return $typefamily{$e->{DATA}->{TYPE}}->{DECL}->($e->{DATA}, $t, $name);
}
sub ArgsTypedefNdrSize($$)
{
my ($d, $name) = @_;
return $typefamily{$d->{DATA}->{TYPE}}->{SIZE_FN_ARGS}->($d->{DATA}, $name);
}
$typefamily{TYPEDEF} = {
PUSH_FN_BODY => \&ParseTypedefPush,
DECL => \&DeclTypedef,
PULL_FN_BODY => \&ParseTypedefPull,
PRINT_FN_BODY => \&ParseTypedefPrint,
SIZE_FN_ARGS => \&ArgsTypedefNdrSize,
SIZE_FN_BODY => \&ParseTypedefNdrSize,
};
#####################################################################
# parse a function - print side
sub ParseFunctionPrint($)
@ -2379,6 +2360,74 @@ sub HeaderInterface($)
}
sub ParseTypePush($)
{
my ($e) = @_;
my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "push", $e->{NAME});
fn_declare("push", $e, "NTSTATUS ndr_push_$e->{NAME}(struct ndr_push *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
$typefamily{$e->{TYPE}}->{PUSH_FN_BODY}->($e, $e->{NAME});
pidl "return NT_STATUS_OK;";
deindent;
pidl "}";
pidl "";;
}
sub ParseTypePull($)
{
my ($e) = @_;
my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "pull", $e->{NAME});
fn_declare("pull", $e, "NTSTATUS ndr_pull_$e->{NAME}(struct ndr_pull *ndr, int ndr_flags, $args)") or return;
pidl "{";
indent;
$typefamily{$e->{TYPE}}->{PULL_FN_BODY}->($e, $e->{NAME});
pidl "return NT_STATUS_OK;";
deindent;
pidl "}";
pidl "";
}
sub ParseTypePrint($)
{
my ($e) = @_;
my $args = $typefamily{$e->{TYPE}}->{DECL}->($e, "print", $e->{NAME});
pidl_hdr "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args);";
return if (has_property($e, "noprint"));
pidl "_PUBLIC_ void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, $args)";
pidl "{";
indent;
$typefamily{$e->{TYPE}}->{PRINT_FN_BODY}->($e, $e->{NAME});
deindent;
pidl "}";
pidl "";
}
sub ParseTypeNdrSize($)
{
my ($t) = @_;
my $tf = $typefamily{$t->{TYPE}};
my $args = $tf->{SIZE_FN_ARGS}->($t, $t->{NAME});
fn_declare("size", $t, "size_t ndr_size_$t->{NAME}($args)") or return;
pidl "{";
indent;
$typefamily{$t->{TYPE}}->{SIZE_FN_BODY}->($t, $t->{NAME});
deindent;
pidl "}";
pidl "";
}
#####################################################################
# parse the interface definitions
sub ParseInterface($$)
@ -2398,15 +2447,15 @@ sub ParseInterface($$)
# Typedefs
foreach my $d (@{$interface->{TYPES}}) {
($needed->{"push_$d->{NAME}"}) && ParseTypedefPush($d);
($needed->{"pull_$d->{NAME}"}) && ParseTypedefPull($d);
($needed->{"print_$d->{NAME}"}) && ParseTypedefPrint($d);
($needed->{"push_$d->{NAME}"}) && ParseTypePush($d);
($needed->{"pull_$d->{NAME}"}) && ParseTypePull($d);
($needed->{"print_$d->{NAME}"}) && ParseTypePrint($d);
# Make sure we don't generate a function twice...
$needed->{"push_$d->{NAME}"} = $needed->{"pull_$d->{NAME}"} =
$needed->{"print_$d->{NAME}"} = 0;
($needed->{"ndr_size_$d->{NAME}"}) && ParseTypedefNdrSize($d);
($needed->{"ndr_size_$d->{NAME}"}) && ParseTypeNdrSize($d);
}
# Functions
@ -2524,7 +2573,7 @@ sub NeededFunction($$)
}
}
sub NeededTypedef($$)
sub NeededType($$)
{
my ($t,$needed) = @_;
if (has_property($t, "public")) {
@ -2556,7 +2605,7 @@ sub NeededInterface($$)
{
my ($interface,$needed) = @_;
NeededFunction($_, $needed) foreach (@{$interface->{FUNCTIONS}});
NeededTypedef($_, $needed) foreach (reverse @{$interface->{TYPES}});
NeededType($_, $needed) foreach (reverse @{$interface->{TYPES}});
}
1;

View File

@ -91,7 +91,6 @@ SKIP: {
my $cmd = "$cc $cflags -x c - -o $outfile $flags $ldflags";
$cmd =~ s/\n//g;
print "$cmd\n";
open CC, "|$cmd";
print CC "#define uint_t unsigned int\n";
print CC "#define _GNU_SOURCE\n";

View File

@ -4,7 +4,7 @@
use strict;
use warnings;
use Test::More tests => 9;
use Test::More tests => 10;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
@ -34,3 +34,5 @@ like(parse_idl("interface x { void foo ([out] uint32 x); };"),
like(parse_idl("interface x { void foo ([in,out] uint32 x); };"),
qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} in;\s+struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn in,out arg works");
like(parse_idl("interface x { void foo (uint32 x); };"), qr/struct foo.*{.*struct\s+{\s+uint32_t x;\s+} in;\s+struct\s+{\s+uint32_t x;\s+} out;.*};/sm, "fn with no props implies in,out");
like(parse_idl("interface p { struct x { int y; }; };"),
qr/struct x.*{.*int32_t y;.*}.*;/sm, "interface member generated properly");

View File

@ -24,5 +24,3 @@ my $e = {
test_warnings("foo.idl:42: subcontext() is deprecated. Use represent_as() or transmit_as() instead\n",
sub { ValidElement($e); });

View File

@ -8,15 +8,7 @@ use FindBin qw($RealBin);
use lib "$RealBin";
use Util qw(test_samba4_ndr);
SKIP: {
skip "Tagged types without typedef are not supported yet", 8;
test_samba4_ndr('struct-notypedef',
'
struct bla {
uint8 x;
};
',
test_samba4_ndr('struct-notypedef', '[public] struct bla { uint8 x; }; ',
'
struct ndr_push *ndr = ndr_push_init_ctx(NULL);
struct bla r;
@ -33,5 +25,3 @@ test_samba4_ndr('struct-notypedef',
if (!data_blob_equal(&result_blob, &expected_blob))
return 2;
');
}

View File

@ -4,7 +4,7 @@
# Published under the GNU General Public License
use strict;
use Test::More tests => 59 * 2;
use Test::More tests => 62 * 2;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util qw(test_errors);
@ -83,8 +83,12 @@ testok "nested1", "interface test { struct x { struct { int a; } z; }; };";
testok "nested2", "interface test { struct x { struct y { int a; } z; }; };";
testok "bitmap1", "interface test { bitmap x { a=1 }; };";
testok "unsigned", "interface test { struct x { unsigned short y; }; };";
testok "struct-property", "interface test { [public] struct x { short y; }; };";
testok "signed", "interface test { struct x { signed short y; }; };";
testok "declarg", "interface test { void test(struct { int x; } a); };";
testok "structarg", "interface test { void test(struct a b); };";
testfail "structargmissing", "interface test { void test(struct a); };",
"<structargmissing>:0: Syntax error near ')'\n";
testok "structqual", "interface test { struct x { struct y z; }; };";
testok "unionqual", "interface test { struct x { union y z; }; };";
testok "enumqual", "interface test { struct x { enum y z; }; };";

View File

@ -11,7 +11,7 @@ use Util;
use Parse::Pidl::Util qw(MyDumper);
use Parse::Pidl::Samba4::NDR::Parser qw(check_null_pointer
GenerateFunctionInEnv GenerateFunctionOutEnv GenerateStructEnv
EnvSubstituteValue NeededFunction NeededElement NeededTypedef);
EnvSubstituteValue NeededFunction NeededElement NeededType);
my $output;
sub print_fn($) { my $x = shift; $output.=$x; }
@ -202,19 +202,19 @@ is_deeply($needed, { pull_foo => 1, print_foo => 1, push_foo => 1,
# public structs are always needed
$needed = {};
NeededTypedef({ NAME => "bla", DATA => { TYPE => "STRUCT", ELEMENTS => [] } },
NeededType({ NAME => "bla", DATA => { TYPE => "STRUCT", ELEMENTS => [] } },
$needed);
is_deeply($needed, { });
$needed = {};
NeededTypedef({ PROPERTIES => { public => 1 }, NAME => "bla",
NeededType({ PROPERTIES => { public => 1 }, NAME => "bla",
DATA => { TYPE => "STRUCT", ELEMENTS => [] } },
$needed);
is_deeply($needed, { pull_bla => 1, print_bla => 1, push_bla => 1 });
# make sure types for elements are set too
$needed = {};
NeededTypedef({ PROPERTIES => { public => 1 }, NAME => "bla",
NeededType({ PROPERTIES => { public => 1 }, NAME => "bla",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] } },
$needed);
@ -222,7 +222,7 @@ is_deeply($needed, { pull_bla => 1, print_bla => 1, push_bla => 1,
pull_bar => 1, print_bar => 1, push_bar => 1});
$needed = {};
NeededTypedef({ PROPERTIES => { gensize => 1}, NAME => "bla",
NeededType({ PROPERTIES => { gensize => 1}, NAME => "bla",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] } },
$needed);
@ -230,14 +230,14 @@ is_deeply($needed, { ndr_size_bla => 1 });
# make sure types for elements are set too
$needed = { pull_bla => 1 };
NeededTypedef({ NAME => "bla",
NeededType({ NAME => "bla",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "bar" } ] } },
$needed);
is_deeply($needed, { pull_bla => 1, pull_bar => 1 });
$needed = {};
NeededTypedef({ PROPERTIES => { public => 1},
NeededType({ PROPERTIES => { public => 1},
NAME => "bla",
DATA => { TYPE => "STRUCT",
ELEMENTS => [ { TYPE => "bar", REPRESENTATION_TYPE => "rep" } ] } },