mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added support for constexpr in function signatures
This commit is contained in:
@@ -421,27 +421,31 @@ class MemberObjDefExpr(NamedDefExpr):
|
|||||||
|
|
||||||
class FuncDefExpr(NamedDefExpr):
|
class FuncDefExpr(NamedDefExpr):
|
||||||
|
|
||||||
def __init__(self, name, visibility, static, explicit, rv,
|
def __init__(self, name, visibility, static, explicit, constexpr, rv,
|
||||||
signature, const, pure_virtual):
|
signature, const, pure_virtual):
|
||||||
NamedDefExpr.__init__(self, name, visibility, static)
|
NamedDefExpr.__init__(self, name, visibility, static)
|
||||||
self.rv = rv
|
self.rv = rv
|
||||||
self.signature = signature
|
self.signature = signature
|
||||||
self.explicit = explicit
|
self.explicit = explicit
|
||||||
|
self.constexpr = constexpr
|
||||||
self.const = const
|
self.const = const
|
||||||
self.pure_virtual = pure_virtual
|
self.pure_virtual = pure_virtual
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return u'%s%s%s' % (
|
return u'%s%s%s%s' % (
|
||||||
self.name.get_id(),
|
self.name.get_id(),
|
||||||
self.signature and u'__' +
|
self.signature and u'__' +
|
||||||
u'.'.join(x.get_id() for x in self.signature) or 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):
|
def __unicode__(self):
|
||||||
buf = self.get_modifiers()
|
buf = self.get_modifiers()
|
||||||
if self.explicit:
|
if self.explicit:
|
||||||
buf.append(u'explicit')
|
buf.append(u'explicit')
|
||||||
|
if self.constexpr:
|
||||||
|
buf.append(u'constexpr')
|
||||||
if self.rv is not None:
|
if self.rv is not None:
|
||||||
buf.append(unicode(self.rv))
|
buf.append(unicode(self.rv))
|
||||||
buf.append(u'%s(%s)' % (self.name, u', '.join(
|
buf.append(u'%s(%s)' % (self.name, u', '.join(
|
||||||
@@ -811,11 +815,14 @@ class DefinitionParser(object):
|
|||||||
|
|
||||||
def parse_function(self):
|
def parse_function(self):
|
||||||
visibility, static = self._parse_visibility_static()
|
visibility, static = self._parse_visibility_static()
|
||||||
if self.skip_word('explicit'):
|
def _read_word(x):
|
||||||
explicit = True
|
if self.skip_word(x):
|
||||||
self.skip_ws()
|
self.skip_ws()
|
||||||
else:
|
return True
|
||||||
explicit = False
|
return False
|
||||||
|
explicit = _read_word('explicit')
|
||||||
|
constexpr = _read_word('constexpr')
|
||||||
|
|
||||||
rv = self._parse_type()
|
rv = self._parse_type()
|
||||||
self.skip_ws()
|
self.skip_ws()
|
||||||
# some things just don't have return values
|
# some things just don't have return values
|
||||||
@@ -824,7 +831,7 @@ class DefinitionParser(object):
|
|||||||
rv = None
|
rv = None
|
||||||
else:
|
else:
|
||||||
name = self._parse_type()
|
name = self._parse_type()
|
||||||
return FuncDefExpr(name, visibility, static, explicit, rv,
|
return FuncDefExpr(name, visibility, static, explicit, constexpr, rv,
|
||||||
*self._parse_signature())
|
*self._parse_signature())
|
||||||
|
|
||||||
def parse_class(self):
|
def parse_class(self):
|
||||||
|
|||||||
@@ -48,10 +48,12 @@ def test_type_definitions():
|
|||||||
|
|
||||||
assert unicode(parse('type_object', 'long long int foo')) == 'long long foo'
|
assert unicode(parse('type_object', 'long long int foo')) == 'long long foo'
|
||||||
|
|
||||||
|
|
||||||
x = 'MyClass::MyClass(MyClass::MyClass&&)'
|
x = 'MyClass::MyClass(MyClass::MyClass&&)'
|
||||||
assert unicode(parse('function', x)) == x
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
x = 'constexpr int get_value()'
|
||||||
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
|
||||||
def test_operators():
|
def test_operators():
|
||||||
x = parse('function', 'void operator new [ ] ()')
|
x = parse('function', 'void operator new [ ] ()')
|
||||||
|
|||||||
Reference in New Issue
Block a user