-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[clang-format] modified goto bool to enum #65140
base: main
Are you sure you want to change the base?
[clang-format] modified goto bool to enum #65140
Conversation
What am I Missing here? |
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.
You are missing unit tests
IO.enumCase(Value, "HalfIndent", FormatStyle::GLI_HalfIndent); | ||
} | ||
}; | ||
|
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.
You are not supporting the old true/false case this would cause everyone else to break
I'd expect to see something like this
// For backward compatibility.
IO.enumCase(Value, "true", FormatStyle::GLI_Indent);
IO.enumCase(Value, "false", FormatStyle::GLI_None);
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.
working on it
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.
Ok this should have been in addition to what you had before not instead of
clang/include/clang/Format/Format.h
Outdated
@@ -2432,9 +2431,25 @@ struct FormatStyle { | |||
/// label2: label2: | |||
/// return 1; return 1; | |||
/// } } | |||
/// | |||
/// GLI_HalfIndent: |
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.
where in hte code is GLI_HalfIndent handled differently from GLI_Indent sorry I'm confused
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.
This is not the way, create your feature, test it, and document it, use it yourself to ensure it works, find corner cases anf fix them, then send us the PR when it ready. |
clang/include/clang/Format/Format.h
Outdated
enum GotoLabelIndentation { | ||
GLI_None, // Do not indent goto labels. | ||
GLI_Indent, // Indent goto labels at the same level as the surrounding code. | ||
GLI_HalfIndent, // Indent goto labels at a half indent level. |
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.
You need more examples (with more indentation) and/or more description what you intend to do. Do you round up or down for odd indentation levels? Do you really want that, or do you only want one level less?
namespace NS {
class C {
void foo() {
while (x) {
if (y) {
label: //where would this be?
}
}
}
}
}
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.
doing it
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 am testing the changes
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.
3047 | Style.IndentGotoLabels = false;
in llvm-project/clang/unittests/Format/FormatTest.cpp
I missed this and it's shameful correcting it
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.
Do you actually want to use that feature, or do you only want to work on something?
Please take a greater look on how enums are documented, parsed, and tested. A fairly recent example which transitioned from bool
would be: BreakBeforeInlineASMColon
@@ -161,7 +171,8 @@ TEST(ConfigParseTest, ParsesConfigurationBools) { | |||
CHECK_PARSE_BOOL(IndentAccessModifiers); | |||
CHECK_PARSE_BOOL(IndentCaseLabels); | |||
CHECK_PARSE_BOOL(IndentCaseBlocks); | |||
CHECK_PARSE_BOOL(IndentGotoLabels); | |||
CHECK_PARSE_ENUM(IndentGotoLabels, |
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.
We have dedicated sections on how to check enum parsing.
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.
3047 | Style.IndentGotoLabels = false;
in llvm-project/clang/unittests/Format/FormatTest.cpp
I missed this and it's shameful and I corrected it but now looking carefully at my local end.
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 want you to also test the actual usage of your option
/// void foo() { void foo() { | ||
/// while (x) { while (x) { | ||
/// if (y) { if (y) { | ||
/// label: label: |
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.
This does not display what None
should do. You would break thousands of users.
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.
looking into this
Indent goto labels. | ||
|
||
When ``false``, goto labels are flushed left. | ||
When ``GLI_None``, goto labels are flushed left. |
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.
Do you edit this by hand?
ClangFormatStyleOptions.rst
is generated by clang/docs/tools/dump_format_style.py.
So do all your edits in Format.h
, and then run the script.
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.
1> yes. I did not know that.
2> okay. Got it.
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 will do it correctly in the morning.
As it's something of my past pending task, I'm looking to learn and contribute in any way I can. I left without even trying to contribute to open source codes. =) |
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’m not sure I quite understand what you are trying to do here now
|
||
enum GotoLabelIndentation { | ||
GLI_None, // Do not indent goto labels. | ||
GLI_Indent, // Indent goto labels at the same level as the surrounding code. |
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.
Now I’m confused where did the half indent go?
IO.enumCase(Value, "HalfIndent", FormatStyle::GLI_HalfIndent); | ||
} | ||
}; | ||
|
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.
Ok this should have been in addition to what you had before not instead of
@@ -161,7 +171,8 @@ TEST(ConfigParseTest, ParsesConfigurationBools) { | |||
CHECK_PARSE_BOOL(IndentAccessModifiers); | |||
CHECK_PARSE_BOOL(IndentCaseLabels); | |||
CHECK_PARSE_BOOL(IndentCaseBlocks); | |||
CHECK_PARSE_BOOL(IndentGotoLabels); | |||
CHECK_PARSE_ENUM(IndentGotoLabels, |
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 want you to also test the actual usage of your option
The basics
The details
Resolves
Proposed Changes
Add a clang format style options for the
goto
to get the proper desired output.Behavior Before Change
Our handling of
goto
labels isn't ideal, as often we are not getting the desired output and missing out the proper indentation for the got label.Behavior After Change
The user will have three options to determine how they want their
goto
labels to be formatted with the 3 available options-Test Coverage
I haven't tested this, as soon as I got confirmation that these are the required changes that will update the status of the Test Coverage.
Documentation
Documentation needs to be done for this as it's a feature request. Once this will pass all the test cases I will add the required document for this.
Additional Information