diff options
author | Haojian Wu <hokein@google.com> | 2019-03-14 11:25:26 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2019-03-14 11:25:26 +0000 |
commit | 7f51b5dc3271bc8078a6f63db2e50f06def9090d (patch) | |
tree | c4da160745384c2ad35329e984f99da331e02cf3 /clang-tools-extra/clangd/include-mapping/test.py | |
parent | e81f5f91b49677f4fbf545fcd9a742d5de155f0a (diff) | |
download | bcm5719-llvm-7f51b5dc3271bc8078a6f63db2e50f06def9090d.tar.gz bcm5719-llvm-7f51b5dc3271bc8078a6f63db2e50f06def9090d.zip |
[clangd] Using symbol name to map includes for STL symbols.
Summary:
Using suffix path mapping relies on the STL implementations, and it is
not portable. This patch is using symbol name mapping, which should
work with different STL implementations, fix clangd/clangd#9.
To generate the symbol mapping, we parse the cppreference symbol index
page to build a lookup table.
The mapping is not completed, a few TODOs:
- support symbols from different headers (e.g. std::move)
- support STL macros
- support symbols from std's sub-namespaces (e.g. chrono)
Reviewers: ioeric, jfb, serge-sans-paille
Reviewed By: ioeric
Subscribers: sammccall, klimek, ilya-biryukov, ioeric, MaskRay, jkorous, mgrang, arphaman, kadircet, jfb, jdoerfert, cfe-commits
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D58345
llvm-svn: 356134
Diffstat (limited to 'clang-tools-extra/clangd/include-mapping/test.py')
-rwxr-xr-x | clang-tools-extra/clangd/include-mapping/test.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/include-mapping/test.py b/clang-tools-extra/clangd/include-mapping/test.py new file mode 100755 index 00000000000..89fa359184c --- /dev/null +++ b/clang-tools-extra/clangd/include-mapping/test.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python +#===- test.py - ---------------------------------------------*- python -*--===# +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +#===------------------------------------------------------------------------===# + +from gen_std import ParseSymbolPage, ParseIndexPage + +import unittest + +class TestStdGen(unittest.TestCase): + + def testParseIndexPage(self): + html = """ + <a href="abs.html" title="abs"><tt>abs()</tt></a> (int) <br> + <a href="complex/abs.html" title="abs"><tt>abs<>()</tt></a> (std::complex) <br> + <a href="acos.html" title="acos"><tt>acos()</tt></a> <br> + <a href="acosh.html" title="acosh"><tt>acosh()</tt></a> <span class="t-mark-rev">(since C++11)</span> <br> + <a href="as_bytes.html" title="as bytes"><tt>as_bytes<>()</tt></a> <span class="t-mark-rev t-since-cxx20">(since C++20)</span> <br> + """ + + actual = ParseIndexPage(html) + expected = [ + ("abs", "abs.html"), + ("abs", "complex/abs.html"), + ("acos", "acos.html"), + ("acosh", "acosh.html"), + ("as_bytes", "as_bytes.html"), + ] + 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])) + + + def testParseSymbolPage_SingleHeader(self): + # Defined in header <cmath> + html = """ + <table class="t-dcl-begin"><tbody> + <tr class="t-dsc-header"> + <td> <div>Defined in header <code><a href="cmath.html" title="cmath"><cmath></a></code> + </div></td> + <td></td> + <td></td> + </tr> +</tbody></table> +""" + self.assertEqual(ParseSymbolPage(html), ['<cmath>']) + + + def testParseSymbolPage_MulHeaders(self): + # Defined in header <cstddef> + # Defined in header <cstdio> + # Defined in header <cstdlib> + html = """ +<table class="t-dcl-begin"><tbody> + <tr class="t-dsc-header"> + <td> <div>Defined in header <code><a href="cstddef.html" title="cstddef"><cstddef></a></code> + </div></td> + <td></td> + <td></td> + </tr> + <tr class="t-dsc-header"> + <td> <div>Defined in header <code><a href="cstdio.html" title="cstdio"><cstdio></a></code> + </div></td> + <td></td> + <td></td> + </tr> + <tr class="t-dsc-header"> + <td> <div>Defined in header <code><a href=".cstdlib.html" title="ccstdlib"><cstdlib></a></code> + </div></td> + <td></td> + <td></td> + </tr> +</tbody></table> +""" + self.assertEqual(ParseSymbolPage(html), + ['<cstddef>', '<cstdio>', '<cstdlib>']) + + + def testParseSymbolPage_MulHeadersInSameDiv(self): + # Multile <code> blocks in a Div. + # Defined in header <algorithm> + # Defined in header <utility> + html = """ +<tr class="t-dsc-header"> +<td><div> + Defined in header <code><a href="../header/algorithm.html" title="cpp/header/algorithm"><algorithm></a></code><br> + Defined in header <code><a href="../header/utility.html" title="cpp/header/utility"><utility></a></code> +</div></td> +<td></td> +</tr> +""" + self.assertEqual(ParseSymbolPage(html), ['<algorithm>', '<utility>']) + + +if __name__ == '__main__': + unittest.main() |