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] IncludeCategories: Add a regex group named main into the Regex Solver #60586

Open
Febbe opened this issue Feb 7, 2023 · 1 comment
Labels
clang-format enhancement Improving things as opposed to bug fixing, e.g. new or missing feature

Comments

@Febbe
Copy link
Contributor

Febbe commented Feb 7, 2023

There are many issues, regarding main file sorting.
Also, we have the issue, that a main source file can have 2 main headers, e.g. a.cpp a.h and a_priv.h

With IncludeIsMainRegex and IncludeIsMainSourceRegex only a mapping between a header to a source can be defined, but not the other way round.

A solution to all issues would be, to add a parameter in the form of a named capture group to the regex.
For example, a hypothetical group definition (?<main>regex) would map to \k<main>, which then maps to the main file's stem.

IncludeCategories:
  - Regex:           '\k<main>_priv\.h"$'
    Priority:        0

The above would then match a_priv.h as expected.
With that, programmers could also override the default behavior, to accomplish:

#58284
#37620 #39735 #53013

Possible implementation could be:

  • generate all possible main-header stems from IncludeIsMainRegex and IncludeIsMainSourceRegex
  • supply all (including the original stem) to the Regex solver as group (do this in a loop, if it's not possible to accomplish this via one group)
@llvmbot
Copy link
Member

llvmbot commented Feb 7, 2023

@llvm/issue-subscribers-clang-format

@rymiel rymiel added the enhancement Improving things as opposed to bug fixing, e.g. new or missing feature label Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format enhancement Improving things as opposed to bug fixing, e.g. new or missing feature
Projects
None yet
Development

No branches or pull requests

4 participants