mirror of
https://github.com/boostorg/docca.git
synced 2026-01-19 04:12:08 +00:00
collect bases when Doxygen fails to
This commit is contained in:
68
docca.py
68
docca.py
@@ -474,8 +474,10 @@ def make_url_link(element, index, allow_missing_refs=False):
|
||||
def make_linebreak(element, index, allow_missing_refs=None):
|
||||
return Linebreak()
|
||||
|
||||
def make_entity_reference(element, index, allow_missing_refs=False):
|
||||
refid = element.get('refid')
|
||||
def make_entity_reference(
|
||||
element, index, refid=None, allow_missing_refs=False
|
||||
):
|
||||
refid = refid or element.get('refid')
|
||||
assert refid
|
||||
|
||||
target = index.get(refid)
|
||||
@@ -562,6 +564,41 @@ class Entity():
|
||||
result.append(self)
|
||||
return result
|
||||
|
||||
def lookup(self, qname):
|
||||
name_parts = qname.split('::')
|
||||
if not name_parts:
|
||||
return
|
||||
|
||||
scope = self
|
||||
while scope is not None:
|
||||
if scope.name == name_parts[0]:
|
||||
break
|
||||
else:
|
||||
found = None
|
||||
for entity in scope.members.values():
|
||||
if entity.name == name_parts[0]:
|
||||
found = entity
|
||||
break
|
||||
if found is None:
|
||||
scope = scope.scope
|
||||
else:
|
||||
break
|
||||
if not scope:
|
||||
return
|
||||
|
||||
for part in name_parts:
|
||||
if scope.name != part:
|
||||
found = None
|
||||
for entity in scope.members.values():
|
||||
if entity.name == part:
|
||||
found = entity
|
||||
break
|
||||
scope = found
|
||||
if found is None:
|
||||
break
|
||||
|
||||
return scope
|
||||
|
||||
def resolve_references(self):
|
||||
self.brief = make_blocks(self._brief, self.index)
|
||||
delattr(self, '_brief')
|
||||
@@ -569,6 +606,9 @@ class Entity():
|
||||
self.description = make_blocks(self._description, self.index)
|
||||
delattr(self, '_description')
|
||||
|
||||
def update_scopes(self):
|
||||
pass
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.name < other.name
|
||||
|
||||
@@ -587,8 +627,8 @@ class Compound(Entity):
|
||||
section.get('prot', Access.public),
|
||||
section.get('refid')))
|
||||
|
||||
def resolve_references(self):
|
||||
super().resolve_references()
|
||||
def update_scopes(self):
|
||||
super().update_scopes()
|
||||
|
||||
for access, refid in self._nested:
|
||||
entity = self.index[refid]
|
||||
@@ -599,6 +639,11 @@ class Compound(Entity):
|
||||
self.members[entity.name] = entity
|
||||
delattr(self, '_nested')
|
||||
|
||||
def resolve_references(self):
|
||||
super().resolve_references()
|
||||
if getattr(self, '_nested', None):
|
||||
self.update_scopes()
|
||||
|
||||
|
||||
class Member(Entity):
|
||||
nametag = 'name'
|
||||
@@ -727,14 +772,22 @@ class Class(Scope, Compound, Type):
|
||||
self.bases = [Generalization(entry, self) for entry in self._bases]
|
||||
delattr(self, '_bases')
|
||||
|
||||
|
||||
class Generalization():
|
||||
def __init__(self, element, derived):
|
||||
self.is_virtual = element.get('virt') == 'virtual'
|
||||
self.access = element.get('prot')
|
||||
assert self.access
|
||||
|
||||
if element.get('refid'):
|
||||
self.base = Phrase([make_entity_reference(element, derived.index)])
|
||||
refid = element.get('refid')
|
||||
if not refid:
|
||||
entity = derived.lookup( ''.join(element.itertext()).strip() )
|
||||
if entity is not None:
|
||||
refid = entity.id
|
||||
|
||||
if refid:
|
||||
self.base = Phrase(
|
||||
[make_entity_reference(element, derived.index, refid)])
|
||||
else:
|
||||
self.base = text_with_refs(element, derived.index)
|
||||
|
||||
@@ -1123,6 +1176,9 @@ def collect_data(parent_dir, refs):
|
||||
|
||||
for entity in result.values():
|
||||
assert entity is not None
|
||||
entity.update_scopes()
|
||||
|
||||
for entity in result.values():
|
||||
entity.resolve_references();
|
||||
|
||||
return result
|
||||
|
||||
@@ -584,6 +584,12 @@ def test_namespace():
|
||||
assert ns.location.file == 'some/file.cpp'
|
||||
assert ns.location.line == 100
|
||||
assert ns.location.column == 12
|
||||
assert ns.lookup('MyNs') == ns
|
||||
assert ns.lookup('OtherNs') == ns2
|
||||
assert ns.lookup('OtherNs::MyNs') == ns
|
||||
assert ns2.lookup('OtherNs') == ns2
|
||||
assert ns2.lookup('MyNs') == ns
|
||||
assert ns2.lookup('OtherNs::MyNs') == ns
|
||||
|
||||
index = dict()
|
||||
c = docca.Class(
|
||||
@@ -613,6 +619,21 @@ def test_namespace():
|
||||
assert c.name == 'MyClass'
|
||||
assert c.scope == ns
|
||||
assert c.fully_qualified_name == 'OtherNs::MyClass'
|
||||
assert c.lookup('MyClass') == c
|
||||
assert c.lookup('OtherNs') == ns
|
||||
assert c.lookup('OtherNs::MyClass') == c
|
||||
|
||||
ns2.name = 'TopNs'
|
||||
ns2.members[ns.name] = ns
|
||||
ns.scope = ns2
|
||||
assert c.lookup('TopNs') == ns2
|
||||
assert c.lookup('TopNs::OtherNs') == ns
|
||||
assert c.lookup('TopNs::OtherNs::MyClass') == c
|
||||
assert ns2.lookup('TopNs') == ns2
|
||||
assert ns2.lookup('TopNs::OtherNs') == ns
|
||||
assert ns2.lookup('TopNs::OtherNs::MyClass') == c
|
||||
assert ns2.lookup('OtherNs') == ns
|
||||
assert ns2.lookup('OtherNs::MyClass') == c
|
||||
|
||||
def test_class():
|
||||
for Kind in (docca.Union, docca.Struct, docca.Class):
|
||||
|
||||
Reference in New Issue
Block a user