1/* -*- c-basic-offset: 2 -*- */
2/*
3 Copyright(C) 2015-2016 Brazil
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License version 2.1 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#include "ts_op.h"
20
21size_t
22grn_ts_op_get_n_args(grn_ts_op_type op_type)
23{
24 switch (op_type) {
25 case GRN_TS_OP_LOGICAL_NOT: /* !X */
26 case GRN_TS_OP_BITWISE_NOT: /* ~X */
27 case GRN_TS_OP_POSITIVE: /* +X */
28 case GRN_TS_OP_NEGATIVE: /* -X */
29 case GRN_TS_OP_FLOAT:
30 case GRN_TS_OP_TIME: {
31 return 1;
32 }
33 case GRN_TS_OP_LOGICAL_AND: /* X && Y */
34 case GRN_TS_OP_LOGICAL_OR: /* X || Y */
35 case GRN_TS_OP_LOGICAL_SUB: /* X &! Y */
36 case GRN_TS_OP_BITWISE_AND: /* X & Y */
37 case GRN_TS_OP_BITWISE_OR: /* X | Y */
38 case GRN_TS_OP_BITWISE_XOR: /* X ^ Y */
39 case GRN_TS_OP_EQUAL: /* X == Y */
40 case GRN_TS_OP_NOT_EQUAL: /* X != Y */
41 case GRN_TS_OP_LESS: /* X < Y */
42 case GRN_TS_OP_LESS_EQUAL: /* X <= Y */
43 case GRN_TS_OP_GREATER: /* X > Y */
44 case GRN_TS_OP_GREATER_EQUAL: /* X >= Y */
45 case GRN_TS_OP_SHIFT_ARITHMETIC_LEFT: /* X << Y */
46 case GRN_TS_OP_SHIFT_ARITHMETIC_RIGHT: /* X >> Y */
47 case GRN_TS_OP_SHIFT_LOGICAL_LEFT: /* X <<< Y */
48 case GRN_TS_OP_SHIFT_LOGICAL_RIGHT: /* X >>> Y */
49 case GRN_TS_OP_PLUS: /* X + Y */
50 case GRN_TS_OP_MINUS: /* X - Y */
51 case GRN_TS_OP_MULTIPLICATION: /* X * Y */
52 case GRN_TS_OP_DIVISION: /* X / Y */
53 case GRN_TS_OP_MODULUS: /* X % Y */
54 case GRN_TS_OP_MATCH: /* X @ Y */
55 case GRN_TS_OP_PREFIX_MATCH: /* X @^ Y */
56 case GRN_TS_OP_SUFFIX_MATCH: { /* X @$ Y */
57 return 2;
58 }
59 default: {
60 return 0;
61 }
62 }
63}
64
65grn_ts_op_precedence
66grn_ts_op_get_precedence(grn_ts_op_type op_type)
67{
68 switch (op_type) {
69 case GRN_TS_OP_LOGICAL_NOT:
70 case GRN_TS_OP_BITWISE_NOT:
71 case GRN_TS_OP_POSITIVE:
72 case GRN_TS_OP_NEGATIVE: {
73 return 15;
74 }
75 case GRN_TS_OP_FLOAT:
76 case GRN_TS_OP_TIME: {
77 return 16;
78 }
79 case GRN_TS_OP_LOGICAL_AND: {
80 return 5;
81 }
82 case GRN_TS_OP_LOGICAL_OR: {
83 return 3;
84 }
85 case GRN_TS_OP_LOGICAL_SUB: {
86 return 4;
87 }
88 case GRN_TS_OP_BITWISE_AND: {
89 return 8;
90 }
91 case GRN_TS_OP_BITWISE_OR: {
92 return 6;
93 }
94 case GRN_TS_OP_BITWISE_XOR: {
95 return 7;
96 }
97 case GRN_TS_OP_EQUAL:
98 case GRN_TS_OP_NOT_EQUAL: {
99 return 9;
100 }
101 case GRN_TS_OP_LESS:
102 case GRN_TS_OP_LESS_EQUAL:
103 case GRN_TS_OP_GREATER:
104 case GRN_TS_OP_GREATER_EQUAL: {
105 return 10;
106 }
107 case GRN_TS_OP_SHIFT_ARITHMETIC_LEFT:
108 case GRN_TS_OP_SHIFT_ARITHMETIC_RIGHT:
109 case GRN_TS_OP_SHIFT_LOGICAL_LEFT:
110 case GRN_TS_OP_SHIFT_LOGICAL_RIGHT: {
111 return 11;
112 }
113 case GRN_TS_OP_PLUS:
114 case GRN_TS_OP_MINUS: {
115 return 12;
116 }
117 case GRN_TS_OP_MULTIPLICATION:
118 case GRN_TS_OP_DIVISION:
119 case GRN_TS_OP_MODULUS: {
120 return 13;
121 }
122 case GRN_TS_OP_MATCH:
123 case GRN_TS_OP_PREFIX_MATCH:
124 case GRN_TS_OP_SUFFIX_MATCH: {
125 return 14;
126 }
127 default: {
128 return 0;
129 }
130 }
131}
132