[PATCH] D114724: [clangd][StdSymbolMap] Prefer std::remove from algorithm

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 29 10:22:04 PST 2021

kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

std::remove from algorithm is a lot more common than the overload from
the cstdio (which deletes files). This patch introduces a set of symbols
for which we should prefer the overloaded versions.

  rG LLVM Github Monorepo



Index: clang-tools-extra/clangd/include-mapping/cppreference_parser.py
--- clang-tools-extra/clangd/include-mapping/cppreference_parser.py
+++ clang-tools-extra/clangd/include-mapping/cppreference_parser.py
@@ -116,7 +116,7 @@
     return _ParseSymbolPage(f.read(), name)
-def _GetSymbols(pool, root_dir, index_page_name, namespace):
+def _GetSymbols(pool, root_dir, index_page_name, namespace, variants_to_accept):
   """Get all symbols listed in the index page. All symbols should be in the
   given namespace.
@@ -135,7 +135,7 @@
     for symbol_name, symbol_page_path, variant in _ParseIndexPage(f.read()):
       # Variant symbols (e.g. the std::locale version of isalpha) add ambiguity.
       # FIXME: use these as a fallback rather than ignoring entirely.
-      if variant:
+      if variant != (namespace+symbol_name in variants_to_accept):
       path = os.path.join(root_dir, symbol_page_path)
@@ -158,6 +158,10 @@
     parse_pages: a list of tuples (page_root_dir, index_page_name, namespace)
+  # By default we prefer the non-variant versions, as they're more common. But
+  # there are some symbols, whose variant is more common. This list describes
+  # those symbols.
+  variants_to_accept = set(["std::remove"])
   symbols = []
   # Run many workers to process individual symbol pages under the symbol index.
   # Don't allow workers to capture Ctrl-C.
@@ -165,7 +169,8 @@
       initializer=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN))
     for root_dir, page_name, namespace in parse_pages:
-      symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace))
+      symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace,
+                                 variants_to_accept))
Index: clang-tools-extra/clangd/StdSymbolMap.inc
--- clang-tools-extra/clangd/StdSymbolMap.inc
+++ clang-tools-extra/clangd/StdSymbolMap.inc
@@ -955,7 +955,7 @@
 SYMBOL(regex_traits, std::, <regex>)
 SYMBOL(reinterpret_pointer_cast, std::, <memory>)
 SYMBOL(remainder, std::, <cmath>)
-SYMBOL(remove, std::, <cstdio>)
+SYMBOL(remove, std::, <algorithm>)
 SYMBOL(remove_all_extents, std::, <type_traits>)
 SYMBOL(remove_all_extents_t, std::, <type_traits>)
 SYMBOL(remove_const, std::, <type_traits>)
Index: clang-tools-extra/clangd/CSymbolMap.inc
--- clang-tools-extra/clangd/CSymbolMap.inc
+++ clang-tools-extra/clangd/CSymbolMap.inc
@@ -698,7 +698,6 @@
 SYMBOL(remainder, None, <math.h>)
 SYMBOL(remainderf, None, <math.h>)
 SYMBOL(remainderl, None, <math.h>)
-SYMBOL(remove, None, <stdio.h>)
 SYMBOL(remquo, None, <math.h>)
 SYMBOL(remquof, None, <math.h>)
 SYMBOL(remquol, None, <math.h>)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114724.390405.patch
Type: text/x-patch
Size: 2952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211129/f4fd1995/attachment.bin>

More information about the cfe-commits mailing list