Stop forward declaring global QueryOptimiser in API header
[xapian.git] / xapian-bindings / php / add-php-ref-handling
blob2c9c7a9fcef2db6861a9d6dcdf1d060162c85a11
1 #!/usr/bin/perl -w
2 # Add reference handling code
4 # Copyright (C) 2013,2014,2017 Olly Betts
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to
8 # deal in the Software without restriction, including without limitation the
9 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 # sell copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 # IN THE SOFTWARE.
24 use strict;
26 my $query_ctor = 0;
28 while (<>) {
29 if (/^class XapianEnquire\b/) {
30 $_ .= "\tprotected \$_ps=null;\n";
31 $_ .= "\tprotected \$_sorter=null;\n";
32 $_ .= "\tprotected \$_spies=null;\n";
33 } elsif (/^\tfunction set_sort_by_\w*key\w*\((\$\w+)/) {
34 $_ .= "\t\t\$this->_sorter=$1;\n";
35 } elsif (/^\tfunction add_matchspy\((\$\w+)/) {
36 $_ .= "\t\t\$this->_spies[]=$1;\n";
37 } elsif (/^\tfunction clear_matchspies\(/) {
38 $_ .= "\t\t\$this->_spies=null;\n";
39 } elsif (/^\tfunction set_query\((\$\w+)/) {
40 $_ .= "\t\t\$this->_ps=$1->_ps;\n";
41 } elsif (/^\tfunction get_query\((\$\w+)/) {
42 print;
43 while (<>) {
44 last if /^\t}/;
45 s/^(\t+)return (new XapianQuery\(.*)/$1\$r=$2; \$r->_ps=\$this->_ps; return \$r;/;
46 print;
48 } elsif (/^class XapianQuery\b/) {
49 $_ .= "\tpublic \$_ps=null;\n";
50 $query_ctor = 1;
51 } elsif ($query_ctor && /^\tfunction __construct\((\$\w+)[^,]*,(\$\w+)[^,]*,(\$\w+)/) {
52 $query_ctor = 0;
53 $_ .= "\t\tif ($1 instanceof XapianPostingSource) {\n";
54 $_ .= "\t\t\t\$this->_ps[]=$1;\n";
55 $_ .= "\t\t} else if (is_array($2)) {\n";
56 $_ .= "\t\t\tforeach ($2 as \$xxx) {\n";
57 $_ .= "\t\t\t\tif (\$xxx instanceof XapianQuery) \$this->_ps[]=\$xxx->_ps;\n";
58 $_ .= "\t\t\t}\n";
59 $_ .= "\t\t} else {\n";
60 $_ .= "\t\t\tif ($1 instanceof XapianQuery) \$this->_ps[]=$1->_ps;\n";
61 $_ .= "\t\t\tif ($2 instanceof XapianQuery) \$this->_ps[]=$2->_ps;\n";
62 $_ .= "\t\t\tif ($3 instanceof XapianQuery) \$this->_ps[]=$3->_ps;\n";
63 $_ .= "\t\t}\n";
64 } elsif (/^class XapianQueryParser\b/) {
65 $_ .= "\tprotected \$_rps=null;\n";
66 $_ .= "\tprotected \$_vrps=null;\n";
67 $_ .= "\tprotected \$_stopper=null;\n";
68 } elsif (/^class XapianTermGenerator\b/) {
69 $_ .= "\tprotected \$_stopper=null;\n";
70 } elsif (/^\tfunction add_rangeprocessor\((\$\w+)/) {
71 $_ .= "\t\t\$this->_rps[]=$1;\n";
72 } elsif (/^\tfunction add_valuerangeprocessor\((\$\w+)/) {
73 $_ .= "\t\t\$this->_vrps[]=$1;\n";
74 } elsif (/^\tfunction set_stopper\((\$\w+)/) {
75 $_ .= "\t\t\$this->_stopper=$1;\n";
77 print;