Matchcompiler parse all Match|simpleMatch on the same line#2993
Merged
danmar merged 3 commits intoDec 31, 2020
Merged
Conversation
Especially the added space makes it a little more readable.
If matchcompiler found a call to Token::Match() or Token::simpleMatch() with an unknown string argument, subsequent calls to Token::Match() or Token::simpleMatch() on the same line would not be processed by matchcompiler. To fix this, keep track of the last index we found a match, and update it accordingly when the line is modified. To avoid having to keep track of if "Match" or "simpleMatch" is the first match we find, just make a loop over them.
rikardfalkeborn
commented
Dec 29, 2020
| varId = None | ||
| if len(res) == 4: | ||
| varId = res[3] | ||
| for func in ('Match', 'simpleMatch'): |
Contributor
Author
There was a problem hiding this comment.
I was a bit back and forth if this should be a function which is called twice, instead of having a loop, but I guess it doesn't matter that much.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Previously, Matchcompiler stopped processing the line in case it found a match it could not process, which meant other matches on the same line were not processed, even though they might be simplified (also, due to the implementation, all
Token::Matchon the line were processed first, so if the line contained one Match that could not be simplified, no simpleMatches would be simplified). Fix this by not bailing out and check all matches. Due to indentation changes (I put the relevant lines of code in a for loop), the diff look larger than it really is (compare without whitespace changes and you'll see).Also, while at it, fix some whitespace formatting in the generated code, and neaten some error messages slightly (I actually looked at the code and error messages when debugging, and the minor changes actually improved readability for me).
Also, it can be noted that current cppcheck main branch do not contain any such lines at the moment.