Tweaked some things so that make distcheck passes
[pspp-builds.git] / src / expressions / operations.h.pl
1 #!/usr/bin/perl
2
3 use PSPP_expressions ;
4 #
5 # Produce output.
6 print_header ();
7 generate_output ();
8 print_trailer ();
9
10
11 sub generate_output {
12     print "#include <stdlib.h>\n";
13     print "#include \"bool.h\"\n\n";
14
15     print "typedef enum";
16     print "  {\n";
17     my (@atoms);
18     foreach my $type (@types) {
19         next if $type->{ROLE} eq 'fixed';
20         push (@atoms, "OP_$type->{NAME}");
21     }
22     print_operations ('atom', 1, \@atoms);
23     print_operations ('function', "OP_atom_last + 1", \@funcs);
24     print_operations ('operator', "OP_function_last + 1", \@opers);
25     print_range ("OP_composite", "OP_function_first", "OP_operator_last");
26     print ",\n\n";
27     print_range ("OP", "OP_atom_first", "OP_composite_last");
28     print "\n  }\n";
29     print "operation_type, atom_type;\n";
30
31     print_predicate ('is_operation', 'OP');
32     print_predicate ("is_$_", "OP_$_")
33         foreach qw (atom composite function operator);
34 }
35
36 sub print_operations {
37     my ($type, $first, $names) = @_;
38     print "    /* \u$type types. */\n";
39     print "    $names->[0] = $first,\n";
40     print "    $_,\n" foreach @$names[1...$#{$names}];
41     print_range ("OP_$type", $names->[0], $names->[$#{$names}]);
42     print ",\n\n";
43 }
44
45 sub print_range {
46     my ($prefix, $first, $last) = @_;
47     print "    ${prefix}_first = $first,\n";
48     print "    ${prefix}_last = $last,\n";
49     print "    ${prefix}_cnt = ${prefix}_last - ${prefix}_first + 1";
50 }
51
52 sub print_predicate {
53     my ($function, $category) = @_;
54     my ($assertion) = "";
55
56     print "\nstatic inline bool\n";
57     print "$function (operation_type op)\n";
58     print "{\n";
59     print "  assert (is_operation (op));\n" if $function ne 'is_operation';
60     print "  return op >= ${category}_first && op <= ${category}_last;\n";
61     print "}\n";
62 }