Adjust new comments to match existing
[xapian.git] / xapian-letor / exception_data.pm
blobc150e38eedfb41c4ee899af9e99d909e0a4c55ae
1 # exception_data.pm: details of the exception hierarchy used by Xapian.
2 package exception_data;
3 $copyright = <<'EOF';
4 /* Copyright (C) 2003,2004,2006,2007,2008,2009,2011,2015,2019,2020 Olly Betts
5 * Copyright (C) 2007 Richard Boulton
6 * Copyright (C) 2016 Ayush Tomar
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 EOF
24 use Exporter;
25 @ISA = qw(Exporter);
26 @EXPORT = qw(
27 $copyright $generated_warning @baseclasses @classes %subclasses %classcode
30 $generated_warning =
31 "/* Warning: This file is generated by $0 - do not modify directly! */\n";
33 @baseclasses = ();
34 @classes = ();
35 %subclasses = ();
36 %classcode = ();
38 sub errorbaseclass {
39 push @baseclasses, \@_;
40 push @{$subclasses{$_[1]}}, $_[0];
43 sub errorclass {
44 my $typecode = shift;
45 my ($class, $parent) = @_;
46 push @classes, \@_;
47 push @{$subclasses{$parent}}, $class;
48 $classcode{$class} = $typecode;
51 errorbaseclass('LogicError', 'Error',
52 'The base class for exceptions indicating errors in the program logic.',
53 <<'DOC');
54 A subclass of LogicError will be thrown if Xapian detects a violation
55 of a class invariant or a logical precondition or postcondition, etc.
56 DOC
58 # RuntimeError and subclasses:
60 errorbaseclass('RuntimeError', 'Error',
61 'The base class for exceptions indicating errors only detectable at runtime.',
62 <<'DOC');
63 A subclass of RuntimeError will be thrown if Xapian detects an error
64 which is exception derived from RuntimeError is thrown when an
65 error is caused by problems with the data or environment rather
66 than a programming mistake.
67 DOC
69 errorclass(0, 'FileNotFoundError', 'RuntimeError',
70 'FileNotFoundError indicates that the file was not found at the path supplied.',
71 '');
73 errorclass(1, 'LetorParseError', 'RuntimeError',
74 'LetorParseError indicates file parsing error.',
75 <<'DOC');
76 You should check that the file being parsed follows the standard set by
77 xapian-letor.
78 DOC
80 errorclass(2, 'LetorInternalError', 'RuntimeError',
81 'LetorInternalError indicates a runtime problem of some sort.',
82 '');
84 sub for_each_nothrow {
85 my $func = shift @_;
86 foreach my $header ('include/xapian-letor.h', <include/xapian-letor/*.h>) {
87 local $/ = undef;
88 open H, '<', $header or die $!;
89 my $header_text = <H>;
90 # Strip comments.
91 $header_text =~ s!/(?:/[^\n]*|\*.*?\*/)! !gs;
92 # Ignore the parts SWIG is told to ignore.
93 $header_text =~ s/^\s*#\s*if(?:ndef|\s+!\s*defined)\s+SWIG\b.*?^\s*#\s*endif\b.*?$//gsm;
94 my $class = '';
95 for (split /[;}{]\n/, $header_text) {
96 s/\n\s*/ /g;
97 if (/^\s*(?:class|struct)\s+XAPIAN_VISIBILITY_DEFAULT\s+(\w+)/) {
98 $class = "$1::";
99 &$func("Xapian::$class~$1");
100 next;
102 s/ : .*//;
103 /\b((?:operator *\S+|[A-Za-z][A-Za-z0-9_]+)\(.*\))((?: \w+)*)/ or next;
104 my $method = $1;
105 my $attributes = $2;
106 if ($attributes !~ /\bnoexcept\b/) {
107 next;
109 if ($attributes =~ /\bconst\b/) {
110 $method .= ' const';
112 &$func("Xapian::$class$method");
114 close H;