kwk created this revision. kwk added a reviewer: FederAndInk. kwk requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
If there was this enum definition before: struct FormatStyle { //... /// Different styles for aligning after open brackets. enum WhateverStyle : unsigned char { /// Foo WS_Bar = 5 }; }; We would output the following in `clang/docs/ClangFormatStyleOptions.rst` when running `cd ~/llvm-project/clang/docs/tools && ./dump_format_style.py`: * ``WS_Bar = 5`` (in configuration: ``Bar = 5``) Foo. With this patch, we change it to something that looks more like what we are accustomed to: * ``WS_Bar`` (in configuration: ``Bar``) Foo. This is a theoretical change because we don't have format style enums that currently explicitly select a value. But while I was doing some research on how to extend the `FormatStyle` I noticed this behavior and thought it would make a small change. You can experiment with and without this change by simply running `dump_format_style.py` while setting `AIAS_Left` to `AIAS_Left = 0` in `clang/include/clang/Format/Format.h`. Without this change in `Format.h` you shouldn't see any change being made to `clang/docs/ClangFormatStyleOptions.rst`. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D120712 Files: clang/docs/tools/dump_format_style.py Index: clang/docs/tools/dump_format_style.py =================================================================== --- clang/docs/tools/dump_format_style.py +++ clang/docs/tools/dump_format_style.py @@ -159,10 +159,20 @@ self.comment = comment self.config = config + @property + def clean_name(self) -> str: + # In case the enum value has an explicit value (e.g. enum foo {bar = 42};) + # we remove everything after the equal sign and just use "bar". + return self.name.split("=", 1)[0].strip() + + @property + def clean_config(self) -> str: + return re.sub('.*_', '', self.config).split("=", 1)[0].strip() + def __str__(self): return '* ``%s`` (in configuration: ``%s``)\n%s' % ( - self.name, - re.sub('.*_', '', self.config), + self.clean_name, + self.clean_config, doxygen2rst(indent(self.comment, 2)))
Index: clang/docs/tools/dump_format_style.py =================================================================== --- clang/docs/tools/dump_format_style.py +++ clang/docs/tools/dump_format_style.py @@ -159,10 +159,20 @@ self.comment = comment self.config = config + @property + def clean_name(self) -> str: + # In case the enum value has an explicit value (e.g. enum foo {bar = 42};) + # we remove everything after the equal sign and just use "bar". + return self.name.split("=", 1)[0].strip() + + @property + def clean_config(self) -> str: + return re.sub('.*_', '', self.config).split("=", 1)[0].strip() + def __str__(self): return '* ``%s`` (in configuration: ``%s``)\n%s' % ( - self.name, - re.sub('.*_', '', self.config), + self.clean_name, + self.clean_config, doxygen2rst(indent(self.comment, 2)))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits