Robert Lehmann avatar Robert Lehmann committed f061f97

Fixes #678: Support superclass declarations in C++ domain.

Comments (0)

Files changed (3)

   - 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:
 

sphinx/domains/cpp.py

 
 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()
     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)
 
 
 
     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:]
         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):

tests/test_cpp_domain.py

     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[]()'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.