summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorZecong Hu <huzecong@gmail.com>2020-03-03 09:33:11 -0500
committerGitHub <noreply@github.com>2020-03-03 06:33:11 -0800
commit67f545dd27c00e73545ec34169bcb866d47020c5 (patch)
treeab23381bf2ec89b61491afec5696ffdd6945af3e /tests
parent74cc649ddb4eb86f73b68d6b04348f1690310a94 (diff)
downloadpycparser-67f545dd27c00e73545ec34169bcb866d47020c5.tar.gz
Fix #363 incorrect AST when parsing offsetof (#364)
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_c_parser.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py
index 49cada3..b6ecdd5 100755
--- a/tests/test_c_parser.py
+++ b/tests/test_c_parser.py
@@ -529,6 +529,18 @@ class TestCParser_fundamentals(TestCParser_base):
['IdentifierType', ['int']]]]]])
def test_offsetof(self):
+ def expand_ref(n):
+ if isinstance(n, StructRef):
+ return ['StructRef', expand_ref(n.name), expand_ref(n.field)]
+ elif isinstance(n, ArrayRef):
+ return ['ArrayRef', expand_ref(n.name), expand_ref(n.subscript)]
+ elif isinstance(n, ID):
+ return ['ID', n.name]
+ elif isinstance(n, Constant):
+ return ['Constant', n.type, n.value]
+ else:
+ raise TypeError("Unexpected type " + n.__class__.__name__)
+
e = """
void foo() {
int a = offsetof(struct S, p);
@@ -546,8 +558,20 @@ class TestCParser_fundamentals(TestCParser_base):
self.assertIsInstance(s1.args.exprs[1], ID)
s3 = compound.block_items[2].init
self.assertIsInstance(s3.args.exprs[1], StructRef)
+ self.assertEqual(expand_ref(s3.args.exprs[1]),
+ ['StructRef',
+ ['StructRef', ['ID', 'p'], ['ID', 'q']],
+ ['ID', 'r']])
s4 = compound.block_items[3].init
self.assertIsInstance(s4.args.exprs[1], ArrayRef)
+ self.assertEqual(expand_ref(s4.args.exprs[1]),
+ ['ArrayRef',
+ ['ArrayRef',
+ ['StructRef',
+ ['ArrayRef', ['ID', 'p'], ['Constant', 'int', '5']],
+ ['ID', 'q']],
+ ['Constant', 'int', '4']],
+ ['Constant', 'int', '5']])
def test_compound_statement(self):
e = """