diff options
author | Robert Lehmann <mail@robertlehmann.de> | 2011-10-08 14:02:13 +0200 |
---|---|---|
committer | Robert Lehmann <mail@robertlehmann.de> | 2011-10-08 14:02:13 +0200 |
commit | f81ceba276d562a24d2765d85e73c165d5d38499 (patch) | |
tree | 9b6d75d2c9fc9146d9c19fb28b3b1f6b59208577 | |
parent | a49c13f08a85ad353d073f015ec446caaebb0ad5 (diff) | |
download | sphinx-f81ceba276d562a24d2765d85e73c165d5d38499.tar.gz |
Fixes #678: Support superclass declarations in C++ domain.
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sphinx/domains/cpp.py | 29 | ||||
-rw-r--r-- | tests/test_cpp_domain.py | 20 |
3 files changed, 48 insertions, 2 deletions
@@ -46,6 +46,7 @@ Features added - Section headings in :rst:dir:`only` directives are now correctly handled. - Added ``emphasize-lines`` option to source code directives. + - #678: C++ domain now supports superclasses. * HTML builder: diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 7a4e479a..61173d44 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -488,8 +488,9 @@ class FuncDefExpr(NamedDefExpr): class ClassDefExpr(NamedDefExpr): - def __init__(self, name, visibility, static): + def __init__(self, name, visibility, static, bases): NamedDefExpr.__init__(self, name, visibility, static) + self.bases = bases def get_id(self): return self.name.get_id() @@ -497,6 +498,9 @@ class ClassDefExpr(NamedDefExpr): def __unicode__(self): buf = self.get_modifiers() buf.append(unicode(self.name)) + if self.bases: + buf.append(u':') + buf.append(u', '.join(unicode(base) for base in self.bases)) return u' '.join(buf) @@ -879,7 +883,21 @@ class DefinitionParser(object): def parse_class(self): visibility, static = self._parse_visibility_static() - return ClassDefExpr(self._parse_type(), visibility, static) + name = self._parse_type() + bases = [] + if self.skip_string(':'): + self.skip_ws() + while 1: + access = 'public' + if self.match(_visibility_re): + access = self.matched_text + base = self._parse_type() + bases.append(ClassDefExpr(base, access, False, [])) + if self.skip_string(','): + self.skip_ws() + else: + break + return ClassDefExpr(name, visibility, static, bases) def read_rest(self): rv = self.definition[self.pos:] @@ -1005,6 +1023,13 @@ class CPPClassObject(CPPObject): self.attach_modifiers(signode, cls) signode += addnodes.desc_annotation('class ', 'class ') self.attach_name(signode, cls.name) + if cls.bases: + signode += nodes.Text(' : ') + for base in cls.bases: + self.attach_modifiers(signode, base) + signode += nodes.emphasis(unicode(base.name), unicode(base.name)) + signode += nodes.Text(', ') + signode.pop() # remove the trailing comma class CPPTypeObject(CPPObject): diff --git a/tests/test_cpp_domain.py b/tests/test_cpp_domain.py index 22e24a08..ff44c8db 100644 --- a/tests/test_cpp_domain.py +++ b/tests/test_cpp_domain.py @@ -74,6 +74,26 @@ def test_type_definitions(): assert unicode(parse('member_object', x)) == x +def test_bases(): + x = 'A' + assert unicode(parse('class', x)) == x + + x = 'A : B' + assert unicode(parse('class', x)) == x + + x = 'A : private B' + assert unicode(parse('class', x)) == x + + x = 'A : public B' + assert unicode(parse('class', x)) == 'A : B' + + x = 'A : B, C' + assert unicode(parse('class', x)) == x + + x = 'A : B, protected C, D' + assert unicode(parse('class', x)) == x + + def test_operators(): x = parse('function', 'void operator new [ ] ()') assert unicode(x) == 'void operator new[]()' |