-
Notifications
You must be signed in to change notification settings - Fork 254
Remove duplicated scan substring captures #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+382
−119
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6495,8 +6495,63 @@ for (;; pptr++) | |
| req_caseopt = ((options & PCRE2_CASELESS) != 0)? REQ_CASELESS : 0; | ||
| break; | ||
|
|
||
| /* ===================================================================*/ | ||
| /* Handle scan substring. Scan substring assertion starts with META_SCS, | ||
| which recursively calls compile_branch. The first opcode processed by | ||
| this recursive call is always META_OFFSET. */ | ||
|
|
||
| case META_OFFSET: | ||
| GETPLUSOFFSET(offset, pptr); | ||
| if (lengthptr != NULL) | ||
| { | ||
| pptr = PRIV(compile_parse_scan_substr_args)(pptr, errorcodeptr, cb, lengthptr); | ||
| if (pptr == NULL) | ||
| return 0; | ||
| break; | ||
| } | ||
|
|
||
| while (TRUE) | ||
| { | ||
| int count, index; | ||
| named_group *ng; | ||
|
|
||
| switch (META_CODE(*pptr)) | ||
| { | ||
| case META_OFFSET: | ||
| pptr++; | ||
| SKIPOFFSET(pptr); | ||
| continue; | ||
|
|
||
| case META_CAPTURE_NAME: | ||
| ng = cb->named_groups + pptr[1]; | ||
| pptr += 2; | ||
| count = 0; | ||
| index = 0; | ||
|
|
||
| if (!PRIV(compile_find_dupname_details)(ng->name, ng->length, &index, | ||
| &count, errorcodeptr, cb)) return 0; | ||
|
|
||
| code[0] = OP_DNCREF; | ||
| PUT2(code, 1, index); | ||
| PUT2(code, 1 + IMM2_SIZE, count); | ||
| code += 1 + 2 * IMM2_SIZE; | ||
| continue; | ||
|
|
||
| case META_CAPTURE_NUMBER: | ||
| pptr += 2; | ||
| if (pptr[-1] == 0) continue; | ||
|
|
||
| code[0] = OP_CREF; | ||
| PUT2(code, 1, pptr[-1]); | ||
| code += 1 + IMM2_SIZE; | ||
| continue; | ||
|
|
||
| default: | ||
| break; | ||
| } | ||
|
|
||
| break; | ||
| } | ||
| --pptr; | ||
| break; | ||
|
|
||
| case META_SCS: | ||
|
|
@@ -6515,7 +6570,6 @@ for (;; pptr++) | |
| case META_COND_RNUMBER: /* (?(Rdigits) */ | ||
| case META_COND_NAME: /* (?(name) or (?'name') or ?(<name>) */ | ||
| case META_COND_RNAME: /* (?(R&name) - test for recursion */ | ||
| case META_CAPTURE_NAME: /* Generic capture name */ | ||
| bravalue = OP_COND; | ||
|
|
||
| if (lengthptr != NULL) | ||
|
|
@@ -6526,10 +6580,7 @@ for (;; pptr++) | |
| uint32_t *start_pptr = pptr; | ||
| uint32_t length = *(++pptr); | ||
|
|
||
| if (meta == META_CAPTURE_NAME) | ||
| offset += meta_arg; | ||
| else | ||
| GETPLUSOFFSET(offset, pptr); | ||
| GETPLUSOFFSET(offset, pptr); | ||
| name = cb->start_pattern + offset; | ||
|
|
||
| /* In the first pass, the names generated in the pre-pass are available, | ||
|
|
@@ -6592,12 +6643,6 @@ for (;; pptr++) | |
| start_pptr[0] = meta; | ||
| start_pptr[1] = ng->number; | ||
|
|
||
| if (meta == META_CAPTURE_NAME) | ||
| { | ||
| code += 1 + IMM2_SIZE; | ||
| break; | ||
| } | ||
|
|
||
|
Comment on lines
-6595
to
-6600
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the other hand I do agree that all these META_CAPTURE_NAME/NUMBER special cases were really ugly down here, and it's definitely better to be able to move them somewhere else where they can be handled together. |
||
| skipunits = 1 + IMM2_SIZE; | ||
| goto GROUP_PROCESS_NOTE_EMPTY; | ||
| } | ||
|
|
@@ -6608,12 +6653,6 @@ for (;; pptr++) | |
| start_pptr[0] = meta | 1; | ||
| start_pptr[1] = (uint32_t)(ng - cb->named_groups); | ||
|
|
||
| if (meta == META_CAPTURE_NAME) | ||
| { | ||
| code += 1 + 2 * IMM2_SIZE; | ||
| break; | ||
| } | ||
|
|
||
| /* A duplicated name was found. Note that if an R<digits> name is found | ||
| (META_COND_RNUMBER), it is a reference test, not a recursion test. */ | ||
| skipunits = 1 + 2 * IMM2_SIZE; | ||
|
|
@@ -6639,15 +6678,6 @@ for (;; pptr++) | |
|
|
||
| if (meta_arg == 0) | ||
| { | ||
| if (meta == META_CAPTURE_NAME) | ||
| { | ||
| code[0] = OP_CREF; | ||
| PUT2(code, 1, pptr[1]); | ||
| code += 1 + IMM2_SIZE; | ||
| pptr++; | ||
| break; | ||
| } | ||
|
|
||
| code[1+LINK_SIZE] = (meta == META_COND_RNAME)? OP_RREF : OP_CREF; | ||
| PUT2(code, 2 + LINK_SIZE, pptr[1]); | ||
| skipunits = 1 + IMM2_SIZE; | ||
|
|
@@ -6663,16 +6693,6 @@ for (;; pptr++) | |
| if (!PRIV(compile_find_dupname_details)(ng->name, ng->length, &index, | ||
| &count, errorcodeptr, cb)) return 0; | ||
|
|
||
| if (meta == META_CAPTURE_NAME) | ||
| { | ||
| code[0] = OP_DNCREF; | ||
| PUT2(code, 1, index); | ||
| PUT2(code, 1 + IMM2_SIZE, count); | ||
| code += 1 + 2 * IMM2_SIZE; | ||
| pptr++; | ||
| break; | ||
| } | ||
|
|
||
| /* A duplicated name was found. Note that if an R<digits> name is found | ||
| (META_COND_RNUMBER), it is a reference test, not a recursion test. */ | ||
|
|
||
|
|
@@ -6702,12 +6722,8 @@ for (;; pptr++) | |
| /* Conditional test of a group's being set. */ | ||
|
|
||
| case META_COND_NUMBER: | ||
| case META_CAPTURE_NUMBER: | ||
| bravalue = OP_COND; | ||
| if (meta == META_CAPTURE_NUMBER) | ||
| offset += meta_arg; | ||
| else | ||
| GETPLUSOFFSET(offset, pptr); | ||
| GETPLUSOFFSET(offset, pptr); | ||
|
|
||
| groupnumber = *(++pptr); | ||
| if (groupnumber > cb->bracount) | ||
|
|
@@ -6718,14 +6734,6 @@ for (;; pptr++) | |
| } | ||
| if (groupnumber > cb->top_backref) cb->top_backref = groupnumber; | ||
|
|
||
| if (meta == META_CAPTURE_NUMBER) | ||
| { | ||
| code[0] = OP_CREF; | ||
| PUT2(code, 1, groupnumber); | ||
| code += 1+IMM2_SIZE; | ||
| break; | ||
| } | ||
|
|
||
| /* Point at initial ( for too many branches error */ | ||
| offset -= 2; | ||
| code[1+LINK_SIZE] = OP_CREF; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err. I don't know how I feel about this, how you've moved the META_CAPTURE_NAME/NUMBER code so it's now hanging under the META_OFFSET handling. I'd named & implemented META_OFFSET in an intentionally generic way, so it could be used outside of scan-substring capture lists.
Do we have to make this change? Maybe we should just merge META_OFFSET and META_SCS now, if you do want to go in this direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think they can be merged. META_SCS starts a recursive call to process its block, and another opcode is needed to show that we are processing scan substring. We could change the code generator to support optional arguments (it currently expects a fixed size byte code), but that is complex enough.
Option: the 16 bit arg of META_OFFSET is not used, it could represent the different types of blocks if needed.