parser: fix `extension static inline` in bits/byteswap.h
[m6w6/ext-psi] / scripts / gen_calc_oper.php
1 <?php
2
3 include __DIR__."/_include.php";
4
5 $oper = [
6 ["NOT", "TILDE", "CAST"],
7 ["ASTERISK", "SLASH", "MODULO"],
8 ["PLUS", "MINUS"],
9 ["LSHIFT", "RSHIFT"],
10 ["LCHEVR", "CMP_LE", "RCHEVR", "CMP_GE"],
11 ["AMPERSAND"],
12 ["CMP_EQ", "CMP_NE"],
13 ["CARET"],
14 ["PIPE"],
15 ["AND"],
16 ["OR"]
17 ];
18
19 ?>
20
21
22 static inline int psi_calc_oper(token_t op1, token_t op2)
23 {
24 if (PSI_T_LPAREN == op2) {
25 return -1;
26 } else if (PSI_T_LPAREN == op1) {
27 return 1;
28 } else if (op1 == op2) {
29 return 0;
30 } else if (!op1 || op1 == PSI_T_NUMBER) {
31 return 1;
32 } else if (!op2 || op2 == PSI_T_NUMBER) {
33 return -1;
34 }
35
36 switch (op1) {<?php /*nobr*/ ?>
37 <?php foreach ($oper as $prec1 => $ops1) : ?>
38 <?php foreach ($ops1 as $op1) : $check = NAN; ?>
39
40 case PSI_T_<?=$op1?>:
41 switch (op2) {<?php /*nobr*/ ?>
42 <?php foreach ($oper as $prec2 => $ops2) : ?>
43 <?php foreach ($ops2 as $op2) : ?>
44 <?php
45 if ($prec1 == $prec2) :
46 $ret = 0;
47 elseif ($prec1 > $prec2) :
48 $ret = 1;
49 else :
50 $ret = -1;
51 endif;
52 ?>
53 <?php if (!is_nan($check) && $check !== $ret) : ?>
54
55 return <?=$check?>;
56 <?php endif; ?>
57 <?php $check = $ret; ?>
58
59 case PSI_T_<?=$op2?>:<?php /*nobr*/ ?>
60 <?php endforeach; ?>
61 <?php endforeach; ?>
62
63 return <?=$ret?>;<?php /*nobr*/ ?>
64
65 default:
66 assert(0);
67 break;
68 }
69 break;
70 <?php endforeach; ?>
71 <?php endforeach; ?>
72
73 default:
74 assert(0);
75 break;
76 }
77 return 0;
78 }