aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2019-05-02 09:31:24 +0000
committerSam McCall <sam.mccall@gmail.com>2019-05-02 09:31:24 +0000
commit7e7f22616a7502599d0ac0966aaf2bce9891ad0b (patch)
tree323f55948331f71bf667962a46f6767f80936094
parent751390fed3acfb505bcdac365797ec894dde862f (diff)
[clangd] Standard library mapping: prefer "primary" versions of functions over variants.
Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61349 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@359770 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--clangd/StdSymbolMap.inc34
-rwxr-xr-xclangd/include-mapping/gen_std.py18
-rwxr-xr-xclangd/include-mapping/test.py11
3 files changed, 54 insertions, 9 deletions
diff --git a/clangd/StdSymbolMap.inc b/clangd/StdSymbolMap.inc
index 71161636..c4a4c1f4 100644
--- a/clangd/StdSymbolMap.inc
+++ b/clangd/StdSymbolMap.inc
@@ -42,6 +42,8 @@ SYMBOL(UniformRandomBitGenerator, std::, <random>)
SYMBOL(UnsignedIntegral, std::, <concepts>)
SYMBOL(_Exit, std::, <cstdlib>)
SYMBOL(accumulate, std::, <numeric>)
+SYMBOL(acos, std::, <cmath>)
+SYMBOL(acosh, std::, <cmath>)
SYMBOL(add_const, std::, <type_traits>)
SYMBOL(add_const_t, std::, <type_traits>)
SYMBOL(add_cv, std::, <type_traits>)
@@ -82,8 +84,13 @@ SYMBOL(arg, std::, <complex>)
SYMBOL(array, std::, <array>)
SYMBOL(as_const, std::, <utility>)
SYMBOL(asctime, std::, <ctime>)
+SYMBOL(asin, std::, <cmath>)
+SYMBOL(asinh, std::, <cmath>)
SYMBOL(async, std::, <future>)
SYMBOL(at_quick_exit, std::, <cstdlib>)
+SYMBOL(atan, std::, <cmath>)
+SYMBOL(atan2, std::, <cmath>)
+SYMBOL(atanh, std::, <cmath>)
SYMBOL(atexit, std::, <cstdlib>)
SYMBOL(atof, std::, <cstdlib>)
SYMBOL(atoi, std::, <cstdlib>)
@@ -220,6 +227,8 @@ SYMBOL(copy_backward, std::, <algorithm>)
SYMBOL(copy_if, std::, <algorithm>)
SYMBOL(copy_n, std::, <algorithm>)
SYMBOL(copysign, std::, <cmath>)
+SYMBOL(cos, std::, <cmath>)
+SYMBOL(cosh, std::, <cmath>)
SYMBOL(count, std::, <algorithm>)
SYMBOL(count_if, std::, <algorithm>)
SYMBOL(cout, std::, <iostream>)
@@ -292,6 +301,7 @@ SYMBOL(exception_ptr, std::, <exception>)
SYMBOL(exchange, std::, <utility>)
SYMBOL(exclusive_scan, std::, <numeric>)
SYMBOL(exit, std::, <cstdlib>)
+SYMBOL(exp, std::, <cmath>)
SYMBOL(exp2, std::, <cmath>)
SYMBOL(expm1, std::, <cmath>)
SYMBOL(exponential_distribution, std::, <random>)
@@ -609,20 +619,31 @@ SYMBOL(is_void, std::, <type_traits>)
SYMBOL(is_void_v, std::, <type_traits>)
SYMBOL(is_volatile, std::, <type_traits>)
SYMBOL(is_volatile_v, std::, <type_traits>)
+SYMBOL(isalnum, std::, <cctype>)
+SYMBOL(isalpha, std::, <cctype>)
+SYMBOL(isblank, std::, <cctype>)
+SYMBOL(iscntrl, std::, <cctype>)
+SYMBOL(isdigit, std::, <cctype>)
SYMBOL(isfinite, std::, <cmath>)
+SYMBOL(isgraph, std::, <cctype>)
SYMBOL(isgreater, std::, <cmath>)
SYMBOL(isgreaterequal, std::, <cmath>)
SYMBOL(isinf, std::, <cmath>)
SYMBOL(isless, std::, <cmath>)
SYMBOL(islessequal, std::, <cmath>)
SYMBOL(islessgreater, std::, <cmath>)
+SYMBOL(islower, std::, <cctype>)
SYMBOL(isnan, std::, <cmath>)
SYMBOL(isnormal, std::, <cmath>)
SYMBOL(ispow2, std::, <bit>)
+SYMBOL(isprint, std::, <cctype>)
+SYMBOL(ispunct, std::, <cctype>)
+SYMBOL(isspace, std::, <cctype>)
SYMBOL(istream_iterator, std::, <iterator>)
SYMBOL(istreambuf_iterator, std::, <iterator>)
SYMBOL(istringstream, std::, <sstream>)
SYMBOL(isunordered, std::, <cmath>)
+SYMBOL(isupper, std::, <cctype>)
SYMBOL(iswalnum, std::, <cwctype>)
SYMBOL(iswalpha, std::, <cwctype>)
SYMBOL(iswblank, std::, <cwctype>)
@@ -636,6 +657,7 @@ SYMBOL(iswpunct, std::, <cwctype>)
SYMBOL(iswspace, std::, <cwctype>)
SYMBOL(iswupper, std::, <cwctype>)
SYMBOL(iswxdigit, std::, <cwctype>)
+SYMBOL(isxdigit, std::, <cctype>)
SYMBOL(iter_swap, std::, <algorithm>)
SYMBOL(iterator, std::, <iterator>)
SYMBOL(iterator_traits, std::, <iterator>)
@@ -663,6 +685,8 @@ SYMBOL(localeconv, std::, <clocale>)
SYMBOL(localtime, std::, <ctime>)
SYMBOL(lock, std::, <mutex>)
SYMBOL(lock_guard, std::, <mutex>)
+SYMBOL(log, std::, <cmath>)
+SYMBOL(log10, std::, <cmath>)
SYMBOL(log1p, std::, <cmath>)
SYMBOL(log2, std::, <cmath>)
SYMBOL(log2p1, std::, <bit>)
@@ -824,6 +848,7 @@ SYMBOL(poisson_distribution, std::, <random>)
SYMBOL(polar, std::, <complex>)
SYMBOL(polymorphic_allocator, std::, <memory_resource>)
SYMBOL(pop_heap, std::, <algorithm>)
+SYMBOL(pow, std::, <cmath>)
SYMBOL(prev, std::, <iterator>)
SYMBOL(prev_permutation, std::, <algorithm>)
SYMBOL(printf, std::, <cstdio>)
@@ -886,6 +911,7 @@ SYMBOL(regex_token_iterator, std::, <regex>)
SYMBOL(regex_traits, std::, <regex>)
SYMBOL(reinterpret_pointer_cast, std::, <memory>)
SYMBOL(remainder, std::, <cmath>)
+SYMBOL(remove, std::, <cstdio>)
SYMBOL(remove_all_extents, std::, <type_traits>)
SYMBOL(remove_all_extents_t, std::, <type_traits>)
SYMBOL(remove_const, std::, <type_traits>)
@@ -970,6 +996,8 @@ SYMBOL(shuffle_order_engine, std::, <random>)
SYMBOL(sig_atomic_t, std::, <csignal>)
SYMBOL(signal, std::, <csignal>)
SYMBOL(signbit, std::, <cmath>)
+SYMBOL(sin, std::, <cmath>)
+SYMBOL(sinh, std::, <cmath>)
SYMBOL(size, std::, <iterator>)
SYMBOL(skipws, std::, <ios>)
SYMBOL(slice, std::, <valarray>)
@@ -980,6 +1008,7 @@ SYMBOL(sort, std::, <algorithm>)
SYMBOL(sort_heap, std::, <algorithm>)
SYMBOL(span, std::, <span>)
SYMBOL(sprintf, std::, <cstdio>)
+SYMBOL(sqrt, std::, <cmath>)
SYMBOL(srand, std::, <cstdlib>)
SYMBOL(sregex_iterator, std::, <regex>)
SYMBOL(sregex_token_iterator, std::, <regex>)
@@ -1038,6 +1067,8 @@ SYMBOL(syncbuf, std::, <syncstream>)
SYMBOL(system, std::, <cstdlib>)
SYMBOL(system_category, std::, <system_error>)
SYMBOL(system_error, std::, <system_error>)
+SYMBOL(tan, std::, <cmath>)
+SYMBOL(tanh, std::, <cmath>)
SYMBOL(tera, std::, <ratio>)
SYMBOL(terminate, std::, <exception>)
SYMBOL(terminate_handler, std::, <exception>)
@@ -1062,6 +1093,8 @@ SYMBOL(to_address, std::, <memory>)
SYMBOL(to_chars, std::, <charconv>)
SYMBOL(to_integer, std::, <cstddef>)
SYMBOL(to_string, std::, <string>)
+SYMBOL(tolower, std::, <cctype>)
+SYMBOL(toupper, std::, <cctype>)
SYMBOL(towctrans, std::, <cwctype>)
SYMBOL(towlower, std::, <cwctype>)
SYMBOL(towupper, std::, <cwctype>)
@@ -1118,6 +1151,7 @@ SYMBOL(unordered_set, std::, <unordered_set>)
SYMBOL(upper_bound, std::, <algorithm>)
SYMBOL(uppercase, std::, <ios>)
SYMBOL(use_facet, std::, <locale>)
+SYMBOL(uses_allocator, std::, <memory>)
SYMBOL(uses_allocator_v, std::, <memory>)
SYMBOL(va_list, std::, <cstdarg>)
SYMBOL(valarray, std::, <valarray>)
diff --git a/clangd/include-mapping/gen_std.py b/clangd/include-mapping/gen_std.py
index 2cca2cfd..7e0e1966 100755
--- a/clangd/include-mapping/gen_std.py
+++ b/clangd/include-mapping/gen_std.py
@@ -28,7 +28,7 @@ Usage:
gen_std.py -cppreference </cppreference/reference> > StdSymbolMap.inc
"""
-from bs4 import BeautifulSoup
+from bs4 import BeautifulSoup, NavigableString
import argparse
import collections
@@ -82,15 +82,21 @@ def ParseIndexPage(index_page_html):
<a href="abs.html" title="abs"><tt>abs()</tt></a> (int) <br>
<a href="acos.html" title="acos"><tt>acos()</tt></a> <br>
- Returns a list of tuple (symbol_name, relative_path_to_symbol_page).
+ Returns a list of tuple (symbol_name, relative_path_to_symbol_page, variant).
"""
symbols = []
soup = BeautifulSoup(index_page_html, "html.parser")
for symbol_href in soup.select("a[title]"):
+ # Ignore annotated symbols like "acos<>() (std::complex)".
+ # These tend to be overloads, and we the primary is more useful.
+ # This accidentally accepts begin/end despite the (iterator) caption: the
+ # (since C++11) note is first. They are good symbols, so the bug is unfixed.
+ caption = symbol_href.next_sibling
+ variant = isinstance(caption, NavigableString) and "(" in caption
symbol_tt = symbol_href.find("tt")
if symbol_tt:
symbols.append((symbol_tt.text.rstrip("<>()"), # strip any trailing <>()
- symbol_href["href"]))
+ symbol_href["href"], variant))
return symbols
class Symbol:
@@ -125,7 +131,11 @@ def GetSymbols(pool, root_dir, index_page_name, namespace):
with open(index_page_path, "r") as f:
# Read each symbol page in parallel.
results = [] # (symbol_name, promise of [header...])
- for symbol_name, symbol_page_path in ParseIndexPage(f.read()):
+ 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:
+ continue
path = os.path.join(root_dir, symbol_page_path)
results.append((symbol_name,
pool.apply_async(ReadSymbolPage, (path, symbol_name))))
diff --git a/clangd/include-mapping/test.py b/clangd/include-mapping/test.py
index 89fa3591..742bfda3 100755
--- a/clangd/include-mapping/test.py
+++ b/clangd/include-mapping/test.py
@@ -24,16 +24,17 @@ class TestStdGen(unittest.TestCase):
actual = ParseIndexPage(html)
expected = [
- ("abs", "abs.html"),
- ("abs", "complex/abs.html"),
- ("acos", "acos.html"),
- ("acosh", "acosh.html"),
- ("as_bytes", "as_bytes.html"),
+ ("abs", "abs.html", True),
+ ("abs", "complex/abs.html", True),
+ ("acos", "acos.html", False),
+ ("acosh", "acosh.html", False),
+ ("as_bytes", "as_bytes.html", False),
]
self.assertEqual(len(actual), len(expected))
for i in range(0, len(actual)):
self.assertEqual(expected[i][0], actual[i][0])
self.assertTrue(actual[i][1].endswith(expected[i][1]))
+ self.assertEqual(expected[i][2], actual[i][2])
def testParseSymbolPage_SingleHeader(self):