File: ProcImpl.pm

package info (click to toggle)
aspell 0.60.8.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,336 kB
  • sloc: cpp: 24,378; sh: 12,340; perl: 1,924; ansic: 1,661; makefile: 852; sed: 16
file content (158 lines) | stat: -rw-r--r-- 5,605 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# This file is part of The New Aspell
# Copyright (C) 2001-2002 by Kevin Atkinson under the GNU LGPL
# license version 2.0 or 2.1.  You should have received a copy of the
# LGPL license along with this library if you did not you can find it
# at http://www.gnu.org/.

package MkSrc::ProcImpl;

BEGIN {
  use Exporter;
  our @ISA = qw(Exporter);
}

use strict;
use warnings;
no warnings qw(uninitialized);
no locale;

use MkSrc::Util;
use MkSrc::CcHelper;
use MkSrc::Info;
use MkSrc::Create;

$info{forward}{proc}{impl} = sub {
  my ($type) = @_;
  return "$type->{type} ".to_mixed($type->{name}).";\n";
};

$info{group}{proc}{impl} = sub {
  my ($data) = @_;
  create_cc_file (type => 'impl',
		  cxx => true,
		  namespace => 'acommon',
		  dir => "lib",
		  pre_ext => "-c",
		  header => false,
		  data => $data,
		  accum => {headers => {$data->{name} => true} }
		  );
};

$info{class}{proc}{impl} = sub {
  my ($data, $accum) = @_;
  my $ret;
  foreach (grep {$_ ne ''} split /\s*,\s*/, $data->{'c impl headers'}) {
    $accum->{headers}{$_} = true;
  }
  my @d = @{$data->{data}};
  while (@d) {
    my $d = shift @d;
    my $need_wide = false;
    next unless one_of $d->{type}, qw(method constructor destructor);
    my @parms = @{$d->{data}} if exists $d->{data};
    my $m = make_c_method $data->{name}, $d, {mode=>'cc_cxx', use_name=>true, wide=>$d->{wide}}, %$accum;
    next unless defined $m;
    $ret .= "extern \"C\" $m\n";
    $ret .= "{\n";
    if (exists $d->{'c impl'}) {
      $ret .= cmap {"  $_\n"} split /\n/, $d->{'c impl'};
    } else {
      if ($d->{type} eq 'method') {
	my $ret_type = shift @parms;
	my $ret_native = to_type_name $ret_type, {mode=>'native_no_err', pos=>'return', wide=>$d->{wide}}, %$accum;
	my $snum = 0;
        my $call_fun = $d->{name};
        my @call_parms;
	foreach (@parms) {
	  my $n = to_lower($_->{name});
	  if ($_->{type} eq 'encoded string' && !exists($d->{'no conv'})) {
            $need_wide = true unless $d->{wide};
            die unless exists $d->{'posib err'};
            $accum->{headers}{'mutable string'} = true;
            $accum->{headers}{'convert'} = true;
            my $name = get_c_func_name $data->{name}, $d, {mode=>'cc_cxx', use_name=>true, wide=>$d->{wide}};
            $ret .= "  ths->temp_str_$snum.clear();\n";
            if ($d->{wide}) {
              $ret .= "  ${n}_size = get_correct_size(\"$name\", ths->to_internal_->in_type_width(), ${n}_size, ${n}_type_width);\n";
            } else {
              $ret .= "  PosibErr<int> ${n}_fixed_size = get_correct_size(\"$name\", ths->to_internal_->in_type_width(), ${n}_size);\n";
              if (exists($d->{'on conv error'})) {
                $ret .= "  if (${n}_fixed_size.get_err()) {\n";
                $ret .= "    ".$d->{'on conv error'}."\n";
                $ret .= "  } else {\n";
                $ret .= "    ${n}_size = ${n}_fixed_size;\n";
                $ret .= "  }\n";
              } else {
                $ret .= "  ths->err_.reset(${n}_fixed_size.release_err());\n";
                $ret .= "  if (ths->err_ != 0) return ".(c_error_cond $ret_type).";\n";
              }
            }
            $ret .= "  ths->to_internal_->convert($n, ${n}_size, ths->temp_str_$snum);\n";
            $ret .= "  unsigned int s$snum = ths->temp_str_$snum.size();\n";
            push @call_parms, "MutableString(ths->temp_str_$snum.mstr(), s$snum)";
            $snum++;
          } elsif ($_->{type} eq 'encoded string') {
            $need_wide = true unless $d->{wide};
            push @call_parms, $n, "${n}_size";
            push @call_parms, "${n}_type_width" if $d->{wide};
            $call_fun .= " wide" if $d->{wide};
	  } else {
	    push @call_parms, $n;
	  }
	}
	my $parms = '('.(join ', ', @call_parms).')';
	my $exp = "ths->".to_lower($call_fun)."$parms";
	if (exists $d->{'posib err'}) {
	  $accum->{headers}{'posib err'} = true;
	  $ret .= "  PosibErr<$ret_native> ret = $exp;\n";
	  $ret .= "  ths->err_.reset(ret.release_err());\n";
	  $ret .= "  if (ths->err_ != 0) return ".(c_error_cond $ret_type).";\n";
	  if ($ret_type->{type} eq 'void') {
	    $ret_type = {type=>'special'};
	    $exp = "1";
	  } else {
	    $exp = "ret.data";
	  }
	}
	if ($ret_type->{type} eq 'string obj') {
	  $ret .= "  ths->temp_str = $exp;\n";
	  $exp = "ths->temp_str.c_str()";
	} elsif ($ret_type->{type} eq 'encoded string') {
	  die; 
	  # This is not used and also not implemented right
	  $ret .= "  if (to_encoded_ != 0) (*to_encoded)($exp,temp_str_);\n";
	  $ret .= "  else                  temp_str_ = $exp;\n";
	  $exp = "temp_str_0.data()";
	}
	if ($ret_type->{type} eq 'const word list') {
	  $accum->{headers}{'word list'} = true;
          $ret .= "  if (ret.data)\n";
	  $ret .= "    const_cast<WordList *>(ret.data)->from_internal_ = ths->from_internal_;\n";
	}
	$ret .= "  ";
	$ret .= "return " unless $ret_type->{type} eq 'void';
	$ret .= $exp;
	$ret .= ";\n";
      } elsif ($d->{type} eq 'constructor') {
	my $name = $d->{name} ? $d->{name} : "new $data->{name}";
	$name =~ s/aspell\ ?//; # FIXME: Abstract this in a function
	$name = to_lower($name);
	shift @parms if exists $d->{'returns alt type'}; # FIXME: Abstract this in a function
	my $parms = '('.(join ', ', map {$_->{name}} @parms).')';
	$ret .= "  return $name$parms;\n";
      } elsif ($d->{type} eq 'destructor') {
	$ret .= "  delete ths;\n";
      }
    }
    $ret .= "}\n\n";
    unshift @d,{%$d, wide=>true} if $need_wide;
  }
  return $ret;
};

$info{struct}{proc}{impl} = $info{class}{proc}{impl};

$info{union}{proc}{impl} = $info{class}{proc}{impl};

1;