Armin Ronacher avatar Armin Ronacher committed 7e01687

Added support for constexpr in function signatures

Comments (0)

Files changed (2)

sphinx/domains/cpp.py

 
 class FuncDefExpr(NamedDefExpr):
 
-    def __init__(self, name, visibility, static, explicit, rv,
+    def __init__(self, name, visibility, static, explicit, constexpr, rv,
                  signature, const, pure_virtual):
         NamedDefExpr.__init__(self, name, visibility, static)
         self.rv = rv
         self.signature = signature
         self.explicit = explicit
+        self.constexpr = constexpr
         self.const = const
         self.pure_virtual = pure_virtual
 
     def get_id(self):
-        return u'%s%s%s' % (
+        return u'%s%s%s%s' % (
             self.name.get_id(),
             self.signature and u'__' +
                 u'.'.join(x.get_id() for x in self.signature) or u'',
-            self.const and u'C' or u''
+            self.const and u'C' or u'',
+            self.constexpr and 'CE' or ''
         )
 
     def __unicode__(self):
         buf = self.get_modifiers()
         if self.explicit:
             buf.append(u'explicit')
+        if self.constexpr:
+            buf.append(u'constexpr')
         if self.rv is not None:
             buf.append(unicode(self.rv))
         buf.append(u'%s(%s)' % (self.name, u', '.join(
 
     def parse_function(self):
         visibility, static = self._parse_visibility_static()
-        if self.skip_word('explicit'):
-            explicit = True
-            self.skip_ws()
-        else:
-            explicit = False
+        def _read_word(x):
+            if self.skip_word(x):
+                self.skip_ws()
+                return True
+            return False
+        explicit = _read_word('explicit')
+        constexpr = _read_word('constexpr')
+
         rv = self._parse_type()
         self.skip_ws()
         # some things just don't have return values
             rv = None
         else:
             name = self._parse_type()
-        return FuncDefExpr(name, visibility, static, explicit, rv,
+        return FuncDefExpr(name, visibility, static, explicit, constexpr, rv,
                            *self._parse_signature())
 
     def parse_class(self):

tests/test_cpp_domain.py

 
     assert unicode(parse('type_object', 'long long int foo')) == 'long long foo'
 
+    x = 'MyClass::MyClass(MyClass::MyClass&&)'
+    assert unicode(parse('function', x)) == x
 
-    x = 'MyClass::MyClass(MyClass::MyClass&&)'
+    x = 'constexpr int get_value()'
     assert unicode(parse('function', x)) == x
 
 
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.