owenpan created this revision. owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, curdeius. owenpan added a project: clang-format. Herald added a project: All. owenpan requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D134103 Files: clang/lib/Format/Format.cpp clang/lib/Format/TokenAnalyzer.cpp clang/lib/Format/TokenAnalyzer.h Index: clang/lib/Format/TokenAnalyzer.h =================================================================== --- clang/lib/Format/TokenAnalyzer.h +++ clang/lib/Format/TokenAnalyzer.h @@ -89,7 +89,8 @@ public: TokenAnalyzer(const Environment &Env, const FormatStyle &Style); - std::pair<tooling::Replacements, unsigned> process(); + std::pair<tooling::Replacements, unsigned> + process(bool SkipAnnotation = false); protected: virtual std::pair<tooling::Replacements, unsigned> Index: clang/lib/Format/TokenAnalyzer.cpp =================================================================== --- clang/lib/Format/TokenAnalyzer.cpp +++ clang/lib/Format/TokenAnalyzer.cpp @@ -97,7 +97,8 @@ << "\n"); } -std::pair<tooling::Replacements, unsigned> TokenAnalyzer::process() { +std::pair<tooling::Replacements, unsigned> +TokenAnalyzer::process(bool SkipAnnotation) { tooling::Replacements Result; llvm::SpecificBumpPtrAllocator<FormatToken> Allocator; IdentifierTable IdentTable(getFormattingLangOpts(Style)); @@ -121,7 +122,8 @@ TokenAnnotator Annotator(Style, Lex.getKeywords()); for (const UnwrappedLine &Line : Lines) { AnnotatedLines.push_back(new AnnotatedLine(Line)); - Annotator.annotate(*AnnotatedLines.back()); + if (!SkipAnnotation) + Annotator.annotate(*AnnotatedLines.back()); } std::pair<tooling::Replacements, unsigned> RunResult = Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -3273,13 +3273,13 @@ if (Style.InsertBraces) { Passes.emplace_back([&](const Environment &Env) { - return BracesInserter(Env, Expanded).process(); + return BracesInserter(Env, Expanded).process(/*SkipsAnnotation=*/true); }); } if (Style.RemoveBracesLLVM) { Passes.emplace_back([&](const Environment &Env) { - return BracesRemover(Env, Expanded).process(); + return BracesRemover(Env, Expanded).process(/*SkipsAnnotation=*/true); }); } @@ -3305,7 +3305,8 @@ if (Style.isJavaScript() && Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) { Passes.emplace_back([&](const Environment &Env) { - return JavaScriptRequoter(Env, Expanded).process(); + return JavaScriptRequoter(Env, Expanded) + .process(/*SkipsAnnotation=*/true); }); }
Index: clang/lib/Format/TokenAnalyzer.h =================================================================== --- clang/lib/Format/TokenAnalyzer.h +++ clang/lib/Format/TokenAnalyzer.h @@ -89,7 +89,8 @@ public: TokenAnalyzer(const Environment &Env, const FormatStyle &Style); - std::pair<tooling::Replacements, unsigned> process(); + std::pair<tooling::Replacements, unsigned> + process(bool SkipAnnotation = false); protected: virtual std::pair<tooling::Replacements, unsigned> Index: clang/lib/Format/TokenAnalyzer.cpp =================================================================== --- clang/lib/Format/TokenAnalyzer.cpp +++ clang/lib/Format/TokenAnalyzer.cpp @@ -97,7 +97,8 @@ << "\n"); } -std::pair<tooling::Replacements, unsigned> TokenAnalyzer::process() { +std::pair<tooling::Replacements, unsigned> +TokenAnalyzer::process(bool SkipAnnotation) { tooling::Replacements Result; llvm::SpecificBumpPtrAllocator<FormatToken> Allocator; IdentifierTable IdentTable(getFormattingLangOpts(Style)); @@ -121,7 +122,8 @@ TokenAnnotator Annotator(Style, Lex.getKeywords()); for (const UnwrappedLine &Line : Lines) { AnnotatedLines.push_back(new AnnotatedLine(Line)); - Annotator.annotate(*AnnotatedLines.back()); + if (!SkipAnnotation) + Annotator.annotate(*AnnotatedLines.back()); } std::pair<tooling::Replacements, unsigned> RunResult = Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -3273,13 +3273,13 @@ if (Style.InsertBraces) { Passes.emplace_back([&](const Environment &Env) { - return BracesInserter(Env, Expanded).process(); + return BracesInserter(Env, Expanded).process(/*SkipsAnnotation=*/true); }); } if (Style.RemoveBracesLLVM) { Passes.emplace_back([&](const Environment &Env) { - return BracesRemover(Env, Expanded).process(); + return BracesRemover(Env, Expanded).process(/*SkipsAnnotation=*/true); }); } @@ -3305,7 +3305,8 @@ if (Style.isJavaScript() && Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) { Passes.emplace_back([&](const Environment &Env) { - return JavaScriptRequoter(Env, Expanded).process(); + return JavaScriptRequoter(Env, Expanded) + .process(/*SkipsAnnotation=*/true); }); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits