aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
authorGedare Bloom <gedare@rtems.org>2025-09-14 14:47:06 -0600
committerGitHub <noreply@github.com>2025-09-14 13:47:06 -0700
commit7dd2f1cc10902e632c0c78c75a30432a53eb59dc (patch)
treef0fd3b24672aac4bce31b131b445e41e50d5cd0f /clang/lib/Format/ContinuationIndenter.cpp
parent43384913b636854b92c7de9e326f879a1993f445 (diff)
downloadllvm-7dd2f1cc10902e632c0c78c75a30432a53eb59dc.zip
llvm-7dd2f1cc10902e632c0c78c75a30432a53eb59dc.tar.gz
llvm-7dd2f1cc10902e632c0c78c75a30432a53eb59dc.tar.bz2
[clang-format] Add IndentPPDirectives Leave option (#139750)
Allow an option to leave preprocessor directive indenting as-is. This simplifies handling mixed styles of CPP directive indentation. Fixes #38511
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 888d0fa..9413c13 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -780,19 +780,21 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
// Indent preprocessor directives after the hash if required.
int PPColumnCorrection = 0;
- if (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash &&
- Previous.is(tok::hash) && State.FirstIndent > 0 &&
- &Previous == State.Line->First &&
+ if (&Previous == State.Line->First && Previous.is(tok::hash) &&
(State.Line->Type == LT_PreprocessorDirective ||
State.Line->Type == LT_ImportStatement)) {
- Spaces += State.FirstIndent;
-
- // For preprocessor indent with tabs, State.Column will be 1 because of the
- // hash. This causes second-level indents onward to have an extra space
- // after the tabs. We avoid this misalignment by subtracting 1 from the
- // column value passed to replaceWhitespace().
- if (Style.UseTab != FormatStyle::UT_Never)
- PPColumnCorrection = -1;
+ if (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash) {
+ Spaces += State.FirstIndent;
+
+ // For preprocessor indent with tabs, State.Column will be 1 because of
+ // the hash. This causes second-level indents onward to have an extra
+ // space after the tabs. We avoid this misalignment by subtracting 1 from
+ // the column value passed to replaceWhitespace().
+ if (Style.UseTab != FormatStyle::UT_Never)
+ PPColumnCorrection = -1;
+ } else if (Style.IndentPPDirectives == FormatStyle::PPDIS_Leave) {
+ Spaces += Current.OriginalColumn - Previous.OriginalColumn - 1;
+ }
}
if (!DryRun) {