mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #5269 from jakobandersen/cpp_5191
C++, prevent nested declarations in functions.
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -200,6 +200,7 @@ Bugs fixed
|
|||||||
* #5114: sphinx-build: Handle errors on scanning documents
|
* #5114: sphinx-build: Handle errors on scanning documents
|
||||||
* epub: spine has been broken when "self" is listed on toctree (refs: #4611)
|
* epub: spine has been broken when "self" is listed on toctree (refs: #4611)
|
||||||
* #344: autosummary does not understand docstring of module level attributes
|
* #344: autosummary does not understand docstring of module level attributes
|
||||||
|
* #5191: C++, prevent nested declarations in functions to avoid lookup problems.
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
|||||||
@@ -2085,7 +2085,7 @@ class ASTTrailingTypeSpecName(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> Any
|
# type: () -> ASTNestedName
|
||||||
return self.nestedName
|
return self.nestedName
|
||||||
|
|
||||||
def get_id(self, version):
|
def get_id(self, version):
|
||||||
@@ -2379,7 +2379,7 @@ class ASTDeclSpecs(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.trailingTypeSpec.name
|
return self.trailingTypeSpec.name
|
||||||
|
|
||||||
def get_id(self, version):
|
def get_id(self, version):
|
||||||
@@ -2487,7 +2487,7 @@ class ASTDeclaratorPtr(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.next.name
|
return self.next.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -2583,7 +2583,7 @@ class ASTDeclaratorRef(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.next.name
|
return self.next.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -2638,7 +2638,7 @@ class ASTDeclaratorParamPack(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.next.name
|
return self.next.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -2702,7 +2702,7 @@ class ASTDeclaratorMemPtr(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.next.name
|
return self.next.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -2798,7 +2798,7 @@ class ASTDeclaratorParen(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.inner.name
|
return self.inner.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -2864,7 +2864,7 @@ class ASTDeclaratorNameParamQual(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.declId
|
return self.declId
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -2962,9 +2962,8 @@ class ASTType(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
name = self.decl.name
|
return self.decl.name
|
||||||
return name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def function_params(self):
|
def function_params(self):
|
||||||
@@ -3054,7 +3053,7 @@ class ASTTypeWithInit(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.type.name
|
return self.type.name
|
||||||
|
|
||||||
def get_id(self, version, objectType=None, symbol=None):
|
def get_id(self, version, objectType=None, symbol=None):
|
||||||
@@ -3122,7 +3121,7 @@ class ASTConcept(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.nestedName
|
return self.nestedName
|
||||||
|
|
||||||
def get_id(self, version, objectType=None, symbol=None):
|
def get_id(self, version, objectType=None, symbol=None):
|
||||||
@@ -3326,7 +3325,7 @@ class ASTDeclaration(ASTBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# type: () -> unicode
|
# type: () -> ASTNestedName
|
||||||
return self.declaration.name
|
return self.declaration.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -5791,12 +5790,37 @@ class CPPObject(ObjectDescription):
|
|||||||
# type: (addnodes.desc_signature, Any, Dict) -> None
|
# type: (addnodes.desc_signature, Any, Dict) -> None
|
||||||
ast.describe_signature(signode, 'lastIsName', self.env, options)
|
ast.describe_signature(signode, 'lastIsName', self.env, options)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
env = self.state.document.settings.env # from ObjectDescription.run
|
||||||
|
if 'cpp:parent_symbol' not in env.temp_data:
|
||||||
|
root = env.domaindata['cpp']['root_symbol']
|
||||||
|
env.temp_data['cpp:parent_symbol'] = root
|
||||||
|
env.ref_context['cpp:parent_key'] = root.get_lookup_key()
|
||||||
|
|
||||||
|
# The lookup keys assume that no nested scopes exists inside overloaded functions.
|
||||||
|
# (see also #5191)
|
||||||
|
# Example:
|
||||||
|
# .. cpp:function:: void f(int)
|
||||||
|
# .. cpp:function:: void f(double)
|
||||||
|
#
|
||||||
|
# .. cpp:function:: void g()
|
||||||
|
#
|
||||||
|
# :cpp:any:`boom`
|
||||||
|
#
|
||||||
|
# So we disallow any signatures inside functions.
|
||||||
|
parentSymbol = env.temp_data['cpp:parent_symbol']
|
||||||
|
parentDecl = parentSymbol.declaration
|
||||||
|
if parentDecl is not None and parentDecl.objectType == 'function':
|
||||||
|
self.warn("C++ declarations inside functions are not supported." +
|
||||||
|
" Parent function is " + text_type(parentSymbol.get_full_nested_name()))
|
||||||
|
name = _make_phony_error_name()
|
||||||
|
symbol = parentSymbol.add_name(name)
|
||||||
|
env.temp_data['cpp:last_symbol'] = symbol
|
||||||
|
return []
|
||||||
|
return ObjectDescription.run(self)
|
||||||
|
|
||||||
def handle_signature(self, sig, signode):
|
def handle_signature(self, sig, signode):
|
||||||
# type: (unicode, addnodes.desc_signature) -> Any
|
# type: (unicode, addnodes.desc_signature) -> Any
|
||||||
if 'cpp:parent_symbol' not in self.env.temp_data:
|
|
||||||
root = self.env.domaindata['cpp']['root_symbol']
|
|
||||||
self.env.temp_data['cpp:parent_symbol'] = root
|
|
||||||
self.env.ref_context['cpp:parent_key'] = root.get_lookup_key()
|
|
||||||
parentSymbol = self.env.temp_data['cpp:parent_symbol']
|
parentSymbol = self.env.temp_data['cpp:parent_symbol']
|
||||||
|
|
||||||
parser = DefinitionParser(sig, self, self.env.config)
|
parser = DefinitionParser(sig, self, self.env.config)
|
||||||
|
|||||||
Reference in New Issue
Block a user