[PATCH] D118109: [clang] Replace `std::vector<bool>` use in Syntax

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 25 01:21:03 PST 2022


jansvoboda11 created this revision.
jansvoboda11 added a reviewer: dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

LLVM Programmer’s Manual strongly discourages the use of `std::vector<bool>` and suggests `llvm::BitVector` as a possible replacement.

This patch replaces `std::vector<bool>` with `llvm::BitVector` in the Format library and replaces range-based for loop with regular for loop. This is necessary due to `llvm::BitVector` not having `begin()` and `end()` (D117116 <https://reviews.llvm.org/D117116>).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118109

Files:
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===================================================================
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include <cassert>
@@ -202,7 +203,7 @@
 }
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
-                     const SourceManager &SM, std::vector<bool> IndentMask) {
+                     const SourceManager &SM, llvm::BitVector IndentMask) {
   auto DumpExtraInfo = [&OS](const syntax::Node *N) {
     if (N->getRole() != syntax::NodeRole::Unknown)
       OS << " " << N->getRole();
@@ -228,8 +229,8 @@
   OS << "\n";
 
   for (const syntax::Node &It : T->getChildren()) {
-    for (bool Filled : IndentMask) {
-      if (Filled)
+    for (unsigned Idx = 0; Idx < IndentMask.size(); ++Idx) {
+      if (IndentMask[Idx])
         OS << "| ";
       else
         OS << "  ";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118109.402793.patch
Type: text/x-patch
Size: 1107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220125/4472e710/attachment.bin>


More information about the cfe-commits mailing list