Skip to content

Commit

Permalink
Merge pull request #7895 from jakobandersen/c_cpp_noindex
Browse files Browse the repository at this point in the history
C, C++: remove noindex option
  • Loading branch information
jakobandersen committed Jul 2, 2020
2 parents 61c9aa5 + ff5eb7c commit 8c82ecb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -29,6 +29,8 @@ Bugs fixed
* #7846: html theme: XML-invalid files were generated
* #7869: :rst:role:`abbr` role without an explanation will show the explanation
from the previous abbr role
* C and C++, removed ``noindex`` directive option as it did
nothing.

Testing
--------
Expand Down
1 change: 0 additions & 1 deletion doc/usage/restructuredtext/domains.rst
Expand Up @@ -1073,7 +1073,6 @@ Options
Some directives support options:
- ``:noindex:``, see :ref:`basic-domain-markup`.
- ``:tparam-line-spec:``, for templated declarations.
If specified, each template parameter will be rendered on a separate line.
Expand Down
33 changes: 16 additions & 17 deletions sphinx/domains/c.py
Expand Up @@ -1887,7 +1887,7 @@ def merge_with(self, other: "Symbol", docnames: List[str],
ourChild._fill_empty(otherChild.declaration, otherChild.docname)
elif ourChild.docname != otherChild.docname:
name = str(ourChild.declaration)
msg = __("Duplicate declaration, also defined in '%s'.\n"
msg = __("Duplicate C declaration, also defined in '%s'.\n"
"Declaration is '%s'.")
msg = msg % (ourChild.docname, name)
logger.warning(msg, location=otherChild.docname)
Expand Down Expand Up @@ -3022,6 +3022,13 @@ class CObject(ObjectDescription):
names=('rtype',)),
]

option_spec = {
# have a dummy option to ensure proper errors on options,
# otherwise the option is taken as a continuation of the
# argument
'dummy': None
}

def _add_enumerator_to_parent(self, ast: ASTDeclaration) -> None:
assert ast.objectType == 'enumerator'
# find the parent, if it exists && is an enum
Expand Down Expand Up @@ -3088,7 +3095,8 @@ def add_target_and_index(self, ast: ASTDeclaration, sig: str,
self.state.document.note_explicit_target(signode)

domain = cast(CDomain, self.env.get_domain('c'))
domain.note_object(name, self.objtype, newestId)
if name not in domain.objects:
domain.objects[name] = (domain.env.docname, newestId, self.objtype)

indexText = self.get_index_text(name)
self.indexnode['entries'].append(('single', indexText, newestId, '', None))
Expand Down Expand Up @@ -3153,7 +3161,10 @@ def handle_signature(self, sig: str, signode: TextElement) -> ASTDeclaration:
# Assume we are actually in the old symbol,
# instead of the newly created duplicate.
self.env.temp_data['c:last_symbol'] = e.symbol
logger.warning("Duplicate declaration, %s", sig, location=signode)
msg = __("Duplicate C declaration, also defined in '%s'.\n"
"Declaration is '%s'.")
msg = msg % (e.symbol.docname, sig)
logger.warning(msg, location=signode)

if ast.objectType == 'enumerator':
self._add_enumerator_to_parent(ast)
Expand Down Expand Up @@ -3523,14 +3534,6 @@ class CDomain(Domain):
def objects(self) -> Dict[str, Tuple[str, str, str]]:
return self.data.setdefault('objects', {}) # fullname -> docname, node_id, objtype

def note_object(self, name: str, objtype: str, node_id: str, location: Any = None) -> None:
if name in self.objects:
docname = self.objects[name][0]
logger.warning(__('Duplicate C object description of %s, '
'other instance in %s, use :noindex: for one of them'),
name, docname, location=location)
self.objects[name] = (self.env.docname, node_id, objtype)

def clear_doc(self, docname: str) -> None:
if Symbol.debug_show_tree:
print("clear_doc:", docname)
Expand Down Expand Up @@ -3576,13 +3579,9 @@ def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None:
ourObjects = self.data['objects']
for fullname, (fn, id_, objtype) in otherdata['objects'].items():
if fn in docnames:
if fullname in ourObjects:
msg = __("Duplicate declaration, also defined in '%s'.\n"
"Name of declaration is '%s'.")
msg = msg % (ourObjects[fullname], fullname)
logger.warning(msg, location=fn)
else:
if fullname not in ourObjects:
ourObjects[fullname] = (fn, id_, objtype)
# no need to warn on duplicates, the symbol merge already does that

def _resolve_xref_inner(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
typ: str, target: str, node: pending_xref,
Expand Down
21 changes: 10 additions & 11 deletions sphinx/domains/cpp.py
Expand Up @@ -4455,7 +4455,7 @@ def unconditionalAdd(self, otherChild):
ourChild._fill_empty(otherChild.declaration, otherChild.docname)
elif ourChild.docname != otherChild.docname:
name = str(ourChild.declaration)
msg = __("Duplicate declaration, also defined in '%s'.\n"
msg = __("Duplicate C++ declaration, also defined in '%s'.\n"
"Declaration is '%s'.")
msg = msg % (ourChild.docname, name)
logger.warning(msg, location=otherChild.docname)
Expand Down Expand Up @@ -6624,8 +6624,9 @@ class CPPObject(ObjectDescription):
names=('returns', 'return')),
]

option_spec = dict(ObjectDescription.option_spec)
option_spec['tparam-line-spec'] = directives.flag
option_spec = {
'tparam-line-spec': directives.flag,
}

def _add_enumerator_to_parent(self, ast: ASTDeclaration) -> None:
assert ast.objectType == 'enumerator'
Expand Down Expand Up @@ -6808,7 +6809,10 @@ def handle_signature(self, sig: str, signode: desc_signature) -> ASTDeclaration:
# Assume we are actually in the old symbol,
# instead of the newly created duplicate.
self.env.temp_data['cpp:last_symbol'] = e.symbol
logger.warning("Duplicate declaration, %s", sig, location=signode)
msg = __("Duplicate C++ declaration, also defined in '%s'.\n"
"Declaration is '%s'.")
msg = msg % (e.symbol.docname, sig)
logger.warning(msg, location=signode)

if ast.objectType == 'enumerator':
self._add_enumerator_to_parent(ast)
Expand Down Expand Up @@ -7083,7 +7087,6 @@ def run(self) -> List[Node]:
node['domain'] = self.domain
# 'desctype' is a backwards compatible attribute
node['objtype'] = node['desctype'] = self.objtype
node['noindex'] = True

self.names = [] # type: List[str]
signatures = self.get_signatures()
Expand Down Expand Up @@ -7275,13 +7278,9 @@ def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None:
ourNames = self.data['names']
for name, docname in otherdata['names'].items():
if docname in docnames:
if name in ourNames:
msg = __("Duplicate declaration, also defined in '%s'.\n"
"Name of declaration is '%s'.")
msg = msg % (ourNames[name], name)
logger.warning(msg, location=docname)
else:
if name not in ourNames:
ourNames[name] = docname
# no need to warn on duplicates, the symbol merge already does that
if Symbol.debug_show_tree:
print("\tresult:")
print(self.data['root_symbol'].dump(1))
Expand Down

0 comments on commit 8c82ecb

Please sign in to comment.