inducer / pycparserext

Extensions for Eli Bendersky's pycparser
http://pypi.python.org/pypi/pycparserext
Other
83 stars 28 forks source link

Using OpenCLCParser with cpp breaks show() #27

Open ChrisCummins opened 7 years ago

ChrisCummins commented 7 years ago

Hi,

given this simple test file:

$ cat kernel.cl
void A() {}

The output of parse_file() is different when using the OpenCLCparser vs the pycparser default:

>>> parse_file("kernel.cl", use_cpp=True).children()
(('ext[0]', <pycparser.c_ast.FuncDef at 0x7f986ea2e2c8>),)

>>> parse_file("kernel.cl", use_cpp=True, parser=OpenCLCParser()).children()
(('ext[0]', [<pycparserext.ext_c_parser.PreprocessorLine at 0x7f986ea31240>]),
 ('ext[1]', [<pycparserext.ext_c_parser.PreprocessorLine at 0x7f986ea314e0>]),
 ('ext[2]', [<pycparserext.ext_c_parser.PreprocessorLine at 0x7f986ea271d0>]),
 ('ext[3]', [<pycparserext.ext_c_parser.PreprocessorLine at 0x7f986eacc898>]),
 ('ext[4]', [<pycparserext.ext_c_parser.PreprocessorLine at 0x7f986ea31470>]),
 ('ext[5]', [<pycparserext.ext_c_parser.PreprocessorLine at 0x7f986ea31128>]),
 ('ext[6]', <pycparser.c_ast.FuncDef at 0x7f986ed6b908>))

This breaks the behaviour of the show() method:

>>> parse_file("kernel.cl", use_cpp=True, parser=OpenCLCParser()).show()
Traceback (most recent call last)
...
AttributeError: 'list' object has no attribute 'show'

What is the meaning of the PreprocessorLine objects? Is there a way I can disable their creation, or have I misunderstood the API?

$ pip freeze | grep pycp
pycparser==2.17
pycparserext==2016.2
ChrisCummins commented 7 years ago

By the way, this is the workaround I'm currently using. Stripping out the PreprocessorLines and constructing a new FileAST. It seems to work.