Skip to content

Commit 630732e

Browse files
authored
Merge pull request #173 from Pennycook/bugfix/unsigned-constants
Fix bug in handling of unsigned constants
2 parents 4b320c1 + 75cc1ae commit 630732e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

codebasin/preprocessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ def term(self):
20022002
# Convert to decimal and then to integer with correct sign
20032003
# Preprocessor always uses 64-bit arithmetic!
20042004
int_value = int(value, base)
2005-
if suffix and "u" in suffix:
2005+
if suffix and "u" in suffix.lower():
20062006
return np.uint64(int_value)
20072007
else:
20082008
return np.int64(int_value)

tests/literals/test_literals.py

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import unittest
66
from pathlib import Path
77

8+
import numpy as np
9+
810
from codebasin import CodeBase, finder, preprocessor
911

1012

@@ -60,6 +62,11 @@ def test_strings(self):
6062
)
6163
self.assertEqual(tokens[0].token, expected.token)
6264

65+
def test_long_constants(self):
66+
tokens = preprocessor.Lexer("0xFFFFFFFFFFFFFFFFULL").tokenize()
67+
term = preprocessor.ExpressionEvaluator(tokens).term()
68+
self.assertEqual(term, np.uint64(int("0xFFFFFFFFFFFFFFFF", 16)))
69+
6370

6471
if __name__ == "__main__":
6572
unittest.main()

0 commit comments

Comments
 (0)