Skip to content

Commit ece85e0

Browse files
committed
Preserve coords on atomic TypeDecl
fixes #475
1 parent 1cfaa26 commit ece85e0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pycparser/ast_transforms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ def _fix_atomic_specifiers_once(
168168

169169
assert isinstance(parent, c_ast.TypeDecl)
170170
assert grandparent is not None
171+
if node.type.coord is None:
172+
# Preserve the declarator coord for _Atomic(T) so TypeDecl doesn't lose
173+
# its location when we replace the wrapper Typename.
174+
node.type.coord = parent.coord
171175
cast(Any, grandparent).type = node.type
172176
if "_Atomic" not in node.type.quals:
173177
node.type.quals.append("_Atomic")

tests/test_c_parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ def test_coords(self):
249249
}"""
250250
self.assert_coord(self.parse(t6).ext[0].decl.type.args.params[1], 3, 17)
251251

252+
# Coord for _Atomic type decls
253+
t7 = """
254+
typedef _Atomic(char) atomic_char;
255+
"""
256+
self.assert_coord(self.parse(t7).ext[0], 2, 31)
257+
self.assert_coord(self.parse(t7).ext[0].type, 2, 31)
258+
252259
def test_forloop_coord(self):
253260
t = """\
254261
void foo() {

0 commit comments

Comments
 (0)