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

[clang-format] modified goto bool to enum #65140

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

varshneydevansh
Copy link

The basics

  • I branched from the main
  • My pull request is against main
  • My code follows the llvm Style Guide

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-

  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.
  };

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

@varshneydevansh
Copy link
Author

What am I Missing here?

@tbaederr tbaederr changed the title [clang] modified goto bool to enum [clang-format] modified goto bool to enum Sep 1, 2023
Copy link
Contributor

@mydeveloperday mydeveloperday left a 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);
}
};

Copy link
Contributor

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);

Copy link
Author

Choose a reason for hiding this comment

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

working on it

Copy link
Contributor

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 Show resolved Hide resolved
@@ -2432,9 +2431,25 @@ struct FormatStyle {
/// label2: label2:
/// return 1; return 1;
/// } }
///
/// GLI_HalfIndent:
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

#24492 (comment)

#24492 (comment)

I added this based on the above two

clang/include/clang/Format/Format.h Outdated Show resolved Hide resolved
@mydeveloperday
Copy link
Contributor

mydeveloperday commented Sep 1, 2023

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.

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.

@mydeveloperday mydeveloperday added the enhancement Improving things as opposed to bug fixing, e.g. new or missing feature label Sep 1, 2023
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.
Copy link
Contributor

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?
        }
      }
    }
  }
}

Copy link
Author

Choose a reason for hiding this comment

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

doing it

Copy link
Author

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

Copy link
Author

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

@varshneydevansh varshneydevansh requested review from a team as code owners September 4, 2023 16:27
Copy link
Contributor

@HazardyKnusperkeks HazardyKnusperkeks left a 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,
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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:
Copy link
Contributor

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.

Copy link
Author

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.
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

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.

@varshneydevansh
Copy link
Author

Do you actually want to use that feature, or do you only want to work on something?

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. =)

Copy link
Contributor

@mydeveloperday mydeveloperday left a 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.
Copy link
Contributor

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);
}
};

Copy link
Contributor

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,
Copy link
Contributor

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

@owenca owenca removed the enhancement Improving things as opposed to bug fixing, e.g. new or missing feature label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proper indention for goto destination point
5 participants