From: K.Kosako Date: Fri, 9 Jun 2017 07:40:15 +0000 (+0900) Subject: divide setup_subexp_call() into setup_subexp_call_node_call() X-Git-Tag: v6.4.0~1^2~104 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41eb14754811db788dbdcea38947b9e8b0926be7;p=onig divide setup_subexp_call() into setup_subexp_call_node_call() --- diff --git a/src/regcomp.c b/src/regcomp.c index 0b4b90a..dbfb79e 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -2991,10 +2991,72 @@ subexp_recursive_check_trav(Node* node, ScanEnv* env) return r; } +#ifdef __GNUC__ +__inline +#endif +static int +setup_subexp_call_node_call(CallNode* cn, ScanEnv* env) +{ + MemEnv* mem_env = SCANENV_MEMENV(env); + + if (cn->group_num != 0) { + int gnum = cn->group_num; + +#ifdef USE_NAMED_GROUP + if (env->num_named > 0 && + IS_SYNTAX_BV(env->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) && + !ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_CAPTURE_GROUP)) { + return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED; + } +#endif + if (gnum > env->num_mem) { + onig_scan_env_set_error_string(env, ONIGERR_UNDEFINED_GROUP_REFERENCE, + cn->name, cn->name_end); + return ONIGERR_UNDEFINED_GROUP_REFERENCE; + } + +#ifdef USE_NAMED_GROUP + set_call_attr: +#endif + NODE_CALL_BODY(cn) = mem_env[cn->group_num].node; + if (IS_NULL(NODE_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), NST_CALLED); + BIT_STATUS_ON_AT(env->bt_mem_start, cn->group_num); + cn->unset_addr_list = env->unset_addr_list; + } +#ifdef USE_NAMED_GROUP + else { + int *refs; + + int n = onig_name_to_group_numbers(env->reg, cn->name, cn->name_end, &refs); + if (n <= 0) { + onig_scan_env_set_error_string(env, ONIGERR_UNDEFINED_NAME_REFERENCE, + cn->name, cn->name_end); + return ONIGERR_UNDEFINED_NAME_REFERENCE; + } + else if (n > 1) { + onig_scan_env_set_error_string(env, ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL, + cn->name, cn->name_end); + return ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL; + } + else { + cn->group_num = refs[0]; + goto set_call_attr; + } + } +#endif + + return 0; +} + static int setup_subexp_call(Node* node, ScanEnv* env) { - int r = 0; + int r; switch (NODE_TYPE(node)) { case NODE_LIST: @@ -3010,62 +3072,7 @@ setup_subexp_call(Node* node, ScanEnv* env) break; case NODE_CALL: - { - CallNode* cn = CALL_(node); - MemEnv* mem_env = SCANENV_MEMENV(env); - - if (cn->group_num != 0) { - int gnum = cn->group_num; - -#ifdef USE_NAMED_GROUP - if (env->num_named > 0 && - IS_SYNTAX_BV(env->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) && - !ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_CAPTURE_GROUP)) { - return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED; - } -#endif - if (gnum > env->num_mem) { - onig_scan_env_set_error_string(env, - ONIGERR_UNDEFINED_GROUP_REFERENCE, cn->name, cn->name_end); - return ONIGERR_UNDEFINED_GROUP_REFERENCE; - } - -#ifdef USE_NAMED_GROUP - set_call_attr: -#endif - NODE_CALL_BODY(cn) = mem_env[cn->group_num].node; - if (IS_NULL(NODE_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), NST_CALLED); - BIT_STATUS_ON_AT(env->bt_mem_start, cn->group_num); - cn->unset_addr_list = env->unset_addr_list; - } -#ifdef USE_NAMED_GROUP - else { - int *refs; - - int n = onig_name_to_group_numbers(env->reg, cn->name, cn->name_end, - &refs); - if (n <= 0) { - onig_scan_env_set_error_string(env, - ONIGERR_UNDEFINED_NAME_REFERENCE, cn->name, cn->name_end); - return ONIGERR_UNDEFINED_NAME_REFERENCE; - } - else if (n > 1) { - onig_scan_env_set_error_string(env, - ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL, cn->name, cn->name_end); - return ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL; - } - else { - cn->group_num = refs[0]; - goto set_call_attr; - } - } -#endif - } + r = setup_subexp_call_node_call(CALL_(node), env); break; case NODE_ANCHOR: @@ -3073,10 +3080,13 @@ setup_subexp_call(Node* node, ScanEnv* env) AnchorNode* an = ANCHOR_(node); if (ANCHOR_HAS_BODY(an)) r = setup_subexp_call(NODE_ANCHOR_BODY(an), env); + else + r = 0; } break; default: + r = 0; break; }