This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Use an enum for context types. NFC
ClosedPublic

Authored by sstwcw on Mar 17 2022, 5:28 AM.

Details

Summary

We currently have all those fields in AnnotatingParser::Context. They
are not inherited from the Context object for the parent scope. They
are exclusive. Now they are replaced with an enum.

InCpp11AttributeSpecifier and InCSharpAttributeSpecifier are not
handled like the rest in ContextType because they are not exclusive.

Diff Detail

Event Timeline

sstwcw created this revision.Mar 17 2022, 5:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 5:28 AM
sstwcw requested review of this revision.Mar 17 2022, 5:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 5:28 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

If this patch is an NFC, please add [NFC] to the title.

Please add @MyDeveloperDay @curdeius @HazardyKnusperkeks to Reviewers.

clang/lib/Format/TokenAnnotator.cpp
116

If this was bug, it should be in a separate patch with test cases added.

So out of interest, what is the reason? my assumption is that you wanted to add more for Verilog and you felt adding the extra bools was the wrong design and its better an an enum

bool InCpp11AttributeSpecifier = false;
bool InCSharpAttributeSpecifier = false;

Does the fact that some aren't exclusive make you think its ok to split it into enums and bools is ok? (no real opinion just wondered what you and others think?)

MyDeveloperDay edited reviewers, added: curdeius, MyDeveloperDay, HazardyKnusperkeks, owenpan; removed: Restricted Project.Mar 17 2022, 12:46 PM

So out of interest, what is the reason? my assumption is that you wanted to add more for Verilog and you felt adding the extra bools was the wrong design and its better an an enum

bool InCpp11AttributeSpecifier = false;
bool InCSharpAttributeSpecifier = false;

Does the fact that some aren't exclusive make you think its ok to split it into enums and bools is ok? (no real opinion just wondered what you and others think?)

It is really helpful to see that these are exclusive. It helps reasoning about the code.

clang/lib/Format/TokenAnnotator.cpp
1498

This is a comment for the change, afterwards it's strange to see for newcomers. Since it's without Context. *scnr*

sstwcw updated this revision to Diff 416458.Mar 18 2022, 4:20 AM

Remove comment.

sstwcw retitled this revision from [clang-format] Use an enum for context types. to [clang-format] Use an enum for context types. NFC.Mar 18 2022, 4:21 AM
sstwcw edited the summary of this revision. (Show Details)
MyDeveloperDay accepted this revision.Mar 18 2022, 4:26 AM

I think fundamentally this look ok? @curdeius and @owenpan I feel I want to bow to your better judgement.

This revision is now accepted and ready to land.Mar 18 2022, 4:26 AM

Please wait for the other reviewers if you have commit access.

sstwcw marked 2 inline comments as done.Mar 18 2022, 4:39 AM

So out of interest, what is the reason? my assumption is that you wanted to add more for Verilog and you felt adding the extra bools was the wrong design and its better an an enum

You are right.

bool InCpp11AttributeSpecifier = false;
bool InCSharpAttributeSpecifier = false;

Does the fact that some aren't exclusive make you think its ok to split it into enums and bools is ok? (no real opinion just wondered what you and others think?)

Does it make me think it's ok? Yes. Good? No. I am lazy and I chose this way which doesn't require examining those two options.

clang/lib/Format/TokenAnnotator.cpp
116

Sorry that the previous patch did not include more context. Pun intended. Now you can scroll up and see that the context was just initialized, so InTemplateArgument starts being false, so it didn't matter whether the original code was InTemplateArgument = ...; or if (...) InTemplateArgument = true;.

owenpan accepted this revision.Mar 18 2022, 5:03 AM

LGTM. Any comments, @curdeius?

clang/lib/Format/TokenAnnotator.cpp
116

Got it. Thanks.

curdeius accepted this revision.Mar 18 2022, 5:46 AM

I really like this change. Thanks!

This revision was landed with ongoing or failed builds.Mar 21 2022, 2:58 PM
This revision was automatically updated to reflect the committed changes.
sstwcw marked an inline comment as done.