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

CGenerator doesn't consider the NOT operator when using reduce_parentheses=True #425

Open
Kyvski opened this issue Jul 26, 2021 · 2 comments

Comments

@Kyvski
Copy link

Kyvski commented Jul 26, 2021

When using the CGenerator class with reduce_parentheses=True, the output still includes unnecessary parentheses around instances of UnaryOp with the NOT operator.

For example:

		      Input: if (a && !b && (!c || d)) …
	     	     Output: if (a && (!b) && ((!c) || d)) …
            Expected Output: if (a && !b && (!c || d)) …

To get around this, I just included UnaryOp in the list of simple nodes for _is_simple_node. Though, I'm not sure if this would have unexpected consequences. Another possible solution would be to include it in the precedence_map, but I couldn't get an ideal output doing it that way.

@eliben
Copy link
Owner

eliben commented Aug 1, 2021

PRs to fix this are welcome

@FlorianDyck
Copy link

included UnaryOp in the list of simple nodes for _is_simple_node. Though, I'm not sure if this would have unexpected consequences. Another possible solution would be to include it in the precedence_map, but I couldn't get an ideal output doing it that way.

(&pointer)++ and &(pointer++) for example have different meanings. There would have to be a priority check like with binary operators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants