Skip to content
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

Feature/refactor cpp2 language module #1167

Merged
merged 7 commits into from
Jul 10, 2023
Merged

Conversation

TwoOfTwelve
Copy link
Contributor

@TwoOfTwelve TwoOfTwelve commented Jul 4, 2023

This PR refactors the cpp2 tests and language module.
Also contains minor improvements for the abstract antlr utils and test utils.

The refactoring of the cpp2 module fixes a couple of issues with the module. As far as I can tell all tokens are still extracted by the same rules, although it would be nice if someone could verify that.

The fixed errors are:
-Nested if-else statements lead to the wrong line being assigned to the second else token
-The Antlr grammar was missing DivAssign in the list of operators for operator overloading

The things changed in the testutils:
-The tokenprinter is now called for the tests (should we maybe only do this if the test fails?)
-The configured tests are now passed as a list instead of a set internally, so the order of tests does not change between runs.

@brodmo
Copy link
Contributor

brodmo commented Jul 4, 2023

With this change, how could I add semantic information to the tokens as is done in the TokenGeneratingTreeScanner? How could I track variables, for instance?

@TwoOfTwelve
Copy link
Contributor Author

Right now that is not possible, but I will write a small expansion to the abstract antlr utils, that as far as I can tell should suffice. I just did not want to make this pr any bigger.

@tsaglam tsaglam changed the title Feature/refactor cpp2 tests Feature/refactor cpp2 language module Jul 5, 2023
@tsaglam tsaglam requested a review from a team July 5, 2023 05:44
@tsaglam
Copy link
Member

tsaglam commented Jul 5, 2023

@TwoOfTwelve could you extend the PR description a bit? List the fixes to the cpp2 language explicitly (e.g., which tokens/syntax elements were affected).

Also, for testing the token extraction quickly, you can always use the token printer to print the token before and after your change with a large cpp file and then to a text diff.

Finally, the expansion for semantic token information would be of the highest priority right now.

@tsaglam tsaglam added enhancement Issue/PR that involves features, improvements and other changes major Major issue/feature/contribution/change language PR / Issue deals (partly) with new and/or existing languages for JPlag labels Jul 5, 2023
@TwoOfTwelve
Copy link
Contributor Author

I compared the old and new versions. Aside from some formatting and the wrong else token mentioned in the description the tokens are the same (My testfile had about 3000 lines of code).

The semantics stuff is mostly done already I just need to write the javadoc and some JUnit tests mostly. I think I can create the PR today.

Copy link
Member

@tsaglam tsaglam left a comment

Choose a reason for hiding this comment

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

We may need to clarify in the language readme that this grammar has been changed compared to the original one. Ideally, add a note on what has been changed.

@tsaglam tsaglam requested review from a team and removed request for a team July 6, 2023 14:22
Copy link
Contributor

@brodmo brodmo left a comment

Choose a reason for hiding this comment

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

some minor things

public CPPListener(TokenCollector collector, File currentFile) {
super(collector, currentFile);

createStartStopMapping(ClassSpecifierContext.class, UNION_BEGIN, UNION_END, rule -> rule.classHead().Union() != null);
Copy link
Contributor

Choose a reason for hiding this comment

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

looks clean, but since create...Mapping is repeated so often it should be less verbose, my suggestion would be simply map..., in this case mapStartStop, or, in this case specifically even simpler, mapScope

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that this naming would be better, but since these methods were introduced before this PR and it is not directly connected to the cpp2 module, I would prefer to change them in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, makes sense. Do you have time to make this PR? Otherwise I can do it as well. But I should really get started on the semantic token info 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do it, but it will have to wait until this evening. If you would like it before then go for it, but I think it is not that urgent.

createStartStopMapping(SelectionStatementContext.class, IF_BEGIN, IF_END, rule -> rule.If() != null);
createTerminalMapping(CPP14Parser.Else, ELSE);

createStartMapping(LabeledStatementContext.class, CASE, rule -> rule.Case() != null);
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like it should be enter/exit instead of start/stop, so mapEnter here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

@sonarqubecloud
Copy link

[JPlag Plagiarism Detector] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@tsaglam tsaglam merged commit 7fde56b into develop Jul 10, 2023
@dfuchss dfuchss deleted the feature/refactor-cpp2-tests branch December 6, 2023 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issue/PR that involves features, improvements and other changes language PR / Issue deals (partly) with new and/or existing languages for JPlag major Major issue/feature/contribution/change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants