Skip to content

Commit 76fd590

Browse files
committed
Parse symbols with qualified name
1 parent 8538819 commit 76fd590

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

clang/tools/include-mapping/cppreference_parser.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _HasClass(tag, *classes):
4040
return False
4141

4242

43-
def _ParseSymbolPage(symbol_page_html, symbol_name):
43+
def _ParseSymbolPage(symbol_page_html, symbol_name, qual_name):
4444
"""Parse symbol page and retrieve the include header defined in this page.
4545
The symbol page provides header for the symbol, specifically in
4646
"Defined in header <header>" section. An example:
@@ -69,7 +69,9 @@ def _ParseSymbolPage(symbol_page_html, symbol_name):
6969
was_decl = True
7070
# Symbols are in the first cell.
7171
found_symbols = row.find("td").stripped_strings
72-
if not symbol_name in found_symbols:
72+
if not any(
73+
sym == symbol_name or sym == qual_name for sym in found_symbols
74+
):
7375
continue
7476
headers.update(current_headers)
7577
elif _HasClass(row, "t-dsc-header"):
@@ -93,19 +95,18 @@ def _ParseSymbolVariant(caption):
9395
if not (isinstance(caption, NavigableString) and "(" in caption):
9496
return None
9597

96-
if ')' in caption.text: # (locale), (algorithm), etc.
98+
if ")" in caption.text: # (locale), (algorithm), etc.
9799
return caption.text.strip(" ()")
98100

99101
second_part = caption.next_sibling
100102
if isinstance(second_part, Tag) and second_part.name == "code":
101103
# (<code>std::complex</code>), etc.
102104
third_part = second_part.next_sibling
103-
if isinstance(third_part, NavigableString) and third_part.text.startswith(')'):
105+
if isinstance(third_part, NavigableString) and third_part.text.startswith(")"):
104106
return second_part.text
105107
return None
106108

107109

108-
109110
def _ParseIndexPage(index_page_html):
110111
"""Parse index page.
111112
The index page lists all std symbols and hrefs to their detailed pages
@@ -137,9 +138,9 @@ def _ParseIndexPage(index_page_html):
137138
return symbols
138139

139140

140-
def _ReadSymbolPage(path, name):
141+
def _ReadSymbolPage(path, name, qual_name):
141142
with open(path) as f:
142-
return _ParseSymbolPage(f.read(), name)
143+
return _ParseSymbolPage(f.read(), name, qual_name)
143144

144145

145146
def _GetSymbols(pool, root_dir, index_page_name, namespace, variants_to_accept):
@@ -161,17 +162,18 @@ def _GetSymbols(pool, root_dir, index_page_name, namespace, variants_to_accept):
161162
for symbol_name, symbol_page_path, variant in _ParseIndexPage(f.read()):
162163
# Variant symbols (e.g. the std::locale version of isalpha) add ambiguity.
163164
# FIXME: use these as a fallback rather than ignoring entirely.
164-
variants_for_symbol = variants_to_accept.get(
165-
(namespace or "") + symbol_name, ()
166-
)
165+
qualified_symbol_name = (namespace or "") + symbol_name
166+
variants_for_symbol = variants_to_accept.get(qualified_symbol_name, ())
167167
if variant and variant not in variants_for_symbol:
168168
continue
169169
path = os.path.join(root_dir, symbol_page_path)
170170
if os.path.isfile(path):
171171
results.append(
172172
(
173173
symbol_name,
174-
pool.apply_async(_ReadSymbolPage, (path, symbol_name)),
174+
pool.apply_async(
175+
_ReadSymbolPage, (path, symbol_name, qualified_symbol_name)
176+
),
175177
)
176178
)
177179
else:

0 commit comments

Comments
 (0)