aboutsummaryrefslogtreecommitdiff
path: root/pycparser/c_parser.py
diff options
context:
space:
mode:
authorKevin <kevin.corre@base-echo.net>2019-05-09 16:00:24 +0200
committerEli Bendersky <eliben@users.noreply.github.com>2019-05-09 07:00:24 -0700
commitf3a7cda31fc663a9ff6d1122e43999771f411df2 (patch)
treeac1af008142a91720b2fcfce7caeb3b83ec52700 /pycparser/c_parser.py
parent1c6fbab46ef9ef1397a66391d5e5af0487fcaebd (diff)
downloadpycparser-f3a7cda31fc663a9ff6d1122e43999771f411df2.tar.gz
Fix issue #324: u/l constant integer suffix (#326)
Diffstat (limited to 'pycparser/c_parser.py')
-rw-r--r--pycparser/c_parser.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py
index 4e1889d..a32d0cc 100644
--- a/pycparser/c_parser.py
+++ b/pycparser/c_parser.py
@@ -1766,8 +1766,28 @@ class CParser(PLYParser):
| INT_CONST_HEX
| INT_CONST_BIN
"""
+ uCount = 0
+ lCount = 0
+ for x in p[1][-3:]:
+ if x in ('l', 'L'):
+ lCount += 1
+ elif x in ('u', 'U'):
+ uCount += 1
+ t = ''
+ if uCount > 1:
+ raise ValueError('Constant cannot have more than one u/U suffix.')
+ elif lCount > 2:
+ raise ValueError('Constant cannot have more than two l/L suffix.')
+ else:
+ if uCount:
+ t += 'unsigned '
+ if lCount == 1:
+ t += 'long '
+ elif lCount == 2:
+ t += 'long long '
+ t += 'int'
p[0] = c_ast.Constant(
- 'int', p[1], self._token_coord(p, 1))
+ t, p[1], self._token_coord(p, 1))
def p_constant_2(self, p):
""" constant : FLOAT_CONST