summaryrefslogtreecommitdiff
path: root/source4/build/pidl/header.pm
diff options
context:
space:
mode:
Diffstat (limited to 'source4/build/pidl/header.pm')
-rw-r--r--source4/build/pidl/header.pm116
1 files changed, 99 insertions, 17 deletions
diff --git a/source4/build/pidl/header.pm b/source4/build/pidl/header.pm
index 34707f8672..783fff2204 100644
--- a/source4/build/pidl/header.pm
+++ b/source4/build/pidl/header.pm
@@ -7,12 +7,23 @@ package IdlHeader;
use Data::Dumper;
my($res);
+my($tab_depth);
+
+sub tabs()
+{
+ for (my($i)=0; $i < $tab_depth; $i++) {
+ $res .= "\t";
+ }
+}
#####################################################################
# dump a properties list
sub DumpProperties($)
{
my($props) = shift;
+
+ return;
+
foreach my $d (@{$props}) {
if (ref($d) ne "HASH") {
$res .= "/* [$d] */ ";
@@ -29,30 +40,48 @@ sub DumpProperties($)
sub DumpElement($)
{
my($element) = shift;
+
+ if (util::has_property($element->{PROPERTIES}, "struct_len")) {
+ # a struct_len is an internal artifact - it is put on the
+ # wire but not exposed via the api, which means it does
+ # not appear in the header file
+ return;
+ }
+
+
(defined $element->{PROPERTIES}) && DumpProperties($element->{PROPERTIES});
- DumpType($element->{TYPE});
+ $res .= tabs();
+ DumpType($element->{TYPE}, "");
$res .= " ";
if ($element->{POINTERS}) {
- for (my($i)=0; $i < $element->{POINTERS}; $i++) {
- $res .= "*";
- }
+ my($n) = $element->{POINTERS};
+ if (util::is_scalar_type($element->{TYPE}) &&
+ util::has_property($element->{PROPERTIES}, "ref")) {
+ $n--;
+ }
+ for (my($i)=$n; $i > 0; $i--) {
+ $res .= "*";
+ }
}
$res .= "$element->{NAME}";
(defined $element->{ARRAY_LEN}) && ($res .= "[$element->{ARRAY_LEN}]");
+ $res .= ";\n";
}
#####################################################################
# dump a struct
-sub DumpStruct($)
+sub DumpStruct($$)
{
my($struct) = shift;
- $res .= "struct {\n";
+ my($name) = shift;
+ $res .= "struct $name {\n";
+ $tab_depth++;
if (defined $struct->{ELEMENTS}) {
foreach my $e (@{$struct->{ELEMENTS}}) {
DumpElement($e);
- $res .= ";\n";
}
}
+ $tab_depth--;
$res .= "}";
}
@@ -64,16 +93,16 @@ sub DumpUnionElement($)
my($element) = shift;
$res .= "/* [case($element->{CASE})] */ ";
DumpElement($element->{DATA});
- $res .= ";\n";
}
#####################################################################
# dump a union
-sub DumpUnion($)
+sub DumpUnion($$)
{
my($union) = shift;
+ my($name) = shift;
(defined $union->{PROPERTIES}) && DumpProperties($union->{PROPERTIES});
- $res .= "union {\n";
+ $res .= "union $name {\n";
foreach my $e (@{$union->{DATA}}) {
DumpUnionElement($e);
}
@@ -82,16 +111,23 @@ sub DumpUnion($)
#####################################################################
# dump a type
-sub DumpType($)
+sub DumpType($$)
{
my($data) = shift;
+ my($name) = shift;
if (ref($data) eq "HASH") {
($data->{TYPE} eq "STRUCT") &&
- DumpStruct($data);
+ DumpStruct($data, $name);
($data->{TYPE} eq "UNION") &&
- DumpUnion($data);
+ DumpUnion($data, $name);
+ return;
+ }
+ if ($data =~ "unistr") {
+ $res .= "const char";
+ } elsif (util::is_scalar_type($data)) {
+ $res .= "$data";
} else {
- $res .= "$data";
+ $res .= "struct $data";
}
}
@@ -100,9 +136,51 @@ sub DumpType($)
sub DumpTypedef($)
{
my($typedef) = shift;
- $res .= "typedef ";
- DumpType($typedef->{DATA});
- $res .= " $typedef->{NAME};\n\n";
+ DumpType($typedef->{DATA}, $typedef->{NAME});
+ $res .= ";\n\n";
+}
+
+#####################################################################
+# dump a function
+sub DumpFunctionInOut($$)
+{
+ my($fn) = shift;
+ my($prop) = shift;
+ foreach my $e (@{$fn->{DATA}}) {
+ if (util::has_property($e->{PROPERTIES}, $prop)) {
+ DumpElement($e);
+ }
+ }
+}
+
+
+#####################################################################
+# dump a function
+sub DumpFunction($)
+{
+ my($fn) = shift;
+ $res .= "struct $fn->{NAME} {\n";
+ $tab_depth++;
+ tabs();
+ $res .= "struct {\n";
+ $tab_depth++;
+ DumpFunctionInOut($fn, "in");
+ $tab_depth--;
+ tabs();
+ $res .= "} in;\n\n";
+ tabs();
+ $res .= "struct {\n";
+ $tab_depth++;
+ DumpFunctionInOut($fn, "out");
+ if ($fn->{RETURN_TYPE}) {
+ tabs();
+ $res .= "$fn->{RETURN_TYPE} result;\n";
+ }
+ $tab_depth--;
+ tabs();
+ $res .= "} out;\n\n";
+ $tab_depth--;
+ $res .= "};\n\n";
}
#####################################################################
@@ -114,6 +192,8 @@ sub DumpInterface($)
foreach my $d (@{$data}) {
($d->{TYPE} eq "TYPEDEF") &&
DumpTypedef($d);
+ ($d->{TYPE} eq "FUNCTION") &&
+ DumpFunction($d);
}
}
@@ -123,6 +203,8 @@ sub DumpInterface($)
sub Dump($)
{
my($idl) = shift;
+ $tab_depth = 0;
+
$res = "/* header auto-generated by pidl */\n\n";
foreach my $x (@{$idl}) {
($x->{TYPE} eq "INTERFACE") &&