Anonymous avatar Anonymous committed 37257be

* Support for C class names (and const specifiers).
* Fix handling of describe environment.

Comments (0)

Files changed (4)

 * A new config value, `autoclass_content`, selects if the docstring of the
   class' ``__init__`` method is added to the directive's body.
 
+* Support for C++ class names (in the style ``Class::Function``) in C function
+  descriptions.
+
 Bugs fixed
 ----------
 
 slashes.  All values, parameters and suchlike referring to "documents" expect
 such a document name.
 
+.. cfunction:: Class::method(int bla, int foo) const
+
+   pass
+
+.. cmdoption:: --longopt <arg>
+
+.. class:: Test
+
+   .. method:: X
+
 
 The TOC tree
 ------------

sphinx/directives/desc.py

 c_sig_re = re.compile(
     r'''^([^(]*?)          # return type
         ([\w:]+)  \s*      # thing name (colon allowed for C++ class names)
-        (?: \((.*)\) )? $  # optionally arguments
+        (?: \((.*)\) )?    # optionally arguments
+        (\s+const)? $      # const specifier
     ''', re.VERBOSE)
 c_funcptr_sig_re = re.compile(
     r'''^([^(]+?)          # return type
         (\( [^()]+ \)) \s* # name in parentheses
-        \( (.*) \) $       # arguments
+        \( (.*) \)         # arguments
+        (\s+const)? $      # const specifier
     ''', re.VERBOSE)
 c_funcptr_name_re = re.compile(r'^\(\s*\*\s*(.*?)\s*\)$')
 
         m = c_sig_re.match(sig)
     if m is None:
         raise ValueError('no match')
-    rettype, name, arglist = m.groups()
+    rettype, name, arglist, const = m.groups()
 
     signode += addnodes.desc_type("", "")
     parse_c_type(signode[-1], rettype)
-    signode += addnodes.desc_name(name, name)
+    try:
+        classname, funcname = name.split('::', 1)
+        classname += '::'
+        signode += addnodes.desc_classname(classname, classname)
+        signode += addnodes.desc_name(funcname, funcname)
+        # name (the full name) is still both parts
+    except ValueError:
+        signode += addnodes.desc_name(name, name)
     # clean up parentheses from canonical name
     m = c_funcptr_name_re.match(name)
     if m:
             param += nodes.emphasis(' '+argname, ' '+argname)
         paramlist += param
     signode += paramlist
+    if const:
+        signode += addnodes.desc_classname(const, const)
     return name
 
 

sphinx/latexwriter.py

         self.ni = node['noindex']
         self.type = self.cls = self.name = self.params = ''
         self.count = 0
+        self.name = ''
 
 
 class LaTeXTranslator(nodes.NodeVisitor):
             else:
                 t2 = "{%s}" % d.name
         elif d.env == 'cfuncdesc':
+            if d.cls:
+                # C++ class names
+                d.name = '%s::%s' % (d.cls, d.name)
             t2 = "{%s}{%s}{%s}" % (d.type, d.name, d.params)
         elif d.env == 'cmemberdesc':
             try:
         self.body.append(t1 + t2)
 
     def visit_desc_type(self, node):
-        self.descstack[-1].type = self.encode(node.astext().strip())
+        d = self.descstack[-1]
+        if d.env == 'describe':
+            d.name += self.encode(node.astext())
+        else:
+            self.descstack[-1].type = self.encode(node.astext().strip())
         raise nodes.SkipNode
 
     def visit_desc_name(self, node):
-        self.descstack[-1].name = self.encode(node.astext().strip())
+        d = self.descstack[-1]
+        if d.env == 'describe':
+            d.name += self.encode(node.astext())
+        else:
+            self.descstack[-1].name = self.encode(node.astext().strip())
         raise nodes.SkipNode
 
     def visit_desc_classname(self, node):
-        self.descstack[-1].cls = self.encode(node.astext().strip())
+        d = self.descstack[-1]
+        if d.env == 'describe':
+            d.name += self.encode(node.astext())
+        else:
+            self.descstack[-1].cls = self.encode(node.astext().strip())
         raise nodes.SkipNode
 
     def visit_desc_parameterlist(self, node):
-        self.descstack[-1].params = self.encode(node.astext().strip())
+        d = self.descstack[-1]
+        if d.env == 'describe':
+            d.name += self.encode(node.astext())
+        else:
+            self.descstack[-1].params = self.encode(node.astext().strip())
         raise nodes.SkipNode
 
     def visit_refcount(self, node):
         self.body.append("}\\\\")
 
     def visit_desc_content(self, node):
-        pass
+        if node.children and isinstance(node.children[0], addnodes.desc):
+            # avoid empty desc environment which causes a formatting bug
+            self.body.append('~')
     def depart_desc_content(self, node):
         pass
 
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.