eliben / pycparser

:snake: Complete C99 parser in pure Python
Other
3.21k stars 611 forks source link

TypeDecl nodes of _Atomic C11 declarations have empty coord #475

Open ebmoll opened 1 year ago

ebmoll commented 1 year ago

Nodes of type TypeDecl created by _Atomic() don't seem to have a correct coord attribute:

file atomic.c:

typedef _Atomic(char) atomic_char;
from pycparser import parse_file
from pycparser.c_ast import NodeVisitor

class TypedefVisitor(NodeVisitor):
    def visit_TypeDecl(self, node):
        print(node.coord) # prints None
        print(node.type.coord) # prints the correct location

ast = parse_file('atomic.c')
TypedefVisitor().visit(ast)

I don't know if this behavior is correct, but it seems inconsistent to me. It's a bit annoying since I use it to filter out ast nodes from included files when generating wrapper code.

eliben commented 1 year ago

PRs welcome