mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
C, add short int, and treat spaced types properly
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user