Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coord.line is always set to 0 for Asm nodes #40

Open
maximumspatium opened this issue Aug 2, 2018 · 1 comment
Open

Coord.line is always set to 0 for Asm nodes #40

maximumspatium opened this issue Aug 2, 2018 · 1 comment

Comments

@maximumspatium
Copy link
Contributor

As the title says, the line number in the Coord object is always set to 0 for Asm nodes. This happens because lineno in the following lines

p[0] = Asm(p[1], p[3], None, None, None, coord=self._coord(p.lineno(1)))

p[0] = Asm(p[1], p[3], p[5], None, None, coord=self._coord(p.lineno(1)))

p[0] = Asm(p[1], p[3], p[5], p[7], None, coord=self._coord(p.lineno(1)))

p[0] = Asm(p[1], p[3], p[5], p[7], p[9], coord=self._coord(p.lineno(1)))

tries to get the 'lineno' attribute from p.slice[1] that isn't there so getattr() will return the default value of 0 instead of the actual line number.

I figured out that p.slice[2] contains the appropriate 'lineno' attribute. Changing the last param of the Asm constructor calls from

coord=self._coord(p.lineno(1)))

to

coord=self._coord(p.lineno(2)))

makes the code to return correct file:line position for Asm nodes. Coord.column seems often to be set to None while pycparser fills it with meaningful values.

Would you kindly verify whether that simply fix is okay?

I cannot provide any test case right now because it would require a file with several lines. I confirm that the above mentioned fix works for several real-world C sources I fed in so far.

@inducer
Copy link
Owner

inducer commented Aug 2, 2018

I'm happy to take your word for it--could you submit a PR?

maximumspatium added a commit to maximumspatium/pycparserext that referenced this issue Aug 2, 2018
This fixes the issue inducer#40.
WRNING: coord.column is still not usable.
maximumspatium added a commit to maximumspatium/pycparserext that referenced this issue Aug 2, 2018
This fixes the issue inducer#40.
WARNING: coord.column is still not usable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants