Skip to content

Matchcompiler parse all Match|simpleMatch on the same line#2993

Merged
danmar merged 3 commits into
cppcheck-opensource:mainfrom
rikardfalkeborn:matchcompiler-bailout-same-line
Dec 31, 2020
Merged

Matchcompiler parse all Match|simpleMatch on the same line#2993
danmar merged 3 commits into
cppcheck-opensource:mainfrom
rikardfalkeborn:matchcompiler-bailout-same-line

Conversation

@rikardfalkeborn

Copy link
Copy Markdown
Contributor

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::Match on 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.

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.
Comment thread tools/matchcompiler.py
varId = None
if len(res) == 4:
varId = res[3]
for func in ('Match', 'simpleMatch'):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danmar danmar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@danmar danmar merged commit 8dc8aa0 into cppcheck-opensource:main Dec 31, 2020
@rikardfalkeborn rikardfalkeborn deleted the matchcompiler-bailout-same-line branch December 31, 2020 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants