Skip to content

Commit c490f8f

Browse files
committed
[clangd][StdSymbolMap] Prefer std::remove from algorithm
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. Differential Revision: https://reviews.llvm.org/D114724
1 parent 0f85393 commit c490f8f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

clang-tools-extra/clangd/StdSymbolMap.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,6 @@ SYMBOL(regex_token_iterator, std::, <regex>)
955955
SYMBOL(regex_traits, std::, <regex>)
956956
SYMBOL(reinterpret_pointer_cast, std::, <memory>)
957957
SYMBOL(remainder, std::, <cmath>)
958-
SYMBOL(remove, std::, <cstdio>)
959958
SYMBOL(remove_all_extents, std::, <type_traits>)
960959
SYMBOL(remove_all_extents_t, std::, <type_traits>)
961960
SYMBOL(remove_const, std::, <type_traits>)

clang-tools-extra/clangd/include-mapping/cppreference_parser.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ def _ParseIndexPage(index_page_html):
103103
# This accidentally accepts begin/end despite the (iterator) caption: the
104104
# (since C++11) note is first. They are good symbols, so the bug is unfixed.
105105
caption = symbol_href.next_sibling
106-
variant = isinstance(caption, NavigableString) and "(" in caption
106+
variant = None
107+
if isinstance(caption, NavigableString) and "(" in caption:
108+
variant = caption.text.strip(" ()")
107109
symbol_tt = symbol_href.find("tt")
108110
if symbol_tt:
109111
symbols.append((symbol_tt.text.rstrip("<>()"), # strip any trailing <>()
@@ -116,7 +118,7 @@ def _ReadSymbolPage(path, name):
116118
return _ParseSymbolPage(f.read(), name)
117119

118120

119-
def _GetSymbols(pool, root_dir, index_page_name, namespace):
121+
def _GetSymbols(pool, root_dir, index_page_name, namespace, variants_to_accept):
120122
"""Get all symbols listed in the index page. All symbols should be in the
121123
given namespace.
122124
@@ -135,7 +137,9 @@ def _GetSymbols(pool, root_dir, index_page_name, namespace):
135137
for symbol_name, symbol_page_path, variant in _ParseIndexPage(f.read()):
136138
# Variant symbols (e.g. the std::locale version of isalpha) add ambiguity.
137139
# FIXME: use these as a fallback rather than ignoring entirely.
138-
if variant:
140+
variants_for_symbol = variants_to_accept.get(
141+
(namespace or "") + symbol_name, ())
142+
if variant and variant not in variants_for_symbol:
139143
continue
140144
path = os.path.join(root_dir, symbol_page_path)
141145
results.append((symbol_name,
@@ -158,14 +162,22 @@ def GetSymbols(parse_pages):
158162
Args:
159163
parse_pages: a list of tuples (page_root_dir, index_page_name, namespace)
160164
"""
165+
# By default we prefer the non-variant versions, as they're more common. But
166+
# there are some symbols, whose variant is more common. This list describes
167+
# those symbols.
168+
variants_to_accept = {
169+
# std::remove<> has variant algorithm.
170+
"std::remove": ("algorithm"),
171+
}
161172
symbols = []
162173
# Run many workers to process individual symbol pages under the symbol index.
163174
# Don't allow workers to capture Ctrl-C.
164175
pool = multiprocessing.Pool(
165176
initializer=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN))
166177
try:
167178
for root_dir, page_name, namespace in parse_pages:
168-
symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace))
179+
symbols.extend(_GetSymbols(pool, root_dir, page_name, namespace,
180+
variants_to_accept))
169181
finally:
170182
pool.terminate()
171183
pool.join()

0 commit comments

Comments
 (0)