| 1 | /* |
| 2 | Copyright(C) 2014-2015 Brazil |
| 3 | Copyright(C) 2022 Sutou Kouhei <[email protected]> |
| 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 as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "grn_expr_code.h"cxx . . $ `<file>/lib/grn_expr_code.h`/ |
| 21 | |
| 22 | uint32_tcxx . . $ uint32_t# |
| 23 | grn_expr_code_n_used_codescxx . . $ grn_expr_code_n_used_codes(fc31cc6e0ef54a73).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 24 | grn_expr_codecxx . . $ grn_expr_code# *start, |
| 25 | grn_expr_codecxx . . $ grn_expr_code# *target) |
| 26 | { |
| 27 | unsigned int n_codes; |
| 28 | int i, n_args; |
| 29 | grn_expr_codecxx . . $ grn_expr_code# *sub_code; |
| 30 | |
| 31 | if (start == target) { |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | n_args = target->nargscxx . . $ $anonymous_type_640a68f6a3c9e981_0#nargs.; |
| 36 | if (target->valuecxx . . $ $anonymous_type_640a68f6a3c9e981_0#value.) { |
| 37 | n_args--; |
| 38 | if (n_args == 0) { |
| 39 | return 1; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | n_codes = 1; |
| 44 | sub_code = target - 1; |
| 45 | for (i = 0; i < n_args; i++) { |
| 46 | uint32_tcxx . . $ uint32_t# sub_n_codes; |
| 47 | sub_n_codes = grn_expr_code_n_used_codescxx . . $ grn_expr_code_n_used_codes(fc31cc6e0ef54a73).(ctx, start, sub_code); |
| 48 | n_codes += sub_n_codes; |
| 49 | sub_code -= sub_n_codes; |
| 50 | if (sub_code < start) { |
| 51 | /* TODO: report error */ |
| 52 | return 0; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return n_codes; |
| 57 | } |