aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2025-01-04 16:22:54 -0800
committerGitHub <noreply@github.com>2025-01-04 16:22:54 -0800
commit44b83e81b5a48d543bf718907f00a21179ec03a4 (patch)
tree3e48eabff52616ea3ce37151d3eeb40dc79aa0e7 /clang/lib/Format/UnwrappedLineParser.cpp
parent04610b901f41c4abec169b9a38f1b0a2fde976c1 (diff)
downloadllvm-44b83e81b5a48d543bf718907f00a21179ec03a4.zip
llvm-44b83e81b5a48d543bf718907f00a21179ec03a4.tar.gz
llvm-44b83e81b5a48d543bf718907f00a21179ec03a4.tar.bz2
[clang-format] Add TT_AfterPPDirective for better annotation (#121622)
For now, we only need to annotate the token after #error or #warning. Fixes #117706.
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 5375eef..46fd566 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1030,6 +1030,12 @@ void UnwrappedLineParser::parsePPDirective() {
case tok::pp_pragma:
parsePPPragma();
break;
+ case tok::pp_error:
+ case tok::pp_warning:
+ nextToken();
+ if (!eof() && Style.isCpp())
+ FormatTok->setFinalizedType(TT_AfterPPDirective);
+ [[fallthrough]];
default:
parsePPUnknown();
break;
@@ -1209,9 +1215,8 @@ void UnwrappedLineParser::parsePPPragma() {
}
void UnwrappedLineParser::parsePPUnknown() {
- do {
+ while (!eof())
nextToken();
- } while (!eof());
if (Style.IndentPPDirectives != FormatStyle::PPDIS_None)
Line->Level += PPBranchLevel + 1;
addUnwrappedLine();