summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2014-09-16 17:16:47 -0600
committerKarl Williamson <khw@cpan.org>2014-09-29 11:07:39 -0600
commit9990d5ab621b83dea3adb80c343aff125fe9764b (patch)
tree853129d0e9d992ca9ae29f030bef10d507af689b
parent975a06f7f899d1dd89d8a66defc0b3ee41013d1f (diff)
downloadperl-9990d5ab621b83dea3adb80c343aff125fe9764b.tar.gz
regcomp.c: Add a function and use it
This adds a function to allocate a regnode with 2 32-bit arguments, and uses it, rather than the ad-hoc code that did the same thing previously. This is in preparation for this code being used in a 2nd place in a future commit.
-rw-r--r--embed.fnc4
-rw-r--r--embed.h1
-rw-r--r--proto.h5
-rw-r--r--regcomp.c28
-rw-r--r--regcomp.h7
5 files changed, 39 insertions, 6 deletions
diff --git a/embed.fnc b/embed.fnc
index 1c3d0bc7cc..ee5f115d6e 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -2092,6 +2092,10 @@ Es |regnode*|regnode_guts |NN RExC_state_t *pRExC_state \
|NN const char* const name
Es |regnode*|reganode |NN RExC_state_t *pRExC_state|U8 op \
|U32 arg
+Es |regnode*|reg2Lanode |NN RExC_state_t *pRExC_state \
+ |const U8 op \
+ |const U32 arg1 \
+ |const I32 arg2
Es |regnode*|regatom |NN RExC_state_t *pRExC_state \
|NN I32 *flagp|U32 depth
Es |regnode*|regbranch |NN RExC_state_t *pRExC_state \
diff --git a/embed.h b/embed.h
index b6aabef3f7..e0df072e94 100644
--- a/embed.h
+++ b/embed.h
@@ -977,6 +977,7 @@
#define parse_lparen_question_flags(a) S_parse_lparen_question_flags(aTHX_ a)
#define populate_ANYOF_from_invlist(a,b) S_populate_ANYOF_from_invlist(aTHX_ a,b)
#define reg(a,b,c,d) S_reg(aTHX_ a,b,c,d)
+#define reg2Lanode(a,b,c,d) S_reg2Lanode(aTHX_ a,b,c,d)
#define reg_node(a,b) S_reg_node(aTHX_ a,b)
#define reg_recode(a,b) S_reg_recode(aTHX_ a,b)
#define reg_scan_name(a,b) S_reg_scan_name(aTHX_ a,b)
diff --git a/proto.h b/proto.h
index 2f9e62fae8..b4ab3df450 100644
--- a/proto.h
+++ b/proto.h
@@ -6918,6 +6918,11 @@ STATIC regnode* S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp, U3
#define PERL_ARGS_ASSERT_REG \
assert(pRExC_state); assert(flagp)
+STATIC regnode* S_reg2Lanode(pTHX_ RExC_state_t *pRExC_state, const U8 op, const U32 arg1, const I32 arg2)
+ __attribute__nonnull__(pTHX_1);
+#define PERL_ARGS_ASSERT_REG2LANODE \
+ assert(pRExC_state)
+
STATIC regnode* S_reg_node(pTHX_ RExC_state_t *pRExC_state, U8 op)
__attribute__nonnull__(pTHX_1);
#define PERL_ARGS_ASSERT_REG_NODE \
diff --git a/regcomp.c b/regcomp.c
index fa0e9c2ad2..a425810cbb 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -9931,20 +9931,17 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth)
num = RExC_npar + num - 1;
}
- ret = reganode(pRExC_state, GOSUB, num);
+ ret = reg2Lanode(pRExC_state, GOSUB, num, RExC_recurse_count);
if (!SIZE_ONLY) {
if (num > (I32)RExC_rx->nparens) {
RExC_parse++;
vFAIL("Reference to nonexistent group");
}
- ARG2L_SET( ret, RExC_recurse_count++);
- RExC_emit++;
+ RExC_recurse_count++;
DEBUG_OPTIMISE_MORE_r(PerlIO_printf(Perl_debug_log,
"Recurse #%"UVuf" to %"IVdf"\n",
(UV)ARG(ret), (IV)ARG2L(ret)));
- } else {
- RExC_size++;
- }
+ }
RExC_seen |= REG_RECURSE_SEEN;
Set_Node_Length(ret, 1 + regarglen[OP(ret)]); /* MJD */
Set_Node_Offset(ret, parse_start); /* MJD */
@@ -15493,6 +15490,25 @@ S_reganode(pTHX_ RExC_state_t *pRExC_state, U8 op, U32 arg)
return(ret);
}
+STATIC regnode *
+S_reg2Lanode(pTHX_ RExC_state_t *pRExC_state, const U8 op, const U32 arg1, const I32 arg2)
+{
+ /* emit a node with U32 and I32 arguments */
+
+ regnode * const ret = regnode_guts(pRExC_state, op, regarglen[op], "rega2Lnode");
+
+ PERL_ARGS_ASSERT_REG2LANODE;
+
+ assert(regarglen[op] == 2);
+
+ if (PASS2) {
+ regnode *ptr = ret;
+ FILL_ADVANCE_NODE_2L_ARG(ptr, op, arg1, arg2);
+ RExC_emit = ptr;
+ }
+ return(ret);
+}
+
/*
- reguni - emit (if appropriate) a Unicode character
*/
diff --git a/regcomp.h b/regcomp.h
index 9b59d020f0..c08e5ad56c 100644
--- a/regcomp.h
+++ b/regcomp.h
@@ -361,6 +361,13 @@ struct regnode_ssc {
(ptr)->type = op; (ptr)->next_off = 0; (ptr)++; } STMT_END
#define FILL_ADVANCE_NODE_ARG(ptr, op, arg) STMT_START { \
ARG_SET(ptr, arg); FILL_ADVANCE_NODE(ptr, op); (ptr) += 1; } STMT_END
+#define FILL_ADVANCE_NODE_2L_ARG(ptr, op, arg1, arg2) \
+ STMT_START { \
+ ARG_SET(ptr, arg1); \
+ ARG2L_SET(ptr, arg2); \
+ FILL_ADVANCE_NODE(ptr, op); \
+ (ptr) += 2; \
+ } STMT_END
#define REG_MAGIC 0234