[clang-tools-extra] r359770 - [clangd] Standard library mapping: prefer "primary" versions of functions over variants.

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Thu May 2 02:31:24 PDT 2019


Author: sammccall
Date: Thu May  2 02:31:24 2019
New Revision: 359770

URL: http://llvm.org/viewvc/llvm-project?rev=359770&view=rev
Log:
[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

Modified:
    clang-tools-extra/trunk/clangd/StdSymbolMap.inc
    clang-tools-extra/trunk/clangd/include-mapping/gen_std.py
    clang-tools-extra/trunk/clangd/include-mapping/test.py

Modified: clang-tools-extra/trunk/clangd/StdSymbolMap.inc
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/StdSymbolMap.inc?rev=359770&r1=359769&r2=359770&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/StdSymbolMap.inc (original)
+++ clang-tools-extra/trunk/clangd/StdSymbolMap.inc Thu May  2 02:31:24 2019
@@ -42,6 +42,8 @@ SYMBOL(UniformRandomBitGenerator, std::,
 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::, <ran
 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::, <reg
 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::, <ran
 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_
 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>)

Modified: clang-tools-extra/trunk/clangd/include-mapping/gen_std.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/include-mapping/gen_std.py?rev=359770&r1=359769&r2=359770&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/include-mapping/gen_std.py (original)
+++ clang-tools-extra/trunk/clangd/include-mapping/gen_std.py Thu May  2 02:31:24 2019
@@ -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_pag
   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))))

Modified: clang-tools-extra/trunk/clangd/include-mapping/test.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/include-mapping/test.py?rev=359770&r1=359769&r2=359770&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/include-mapping/test.py (original)
+++ clang-tools-extra/trunk/clangd/include-mapping/test.py Thu May  2 02:31:24 2019
@@ -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):




More information about the cfe-commits mailing list