diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2023-11-20 20:10:50 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2023-11-20 20:10:50 +0100 |
commit | 35e13e4c9637f5bf7bef6039c8c813207780a174 (patch) | |
tree | f2ea0b1aa455bb2552ffe8a7bb083f24e86d1f34 /src/regcomp.c | |
parent | db6f38bc1b73930f1da954525464cf1986f43a28 (diff) |
New upstream version 6.9.9upstream/6.9.9upstream
Diffstat (limited to 'src/regcomp.c')
-rw-r--r-- | src/regcomp.c | 1772 |
1 files changed, 920 insertions, 852 deletions
diff --git a/src/regcomp.c b/src/regcomp.c index d341c38..10da9c4 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -2,7 +2,7 @@ regcomp.c - Oniguruma (regular expression library) **********************************************************************/ /*- - * Copyright (c) 2002-2022 K.Kosako + * Copyright (c) 2002-2023 K.Kosako * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,8 +31,8 @@ #define OPS_INIT_SIZE 8 -#define NODE_IS_REAL_IGNORECASE(node) \ - (NODE_IS_IGNORECASE(node) && !NODE_STRING_IS_CRUDE(node)) +#define ND_IS_REAL_IGNORECASE(node) \ + (ND_IS_IGNORECASE(node) && !ND_STRING_IS_CRUDE(node)) typedef struct { OnigLen min; @@ -360,7 +360,7 @@ node_swap(Node* a, Node* b) c = *a; *a = *b; *b = c; - if (NODE_TYPE(a) == NODE_STRING) { + if (ND_TYPE(a) == ND_STRING) { StrNode* sn = STR_(a); if (sn->capacity == 0) { int len = (int )(sn->end - sn->s); @@ -369,7 +369,7 @@ node_swap(Node* a, Node* b) } } - if (NODE_TYPE(b) == NODE_STRING) { + if (ND_TYPE(b) == ND_STRING) { StrNode* sn = STR_(b); if (sn->capacity == 0) { int len = (int )(sn->end - sn->s); @@ -385,8 +385,8 @@ node_list_len(Node* list) int len; len = 1; - while (IS_NOT_NULL(NODE_CDR(list))) { - list = NODE_CDR(list); + while (IS_NOT_NULL(ND_CDR(list))) { + list = ND_CDR(list); len++; } @@ -402,10 +402,10 @@ node_list_add(Node* list, Node* x) if (IS_NULL(n)) return NULL_NODE; if (IS_NOT_NULL(list)) { - while (IS_NOT_NULL(NODE_CDR(list))) - list = NODE_CDR(list); + while (IS_NOT_NULL(ND_CDR(list))) + list = ND_CDR(list); - NODE_CDR(list) = n; + ND_CDR(list) = n; } return n; @@ -416,7 +416,7 @@ node_str_node_cat(Node* node, Node* add) { int r; - if (NODE_STATUS(node) != NODE_STATUS(add)) + if (ND_STATUS(node) != ND_STATUS(add)) return ONIGERR_TYPE_BUG; if (STR_(node)->flag != STR_(add)->flag) @@ -432,8 +432,8 @@ static void node_conv_to_str_node(Node* node, Node* ref_node) { xmemset(node, 0, sizeof(*node)); - NODE_SET_TYPE(node, NODE_STRING); - NODE_STATUS(node) = NODE_STATUS(ref_node); + ND_SET_TYPE(node, ND_STRING); + ND_STATUS(node) = ND_STATUS(ref_node); STR_(node)->flag = STR_(ref_node)->flag; STR_(node)->s = STR_(node)->buf; @@ -639,12 +639,12 @@ node_char_len1(Node* node, regex_t* reg, MinMaxCharLen* ci, ParseEnv* env, level++; - switch (NODE_TYPE(node)) { - case NODE_LIST: + switch (ND_TYPE(node)) { + case ND_LIST: { int first = TRUE; do { - r = node_char_len1(NODE_CAR(node), reg, &tci, env, level); + r = node_char_len1(ND_CAR(node), reg, &tci, env, level); if (r < 0) break; if (first == TRUE) { *ci = tci; @@ -652,20 +652,20 @@ node_char_len1(Node* node, regex_t* reg, MinMaxCharLen* ci, ParseEnv* env, } else mmcl_add(ci, &tci); - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); } break; - case NODE_ALT: + case ND_ALT: { int fixed; - r = node_char_len1(NODE_CAR(node), reg, ci, env, level); + r = node_char_len1(ND_CAR(node), reg, ci, env, level); if (r < 0) break; fixed = TRUE; - while (IS_NOT_NULL(node = NODE_CDR(node))) { - r = node_char_len1(NODE_CAR(node), reg, &tci, env, level); + while (IS_NOT_NULL(node = ND_CDR(node))) { + r = node_char_len1(ND_CAR(node), reg, &tci, env, level); if (r < 0) break; if (! mmcl_fixed(&tci)) fixed = FALSE; @@ -682,13 +682,13 @@ node_char_len1(Node* node, regex_t* reg, MinMaxCharLen* ci, ParseEnv* env, } break; - case NODE_STRING: + case ND_STRING: { OnigLen clen; StrNode* sn = STR_(node); UChar *s = sn->s; - if (NODE_IS_REAL_IGNORECASE(node) && + if (ND_IS_REAL_IGNORECASE(node) && CASE_FOLD_IS_NOT_ASCII_ONLY(env->case_fold_flag)) { /* Such a case is possible. ex. /(?i)(?<=\1)(a)/ @@ -707,7 +707,7 @@ node_char_len1(Node* node, regex_t* reg, MinMaxCharLen* ci, ParseEnv* env, } break; - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); @@ -716,13 +716,13 @@ node_char_len1(Node* node, regex_t* reg, MinMaxCharLen* ci, ParseEnv* env, mmcl_set(ci, 0); } else { - r = node_char_len1(NODE_BODY(node), reg, ci, env, level); + r = node_char_len1(ND_BODY(node), reg, ci, env, level); if (r < 0) break; mmcl_multiply(ci, qn->lower); } } else { - r = node_char_len1(NODE_BODY(node), reg, ci, env, level); + r = node_char_len1(ND_BODY(node), reg, ci, env, level); if (r < 0) break; mmcl_repeat_range_multiply(ci, qn->lower, qn->upper); } @@ -730,44 +730,44 @@ node_char_len1(Node* node, regex_t* reg, MinMaxCharLen* ci, ParseEnv* env, break; #ifdef USE_CALL - case NODE_CALL: - if (NODE_IS_RECURSION(node)) + case ND_CALL: + if (ND_IS_RECURSION(node)) mmcl_set_min_max(ci, 0, INFINITE_LEN, FALSE); else - r = node_char_len1(NODE_BODY(node), reg, ci, env, level); + r = node_char_len1(ND_BODY(node), reg, ci, env, level); break; #endif - case NODE_CTYPE: - case NODE_CCLASS: + case ND_CTYPE: + case ND_CCLASS: mmcl_set(ci, 1); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); switch (en->type) { case BAG_MEMORY: - if (NODE_IS_FIXED_CLEN(node)) { + if (ND_IS_FIXED_CLEN(node)) { mmcl_set_min_max(ci, en->min_char_len, en->max_char_len, - NODE_IS_FIXED_CLEN_MIN_SURE(node)); + ND_IS_FIXED_CLEN_MIN_SURE(node)); } else { - if (NODE_IS_MARK1(node)) { + if (ND_IS_MARK1(node)) { mmcl_set_min_max(ci, 0, INFINITE_LEN, FALSE); } else { - NODE_STATUS_ADD(node, MARK1); - r = node_char_len1(NODE_BODY(node), reg, ci, env, level); - NODE_STATUS_REMOVE(node, MARK1); + ND_STATUS_ADD(node, MARK1); + r = node_char_len1(ND_BODY(node), reg, ci, env, level); + ND_STATUS_REMOVE(node, MARK1); if (r < 0) break; en->min_char_len = ci->min; en->max_char_len = ci->max; - NODE_STATUS_ADD(node, FIXED_CLEN); + ND_STATUS_ADD(node, FIXED_CLEN); if (ci->min_is_sure != FALSE) - NODE_STATUS_ADD(node, FIXED_CLEN_MIN_SURE); + ND_STATUS_ADD(node, FIXED_CLEN_MIN_SURE); } } /* can't optimize look-behind if capture exists. */ @@ -775,13 +775,13 @@ node_char_len1(Node* node, regex_t* reg, MinMaxCharLen* ci, ParseEnv* env, break; case BAG_OPTION: case BAG_STOP_BACKTRACK: - r = node_char_len1(NODE_BODY(node), reg, ci, env, level); + r = node_char_len1(ND_BODY(node), reg, ci, env, level); break; case BAG_IF_ELSE: { MinMaxCharLen eci; - r = node_char_len1(NODE_BODY(node), reg, ci, env, level); + r = node_char_len1(ND_BODY(node), reg, ci, env, level); if (r < 0) break; if (IS_NOT_NULL(en->te.Then)) { @@ -808,24 +808,24 @@ node_char_len1(Node* node, regex_t* reg, MinMaxCharLen* ci, ParseEnv* env, } break; - case NODE_GIMMICK: + case ND_GIMMICK: mmcl_set(ci, 0); break; - case NODE_ANCHOR: + case ND_ANCHOR: zero: mmcl_set(ci, 0); /* can't optimize look-behind if anchor exists. */ ci->min_is_sure = FALSE; break; - case NODE_BACKREF: - if (NODE_IS_CHECKER(node)) + case ND_BACKREF: + if (ND_IS_CHECKER(node)) goto zero; - if (NODE_IS_RECURSION(node)) { + if (ND_IS_RECURSION(node)) { #ifdef USE_BACKREF_WITH_LEVEL - if (NODE_IS_NEST_LEVEL(node)) { + if (ND_IS_NEST_LEVEL(node)) { mmcl_set_min_max(ci, 0, INFINITE_LEN, FALSE); break; } @@ -887,7 +887,7 @@ add_op(regex_t* reg, int opcode) return 0; } -static int compile_length_tree(Node* node, regex_t* reg); +static int compile_length_tree(Node* node, regex_t* reg, ParseEnv* env); static int compile_tree(Node* node, regex_t* reg, ParseEnv* env); @@ -936,16 +936,16 @@ select_str_opcode(int mb_len, int str_len) static int is_strict_real_node(Node* node) { - switch (NODE_TYPE(node)) { - case NODE_STRING: + switch (ND_TYPE(node)) { + case ND_STRING: { StrNode* sn = STR_(node); return (sn->end != sn->s); } break; - case NODE_CCLASS: - case NODE_CTYPE: + case ND_CCLASS: + case ND_CTYPE: return 1; break; @@ -963,7 +963,7 @@ compile_quant_body_with_empty_check(QuantNode* qn, regex_t* reg, ParseEnv* env) int emptiness; Node* body; - body = NODE_BODY((Node* )qn); + body = ND_BODY((Node* )qn); emptiness = qn->emptiness; saved_num_empty_check = reg->num_empty_check; @@ -981,7 +981,7 @@ compile_quant_body_with_empty_check(QuantNode* qn, regex_t* reg, ParseEnv* env) if (emptiness == BODY_MAY_BE_EMPTY) r = add_op(reg, OP_EMPTY_CHECK_END); else if (emptiness == BODY_MAY_BE_EMPTY_MEM) { - if (NODE_IS_EMPTY_STATUS_CHECK(qn) != 0 && qn->empty_status_mem != 0) { + if (ND_IS_EMPTY_STATUS_CHECK(qn) != 0 && qn->empty_status_mem != 0) { r = add_op(reg, OP_EMPTY_CHECK_END_MEMST); if (r != 0) return r; COP(reg)->empty_check_end.empty_status_mem = qn->empty_status_mem; @@ -1019,7 +1019,7 @@ compile_call(CallNode* node, regex_t* reg, ParseEnv* env) #endif offset = COP_CURR_OFFSET_BYTES(reg, call.addr); - r = unset_addr_list_add(env->unset_addr_list, offset, NODE_CALL_BODY(node)); + r = unset_addr_list_add(env->unset_addr_list, offset, ND_CALL_BODY(node)); return r; } #endif @@ -1312,7 +1312,7 @@ static int is_anychar_infinite_greedy(QuantNode* qn) { if (qn->greedy && IS_INFINITE_REPEAT(qn->upper) && - NODE_IS_ANYCHAR(NODE_QUANT_BODY(qn))) + ND_IS_ANYCHAR(ND_QUANT_BODY(qn))) return 1; else return 0; @@ -1322,12 +1322,12 @@ is_anychar_infinite_greedy(QuantNode* qn) #define CKN_ON (ckn > 0) static int -compile_length_quantifier_node(QuantNode* qn, regex_t* reg) +compile_length_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) { int len, mod_tlen; int infinite = IS_INFINITE_REPEAT(qn->upper); enum BodyEmptyType emptiness = qn->emptiness; - int tlen = compile_length_tree(NODE_QUANT_BODY(qn), reg); + int tlen = compile_length_tree(ND_QUANT_BODY(qn), reg, env); if (tlen < 0) return tlen; if (tlen == 0) return 0; @@ -1401,7 +1401,7 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) int i, r, mod_tlen; int infinite = IS_INFINITE_REPEAT(qn->upper); enum BodyEmptyType emptiness = qn->emptiness; - int tlen = compile_length_tree(NODE_QUANT_BODY(qn), reg); + int tlen = compile_length_tree(ND_QUANT_BODY(qn), reg, env); if (tlen < 0) return tlen; if (tlen == 0) return 0; @@ -1410,10 +1410,10 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) (qn->lower <= 1 || len_multiply_cmp((OnigLen )tlen, qn->lower, QUANTIFIER_EXPAND_LIMIT_SIZE) <= 0)) { - r = compile_tree_n_times(NODE_QUANT_BODY(qn), qn->lower, reg, env); + r = compile_tree_n_times(ND_QUANT_BODY(qn), qn->lower, reg, env); if (r != 0) return r; if (IS_NOT_NULL(qn->next_head_exact)) { - r = add_op(reg, NODE_IS_MULTILINE(NODE_QUANT_BODY(qn)) ? + r = add_op(reg, ND_IS_MULTILINE(ND_QUANT_BODY(qn)) ? OP_ANYCHAR_ML_STAR_PEEK_NEXT : OP_ANYCHAR_STAR_PEEK_NEXT); if (r != 0) return r; @@ -1421,7 +1421,7 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) return 0; } else { - r = add_op(reg, NODE_IS_MULTILINE(NODE_QUANT_BODY(qn)) ? + r = add_op(reg, ND_IS_MULTILINE(ND_QUANT_BODY(qn)) ? OP_ANYCHAR_ML_STAR : OP_ANYCHAR_STAR); return r; } @@ -1456,7 +1456,7 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) } } else { - r = compile_tree_n_times(NODE_QUANT_BODY(qn), qn->lower, reg, env); + r = compile_tree_n_times(ND_QUANT_BODY(qn), qn->lower, reg, env); if (r != 0) return r; } @@ -1520,7 +1520,7 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) if (r != 0) return r; COP(reg)->jump.addr = tlen + SIZE_INC; - r = compile_tree(NODE_QUANT_BODY(qn), reg, env); + r = compile_tree(ND_QUANT_BODY(qn), reg, env); } else { /* Nothing output */ @@ -1533,7 +1533,7 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) QUANTIFIER_EXPAND_LIMIT_SIZE) <= 0)) { int n = qn->upper - qn->lower; - r = compile_tree_n_times(NODE_QUANT_BODY(qn), qn->lower, reg, env); + r = compile_tree_n_times(ND_QUANT_BODY(qn), qn->lower, reg, env); if (r != 0) return r; for (i = 0; i < n; i++) { @@ -1544,7 +1544,7 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) if (r != 0) return r; COP(reg)->push.addr = v; - r = compile_tree(NODE_QUANT_BODY(qn), reg, env); + r = compile_tree(ND_QUANT_BODY(qn), reg, env); if (r != 0) return r; } } @@ -1557,7 +1557,7 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) if (r != 0) return r; COP(reg)->jump.addr = tlen + SIZE_INC; - r = compile_tree(NODE_QUANT_BODY(qn), reg, env); + r = compile_tree(ND_QUANT_BODY(qn), reg, env); } else { r = compile_range_repeat_node(qn, mod_tlen, emptiness, reg, env); @@ -1566,11 +1566,11 @@ compile_quantifier_node(QuantNode* qn, regex_t* reg, ParseEnv* env) } static int -compile_length_option_node(BagNode* node, regex_t* reg) +compile_length_option_node(BagNode* node, regex_t* reg, ParseEnv* env) { int tlen; - tlen = compile_length_tree(NODE_BAG_BODY(node), reg); + tlen = compile_length_tree(ND_BAG_BODY(node), reg, env); return tlen; } @@ -1580,22 +1580,22 @@ compile_option_node(BagNode* node, regex_t* reg, ParseEnv* env) { int r; - r = compile_tree(NODE_BAG_BODY(node), reg, env); + r = compile_tree(ND_BAG_BODY(node), reg, env); return r; } static int -compile_length_bag_node(BagNode* node, regex_t* reg) +compile_length_bag_node(BagNode* node, regex_t* reg, ParseEnv* env) { int len; int tlen; if (node->type == BAG_OPTION) - return compile_length_option_node(node, reg); + return compile_length_option_node(node, reg, env); - if (NODE_BAG_BODY(node)) { - tlen = compile_length_tree(NODE_BAG_BODY(node), reg); + if (ND_BAG_BODY(node)) { + tlen = compile_length_tree(ND_BAG_BODY(node), reg, env); if (tlen < 0) return tlen; } else @@ -1605,22 +1605,22 @@ compile_length_bag_node(BagNode* node, regex_t* reg) case BAG_MEMORY: #ifdef USE_CALL - if (node->m.regnum == 0 && NODE_IS_CALLED(node)) { + if (node->m.regnum == 0 && ND_IS_CALLED(node)) { len = tlen + OPSIZE_CALL + OPSIZE_JUMP + OPSIZE_RETURN; return len; } - if (NODE_IS_CALLED(node)) { + if (ND_IS_CALLED(node)) { len = OPSIZE_MEM_START_PUSH + tlen + OPSIZE_CALL + OPSIZE_JUMP + OPSIZE_RETURN; if (MEM_STATUS_AT0(reg->push_mem_end, node->m.regnum)) - len += (NODE_IS_RECURSION(node) + len += (ND_IS_RECURSION(node) ? OPSIZE_MEM_END_PUSH_REC : OPSIZE_MEM_END_PUSH); else - len += (NODE_IS_RECURSION(node) + len += (ND_IS_RECURSION(node) ? OPSIZE_MEM_END_REC : OPSIZE_MEM_END); } - else if (NODE_IS_RECURSION(node)) { + else if (ND_IS_RECURSION(node)) { len = OPSIZE_MEM_START_PUSH; len += tlen + (MEM_STATUS_AT0(reg->push_mem_end, node->m.regnum) ? OPSIZE_MEM_END_PUSH_REC : OPSIZE_MEM_END_REC); @@ -1639,12 +1639,12 @@ compile_length_bag_node(BagNode* node, regex_t* reg) break; case BAG_STOP_BACKTRACK: - if (NODE_IS_STRICT_REAL_REPEAT(node)) { + if (ND_IS_STRICT_REAL_REPEAT(node)) { int v; QuantNode* qn; - qn = QUANT_(NODE_BAG_BODY(node)); - tlen = compile_length_tree(NODE_QUANT_BODY(qn), reg); + qn = QUANT_(ND_BAG_BODY(node)); + tlen = compile_length_tree(ND_QUANT_BODY(qn), reg, env); if (tlen < 0) return tlen; v = onig_positive_int_multiply(qn->lower, tlen); @@ -1658,16 +1658,16 @@ compile_length_bag_node(BagNode* node, regex_t* reg) case BAG_IF_ELSE: { - Node* cond = NODE_BAG_BODY(node); + Node* cond = ND_BAG_BODY(node); Node* Then = node->te.Then; Node* Else = node->te.Else; - len = compile_length_tree(cond, reg); + len = compile_length_tree(cond, reg, env); if (len < 0) return len; len += OPSIZE_PUSH + OPSIZE_MARK + OPSIZE_CUT_TO_MARK; if (IS_NOT_NULL(Then)) { - tlen = compile_length_tree(Then, reg); + tlen = compile_length_tree(Then, reg, env); if (tlen < 0) return tlen; len += tlen; } @@ -1675,7 +1675,7 @@ compile_length_bag_node(BagNode* node, regex_t* reg) len += OPSIZE_JUMP + OPSIZE_CUT_TO_MARK; if (IS_NOT_NULL(Else)) { - tlen = compile_length_tree(Else, reg); + tlen = compile_length_tree(Else, reg, env); if (tlen < 0) return tlen; len += tlen; } @@ -1686,6 +1686,10 @@ compile_length_bag_node(BagNode* node, regex_t* reg) /* never come here, but set for escape warning */ len = 0; break; + + default: + return ONIGERR_TYPE_BUG; + break; } return len; @@ -1697,38 +1701,38 @@ compile_bag_memory_node(BagNode* node, regex_t* reg, ParseEnv* env) int r; #ifdef USE_CALL - if (NODE_IS_CALLED(node)) { + if (ND_IS_CALLED(node)) { int len; r = add_op(reg, OP_CALL); if (r != 0) return r; node->m.called_addr = COP_CURR_OFFSET(reg) + 1 + OPSIZE_JUMP; - NODE_STATUS_ADD(node, FIXED_ADDR); + ND_STATUS_ADD(node, FIXED_ADDR); COP(reg)->call.addr = (int )node->m.called_addr; if (node->m.regnum == 0) { - len = compile_length_tree(NODE_BAG_BODY(node), reg); + len = compile_length_tree(ND_BAG_BODY(node), reg, env); len += OPSIZE_RETURN; r = add_op(reg, OP_JUMP); if (r != 0) return r; COP(reg)->jump.addr = len + SIZE_INC; - r = compile_tree(NODE_BAG_BODY(node), reg, env); + r = compile_tree(ND_BAG_BODY(node), reg, env); if (r != 0) return r; r = add_op(reg, OP_RETURN); return r; } else { - len = compile_length_tree(NODE_BAG_BODY(node), reg); + len = compile_length_tree(ND_BAG_BODY(node), reg, env); len += (OPSIZE_MEM_START_PUSH + OPSIZE_RETURN); if (MEM_STATUS_AT0(reg->push_mem_end, node->m.regnum)) - len += (NODE_IS_RECURSION(node) + len += (ND_IS_RECURSION(node) ? OPSIZE_MEM_END_PUSH_REC : OPSIZE_MEM_END_PUSH); else - len += (NODE_IS_RECURSION(node) ? OPSIZE_MEM_END_REC : OPSIZE_MEM_END); + len += (ND_IS_RECURSION(node) ? OPSIZE_MEM_END_REC : OPSIZE_MEM_END); r = add_op(reg, OP_JUMP); if (r != 0) return r; @@ -1744,19 +1748,19 @@ compile_bag_memory_node(BagNode* node, regex_t* reg, ParseEnv* env) if (r != 0) return r; COP(reg)->memory_start.num = node->m.regnum; - r = compile_tree(NODE_BAG_BODY(node), reg, env); + r = compile_tree(ND_BAG_BODY(node), reg, env); if (r != 0) return r; #ifdef USE_CALL if (MEM_STATUS_AT0(reg->push_mem_end, node->m.regnum)) - r = add_op(reg, (NODE_IS_RECURSION(node) + r = add_op(reg, (ND_IS_RECURSION(node) ? OP_MEM_END_PUSH_REC : OP_MEM_END_PUSH)); else - r = add_op(reg, (NODE_IS_RECURSION(node) ? OP_MEM_END_REC : OP_MEM_END)); + r = add_op(reg, (ND_IS_RECURSION(node) ? OP_MEM_END_REC : OP_MEM_END)); if (r != 0) return r; COP(reg)->memory_end.num = node->m.regnum; - if (NODE_IS_CALLED(node)) { + if (ND_IS_CALLED(node)) { r = add_op(reg, OP_RETURN); } #else @@ -1786,19 +1790,19 @@ compile_bag_node(BagNode* node, regex_t* reg, ParseEnv* env) break; case BAG_STOP_BACKTRACK: - if (NODE_IS_STRICT_REAL_REPEAT(node)) { - QuantNode* qn = QUANT_(NODE_BAG_BODY(node)); - r = compile_tree_n_times(NODE_QUANT_BODY(qn), qn->lower, reg, env); + if (ND_IS_STRICT_REAL_REPEAT(node)) { + QuantNode* qn = QUANT_(ND_BAG_BODY(node)); + r = compile_tree_n_times(ND_QUANT_BODY(qn), qn->lower, reg, env); if (r != 0) return r; - len = compile_length_tree(NODE_QUANT_BODY(qn), reg); + len = compile_length_tree(ND_QUANT_BODY(qn), reg, env); if (len < 0) return len; r = add_op(reg, OP_PUSH); if (r != 0) return r; COP(reg)->push.addr = SIZE_INC + len + OPSIZE_POP + OPSIZE_JUMP; - r = compile_tree(NODE_QUANT_BODY(qn), reg, env); + r = compile_tree(ND_QUANT_BODY(qn), reg, env); if (r != 0) return r; r = add_op(reg, OP_POP); if (r != 0) return r; @@ -1816,7 +1820,7 @@ compile_bag_node(BagNode* node, regex_t* reg, ParseEnv* env) COP(reg)->mark.id = mid; COP(reg)->mark.save_pos = 0; - r = compile_tree(NODE_BAG_BODY(node), reg, env); + r = compile_tree(ND_BAG_BODY(node), reg, env); if (r != 0) return r; r = add_op(reg, OP_CUT_TO_MARK); if (r != 0) return r; @@ -1829,7 +1833,7 @@ compile_bag_node(BagNode* node, regex_t* reg, ParseEnv* env) { int cond_len, then_len, else_len, jump_len; MemNumType mid; - Node* cond = NODE_BAG_BODY(node); + Node* cond = ND_BAG_BODY(node); Node* Then = node->te.Then; Node* Else = node->te.Else; @@ -1840,10 +1844,10 @@ compile_bag_node(BagNode* node, regex_t* reg, ParseEnv* env) COP(reg)->mark.id = mid; COP(reg)->mark.save_pos = 0; - cond_len = compile_length_tree(cond, reg); + cond_len = compile_length_tree(cond, reg, env); if (cond_len < 0) return cond_len; if (IS_NOT_NULL(Then)) { - then_len = compile_length_tree(Then, reg); + then_len = compile_length_tree(Then, reg, env); if (then_len < 0) return then_len; } else @@ -1868,7 +1872,7 @@ compile_bag_node(BagNode* node, regex_t* reg, ParseEnv* env) } if (IS_NOT_NULL(Else)) { - else_len = compile_length_tree(Else, reg); + else_len = compile_length_tree(Else, reg, env); if (else_len < 0) return else_len; } else @@ -1888,19 +1892,23 @@ compile_bag_node(BagNode* node, regex_t* reg, ParseEnv* env) } } break; + + default: + return ONIGERR_TYPE_BUG; + break; } return r; } static int -compile_length_anchor_node(AnchorNode* node, regex_t* reg) +compile_length_anchor_node(AnchorNode* node, regex_t* reg, ParseEnv* env) { int len; int tlen = 0; - if (IS_NOT_NULL(NODE_ANCHOR_BODY(node))) { - tlen = compile_length_tree(NODE_ANCHOR_BODY(node), reg); + if (IS_NOT_NULL(ND_ANCHOR_BODY(node))) { + tlen = compile_length_tree(ND_ANCHOR_BODY(node), reg, env); if (tlen < 0) return tlen; } @@ -1918,11 +1926,14 @@ compile_length_anchor_node(AnchorNode* node, regex_t* reg) len = OPSIZE_SAVE_VAL + OPSIZE_UPDATE_VAR + OPSIZE_MARK + OPSIZE_PUSH + OPSIZE_UPDATE_VAR + OPSIZE_FAIL + OPSIZE_JUMP + OPSIZE_STEP_BACK_START + OPSIZE_STEP_BACK_NEXT + tlen + OPSIZE_CHECK_POSITION + OPSIZE_CUT_TO_MARK + OPSIZE_UPDATE_VAR; if (IS_NOT_NULL(node->lead_node)) { - int llen = compile_length_tree(node->lead_node, reg); + int llen = compile_length_tree(node->lead_node, reg, env); if (llen < 0) return llen; len += OPSIZE_MOVE + llen; } + + if ((env->flags & PE_FLAG_HAS_ABSENT_STOPPER) != 0) + len += OPSIZE_SAVE_VAL + OPSIZE_UPDATE_VAR; } break; case ANCR_LOOK_BEHIND_NOT: @@ -1932,11 +1943,14 @@ compile_length_anchor_node(AnchorNode* node, regex_t* reg) len = OPSIZE_SAVE_VAL + OPSIZE_UPDATE_VAR + OPSIZE_MARK + OPSIZE_PUSH + OPSIZE_STEP_BACK_START + OPSIZE_STEP_BACK_NEXT + tlen + OPSIZE_CHECK_POSITION + OPSIZE_POP_TO_MARK + OPSIZE_UPDATE_VAR + OPSIZE_POP + OPSIZE_FAIL + OPSIZE_UPDATE_VAR + OPSIZE_POP + OPSIZE_POP; if (IS_NOT_NULL(node->lead_node)) { - int llen = compile_length_tree(node->lead_node, reg); + int llen = compile_length_tree(node->lead_node, reg, env); if (llen < 0) return llen; len += OPSIZE_MOVE + llen; } + + if ((env->flags & PE_FLAG_HAS_ABSENT_STOPPER) != 0) + len += OPSIZE_SAVE_VAL + OPSIZE_UPDATE_VAR; } break; @@ -1982,7 +1996,7 @@ compile_anchor_look_behind_node(AnchorNode* node, regex_t* reg, ParseEnv* env) COP(reg)->step_back_start.remaining = 0; COP(reg)->step_back_start.addr = 1; - r = compile_tree(NODE_ANCHOR_BODY(node), reg, env); + r = compile_tree(ND_ANCHOR_BODY(node), reg, env); if (r != 0) return r; r = add_op(reg, OP_CUT_TO_MARK); @@ -1991,8 +2005,9 @@ compile_anchor_look_behind_node(AnchorNode* node, regex_t* reg, ParseEnv* env) COP(reg)->cut_to_mark.restore_pos = FALSE; } else { - MemNumType mid1, mid2; OnigLen diff; + MemNumType mid1, mid2; + MemNumType mid3 = 0; /* ignore uninitialized warning */ if (IS_NOT_NULL(node->lead_node)) { MinMaxCharLen ci; @@ -2038,6 +2053,14 @@ compile_anchor_look_behind_node(AnchorNode* node, regex_t* reg, ParseEnv* env) r = add_op(reg, OP_FAIL); if (r != 0) return r; + if ((env->flags & PE_FLAG_HAS_ABSENT_STOPPER) != 0) { + ID_ENTRY(env, mid3); + r = add_op(reg, OP_SAVE_VAL); + if (r != 0) return r; + COP(reg)->save_val.type = SAVE_RIGHT_RANGE; + COP(reg)->save_val.id = mid3; + } + r = add_op(reg, OP_STEP_BACK_START); if (r != 0) return r; @@ -2053,9 +2076,17 @@ compile_anchor_look_behind_node(AnchorNode* node, regex_t* reg, ParseEnv* env) r = add_op(reg, OP_STEP_BACK_NEXT); if (r != 0) return r; - r = compile_tree(NODE_ANCHOR_BODY(node), reg, env); + r = compile_tree(ND_ANCHOR_BODY(node), reg, env); if (r != 0) return r; + if ((env->flags & PE_FLAG_HAS_ABSENT_STOPPER) != 0) { + r = add_op(reg, OP_UPDATE_VAR); + if (r != 0) return r; + COP(reg)->update_var.type = UPDATE_VAR_RIGHT_RANGE_FROM_STACK; + COP(reg)->update_var.id = mid3; + COP(reg)->update_var.clear = FALSE; + } + r = add_op(reg, OP_CHECK_POSITION); if (r != 0) return r; COP(reg)->check_position.type = CHECK_POSITION_CURRENT_RIGHT_RANGE; @@ -2082,7 +2113,7 @@ compile_anchor_look_behind_not_node(AnchorNode* node, regex_t* reg, int r; int len; - len = compile_length_tree(NODE_ANCHOR_BODY(node), reg); + len = compile_length_tree(ND_ANCHOR_BODY(node), reg, env); if (node->char_min_len == node->char_max_len) { MemNumType mid; @@ -2103,7 +2134,7 @@ compile_anchor_look_behind_not_node(AnchorNode* node, regex_t* reg, COP(reg)->step_back_start.remaining = 0; COP(reg)->step_back_start.addr = 1; - r = compile_tree(NODE_ANCHOR_BODY(node), reg, env); + r = compile_tree(ND_ANCHOR_BODY(node), reg, env); if (r != 0) return r; r = add_op(reg, OP_POP_TO_MARK); @@ -2114,8 +2145,9 @@ compile_anchor_look_behind_not_node(AnchorNode* node, regex_t* reg, r = add_op(reg, OP_POP); } else { - MemNumType mid1, mid2; OnigLen diff; + MemNumType mid1, mid2; + MemNumType mid3 = 0; /* ignore uninitialized warning */ ID_ENTRY(env, mid1); r = add_op(reg, OP_SAVE_VAL); @@ -2135,13 +2167,16 @@ compile_anchor_look_behind_not_node(AnchorNode* node, regex_t* reg, r = add_op(reg, OP_PUSH); if (r != 0) return r; + COP(reg)->push.addr = SIZE_INC + OPSIZE_STEP_BACK_START + OPSIZE_STEP_BACK_NEXT + len + OPSIZE_CHECK_POSITION + OPSIZE_POP_TO_MARK + OPSIZE_UPDATE_VAR + OPSIZE_POP + OPSIZE_FAIL; + if ((env->flags & PE_FLAG_HAS_ABSENT_STOPPER) != 0) + COP(reg)->push.addr += OPSIZE_SAVE_VAL + OPSIZE_UPDATE_VAR; if (IS_NOT_NULL(node->lead_node)) { int clen; MinMaxCharLen ci; - clen = compile_length_tree(node->lead_node, reg); + clen = compile_length_tree(node->lead_node, reg, env); COP(reg)->push.addr += OPSIZE_MOVE + clen; r = node_char_len(node->lead_node, reg, &ci, env); @@ -2154,6 +2189,14 @@ compile_anchor_look_behind_not_node(AnchorNode* node, regex_t* reg, if (r != 0) return r; } + if ((env->flags & PE_FLAG_HAS_ABSENT_STOPPER) != 0) { + ID_ENTRY(env, mid3); + r = add_op(reg, OP_SAVE_VAL); + if (r != 0) return r; + COP(reg)->save_val.type = SAVE_RIGHT_RANGE; + COP(reg)->save_val.id = mid3; + } + r = add_op(reg, OP_STEP_BACK_START); if (r != 0) return r; @@ -2169,9 +2212,17 @@ compile_anchor_look_behind_not_node(AnchorNode* node, regex_t* reg, r = add_op(reg, OP_STEP_BACK_NEXT); if (r != 0) return r; - r = compile_tree(NODE_ANCHOR_BODY(node), reg, env); + r = compile_tree(ND_ANCHOR_BODY(node), reg, env); if (r != 0) return r; + if ((env->flags & PE_FLAG_HAS_ABSENT_STOPPER) != 0) { + r = add_op(reg, OP_UPDATE_VAR); + if (r != 0) return r; + COP(reg)->update_var.type = UPDATE_VAR_RIGHT_RANGE_FROM_STACK; + COP(reg)->update_var.id = mid3; + COP(reg)->update_var.clear = FALSE; + } + r = add_op(reg, OP_CHECK_POSITION); if (r != 0) return r; COP(reg)->check_position.type = CHECK_POSITION_CURRENT_RIGHT_RANGE; @@ -2254,7 +2305,7 @@ compile_anchor_node(AnchorNode* node, regex_t* reg, ParseEnv* env) type = EXTENDED_GRAPHEME_CLUSTER_BOUNDARY; #ifdef USE_UNICODE_WORD_BREAK - if (NODE_IS_TEXT_SEGMENT_WORD(node)) + if (ND_IS_TEXT_SEGMENT_WORD(node)) type = WORD_BOUNDARY; #endif @@ -2272,7 +2323,7 @@ compile_anchor_node(AnchorNode* node, regex_t* reg, ParseEnv* env) COP(reg)->mark.id = mid; COP(reg)->mark.save_pos = TRUE; - r = compile_tree(NODE_ANCHOR_BODY(node), reg, env); + r = compile_tree(ND_ANCHOR_BODY(node), reg, env); if (r != 0) return r; r = add_op(reg, OP_CUT_TO_MARK); @@ -2284,7 +2335,7 @@ compile_anchor_node(AnchorNode* node, regex_t* reg, ParseEnv* env) case ANCR_PREC_READ_NOT: { - len = compile_length_tree(NODE_ANCHOR_BODY(node), reg); + len = compile_length_tree(ND_ANCHOR_BODY(node), reg, env); if (len < 0) return len; ID_ENTRY(env, mid); @@ -2298,7 +2349,7 @@ compile_anchor_node(AnchorNode* node, regex_t* reg, ParseEnv* env) COP(reg)->mark.id = mid; COP(reg)->mark.save_pos = FALSE; - r = compile_tree(NODE_ANCHOR_BODY(node), reg, env); + r = compile_tree(ND_ANCHOR_BODY(node), reg, env); if (r != 0) return r; r = add_op(reg, OP_POP_TO_MARK); @@ -2416,78 +2467,82 @@ compile_length_gimmick_node(GimmickNode* node, regex_t* reg) } break; #endif + + default: + return ONIGERR_TYPE_BUG; + break; } return len; } static int -compile_length_tree(Node* node, regex_t* reg) +compile_length_tree(Node* node, regex_t* reg, ParseEnv* env) { int len, r; - switch (NODE_TYPE(node)) { - case NODE_LIST: + switch (ND_TYPE(node)) { + case ND_LIST: len = 0; do { - r = compile_length_tree(NODE_CAR(node), reg); + r = compile_length_tree(ND_CAR(node), reg, env); if (r < 0) return r; len += r; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); r = len; break; - case NODE_ALT: + case ND_ALT: { int n; n = r = 0; do { - r += compile_length_tree(NODE_CAR(node), reg); + r += compile_length_tree(ND_CAR(node), reg, env); n++; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); r += (OPSIZE_PUSH + OPSIZE_JUMP) * (n - 1); } break; - case NODE_STRING: - if (NODE_STRING_IS_CRUDE(node)) + case ND_STRING: + if (ND_STRING_IS_CRUDE(node)) r = compile_length_string_crude_node(STR_(node), reg); else r = compile_length_string_node(node, reg); break; - case NODE_CCLASS: + case ND_CCLASS: r = compile_length_cclass_node(CCLASS_(node), reg); break; - case NODE_CTYPE: + case ND_CTYPE: r = SIZE_OPCODE; break; - case NODE_BACKREF: + case ND_BACKREF: r = OPSIZE_BACKREF; break; #ifdef USE_CALL - case NODE_CALL: + case ND_CALL: r = OPSIZE_CALL; break; #endif - case NODE_QUANT: - r = compile_length_quantifier_node(QUANT_(node), reg); + case ND_QUANT: + r = compile_length_quantifier_node(QUANT_(node), reg, env); break; - case NODE_BAG: - r = compile_length_bag_node(BAG_(node), reg); + case ND_BAG: + r = compile_length_bag_node(BAG_(node), reg, env); break; - case NODE_ANCHOR: - r = compile_length_anchor_node(ANCHOR_(node), reg); + case ND_ANCHOR: + r = compile_length_anchor_node(ANCHOR_(node), reg, env); break; - case NODE_GIMMICK: + case ND_GIMMICK: r = compile_length_gimmick_node(GIMMICK_(node), reg); break; @@ -2504,63 +2559,63 @@ compile_tree(Node* node, regex_t* reg, ParseEnv* env) { int n, len, pos, r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: + switch (ND_TYPE(node)) { + case ND_LIST: do { - r = compile_tree(NODE_CAR(node), reg, env); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = compile_tree(ND_CAR(node), reg, env); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ALT: + case ND_ALT: { Node* x = node; len = 0; do { - len += compile_length_tree(NODE_CAR(x), reg); - if (IS_NOT_NULL(NODE_CDR(x))) { + len += compile_length_tree(ND_CAR(x), reg, env); + if (IS_NOT_NULL(ND_CDR(x))) { len += OPSIZE_PUSH + OPSIZE_JUMP; } - } while (IS_NOT_NULL(x = NODE_CDR(x))); + } while (IS_NOT_NULL(x = ND_CDR(x))); pos = COP_CURR_OFFSET(reg) + 1 + len; /* goal position */ do { - len = compile_length_tree(NODE_CAR(node), reg); - if (IS_NOT_NULL(NODE_CDR(node))) { - enum OpCode push = NODE_IS_SUPER(node) ? OP_PUSH_SUPER : OP_PUSH; + len = compile_length_tree(ND_CAR(node), reg, env); + if (IS_NOT_NULL(ND_CDR(node))) { + enum OpCode push = ND_IS_SUPER(node) ? OP_PUSH_SUPER : OP_PUSH; r = add_op(reg, push); if (r != 0) break; COP(reg)->push.addr = SIZE_INC + len + OPSIZE_JUMP; } - r = compile_tree(NODE_CAR(node), reg, env); + r = compile_tree(ND_CAR(node), reg, env); if (r != 0) break; - if (IS_NOT_NULL(NODE_CDR(node))) { + if (IS_NOT_NULL(ND_CDR(node))) { len = pos - (COP_CURR_OFFSET(reg) + 1); r = add_op(reg, OP_JUMP); if (r != 0) break; COP(reg)->jump.addr = len; } - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); } break; - case NODE_STRING: - if (NODE_STRING_IS_CRUDE(node)) + case ND_STRING: + if (ND_STRING_IS_CRUDE(node)) r = compile_string_crude_node(STR_(node), reg); else r = compile_string_node(node, reg); break; - case NODE_CCLASS: + case ND_CCLASS: r = compile_cclass_node(CCLASS_(node), reg); break; - case NODE_CTYPE: + case ND_CTYPE: { int op; switch (CTYPE_(node)->ctype) { case CTYPE_ANYCHAR: - r = add_op(reg, NODE_IS_MULTILINE(node) ? OP_ANYCHAR_ML : OP_ANYCHAR); + r = add_op(reg, ND_IS_MULTILINE(node) ? OP_ANYCHAR_ML : OP_ANYCHAR); break; case ONIGENC_CTYPE_WORD: @@ -2580,13 +2635,13 @@ compile_tree(Node* node, regex_t* reg, ParseEnv* env) } break; - case NODE_BACKREF: + case ND_BACKREF: { BackRefNode* br = BACKREF_(node); - if (NODE_IS_CHECKER(node)) { + if (ND_IS_CHECKER(node)) { #ifdef USE_BACKREF_WITH_LEVEL - if (NODE_IS_NEST_LEVEL(node)) { + if (ND_IS_NEST_LEVEL(node)) { r = add_op(reg, OP_BACKREF_CHECK_WITH_LEVEL); if (r != 0) return r; COP(reg)->backref_general.nest_level = br->nest_level; @@ -2601,8 +2656,8 @@ compile_tree(Node* node, regex_t* reg, ParseEnv* env) } else { #ifdef USE_BACKREF_WITH_LEVEL - if (NODE_IS_NEST_LEVEL(node)) { - if (NODE_IS_IGNORECASE(node)) + if (ND_IS_NEST_LEVEL(node)) { + if (ND_IS_IGNORECASE(node)) r = add_op(reg, OP_BACKREF_WITH_LEVEL_IC); else r = add_op(reg, OP_BACKREF_WITH_LEVEL); @@ -2615,7 +2670,7 @@ compile_tree(Node* node, regex_t* reg, ParseEnv* env) #endif if (br->back_num == 1) { n = br->back_static[0]; - if (NODE_IS_IGNORECASE(node)) { + if (ND_IS_IGNORECASE(node)) { r = add_op(reg, OP_BACKREF_N_IC); if (r != 0) return r; COP(reg)->backref_n.n1 = n; @@ -2636,7 +2691,7 @@ compile_tree(Node* node, regex_t* reg, ParseEnv* env) int num; int* p; - r = add_op(reg, NODE_IS_IGNORECASE(node) ? + r = add_op(reg, ND_IS_IGNORECASE(node) ? OP_BACKREF_MULTI_IC : OP_BACKREF_MULTI); if (r != 0) return r; @@ -2664,30 +2719,30 @@ compile_tree(Node* node, regex_t* reg, ParseEnv* env) break; #ifdef USE_CALL - case NODE_CALL: + case ND_CALL: r = compile_call(CALL_(node), reg, env); break; #endif - case NODE_QUANT: + case ND_QUANT: r = compile_quantifier_node(QUANT_(node), reg, env); break; - case NODE_BAG: + case ND_BAG: r = compile_bag_node(BAG_(node), reg, env); break; - case NODE_ANCHOR: + case ND_ANCHOR: r = compile_anchor_node(ANCHOR_(node), reg, env); break; - case NODE_GIMMICK: + case ND_GIMMICK: r = compile_gimmick_node(GIMMICK_(node), reg); break; default: #ifdef ONIG_DEBUG - fprintf(DBGFP, "compile_tree: undefined node type %d\n", NODE_TYPE(node)); + fprintf(DBGFP, "compile_tree: undefined node type %d\n", ND_TYPE(node)); #endif break; } @@ -2701,40 +2756,40 @@ make_named_capture_number_map(Node** plink, GroupNumMap* map, int* counter) int r; Node* node = *plink; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = make_named_capture_number_map(&(NODE_CAR(node)), map, counter); - } while (r >= 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = make_named_capture_number_map(&(ND_CAR(node)), map, counter); + } while (r >= 0 && IS_NOT_NULL(node = ND_CDR(node))); if (r < 0) return r; break; - case NODE_QUANT: + case ND_QUANT: { - Node** ptarget = &(NODE_BODY(node)); + Node** ptarget = &(ND_BODY(node)); r = make_named_capture_number_map(ptarget, map, counter); if (r < 0) return r; - if (r == 1 && NODE_TYPE(*ptarget) == NODE_QUANT) { + if (r == 1 && ND_TYPE(*ptarget) == ND_QUANT) { return onig_reduce_nested_quantifier(node); } } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (NODE_IS_NAMED_GROUP(node)) { + if (ND_IS_NAMED_GROUP(node)) { (*counter)++; map[en->m.regnum].new_val = *counter; en->m.regnum = *counter; - r = make_named_capture_number_map(&(NODE_BODY(node)), map, counter); + r = make_named_capture_number_map(&(ND_BODY(node)), map, counter); if (r < 0) return r; } else { - *plink = NODE_BODY(node); - NODE_BODY(node) = NULL_NODE; + *plink = ND_BODY(node); + ND_BODY(node) = NULL_NODE; onig_node_free(node); r = make_named_capture_number_map(plink, map, counter); if (r < 0) return r; @@ -2742,7 +2797,7 @@ make_named_capture_number_map(Node** plink, GroupNumMap* map, int* counter) } } else if (en->type == BAG_IF_ELSE) { - r = make_named_capture_number_map(&(NODE_BAG_BODY(en)), map, counter); + r = make_named_capture_number_map(&(ND_BAG_BODY(en)), map, counter); if (r < 0) return r; if (IS_NOT_NULL(en->te.Then)) { r = make_named_capture_number_map(&(en->te.Then), map, counter); @@ -2754,15 +2809,15 @@ make_named_capture_number_map(Node** plink, GroupNumMap* map, int* counter) } } else { - r = make_named_capture_number_map(&(NODE_BODY(node)), map, counter); + r = make_named_capture_number_map(&(ND_BODY(node)), map, counter); if (r < 0) return r; } } break; - case NODE_ANCHOR: - if (IS_NOT_NULL(NODE_BODY(node))) { - r = make_named_capture_number_map(&(NODE_BODY(node)), map, counter); + case ND_ANCHOR: + if (IS_NOT_NULL(ND_BODY(node))) { + r = make_named_capture_number_map(&(ND_BODY(node)), map, counter); if (r < 0) return r; } break; @@ -2781,7 +2836,7 @@ renumber_backref_node(Node* node, GroupNumMap* map) int *backs; BackRefNode* bn = BACKREF_(node); - if (! NODE_IS_BY_NAME(node)) + if (! ND_IS_BY_NAME(node)) return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED; old_num = bn->back_num; @@ -2807,23 +2862,23 @@ renumber_backref_traverse(Node* node, GroupNumMap* map) { int r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = renumber_backref_traverse(NODE_CAR(node), map); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = renumber_backref_traverse(ND_CAR(node), map); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_QUANT: - r = renumber_backref_traverse(NODE_BODY(node), map); + case ND_QUANT: + r = renumber_backref_traverse(ND_BODY(node), map); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); - r = renumber_backref_traverse(NODE_BODY(node), map); + r = renumber_backref_traverse(ND_BODY(node), map); if (r != 0) return r; if (en->type == BAG_IF_ELSE) { @@ -2839,13 +2894,13 @@ renumber_backref_traverse(Node* node, GroupNumMap* map) } break; - case NODE_BACKREF: + case ND_BACKREF: r = renumber_backref_node(node, map); break; - case NODE_ANCHOR: - if (IS_NOT_NULL(NODE_BODY(node))) - r = renumber_backref_traverse(NODE_BODY(node), map); + case ND_ANCHOR: + if (IS_NOT_NULL(ND_BODY(node))) + r = renumber_backref_traverse(ND_BODY(node), map); break; default: @@ -2860,27 +2915,27 @@ numbered_ref_check(Node* node) { int r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = numbered_ref_check(NODE_CAR(node)); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = numbered_ref_check(ND_CAR(node)); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ANCHOR: - if (IS_NULL(NODE_BODY(node))) + case ND_ANCHOR: + if (IS_NULL(ND_BODY(node))) break; /* fall */ - case NODE_QUANT: - r = numbered_ref_check(NODE_BODY(node)); + case ND_QUANT: + r = numbered_ref_check(ND_BODY(node)); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); - r = numbered_ref_check(NODE_BODY(node)); + r = numbered_ref_check(ND_BODY(node)); if (r != 0) return r; if (en->type == BAG_IF_ELSE) { @@ -2897,8 +2952,8 @@ numbered_ref_check(Node* node) break; - case NODE_BACKREF: - if (! NODE_IS_BY_NAME(node)) + case ND_BACKREF: + if (! ND_IS_BY_NAME(node)) return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED; break; @@ -2959,8 +3014,8 @@ fix_unset_addr_list(UnsetAddrList* uslist, regex_t* reg) AbsAddrType* paddr; for (i = 0; i < uslist->num; i++) { - if (! NODE_IS_FIXED_ADDR(uslist->us[i].target)) { - if (NODE_IS_CALLED(uslist->us[i].target)) + if (! ND_IS_FIXED_ADDR(uslist->us[i].target)) { + if (ND_IS_CALLED(uslist->us[i].target)) return ONIGERR_PARSER_BUG; else { /* CASE: called node doesn't have called address. @@ -2993,16 +3048,16 @@ is_exclusive(Node* x, Node* y, regex_t* reg) NodeType ytype; retry: - ytype = NODE_TYPE(y); - switch (NODE_TYPE(x)) { - case NODE_CTYPE: + ytype = ND_TYPE(y); + switch (ND_TYPE(x)) { + case ND_CTYPE: { if (CTYPE_(x)->ctype == CTYPE_ANYCHAR || CTYPE_(y)->ctype == CTYPE_ANYCHAR) break; switch (ytype) { - case NODE_CTYPE: + case ND_CTYPE: if (CTYPE_(y)->ctype == CTYPE_(x)->ctype && CTYPE_(y)->not != CTYPE_(x)->not && CTYPE_(y)->ascii_mode == CTYPE_(x)->ascii_mode) @@ -3011,7 +3066,7 @@ is_exclusive(Node* x, Node* y, regex_t* reg) return 0; break; - case NODE_CCLASS: + case ND_CCLASS: swap: { Node* tmp; @@ -3020,7 +3075,7 @@ is_exclusive(Node* x, Node* y, regex_t* reg) } break; - case NODE_STRING: + case ND_STRING: goto swap; break; @@ -3030,13 +3085,13 @@ is_exclusive(Node* x, Node* y, regex_t* reg) } break; - case NODE_CCLASS: + case ND_CCLASS: { int range; CClassNode* xc = CCLASS_(x); switch (ytype) { - case NODE_CTYPE: + case ND_CTYPE: switch (CTYPE_(y)->ctype) { case CTYPE_ANYCHAR: return 0; @@ -3078,7 +3133,7 @@ is_exclusive(Node* x, Node* y, regex_t* reg) } break; - case NODE_CCLASS: + case ND_CCLASS: { int v; CClassNode* yc = CCLASS_(y); @@ -3099,7 +3154,7 @@ is_exclusive(Node* x, Node* y, regex_t* reg) } break; - case NODE_STRING: + case ND_STRING: goto swap; break; @@ -3109,15 +3164,15 @@ is_exclusive(Node* x, Node* y, regex_t* reg) } break; - case NODE_STRING: + case ND_STRING: { StrNode* xs = STR_(x); - if (NODE_STRING_LEN(x) == 0) + if (ND_STRING_LEN(x) == 0) break; switch (ytype) { - case NODE_CTYPE: + case ND_CTYPE: switch (CTYPE_(y)->ctype) { case CTYPE_ANYCHAR: break; @@ -3141,7 +3196,7 @@ is_exclusive(Node* x, Node* y, regex_t* reg) } break; - case NODE_CCLASS: + case ND_CCLASS: { CClassNode* cc = CCLASS_(y); @@ -3151,13 +3206,13 @@ is_exclusive(Node* x, Node* y, regex_t* reg) } break; - case NODE_STRING: + case ND_STRING: { UChar *q; StrNode* ys = STR_(y); - len = NODE_STRING_LEN(x); - if (len > NODE_STRING_LEN(y)) len = NODE_STRING_LEN(y); + len = ND_STRING_LEN(x); + if (len > ND_STRING_LEN(y)) len = ND_STRING_LEN(y); for (i = 0, p = ys->s, q = xs->s; i < len; i++, p++, q++) { if (*p != *q) return 1; @@ -3183,73 +3238,74 @@ get_tree_head_literal(Node* node, int exact, regex_t* reg) { Node* n = NULL_NODE; - switch (NODE_TYPE(node)) { - case NODE_BACKREF: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_BACKREF: + case ND_ALT: #ifdef USE_CALL - case NODE_CALL: + case ND_CALL: #endif break; - case NODE_CTYPE: + case ND_CTYPE: if (CTYPE_(node)->ctype == CTYPE_ANYCHAR) break; /* fall */ - case NODE_CCLASS: + case ND_CCLASS: if (exact == 0) { n = node; } break; - case NODE_LIST: - n = get_tree_head_literal(NODE_CAR(node), exact, reg); + case ND_LIST: + n = get_tree_head_literal(ND_CAR(node), exact, reg); break; - case NODE_STRING: + case ND_STRING: { StrNode* sn = STR_(node); if (sn->end <= sn->s) break; - if (exact == 0 || !NODE_IS_REAL_IGNORECASE(node)) { + if (exact == 0 || !ND_IS_REAL_IGNORECASE(node)) { n = node; } } break; - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); if (qn->lower > 0) { if (IS_NOT_NULL(qn->head_exact)) n = qn->head_exact; else - n = get_tree_head_literal(NODE_BODY(node), exact, reg); + n = get_tree_head_literal(ND_BODY(node), exact, reg); } } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); switch (en->type) { case BAG_OPTION: case BAG_MEMORY: case BAG_STOP_BACKTRACK: - case BAG_IF_ELSE: - n = get_tree_head_literal(NODE_BODY(node), exact, reg); + n = get_tree_head_literal(ND_BODY(node), exact, reg); + break; + default: break; } } break; - case NODE_ANCHOR: + case ND_ANCHOR: if (ANCHOR_(node)->type == ANCR_PREC_READ) - n = get_tree_head_literal(NODE_BODY(node), exact, reg); + n = get_tree_head_literal(ND_BODY(node), exact, reg); break; - case NODE_GIMMICK: + case ND_GIMMICK: default: break; } @@ -3275,37 +3331,37 @@ get_tree_tail_literal(Node* node, Node** rnode, regex_t* reg, int nest_level) return GET_VALUE_NONE; } - switch (NODE_TYPE(node)) { - case NODE_LIST: - if (IS_NULL(NODE_CDR(node))) { - r = get_tree_tail_literal(NODE_CAR(node), rnode, reg, nest_level); + switch (ND_TYPE(node)) { + case ND_LIST: + if (IS_NULL(ND_CDR(node))) { + r = get_tree_tail_literal(ND_CAR(node), rnode, reg, nest_level); } else { - r = get_tree_tail_literal(NODE_CDR(node), rnode, reg, nest_level); + r = get_tree_tail_literal(ND_CDR(node), rnode, reg, nest_level); if (r == GET_VALUE_IGNORE) { - r = get_tree_tail_literal(NODE_CAR(node), rnode, reg, nest_level); + r = get_tree_tail_literal(ND_CAR(node), rnode, reg, nest_level); } } break; #ifdef USE_CALL - case NODE_CALL: - r = get_tree_tail_literal(NODE_BODY(node), rnode, reg, nest_level); + case ND_CALL: + r = get_tree_tail_literal(ND_BODY(node), rnode, reg, nest_level); break; #endif - case NODE_CTYPE: + case ND_CTYPE: if (CTYPE_(node)->ctype == CTYPE_ANYCHAR) { r = GET_VALUE_NONE; break; } /* fall */ - case NODE_CCLASS: + case ND_CCLASS: *rnode = node; r = GET_VALUE_FOUND; break; - case NODE_STRING: + case ND_STRING: { StrNode* sn = STR_(node); @@ -3314,7 +3370,7 @@ get_tree_tail_literal(Node* node, Node** rnode, regex_t* reg, int nest_level) break; } - if (NODE_IS_REAL_IGNORECASE(node)) { + if (ND_IS_REAL_IGNORECASE(node)) { r = GET_VALUE_NONE; break; } @@ -3324,43 +3380,43 @@ get_tree_tail_literal(Node* node, Node** rnode, regex_t* reg, int nest_level) } break; - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); if (qn->lower != 0) { - r = get_tree_tail_literal(NODE_BODY(node), rnode, reg, nest_level); + r = get_tree_tail_literal(ND_BODY(node), rnode, reg, nest_level); } else r = GET_VALUE_NONE; } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (NODE_IS_MARK1(node)) + if (ND_IS_MARK1(node)) r = GET_VALUE_NONE; else { - NODE_STATUS_ADD(node, MARK1); - r = get_tree_tail_literal(NODE_BODY(node), rnode, reg, nest_level); - NODE_STATUS_REMOVE(node, MARK1); + ND_STATUS_ADD(node, MARK1); + r = get_tree_tail_literal(ND_BODY(node), rnode, reg, nest_level); + ND_STATUS_REMOVE(node, MARK1); } } else { - r = get_tree_tail_literal(NODE_BODY(node), rnode, reg, nest_level); + r = get_tree_tail_literal(ND_BODY(node), rnode, reg, nest_level); } } break; - case NODE_ANCHOR: - case NODE_GIMMICK: + case ND_ANCHOR: + case ND_GIMMICK: r = GET_VALUE_IGNORE; break; - case NODE_ALT: - case NODE_BACKREF: + case ND_ALT: + case ND_BACKREF: default: r = GET_VALUE_NONE; break; @@ -3376,33 +3432,33 @@ check_called_node_in_look_behind(Node* node, int not) r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = check_called_node_in_look_behind(NODE_CAR(node), not); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = check_called_node_in_look_behind(ND_CAR(node), not); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_QUANT: - r = check_called_node_in_look_behind(NODE_BODY(node), not); + case ND_QUANT: + r = check_called_node_in_look_behind(ND_BODY(node), not); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (NODE_IS_MARK1(node)) + if (ND_IS_MARK1(node)) return 0; else { - NODE_STATUS_ADD(node, MARK1); - r = check_called_node_in_look_behind(NODE_BODY(node), not); - NODE_STATUS_REMOVE(node, MARK1); + ND_STATUS_ADD(node, MARK1); + r = check_called_node_in_look_behind(ND_BODY(node), not); + ND_STATUS_REMOVE(node, MARK1); } } else { - r = check_called_node_in_look_behind(NODE_BODY(node), not); + r = check_called_node_in_look_behind(ND_BODY(node), not); if (r == 0 && en->type == BAG_IF_ELSE) { if (IS_NOT_NULL(en->te.Then)) { r = check_called_node_in_look_behind(en->te.Then, not); @@ -3416,13 +3472,13 @@ check_called_node_in_look_behind(Node* node, int not) } break; - case NODE_ANCHOR: - if (IS_NOT_NULL(NODE_BODY(node))) - r = check_called_node_in_look_behind(NODE_BODY(node), not); + case ND_ANCHOR: + if (IS_NOT_NULL(ND_BODY(node))) + r = check_called_node_in_look_behind(ND_BODY(node), not); break; - case NODE_GIMMICK: - if (NODE_IS_ABSENT_WITH_SIDE_EFFECTS(node) != 0) + case ND_GIMMICK: + if (ND_IS_ABSENT_WITH_SIDE_EFFECTS(node) != 0) return 1; break; @@ -3435,9 +3491,9 @@ check_called_node_in_look_behind(Node* node, int not) /* allowed node types in look-behind */ #define ALLOWED_TYPE_IN_LB \ - ( NODE_BIT_LIST | NODE_BIT_ALT | NODE_BIT_STRING | NODE_BIT_CCLASS \ - | NODE_BIT_CTYPE | NODE_BIT_ANCHOR | NODE_BIT_BAG | NODE_BIT_QUANT \ - | NODE_BIT_CALL | NODE_BIT_BACKREF | NODE_BIT_GIMMICK) + ( ND_BIT_LIST | ND_BIT_ALT | ND_BIT_STRING | ND_BIT_CCLASS \ + | ND_BIT_CTYPE | ND_BIT_ANCHOR | ND_BIT_BAG | ND_BIT_QUANT \ + | ND_BIT_CALL | ND_BIT_BACKREF | ND_BIT_GIMMICK) #define ALLOWED_BAG_IN_LB ( 1<<BAG_MEMORY | 1<<BAG_OPTION | 1<<BAG_STOP_BACKTRACK | 1<<BAG_IF_ELSE ) #define ALLOWED_BAG_IN_LB_NOT ( 1<<BAG_OPTION | 1<<BAG_STOP_BACKTRACK | 1<<BAG_IF_ELSE ) @@ -3467,34 +3523,34 @@ check_node_in_look_behind(Node* node, int not, int* used) NodeType type; int r = 0; - type = NODE_TYPE(node); - if ((NODE_TYPE2BIT(type) & ALLOWED_TYPE_IN_LB) == 0) + type = ND_TYPE(node); + if ((ND_TYPE2BIT(type) & ALLOWED_TYPE_IN_LB) == 0) return 1; switch (type) { - case NODE_LIST: - case NODE_ALT: + case ND_LIST: + case ND_ALT: do { - r = check_node_in_look_behind(NODE_CAR(node), not, used); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = check_node_in_look_behind(ND_CAR(node), not, used); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_QUANT: - r = check_node_in_look_behind(NODE_BODY(node), not, used); + case ND_QUANT: + r = check_node_in_look_behind(ND_BODY(node), not, used); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (((1<<en->type) & bag_mask[not]) == 0) return 1; - r = check_node_in_look_behind(NODE_BODY(node), not, used); + r = check_node_in_look_behind(ND_BODY(node), not, used); if (r != 0) break; if (en->type == BAG_MEMORY) { - if (NODE_IS_BACKREF(node) || NODE_IS_CALLED(node) - || NODE_IS_REFERENCED(node)) + if (ND_IS_BACKREF(node) || ND_IS_CALLED(node) + || ND_IS_REFERENCED(node)) *used = TRUE; } else if (en->type == BAG_IF_ELSE) { @@ -3509,17 +3565,17 @@ check_node_in_look_behind(Node* node, int not, int* used) } break; - case NODE_ANCHOR: + case ND_ANCHOR: type = ANCHOR_(node)->type; if ((type & anchor_mask[not]) == 0) return 1; - if (IS_NOT_NULL(NODE_BODY(node))) - r = check_node_in_look_behind(NODE_BODY(node), not, used); + if (IS_NOT_NULL(ND_BODY(node))) + r = check_node_in_look_behind(ND_BODY(node), not, used); break; - case NODE_GIMMICK: - if (NODE_IS_ABSENT_WITH_SIDE_EFFECTS(node) != 0) + case ND_GIMMICK: + if (ND_IS_ABSENT_WITH_SIDE_EFFECTS(node) != 0) return 1; { @@ -3529,14 +3585,14 @@ check_node_in_look_behind(Node* node, int not, int* used) } break; - case NODE_CALL: - if (NODE_IS_RECURSION(node)) { + case ND_CALL: + if (ND_IS_RECURSION(node)) { /* fix: Issue 38040 in oss-fuzz */ /* This node should be removed before recursive call check. */ *used = TRUE; } else - r = check_called_node_in_look_behind(NODE_BODY(node), not); + r = check_called_node_in_look_behind(ND_BODY(node), not); break; default: @@ -3552,14 +3608,14 @@ node_min_byte_len(Node* node, ParseEnv* env) OnigLen tmin; len = 0; - switch (NODE_TYPE(node)) { - case NODE_BACKREF: - if (! NODE_IS_CHECKER(node)) { + switch (ND_TYPE(node)) { + case ND_BACKREF: + if (! ND_IS_CHECKER(node)) { int i; int* backs; MemEnv* mem_env = PARSEENV_MEMENV(env); BackRefNode* br = BACKREF_(node); - if (NODE_IS_RECURSION(node)) break; + if (ND_IS_RECURSION(node)) break; backs = BACKREFS_P(br); len = node_min_byte_len(mem_env[backs[0]].mem_node, env); @@ -3571,10 +3627,10 @@ node_min_byte_len(Node* node, ParseEnv* env) break; #ifdef USE_CALL - case NODE_CALL: + case ND_CALL: { - Node* t = NODE_BODY(node); - if (NODE_IS_FIXED_MIN(t)) + Node* t = ND_BODY(node); + if (ND_IS_FIXED_MIN(t)) len = BAG_(t)->min_len; else len = node_min_byte_len(t, env); @@ -3582,79 +3638,79 @@ node_min_byte_len(Node* node, ParseEnv* env) break; #endif - case NODE_LIST: + case ND_LIST: do { - tmin = node_min_byte_len(NODE_CAR(node), env); + tmin = node_min_byte_len(ND_CAR(node), env); len = distance_add(len, tmin); - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ALT: + case ND_ALT: { Node *x, *y; y = node; do { - x = NODE_CAR(y); + x = ND_CAR(y); tmin = node_min_byte_len(x, env); if (y == node) len = tmin; else if (len > tmin) len = tmin; - } while (IS_NOT_NULL(y = NODE_CDR(y))); + } while (IS_NOT_NULL(y = ND_CDR(y))); } break; - case NODE_STRING: + case ND_STRING: { StrNode* sn = STR_(node); len = (int )(sn->end - sn->s); } break; - case NODE_CTYPE: - case NODE_CCLASS: + case ND_CTYPE: + case ND_CCLASS: len = ONIGENC_MBC_MINLEN(env->enc); break; - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); if (qn->lower > 0) { - len = node_min_byte_len(NODE_BODY(node), env); + len = node_min_byte_len(ND_BODY(node), env); len = distance_multiply(len, qn->lower); } } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); switch (en->type) { case BAG_MEMORY: - if (NODE_IS_FIXED_MIN(node)) + if (ND_IS_FIXED_MIN(node)) len = en->min_len; else { - if (NODE_IS_MARK1(node)) + if (ND_IS_MARK1(node)) len = 0; /* recursive */ else { - NODE_STATUS_ADD(node, MARK1); - len = node_min_byte_len(NODE_BODY(node), env); - NODE_STATUS_REMOVE(node, MARK1); + ND_STATUS_ADD(node, MARK1); + len = node_min_byte_len(ND_BODY(node), env); + ND_STATUS_REMOVE(node, MARK1); en->min_len = len; - NODE_STATUS_ADD(node, FIXED_MIN); + ND_STATUS_ADD(node, FIXED_MIN); } } break; case BAG_OPTION: case BAG_STOP_BACKTRACK: - len = node_min_byte_len(NODE_BODY(node), env); + len = node_min_byte_len(ND_BODY(node), env); break; case BAG_IF_ELSE: { OnigLen elen; - len = node_min_byte_len(NODE_BODY(node), env); + len = node_min_byte_len(ND_BODY(node), env); if (IS_NOT_NULL(en->te.Then)) len += node_min_byte_len(en->te.Then, env); if (IS_NOT_NULL(en->te.Else)) @@ -3668,7 +3724,7 @@ node_min_byte_len(Node* node, ParseEnv* env) } break; - case NODE_GIMMICK: + case ND_GIMMICK: { GimmickNode* g = GIMMICK_(node); if (g->type == GIMMICK_FAIL) { @@ -3677,7 +3733,7 @@ node_min_byte_len(Node* node, ParseEnv* env) } } /* fall */ - case NODE_ANCHOR: + case ND_ANCHOR: default: break; } @@ -3690,26 +3746,26 @@ check_backrefs(Node* node, ParseEnv* env) { int r; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = check_backrefs(NODE_CAR(node), env); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = check_backrefs(ND_CAR(node), env); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ANCHOR: + case ND_ANCHOR: if (! ANCHOR_HAS_BODY(ANCHOR_(node))) { r = 0; break; } /* fall */ - case NODE_QUANT: - r = check_backrefs(NODE_BODY(node), env); + case ND_QUANT: + r = check_backrefs(ND_BODY(node), env); break; - case NODE_BAG: - r = check_backrefs(NODE_BODY(node), env); + case ND_BAG: + r = check_backrefs(ND_BODY(node), env); { BagNode* en = BAG_(node); @@ -3726,7 +3782,7 @@ check_backrefs(Node* node, ParseEnv* env) } break; - case NODE_BACKREF: + case ND_BACKREF: { int i; BackRefNode* br = BACKREF_(node); @@ -3737,7 +3793,7 @@ check_backrefs(Node* node, ParseEnv* env) if (backs[i] > env->num_mem) return ONIGERR_INVALID_BACKREF; - NODE_STATUS_ADD(mem_env[backs[i]].mem_node, BACKREF); + ND_STATUS_ADD(mem_env[backs[i]].mem_node, BACKREF); } r = 0; } @@ -3756,15 +3812,15 @@ set_empty_repeat_node_trav(Node* node, Node* empty, ParseEnv* env) { int r; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = set_empty_repeat_node_trav(NODE_CAR(node), empty, env); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = set_empty_repeat_node_trav(ND_CAR(node), empty, env); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ANCHOR: + case ND_ANCHOR: { AnchorNode* an = ANCHOR_(node); @@ -3781,22 +3837,22 @@ set_empty_repeat_node_trav(Node* node, Node* empty, ParseEnv* env) default: break; } - r = set_empty_repeat_node_trav(NODE_BODY(node), empty, env); + r = set_empty_repeat_node_trav(ND_BODY(node), empty, env); } break; - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); if (qn->emptiness != BODY_IS_NOT_EMPTY) empty = node; - r = set_empty_repeat_node_trav(NODE_BODY(node), empty, env); + r = set_empty_repeat_node_trav(ND_BODY(node), empty, env); } break; - case NODE_BAG: - if (IS_NOT_NULL(NODE_BODY(node))) { - r = set_empty_repeat_node_trav(NODE_BODY(node), empty, env); + case ND_BAG: + if (IS_NOT_NULL(ND_BODY(node))) { + r = set_empty_repeat_node_trav(ND_BODY(node), empty, env); if (r != 0) return r; } { @@ -3804,7 +3860,7 @@ set_empty_repeat_node_trav(Node* node, Node* empty, ParseEnv* env) r = 0; if (en->type == BAG_MEMORY) { - if (NODE_IS_BACKREF(node)) { + if (ND_IS_BACKREF(node)) { if (IS_NOT_NULL(empty)) PARSEENV_MEMENV(env)[en->m.regnum].empty_repeat_node = empty; } @@ -3834,7 +3890,7 @@ is_ancestor_node(Node* node, Node* me) { Node* parent; - while ((parent = NODE_PARENT(me)) != NULL_NODE) { + while ((parent = ND_PARENT(me)) != NULL_NODE) { if (parent == node) return 1; me = parent; } @@ -3844,30 +3900,30 @@ is_ancestor_node(Node* node, Node* me) static void set_empty_status_check_trav(Node* node, ParseEnv* env) { - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - set_empty_status_check_trav(NODE_CAR(node), env); - } while (IS_NOT_NULL(node = NODE_CDR(node))); + set_empty_status_check_trav(ND_CAR(node), env); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ANCHOR: + case ND_ANCHOR: { AnchorNode* an = ANCHOR_(node); if (! ANCHOR_HAS_BODY(an)) break; - set_empty_status_check_trav(NODE_BODY(node), env); + set_empty_status_check_trav(ND_BODY(node), env); } break; - case NODE_QUANT: - set_empty_status_check_trav(NODE_BODY(node), env); + case ND_QUANT: + set_empty_status_check_trav(ND_BODY(node), env); break; - case NODE_BAG: - if (IS_NOT_NULL(NODE_BODY(node))) - set_empty_status_check_trav(NODE_BODY(node), env); + case ND_BAG: + if (IS_NOT_NULL(ND_BODY(node))) + set_empty_status_check_trav(ND_BODY(node), env); { BagNode* en = BAG_(node); @@ -3882,7 +3938,7 @@ set_empty_status_check_trav(Node* node, ParseEnv* env) } break; - case NODE_BACKREF: + case ND_BACKREF: { int i; int* backs; @@ -3894,8 +3950,8 @@ set_empty_status_check_trav(Node* node, ParseEnv* env) if (IS_NOT_NULL(ernode)) { if (! is_ancestor_node(ernode, node)) { MEM_STATUS_LIMIT_ON(QUANT_(ernode)->empty_status_mem, backs[i]); - NODE_STATUS_ADD(ernode, EMPTY_STATUS_CHECK); - NODE_STATUS_ADD(mem_env[backs[i]].mem_node, EMPTY_STATUS_CHECK); + ND_STATUS_ADD(ernode, EMPTY_STATUS_CHECK); + ND_STATUS_ADD(mem_env[backs[i]].mem_node, EMPTY_STATUS_CHECK); } } } @@ -3910,28 +3966,28 @@ set_empty_status_check_trav(Node* node, ParseEnv* env) static void set_parent_node_trav(Node* node, Node* parent) { - NODE_PARENT(node) = parent; + ND_PARENT(node) = parent; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - set_parent_node_trav(NODE_CAR(node), node); - } while (IS_NOT_NULL(node = NODE_CDR(node))); + set_parent_node_trav(ND_CAR(node), node); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ANCHOR: + case ND_ANCHOR: if (! ANCHOR_HAS_BODY(ANCHOR_(node))) break; - set_parent_node_trav(NODE_BODY(node), node); + set_parent_node_trav(ND_BODY(node), node); break; - case NODE_QUANT: - set_parent_node_trav(NODE_BODY(node), node); + case ND_QUANT: + set_parent_node_trav(ND_BODY(node), node); break; - case NODE_BAG: - if (IS_NOT_NULL(NODE_BODY(node))) - set_parent_node_trav(NODE_BODY(node), node); + case ND_BAG: + if (IS_NOT_NULL(ND_BODY(node))) + set_parent_node_trav(ND_BODY(node), node); { BagNode* en = BAG_(node); @@ -3963,45 +4019,45 @@ infinite_recursive_call_check(Node* node, ParseEnv* env, int head) int ret; int r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: + switch (ND_TYPE(node)) { + case ND_LIST: { Node *x; OnigLen min; x = node; do { - ret = infinite_recursive_call_check(NODE_CAR(x), env, head); + ret = infinite_recursive_call_check(ND_CAR(x), env, head); if (ret < 0 || (ret & RECURSION_INFINITE) != 0) return ret; r |= ret; if (head != 0) { - min = node_min_byte_len(NODE_CAR(x), env); + min = node_min_byte_len(ND_CAR(x), env); if (min != 0) head = 0; } - } while (IS_NOT_NULL(x = NODE_CDR(x))); + } while (IS_NOT_NULL(x = ND_CDR(x))); } break; - case NODE_ALT: + case ND_ALT: { int must; must = RECURSION_MUST; do { - ret = infinite_recursive_call_check(NODE_CAR(node), env, head); + ret = infinite_recursive_call_check(ND_CAR(node), env, head); if (ret < 0 || (ret & RECURSION_INFINITE) != 0) return ret; r |= (ret & RECURSION_EXIST); must &= ret; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); r |= must; } break; - case NODE_QUANT: + case ND_QUANT: if (QUANT_(node)->upper == 0) break; - r = infinite_recursive_call_check(NODE_BODY(node), env, head); + r = infinite_recursive_call_check(ND_BODY(node), env, head); if (r < 0) return r; if ((r & RECURSION_MUST) != 0) { if (QUANT_(node)->lower == 0) @@ -4009,40 +4065,40 @@ infinite_recursive_call_check(Node* node, ParseEnv* env, int head) } break; - case NODE_ANCHOR: + case ND_ANCHOR: if (! ANCHOR_HAS_BODY(ANCHOR_(node))) break; /* fall */ - case NODE_CALL: - r = infinite_recursive_call_check(NODE_BODY(node), env, head); + case ND_CALL: + r = infinite_recursive_call_check(ND_BODY(node), env, head); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (NODE_IS_MARK2(node)) + if (ND_IS_MARK2(node)) return 0; - else if (NODE_IS_MARK1(node)) + else if (ND_IS_MARK1(node)) return (head == 0 ? RECURSION_EXIST | RECURSION_MUST : RECURSION_EXIST | RECURSION_MUST | RECURSION_INFINITE); else { - NODE_STATUS_ADD(node, MARK2); - r = infinite_recursive_call_check(NODE_BODY(node), env, head); - NODE_STATUS_REMOVE(node, MARK2); + ND_STATUS_ADD(node, MARK2); + r = infinite_recursive_call_check(ND_BODY(node), env, head); + ND_STATUS_REMOVE(node, MARK2); } } else if (en->type == BAG_IF_ELSE) { int eret; - ret = infinite_recursive_call_check(NODE_BODY(node), env, head); + ret = infinite_recursive_call_check(ND_BODY(node), env, head); if (ret < 0 || (ret & RECURSION_INFINITE) != 0) return ret; r |= ret; if (IS_NOT_NULL(en->te.Then)) { OnigLen min; if (head != 0) { - min = node_min_byte_len(NODE_BODY(node), env); + min = node_min_byte_len(ND_BODY(node), env); } else min = 0; @@ -4062,7 +4118,7 @@ infinite_recursive_call_check(Node* node, ParseEnv* env, int head) } } else { - r = infinite_recursive_call_check(NODE_BODY(node), env, head); + r = infinite_recursive_call_check(ND_BODY(node), env, head); } } break; @@ -4079,40 +4135,40 @@ infinite_recursive_call_check_trav(Node* node, ParseEnv* env) { int r; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = infinite_recursive_call_check_trav(NODE_CAR(node), env); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = infinite_recursive_call_check_trav(ND_CAR(node), env); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ANCHOR: + case ND_ANCHOR: if (! ANCHOR_HAS_BODY(ANCHOR_(node))) { r = 0; break; } /* fall */ - case NODE_QUANT: - r = infinite_recursive_call_check_trav(NODE_BODY(node), env); + case ND_QUANT: + r = infinite_recursive_call_check_trav(ND_BODY(node), env); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (NODE_IS_RECURSION(node) && NODE_IS_CALLED(node)) { + if (ND_IS_RECURSION(node) && ND_IS_CALLED(node)) { int ret; - NODE_STATUS_ADD(node, MARK1); + ND_STATUS_ADD(node, MARK1); - ret = infinite_recursive_call_check(NODE_BODY(node), env, 1); + ret = infinite_recursive_call_check(ND_BODY(node), env, 1); if (ret < 0) return ret; else if ((ret & (RECURSION_MUST | RECURSION_INFINITE)) != 0) return ONIGERR_NEVER_ENDING_RECURSION; - NODE_STATUS_REMOVE(node, MARK1); + ND_STATUS_REMOVE(node, MARK1); } } else if (en->type == BAG_IF_ELSE) { @@ -4127,7 +4183,7 @@ infinite_recursive_call_check_trav(Node* node, ParseEnv* env) } } - r = infinite_recursive_call_check_trav(NODE_BODY(node), env); + r = infinite_recursive_call_check_trav(ND_BODY(node), env); break; default: @@ -4143,46 +4199,46 @@ recursive_call_check(Node* node) { int r; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: r = 0; do { - r |= recursive_call_check(NODE_CAR(node)); - } while (IS_NOT_NULL(node = NODE_CDR(node))); + r |= recursive_call_check(ND_CAR(node)); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ANCHOR: + case ND_ANCHOR: if (! ANCHOR_HAS_BODY(ANCHOR_(node))) { r = 0; break; } /* fall */ - case NODE_QUANT: - r = recursive_call_check(NODE_BODY(node)); + case ND_QUANT: + r = recursive_call_check(ND_BODY(node)); break; - case NODE_CALL: - r = recursive_call_check(NODE_BODY(node)); + case ND_CALL: + r = recursive_call_check(ND_BODY(node)); if (r != 0) { - if (NODE_IS_MARK1(NODE_BODY(node))) - NODE_STATUS_ADD(node, RECURSION); + if (ND_IS_MARK1(ND_BODY(node))) + ND_STATUS_ADD(node, RECURSION); } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (NODE_IS_MARK2(node)) + if (ND_IS_MARK2(node)) return 0; - else if (NODE_IS_MARK1(node)) + else if (ND_IS_MARK1(node)) return 1; /* recursion */ else { - NODE_STATUS_ADD(node, MARK2); - r = recursive_call_check(NODE_BODY(node)); - NODE_STATUS_REMOVE(node, MARK2); + ND_STATUS_ADD(node, MARK2); + r = recursive_call_check(ND_BODY(node)); + ND_STATUS_REMOVE(node, MARK2); } } else if (en->type == BAG_IF_ELSE) { @@ -4193,10 +4249,10 @@ recursive_call_check(Node* node) if (IS_NOT_NULL(en->te.Else)) { r |= recursive_call_check(en->te.Else); } - r |= recursive_call_check(NODE_BODY(node)); + r |= recursive_call_check(ND_BODY(node)); } else { - r = recursive_call_check(NODE_BODY(node)); + r = recursive_call_check(ND_BODY(node)); } } break; @@ -4217,65 +4273,65 @@ recursive_call_check_trav(Node* node, ParseEnv* env, int state) { int r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: { int ret; do { - ret = recursive_call_check_trav(NODE_CAR(node), env, state); + ret = recursive_call_check_trav(ND_CAR(node), env, state); if (ret == FOUND_CALLED_NODE) r = FOUND_CALLED_NODE; else if (ret < 0) return ret; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); } break; - case NODE_QUANT: - r = recursive_call_check_trav(NODE_BODY(node), env, state); + case ND_QUANT: + r = recursive_call_check_trav(ND_BODY(node), env, state); if (QUANT_(node)->upper == 0) { if (r == FOUND_CALLED_NODE) QUANT_(node)->include_referred = 1; } break; - case NODE_ANCHOR: + case ND_ANCHOR: { AnchorNode* an = ANCHOR_(node); if (ANCHOR_HAS_BODY(an)) - r = recursive_call_check_trav(NODE_ANCHOR_BODY(an), env, state); + r = recursive_call_check_trav(ND_ANCHOR_BODY(an), env, state); } break; - case NODE_BAG: + case ND_BAG: { int ret; int state1; BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (NODE_IS_CALLED(node)) { + if (ND_IS_CALLED(node)) { r = FOUND_CALLED_NODE; goto check_recursion; } else if ((state & IN_RECURSION) != 0) { check_recursion: - if (! NODE_IS_RECURSION(node)) { - NODE_STATUS_ADD(node, MARK1); - ret = recursive_call_check(NODE_BODY(node)); + if (! ND_IS_RECURSION(node)) { + ND_STATUS_ADD(node, MARK1); + ret = recursive_call_check(ND_BODY(node)); if (ret != 0) { - NODE_STATUS_ADD(node, RECURSION); + ND_STATUS_ADD(node, RECURSION); MEM_STATUS_ON(env->backtrack_mem, en->m.regnum); } - NODE_STATUS_REMOVE(node, MARK1); + ND_STATUS_REMOVE(node, MARK1); } } } state1 = state; - if (NODE_IS_RECURSION(node)) + if (ND_IS_RECURSION(node)) state1 |= IN_RECURSION; - ret = recursive_call_check_trav(NODE_BODY(node), env, state1); + ret = recursive_call_check_trav(ND_BODY(node), env, state1); if (ret == FOUND_CALLED_NODE) r = FOUND_CALLED_NODE; @@ -4306,10 +4362,10 @@ recursive_call_check_trav(Node* node, ParseEnv* env, int state) static void remove_from_list(Node* prev, Node* a) { - if (NODE_CDR(prev) != a) return ; + if (ND_CDR(prev) != a) return ; - NODE_CDR(prev) = NODE_CDR(a); - NODE_CDR(a) = NULL_NODE; + ND_CDR(prev) = ND_CDR(a); + ND_CDR(a) = NULL_NODE; } static int @@ -4317,8 +4373,8 @@ reduce_string_list(Node* node, OnigEncoding enc) { int r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: + switch (ND_TYPE(node)) { + case ND_LIST: { Node* prev; Node* curr; @@ -4327,12 +4383,12 @@ reduce_string_list(Node* node, OnigEncoding enc) prev = NULL_NODE; do { - next_node = NODE_CDR(node); - curr = NODE_CAR(node); - if (NODE_TYPE(curr) == NODE_STRING) { + next_node = ND_CDR(node); + curr = ND_CAR(node); + if (ND_TYPE(curr) == ND_STRING) { if (IS_NULL(prev) || STR_(curr)->flag != STR_(prev)->flag - || NODE_STATUS(curr) != NODE_STATUS(prev)) { + || ND_STATUS(curr) != ND_STATUS(prev)) { prev = curr; prev_node = node; } @@ -4370,14 +4426,14 @@ reduce_string_list(Node* node, OnigEncoding enc) } break; - case NODE_ALT: + case ND_ALT: do { - r = reduce_string_list(NODE_CAR(node), enc); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = reduce_string_list(ND_CAR(node), enc); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; #ifdef USE_CHECK_VALIDITY_OF_STRING_IN_TREE - case NODE_STRING: + case ND_STRING: { StrNode* sn = STR_(node); if (! ONIGENC_IS_VALID_MBC_STRING(enc, sn->s, sn->end)) @@ -4386,19 +4442,19 @@ reduce_string_list(Node* node, OnigEncoding enc) break; #endif - case NODE_ANCHOR: - if (IS_NULL(NODE_BODY(node))) + case ND_ANCHOR: + if (IS_NULL(ND_BODY(node))) break; /* fall */ - case NODE_QUANT: - r = reduce_string_list(NODE_BODY(node), enc); + case ND_QUANT: + r = reduce_string_list(ND_BODY(node), enc); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); - r = reduce_string_list(NODE_BODY(node), enc); + r = reduce_string_list(ND_BODY(node), enc); if (r != 0) return r; if (en->type == BAG_IF_ELSE) { @@ -4447,26 +4503,26 @@ divide_look_behind_alternatives(Node* node) an = ANCHOR_(node); anc_type = an->type; - head = NODE_ANCHOR_BODY(an); - np = NODE_CAR(head); + head = ND_ANCHOR_BODY(an); + np = ND_CAR(head); node_swap(node, head); - NODE_CAR(node) = head; - NODE_BODY(head) = np; + ND_CAR(node) = head; + ND_BODY(head) = np; np = node; - while (IS_NOT_NULL(np = NODE_CDR(np))) { + while (IS_NOT_NULL(np = ND_CDR(np))) { r = onig_node_copy(&insert_node, head); if (r != 0) return r; CHECK_NULL_RETURN_MEMERR(insert_node); - NODE_BODY(insert_node) = NODE_CAR(np); - NODE_CAR(np) = insert_node; + ND_BODY(insert_node) = ND_CAR(np); + ND_CAR(np) = insert_node; } if (anc_type == ANCR_LOOK_BEHIND_NOT) { np = node; do { - NODE_SET_TYPE(np, NODE_LIST); /* alt -> list */ - } while (IS_NOT_NULL(np = NODE_CDR(np))); + ND_SET_TYPE(np, ND_LIST); /* alt -> list */ + } while (IS_NOT_NULL(np = ND_CDR(np))); } return 0; } @@ -4477,12 +4533,12 @@ node_reduce_in_look_behind(Node* node) NodeType type; Node* body; - if (NODE_TYPE(node) != NODE_QUANT) return 0; + if (ND_TYPE(node) != ND_QUANT) return 0; - body = NODE_BODY(node); - type = NODE_TYPE(body); - if (type == NODE_STRING || type == NODE_CTYPE || - type == NODE_CCLASS || type == NODE_BACKREF) { + body = ND_BODY(node); + type = ND_TYPE(body); + if (type == ND_STRING || type == ND_CTYPE || + type == ND_CCLASS || type == ND_BACKREF) { QuantNode* qn = QUANT_(node); qn->upper = qn->lower; if (qn->upper == 0) @@ -4497,17 +4553,17 @@ list_reduce_in_look_behind(Node* node) { int r; - switch (NODE_TYPE(node)) { - case NODE_QUANT: + switch (ND_TYPE(node)) { + case ND_QUANT: r = node_reduce_in_look_behind(node); if (r > 0) r = 0; break; - case NODE_LIST: + case ND_LIST: do { - r = node_reduce_in_look_behind(NODE_CAR(node)); + r = node_reduce_in_look_behind(ND_CAR(node)); if (r <= 0) break; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; default: @@ -4523,11 +4579,11 @@ alt_reduce_in_look_behind(Node* node, regex_t* reg, ParseEnv* env) { int r; - switch (NODE_TYPE(node)) { - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_ALT: do { - r = list_reduce_in_look_behind(NODE_CAR(node)); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = list_reduce_in_look_behind(ND_CAR(node)); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; default: @@ -4551,7 +4607,7 @@ tune_look_behind(Node* node, regex_t* reg, int state, ParseEnv* env) AnchorNode* an = ANCHOR_(node); used = FALSE; - r = check_node_in_look_behind(NODE_ANCHOR_BODY(an), + r = check_node_in_look_behind(ND_ANCHOR_BODY(an), an->type == ANCR_LOOK_BEHIND_NOT ? 1 : 0, &used); if (r < 0) return r; @@ -4562,7 +4618,7 @@ tune_look_behind(Node* node, regex_t* reg, int state, ParseEnv* env) else state1 = state | IN_LOOK_BEHIND; - body = NODE_ANCHOR_BODY(an); + body = ND_ANCHOR_BODY(an); /* Execute tune_tree(body) before call node_char_len(). Because case-fold expansion must be done before node_char_len(). */ @@ -4642,8 +4698,8 @@ tune_next(Node* node, Node* next_node, regex_t* reg) called = FALSE; retry: - type = NODE_TYPE(node); - if (type == NODE_QUANT) { + type = ND_TYPE(node); + if (type == ND_QUANT) { QuantNode* qn = QUANT_(node); if (qn->greedy && IS_INFINITE_REPEAT(qn->upper)) { #ifdef USE_QUANT_PEEK_NEXT @@ -4657,29 +4713,29 @@ tune_next(Node* node, Node* next_node, regex_t* reg) #endif /* automatic posseivation a*b ==> (?>a*)b */ if (qn->lower <= 1) { - if (is_strict_real_node(NODE_BODY(node))) { + if (is_strict_real_node(ND_BODY(node))) { Node *x, *y; - x = get_tree_head_literal(NODE_BODY(node), 0, reg); + x = get_tree_head_literal(ND_BODY(node), 0, reg); if (IS_NOT_NULL(x)) { y = get_tree_head_literal(next_node, 0, reg); if (IS_NOT_NULL(y) && is_exclusive(x, y, reg)) { Node* en = onig_node_new_bag(BAG_STOP_BACKTRACK); CHECK_NULL_RETURN_MEMERR(en); - NODE_STATUS_ADD(en, STRICT_REAL_REPEAT); + ND_STATUS_ADD(en, STRICT_REAL_REPEAT); node_swap(node, en); - NODE_BODY(node) = en; + ND_BODY(node) = en; } } } } } } - else if (type == NODE_BAG) { + else if (type == ND_BAG) { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (NODE_IS_CALLED(node)) + if (ND_IS_CALLED(node)) called = TRUE; - node = NODE_BODY(node); + node = ND_BODY(node); goto retry; } } @@ -4846,7 +4902,7 @@ unravel_cf_string_alt_or_cc_add(Node** rlist, int n, return ONIGERR_MEMORY; } - NODE_CDR(curr) = alt; + ND_CDR(curr) = alt; curr = alt; } } @@ -4914,9 +4970,9 @@ unravel_case_fold_string(Node* node, regex_t* reg, int state) OnigEncoding enc; OnigCaseFoldCodeItem items[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM]; - if (NODE_STRING_IS_CASE_EXPANDED(node)) return 0; + if (ND_STRING_IS_CASE_EXPANDED(node)) return 0; - NODE_STATUS_REMOVE(node, IGNORECASE); + ND_STATUS_REMOVE(node, IGNORECASE); snode = STR_(node); start = snode->s; end = snode->end; @@ -4974,7 +5030,7 @@ unravel_case_fold_string(Node* node, regex_t* reg, int state) if (IS_NOT_NULL(list)) { if (node_list_len(list) == 1) { - node_swap(node, NODE_CAR(list)); + node_swap(node, ND_CAR(list)); } else { node_swap(node, list); @@ -5002,43 +5058,43 @@ quantifiers_memory_node_info(Node* node) { int r = BODY_MAY_BE_EMPTY; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: { int v; do { - v = quantifiers_memory_node_info(NODE_CAR(node)); + v = quantifiers_memory_node_info(ND_CAR(node)); if (v > r) r = v; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); } break; #ifdef USE_CALL - case NODE_CALL: - if (NODE_IS_RECURSION(node)) { + case ND_CALL: + if (ND_IS_RECURSION(node)) { return BODY_MAY_BE_EMPTY_REC; /* tiny version */ } else - r = quantifiers_memory_node_info(NODE_BODY(node)); + r = quantifiers_memory_node_info(ND_BODY(node)); break; #endif - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); if (qn->upper != 0) { - r = quantifiers_memory_node_info(NODE_BODY(node)); + r = quantifiers_memory_node_info(ND_BODY(node)); } } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); switch (en->type) { case BAG_MEMORY: - if (NODE_IS_RECURSION(node)) { + if (ND_IS_RECURSION(node)) { return BODY_MAY_BE_EMPTY_REC; } return BODY_MAY_BE_EMPTY_MEM; @@ -5046,12 +5102,12 @@ quantifiers_memory_node_info(Node* node) case BAG_OPTION: case BAG_STOP_BACKTRACK: - r = quantifiers_memory_node_info(NODE_BODY(node)); + r = quantifiers_memory_node_info(ND_BODY(node)); break; case BAG_IF_ELSE: { int v; - r = quantifiers_memory_node_info(NODE_BODY(node)); + r = quantifiers_memory_node_info(ND_BODY(node)); if (IS_NOT_NULL(en->te.Then)) { v = quantifiers_memory_node_info(en->te.Then); if (v > r) r = v; @@ -5066,12 +5122,12 @@ quantifiers_memory_node_info(Node* node) } break; - case NODE_BACKREF: - case NODE_STRING: - case NODE_CTYPE: - case NODE_CCLASS: - case NODE_ANCHOR: - case NODE_GIMMICK: + case ND_BACKREF: + case ND_STRING: + case ND_CTYPE: + case ND_CCLASS: + case ND_ANCHOR: + case ND_GIMMICK: default: break; } @@ -5107,14 +5163,14 @@ check_call_reference(CallNode* cn, ParseEnv* env, int state) } set_call_attr: - NODE_CALL_BODY(cn) = mem_env[cn->called_gnum].mem_node; - if (IS_NULL(NODE_CALL_BODY(cn))) { + ND_CALL_BODY(cn) = mem_env[cn->called_gnum].mem_node; + if (IS_NULL(ND_CALL_BODY(cn))) { onig_scan_env_set_error_string(env, ONIGERR_UNDEFINED_NAME_REFERENCE, cn->name, cn->name_end); return ONIGERR_UNDEFINED_NAME_REFERENCE; } - NODE_STATUS_ADD(NODE_CALL_BODY(cn), REFERENCED); + ND_STATUS_ADD(ND_CALL_BODY(cn), REFERENCED); } else { int *refs; @@ -5148,22 +5204,22 @@ check_whole_options_position(Node* node /* root */) is_list = FALSE; start: - switch (NODE_TYPE(node)) { - case NODE_LIST: - if (IS_NOT_NULL(NODE_CDR(node))) + switch (ND_TYPE(node)) { + case ND_LIST: + if (IS_NOT_NULL(ND_CDR(node))) is_list = TRUE; - node = NODE_CAR(node); + node = ND_CAR(node); goto start; break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_OPTION) { - if (NODE_IS_WHOLE_OPTIONS(node)) { - if (is_list == TRUE && IS_NOT_NULL(NODE_BODY(node))) + if (ND_IS_WHOLE_OPTIONS(node)) { + if (is_list == TRUE && IS_NOT_NULL(ND_BODY(node))) break; return 0; @@ -5183,61 +5239,61 @@ check_whole_options_position(Node* node /* root */) static void tune_call2_call(Node* node) { - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - tune_call2_call(NODE_CAR(node)); - } while (IS_NOT_NULL(node = NODE_CDR(node))); + tune_call2_call(ND_CAR(node)); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_QUANT: - tune_call2_call(NODE_BODY(node)); + case ND_QUANT: + tune_call2_call(ND_BODY(node)); break; - case NODE_ANCHOR: + case ND_ANCHOR: if (ANCHOR_HAS_BODY(ANCHOR_(node))) - tune_call2_call(NODE_BODY(node)); + tune_call2_call(ND_BODY(node)); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (! NODE_IS_MARK1(node)) { - NODE_STATUS_ADD(node, MARK1); - tune_call2_call(NODE_BODY(node)); - NODE_STATUS_REMOVE(node, MARK1); + if (! ND_IS_MARK1(node)) { + ND_STATUS_ADD(node, MARK1); + tune_call2_call(ND_BODY(node)); + ND_STATUS_REMOVE(node, MARK1); } } else if (en->type == BAG_IF_ELSE) { - tune_call2_call(NODE_BODY(node)); + tune_call2_call(ND_BODY(node)); if (IS_NOT_NULL(en->te.Then)) tune_call2_call(en->te.Then); if (IS_NOT_NULL(en->te.Else)) tune_call2_call(en->te.Else); } else { - tune_call2_call(NODE_BODY(node)); + tune_call2_call(ND_BODY(node)); } } break; - case NODE_CALL: - if (! NODE_IS_MARK1(node)) { - NODE_STATUS_ADD(node, MARK1); + case ND_CALL: + if (! ND_IS_MARK1(node)) { + ND_STATUS_ADD(node, MARK1); { CallNode* cn = CALL_(node); - Node* called = NODE_CALL_BODY(cn); + Node* called = ND_CALL_BODY(cn); cn->entry_count++; - NODE_STATUS_ADD(called, CALLED); + ND_STATUS_ADD(called, CALLED); BAG_(called)->m.entry_count++; tune_call2_call(called); } - NODE_STATUS_REMOVE(node, MARK1); + ND_STATUS_REMOVE(node, MARK1); } break; @@ -5251,41 +5307,41 @@ tune_call(Node* node, ParseEnv* env, int state) { int r; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = tune_call(NODE_CAR(node), env, state); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = tune_call(ND_CAR(node), env, state); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_QUANT: + case ND_QUANT: if (QUANT_(node)->upper == 0) state |= IN_ZERO_REPEAT; - r = tune_call(NODE_BODY(node), env, state); + r = tune_call(ND_BODY(node), env, state); break; - case NODE_ANCHOR: + case ND_ANCHOR: if (ANCHOR_HAS_BODY(ANCHOR_(node))) - r = tune_call(NODE_BODY(node), env, state); + r = tune_call(ND_BODY(node), env, state); else r = 0; break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { if ((state & IN_ZERO_REPEAT) != 0) { - NODE_STATUS_ADD(node, IN_ZERO_REPEAT); + ND_STATUS_ADD(node, IN_ZERO_REPEAT); BAG_(node)->m.entry_count--; } - r = tune_call(NODE_BODY(node), env, state); + r = tune_call(ND_BODY(node), env, state); } else if (en->type == BAG_IF_ELSE) { - r = tune_call(NODE_BODY(node), env, state); + r = tune_call(ND_BODY(node), env, state); if (r != 0) return r; if (IS_NOT_NULL(en->te.Then)) { r = tune_call(en->te.Then, env, state); @@ -5295,13 +5351,13 @@ tune_call(Node* node, ParseEnv* env, int state) r = tune_call(en->te.Else, env, state); } else - r = tune_call(NODE_BODY(node), env, state); + r = tune_call(ND_BODY(node), env, state); } break; - case NODE_CALL: + case ND_CALL: if ((state & IN_ZERO_REPEAT) != 0) { - NODE_STATUS_ADD(node, IN_ZERO_REPEAT); + ND_STATUS_ADD(node, IN_ZERO_REPEAT); CALL_(node)->entry_count--; } @@ -5321,27 +5377,27 @@ tune_call2(Node* node) { int r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = tune_call2(NODE_CAR(node)); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = tune_call2(ND_CAR(node)); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_QUANT: + case ND_QUANT: if (QUANT_(node)->upper != 0) - r = tune_call2(NODE_BODY(node)); + r = tune_call2(ND_BODY(node)); break; - case NODE_ANCHOR: + case ND_ANCHOR: if (ANCHOR_HAS_BODY(ANCHOR_(node))) - r = tune_call2(NODE_BODY(node)); + r = tune_call2(ND_BODY(node)); break; - case NODE_BAG: - if (! NODE_IS_IN_ZERO_REPEAT(node)) - r = tune_call2(NODE_BODY(node)); + case ND_BAG: + if (! ND_IS_IN_ZERO_REPEAT(node)) + r = tune_call2(ND_BODY(node)); { BagNode* en = BAG_(node); @@ -5358,8 +5414,8 @@ tune_call2(Node* node) } break; - case NODE_CALL: - if (! NODE_IS_IN_ZERO_REPEAT(node)) { + case ND_CALL: + if (! ND_IS_IN_ZERO_REPEAT(node)) { tune_call2_call(node); } break; @@ -5375,17 +5431,17 @@ tune_call2(Node* node) static void tune_called_state_call(Node* node, int state) { - switch (NODE_TYPE(node)) { - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_ALT: state |= IN_ALT; /* fall */ - case NODE_LIST: + case ND_LIST: do { - tune_called_state_call(NODE_CAR(node), state); - } while (IS_NOT_NULL(node = NODE_CDR(node))); + tune_called_state_call(ND_CAR(node), state); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); @@ -5394,13 +5450,13 @@ tune_called_state_call(Node* node, int state) if (qn->lower != qn->upper) state |= IN_VAR_REPEAT; if ((state & IN_PEEK) != 0) - NODE_STATUS_ADD(node, INPEEK); + ND_STATUS_ADD(node, INPEEK); - tune_called_state_call(NODE_QUANT_BODY(qn), state); + tune_called_state_call(ND_QUANT_BODY(qn), state); } break; - case NODE_ANCHOR: + case ND_ANCHOR: { AnchorNode* an = ANCHOR_(node); @@ -5408,12 +5464,12 @@ tune_called_state_call(Node* node, int state) case ANCR_PREC_READ_NOT: case ANCR_LOOK_BEHIND_NOT: state |= (IN_NOT | IN_PEEK); - tune_called_state_call(NODE_ANCHOR_BODY(an), state); + tune_called_state_call(ND_ANCHOR_BODY(an), state); break; case ANCR_PREC_READ: case ANCR_LOOK_BEHIND: state |= IN_PEEK; - tune_called_state_call(NODE_ANCHOR_BODY(an), state); + tune_called_state_call(ND_ANCHOR_BODY(an), state); break; default: break; @@ -5421,27 +5477,27 @@ tune_called_state_call(Node* node, int state) } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); if (en->type == BAG_MEMORY) { - if (NODE_IS_MARK1(node)) { + if (ND_IS_MARK1(node)) { if ((~en->m.called_state & state) != 0) { en->m.called_state |= state; - tune_called_state_call(NODE_BODY(node), state); + tune_called_state_call(ND_BODY(node), state); } } else { - NODE_STATUS_ADD(node, MARK1); + ND_STATUS_ADD(node, MARK1); en->m.called_state |= state; - tune_called_state_call(NODE_BODY(node), state); - NODE_STATUS_REMOVE(node, MARK1); + tune_called_state_call(ND_BODY(node), state); + ND_STATUS_REMOVE(node, MARK1); } } else if (en->type == BAG_IF_ELSE) { state |= IN_ALT; - tune_called_state_call(NODE_BODY(node), state); + tune_called_state_call(ND_BODY(node), state); if (IS_NOT_NULL(en->te.Then)) { tune_called_state_call(en->te.Then, state); } @@ -5449,18 +5505,18 @@ tune_called_state_call(Node* node, int state) tune_called_state_call(en->te.Else, state); } else { - tune_called_state_call(NODE_BODY(node), state); + tune_called_state_call(ND_BODY(node), state); } } break; - case NODE_CALL: + case ND_CALL: if ((state & IN_PEEK) != 0) - NODE_STATUS_ADD(node, INPEEK); + ND_STATUS_ADD(node, INPEEK); if ((state & IN_REAL_REPEAT) != 0) - NODE_STATUS_ADD(node, IN_REAL_REPEAT); + ND_STATUS_ADD(node, IN_REAL_REPEAT); - tune_called_state_call(NODE_BODY(node), state); + tune_called_state_call(ND_BODY(node), state); break; default: @@ -5471,28 +5527,28 @@ tune_called_state_call(Node* node, int state) static void tune_called_state(Node* node, int state) { - switch (NODE_TYPE(node)) { - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_ALT: state |= IN_ALT; /* fall */ - case NODE_LIST: + case ND_LIST: do { - tune_called_state(NODE_CAR(node), state); - } while (IS_NOT_NULL(node = NODE_CDR(node))); + tune_called_state(ND_CAR(node), state); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; #ifdef USE_CALL - case NODE_CALL: + case ND_CALL: if ((state & IN_PEEK) != 0) - NODE_STATUS_ADD(node, INPEEK); + ND_STATUS_ADD(node, INPEEK); if ((state & IN_REAL_REPEAT) != 0) - NODE_STATUS_ADD(node, IN_REAL_REPEAT); + ND_STATUS_ADD(node, IN_REAL_REPEAT); tune_called_state_call(node, state); break; #endif - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); @@ -5505,11 +5561,11 @@ tune_called_state(Node* node, int state) /* fall */ case BAG_OPTION: case BAG_STOP_BACKTRACK: - tune_called_state(NODE_BODY(node), state); + tune_called_state(ND_BODY(node), state); break; case BAG_IF_ELSE: state |= IN_ALT; - tune_called_state(NODE_BODY(node), state); + tune_called_state(ND_BODY(node), state); if (IS_NOT_NULL(en->te.Then)) tune_called_state(en->te.Then, state); if (IS_NOT_NULL(en->te.Else)) @@ -5519,7 +5575,7 @@ tune_called_state(Node* node, int state) } break; - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); @@ -5528,13 +5584,13 @@ tune_called_state(Node* node, int state) if (qn->lower != qn->upper) state |= IN_VAR_REPEAT; if ((state & IN_PEEK) != 0) - NODE_STATUS_ADD(node, INPEEK); + ND_STATUS_ADD(node, INPEEK); - tune_called_state(NODE_QUANT_BODY(qn), state); + tune_called_state(ND_QUANT_BODY(qn), state); } break; - case NODE_ANCHOR: + case ND_ANCHOR: { AnchorNode* an = ANCHOR_(node); @@ -5542,12 +5598,12 @@ tune_called_state(Node* node, int state) case ANCR_PREC_READ_NOT: case ANCR_LOOK_BEHIND_NOT: state |= (IN_NOT | IN_PEEK); - tune_called_state(NODE_ANCHOR_BODY(an), state); + tune_called_state(ND_ANCHOR_BODY(an), state); break; case ANCR_PREC_READ: case ANCR_LOOK_BEHIND: state |= IN_PEEK; - tune_called_state(NODE_ANCHOR_BODY(an), state); + tune_called_state(ND_ANCHOR_BODY(an), state); break; default: break; @@ -5555,11 +5611,11 @@ tune_called_state(Node* node, int state) } break; - case NODE_BACKREF: - case NODE_STRING: - case NODE_CTYPE: - case NODE_CCLASS: - case NODE_GIMMICK: + case ND_BACKREF: + case ND_STRING: + case ND_CTYPE: + case ND_CCLASS: + case ND_GIMMICK: default: break; } @@ -5579,10 +5635,10 @@ tune_anchor(Node* node, regex_t* reg, int state, ParseEnv* env) switch (an->type) { case ANCR_PREC_READ: - r = tune_tree(NODE_ANCHOR_BODY(an), reg, (state | IN_PREC_READ), env); + r = tune_tree(ND_ANCHOR_BODY(an), reg, (state | IN_PREC_READ), env); break; case ANCR_PREC_READ_NOT: - r = tune_tree(NODE_ANCHOR_BODY(an), reg, (state | IN_PREC_READ | IN_NOT), + r = tune_tree(ND_ANCHOR_BODY(an), reg, (state | IN_PREC_READ | IN_NOT), env); break; @@ -5607,13 +5663,13 @@ tune_quant(Node* node, regex_t* reg, int state, ParseEnv* env) { int r; QuantNode* qn = QUANT_(node); - Node* body = NODE_BODY(node); + Node* body = ND_BODY(node); if ((state & IN_REAL_REPEAT) != 0) { - NODE_STATUS_ADD(node, IN_REAL_REPEAT); + ND_STATUS_ADD(node, IN_REAL_REPEAT); } if ((state & IN_MULTI_ENTRY) != 0) { - NODE_STATUS_ADD(node, IN_MULTI_ENTRY); + ND_STATUS_ADD(node, IN_MULTI_ENTRY); } if (IS_INFINITE_REPEAT(qn->upper) || qn->upper >= 1) { @@ -5637,10 +5693,10 @@ tune_quant(Node* node, regex_t* reg, int state, ParseEnv* env) /* expand string */ #define EXPAND_STRING_MAX_LENGTH 100 - if (NODE_TYPE(body) == NODE_STRING) { + if (ND_TYPE(body) == ND_STRING) { if (!IS_INFINITE_REPEAT(qn->lower) && qn->lower == qn->upper && qn->lower > 1 && qn->lower <= EXPAND_STRING_MAX_LENGTH) { - int len = NODE_STRING_LEN(body); + int len = ND_STRING_LEN(body); if (len * qn->lower <= EXPAND_STRING_MAX_LENGTH) { int i, n = qn->lower; @@ -5656,7 +5712,7 @@ tune_quant(Node* node, regex_t* reg, int state, ParseEnv* env) } if (qn->greedy && (qn->emptiness == BODY_IS_NOT_EMPTY)) { - if (NODE_TYPE(body) == NODE_QUANT) { + if (ND_TYPE(body) == ND_QUANT) { QuantNode* tqn = QUANT_(body); if (IS_NOT_NULL(tqn->head_exact)) { qn->head_exact = tqn->head_exact; @@ -5664,7 +5720,7 @@ tune_quant(Node* node, regex_t* reg, int state, ParseEnv* env) } } else { - qn->head_exact = get_tree_head_literal(NODE_BODY(node), 1, reg); + qn->head_exact = get_tree_head_literal(ND_BODY(node), 1, reg); } } @@ -5684,33 +5740,33 @@ tune_tree(Node* node, regex_t* reg, int state, ParseEnv* env) { int r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: + switch (ND_TYPE(node)) { + case ND_LIST: { Node* prev = NULL_NODE; do { - r = tune_tree(NODE_CAR(node), reg, state, env); + r = tune_tree(ND_CAR(node), reg, state, env); if (IS_NOT_NULL(prev) && r == 0) { - r = tune_next(prev, NODE_CAR(node), reg); + r = tune_next(prev, ND_CAR(node), reg); } - prev = NODE_CAR(node); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + prev = ND_CAR(node); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); } break; - case NODE_ALT: + case ND_ALT: do { - r = tune_tree(NODE_CAR(node), reg, (state | IN_ALT), env); - } while (r == 0 && IS_NOT_NULL(node = NODE_CDR(node))); + r = tune_tree(ND_CAR(node), reg, (state | IN_ALT), env); + } while (r == 0 && IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_STRING: - if (NODE_IS_REAL_IGNORECASE(node)) { + case ND_STRING: + if (ND_IS_REAL_IGNORECASE(node)) { r = unravel_case_fold_string(node, reg, state); } break; - case NODE_BACKREF: + case ND_BACKREF: { int i; int* p; @@ -5721,7 +5777,7 @@ tune_tree(Node* node, regex_t* reg, int state, ParseEnv* env) MEM_STATUS_ON(env->backrefed_mem, p[i]); #if 0 #ifdef USE_BACKREF_WITH_LEVEL - if (NODE_IS_NEST_LEVEL(node)) { + if (ND_IS_NEST_LEVEL(node)) { MEM_STATUS_ON(env->backtrack_mem, p[i]); } #endif @@ -5735,7 +5791,7 @@ tune_tree(Node* node, regex_t* reg, int state, ParseEnv* env) } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); @@ -5744,7 +5800,7 @@ tune_tree(Node* node, regex_t* reg, int state, ParseEnv* env) { OnigOptionType options = reg->options; reg->options = BAG_(node)->o.options; - r = tune_tree(NODE_BODY(node), reg, state, env); + r = tune_tree(ND_BODY(node), reg, state, env); reg->options = options; } break; @@ -5755,29 +5811,29 @@ tune_tree(Node* node, regex_t* reg, int state, ParseEnv* env) #endif if ((state & (IN_ALT | IN_NOT | IN_VAR_REPEAT | IN_MULTI_ENTRY)) != 0 - || NODE_IS_RECURSION(node)) { + || ND_IS_RECURSION(node)) { MEM_STATUS_ON(env->backtrack_mem, en->m.regnum); } - r = tune_tree(NODE_BODY(node), reg, state, env); + r = tune_tree(ND_BODY(node), reg, state, env); break; case BAG_STOP_BACKTRACK: { - Node* target = NODE_BODY(node); + Node* target = ND_BODY(node); r = tune_tree(target, reg, state, env); - if (NODE_TYPE(target) == NODE_QUANT) { + if (ND_TYPE(target) == ND_QUANT) { QuantNode* tqn = QUANT_(target); if (IS_INFINITE_REPEAT(tqn->upper) && tqn->lower <= 1 && tqn->greedy != 0) { /* (?>a*), a*+ etc... */ - if (is_strict_real_node(NODE_BODY(target))) - NODE_STATUS_ADD(node, STRICT_REAL_REPEAT); + if (is_strict_real_node(ND_BODY(target))) + ND_STATUS_ADD(node, STRICT_REAL_REPEAT); } } } break; case BAG_IF_ELSE: - r = tune_tree(NODE_BODY(node), reg, (state | IN_ALT), env); + r = tune_tree(ND_BODY(node), reg, (state | IN_ALT), env); if (r != 0) return r; if (IS_NOT_NULL(en->te.Then)) { r = tune_tree(en->te.Then, reg, (state | IN_ALT), env); @@ -5790,23 +5846,23 @@ tune_tree(Node* node, regex_t* reg, int state, ParseEnv* env) } break; - case NODE_QUANT: + case ND_QUANT: if ((state & (IN_PREC_READ | IN_LOOK_BEHIND)) != 0) - NODE_STATUS_ADD(node, INPEEK); + ND_STATUS_ADD(node, INPEEK); r = tune_quant(node, reg, state, env); break; - case NODE_ANCHOR: + case ND_ANCHOR: r = tune_anchor(node, reg, state, env); break; #ifdef USE_CALL - case NODE_CALL: + case ND_CALL: #endif - case NODE_CTYPE: - case NODE_CCLASS: - case NODE_GIMMICK: + case ND_CTYPE: + case ND_CCLASS: + case ND_GIMMICK: default: break; } @@ -6427,42 +6483,42 @@ node_max_byte_len(Node* node, ParseEnv* env) OnigLen tmax; len = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: + switch (ND_TYPE(node)) { + case ND_LIST: do { - tmax = node_max_byte_len(NODE_CAR(node), env); + tmax = node_max_byte_len(ND_CAR(node), env); len = distance_add(len, tmax); - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_ALT: + case ND_ALT: do { - tmax = node_max_byte_len(NODE_CAR(node), env); + tmax = node_max_byte_len(ND_CAR(node), env); if (len < tmax) len = tmax; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_STRING: + case ND_STRING: { StrNode* sn = STR_(node); len = (OnigLen )(sn->end - sn->s); } break; - case NODE_CTYPE: - case NODE_CCLASS: + case ND_CTYPE: + case ND_CCLASS: len = ONIGENC_MBC_MAXLEN_DIST(env->enc); break; - case NODE_BACKREF: - if (! NODE_IS_CHECKER(node)) { + case ND_BACKREF: + if (! ND_IS_CHECKER(node)) { int i; int* backs; MemEnv* mem_env = PARSEENV_MEMENV(env); BackRefNode* br = BACKREF_(node); - if (NODE_IS_RECURSION(node)) { + if (ND_IS_RECURSION(node)) { #ifdef USE_BACKREF_WITH_LEVEL - if (NODE_IS_NEST_LEVEL(node)) { + if (ND_IS_NEST_LEVEL(node)) { len = INFINITE_LEN; } #endif @@ -6477,20 +6533,20 @@ node_max_byte_len(Node* node, ParseEnv* env) break; #ifdef USE_CALL - case NODE_CALL: - if (! NODE_IS_RECURSION(node)) - len = node_max_byte_len(NODE_BODY(node), env); + case ND_CALL: + if (! ND_IS_RECURSION(node)) + len = node_max_byte_len(ND_BODY(node), env); else len = INFINITE_LEN; break; #endif - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); if (qn->upper != 0) { - len = node_max_byte_len(NODE_BODY(node), env); + len = node_max_byte_len(ND_BODY(node), env); if (len != 0) { if (! IS_INFINITE_REPEAT(qn->upper)) len = distance_multiply(len, qn->upper); @@ -6501,36 +6557,36 @@ node_max_byte_len(Node* node, ParseEnv* env) } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); switch (en->type) { case BAG_MEMORY: - if (NODE_IS_FIXED_MAX(node)) + if (ND_IS_FIXED_MAX(node)) len = en->max_len; else { - if (NODE_IS_MARK1(node)) + if (ND_IS_MARK1(node)) len = INFINITE_LEN; else { - NODE_STATUS_ADD(node, MARK1); - len = node_max_byte_len(NODE_BODY(node), env); - NODE_STATUS_REMOVE(node, MARK1); + ND_STATUS_ADD(node, MARK1); + len = node_max_byte_len(ND_BODY(node), env); + ND_STATUS_REMOVE(node, MARK1); en->max_len = len; - NODE_STATUS_ADD(node, FIXED_MAX); + ND_STATUS_ADD(node, FIXED_MAX); } } break; case BAG_OPTION: case BAG_STOP_BACKTRACK: - len = node_max_byte_len(NODE_BODY(node), env); + len = node_max_byte_len(ND_BODY(node), env); break; case BAG_IF_ELSE: { OnigLen tlen, elen; - len = node_max_byte_len(NODE_BODY(node), env); + len = node_max_byte_len(ND_BODY(node), env); if (IS_NOT_NULL(en->te.Then)) { tlen = node_max_byte_len(en->te.Then, env); len = distance_add(len, tlen); @@ -6546,8 +6602,8 @@ node_max_byte_len(Node* node, ParseEnv* env) } break; - case NODE_ANCHOR: - case NODE_GIMMICK: + case ND_ANCHOR: + case ND_GIMMICK: default: break; } @@ -6555,7 +6611,7 @@ node_max_byte_len(Node* node, ParseEnv* env) return len; } -#define MAX_NODE_OPT_INFO_REF_COUNT 5 +#define MAX_ND_OPT_INFO_REF_COUNT 5 static int optimize_nodes(Node* node, OptNode* opt, OptEnv* env) @@ -6570,38 +6626,38 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) clear_node_opt_info(opt); set_bound_node_opt_info(opt, &env->mm); - switch (NODE_TYPE(node)) { - case NODE_LIST: + switch (ND_TYPE(node)) { + case ND_LIST: { OptEnv nenv; Node* nd = node; copy_opt_env(&nenv, env); do { - r = optimize_nodes(NODE_CAR(nd), &xo, &nenv); + r = optimize_nodes(ND_CAR(nd), &xo, &nenv); if (r == 0) { mml_add(&nenv.mm, &xo.len); concat_left_node_opt_info(enc, opt, &xo); } - } while (r == 0 && IS_NOT_NULL(nd = NODE_CDR(nd))); + } while (r == 0 && IS_NOT_NULL(nd = ND_CDR(nd))); } break; - case NODE_ALT: + case ND_ALT: { Node* nd = node; do { - r = optimize_nodes(NODE_CAR(nd), &xo, env); + r = optimize_nodes(ND_CAR(nd), &xo, env); if (r == 0) { if (nd == node) copy_node_opt_info(opt, &xo); else alt_merge_node_opt_info(opt, &xo, env); } - } while ((r == 0) && IS_NOT_NULL(nd = NODE_CDR(nd))); + } while ((r == 0) && IS_NOT_NULL(nd = ND_CDR(nd))); } break; - case NODE_STRING: + case ND_STRING: { StrNode* sn = STR_(node); int slen = (int )(sn->end - sn->s); @@ -6614,7 +6670,7 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) } break; - case NODE_CCLASS: + case ND_CCLASS: { int z; CClassNode* cc = CCLASS_(node); @@ -6639,7 +6695,7 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) } break; - case NODE_CTYPE: + case ND_CTYPE: { int min, max; int range; @@ -6682,7 +6738,7 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) } break; - case NODE_ANCHOR: + case ND_ANCHOR: switch (ANCHOR_(node)->type) { case ANCR_BEGIN_BUF: case ANCR_BEGIN_POSITION: @@ -6697,7 +6753,7 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) case ANCR_PREC_READ: { - r = optimize_nodes(NODE_BODY(node), &xo, env); + r = optimize_nodes(ND_BODY(node), &xo, env); if (r == 0) { if (xo.sb.len > 0) copy_opt_exact(&opt->spr, &xo.sb); @@ -6717,8 +6773,8 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) } break; - case NODE_BACKREF: - if (! NODE_IS_CHECKER(node)) { + case ND_BACKREF: + if (! ND_IS_CHECKER(node)) { OnigLen min, max; min = node_min_byte_len(node, env->scan_env); @@ -6728,16 +6784,16 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) break; #ifdef USE_CALL - case NODE_CALL: - if (NODE_IS_RECURSION(node)) + case ND_CALL: + if (ND_IS_RECURSION(node)) mml_set_min_max(&opt->len, 0, INFINITE_LEN); else { - r = optimize_nodes(NODE_BODY(node), opt, env); + r = optimize_nodes(ND_BODY(node), opt, env); } break; #endif - case NODE_QUANT: + case ND_QUANT: { OnigLen min, max; QuantNode* qn = QUANT_(node); @@ -6756,7 +6812,7 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) break; } - r = optimize_nodes(NODE_BODY(node), &xo, env); + r = optimize_nodes(ND_BODY(node), &xo, env); if (r != 0) break; if (qn->lower > 0) { @@ -6781,8 +6837,8 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) if (IS_INFINITE_REPEAT(qn->upper)) { if (env->mm.max == 0 && - NODE_IS_ANYCHAR(NODE_BODY(node)) && qn->greedy != 0) { - if (NODE_IS_MULTILINE(NODE_QUANT_BODY(qn))) + ND_IS_ANYCHAR(ND_BODY(node)) && qn->greedy != 0) { + if (ND_IS_MULTILINE(ND_QUANT_BODY(qn))) add_opt_anc_info(&opt->anc, ANCR_ANYCHAR_INF_ML); else add_opt_anc_info(&opt->anc, ANCR_ANYCHAR_INF); @@ -6799,32 +6855,32 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); switch (en->type) { case BAG_STOP_BACKTRACK: case BAG_OPTION: - r = optimize_nodes(NODE_BODY(node), opt, env); + r = optimize_nodes(ND_BODY(node), opt, env); break; case BAG_MEMORY: #ifdef USE_CALL en->opt_count++; - if (en->opt_count > MAX_NODE_OPT_INFO_REF_COUNT) { + if (en->opt_count > MAX_ND_OPT_INFO_REF_COUNT) { OnigLen min, max; min = 0; max = INFINITE_LEN; - if (NODE_IS_FIXED_MIN(node)) min = en->min_len; - if (NODE_IS_FIXED_MAX(node)) max = en->max_len; + if (ND_IS_FIXED_MIN(node)) min = en->min_len; + if (ND_IS_FIXED_MAX(node)) max = en->max_len; mml_set_min_max(&opt->len, min, max); } else #endif { - r = optimize_nodes(NODE_BODY(node), opt, env); + r = optimize_nodes(ND_BODY(node), opt, env); if (is_set_opt_anc_info(&opt->anc, ANCR_ANYCHAR_INF_MASK)) { if (MEM_STATUS_AT0(env->scan_env->backrefed_mem, en->m.regnum)) remove_opt_anc_info(&opt->anc, ANCR_ANYCHAR_INF_MASK); @@ -6838,7 +6894,7 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) if (IS_NOT_NULL(en->te.Else)) { copy_opt_env(&nenv, env); - r = optimize_nodes(NODE_BAG_BODY(en), &xo, &nenv); + r = optimize_nodes(ND_BAG_BODY(en), &xo, &nenv); if (r == 0) { mml_add(&nenv.mm, &xo.len); concat_left_node_opt_info(enc, opt, &xo); @@ -6860,12 +6916,12 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) } break; - case NODE_GIMMICK: + case ND_GIMMICK: break; default: #ifdef ONIG_DEBUG - fprintf(DBGFP, "optimize_nodes: undefined node type %d\n", NODE_TYPE(node)); + fprintf(DBGFP, "optimize_nodes: undefined node type %d\n", ND_TYPE(node)); #endif r = ONIGERR_TYPE_BUG; break; @@ -7018,10 +7074,12 @@ clear_optimize_info(regex_t* reg) } } -#ifdef ONIG_DEBUG +#if defined(ONIG_DEBUG_PARSE) || defined(ONIG_DEBUG_MATCH) || \ + defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) -static void print_enc_string(FILE* fp, OnigEncoding enc, - const UChar *s, const UChar *end) +static void +print_enc_string(FILE* fp, OnigEncoding enc, + const UChar *s, const UChar *end) { if (ONIGENC_MBC_MINLEN(enc) > 1) { const UChar *p; @@ -7042,7 +7100,17 @@ static void print_enc_string(FILE* fp, OnigEncoding enc, } else { while (s < end) { - fputc((int )*s, fp); + if (ONIGENC_MBC_MAXLEN(enc) == 1) { + if (*s >= 0x80) { + fprintf(fp, "\\x%02x", (unsigned int )*s); + } + else { + fputc((int )*s, fp); + } + } + else { /* for UTF-8 */ + fputc((int )*s, fp); + } s++; } } @@ -7077,7 +7145,7 @@ print_options(FILE* fp, OnigOptionType o) if ((o & ONIG_OPTION_CALLBACK_EACH_MATCH) != 0) fprintf(fp, " CALLBACK_EACH_MATCH"); } -#endif /* ONIG_DEBUG */ +#endif #if defined(ONIG_DEBUG_COMPILE) || defined(ONIG_DEBUG_MATCH) @@ -7426,7 +7494,8 @@ onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end, UnsetAddrList uslist = {0}; #endif -#ifdef ONIG_DEBUG +#if defined(ONIG_DEBUG_PARSE) || defined(ONIG_DEBUG_MATCH) || \ + defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) fprintf(DBGFP, "\nPATTERN: /"); print_enc_string(DBGFP, reg->enc, pattern, pattern_end); fprintf(DBGFP, "/\n"); @@ -7836,30 +7905,30 @@ mostly_just_anychar(Node* node, int in_reluctant) MJ_RESULT r; r = MJ_NO; - switch (NODE_TYPE(node)) { - case NODE_LIST: + switch (ND_TYPE(node)) { + case ND_LIST: { int found = FALSE; do { - r = mostly_just_anychar(NODE_CAR(node), in_reluctant); + r = mostly_just_anychar(ND_CAR(node), in_reluctant); if (r == MJ_NO) break; if (r == MJ_YES) found = TRUE; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); if (r == MJ_IGNORE) { if (found == TRUE) r = MJ_YES; } } break; - case NODE_ALT: + case ND_ALT: r = MJ_IGNORE; do { - r = mostly_just_anychar(NODE_CAR(node), in_reluctant); + r = mostly_just_anychar(ND_CAR(node), in_reluctant); if (r == MJ_YES) break; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_QUANT: + case ND_QUANT: { QuantNode* qn = QUANT_(node); @@ -7873,12 +7942,12 @@ mostly_just_anychar(Node* node, int in_reluctant) in_reluctant = TRUE; } } - r = mostly_just_anychar(NODE_BODY(node), in_reluctant); + r = mostly_just_anychar(ND_BODY(node), in_reluctant); } } break; - case NODE_ANCHOR: + case ND_ANCHOR: switch (ANCHOR_(node)->type) { case ANCR_PREC_READ: case ANCR_PREC_READ_NOT: @@ -7892,7 +7961,7 @@ mostly_just_anychar(Node* node, int in_reluctant) } break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); @@ -7906,34 +7975,34 @@ mostly_just_anychar(Node* node, int in_reluctant) } } else { - r = mostly_just_anychar(NODE_BODY(node), in_reluctant); + r = mostly_just_anychar(ND_BODY(node), in_reluctant); } } break; - case NODE_CTYPE: + case ND_CTYPE: if (CTYPE_(node)->ctype == CTYPE_ANYCHAR) r = MJ_YES; else r = MJ_NO; break; - case NODE_STRING: - if (NODE_STRING_LEN(node) == 0) { + case ND_STRING: + if (ND_STRING_LEN(node) == 0) { r = MJ_IGNORE; break; } /* fall */ - case NODE_CCLASS: + case ND_CCLASS: r = MJ_NO; break; #ifdef USE_CALL - case NODE_CALL: + case ND_CALL: /* ignore call */ #endif - case NODE_BACKREF: - case NODE_GIMMICK: + case ND_BACKREF: + case ND_GIMMICK: r = MJ_IGNORE; break; @@ -7965,23 +8034,23 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) int r; r = 0; - switch (NODE_TYPE(node)) { - case NODE_LIST: - case NODE_ALT: + switch (ND_TYPE(node)) { + case ND_LIST: + case ND_ALT: do { - r = detect_can_be_slow(NODE_CAR(node), ct, ncall, calls); + r = detect_can_be_slow(ND_CAR(node), ct, ncall, calls); if (r != 0) return r; - } while (IS_NOT_NULL(node = NODE_CDR(node))); + } while (IS_NOT_NULL(node = ND_CDR(node))); break; - case NODE_QUANT: + case ND_QUANT: { - int prev_heavy_element; QuantNode* qn; Node* body; + int prev_heavy_element = 0; qn = QUANT_(node); - body = NODE_BODY(node); + body = ND_BODY(node); if (qn->emptiness != BODY_IS_NOT_EMPTY) { prev_heavy_element = ct->heavy_element; @@ -7989,8 +8058,7 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) if (ct->empty_check_nest_level > ct->max_empty_check_nest_level) ct->max_empty_check_nest_level = ct->empty_check_nest_level; } - else if (IS_INFINITE_REPEAT(qn->upper) || - qn->upper > MANY_REPEAT_OF_ANYCHAR) { + else if (IS_INFINITE_REPEAT(qn->upper) || qn->upper > 0) { MJ_RESULT mr = mostly_just_anychar(body, (qn->greedy == 0)); if (mr == MJ_YES) ct->anychar_reluctant_many++; @@ -7999,7 +8067,7 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) r = detect_can_be_slow(body, ct, ncall, calls); if (qn->emptiness != BODY_IS_NOT_EMPTY) { - if (NODE_IS_INPEEK(node)) { + if (ND_IS_INPEEK(node)) { if (ct->empty_check_nest_level > 2) { if (prev_heavy_element == ct->heavy_element) ct->heavy_element++; @@ -8010,7 +8078,7 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) } break; - case NODE_ANCHOR: + case ND_ANCHOR: switch (ANCHOR_(node)->type) { case ANCR_PREC_READ: case ANCR_PREC_READ_NOT: @@ -8025,14 +8093,14 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) } if (ANCHOR_HAS_BODY(ANCHOR_(node))) - r = detect_can_be_slow(NODE_BODY(node), ct, ncall, calls); + r = detect_can_be_slow(ND_BODY(node), ct, ncall, calls); break; - case NODE_BAG: + case ND_BAG: { BagNode* en = BAG_(node); - r = detect_can_be_slow(NODE_BODY(node), ct, ncall, calls); + r = detect_can_be_slow(ND_BODY(node), ct, ncall, calls); if (r != 0) return r; if (en->type == BAG_IF_ELSE) { @@ -8049,8 +8117,8 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) break; #ifdef USE_BACKREF_WITH_LEVEL - case NODE_BACKREF: - if (NODE_IS_NEST_LEVEL(node)) + case ND_BACKREF: + if (ND_IS_NEST_LEVEL(node)) ct->heavy_element++; else ct->backref++; @@ -8058,7 +8126,7 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) #endif #ifdef USE_CALL - case NODE_CALL: + case ND_CALL: { int i; int found; @@ -8067,8 +8135,8 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) gnum = CALL_(node)->called_gnum; ct->call++; - if (NODE_IS_RECURSION(node) && NODE_IS_INPEEK(node) && - NODE_IS_IN_REAL_REPEAT(node)) { + if (ND_IS_RECURSION(node) && ND_IS_INPEEK(node) && + ND_IS_IN_REAL_REPEAT(node)) { ct->heavy_element += 10; } @@ -8083,7 +8151,7 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) if (! found) { if (ncall + 1 < MAX_CALLS_IN_DETECT) { calls[ncall] = gnum; - r = detect_can_be_slow(NODE_BODY(node), ct, ncall + 1, calls); + r = detect_can_be_slow(ND_BODY(node), ct, ncall + 1, calls); } else { ct->heavy_element++; @@ -8092,7 +8160,7 @@ detect_can_be_slow(Node* node, SlowElementCount* ct, int ncall, int calls[]) } break; #endif - case NODE_GIMMICK: + case ND_GIMMICK: { GimmickNode* g = GIMMICK_(node); if (g->type == GIMMICK_SAVE && g->detail_type == SAVE_KEEP) @@ -8236,33 +8304,33 @@ print_indent_tree(FILE* f, Node* node, int indent) exit(0); } - type = NODE_TYPE(node); + type = ND_TYPE(node); switch (type) { - case NODE_LIST: - case NODE_ALT: - if (type == NODE_LIST) + case ND_LIST: + case ND_ALT: + if (type == ND_LIST) fprintf(f, "<list:%p>\n", node); else fprintf(f, "<alt:%p>\n", node); - print_indent_tree(f, NODE_CAR(node), indent + add); - while (IS_NOT_NULL(node = NODE_CDR(node))) { - if (NODE_TYPE(node) != type) { - fprintf(f, "ERROR: list/alt right is not a cons. %d\n", NODE_TYPE(node)); + print_indent_tree(f, ND_CAR(node), indent + add); + while (IS_NOT_NULL(node = ND_CDR(node))) { + if (ND_TYPE(node) != type) { + fprintf(f, "ERROR: list/alt right is not a cons. %d\n", ND_TYPE(node)); exit(0); } - print_indent_tree(f, NODE_CAR(node), indent + add); + print_indent_tree(f, ND_CAR(node), indent + add); } break; - case NODE_STRING: + case ND_STRING: { char* str; char* mode; - if (NODE_STRING_IS_CRUDE(node)) + if (ND_STRING_IS_CRUDE(node)) mode = "-crude"; - else if (NODE_IS_IGNORECASE(node)) + else if (ND_IS_IGNORECASE(node)) mode = "-ignorecase"; else mode = ""; @@ -8283,7 +8351,7 @@ print_indent_tree(FILE* f, Node* node, int indent) } break; - case NODE_CCLASS: + case ND_CCLASS: #define CCLASS_MBUF_MAX_OUTPUT_NUM 10 fprintf(f, "<cclass:%p>", node); @@ -8299,7 +8367,7 @@ print_indent_tree(FILE* f, Node* node, int indent) } break; - case NODE_CTYPE: + case ND_CTYPE: fprintf(f, "<ctype:%p> ", node); switch (CTYPE_(node)->ctype) { case CTYPE_ANYCHAR: @@ -8323,7 +8391,7 @@ print_indent_tree(FILE* f, Node* node, int indent) } break; - case NODE_ANCHOR: + case ND_ANCHOR: fprintf(f, "<anchor:%p> ", node); switch (ANCHOR_(node)->type) { case ANCR_BEGIN_BUF: fputs("begin buf", f); break; @@ -8345,19 +8413,19 @@ print_indent_tree(FILE* f, Node* node, int indent) fputs("no text-segment boundary", f); break; case ANCR_PREC_READ: fprintf(f, "prec read\n"); - print_indent_tree(f, NODE_BODY(node), indent + add); + print_indent_tree(f, ND_BODY(node), indent + add); break; case ANCR_PREC_READ_NOT: fprintf(f, "prec read not\n"); - print_indent_tree(f, NODE_BODY(node), indent + add); + print_indent_tree(f, ND_BODY(node), indent + add); break; case ANCR_LOOK_BEHIND: fprintf(f, "look behind\n"); - print_indent_tree(f, NODE_BODY(node), indent + add); + print_indent_tree(f, ND_BODY(node), indent + add); break; case ANCR_LOOK_BEHIND_NOT: fprintf(f, "look behind not\n"); - print_indent_tree(f, NODE_BODY(node), indent + add); + print_indent_tree(f, ND_BODY(node), indent + add); break; default: @@ -8366,18 +8434,18 @@ print_indent_tree(FILE* f, Node* node, int indent) } break; - case NODE_BACKREF: + case ND_BACKREF: { int* p; BackRefNode* br = BACKREF_(node); p = BACKREFS_P(br); - fprintf(f, "<backref%s:%p>", NODE_IS_CHECKER(node) ? "-checker" : "", node); + fprintf(f, "<backref%s:%p>", ND_IS_CHECKER(node) ? "-checker" : "", node); for (i = 0; i < br->back_num; i++) { if (i > 0) fputs(", ", f); fprintf(f, "%d", p[i]); } #ifdef USE_BACKREF_WITH_LEVEL - if (NODE_IS_NEST_LEVEL(node)) { + if (ND_IS_NEST_LEVEL(node)) { fprintf(f, ", level: %d", br->nest_level); } #endif @@ -8385,33 +8453,33 @@ print_indent_tree(FILE* f, Node* node, int indent) break; #ifdef USE_CALL - case NODE_CALL: + case ND_CALL: { CallNode* cn = CALL_(node); fprintf(f, "<call:%p>", node); fprintf(f, " num: %d, name", cn->called_gnum); p_string(f, cn->name_end - cn->name, cn->name); - if (NODE_IS_RECURSION(node)) fprintf(f, ", recursion"); - if (NODE_IS_INPEEK(node)) fprintf(f, ", in-peek"); - if (NODE_IS_IN_REAL_REPEAT(node)) fprintf(f, ", in-real-repeat"); + if (ND_IS_RECURSION(node)) fprintf(f, ", recursion"); + if (ND_IS_INPEEK(node)) fprintf(f, ", in-peek"); + if (ND_IS_IN_REAL_REPEAT(node)) fprintf(f, ", in-real-repeat"); } break; #endif - case NODE_QUANT: + case ND_QUANT: { fprintf(f, "<quantifier:%p>{%d,%d}%s%s%s", node, QUANT_(node)->lower, QUANT_(node)->upper, (QUANT_(node)->greedy ? "" : "?"), QUANT_(node)->include_referred == 0 ? "" : " referred", emptiness_name[QUANT_(node)->emptiness]); - if (NODE_IS_INPEEK(node)) fprintf(f, ", in-peek"); + if (ND_IS_INPEEK(node)) fprintf(f, ", in-peek"); fprintf(f, "\n"); - print_indent_tree(f, NODE_BODY(node), indent + add); + print_indent_tree(f, ND_BODY(node), indent + add); } break; - case NODE_BAG: + case ND_BAG: { BagNode* bn = BAG_(node); fprintf(f, "<bag:%p> ", node); @@ -8420,7 +8488,7 @@ print_indent_tree(FILE* f, Node* node, int indent) Node* Else; fprintf(f, "if-else\n"); - print_indent_tree(f, NODE_BODY(node), indent + add); + print_indent_tree(f, ND_BODY(node), indent + add); Then = bn->te.Then; Else = bn->te.Else; @@ -8445,15 +8513,15 @@ print_indent_tree(FILE* f, Node* node, int indent) break; case BAG_MEMORY: fprintf(f, "memory:%d", bn->m.regnum); - if (NODE_IS_CALLED(node)) { + if (ND_IS_CALLED(node)) { fprintf(f, ", called"); - if (NODE_IS_RECURSION(node)) + if (ND_IS_RECURSION(node)) fprintf(f, ", recursion"); } - else if (NODE_IS_REFERENCED(node)) + else if (ND_IS_REFERENCED(node)) fprintf(f, ", referenced"); - if (NODE_IS_FIXED_ADDR(node)) + if (ND_IS_FIXED_ADDR(node)) fprintf(f, ", fixed-addr"); if ((bn->m.called_state & IN_PEEK) != 0) fprintf(f, ", in-peek"); @@ -8465,12 +8533,12 @@ print_indent_tree(FILE* f, Node* node, int indent) break; } fprintf(f, "\n"); - print_indent_tree(f, NODE_BODY(node), indent + add); + print_indent_tree(f, ND_BODY(node), indent + add); } } break; - case NODE_GIMMICK: + case ND_GIMMICK: fprintf(f, "<gimmick:%p> ", node); switch (GIMMICK_(node)->type) { case GIMMICK_FAIL: @@ -8497,12 +8565,12 @@ print_indent_tree(FILE* f, Node* node, int indent) break; default: - fprintf(f, "print_indent_tree: undefined node type %d\n", NODE_TYPE(node)); + fprintf(f, "print_indent_tree: undefined node type %d\n", ND_TYPE(node)); break; } - if (type != NODE_LIST && type != NODE_ALT && type != NODE_QUANT && - type != NODE_BAG) + if (type != ND_LIST && type != ND_ALT && type != ND_QUANT && + type != ND_BAG) fprintf(f, "\n"); fflush(f); } |