summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-08-17 13:01:51 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 15:02:08 -0500
commit3e3e5f85ddb407615e5d6a73fc5ec11acac4108e (patch)
tree0bd46aa98397d99e3ff1d7d7d2e406c262e90b9e /source4/pidl/lib/Parse/Pidl
parenta9531c0e23b622cb96c6c4a61a0df43d12a3cee8 (diff)
downloadsamba-3e3e5f85ddb407615e5d6a73fc5ec11acac4108e.tar.gz
samba-3e3e5f85ddb407615e5d6a73fc5ec11acac4108e.tar.bz2
samba-3e3e5f85ddb407615e5d6a73fc5ec11acac4108e.zip
r24518: get rid of using ->{ORIGINAL} and move stuff
into subfunctions metze (This used to be commit ff7fa11e70018e9691441d824483b803781943a7)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4.pm95
1 files changed, 70 insertions, 25 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4.pm b/source4/pidl/lib/Parse/Pidl/Samba4.pm
index 326ac83751..ebe74d488d 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4.pm
@@ -10,6 +10,7 @@ require Exporter;
@EXPORT = qw(is_intree choose_header DeclLong);
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 strict;
@@ -34,40 +35,84 @@ sub choose_header($$)
return "#include <$out>";
}
+sub NumStars($;$)
+{
+ my ($e, $d) = @_;
+ $d = 0 unless defined($d);
+ my $n = 0;
+
+ foreach my $l (@{$e->{LEVELS}}) {
+ next unless ($l->{TYPE} eq "POINTER");
+
+ my $nl = GetNextLevel($e, $l);
+ next if (defined($nl) and $nl->{TYPE} eq "ARRAY");
+
+ $n++;
+ }
+
+ if ($n >= 1) {
+ $n-- if (scalar_is_reference($e->{TYPE}));
+ }
+
+ foreach my $l (@{$e->{LEVELS}}) {
+ next unless ($l->{TYPE} eq "ARRAY");
+ next if ($l->{IS_FIXED}) and not has_property($e, "charset");
+ $n++;
+ }
+
+ fatal($e->{ORIGINAL}, "Too few pointers $n < $d") if ($n < $d);
+
+ $n -= $d;
+
+ return $n;
+}
+
+sub ElementStars($;$)
+{
+ my ($e, $d) = @_;
+ my $res = "";
+ my $n = 0;
+
+ $n = NumStars($e, $d);
+ $res .= "*" foreach (1..$n);
+
+ return $res;
+}
+
+sub ArrayBrackets($)
+{
+ my ($e) = @_;
+ my $res = "";
+
+ foreach my $l (@{$e->{LEVELS}}) {
+ next unless ($l->{TYPE} eq "ARRAY");
+ next unless ($l->{IS_FIXED}) and not has_property($e, "charset");
+ $res .= "[$l->{SIZE_IS}]";
+ }
+
+ return $res;
+}
+
sub DeclLong($)
{
- my($element) = shift;
- my $ret = "";
+ my ($e, $d) = shift;
+ my $res = "";
- if (has_property($element, "represent_as")) {
- $ret.=mapTypeName($element->{PROPERTIES}->{represent_as})." ";
+ if (has_property($e, "represent_as")) {
+ $res .= mapTypeName($e->{PROPERTIES}->{represent_as})." ";
} else {
- if (has_property($element, "charset")) {
- $ret.="const char";
+ if (has_property($e, "charset")) {
+ $res .= "const char ";
} else {
- $ret.=mapTypeName($element->{TYPE});
+ $res .= mapTypeName($e->{TYPE})." ";
}
- $ret.=" ";
- my $numstar = $element->{ORIGINAL}->{POINTERS};
- if ($numstar >= 1) {
- $numstar-- if scalar_is_reference($element->{TYPE});
- }
- foreach (@{$element->{ORIGINAL}->{ARRAY_LEN}})
- {
- next if is_constant($_) and
- not has_property($element, "charset");
- $numstar++;
- }
- $ret.="*" foreach (1..$numstar);
- }
- $ret.=$element->{NAME};
- foreach (@{$element->{ORIGINAL}->{ARRAY_LEN}}) {
- next unless (is_constant($_) and not has_property($element, "charset"));
- $ret.="[$_]";
+ $res .= ElementStars($e);
}
+ $res .= $e->{NAME};
+ $res .= ArrayBrackets($e);
- return $ret;
+ return $res;
}
1;