mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #1705 from jakobandersen/cpp-declspecs-on-right
C++, fix #1689
This commit is contained in:
commit
3068f6c7f1
@ -688,11 +688,8 @@ class ASTParametersQualifiers(ASTBase):
|
|||||||
_add_text(signode, '= ' + text_type(self.initializer))
|
_add_text(signode, '= ' + text_type(self.initializer))
|
||||||
|
|
||||||
|
|
||||||
class ASTDeclSpecs(ASTBase):
|
class ASTDeclSpecsSimple(ASTBase):
|
||||||
def __init__(self, outer, visibility, storage, inline, virtual, explicit,
|
def __init__(self, storage, inline, virtual, explicit, constexpr, volatile, const):
|
||||||
constexpr, volatile, const, trailing):
|
|
||||||
self.outer = outer
|
|
||||||
self.visibility = visibility
|
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
self.inline = inline
|
self.inline = inline
|
||||||
self.virtual = virtual
|
self.virtual = virtual
|
||||||
@ -700,31 +697,9 @@ class ASTDeclSpecs(ASTBase):
|
|||||||
self.constexpr = constexpr
|
self.constexpr = constexpr
|
||||||
self.volatile = volatile
|
self.volatile = volatile
|
||||||
self.const = const
|
self.const = const
|
||||||
self.trailingTypeSpec = trailing
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
return self.trailingTypeSpec.name
|
|
||||||
|
|
||||||
def get_id(self):
|
|
||||||
res = []
|
|
||||||
if self.volatile:
|
|
||||||
res.append('V')
|
|
||||||
if self.const:
|
|
||||||
res.append('K')
|
|
||||||
res.append(self.trailingTypeSpec.get_id())
|
|
||||||
return u''.join(res)
|
|
||||||
|
|
||||||
def _print_visibility(self):
|
|
||||||
return (self.visibility and
|
|
||||||
not (
|
|
||||||
self.outer in ('type', 'member', 'function') and
|
|
||||||
self.visibility == 'public'))
|
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
res = []
|
res = []
|
||||||
if self._print_visibility():
|
|
||||||
res.append(self.visibility)
|
|
||||||
if self.storage:
|
if self.storage:
|
||||||
res.append(self.storage)
|
res.append(self.storage)
|
||||||
if self.inline:
|
if self.inline:
|
||||||
@ -739,21 +714,13 @@ class ASTDeclSpecs(ASTBase):
|
|||||||
res.append('volatile')
|
res.append('volatile')
|
||||||
if self.const:
|
if self.const:
|
||||||
res.append('const')
|
res.append('const')
|
||||||
if self.trailingTypeSpec:
|
|
||||||
res.append(text_type(self.trailingTypeSpec))
|
|
||||||
return u' '.join(res)
|
return u' '.join(res)
|
||||||
|
|
||||||
def describe_signature(self, signode, mode, env):
|
def describe_signature(self, modifiers):
|
||||||
_verify_description_mode(mode)
|
|
||||||
modifiers = []
|
|
||||||
|
|
||||||
def _add(modifiers, text):
|
def _add(modifiers, text):
|
||||||
if len(modifiers) > 0:
|
if len(modifiers) > 0:
|
||||||
modifiers.append(nodes.Text(' '))
|
modifiers.append(nodes.Text(' '))
|
||||||
modifiers.append(addnodes.desc_annotation(text, text))
|
modifiers.append(addnodes.desc_annotation(text, text))
|
||||||
|
|
||||||
if self._print_visibility():
|
|
||||||
_add(modifiers, self.visibility)
|
|
||||||
if self.storage:
|
if self.storage:
|
||||||
_add(modifiers, self.storage)
|
_add(modifiers, self.storage)
|
||||||
if self.inline:
|
if self.inline:
|
||||||
@ -768,13 +735,79 @@ class ASTDeclSpecs(ASTBase):
|
|||||||
_add(modifiers, 'volatile')
|
_add(modifiers, 'volatile')
|
||||||
if self.const:
|
if self.const:
|
||||||
_add(modifiers, 'const')
|
_add(modifiers, 'const')
|
||||||
|
|
||||||
|
class ASTDeclSpecs(ASTBase):
|
||||||
|
def __init__(self, outer, visibility, leftSpecs, rightSpecs, trailing):
|
||||||
|
self.outer = outer
|
||||||
|
self.visibility = visibility
|
||||||
|
self.leftSpecs = leftSpecs
|
||||||
|
self.rightSpecs = rightSpecs
|
||||||
|
self.trailingTypeSpec = trailing
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self.trailingTypeSpec.name
|
||||||
|
|
||||||
|
def get_id(self):
|
||||||
|
res = []
|
||||||
|
if self.leftSpecs.volatile or self.rightSpecs.volatile:
|
||||||
|
res.append('V')
|
||||||
|
if self.leftSpecs.const or self.rightSpecs.volatile:
|
||||||
|
res.append('K')
|
||||||
|
res.append(self.trailingTypeSpec.get_id())
|
||||||
|
return u''.join(res)
|
||||||
|
|
||||||
|
def _print_visibility(self):
|
||||||
|
return (self.visibility and
|
||||||
|
not (
|
||||||
|
self.outer in ('type', 'member', 'function') and
|
||||||
|
self.visibility == 'public'))
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
res = []
|
||||||
|
if self._print_visibility():
|
||||||
|
res.append(self.visibility)
|
||||||
|
l = text_type(self.leftSpecs)
|
||||||
|
if len(l) > 0:
|
||||||
|
if len(res) > 0:
|
||||||
|
res.append(" ")
|
||||||
|
res.append(l)
|
||||||
|
if self.trailingTypeSpec:
|
||||||
|
if len(res) > 0:
|
||||||
|
res.append(" ")
|
||||||
|
res.append(text_type(self.trailingTypeSpec))
|
||||||
|
r = text_type(self.rightSpecs)
|
||||||
|
if len(r) > 0:
|
||||||
|
if len(res) > 0:
|
||||||
|
res.append(" ")
|
||||||
|
res.append(r)
|
||||||
|
return "".join(res)
|
||||||
|
|
||||||
|
def describe_signature(self, signode, mode, env):
|
||||||
|
_verify_description_mode(mode)
|
||||||
|
modifiers = []
|
||||||
|
|
||||||
|
def _add(modifiers, text):
|
||||||
|
if len(modifiers) > 0:
|
||||||
|
modifiers.append(nodes.Text(' '))
|
||||||
|
modifiers.append(addnodes.desc_annotation(text, text))
|
||||||
|
|
||||||
|
if self._print_visibility():
|
||||||
|
_add(modifiers, self.visibility)
|
||||||
|
self.leftSpecs.describe_signature(modifiers)
|
||||||
|
|
||||||
for m in modifiers:
|
for m in modifiers:
|
||||||
signode += m
|
signode += m
|
||||||
if self.trailingTypeSpec:
|
if self.trailingTypeSpec:
|
||||||
if len(modifiers) > 0:
|
if len(modifiers) > 0:
|
||||||
signode += nodes.Text(' ')
|
signode += nodes.Text(' ')
|
||||||
self.trailingTypeSpec.describe_signature(signode, mode, env)
|
self.trailingTypeSpec.describe_signature(signode, mode, env)
|
||||||
|
modifiers = []
|
||||||
|
self.rightSpecs.describe_signature(modifiers)
|
||||||
|
if len(modifiers) > 0:
|
||||||
|
signode += nodes.Text(' ')
|
||||||
|
for m in modifiers:
|
||||||
|
signode += m
|
||||||
|
|
||||||
class ASTPtrOpPtr(ASTBase):
|
class ASTPtrOpPtr(ASTBase):
|
||||||
def __init__(self, volatile, const):
|
def __init__(self, volatile, const):
|
||||||
@ -952,7 +985,6 @@ class ASTType(ASTBase):
|
|||||||
signode += nodes.Text(' ')
|
signode += nodes.Text(' ')
|
||||||
self.decl.describe_signature(signode, mode, env)
|
self.decl.describe_signature(signode, mode, env)
|
||||||
|
|
||||||
|
|
||||||
class ASTTypeWithInit(ASTBase):
|
class ASTTypeWithInit(ASTBase):
|
||||||
def __init__(self, type, init):
|
def __init__(self, type, init):
|
||||||
self.objectType = None
|
self.objectType = None
|
||||||
@ -1337,20 +1369,8 @@ class DefinitionParser(object):
|
|||||||
args, volatile, const, refQual, exceptionSpec, override, final,
|
args, volatile, const, refQual, exceptionSpec, override, final,
|
||||||
initializer)
|
initializer)
|
||||||
|
|
||||||
def _parse_decl_specs(self, outer, typed=True):
|
def _parse_decl_specs_simple(self, outer, typed):
|
||||||
"""
|
"""Just parse the simple ones."""
|
||||||
visibility storage-class-specifier function-specifier "constexpr"
|
|
||||||
"volatile" "const" trailing-type-specifier
|
|
||||||
|
|
||||||
storage-class-specifier -> "static" (only for member_object and
|
|
||||||
function_object)
|
|
||||||
|
|
||||||
function-specifier -> "inline" | "virtual" | "explicit" (only for
|
|
||||||
function_object)
|
|
||||||
|
|
||||||
"constexpr" (only for member_object and function_object)
|
|
||||||
"""
|
|
||||||
visibility = None
|
|
||||||
storage = None
|
storage = None
|
||||||
inline = None
|
inline = None
|
||||||
virtual = None
|
virtual = None
|
||||||
@ -1358,12 +1378,6 @@ class DefinitionParser(object):
|
|||||||
constexpr = None
|
constexpr = None
|
||||||
volatile = None
|
volatile = None
|
||||||
const = None
|
const = None
|
||||||
|
|
||||||
if outer:
|
|
||||||
self.skip_ws()
|
|
||||||
if self.match(_visibility_re):
|
|
||||||
visibility = self.matched_text
|
|
||||||
|
|
||||||
while 1: # accept any permutation of a subset of some decl-specs
|
while 1: # accept any permutation of a subset of some decl-specs
|
||||||
self.skip_ws()
|
self.skip_ws()
|
||||||
if not storage:
|
if not storage:
|
||||||
@ -1409,14 +1423,37 @@ class DefinitionParser(object):
|
|||||||
if const:
|
if const:
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
|
return ASTDeclSpecsSimple(storage, inline, virtual, explicit, constexpr,
|
||||||
|
volatile, const)
|
||||||
|
|
||||||
|
def _parse_decl_specs(self, outer, typed=True):
|
||||||
|
"""
|
||||||
|
visibility storage-class-specifier function-specifier "constexpr"
|
||||||
|
"volatile" "const" trailing-type-specifier
|
||||||
|
|
||||||
|
storage-class-specifier -> "static" (only for member_object and
|
||||||
|
function_object)
|
||||||
|
|
||||||
|
function-specifier -> "inline" | "virtual" | "explicit" (only for
|
||||||
|
function_object)
|
||||||
|
|
||||||
|
"constexpr" (only for member_object and function_object)
|
||||||
|
"""
|
||||||
|
visibility = None
|
||||||
|
leftSepcs = None
|
||||||
|
rightSpecs = None
|
||||||
|
if outer:
|
||||||
|
self.skip_ws()
|
||||||
|
if self.match(_visibility_re):
|
||||||
|
visibility = self.matched_text
|
||||||
|
leftSpecs = self._parse_decl_specs_simple(outer, typed)
|
||||||
|
|
||||||
if typed:
|
if typed:
|
||||||
trailing = self._parse_trailing_type_spec()
|
trailing = self._parse_trailing_type_spec()
|
||||||
|
rightSpecs = self._parse_decl_specs_simple(outer, typed)
|
||||||
else:
|
else:
|
||||||
trailing = None
|
trailing = None
|
||||||
return ASTDeclSpecs(
|
return ASTDeclSpecs(outer, visibility, leftSpecs, rightSpecs, trailing)
|
||||||
outer, visibility, storage, inline, virtual, explicit, constexpr,
|
|
||||||
volatile, const, trailing)
|
|
||||||
|
|
||||||
def _parse_declerator(self, named, paramMode=None, typed=True):
|
def _parse_declerator(self, named, paramMode=None, typed=True):
|
||||||
if paramMode:
|
if paramMode:
|
||||||
|
@ -62,6 +62,8 @@ def test_type_definitions():
|
|||||||
check("type",
|
check("type",
|
||||||
"public MyContainer::const_iterator",
|
"public MyContainer::const_iterator",
|
||||||
"MyContainer::const_iterator")
|
"MyContainer::const_iterator")
|
||||||
|
# test decl specs on right
|
||||||
|
check("type", "bool const b")
|
||||||
|
|
||||||
check('member',
|
check('member',
|
||||||
' const std::string & name = 42',
|
' const std::string & name = 42',
|
||||||
|
Loading…
Reference in New Issue
Block a user