Sphinx 8.1.3__py3-none-any.whl → 8.2.0rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of Sphinx might be problematic. Click here for more details.
- sphinx/__init__.py +8 -4
- sphinx/__main__.py +2 -0
- sphinx/_cli/__init__.py +2 -5
- sphinx/_cli/util/colour.py +34 -11
- sphinx/_cli/util/errors.py +128 -61
- sphinx/addnodes.py +51 -35
- sphinx/application.py +362 -230
- sphinx/builders/__init__.py +87 -64
- sphinx/builders/_epub_base.py +65 -56
- sphinx/builders/changes.py +17 -23
- sphinx/builders/dirhtml.py +8 -13
- sphinx/builders/epub3.py +70 -38
- sphinx/builders/gettext.py +93 -73
- sphinx/builders/html/__init__.py +240 -186
- sphinx/builders/html/_assets.py +9 -2
- sphinx/builders/html/_build_info.py +3 -0
- sphinx/builders/latex/__init__.py +64 -54
- sphinx/builders/latex/constants.py +14 -11
- sphinx/builders/latex/nodes.py +2 -0
- sphinx/builders/latex/theming.py +8 -9
- sphinx/builders/latex/transforms.py +7 -5
- sphinx/builders/linkcheck.py +193 -149
- sphinx/builders/manpage.py +17 -17
- sphinx/builders/singlehtml.py +28 -16
- sphinx/builders/texinfo.py +28 -21
- sphinx/builders/text.py +10 -15
- sphinx/builders/xml.py +10 -19
- sphinx/cmd/build.py +49 -119
- sphinx/cmd/make_mode.py +35 -31
- sphinx/cmd/quickstart.py +78 -62
- sphinx/config.py +265 -163
- sphinx/directives/__init__.py +51 -54
- sphinx/directives/admonitions.py +107 -0
- sphinx/directives/code.py +24 -19
- sphinx/directives/other.py +21 -42
- sphinx/directives/patches.py +28 -16
- sphinx/domains/__init__.py +54 -31
- sphinx/domains/_domains_container.py +22 -17
- sphinx/domains/_index.py +5 -8
- sphinx/domains/c/__init__.py +366 -245
- sphinx/domains/c/_ast.py +378 -256
- sphinx/domains/c/_ids.py +89 -31
- sphinx/domains/c/_parser.py +283 -214
- sphinx/domains/c/_symbol.py +269 -198
- sphinx/domains/changeset.py +39 -24
- sphinx/domains/citation.py +54 -24
- sphinx/domains/cpp/__init__.py +517 -362
- sphinx/domains/cpp/_ast.py +999 -682
- sphinx/domains/cpp/_ids.py +133 -65
- sphinx/domains/cpp/_parser.py +746 -588
- sphinx/domains/cpp/_symbol.py +692 -489
- sphinx/domains/index.py +10 -8
- sphinx/domains/javascript.py +152 -74
- sphinx/domains/math.py +48 -40
- sphinx/domains/python/__init__.py +402 -211
- sphinx/domains/python/_annotations.py +114 -57
- sphinx/domains/python/_object.py +151 -67
- sphinx/domains/rst.py +94 -49
- sphinx/domains/std/__init__.py +510 -249
- sphinx/environment/__init__.py +345 -61
- sphinx/environment/adapters/asset.py +7 -1
- sphinx/environment/adapters/indexentries.py +15 -20
- sphinx/environment/adapters/toctree.py +19 -9
- sphinx/environment/collectors/__init__.py +3 -1
- sphinx/environment/collectors/asset.py +18 -15
- sphinx/environment/collectors/dependencies.py +8 -10
- sphinx/environment/collectors/metadata.py +6 -4
- sphinx/environment/collectors/title.py +3 -1
- sphinx/environment/collectors/toctree.py +4 -4
- sphinx/errors.py +1 -3
- sphinx/events.py +4 -4
- sphinx/ext/apidoc/__init__.py +21 -0
- sphinx/ext/apidoc/__main__.py +9 -0
- sphinx/ext/apidoc/_cli.py +356 -0
- sphinx/ext/apidoc/_generate.py +356 -0
- sphinx/ext/apidoc/_shared.py +66 -0
- sphinx/ext/autodoc/__init__.py +829 -480
- sphinx/ext/autodoc/directive.py +57 -21
- sphinx/ext/autodoc/importer.py +184 -67
- sphinx/ext/autodoc/mock.py +25 -10
- sphinx/ext/autodoc/preserve_defaults.py +17 -9
- sphinx/ext/autodoc/type_comment.py +56 -29
- sphinx/ext/autodoc/typehints.py +49 -26
- sphinx/ext/autosectionlabel.py +28 -11
- sphinx/ext/autosummary/__init__.py +271 -143
- sphinx/ext/autosummary/generate.py +121 -51
- sphinx/ext/coverage.py +152 -91
- sphinx/ext/doctest.py +169 -101
- sphinx/ext/duration.py +12 -6
- sphinx/ext/extlinks.py +33 -21
- sphinx/ext/githubpages.py +8 -8
- sphinx/ext/graphviz.py +175 -109
- sphinx/ext/ifconfig.py +11 -6
- sphinx/ext/imgconverter.py +48 -25
- sphinx/ext/imgmath.py +127 -97
- sphinx/ext/inheritance_diagram.py +177 -103
- sphinx/ext/intersphinx/__init__.py +22 -13
- sphinx/ext/intersphinx/__main__.py +3 -1
- sphinx/ext/intersphinx/_cli.py +18 -14
- sphinx/ext/intersphinx/_load.py +91 -82
- sphinx/ext/intersphinx/_resolve.py +108 -74
- sphinx/ext/intersphinx/_shared.py +2 -2
- sphinx/ext/linkcode.py +28 -12
- sphinx/ext/mathjax.py +60 -29
- sphinx/ext/napoleon/__init__.py +19 -7
- sphinx/ext/napoleon/docstring.py +229 -231
- sphinx/ext/todo.py +44 -49
- sphinx/ext/viewcode.py +105 -57
- sphinx/extension.py +3 -1
- sphinx/highlighting.py +13 -7
- sphinx/io.py +9 -13
- sphinx/jinja2glue.py +29 -26
- sphinx/locale/__init__.py +8 -9
- sphinx/parsers.py +8 -7
- sphinx/project.py +2 -2
- sphinx/pycode/__init__.py +31 -21
- sphinx/pycode/ast.py +6 -3
- sphinx/pycode/parser.py +14 -8
- sphinx/pygments_styles.py +4 -5
- sphinx/registry.py +192 -92
- sphinx/roles.py +58 -7
- sphinx/search/__init__.py +75 -54
- sphinx/search/en.py +11 -13
- sphinx/search/fi.py +1 -1
- sphinx/search/ja.py +8 -6
- sphinx/search/nl.py +1 -1
- sphinx/search/zh.py +19 -21
- sphinx/testing/fixtures.py +26 -29
- sphinx/testing/path.py +26 -62
- sphinx/testing/restructuredtext.py +14 -8
- sphinx/testing/util.py +21 -19
- sphinx/texinputs/make.bat.jinja +50 -50
- sphinx/texinputs/sphinx.sty +4 -3
- sphinx/texinputs/sphinxlatexadmonitions.sty +1 -1
- sphinx/texinputs/sphinxlatexobjects.sty +29 -10
- sphinx/themes/basic/static/searchtools.js +8 -5
- sphinx/theming.py +49 -61
- sphinx/transforms/__init__.py +17 -38
- sphinx/transforms/compact_bullet_list.py +5 -3
- sphinx/transforms/i18n.py +8 -21
- sphinx/transforms/post_transforms/__init__.py +142 -93
- sphinx/transforms/post_transforms/code.py +5 -5
- sphinx/transforms/post_transforms/images.py +28 -24
- sphinx/transforms/references.py +3 -1
- sphinx/util/__init__.py +109 -60
- sphinx/util/_files.py +39 -23
- sphinx/util/_importer.py +4 -1
- sphinx/util/_inventory_file_reader.py +76 -0
- sphinx/util/_io.py +2 -2
- sphinx/util/_lines.py +6 -3
- sphinx/util/_pathlib.py +40 -2
- sphinx/util/build_phase.py +2 -0
- sphinx/util/cfamily.py +19 -14
- sphinx/util/console.py +44 -179
- sphinx/util/display.py +9 -10
- sphinx/util/docfields.py +140 -122
- sphinx/util/docstrings.py +1 -1
- sphinx/util/docutils.py +118 -77
- sphinx/util/fileutil.py +25 -26
- sphinx/util/http_date.py +2 -0
- sphinx/util/i18n.py +77 -64
- sphinx/util/images.py +8 -6
- sphinx/util/inspect.py +147 -38
- sphinx/util/inventory.py +215 -116
- sphinx/util/logging.py +33 -33
- sphinx/util/matching.py +12 -4
- sphinx/util/nodes.py +18 -13
- sphinx/util/osutil.py +38 -39
- sphinx/util/parallel.py +22 -13
- sphinx/util/parsing.py +2 -1
- sphinx/util/png.py +6 -2
- sphinx/util/requests.py +33 -2
- sphinx/util/rst.py +3 -2
- sphinx/util/tags.py +1 -1
- sphinx/util/template.py +18 -10
- sphinx/util/texescape.py +8 -6
- sphinx/util/typing.py +148 -122
- sphinx/versioning.py +3 -3
- sphinx/writers/html.py +3 -1
- sphinx/writers/html5.py +61 -50
- sphinx/writers/latex.py +80 -65
- sphinx/writers/manpage.py +19 -38
- sphinx/writers/texinfo.py +44 -45
- sphinx/writers/text.py +48 -30
- sphinx/writers/xml.py +11 -8
- {sphinx-8.1.3.dist-info → sphinx-8.2.0rc1.dist-info}/LICENSE.rst +1 -1
- {sphinx-8.1.3.dist-info → sphinx-8.2.0rc1.dist-info}/METADATA +23 -15
- {sphinx-8.1.3.dist-info → sphinx-8.2.0rc1.dist-info}/RECORD +190 -186
- {sphinx-8.1.3.dist-info → sphinx-8.2.0rc1.dist-info}/WHEEL +1 -1
- sphinx/builders/html/transforms.py +0 -90
- sphinx/ext/apidoc.py +0 -721
- sphinx/util/exceptions.py +0 -74
- {sphinx-8.1.3.dist-info → sphinx-8.2.0rc1.dist-info}/entry_points.txt +0 -0
sphinx/domains/cpp/_symbol.py
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
4
|
|
|
5
5
|
from sphinx.domains.cpp._ast import (
|
|
6
6
|
ASTDeclaration,
|
|
7
|
-
ASTIdentifier,
|
|
8
7
|
ASTNestedName,
|
|
9
8
|
ASTNestedNameElement,
|
|
10
|
-
ASTOperator,
|
|
11
|
-
ASTTemplateArgs,
|
|
12
|
-
ASTTemplateDeclarationPrefix,
|
|
13
|
-
ASTTemplateIntroduction,
|
|
14
|
-
ASTTemplateParams,
|
|
15
9
|
)
|
|
16
10
|
from sphinx.locale import __
|
|
17
11
|
from sphinx.util import logging
|
|
18
12
|
|
|
19
13
|
if TYPE_CHECKING:
|
|
20
|
-
from collections.abc import Callable, Iterator
|
|
21
|
-
|
|
14
|
+
from collections.abc import Callable, Iterable, Iterator, Sequence
|
|
15
|
+
from typing import Any, NoReturn
|
|
16
|
+
|
|
17
|
+
from sphinx.domains.cpp._ast import (
|
|
18
|
+
ASTIdentifier,
|
|
19
|
+
ASTOperator,
|
|
20
|
+
ASTTemplateArgs,
|
|
21
|
+
ASTTemplateDeclarationPrefix,
|
|
22
|
+
ASTTemplateIntroduction,
|
|
23
|
+
ASTTemplateParams,
|
|
24
|
+
)
|
|
22
25
|
from sphinx.environment import BuildEnvironment
|
|
23
26
|
|
|
24
27
|
logger = logging.getLogger(__name__)
|
|
@@ -32,55 +35,117 @@ class _DuplicateSymbolError(Exception):
|
|
|
32
35
|
self.declaration = declaration
|
|
33
36
|
|
|
34
37
|
def __str__(self) -> str:
|
|
35
|
-
return
|
|
38
|
+
return 'Internal C++ duplicate symbol error:\n%s' % self.symbol.dump(0)
|
|
36
39
|
|
|
37
40
|
|
|
38
41
|
class SymbolLookupResult:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
__slots__ = (
|
|
43
|
+
'symbols',
|
|
44
|
+
'parent_symbol',
|
|
45
|
+
'ident_or_op',
|
|
46
|
+
'template_params',
|
|
47
|
+
'template_args',
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
symbols: Iterable[Symbol]
|
|
51
|
+
parent_symbol: Symbol
|
|
52
|
+
ident_or_op: ASTIdentifier | ASTOperator
|
|
53
|
+
template_params: Any
|
|
54
|
+
template_args: ASTTemplateArgs
|
|
55
|
+
|
|
56
|
+
def __init__(
|
|
57
|
+
self,
|
|
58
|
+
symbols: Iterable[Symbol],
|
|
59
|
+
parent_symbol: Symbol,
|
|
60
|
+
ident_or_op: ASTIdentifier | ASTOperator,
|
|
61
|
+
template_params: Any,
|
|
62
|
+
template_args: ASTTemplateArgs,
|
|
63
|
+
) -> None:
|
|
42
64
|
self.symbols = symbols
|
|
43
|
-
self.
|
|
44
|
-
self.
|
|
45
|
-
self.
|
|
46
|
-
self.
|
|
65
|
+
self.parent_symbol = parent_symbol
|
|
66
|
+
self.ident_or_op = ident_or_op
|
|
67
|
+
self.template_params = template_params
|
|
68
|
+
self.template_args = template_args
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def parentSymbol(self) -> Symbol:
|
|
72
|
+
return self.parent_symbol
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def identOrOp(self) -> ASTIdentifier | ASTOperator:
|
|
76
|
+
return self.ident_or_op
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def templateParams(self) -> Any:
|
|
80
|
+
return self.template_params
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def templateArgs(self) -> ASTTemplateArgs:
|
|
84
|
+
return self.template_args
|
|
47
85
|
|
|
48
86
|
|
|
49
87
|
class LookupKey:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
88
|
+
__slots__ = ('data',)
|
|
89
|
+
|
|
90
|
+
data: Sequence[
|
|
91
|
+
tuple[
|
|
92
|
+
ASTNestedNameElement,
|
|
93
|
+
ASTTemplateParams | ASTTemplateIntroduction,
|
|
94
|
+
str | None,
|
|
95
|
+
]
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
def __init__(
|
|
99
|
+
self,
|
|
100
|
+
data: Sequence[
|
|
101
|
+
tuple[
|
|
102
|
+
ASTNestedNameElement,
|
|
103
|
+
ASTTemplateParams | ASTTemplateIntroduction,
|
|
104
|
+
str | None,
|
|
105
|
+
]
|
|
106
|
+
],
|
|
107
|
+
/,
|
|
108
|
+
) -> None:
|
|
53
109
|
self.data = data
|
|
54
110
|
|
|
111
|
+
def __repr__(self) -> str:
|
|
112
|
+
return f'LookupKey({self.data!r})'
|
|
113
|
+
|
|
114
|
+
def __str__(self) -> str:
|
|
115
|
+
inner = ', '.join(f'({ident}, {id_})' for ident, _, id_ in self.data)
|
|
116
|
+
return f'[{inner}]'
|
|
55
117
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
118
|
+
|
|
119
|
+
def _is_specialization(
|
|
120
|
+
template_params: ASTTemplateParams | ASTTemplateIntroduction,
|
|
121
|
+
template_args: ASTTemplateArgs,
|
|
122
|
+
) -> bool:
|
|
123
|
+
# Checks if `template_args` does not exactly match `template_params`.
|
|
59
124
|
# the names of the template parameters must be given exactly as args
|
|
60
125
|
# and params that are packs must in the args be the name expanded
|
|
61
|
-
if len(
|
|
126
|
+
if len(template_params.params) != len(template_args.args):
|
|
62
127
|
return True
|
|
63
128
|
# having no template params and no arguments is also a specialization
|
|
64
|
-
if len(
|
|
129
|
+
if len(template_params.params) == 0:
|
|
65
130
|
return True
|
|
66
|
-
for i in range(len(
|
|
67
|
-
param =
|
|
68
|
-
arg =
|
|
131
|
+
for i in range(len(template_params.params)):
|
|
132
|
+
param = template_params.params[i]
|
|
133
|
+
arg = template_args.args[i]
|
|
69
134
|
# TODO: doing this by string manipulation is probably not the most efficient
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if param.isPack !=
|
|
135
|
+
param_name = str(param.name)
|
|
136
|
+
arg_txt = str(arg)
|
|
137
|
+
is_arg_pack_expansion = arg_txt.endswith('...')
|
|
138
|
+
if param.isPack != is_arg_pack_expansion:
|
|
74
139
|
return True
|
|
75
|
-
|
|
76
|
-
if
|
|
140
|
+
arg_name = arg_txt[:-3] if is_arg_pack_expansion else arg_txt
|
|
141
|
+
if param_name != arg_name:
|
|
77
142
|
return True
|
|
78
143
|
return False
|
|
79
144
|
|
|
80
145
|
|
|
81
146
|
class Symbol:
|
|
82
147
|
debug_indent = 0
|
|
83
|
-
debug_indent_string =
|
|
148
|
+
debug_indent_string = ' '
|
|
84
149
|
debug_lookup = False # overridden by the corresponding config value
|
|
85
150
|
debug_show_tree = False # overridden by the corresponding config value
|
|
86
151
|
|
|
@@ -95,7 +160,7 @@ class Symbol:
|
|
|
95
160
|
|
|
96
161
|
@staticmethod
|
|
97
162
|
def debug_print(*args: Any) -> None:
|
|
98
|
-
logger.debug(Symbol.debug_indent_string * Symbol.debug_indent, end=
|
|
163
|
+
logger.debug(Symbol.debug_indent_string * Symbol.debug_indent, end='')
|
|
99
164
|
logger.debug(*args)
|
|
100
165
|
|
|
101
166
|
def _assert_invariants(self) -> None:
|
|
@@ -111,15 +176,20 @@ class Symbol:
|
|
|
111
176
|
assert self.docname
|
|
112
177
|
|
|
113
178
|
def __setattr__(self, key: str, value: Any) -> None:
|
|
114
|
-
if key ==
|
|
179
|
+
if key == 'children':
|
|
115
180
|
raise AssertionError
|
|
116
181
|
return super().__setattr__(key, value)
|
|
117
182
|
|
|
118
|
-
def __init__(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
183
|
+
def __init__(
|
|
184
|
+
self,
|
|
185
|
+
parent: Symbol | None,
|
|
186
|
+
identOrOp: ASTIdentifier | ASTOperator | None,
|
|
187
|
+
templateParams: ASTTemplateParams | ASTTemplateIntroduction | None,
|
|
188
|
+
templateArgs: Any,
|
|
189
|
+
declaration: ASTDeclaration | None,
|
|
190
|
+
docname: str | None,
|
|
191
|
+
line: int | None,
|
|
192
|
+
) -> None:
|
|
123
193
|
self.parent = parent
|
|
124
194
|
# declarations in a single directive are linked together
|
|
125
195
|
self.siblingAbove: Symbol | None = None
|
|
@@ -132,8 +202,9 @@ class Symbol:
|
|
|
132
202
|
# and
|
|
133
203
|
#
|
|
134
204
|
# .. cpp:function:: template <typename T> int A<T>::foo()
|
|
135
|
-
if
|
|
136
|
-
|
|
205
|
+
if templateArgs is not None and not _is_specialization(
|
|
206
|
+
templateParams, templateArgs
|
|
207
|
+
):
|
|
137
208
|
templateArgs = None
|
|
138
209
|
self.templateParams = templateParams # template<templateParams>
|
|
139
210
|
self.templateArgs = templateArgs # identifier<templateArgs>
|
|
@@ -145,8 +216,8 @@ class Symbol:
|
|
|
145
216
|
|
|
146
217
|
# Remember to modify Symbol.remove if modifications to the parent change.
|
|
147
218
|
self._children: list[Symbol] = []
|
|
148
|
-
self.
|
|
149
|
-
# note: _children includes
|
|
219
|
+
self._anon_children: list[Symbol] = []
|
|
220
|
+
# note: _children includes _anon_children
|
|
150
221
|
if self.parent:
|
|
151
222
|
self.parent._children.append(self)
|
|
152
223
|
if self.declaration:
|
|
@@ -177,7 +248,7 @@ class Symbol:
|
|
|
177
248
|
def _add_template_and_function_params(self) -> None:
|
|
178
249
|
if Symbol.debug_lookup:
|
|
179
250
|
Symbol.debug_indent += 1
|
|
180
|
-
Symbol.debug_print(
|
|
251
|
+
Symbol.debug_print('_add_template_and_function_params:')
|
|
181
252
|
# Note: we may be called from _fill_empty, so the symbols we want
|
|
182
253
|
# to add may actually already be present (as empty symbols).
|
|
183
254
|
|
|
@@ -195,7 +266,10 @@ class Symbol:
|
|
|
195
266
|
nn = ASTNestedName([nne], [False], rooted=False)
|
|
196
267
|
self._add_symbols(nn, [], decl, self.docname, self.line)
|
|
197
268
|
# add symbols for function parameters, if any
|
|
198
|
-
if
|
|
269
|
+
if (
|
|
270
|
+
self.declaration is not None
|
|
271
|
+
and self.declaration.function_params is not None
|
|
272
|
+
):
|
|
199
273
|
for fp in self.declaration.function_params:
|
|
200
274
|
if fp.arg is None:
|
|
201
275
|
continue
|
|
@@ -218,26 +292,26 @@ class Symbol:
|
|
|
218
292
|
self.parent = None
|
|
219
293
|
|
|
220
294
|
def clear_doc(self, docname: str) -> None:
|
|
221
|
-
|
|
222
|
-
for
|
|
223
|
-
|
|
224
|
-
if
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if
|
|
229
|
-
|
|
230
|
-
if
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
self._children =
|
|
295
|
+
new_children: list[Symbol] = []
|
|
296
|
+
for s_child in self._children:
|
|
297
|
+
s_child.clear_doc(docname)
|
|
298
|
+
if s_child.declaration and s_child.docname == docname:
|
|
299
|
+
s_child.declaration = None
|
|
300
|
+
s_child.docname = None
|
|
301
|
+
s_child.line = None
|
|
302
|
+
if s_child.siblingAbove is not None:
|
|
303
|
+
s_child.siblingAbove.siblingBelow = s_child.siblingBelow
|
|
304
|
+
if s_child.siblingBelow is not None:
|
|
305
|
+
s_child.siblingBelow.siblingAbove = s_child.siblingAbove
|
|
306
|
+
s_child.siblingAbove = None
|
|
307
|
+
s_child.siblingBelow = None
|
|
308
|
+
new_children.append(s_child)
|
|
309
|
+
self._children = new_children
|
|
236
310
|
|
|
237
311
|
def get_all_symbols(self) -> Iterator[Any]:
|
|
238
312
|
yield self
|
|
239
|
-
for
|
|
240
|
-
yield from
|
|
313
|
+
for s_child in self._children:
|
|
314
|
+
yield from s_child.get_all_symbols()
|
|
241
315
|
|
|
242
316
|
@property
|
|
243
317
|
def children_recurse_anon(self) -> Iterator[Symbol]:
|
|
@@ -258,14 +332,14 @@ class Symbol:
|
|
|
258
332
|
while s.parent:
|
|
259
333
|
symbols.append(s)
|
|
260
334
|
s = s.parent
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
335
|
+
key = [
|
|
336
|
+
(
|
|
337
|
+
ASTNestedNameElement(s.identOrOp, s.templateArgs),
|
|
338
|
+
s.templateParams,
|
|
339
|
+
None if s.declaration is None else s.declaration.get_newest_id(),
|
|
340
|
+
)
|
|
341
|
+
for s in reversed(symbols)
|
|
342
|
+
]
|
|
269
343
|
return LookupKey(key)
|
|
270
344
|
|
|
271
345
|
def get_full_nested_name(self) -> ASTNestedName:
|
|
@@ -282,83 +356,100 @@ class Symbol:
|
|
|
282
356
|
templates.append(False)
|
|
283
357
|
return ASTNestedName(names, templates, rooted=False)
|
|
284
358
|
|
|
285
|
-
def _find_first_named_symbol(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
359
|
+
def _find_first_named_symbol(
|
|
360
|
+
self,
|
|
361
|
+
ident_or_op: ASTIdentifier | ASTOperator,
|
|
362
|
+
template_params: ASTTemplateParams | ASTTemplateIntroduction,
|
|
363
|
+
template_args: ASTTemplateArgs | None,
|
|
364
|
+
template_shorthand: bool,
|
|
365
|
+
match_self: bool,
|
|
366
|
+
recurse_in_anon: bool,
|
|
367
|
+
correct_primary_template_args: bool,
|
|
368
|
+
) -> Symbol | None:
|
|
291
369
|
if Symbol.debug_lookup:
|
|
292
|
-
Symbol.debug_print(
|
|
293
|
-
res = self._find_named_symbols(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
370
|
+
Symbol.debug_print('_find_first_named_symbol ->')
|
|
371
|
+
res = self._find_named_symbols(
|
|
372
|
+
ident_or_op,
|
|
373
|
+
template_params,
|
|
374
|
+
template_args,
|
|
375
|
+
template_shorthand,
|
|
376
|
+
match_self,
|
|
377
|
+
recurse_in_anon,
|
|
378
|
+
correct_primary_template_args,
|
|
379
|
+
search_in_siblings=False,
|
|
380
|
+
)
|
|
297
381
|
try:
|
|
298
382
|
return next(res)
|
|
299
383
|
except StopIteration:
|
|
300
384
|
return None
|
|
301
385
|
|
|
302
|
-
def _find_named_symbols(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
386
|
+
def _find_named_symbols(
|
|
387
|
+
self,
|
|
388
|
+
ident_or_op: ASTIdentifier | ASTOperator,
|
|
389
|
+
template_params: ASTTemplateParams | ASTTemplateIntroduction,
|
|
390
|
+
template_args: ASTTemplateArgs,
|
|
391
|
+
template_shorthand: bool,
|
|
392
|
+
match_self: bool,
|
|
393
|
+
recurse_in_anon: bool,
|
|
394
|
+
correct_primary_template_args: bool,
|
|
395
|
+
search_in_siblings: bool,
|
|
396
|
+
) -> Iterator[Symbol]:
|
|
308
397
|
if Symbol.debug_lookup:
|
|
309
398
|
Symbol.debug_indent += 1
|
|
310
|
-
Symbol.debug_print(
|
|
399
|
+
Symbol.debug_print('_find_named_symbols:')
|
|
311
400
|
Symbol.debug_indent += 1
|
|
312
|
-
Symbol.debug_print(
|
|
313
|
-
logger.debug(self.to_string(Symbol.debug_indent + 1), end=
|
|
314
|
-
Symbol.debug_print(
|
|
315
|
-
Symbol.debug_print(
|
|
316
|
-
Symbol.debug_print(
|
|
317
|
-
Symbol.debug_print(
|
|
318
|
-
Symbol.debug_print(
|
|
319
|
-
Symbol.debug_print(
|
|
320
|
-
Symbol.debug_print(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
401
|
+
Symbol.debug_print('self:')
|
|
402
|
+
logger.debug(self.to_string(Symbol.debug_indent + 1), end='')
|
|
403
|
+
Symbol.debug_print('ident_or_op: ', ident_or_op)
|
|
404
|
+
Symbol.debug_print('template_params: ', template_params)
|
|
405
|
+
Symbol.debug_print('template_args: ', template_args)
|
|
406
|
+
Symbol.debug_print('template_shorthand: ', template_shorthand)
|
|
407
|
+
Symbol.debug_print('match_self: ', match_self)
|
|
408
|
+
Symbol.debug_print('recurse_in_anon: ', recurse_in_anon)
|
|
409
|
+
Symbol.debug_print(
|
|
410
|
+
'correct_primary_template_args:', correct_primary_template_args
|
|
411
|
+
)
|
|
412
|
+
Symbol.debug_print('search_in_siblings: ', search_in_siblings)
|
|
413
|
+
|
|
414
|
+
if correct_primary_template_args:
|
|
415
|
+
if template_params is not None and template_args is not None:
|
|
325
416
|
# If both are given, but it's not a specialization, then do lookup as if
|
|
326
417
|
# there is no argument list.
|
|
327
418
|
# For example: template<typename T> int A<T>::var;
|
|
328
|
-
if not _is_specialization(
|
|
329
|
-
|
|
419
|
+
if not _is_specialization(template_params, template_args):
|
|
420
|
+
template_args = None
|
|
330
421
|
|
|
331
422
|
def matches(s: Symbol) -> bool:
|
|
332
|
-
if s.identOrOp !=
|
|
423
|
+
if s.identOrOp != ident_or_op:
|
|
333
424
|
return False
|
|
334
|
-
if (s.templateParams is None) != (
|
|
335
|
-
if
|
|
425
|
+
if (s.templateParams is None) != (template_params is None):
|
|
426
|
+
if template_params is not None:
|
|
336
427
|
# we query with params, they must match params
|
|
337
428
|
return False
|
|
338
|
-
if not
|
|
429
|
+
if not template_shorthand:
|
|
339
430
|
# we don't query with params, and we do care about them
|
|
340
431
|
return False
|
|
341
|
-
if
|
|
432
|
+
if template_params:
|
|
342
433
|
# TODO: do better comparison
|
|
343
|
-
if str(s.templateParams) != str(
|
|
434
|
+
if str(s.templateParams) != str(template_params):
|
|
344
435
|
return False
|
|
345
|
-
if (s.templateArgs is None) != (
|
|
436
|
+
if (s.templateArgs is None) != (template_args is None):
|
|
346
437
|
return False
|
|
347
438
|
if s.templateArgs:
|
|
348
439
|
# TODO: do better comparison
|
|
349
|
-
if str(s.templateArgs) != str(
|
|
440
|
+
if str(s.templateArgs) != str(template_args):
|
|
350
441
|
return False
|
|
351
442
|
return True
|
|
352
443
|
|
|
353
444
|
def candidates() -> Iterator[Symbol]:
|
|
354
445
|
s = self
|
|
355
446
|
if Symbol.debug_lookup:
|
|
356
|
-
Symbol.debug_print(
|
|
357
|
-
logger.debug(s.to_string(Symbol.debug_indent + 1), end=
|
|
447
|
+
Symbol.debug_print('searching in self:')
|
|
448
|
+
logger.debug(s.to_string(Symbol.debug_indent + 1), end='')
|
|
358
449
|
while True:
|
|
359
|
-
if
|
|
450
|
+
if match_self:
|
|
360
451
|
yield s
|
|
361
|
-
if
|
|
452
|
+
if recurse_in_anon:
|
|
362
453
|
yield from s.children_recurse_anon
|
|
363
454
|
else:
|
|
364
455
|
yield from s._children
|
|
@@ -367,17 +458,17 @@ class Symbol:
|
|
|
367
458
|
break
|
|
368
459
|
s = s.siblingAbove
|
|
369
460
|
if Symbol.debug_lookup:
|
|
370
|
-
Symbol.debug_print(
|
|
371
|
-
logger.debug(s.to_string(Symbol.debug_indent + 1), end=
|
|
461
|
+
Symbol.debug_print('searching in sibling:')
|
|
462
|
+
logger.debug(s.to_string(Symbol.debug_indent + 1), end='')
|
|
372
463
|
|
|
373
464
|
for s in candidates():
|
|
374
465
|
if Symbol.debug_lookup:
|
|
375
|
-
Symbol.debug_print(
|
|
376
|
-
logger.debug(s.to_string(Symbol.debug_indent + 1), end=
|
|
466
|
+
Symbol.debug_print('candidate:')
|
|
467
|
+
logger.debug(s.to_string(Symbol.debug_indent + 1), end='')
|
|
377
468
|
if matches(s):
|
|
378
469
|
if Symbol.debug_lookup:
|
|
379
470
|
Symbol.debug_indent += 1
|
|
380
|
-
Symbol.debug_print(
|
|
471
|
+
Symbol.debug_print('matches')
|
|
381
472
|
Symbol.debug_indent -= 3
|
|
382
473
|
yield s
|
|
383
474
|
if Symbol.debug_lookup:
|
|
@@ -387,143 +478,173 @@ class Symbol:
|
|
|
387
478
|
|
|
388
479
|
def _symbol_lookup(
|
|
389
480
|
self,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
[Symbol, ASTIdentifier | ASTOperator, Any, ASTTemplateArgs],
|
|
481
|
+
nested_name: ASTNestedName,
|
|
482
|
+
template_decls: list[Any],
|
|
483
|
+
on_missing_qualified_symbol: Callable[
|
|
484
|
+
[Symbol, ASTIdentifier | ASTOperator, Any, ASTTemplateArgs],
|
|
485
|
+
Symbol | None,
|
|
394
486
|
],
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
487
|
+
strict_template_param_arg_lists: bool,
|
|
488
|
+
ancestor_lookup_type: str,
|
|
489
|
+
template_shorthand: bool,
|
|
490
|
+
match_self: bool,
|
|
491
|
+
recurse_in_anon: bool,
|
|
492
|
+
correct_primary_template_args: bool,
|
|
493
|
+
search_in_siblings: bool,
|
|
494
|
+
) -> SymbolLookupResult | None:
|
|
495
|
+
# ancestor_lookup_type: if not None, specifies the target type of the lookup
|
|
401
496
|
if Symbol.debug_lookup:
|
|
402
497
|
Symbol.debug_indent += 1
|
|
403
|
-
Symbol.debug_print(
|
|
498
|
+
Symbol.debug_print('_symbol_lookup:')
|
|
404
499
|
Symbol.debug_indent += 1
|
|
405
|
-
Symbol.debug_print(
|
|
406
|
-
logger.debug(self.to_string(Symbol.debug_indent + 1), end=
|
|
407
|
-
Symbol.debug_print(
|
|
408
|
-
Symbol.debug_print(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
Symbol.debug_print(
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
Symbol.debug_print(
|
|
415
|
-
Symbol.debug_print(
|
|
416
|
-
|
|
417
|
-
|
|
500
|
+
Symbol.debug_print('self:')
|
|
501
|
+
logger.debug(self.to_string(Symbol.debug_indent + 1), end='')
|
|
502
|
+
Symbol.debug_print('nested_name: ', nested_name)
|
|
503
|
+
Symbol.debug_print(
|
|
504
|
+
'template_decls: ', ','.join(str(t) for t in template_decls)
|
|
505
|
+
)
|
|
506
|
+
Symbol.debug_print(
|
|
507
|
+
'strict_template_param_arg_lists:', strict_template_param_arg_lists
|
|
508
|
+
)
|
|
509
|
+
Symbol.debug_print('ancestor_lookup_type:', ancestor_lookup_type)
|
|
510
|
+
Symbol.debug_print('template_shorthand: ', template_shorthand)
|
|
511
|
+
Symbol.debug_print('match_self: ', match_self)
|
|
512
|
+
Symbol.debug_print('recurse_in_anon: ', recurse_in_anon)
|
|
513
|
+
Symbol.debug_print(
|
|
514
|
+
'correct_primary_template_args: ', correct_primary_template_args
|
|
515
|
+
)
|
|
516
|
+
Symbol.debug_print('search_in_siblings: ', search_in_siblings)
|
|
517
|
+
|
|
518
|
+
if strict_template_param_arg_lists:
|
|
418
519
|
# Each template argument list must have a template parameter list.
|
|
419
520
|
# But to declare a template there must be an additional template parameter list.
|
|
420
|
-
|
|
421
|
-
|
|
521
|
+
num_nested_templates = nested_name.num_templates()
|
|
522
|
+
num_template_decls = len(template_decls)
|
|
523
|
+
assert (
|
|
524
|
+
num_nested_templates == num_template_decls
|
|
525
|
+
or num_nested_templates + 1 == num_template_decls
|
|
526
|
+
)
|
|
422
527
|
else:
|
|
423
|
-
assert len(
|
|
528
|
+
assert len(template_decls) <= nested_name.num_templates() + 1
|
|
424
529
|
|
|
425
|
-
names =
|
|
530
|
+
names = nested_name.names
|
|
426
531
|
|
|
427
532
|
# find the right starting point for lookup
|
|
428
|
-
|
|
429
|
-
if
|
|
430
|
-
while
|
|
431
|
-
|
|
432
|
-
if
|
|
533
|
+
parent_symbol = self
|
|
534
|
+
if nested_name.rooted:
|
|
535
|
+
while parent_symbol.parent:
|
|
536
|
+
parent_symbol = parent_symbol.parent
|
|
537
|
+
if ancestor_lookup_type is not None:
|
|
433
538
|
# walk up until we find the first identifier
|
|
434
|
-
|
|
435
|
-
if not
|
|
436
|
-
while
|
|
437
|
-
if
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
539
|
+
first_name = names[0]
|
|
540
|
+
if not first_name.is_operator():
|
|
541
|
+
while parent_symbol.parent:
|
|
542
|
+
if parent_symbol.find_identifier(
|
|
543
|
+
first_name.identOrOp,
|
|
544
|
+
matchSelf=match_self,
|
|
545
|
+
recurseInAnon=recurse_in_anon,
|
|
546
|
+
searchInSiblings=search_in_siblings,
|
|
547
|
+
):
|
|
441
548
|
# if we are in the scope of a constructor but wants to
|
|
442
549
|
# reference the class we need to walk one extra up
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
|
|
550
|
+
if (
|
|
551
|
+
len(names) == 1
|
|
552
|
+
and ancestor_lookup_type == 'class'
|
|
553
|
+
and match_self
|
|
554
|
+
and parent_symbol.parent
|
|
555
|
+
and parent_symbol.parent.identOrOp == first_name.identOrOp
|
|
556
|
+
):
|
|
446
557
|
pass
|
|
447
558
|
else:
|
|
448
559
|
break
|
|
449
|
-
|
|
560
|
+
parent_symbol = parent_symbol.parent
|
|
450
561
|
|
|
451
562
|
if Symbol.debug_lookup:
|
|
452
|
-
Symbol.debug_print(
|
|
453
|
-
logger.debug(
|
|
563
|
+
Symbol.debug_print('starting point:')
|
|
564
|
+
logger.debug(parent_symbol.to_string(Symbol.debug_indent + 1), end='')
|
|
454
565
|
|
|
455
566
|
# and now the actual lookup
|
|
456
|
-
|
|
567
|
+
i_template_decl = 0
|
|
457
568
|
for name in names[:-1]:
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if
|
|
569
|
+
ident_or_op = name.identOrOp
|
|
570
|
+
template_args = name.templateArgs
|
|
571
|
+
if strict_template_param_arg_lists:
|
|
461
572
|
# there must be a parameter list
|
|
462
|
-
if
|
|
463
|
-
assert
|
|
464
|
-
|
|
465
|
-
|
|
573
|
+
if template_args:
|
|
574
|
+
assert i_template_decl < len(template_decls)
|
|
575
|
+
template_params = template_decls[i_template_decl]
|
|
576
|
+
i_template_decl += 1
|
|
466
577
|
else:
|
|
467
|
-
|
|
578
|
+
template_params = None
|
|
468
579
|
else:
|
|
469
580
|
# take the next template parameter list if there is one
|
|
470
581
|
# otherwise it's ok
|
|
471
|
-
if
|
|
472
|
-
|
|
473
|
-
|
|
582
|
+
if template_args and i_template_decl < len(template_decls):
|
|
583
|
+
template_params = template_decls[i_template_decl]
|
|
584
|
+
i_template_decl += 1
|
|
474
585
|
else:
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
symbol =
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
586
|
+
template_params = None
|
|
587
|
+
|
|
588
|
+
symbol = parent_symbol._find_first_named_symbol(
|
|
589
|
+
ident_or_op,
|
|
590
|
+
template_params,
|
|
591
|
+
template_args,
|
|
592
|
+
template_shorthand=template_shorthand,
|
|
593
|
+
match_self=match_self,
|
|
594
|
+
recurse_in_anon=recurse_in_anon,
|
|
595
|
+
correct_primary_template_args=correct_primary_template_args,
|
|
596
|
+
)
|
|
484
597
|
if symbol is None:
|
|
485
|
-
symbol =
|
|
486
|
-
|
|
598
|
+
symbol = on_missing_qualified_symbol(
|
|
599
|
+
parent_symbol, ident_or_op, template_params, template_args
|
|
600
|
+
)
|
|
487
601
|
if symbol is None:
|
|
488
602
|
if Symbol.debug_lookup:
|
|
489
603
|
Symbol.debug_indent -= 2
|
|
490
604
|
return None
|
|
491
605
|
# We have now matched part of a nested name, and need to match more
|
|
492
|
-
# so even if we should
|
|
493
|
-
# even more.
|
|
494
|
-
|
|
495
|
-
|
|
606
|
+
# so even if we should match_self before, we definitely shouldn't
|
|
607
|
+
# even more.
|
|
608
|
+
# See: https://github.com/sphinx-doc/sphinx/issues/2666
|
|
609
|
+
match_self = False
|
|
610
|
+
parent_symbol = symbol
|
|
496
611
|
|
|
497
612
|
if Symbol.debug_lookup:
|
|
498
|
-
Symbol.debug_print(
|
|
499
|
-
logger.debug(
|
|
613
|
+
Symbol.debug_print('handle last name from:')
|
|
614
|
+
logger.debug(parent_symbol.to_string(Symbol.debug_indent + 1), end='')
|
|
500
615
|
|
|
501
616
|
# handle the last name
|
|
502
617
|
name = names[-1]
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
if
|
|
506
|
-
assert
|
|
507
|
-
|
|
618
|
+
ident_or_op = name.identOrOp
|
|
619
|
+
template_args = name.templateArgs
|
|
620
|
+
if i_template_decl < len(template_decls):
|
|
621
|
+
assert i_template_decl + 1 == len(template_decls)
|
|
622
|
+
template_params = template_decls[i_template_decl]
|
|
508
623
|
else:
|
|
509
|
-
assert
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
symbols =
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
624
|
+
assert i_template_decl == len(template_decls)
|
|
625
|
+
template_params = None
|
|
626
|
+
|
|
627
|
+
symbols = parent_symbol._find_named_symbols(
|
|
628
|
+
ident_or_op,
|
|
629
|
+
template_params,
|
|
630
|
+
template_args,
|
|
631
|
+
template_shorthand=template_shorthand,
|
|
632
|
+
match_self=match_self,
|
|
633
|
+
recurse_in_anon=recurse_in_anon,
|
|
634
|
+
correct_primary_template_args=False,
|
|
635
|
+
search_in_siblings=search_in_siblings,
|
|
636
|
+
)
|
|
517
637
|
if Symbol.debug_lookup:
|
|
518
638
|
symbols = list(symbols) # type: ignore[assignment]
|
|
519
639
|
Symbol.debug_indent -= 2
|
|
520
|
-
return SymbolLookupResult(
|
|
521
|
-
|
|
640
|
+
return SymbolLookupResult(
|
|
641
|
+
symbols, parent_symbol, ident_or_op, template_params, template_args
|
|
642
|
+
)
|
|
522
643
|
|
|
523
644
|
def _add_symbols(
|
|
524
645
|
self,
|
|
525
|
-
|
|
526
|
-
|
|
646
|
+
nested_name: ASTNestedName,
|
|
647
|
+
template_decls: list[Any],
|
|
527
648
|
declaration: ASTDeclaration | None,
|
|
528
649
|
docname: str | None,
|
|
529
650
|
line: int | None,
|
|
@@ -533,175 +654,195 @@ class Symbol:
|
|
|
533
654
|
|
|
534
655
|
if Symbol.debug_lookup:
|
|
535
656
|
Symbol.debug_indent += 1
|
|
536
|
-
Symbol.debug_print(
|
|
657
|
+
Symbol.debug_print('_add_symbols:')
|
|
537
658
|
Symbol.debug_indent += 1
|
|
538
|
-
Symbol.debug_print(
|
|
539
|
-
Symbol.debug_print(
|
|
540
|
-
Symbol.debug_print(
|
|
541
|
-
Symbol.debug_print(f
|
|
542
|
-
|
|
543
|
-
def
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
659
|
+
Symbol.debug_print('tdecls:', ','.join(str(t) for t in template_decls))
|
|
660
|
+
Symbol.debug_print('nn: ', nested_name)
|
|
661
|
+
Symbol.debug_print('decl: ', declaration)
|
|
662
|
+
Symbol.debug_print(f'location: {docname}:{line}')
|
|
663
|
+
|
|
664
|
+
def on_missing_qualified_symbol(
|
|
665
|
+
parent_symbol: Symbol,
|
|
666
|
+
ident_or_op: ASTIdentifier | ASTOperator,
|
|
667
|
+
template_params: Any,
|
|
668
|
+
template_args: ASTTemplateArgs,
|
|
669
|
+
) -> Symbol | None:
|
|
547
670
|
if Symbol.debug_lookup:
|
|
548
671
|
Symbol.debug_indent += 1
|
|
549
|
-
Symbol.debug_print(
|
|
672
|
+
Symbol.debug_print('_add_symbols, on_missing_qualified_symbol:')
|
|
550
673
|
Symbol.debug_indent += 1
|
|
551
|
-
Symbol.debug_print(
|
|
552
|
-
Symbol.debug_print(
|
|
553
|
-
Symbol.debug_print(
|
|
674
|
+
Symbol.debug_print('template_params:', template_params)
|
|
675
|
+
Symbol.debug_print('ident_or_op: ', ident_or_op)
|
|
676
|
+
Symbol.debug_print('template_args: ', template_args)
|
|
554
677
|
Symbol.debug_indent -= 2
|
|
555
|
-
return Symbol(
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
678
|
+
return Symbol(
|
|
679
|
+
parent=parent_symbol,
|
|
680
|
+
identOrOp=ident_or_op,
|
|
681
|
+
templateParams=template_params,
|
|
682
|
+
templateArgs=template_args,
|
|
683
|
+
declaration=None,
|
|
684
|
+
docname=None,
|
|
685
|
+
line=None,
|
|
686
|
+
)
|
|
687
|
+
|
|
688
|
+
lookup_result = self._symbol_lookup(
|
|
689
|
+
nested_name,
|
|
690
|
+
template_decls,
|
|
691
|
+
on_missing_qualified_symbol,
|
|
692
|
+
strict_template_param_arg_lists=True,
|
|
693
|
+
ancestor_lookup_type=None,
|
|
694
|
+
template_shorthand=False,
|
|
695
|
+
match_self=False,
|
|
696
|
+
recurse_in_anon=False,
|
|
697
|
+
correct_primary_template_args=True,
|
|
698
|
+
search_in_siblings=False,
|
|
699
|
+
)
|
|
700
|
+
# we create symbols all the way, so that can't happen
|
|
701
|
+
assert lookup_result is not None
|
|
702
|
+
symbols = list(lookup_result.symbols)
|
|
571
703
|
if len(symbols) == 0:
|
|
572
704
|
if Symbol.debug_lookup:
|
|
573
|
-
Symbol.debug_print(
|
|
705
|
+
Symbol.debug_print('_add_symbols, result, no symbol:')
|
|
574
706
|
Symbol.debug_indent += 1
|
|
575
|
-
Symbol.debug_print(
|
|
576
|
-
Symbol.debug_print(
|
|
577
|
-
Symbol.debug_print(
|
|
578
|
-
Symbol.debug_print(
|
|
579
|
-
Symbol.debug_print(f
|
|
707
|
+
Symbol.debug_print('template_params:', lookup_result.template_params)
|
|
708
|
+
Symbol.debug_print('ident_or_op: ', lookup_result.ident_or_op)
|
|
709
|
+
Symbol.debug_print('template_args: ', lookup_result.template_args)
|
|
710
|
+
Symbol.debug_print('declaration: ', declaration)
|
|
711
|
+
Symbol.debug_print(f'location: {docname}:{line}')
|
|
580
712
|
Symbol.debug_indent -= 1
|
|
581
|
-
symbol = Symbol(
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
713
|
+
symbol = Symbol(
|
|
714
|
+
parent=lookup_result.parent_symbol,
|
|
715
|
+
identOrOp=lookup_result.ident_or_op,
|
|
716
|
+
templateParams=lookup_result.template_params,
|
|
717
|
+
templateArgs=lookup_result.template_args,
|
|
718
|
+
declaration=declaration,
|
|
719
|
+
docname=docname,
|
|
720
|
+
line=line,
|
|
721
|
+
)
|
|
587
722
|
if Symbol.debug_lookup:
|
|
588
723
|
Symbol.debug_indent -= 2
|
|
589
724
|
return symbol
|
|
590
725
|
|
|
591
726
|
if Symbol.debug_lookup:
|
|
592
|
-
Symbol.debug_print(
|
|
727
|
+
Symbol.debug_print('_add_symbols, result, symbols:')
|
|
593
728
|
Symbol.debug_indent += 1
|
|
594
|
-
Symbol.debug_print(
|
|
729
|
+
Symbol.debug_print('number symbols:', len(symbols))
|
|
595
730
|
Symbol.debug_indent -= 1
|
|
596
731
|
|
|
597
732
|
if not declaration:
|
|
598
733
|
if Symbol.debug_lookup:
|
|
599
|
-
Symbol.debug_print(
|
|
734
|
+
Symbol.debug_print('no declaration')
|
|
600
735
|
Symbol.debug_indent -= 2
|
|
601
736
|
# good, just a scope creation
|
|
602
737
|
# TODO: what if we have more than one symbol?
|
|
603
738
|
return symbols[0]
|
|
604
739
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
740
|
+
no_decl = []
|
|
741
|
+
with_decl = []
|
|
742
|
+
dup_decl = []
|
|
608
743
|
for s in symbols:
|
|
609
744
|
if s.declaration is None:
|
|
610
|
-
|
|
745
|
+
no_decl.append(s)
|
|
611
746
|
elif s.isRedeclaration:
|
|
612
|
-
|
|
747
|
+
dup_decl.append(s)
|
|
613
748
|
else:
|
|
614
|
-
|
|
749
|
+
with_decl.append(s)
|
|
615
750
|
if Symbol.debug_lookup:
|
|
616
|
-
Symbol.debug_print(
|
|
617
|
-
Symbol.debug_print(
|
|
618
|
-
Symbol.debug_print(
|
|
751
|
+
Symbol.debug_print('#no_decl: ', len(no_decl))
|
|
752
|
+
Symbol.debug_print('#with_decl:', len(with_decl))
|
|
753
|
+
Symbol.debug_print('#dup_decl: ', len(dup_decl))
|
|
619
754
|
# With partial builds we may start with a large symbol tree stripped of declarations.
|
|
620
|
-
# Essentially any combination of
|
|
755
|
+
# Essentially any combination of no_decl, with_decl, and dup_decls seems possible.
|
|
621
756
|
# TODO: make partial builds fully work. What should happen when the primary symbol gets
|
|
622
757
|
# deleted, and other duplicates exist? The full document should probably be rebuild.
|
|
623
758
|
|
|
624
759
|
# First check if one of those with a declaration matches.
|
|
625
760
|
# If it's a function, we need to compare IDs,
|
|
626
761
|
# otherwise there should be only one symbol with a declaration.
|
|
627
|
-
def
|
|
762
|
+
def make_cand_symbol() -> Symbol:
|
|
628
763
|
if Symbol.debug_lookup:
|
|
629
|
-
Symbol.debug_print(
|
|
630
|
-
symbol = Symbol(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
764
|
+
Symbol.debug_print('begin: creating candidate symbol')
|
|
765
|
+
symbol = Symbol(
|
|
766
|
+
parent=lookup_result.parent_symbol,
|
|
767
|
+
identOrOp=lookup_result.ident_or_op,
|
|
768
|
+
templateParams=lookup_result.template_params,
|
|
769
|
+
templateArgs=lookup_result.template_args,
|
|
770
|
+
declaration=declaration,
|
|
771
|
+
docname=docname,
|
|
772
|
+
line=line,
|
|
773
|
+
)
|
|
636
774
|
if Symbol.debug_lookup:
|
|
637
|
-
Symbol.debug_print(
|
|
775
|
+
Symbol.debug_print('end: creating candidate symbol')
|
|
638
776
|
return symbol
|
|
639
|
-
|
|
640
|
-
|
|
777
|
+
|
|
778
|
+
if len(with_decl) == 0:
|
|
779
|
+
cand_symbol = None
|
|
641
780
|
else:
|
|
642
|
-
|
|
781
|
+
cand_symbol = make_cand_symbol()
|
|
643
782
|
|
|
644
|
-
def
|
|
783
|
+
def handle_duplicate_declaration(
|
|
784
|
+
symbol: Symbol, cand_symbol: Symbol
|
|
785
|
+
) -> None:
|
|
645
786
|
if Symbol.debug_lookup:
|
|
646
787
|
Symbol.debug_indent += 1
|
|
647
|
-
Symbol.debug_print(
|
|
788
|
+
Symbol.debug_print('redeclaration')
|
|
648
789
|
Symbol.debug_indent -= 1
|
|
649
790
|
Symbol.debug_indent -= 2
|
|
650
791
|
# Redeclaration of the same symbol.
|
|
651
792
|
# Let the new one be there, but raise an error to the client
|
|
652
793
|
# so it can use the real symbol as subscope.
|
|
653
794
|
# This will probably result in a duplicate id warning.
|
|
654
|
-
|
|
795
|
+
cand_symbol.isRedeclaration = True
|
|
655
796
|
raise _DuplicateSymbolError(symbol, declaration)
|
|
656
797
|
|
|
657
|
-
if declaration.objectType !=
|
|
658
|
-
assert len(
|
|
659
|
-
|
|
798
|
+
if declaration.objectType != 'function':
|
|
799
|
+
assert len(with_decl) <= 1
|
|
800
|
+
handle_duplicate_declaration(with_decl[0], cand_symbol)
|
|
660
801
|
# (not reachable)
|
|
661
802
|
|
|
662
803
|
# a function, so compare IDs
|
|
663
|
-
|
|
804
|
+
cand_id = declaration.get_newest_id()
|
|
664
805
|
if Symbol.debug_lookup:
|
|
665
|
-
Symbol.debug_print(
|
|
666
|
-
for symbol in
|
|
806
|
+
Symbol.debug_print('cand_id:', cand_id)
|
|
807
|
+
for symbol in with_decl:
|
|
667
808
|
# but all existing must be functions as well,
|
|
668
809
|
# otherwise we declare it to be a duplicate
|
|
669
810
|
if symbol.declaration.objectType != 'function':
|
|
670
|
-
|
|
811
|
+
handle_duplicate_declaration(symbol, cand_symbol)
|
|
671
812
|
# (not reachable)
|
|
672
|
-
|
|
813
|
+
old_id = symbol.declaration.get_newest_id()
|
|
673
814
|
if Symbol.debug_lookup:
|
|
674
|
-
Symbol.debug_print(
|
|
675
|
-
if
|
|
676
|
-
|
|
815
|
+
Symbol.debug_print('old_id: ', old_id)
|
|
816
|
+
if cand_id == old_id:
|
|
817
|
+
handle_duplicate_declaration(symbol, cand_symbol)
|
|
677
818
|
# (not reachable)
|
|
678
819
|
# no candidate symbol found with matching ID
|
|
679
820
|
# if there is an empty symbol, fill that one
|
|
680
|
-
if len(
|
|
821
|
+
if len(no_decl) == 0:
|
|
681
822
|
if Symbol.debug_lookup:
|
|
682
|
-
Symbol.debug_print(
|
|
683
|
-
if
|
|
684
|
-
Symbol.debug_print(
|
|
823
|
+
Symbol.debug_print('no match, no empty')
|
|
824
|
+
if cand_symbol is not None:
|
|
825
|
+
Symbol.debug_print('result is already created cand_symbol')
|
|
685
826
|
else:
|
|
686
|
-
Symbol.debug_print(
|
|
827
|
+
Symbol.debug_print('result is make_cand_symbol()')
|
|
687
828
|
Symbol.debug_indent -= 2
|
|
688
|
-
if
|
|
689
|
-
return
|
|
829
|
+
if cand_symbol is not None:
|
|
830
|
+
return cand_symbol
|
|
690
831
|
else:
|
|
691
|
-
return
|
|
832
|
+
return make_cand_symbol()
|
|
692
833
|
else:
|
|
693
834
|
if Symbol.debug_lookup:
|
|
694
835
|
Symbol.debug_print(
|
|
695
|
-
|
|
696
|
-
|
|
836
|
+
'no match, but fill an empty declaration, cand_sybmol is not None?:',
|
|
837
|
+
cand_symbol is not None,
|
|
697
838
|
)
|
|
698
839
|
Symbol.debug_indent -= 2
|
|
699
|
-
if
|
|
700
|
-
|
|
701
|
-
# assert len(
|
|
840
|
+
if cand_symbol is not None:
|
|
841
|
+
cand_symbol.remove()
|
|
842
|
+
# assert len(no_decl) == 1
|
|
702
843
|
# TODO: enable assertion when we at some point find out how to do cleanup
|
|
703
844
|
# for now, just take the first one, it should work fine ... right?
|
|
704
|
-
symbol =
|
|
845
|
+
symbol = no_decl[0]
|
|
705
846
|
# If someone first opened the scope, and then later
|
|
706
847
|
# declares it, e.g,
|
|
707
848
|
# .. namespace:: Test
|
|
@@ -710,98 +851,118 @@ class Symbol:
|
|
|
710
851
|
symbol._fill_empty(declaration, docname, line)
|
|
711
852
|
return symbol
|
|
712
853
|
|
|
713
|
-
def merge_with(
|
|
714
|
-
|
|
854
|
+
def merge_with(
|
|
855
|
+
self, other: Symbol, docnames: list[str], env: BuildEnvironment
|
|
856
|
+
) -> None:
|
|
715
857
|
if Symbol.debug_lookup:
|
|
716
858
|
Symbol.debug_indent += 1
|
|
717
|
-
Symbol.debug_print(
|
|
859
|
+
Symbol.debug_print('merge_with:')
|
|
718
860
|
assert other is not None
|
|
719
861
|
|
|
720
|
-
def
|
|
862
|
+
def unconditional_add(self: Symbol, other_child: Symbol) -> None:
|
|
721
863
|
# TODO: hmm, should we prune by docnames?
|
|
722
|
-
self._children.append(
|
|
723
|
-
|
|
724
|
-
|
|
864
|
+
self._children.append(other_child)
|
|
865
|
+
other_child.parent = self
|
|
866
|
+
other_child._assert_invariants()
|
|
725
867
|
|
|
726
868
|
if Symbol.debug_lookup:
|
|
727
869
|
Symbol.debug_indent += 1
|
|
728
|
-
for
|
|
870
|
+
for other_child in other._children:
|
|
729
871
|
if Symbol.debug_lookup:
|
|
730
|
-
Symbol.debug_print(
|
|
872
|
+
Symbol.debug_print(
|
|
873
|
+
'other_child:\n', other_child.to_string(Symbol.debug_indent)
|
|
874
|
+
)
|
|
731
875
|
Symbol.debug_indent += 1
|
|
732
|
-
if
|
|
733
|
-
|
|
876
|
+
if other_child.isRedeclaration:
|
|
877
|
+
unconditional_add(self, other_child)
|
|
734
878
|
if Symbol.debug_lookup:
|
|
735
|
-
Symbol.debug_print(
|
|
879
|
+
Symbol.debug_print('is_redeclaration')
|
|
736
880
|
Symbol.debug_indent -= 1
|
|
737
881
|
continue
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
882
|
+
candiate_iter = self._find_named_symbols(
|
|
883
|
+
ident_or_op=other_child.identOrOp,
|
|
884
|
+
template_params=other_child.templateParams,
|
|
885
|
+
template_args=other_child.templateArgs,
|
|
886
|
+
template_shorthand=False,
|
|
887
|
+
match_self=False,
|
|
888
|
+
recurse_in_anon=False,
|
|
889
|
+
correct_primary_template_args=False,
|
|
890
|
+
search_in_siblings=False,
|
|
891
|
+
)
|
|
892
|
+
candidates = list(candiate_iter)
|
|
746
893
|
|
|
747
894
|
if Symbol.debug_lookup:
|
|
748
|
-
Symbol.debug_print(
|
|
895
|
+
Symbol.debug_print('raw candidate symbols:', len(candidates))
|
|
749
896
|
symbols = [s for s in candidates if not s.isRedeclaration]
|
|
750
897
|
if Symbol.debug_lookup:
|
|
751
|
-
Symbol.debug_print(
|
|
898
|
+
Symbol.debug_print('non-duplicate candidate symbols:', len(symbols))
|
|
752
899
|
|
|
753
900
|
if len(symbols) == 0:
|
|
754
|
-
|
|
901
|
+
unconditional_add(self, other_child)
|
|
755
902
|
if Symbol.debug_lookup:
|
|
756
903
|
Symbol.debug_indent -= 1
|
|
757
904
|
continue
|
|
758
905
|
|
|
759
|
-
|
|
760
|
-
if
|
|
906
|
+
our_child = None
|
|
907
|
+
if other_child.declaration is None:
|
|
761
908
|
if Symbol.debug_lookup:
|
|
762
|
-
Symbol.debug_print(
|
|
763
|
-
|
|
909
|
+
Symbol.debug_print('no declaration in other child')
|
|
910
|
+
our_child = symbols[0]
|
|
764
911
|
else:
|
|
765
|
-
|
|
912
|
+
query_id = other_child.declaration.get_newest_id()
|
|
766
913
|
if Symbol.debug_lookup:
|
|
767
|
-
Symbol.debug_print(
|
|
914
|
+
Symbol.debug_print('query_id: ', query_id)
|
|
768
915
|
for symbol in symbols:
|
|
769
916
|
if symbol.declaration is None:
|
|
770
917
|
if Symbol.debug_lookup:
|
|
771
|
-
Symbol.debug_print(
|
|
918
|
+
Symbol.debug_print('empty candidate')
|
|
772
919
|
# if in the end we have non-matching, but have an empty one,
|
|
773
920
|
# then just continue with that
|
|
774
|
-
|
|
921
|
+
our_child = symbol
|
|
775
922
|
continue
|
|
776
|
-
|
|
923
|
+
cand_id = symbol.declaration.get_newest_id()
|
|
777
924
|
if Symbol.debug_lookup:
|
|
778
|
-
Symbol.debug_print(
|
|
779
|
-
if
|
|
780
|
-
|
|
925
|
+
Symbol.debug_print('candidate:', cand_id)
|
|
926
|
+
if cand_id == query_id:
|
|
927
|
+
our_child = symbol
|
|
781
928
|
break
|
|
782
929
|
if Symbol.debug_lookup:
|
|
783
930
|
Symbol.debug_indent -= 1
|
|
784
|
-
if
|
|
785
|
-
|
|
931
|
+
if our_child is None:
|
|
932
|
+
unconditional_add(self, other_child)
|
|
786
933
|
continue
|
|
787
|
-
if
|
|
788
|
-
if not
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
934
|
+
if other_child.declaration and other_child.docname in docnames:
|
|
935
|
+
if not our_child.declaration:
|
|
936
|
+
our_child._fill_empty(
|
|
937
|
+
other_child.declaration, other_child.docname, other_child.line
|
|
938
|
+
)
|
|
939
|
+
elif our_child.docname != other_child.docname:
|
|
940
|
+
name = str(our_child.declaration)
|
|
941
|
+
msg = __(
|
|
942
|
+
'Duplicate C++ declaration, also defined at %s:%s.\n'
|
|
943
|
+
"Declaration is '.. cpp:%s:: %s'."
|
|
944
|
+
)
|
|
945
|
+
logger.warning(
|
|
946
|
+
msg,
|
|
947
|
+
our_child.docname,
|
|
948
|
+
our_child.line,
|
|
949
|
+
our_child.declaration.directiveType,
|
|
950
|
+
name,
|
|
951
|
+
location=(other_child.docname, other_child.line),
|
|
952
|
+
type='duplicate_declaration',
|
|
953
|
+
subtype='cpp',
|
|
954
|
+
)
|
|
798
955
|
else:
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
956
|
+
our_object_type = our_child.declaration.objectType
|
|
957
|
+
other_object_type = other_child.declaration.objectType
|
|
958
|
+
our_child_parent_decl = our_child.parent.declaration
|
|
959
|
+
other_child_parent_decl = other_child.parent.declaration
|
|
960
|
+
if (
|
|
961
|
+
other_object_type == our_object_type
|
|
962
|
+
and other_object_type in {'templateParam', 'functionParam'}
|
|
963
|
+
and our_child_parent_decl == other_child_parent_decl
|
|
964
|
+
):
|
|
965
|
+
# `our_child` was just created during merging by the call
|
|
805
966
|
# to `_fill_empty` on the parent and can be ignored.
|
|
806
967
|
pass
|
|
807
968
|
else:
|
|
@@ -809,70 +970,82 @@ class Symbol:
|
|
|
809
970
|
# This can apparently happen, it should be safe to
|
|
810
971
|
# just ignore it, right?
|
|
811
972
|
# Hmm, only on duplicate declarations, right?
|
|
812
|
-
msg =
|
|
813
|
-
msg +=
|
|
814
|
-
msg +=
|
|
815
|
-
logger.warning(msg, location=
|
|
816
|
-
|
|
973
|
+
msg = 'Internal C++ domain error during symbol merging.\n'
|
|
974
|
+
msg += 'our_child:\n' + our_child.to_string(1)
|
|
975
|
+
msg += '\nother_child:\n' + other_child.to_string(1)
|
|
976
|
+
logger.warning(msg, location=other_child.docname)
|
|
977
|
+
our_child.merge_with(other_child, docnames, env)
|
|
817
978
|
if Symbol.debug_lookup:
|
|
818
979
|
Symbol.debug_indent -= 2
|
|
819
980
|
|
|
820
|
-
def add_name(
|
|
821
|
-
|
|
981
|
+
def add_name(
|
|
982
|
+
self,
|
|
983
|
+
nestedName: ASTNestedName,
|
|
984
|
+
templatePrefix: ASTTemplateDeclarationPrefix | None = None,
|
|
985
|
+
) -> Symbol:
|
|
822
986
|
if Symbol.debug_lookup:
|
|
823
987
|
Symbol.debug_indent += 1
|
|
824
|
-
Symbol.debug_print(
|
|
988
|
+
Symbol.debug_print('add_name:')
|
|
825
989
|
if templatePrefix:
|
|
826
|
-
|
|
990
|
+
template_decls = templatePrefix.templates
|
|
827
991
|
else:
|
|
828
|
-
|
|
829
|
-
res = self._add_symbols(
|
|
830
|
-
|
|
992
|
+
template_decls = []
|
|
993
|
+
res = self._add_symbols(
|
|
994
|
+
nestedName, template_decls, declaration=None, docname=None, line=None
|
|
995
|
+
)
|
|
831
996
|
if Symbol.debug_lookup:
|
|
832
997
|
Symbol.debug_indent -= 1
|
|
833
998
|
return res
|
|
834
999
|
|
|
835
|
-
def add_declaration(
|
|
836
|
-
|
|
1000
|
+
def add_declaration(
|
|
1001
|
+
self, declaration: ASTDeclaration, docname: str, line: int
|
|
1002
|
+
) -> Symbol:
|
|
837
1003
|
if Symbol.debug_lookup:
|
|
838
1004
|
Symbol.debug_indent += 1
|
|
839
|
-
Symbol.debug_print(
|
|
1005
|
+
Symbol.debug_print('add_declaration:')
|
|
840
1006
|
assert declaration is not None
|
|
841
1007
|
assert docname is not None
|
|
842
1008
|
assert line is not None
|
|
843
|
-
|
|
1009
|
+
nested_name = declaration.name
|
|
844
1010
|
if declaration.templatePrefix:
|
|
845
|
-
|
|
1011
|
+
template_decls = declaration.templatePrefix.templates
|
|
846
1012
|
else:
|
|
847
|
-
|
|
848
|
-
res = self._add_symbols(
|
|
1013
|
+
template_decls = []
|
|
1014
|
+
res = self._add_symbols(nested_name, template_decls, declaration, docname, line)
|
|
849
1015
|
if Symbol.debug_lookup:
|
|
850
1016
|
Symbol.debug_indent -= 1
|
|
851
1017
|
return res
|
|
852
1018
|
|
|
853
|
-
def find_identifier(
|
|
854
|
-
|
|
855
|
-
|
|
1019
|
+
def find_identifier(
|
|
1020
|
+
self,
|
|
1021
|
+
identOrOp: ASTIdentifier | ASTOperator,
|
|
1022
|
+
matchSelf: bool,
|
|
1023
|
+
recurseInAnon: bool,
|
|
1024
|
+
searchInSiblings: bool,
|
|
1025
|
+
) -> Symbol | None:
|
|
856
1026
|
if Symbol.debug_lookup:
|
|
857
1027
|
Symbol.debug_indent += 1
|
|
858
|
-
Symbol.debug_print(
|
|
1028
|
+
Symbol.debug_print('find_identifier:')
|
|
859
1029
|
Symbol.debug_indent += 1
|
|
860
|
-
Symbol.debug_print(
|
|
861
|
-
Symbol.debug_print(
|
|
862
|
-
Symbol.debug_print(
|
|
863
|
-
Symbol.debug_print(
|
|
864
|
-
logger.debug(self.to_string(Symbol.debug_indent + 1), end=
|
|
1030
|
+
Symbol.debug_print('identOrOp: ', identOrOp)
|
|
1031
|
+
Symbol.debug_print('matchSelf: ', matchSelf)
|
|
1032
|
+
Symbol.debug_print('recurseInAnon: ', recurseInAnon)
|
|
1033
|
+
Symbol.debug_print('searchInSiblings:', searchInSiblings)
|
|
1034
|
+
logger.debug(self.to_string(Symbol.debug_indent + 1), end='')
|
|
865
1035
|
Symbol.debug_indent -= 2
|
|
866
1036
|
current = self
|
|
867
1037
|
while current is not None:
|
|
868
1038
|
if Symbol.debug_lookup:
|
|
869
1039
|
Symbol.debug_indent += 2
|
|
870
|
-
Symbol.debug_print(
|
|
871
|
-
logger.debug(current.to_string(Symbol.debug_indent + 1), end=
|
|
1040
|
+
Symbol.debug_print('trying:')
|
|
1041
|
+
logger.debug(current.to_string(Symbol.debug_indent + 1), end='')
|
|
872
1042
|
Symbol.debug_indent -= 2
|
|
873
1043
|
if matchSelf and current.identOrOp == identOrOp:
|
|
874
1044
|
return current
|
|
875
|
-
|
|
1045
|
+
if recurseInAnon:
|
|
1046
|
+
children: Iterable[Symbol] = current.children_recurse_anon
|
|
1047
|
+
else:
|
|
1048
|
+
children = current._children
|
|
876
1049
|
for s in children:
|
|
877
1050
|
if s.identOrOp == identOrOp:
|
|
878
1051
|
return s
|
|
@@ -884,10 +1057,10 @@ class Symbol:
|
|
|
884
1057
|
def direct_lookup(self, key: LookupKey) -> Symbol:
|
|
885
1058
|
if Symbol.debug_lookup:
|
|
886
1059
|
Symbol.debug_indent += 1
|
|
887
|
-
Symbol.debug_print(
|
|
1060
|
+
Symbol.debug_print('direct_lookup:')
|
|
888
1061
|
Symbol.debug_indent += 1
|
|
889
1062
|
s = self
|
|
890
|
-
for name,
|
|
1063
|
+
for name, template_params, id_ in key.data:
|
|
891
1064
|
if id_ is not None:
|
|
892
1065
|
res = None
|
|
893
1066
|
for cand in s._children:
|
|
@@ -898,22 +1071,25 @@ class Symbol:
|
|
|
898
1071
|
break
|
|
899
1072
|
s = res
|
|
900
1073
|
else:
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
s = s._find_first_named_symbol(
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1074
|
+
ident_or_op = name.identOrOp
|
|
1075
|
+
template_args = name.templateArgs
|
|
1076
|
+
s = s._find_first_named_symbol(
|
|
1077
|
+
ident_or_op,
|
|
1078
|
+
template_params,
|
|
1079
|
+
template_args,
|
|
1080
|
+
template_shorthand=False,
|
|
1081
|
+
match_self=False,
|
|
1082
|
+
recurse_in_anon=False,
|
|
1083
|
+
correct_primary_template_args=False,
|
|
1084
|
+
)
|
|
909
1085
|
if Symbol.debug_lookup:
|
|
910
|
-
Symbol.debug_print(
|
|
911
|
-
Symbol.debug_print(
|
|
912
|
-
Symbol.debug_print(
|
|
1086
|
+
Symbol.debug_print('name: ', name)
|
|
1087
|
+
Symbol.debug_print('template_params:', template_params)
|
|
1088
|
+
Symbol.debug_print('id: ', id_)
|
|
913
1089
|
if s is not None:
|
|
914
|
-
logger.debug(s.to_string(Symbol.debug_indent + 1), end=
|
|
1090
|
+
logger.debug(s.to_string(Symbol.debug_indent + 1), end='')
|
|
915
1091
|
else:
|
|
916
|
-
Symbol.debug_print(
|
|
1092
|
+
Symbol.debug_print('not found')
|
|
917
1093
|
if s is None:
|
|
918
1094
|
if Symbol.debug_lookup:
|
|
919
1095
|
Symbol.debug_indent -= 2
|
|
@@ -937,68 +1113,78 @@ class Symbol:
|
|
|
937
1113
|
# then the second component _may_ be a string explaining why.
|
|
938
1114
|
if Symbol.debug_lookup:
|
|
939
1115
|
Symbol.debug_indent += 1
|
|
940
|
-
Symbol.debug_print(
|
|
1116
|
+
Symbol.debug_print('find_name:')
|
|
941
1117
|
Symbol.debug_indent += 1
|
|
942
|
-
Symbol.debug_print(
|
|
943
|
-
logger.debug(self.to_string(Symbol.debug_indent + 1), end=
|
|
944
|
-
Symbol.debug_print(
|
|
945
|
-
Symbol.debug_print(
|
|
946
|
-
Symbol.debug_print(
|
|
947
|
-
Symbol.debug_print(
|
|
948
|
-
Symbol.debug_print(
|
|
949
|
-
Symbol.debug_print(
|
|
950
|
-
Symbol.debug_print(
|
|
1118
|
+
Symbol.debug_print('self:')
|
|
1119
|
+
logger.debug(self.to_string(Symbol.debug_indent + 1), end='')
|
|
1120
|
+
Symbol.debug_print('nestedName: ', nestedName)
|
|
1121
|
+
Symbol.debug_print('templateDecls: ', templateDecls)
|
|
1122
|
+
Symbol.debug_print('typ: ', typ)
|
|
1123
|
+
Symbol.debug_print('templateShorthand:', templateShorthand)
|
|
1124
|
+
Symbol.debug_print('matchSelf: ', matchSelf)
|
|
1125
|
+
Symbol.debug_print('recurseInAnon: ', recurseInAnon)
|
|
1126
|
+
Symbol.debug_print('searchInSiblings: ', searchInSiblings)
|
|
951
1127
|
|
|
952
1128
|
class QualifiedSymbolIsTemplateParam(Exception):
|
|
953
1129
|
pass
|
|
954
1130
|
|
|
955
|
-
def
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
1131
|
+
def on_missing_qualified_symbol(
|
|
1132
|
+
parent_symbol: Symbol,
|
|
1133
|
+
ident_or_op: ASTIdentifier | ASTOperator,
|
|
1134
|
+
template_params: Any,
|
|
1135
|
+
template_args: ASTTemplateArgs,
|
|
1136
|
+
) -> Symbol | None:
|
|
959
1137
|
# TODO: Maybe search without template args?
|
|
960
|
-
# Though, the
|
|
1138
|
+
# Though, the correct_primary_template_args does
|
|
961
1139
|
# that for primary templates.
|
|
962
1140
|
# Is there another case where it would be good?
|
|
963
|
-
if
|
|
964
|
-
if
|
|
1141
|
+
if parent_symbol.declaration is not None:
|
|
1142
|
+
if parent_symbol.declaration.objectType == 'templateParam':
|
|
965
1143
|
raise QualifiedSymbolIsTemplateParam
|
|
966
1144
|
return None
|
|
967
1145
|
|
|
968
1146
|
try:
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1147
|
+
lookup_result = self._symbol_lookup(
|
|
1148
|
+
nestedName,
|
|
1149
|
+
templateDecls,
|
|
1150
|
+
on_missing_qualified_symbol,
|
|
1151
|
+
strict_template_param_arg_lists=False,
|
|
1152
|
+
ancestor_lookup_type=typ,
|
|
1153
|
+
template_shorthand=templateShorthand,
|
|
1154
|
+
match_self=matchSelf,
|
|
1155
|
+
recurse_in_anon=recurseInAnon,
|
|
1156
|
+
correct_primary_template_args=False,
|
|
1157
|
+
search_in_siblings=searchInSiblings,
|
|
1158
|
+
)
|
|
978
1159
|
except QualifiedSymbolIsTemplateParam:
|
|
979
|
-
return None,
|
|
1160
|
+
return None, 'templateParamInQualified'
|
|
980
1161
|
|
|
981
|
-
if
|
|
1162
|
+
if lookup_result is None:
|
|
982
1163
|
# if it was a part of the qualification that could not be found
|
|
983
1164
|
if Symbol.debug_lookup:
|
|
984
1165
|
Symbol.debug_indent -= 2
|
|
985
1166
|
return None, None
|
|
986
1167
|
|
|
987
|
-
res = list(
|
|
1168
|
+
res = list(lookup_result.symbols)
|
|
988
1169
|
if len(res) != 0:
|
|
989
1170
|
if Symbol.debug_lookup:
|
|
990
1171
|
Symbol.debug_indent -= 2
|
|
991
1172
|
return res, None
|
|
992
1173
|
|
|
993
|
-
if
|
|
994
|
-
if
|
|
995
|
-
return None,
|
|
1174
|
+
if lookup_result.parent_symbol.declaration is not None:
|
|
1175
|
+
if lookup_result.parent_symbol.declaration.objectType == 'templateParam':
|
|
1176
|
+
return None, 'templateParamInQualified'
|
|
996
1177
|
|
|
997
1178
|
# try without template params and args
|
|
998
|
-
symbol =
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1179
|
+
symbol = lookup_result.parent_symbol._find_first_named_symbol(
|
|
1180
|
+
lookup_result.ident_or_op,
|
|
1181
|
+
None,
|
|
1182
|
+
None,
|
|
1183
|
+
template_shorthand=templateShorthand,
|
|
1184
|
+
match_self=matchSelf,
|
|
1185
|
+
recurse_in_anon=recurseInAnon,
|
|
1186
|
+
correct_primary_template_args=False,
|
|
1187
|
+
)
|
|
1002
1188
|
if Symbol.debug_lookup:
|
|
1003
1189
|
Symbol.debug_indent -= 2
|
|
1004
1190
|
if symbol is not None:
|
|
@@ -1006,58 +1192,71 @@ class Symbol:
|
|
|
1006
1192
|
else:
|
|
1007
1193
|
return None, None
|
|
1008
1194
|
|
|
1009
|
-
def find_declaration(
|
|
1010
|
-
|
|
1195
|
+
def find_declaration(
|
|
1196
|
+
self,
|
|
1197
|
+
declaration: ASTDeclaration,
|
|
1198
|
+
typ: str,
|
|
1199
|
+
templateShorthand: bool,
|
|
1200
|
+
matchSelf: bool,
|
|
1201
|
+
recurseInAnon: bool,
|
|
1202
|
+
) -> Symbol | None:
|
|
1011
1203
|
# templateShorthand: missing template parameter lists for templates is ok
|
|
1012
1204
|
if Symbol.debug_lookup:
|
|
1013
1205
|
Symbol.debug_indent += 1
|
|
1014
|
-
Symbol.debug_print(
|
|
1015
|
-
|
|
1206
|
+
Symbol.debug_print('find_declaration:')
|
|
1207
|
+
nested_name = declaration.name
|
|
1016
1208
|
if declaration.templatePrefix:
|
|
1017
|
-
|
|
1209
|
+
template_decls = declaration.templatePrefix.templates
|
|
1018
1210
|
else:
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
def
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1211
|
+
template_decls = []
|
|
1212
|
+
|
|
1213
|
+
def on_missing_qualified_symbol(
|
|
1214
|
+
parent_symbol: Symbol,
|
|
1215
|
+
ident_or_op: ASTIdentifier | ASTOperator,
|
|
1216
|
+
template_params: Any,
|
|
1217
|
+
template_args: ASTTemplateArgs,
|
|
1218
|
+
) -> Symbol | None:
|
|
1025
1219
|
return None
|
|
1026
1220
|
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1221
|
+
lookup_result = self._symbol_lookup(
|
|
1222
|
+
nested_name,
|
|
1223
|
+
template_decls,
|
|
1224
|
+
on_missing_qualified_symbol,
|
|
1225
|
+
strict_template_param_arg_lists=False,
|
|
1226
|
+
ancestor_lookup_type=typ,
|
|
1227
|
+
template_shorthand=templateShorthand,
|
|
1228
|
+
match_self=matchSelf,
|
|
1229
|
+
recurse_in_anon=recurseInAnon,
|
|
1230
|
+
correct_primary_template_args=False,
|
|
1231
|
+
search_in_siblings=False,
|
|
1232
|
+
)
|
|
1036
1233
|
if Symbol.debug_lookup:
|
|
1037
1234
|
Symbol.debug_indent -= 1
|
|
1038
|
-
if
|
|
1235
|
+
if lookup_result is None:
|
|
1039
1236
|
return None
|
|
1040
1237
|
|
|
1041
|
-
symbols = list(
|
|
1238
|
+
symbols = list(lookup_result.symbols)
|
|
1042
1239
|
if len(symbols) == 0:
|
|
1043
1240
|
return None
|
|
1044
1241
|
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1242
|
+
query_symbol = Symbol(
|
|
1243
|
+
parent=lookup_result.parent_symbol,
|
|
1244
|
+
identOrOp=lookup_result.ident_or_op,
|
|
1245
|
+
templateParams=lookup_result.template_params,
|
|
1246
|
+
templateArgs=lookup_result.template_args,
|
|
1247
|
+
declaration=declaration,
|
|
1248
|
+
docname='fakeDocnameForQuery',
|
|
1249
|
+
line=42,
|
|
1250
|
+
)
|
|
1251
|
+
query_id = declaration.get_newest_id()
|
|
1053
1252
|
for symbol in symbols:
|
|
1054
1253
|
if symbol.declaration is None:
|
|
1055
1254
|
continue
|
|
1056
|
-
|
|
1057
|
-
if
|
|
1058
|
-
|
|
1255
|
+
cand_id = symbol.declaration.get_newest_id()
|
|
1256
|
+
if cand_id == query_id:
|
|
1257
|
+
query_symbol.remove()
|
|
1059
1258
|
return symbol
|
|
1060
|
-
|
|
1259
|
+
query_symbol.remove()
|
|
1061
1260
|
return None
|
|
1062
1261
|
|
|
1063
1262
|
def to_string(self, indent: int) -> str:
|
|
@@ -1066,9 +1265,11 @@ class Symbol:
|
|
|
1066
1265
|
res.append('::')
|
|
1067
1266
|
else:
|
|
1068
1267
|
if self.templateParams:
|
|
1069
|
-
res.
|
|
1070
|
-
|
|
1071
|
-
|
|
1268
|
+
res.extend((
|
|
1269
|
+
str(self.templateParams),
|
|
1270
|
+
'\n',
|
|
1271
|
+
Symbol.debug_indent_string * indent,
|
|
1272
|
+
))
|
|
1072
1273
|
if self.identOrOp:
|
|
1073
1274
|
res.append(str(self.identOrOp))
|
|
1074
1275
|
else:
|
|
@@ -1076,15 +1277,17 @@ class Symbol:
|
|
|
1076
1277
|
if self.templateArgs:
|
|
1077
1278
|
res.append(str(self.templateArgs))
|
|
1078
1279
|
if self.declaration:
|
|
1079
|
-
res.append(
|
|
1280
|
+
res.append(': ')
|
|
1080
1281
|
if self.isRedeclaration:
|
|
1081
1282
|
res.append('!!duplicate!! ')
|
|
1082
|
-
res.
|
|
1083
|
-
|
|
1283
|
+
res.extend((
|
|
1284
|
+
'{',
|
|
1285
|
+
self.declaration.objectType,
|
|
1286
|
+
'} ',
|
|
1287
|
+
str(self.declaration),
|
|
1288
|
+
))
|
|
1084
1289
|
if self.docname:
|
|
1085
|
-
res.
|
|
1086
|
-
res.append(self.docname)
|
|
1087
|
-
res.append(')')
|
|
1290
|
+
res.extend(('\t(', self.docname, ')'))
|
|
1088
1291
|
res.append('\n')
|
|
1089
1292
|
return ''.join(res)
|
|
1090
1293
|
|