Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for parsing pre-v3 syntax in the C domain #10901

Merged
merged 3 commits into from Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES
Expand Up @@ -33,6 +33,9 @@ Incompatible changes
Patch by Adam Turner.
* #10471, #10565: Removed deprecated APIs scheduled for removal in Sphinx 6.0. See
:ref:`dev-deprecated-apis` for details. Patch by Adam Turner.
* XXXXXX: C Domain: Remove support for parsing pre-v3 style type directives and
roles. Also remove associated configuration variables ``c_allow_pre_v3`` and
``c_warn_on_allowed_pre_v3``.

Deprecated
----------
Expand Down
79 changes: 2 additions & 77 deletions sphinx/domains/c.py
Expand Up @@ -3048,23 +3048,6 @@ def parser() -> ASTExpression:
init = ASTInitializer(initVal)
return ASTEnumerator(name, init, attrs)

def parse_pre_v3_type_definition(self) -> ASTDeclaration:
self.skip_ws()
declaration: DeclarationType = None
if self.skip_word('struct'):
typ = 'struct'
declaration = self._parse_struct()
elif self.skip_word('union'):
typ = 'union'
declaration = self._parse_union()
elif self.skip_word('enum'):
typ = 'enum'
declaration = self._parse_enum()
else:
self.fail("Could not parse pre-v3 type directive."
" Must start with 'struct', 'union', or 'enum'.")
return ASTDeclaration(typ, typ, declaration, False)

def parse_declaration(self, objectType: str, directiveType: str) -> ASTDeclaration:
if objectType not in ('function', 'member',
'macro', 'struct', 'union', 'enum', 'enumerator', 'type'):
Expand Down Expand Up @@ -3229,9 +3212,6 @@ def get_index_text(self, name: str) -> str:
def parse_definition(self, parser: DefinitionParser) -> ASTDeclaration:
return parser.parse_declaration(self.object_type, self.objtype)

def parse_pre_v3_type_definition(self, parser: DefinitionParser) -> ASTDeclaration:
return parser.parse_pre_v3_type_definition()

def describe_signature(self, signode: TextElement, ast: ASTDeclaration,
options: Dict) -> None:
ast.describe_signature(signode, 'lastIsName', self.env, options)
Expand All @@ -3254,27 +3234,8 @@ def handle_signature(self, sig: str, signode: TextElement) -> ASTDeclaration:

parser = DefinitionParser(sig, location=signode, config=self.env.config)
try:
try:
ast = self.parse_definition(parser)
parser.assert_end()
except DefinitionError as eOrig:
if not self.env.config['c_allow_pre_v3']:
raise
if self.objtype != 'type':
raise
try:
ast = self.parse_pre_v3_type_definition(parser)
parser.assert_end()
except DefinitionError:
raise eOrig
self.object_type = ast.objectType # type: ignore
if self.env.config['c_warn_on_allowed_pre_v3']:
msg = "{}: Pre-v3 C type directive '.. c:type:: {}' converted to " \
"'.. c:{}:: {}'." \
"\nThe original parsing error was:\n{}"
msg = msg.format(RemovedInSphinx70Warning.__name__,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this was bumped to 70 per request in #10471 (comment), though no version was ever published with the delay in deprecation so we are still OK to remove in 6.0.

A

sig, ast.objectType, ast, eOrig)
logger.warning(msg, location=signode)
ast = self.parse_definition(parser)
parser.assert_end()
except DefinitionError as e:
logger.warning(e, location=signode)
# It is easier to assume some phony name than handling the error in
Expand Down Expand Up @@ -3675,39 +3636,6 @@ def process_link(self, env: BuildEnvironment, refnode: Element,
title = title[dot + 1:]
return title, target

def run(self) -> Tuple[List[Node], List[system_message]]:
if not self.env.config['c_allow_pre_v3']:
return super().run()

text = self.text.replace('\n', ' ')
parser = DefinitionParser(text, location=self.get_location(),
config=self.env.config)
try:
parser.parse_xref_object()
# it succeeded, so let it through
return super().run()
except DefinitionError as eOrig:
# try as if it was an c:expr
parser.pos = 0
try:
ast = parser.parse_expression()
except DefinitionError:
# that didn't go well, just default back
return super().run()
classes = ['xref', 'c', 'c-texpr']
parentSymbol = self.env.temp_data.get('cpp:parent_symbol', None)
if parentSymbol is None:
parentSymbol = self.env.domaindata['c']['root_symbol']
signode = nodes.inline(classes=classes)
ast.describe_signature(signode, 'markType', self.env, parentSymbol)

if self.env.config['c_warn_on_allowed_pre_v3']:
msg = "{}: Pre-v3 C type role ':c:type:`{}`' converted to ':c:expr:`{}`'."
msg += "\nThe original parsing error was:\n{}"
msg = msg.format(RemovedInSphinx70Warning.__name__, text, text, eOrig)
logger.warning(msg, location=self.get_location())
return [signode], []


class CExprRole(SphinxRole):
def __init__(self, asCode: bool) -> None:
Expand Down Expand Up @@ -3917,9 +3845,6 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value("c_extra_keywords", _macroKeywords, 'env')
app.add_post_transform(AliasTransform)

app.add_config_value("c_allow_pre_v3", False, 'env')
app.add_config_value("c_warn_on_allowed_pre_v3", True, 'env')

return {
'version': 'builtin',
'env_version': 2,
Expand Down