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