12 print "#include <stdlib.h>\n";
13 print "#include \"bool.h\"\n\n";
18 foreach my $type (@types) {
19 next if $type->{ROLE} eq 'fixed';
20 push (@atoms, "OP_$type->{NAME}");
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");
27 print_range ("OP", "OP_atom_first", "OP_composite_last");
29 print "operation_type, atom_type;\n";
31 print_predicate ('is_operation', 'OP');
32 print_predicate ("is_$_", "OP_$_")
33 foreach qw (atom composite function operator);
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}]);
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";
53 my ($function, $category) = @_;
56 print "\nstatic inline bool\n";
57 print "$function (operation_type op)\n";
59 print " assert (is_operation (op));\n" if $function ne 'is_operation';
60 print " return op >= ${category}_first && op <= ${category}_last;\n";