[PATCH] D112019: [clang-format] [PR51412] AlignConsecutiveMacros fights with Visual Studio and resource.h
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 18 10:43:49 PDT 2021
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: curdeius, HazardyKnusperkeks, krasimir.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.
clang-format `AlignConsecutiveMacros` feature causes real problems when using Win32 resource.h files via the resource editor in Visual Studio when editing RC files.
VS produces the following for the resource.h files
...
// Microsoft Visual C++ generated include file.
// Used by MyTest.rc
//
#define IDP_OLE_INIT_FAILED 100
#define IDP_FAILED_TO_CREATE 102
#define ID_STATUSBAR_SHOW 108
#define ID_STATUSBAR_TEXT 109
Visual Studio generates a resource.h with Alignment macros which start at 40 characters, but `AlignConsecutiveMacros` will determine the starting point but assume a minimum of 0 meaning a clang-format will result in:
#define IDP_OLE_INIT_FAILED 100
#define IDP_FAILED_TO_CREATE 102
#define ID_STATUSBAR_SHOW 108
#define ID_STATUSBAR_TEXT 109
This is would be good until you make a new rc file change which results in VS writing out the resource.h (back in its own form) - (even clang-format VS plugin to format on save doesn't resolve this. The writing of resource.h seems outside of the normal save system)
This situation is made worse, if it encounters a long symbol, in the VS case it treats this as a one off, but clang-format will assume this is the new minimum.
#define IDP_OLE_INIT_FAILED 100
#define IDP_FAILED_TO_CREATE 102
#define ID_VERYVERYVERYVERY_LONG_LONG_LONG_LONG_RESOURCE 33221
#define ID_STATUSBAR_SHOW 108
#define ID_STATUSBAR_TEXT 109
and will become via clang-format
#define IDP_OLE_INIT_FAILED 100
#define IDP_FAILED_TO_CREATE 102
#define ID_VERYVERYVERYVERY_LONG_LONG_LONG_LONG_RESOURCE 33221
#define ID_STATUSBAR_SHOW 108
#define ID_STATUSBAR_TEXT 109
This patch contains 2 new options
1. Set the minimum to a fixed integer (which for VS should be 40), this means all id numbers will begin at 40
2. An option to allow very long macro names to break the Alignment, meaning the next line will reset back to the previous configured minimum (40 in our case)
These 2 option have functionality that could be useful on their own, however the goal is to allow `AlignConsecutiveMacros` to be useful for Windows Win32 developers and minimize the clang-format changes that the RC editor causes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D112019
Files:
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112019.380465.patch
Type: text/x-patch
Size: 9684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211018/a45c0d65/attachment.bin>
More information about the cfe-commits
mailing list