[clang] 93fcc80 - [clang-format] Skip token annotation in passes that don't need it

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 18 11:20:41 PDT 2022


Author: owenca
Date: 2022-09-18T11:19:40-07:00
New Revision: 93fcc80d1ceba3a28f1aff402a91e1a427e66688

URL: https://github.com/llvm/llvm-project/commit/93fcc80d1ceba3a28f1aff402a91e1a427e66688
DIFF: https://github.com/llvm/llvm-project/commit/93fcc80d1ceba3a28f1aff402a91e1a427e66688.diff

LOG: [clang-format] Skip token annotation in passes that don't need it

Differential Revision: https://reviews.llvm.org/D134103

Added: 
    

Modified: 
    clang/lib/Format/Format.cpp
    clang/lib/Format/TokenAnalyzer.cpp
    clang/lib/Format/TokenAnalyzer.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 8197fccd2f3e3..0327a7ccb22ea 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3273,13 +3273,13 @@ reformat(const FormatStyle &Style, StringRef Code,
 
     if (Style.InsertBraces) {
       Passes.emplace_back([&](const Environment &Env) {
-        return BracesInserter(Env, Expanded).process();
+        return BracesInserter(Env, Expanded).process(/*SkipAnnotation=*/true);
       });
     }
 
     if (Style.RemoveBracesLLVM) {
       Passes.emplace_back([&](const Environment &Env) {
-        return BracesRemover(Env, Expanded).process();
+        return BracesRemover(Env, Expanded).process(/*SkipAnnotation=*/true);
       });
     }
 
@@ -3305,7 +3305,7 @@ reformat(const FormatStyle &Style, StringRef Code,
   if (Style.isJavaScript() &&
       Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) {
     Passes.emplace_back([&](const Environment &Env) {
-      return JavaScriptRequoter(Env, Expanded).process();
+      return JavaScriptRequoter(Env, Expanded).process(/*SkipAnnotation=*/true);
     });
   }
 

diff  --git a/clang/lib/Format/TokenAnalyzer.cpp b/clang/lib/Format/TokenAnalyzer.cpp
index 0a775c0a87eda..77e403581a0d5 100644
--- a/clang/lib/Format/TokenAnalyzer.cpp
+++ b/clang/lib/Format/TokenAnalyzer.cpp
@@ -97,7 +97,8 @@ TokenAnalyzer::TokenAnalyzer(const Environment &Env, const FormatStyle &Style)
                           << "\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 @@ std::pair<tooling::Replacements, unsigned> TokenAnalyzer::process() {
     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 =

diff  --git a/clang/lib/Format/TokenAnalyzer.h b/clang/lib/Format/TokenAnalyzer.h
index aaca518df41f3..e5cc1287c6167 100644
--- a/clang/lib/Format/TokenAnalyzer.h
+++ b/clang/lib/Format/TokenAnalyzer.h
@@ -89,7 +89,8 @@ class TokenAnalyzer : public UnwrappedLineConsumer {
 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>


        


More information about the cfe-commits mailing list