sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Previously we were just jumping from the symbol index to the symbol page, and
grabbing all the headers mentioned there. But the page often lists multiple
symbols, and so we got false positives and thus ambiguities (which were 
dropped).

Now we look at which declarations are for the symbol we want, and prefer headers
listed above that symbol. If there are none, we fall back to the old behavior.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D61316

Files:
  clangd/StdSymbolMap.inc
  clangd/include-mapping/gen_std.py

Index: clangd/include-mapping/gen_std.py
===================================================================
--- clangd/include-mapping/gen_std.py
+++ clangd/include-mapping/gen_std.py
@@ -35,6 +35,7 @@
 import datetime
 import multiprocessing
 import os
+import re
 import signal
 import sys
 
@@ -50,7 +51,13 @@
 //===----------------------------------------------------------------------===//
 """
 
-def ParseSymbolPage(symbol_page_html):
+def HasClass(tag, *classes):
+  for c in tag.get('class', []):
+    if c in classes:
+      return True
+  return False
+
+def ParseSymbolPage(symbol_page_html, symbol_name):
   """Parse symbol page and retrieve the include header defined in this page.
   The symbol page provides header for the symbol, specifically in
   "Defined in header <header>" section. An example:
@@ -61,17 +68,38 @@
 
   Returns a list of headers.
   """
-  headers = []
+  headers = set()
+  all_headers = set()
 
   soup = BeautifulSoup(symbol_page_html, "html.parser")
-  #  "Defined in header " are defined in <tr class="t-dsc-header"> or
-  #  <tr class="t-dcl-header">.
-  for header_tr in soup.select('tr.t-dcl-header,tr.t-dsc-header'):
-    if "Defined in header " in header_tr.text:
-      # The interesting header content (e.g. <cstdlib>) is wrapped in <code>.
-      for header_code in header_tr.find_all("code"):
-        headers.append(header_code.text)
-  return headers
+  # Rows in table are like:
+  #   Defined in header <foo>      .t-dsc-header
+  #   Defined in header <bar>      .t-dsc-header
+  #   decl1                        .t-dcl
+  #   Defined in header <baz>      .t-dsc-header
+  #   decl2                        .t-dcl
+  for table in soup.select('table.t-dcl-begin, table.t-dsc-begin'):
+    current_headers = []
+    was_decl = False
+    for row in table.select('tr'):
+      if HasClass(row, 't-dcl', 't-dsc'):
+        was_decl = True
+        # Declaration is in the first cell.
+        text = row.find('td').text
+        # Decl may not be for the symbol name we're looking for.
+        if not re.search("\\b%s\\b" % symbol_name, text):
+          continue
+        headers.update(current_headers)
+      elif HasClass(row, 't-dsc-header'):
+        if was_decl:
+          current_headers = []
+        was_decl = False
+        # The interesting header content (e.g. <cstdlib>) is wrapped in <code>.
+        for header_code in row.find_all("code"):
+          current_headers.append(header_code.text)
+          all_headers.add(header_code.text)
+  # If the symbol was never named, consider all named headers.
+  return headers or all_headers
 
 
 def ParseIndexPage(index_page_html):
@@ -106,7 +134,7 @@
 
 def ReadSymbolPage(path, name):
   with open(path) as f:
-    return ParseSymbolPage(f.read())
+    return ParseSymbolPage(f.read(), name)
 
 
 def GetSymbols(pool, root_dir, index_page_name, namespace):
Index: clangd/StdSymbolMap.inc
===================================================================
--- clangd/StdSymbolMap.inc
+++ clangd/StdSymbolMap.inc
@@ -134,12 +134,15 @@
 SYMBOL(bad_variant_access, std::, <variant>)
 SYMBOL(bad_weak_ptr, std::, <memory>)
 SYMBOL(basic_common_reference, std::, <type_traits>)
+SYMBOL(basic_filebuf, std::, <fstream>)
 SYMBOL(basic_fstream, std::, <fstream>)
 SYMBOL(basic_ifstream, std::, <fstream>)
 SYMBOL(basic_ios, std::, <ios>)
 SYMBOL(basic_iostream, std::, <istream>)
+SYMBOL(basic_istream, std::, <istream>)
 SYMBOL(basic_istringstream, std::, <sstream>)
 SYMBOL(basic_ofstream, std::, <fstream>)
+SYMBOL(basic_ostream, std::, <ostream>)
 SYMBOL(basic_ostringstream, std::, <sstream>)
 SYMBOL(basic_osyncstream, std::, <syncstream>)
 SYMBOL(basic_regex, std::, <regex>)
@@ -193,6 +196,7 @@
 SYMBOL(codecvt, std::, <locale>)
 SYMBOL(codecvt_base, std::, <locale>)
 SYMBOL(codecvt_byname, std::, <locale>)
+SYMBOL(codecvt_mode, std::, <codecvt>)
 SYMBOL(codecvt_utf16, std::, <codecvt>)
 SYMBOL(codecvt_utf8, std::, <codecvt>)
 SYMBOL(codecvt_utf8_utf16, std::, <codecvt>)
@@ -245,6 +249,7 @@
 SYMBOL(declare_reachable, std::, <memory>)
 SYMBOL(declval, std::, <utility>)
 SYMBOL(default_delete, std::, <memory>)
+SYMBOL(default_random_engine, std::, <random>)
 SYMBOL(default_searcher, std::, <functional>)
 SYMBOL(defaultfloat, std::, <ios>)
 SYMBOL(defer_lock, std::, <mutex>)
@@ -264,8 +269,10 @@
 SYMBOL(disjunction, std::, <type_traits>)
 SYMBOL(disjunction_v, std::, <type_traits>)
 SYMBOL(distance, std::, <iterator>)
+SYMBOL(div_t, std::, <cstdlib>)
 SYMBOL(divides, std::, <functional>)
 SYMBOL(domain_error, std::, <stdexcept>)
+SYMBOL(double_t, std::, <cmath>)
 SYMBOL(dynamic_extent, std::, <span>)
 SYMBOL(dynamic_pointer_cast, std::, <memory>)
 SYMBOL(emit_on_flush, std::, <ostream>)
@@ -298,6 +305,7 @@
 SYMBOL(extent, std::, <type_traits>)
 SYMBOL(extent_v, std::, <type_traits>)
 SYMBOL(extreme_value_distribution, std::, <random>)
+SYMBOL(fabs, std::, <cmath>)
 SYMBOL(false_type, std::, <type_traits>)
 SYMBOL(fclose, std::, <cstdio>)
 SYMBOL(fdim, std::, <cmath>)
@@ -323,6 +331,7 @@
 SYMBOL(fgets, std::, <cstdio>)
 SYMBOL(fgetwc, std::, <cwchar>)
 SYMBOL(fgetws, std::, <cwchar>)
+SYMBOL(filebuf, std::, <streambuf>)
 SYMBOL(fill, std::, <algorithm>)
 SYMBOL(fill_n, std::, <algorithm>)
 SYMBOL(find, std::, <algorithm>)
@@ -334,6 +343,7 @@
 SYMBOL(fixed, std::, <ios>)
 SYMBOL(float_denorm_style, std::, <limits>)
 SYMBOL(float_round_style, std::, <limits>)
+SYMBOL(float_t, std::, <cmath>)
 SYMBOL(floor, std::, <cmath>)
 SYMBOL(floor2, std::, <bit>)
 SYMBOL(flush, std::, <ostream>)
@@ -422,6 +432,9 @@
 SYMBOL(ignore, std::, <tuple>)
 SYMBOL(ilogb, std::, <cmath>)
 SYMBOL(imag, std::, <complex>)
+SYMBOL(imaxabs, std::, <cinttypes>)
+SYMBOL(imaxdiv, std::, <cinttypes>)
+SYMBOL(imaxdiv_t, std::, <cinttypes>)
 SYMBOL(in_place, std::, <utility>)
 SYMBOL(in_place_index, std::, <utility>)
 SYMBOL(in_place_index_t, std::, <utility>)
@@ -440,6 +453,8 @@
 SYMBOL(integer_sequence, std::, <utility>)
 SYMBOL(integral_constant, std::, <type_traits>)
 SYMBOL(internal, std::, <ios>)
+SYMBOL(intmax_t, std::, <cstdint>)
+SYMBOL(intptr_t, std::, <cstdint>)
 SYMBOL(invalid_argument, std::, <stdexcept>)
 SYMBOL(invoke, std::, <functional>)
 SYMBOL(invoke_result, std::, <type_traits>)
@@ -619,6 +634,7 @@
 SYMBOL(isnan, std::, <cmath>)
 SYMBOL(isnormal, std::, <cmath>)
 SYMBOL(ispow2, std::, <bit>)
+SYMBOL(istream, std::, <istream>)
 SYMBOL(istream_iterator, std::, <iterator>)
 SYMBOL(istreambuf_iterator, std::, <iterator>)
 SYMBOL(istringstream, std::, <sstream>)
@@ -642,11 +658,15 @@
 SYMBOL(jmp_buf, std::, <csetjmp>)
 SYMBOL(kill_dependency, std::, <atomic>)
 SYMBOL(kilo, std::, <ratio>)
+SYMBOL(knuth_b, std::, <random>)
+SYMBOL(labs, std::, <cstdlib>)
 SYMBOL(launch, std::, <future>)
 SYMBOL(launder, std::, <new>)
 SYMBOL(lcm, std::, <numeric>)
 SYMBOL(lconv, std::, <clocale>)
 SYMBOL(ldexp, std::, <cmath>)
+SYMBOL(ldiv, std::, <cstdlib>)
+SYMBOL(ldiv_t, std::, <cstdlib>)
 SYMBOL(left, std::, <ios>)
 SYMBOL(length_error, std::, <stdexcept>)
 SYMBOL(less, std::, <functional>)
@@ -656,6 +676,9 @@
 SYMBOL(lgamma, std::, <cmath>)
 SYMBOL(linear_congruential_engine, std::, <random>)
 SYMBOL(list, std::, <list>)
+SYMBOL(llabs, std::, <cstdlib>)
+SYMBOL(lldiv, std::, <cstdlib>)
+SYMBOL(lldiv_t, std::, <cstdlib>)
 SYMBOL(llrint, std::, <cmath>)
 SYMBOL(llround, std::, <cmath>)
 SYMBOL(locale, std::, <locale>)
@@ -731,6 +754,8 @@
 SYMBOL(min_element, std::, <algorithm>)
 SYMBOL(minmax, std::, <algorithm>)
 SYMBOL(minmax_element, std::, <algorithm>)
+SYMBOL(minstd_rand, std::, <random>)
+SYMBOL(minstd_rand0, std::, <random>)
 SYMBOL(minus, std::, <functional>)
 SYMBOL(mismatch, std::, <algorithm>)
 SYMBOL(mktime, std::, <ctime>)
@@ -745,6 +770,8 @@
 SYMBOL(move_backward, std::, <algorithm>)
 SYMBOL(move_if_noexcept, std::, <utility>)
 SYMBOL(move_iterator, std::, <iterator>)
+SYMBOL(mt19937, std::, <random>)
+SYMBOL(mt19937_64, std::, <random>)
 SYMBOL(multimap, std::, <map>)
 SYMBOL(multiplies, std::, <functional>)
 SYMBOL(multiset, std::, <set>)
@@ -793,6 +820,7 @@
 SYMBOL(ofstream, std::, <fstream>)
 SYMBOL(once_flag, std::, <mutex>)
 SYMBOL(optional, std::, <optional>)
+SYMBOL(ostream, std::, <ostream>)
 SYMBOL(ostream_iterator, std::, <iterator>)
 SYMBOL(ostreambuf_iterator, std::, <iterator>)
 SYMBOL(ostringstream, std::, <sstream>)
@@ -851,6 +879,10 @@
 SYMBOL(range_error, std::, <stdexcept>)
 SYMBOL(rank, std::, <type_traits>)
 SYMBOL(rank_v, std::, <type_traits>)
+SYMBOL(ranlux24, std::, <random>)
+SYMBOL(ranlux24_base, std::, <random>)
+SYMBOL(ranlux48, std::, <random>)
+SYMBOL(ranlux48_base, std::, <random>)
 SYMBOL(ratio, std::, <ratio>)
 SYMBOL(ratio_add, std::, <ratio>)
 SYMBOL(ratio_divide, std::, <ratio>)
@@ -1086,6 +1118,8 @@
 SYMBOL(u32streampos, std::, <ios>)
 SYMBOL(u32string, std::, <string>)
 SYMBOL(u32string_view, std::, <string_view>)
+SYMBOL(uintmax_t, std::, <cstdint>)
+SYMBOL(uintptr_t, std::, <cstdint>)
 SYMBOL(uncaught_exceptions, std::, <exception>)
 SYMBOL(undeclare_no_pointers, std::, <memory>)
 SYMBOL(undeclare_reachable, std::, <memory>)
@@ -1184,17 +1218,21 @@
 SYMBOL(wctob, std::, <cwchar>)
 SYMBOL(wctomb, std::, <cstdlib>)
 SYMBOL(wctrans, std::, <cwctype>)
+SYMBOL(wctrans_t, std::, <cwctype>)
 SYMBOL(wctype, std::, <cwctype>)
+SYMBOL(wctype_t, std::, <cwctype>)
 SYMBOL(weak_equal, std::, <compare>)
 SYMBOL(weak_equality, std::, <compare>)
 SYMBOL(weak_order, std::, <compare>)
 SYMBOL(weak_ordering, std::, <compare>)
 SYMBOL(weak_ptr, std::, <memory>)
 SYMBOL(weibull_distribution, std::, <random>)
+SYMBOL(wfilebuf, std::, <streambuf>)
 SYMBOL(wfstream, std::, <fstream>)
 SYMBOL(wifstream, std::, <fstream>)
 SYMBOL(wios, std::, <ios>)
 SYMBOL(wiostream, std::, <istream>)
+SYMBOL(wistream, std::, <istream>)
 SYMBOL(wistringstream, std::, <sstream>)
 SYMBOL(wmemchr, std::, <cwchar>)
 SYMBOL(wmemcmp, std::, <cwchar>)
@@ -1202,6 +1240,7 @@
 SYMBOL(wmemmove, std::, <cwchar>)
 SYMBOL(wmemset, std::, <cwchar>)
 SYMBOL(wofstream, std::, <fstream>)
+SYMBOL(wostream, std::, <ostream>)
 SYMBOL(wostringstream, std::, <sstream>)
 SYMBOL(wosyncstream, std::, <syncstream>)
 SYMBOL(wprintf, std::, <cwchar>)
@@ -1261,7 +1300,6 @@
 SYMBOL(gps_seconds, std::chrono::, <chrono>)
 SYMBOL(gps_time, std::chrono::, <chrono>)
 SYMBOL(high_resolution_clock, std::chrono::, <chrono>)
-SYMBOL(hours, std::chrono::, <chrono>)
 SYMBOL(is_clock, std::chrono::, <chrono>)
 SYMBOL(is_clock_v, std::chrono::, <chrono>)
 SYMBOL(last, std::chrono::, <chrono>)
@@ -1273,18 +1311,13 @@
 SYMBOL(local_t, std::chrono::, <chrono>)
 SYMBOL(local_time, std::chrono::, <chrono>)
 SYMBOL(locate_zone, std::chrono::, <chrono>)
-SYMBOL(microseconds, std::chrono::, <chrono>)
-SYMBOL(milliseconds, std::chrono::, <chrono>)
-SYMBOL(minutes, std::chrono::, <chrono>)
 SYMBOL(month, std::chrono::, <chrono>)
 SYMBOL(month_day, std::chrono::, <chrono>)
 SYMBOL(month_day_last, std::chrono::, <chrono>)
 SYMBOL(month_weekday, std::chrono::, <chrono>)
 SYMBOL(month_weekday_last, std::chrono::, <chrono>)
-SYMBOL(nanoseconds, std::chrono::, <chrono>)
 SYMBOL(nonexistent_local_time, std::chrono::, <chrono>)
 SYMBOL(round, std::chrono::, <chrono>)
-SYMBOL(seconds, std::chrono::, <chrono>)
 SYMBOL(steady_clock, std::chrono::, <chrono>)
 SYMBOL(sys_days, std::chrono::, <chrono>)
 SYMBOL(sys_info, std::chrono::, <chrono>)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to