mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merged in sahchandler/sphinx (pull request #155)
Add support for C++11 member function ref-qualifiers and C++03 volatile member function ref-qualifier
This commit is contained in:
commit
078e9bfb51
@ -448,15 +448,21 @@ class MemberObjDefExpr(NamedDefExpr):
|
|||||||
class FuncDefExpr(NamedDefExpr):
|
class FuncDefExpr(NamedDefExpr):
|
||||||
|
|
||||||
def __init__(self, name, visibility, static, explicit, constexpr, rv,
|
def __init__(self, name, visibility, static, explicit, constexpr, rv,
|
||||||
signature, const, noexcept, pure_virtual):
|
signature, **kwargs):
|
||||||
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.constexpr = constexpr
|
||||||
self.const = const
|
self.const = kwargs.get('const', False)
|
||||||
self.noexcept = noexcept
|
self.volatile = kwargs.get('volatile', False)
|
||||||
self.pure_virtual = pure_virtual
|
self.noexcept = kwargs.get('noexcept', False)
|
||||||
|
self.override = kwargs.get('override', False)
|
||||||
|
self.rvalue_this = kwargs.get('rvalue_this', False)
|
||||||
|
self.lvalue_this = kwargs.get('lvalue_this', False)
|
||||||
|
self.pure_virtual = kwargs.get('pure_virtual', False)
|
||||||
|
self.delete = kwargs.get('delete', False)
|
||||||
|
self.default = kwargs.get('default', False)
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return u'%s%s%s%s' % (
|
return u'%s%s%s%s' % (
|
||||||
@ -479,10 +485,22 @@ class FuncDefExpr(NamedDefExpr):
|
|||||||
map(unicode, self.signature))))
|
map(unicode, self.signature))))
|
||||||
if self.const:
|
if self.const:
|
||||||
buf.append(u'const')
|
buf.append(u'const')
|
||||||
|
if self.volatile:
|
||||||
|
buf.append(u'volatile')
|
||||||
|
if self.rvalue_this:
|
||||||
|
buf.append(u'&&')
|
||||||
|
if self.lvalue_this:
|
||||||
|
buf.append(u'&')
|
||||||
if self.noexcept:
|
if self.noexcept:
|
||||||
buf.append(u'noexcept')
|
buf.append(u'noexcept')
|
||||||
|
if self.override:
|
||||||
|
buf.append(u'override')
|
||||||
if self.pure_virtual:
|
if self.pure_virtual:
|
||||||
buf.append(u'= 0')
|
buf.append(u'= 0')
|
||||||
|
if self.default:
|
||||||
|
buf.append(u'= default')
|
||||||
|
if self.delete:
|
||||||
|
buf.append(u'= delete')
|
||||||
return u' '.join(buf)
|
return u' '.join(buf)
|
||||||
|
|
||||||
|
|
||||||
@ -835,20 +853,46 @@ class DefinitionParser(object):
|
|||||||
args.append(ArgumentDefExpr(argtype, argname,
|
args.append(ArgumentDefExpr(argtype, argname,
|
||||||
type_suffixes, default))
|
type_suffixes, default))
|
||||||
self.skip_ws()
|
self.skip_ws()
|
||||||
const = self.skip_word_and_ws('const')
|
attributes = dict(
|
||||||
noexcept = self.skip_word_and_ws('noexcept')
|
signature=args,
|
||||||
|
const=self.skip_word_and_ws('const'),
|
||||||
|
volatile=self.skip_word_and_ws('volatile'),
|
||||||
|
noexcept=self.skip_word_and_ws('noexcept'),
|
||||||
|
override=self.skip_word_and_ws('override'),
|
||||||
|
pure_virtual=False,
|
||||||
|
lvalue_this=False,
|
||||||
|
rvalue_this=False,
|
||||||
|
delete=False,
|
||||||
|
default=False)
|
||||||
|
|
||||||
|
if self.skip_string('&&'):
|
||||||
|
attributes['rvalue_this'] = True
|
||||||
|
if self.skip_string('&'):
|
||||||
|
attributes['lvalue_this'] = True
|
||||||
|
|
||||||
|
if attributes['lvalue_this'] and attributes['rvalue_this']:
|
||||||
|
self.fail('rvalue reference for *this specifier must be one of'
|
||||||
|
'"&&" or "&"')
|
||||||
|
|
||||||
if self.skip_string('='):
|
if self.skip_string('='):
|
||||||
self.skip_ws()
|
self.skip_ws()
|
||||||
if not (self.skip_string('0') or \
|
if self.skip_string('0'):
|
||||||
self.skip_word('NULL') or \
|
attributes['pure_virtual'] = True
|
||||||
self.skip_word('nullptr')):
|
return attributes
|
||||||
self.fail('pure virtual functions must be defined with '
|
if self.skip_word('NULL') or self.skip_word('nullptr'):
|
||||||
'either 0, NULL or nullptr, other macros are '
|
attributes['pure_virtual'] = True
|
||||||
'not allowed')
|
return attributes
|
||||||
pure_virtual = True
|
if self.skip_word('delete'):
|
||||||
else:
|
attributes['delete'] = True
|
||||||
pure_virtual = False
|
return attributes
|
||||||
return args, const, noexcept, pure_virtual
|
if self.skip_word('default'):
|
||||||
|
attributes['default'] = True
|
||||||
|
return attributes
|
||||||
|
|
||||||
|
self.fail('functions must be defined with '
|
||||||
|
'either 0, NULL, nullptr, default or delete, other'
|
||||||
|
'macros are not allowed')
|
||||||
|
return attributes
|
||||||
|
|
||||||
def _parse_visibility_static(self):
|
def _parse_visibility_static(self):
|
||||||
visibility = 'public'
|
visibility = 'public'
|
||||||
@ -900,7 +944,7 @@ class DefinitionParser(object):
|
|||||||
else:
|
else:
|
||||||
name = self._parse_type()
|
name = self._parse_type()
|
||||||
return FuncDefExpr(name, visibility, static, explicit, constexpr, rv,
|
return FuncDefExpr(name, visibility, static, explicit, constexpr, rv,
|
||||||
*self._parse_signature())
|
**self._parse_signature())
|
||||||
|
|
||||||
def parse_class(self):
|
def parse_class(self):
|
||||||
visibility, static = self._parse_visibility_static()
|
visibility, static = self._parse_visibility_static()
|
||||||
|
@ -75,6 +75,30 @@ def test_type_definitions():
|
|||||||
x = 'int get_value() const noexcept'
|
x = 'int get_value() const noexcept'
|
||||||
assert unicode(parse('function', x)) == x
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
x = 'int get_value() const noexcept = delete'
|
||||||
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
x = 'MyClass::MyClass(MyClass::MyClass&&) = default'
|
||||||
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
x = 'MyClass::a_virtual_function() const override'
|
||||||
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
x = 'MyClass::a_member_function() volatile'
|
||||||
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
x = 'MyClass::a_member_function() const volatile'
|
||||||
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
x = 'MyClass::a_member_function() &&'
|
||||||
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
x = 'MyClass::a_member_function() &'
|
||||||
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
x = 'MyClass::a_member_function() const &'
|
||||||
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
x = 'int main(int argc, char* argv[][])'
|
x = 'int main(int argc, char* argv[][])'
|
||||||
assert unicode(parse('function', x)) == x
|
assert unicode(parse('function', x)) == x
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user