Skip to content

Commit cf091f7

Browse files
committed
C, add short int, and treat spaced types properly
1 parent e2ae287 commit cf091f7

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

sphinx/domains/c.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
# Integer
9999
# -------
100100
|((signed|unsigned)\s+)?(char|(
101-
((long\s+long|long)\s+)?int
101+
((long\s+long|long|short)\s+)?int
102102
))
103103
|__uint128|__int128
104104
# extensions
@@ -114,7 +114,7 @@
114114
|(_Sat\s+)?((signed|unsigned)\s+)?((short|long|long\s+long)\s+)?(_Fract|fract|_Accum|accum)
115115
# Integer types that could be prefixes of the previous ones
116116
# ---------------------------------------------------------
117-
|((signed|unsigned)\s+)?(short|long\s+long|long)
117+
|((signed|unsigned)\s+)?(long\s+long|long|short)
118118
|signed|unsigned
119119
)\b
120120
""")
@@ -636,14 +636,20 @@ class ASTTrailingTypeSpec(ASTBase):
636636

637637
class ASTTrailingTypeSpecFundamental(ASTTrailingTypeSpec):
638638
def __init__(self, name: str) -> None:
639-
self.name = name
639+
self.names = name.split()
640640

641641
def _stringify(self, transform: StringifyTransform) -> str:
642-
return self.name
642+
return ' '.join(self.names)
643643

644644
def describe_signature(self, signode: TextElement, mode: str,
645645
env: "BuildEnvironment", symbol: "Symbol") -> None:
646-
signode += addnodes.desc_sig_keyword_type(self.name, self.name)
646+
first = True
647+
for n in self.names:
648+
if not first:
649+
signode += addnodes.desc_sig_space()
650+
else:
651+
first = False
652+
signode += addnodes.desc_sig_keyword_type(n, n)
647653

648654

649655
class ASTTrailingTypeSpecName(ASTTrailingTypeSpec):

tests/test_domain_c.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,16 @@ def test_domain_c_ast_fundamental_types():
279279
def types():
280280
def signed(t):
281281
yield t
282-
yield 'signed ' + t
283-
yield 'unsigned ' + t
282+
yield 'signed ' + t
283+
yield 'unsigned ' + t
284284

285285
# integer types
286286
# -------------
287287
yield 'void'
288288
yield from ('_Bool', 'bool')
289289
yield from signed('char')
290290
yield from signed('short')
291+
yield from signed('short int')
291292
yield from signed('int')
292293
yield from ('signed', 'unsigned')
293294
yield from signed('long')
@@ -304,8 +305,8 @@ def signed(t):
304305
yield from ('_Decimal32', '_Decimal64', '_Decimal128')
305306
for f in ('float', 'double', 'long double'):
306307
yield f
307-
yield from (f + " _Complex", f + " complex")
308-
yield from (f + " _Imaginary", f + " imaginary")
308+
yield from (f + " _Complex", f + " complex")
309+
yield from (f + " _Imaginary", f + " imaginary")
309310
# extensions
310311
# https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html#Floating-Types
311312
yield from ('__float80', '_Float64x',
@@ -317,14 +318,16 @@ def signed(t):
317318
# fixed-point types (extension)
318319
# -----------------------------
319320
# https://gcc.gnu.org/onlinedocs/gcc/Fixed-Point.html#Fixed-Point
320-
for sat in ('', '_Sat '):
321+
for sat in ('', '_Sat '):
321322
for t in ('_Fract', 'fract', '_Accum', 'accum'):
322-
for size in ('short ', '', 'long ', 'long long '):
323+
for size in ('short ', '', 'long ', 'long long '):
323324
for tt in signed(size + t):
324325
yield sat + tt
325326

326327
for t in types():
327-
check('type', "{key}%s foo" % t, {1: 'foo'}, key='typedef')
328+
input = "{key}%s foo" % t
329+
output = ' '.join(input.split())
330+
check('type', input, {1: 'foo'}, key='typedef', output=output)
328331

329332

330333
def test_domain_c_ast_type_definitions():

0 commit comments

Comments
 (0)