From cf091f7bb64b544b6bb69155677801851209e86a Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Sun, 15 Aug 2021 21:31:31 +0200 Subject: [PATCH] C, add short int, and treat spaced types properly --- sphinx/domains/c.py | 16 +++++++++++----- tests/test_domain_c.py | 17 ++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index 125bf067b..0869d6911 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -98,7 +98,7 @@ _simple_type_sepcifiers_re = re.compile(r"""(?x) # Integer # ------- |((signed|unsigned)\s+)?(char|( - ((long\s+long|long)\s+)?int + ((long\s+long|long|short)\s+)?int )) |__uint128|__int128 # extensions @@ -114,7 +114,7 @@ _simple_type_sepcifiers_re = re.compile(r"""(?x) |(_Sat\s+)?((signed|unsigned)\s+)?((short|long|long\s+long)\s+)?(_Fract|fract|_Accum|accum) # Integer types that could be prefixes of the previous ones # --------------------------------------------------------- - |((signed|unsigned)\s+)?(short|long\s+long|long) + |((signed|unsigned)\s+)?(long\s+long|long|short) |signed|unsigned )\b """) @@ -636,14 +636,20 @@ class ASTTrailingTypeSpec(ASTBase): class ASTTrailingTypeSpecFundamental(ASTTrailingTypeSpec): def __init__(self, name: str) -> None: - self.name = name + self.names = name.split() def _stringify(self, transform: StringifyTransform) -> str: - return self.name + return ' '.join(self.names) def describe_signature(self, signode: TextElement, mode: str, env: "BuildEnvironment", symbol: "Symbol") -> None: - signode += addnodes.desc_sig_keyword_type(self.name, self.name) + first = True + for n in self.names: + if not first: + signode += addnodes.desc_sig_space() + else: + first = False + signode += addnodes.desc_sig_keyword_type(n, n) class ASTTrailingTypeSpecName(ASTTrailingTypeSpec): diff --git a/tests/test_domain_c.py b/tests/test_domain_c.py index b910a2ec8..a9aa55687 100644 --- a/tests/test_domain_c.py +++ b/tests/test_domain_c.py @@ -279,8 +279,8 @@ def test_domain_c_ast_fundamental_types(): def types(): def signed(t): yield t - yield 'signed ' + t - yield 'unsigned ' + t + yield 'signed ' + t + yield 'unsigned ' + t # integer types # ------------- @@ -288,6 +288,7 @@ def test_domain_c_ast_fundamental_types(): yield from ('_Bool', 'bool') yield from signed('char') yield from signed('short') + yield from signed('short int') yield from signed('int') yield from ('signed', 'unsigned') yield from signed('long') @@ -304,8 +305,8 @@ def test_domain_c_ast_fundamental_types(): yield from ('_Decimal32', '_Decimal64', '_Decimal128') for f in ('float', 'double', 'long double'): yield f - yield from (f + " _Complex", f + " complex") - yield from (f + " _Imaginary", f + " imaginary") + yield from (f + " _Complex", f + " complex") + yield from (f + " _Imaginary", f + " imaginary") # extensions # https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html#Floating-Types yield from ('__float80', '_Float64x', @@ -317,14 +318,16 @@ def test_domain_c_ast_fundamental_types(): # fixed-point types (extension) # ----------------------------- # https://gcc.gnu.org/onlinedocs/gcc/Fixed-Point.html#Fixed-Point - for sat in ('', '_Sat '): + for sat in ('', '_Sat '): for t in ('_Fract', 'fract', '_Accum', 'accum'): - for size in ('short ', '', 'long ', 'long long '): + for size in ('short ', '', 'long ', 'long long '): for tt in signed(size + t): yield sat + tt for t in types(): - check('type', "{key}%s foo" % t, {1: 'foo'}, key='typedef') + input = "{key}%s foo" % t + output = ' '.join(input.split()) + check('type', input, {1: 'foo'}, key='typedef', output=output) def test_domain_c_ast_type_definitions():