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

CodeWriter doesn't work for 'CFuncDefNode' #3513

Closed
sighingnow opened this issue Apr 14, 2020 · 7 comments · Fixed by #3514
Closed

CodeWriter doesn't work for 'CFuncDefNode' #3513

sighingnow opened this issue Apr 14, 2020 · 7 comments · Fixed by #3514

Comments

@sighingnow
Copy link
Contributor

>>> writer = CodeWriter()

>>> writer.write(TreeFragment("def fn(): \n    pass").root)
<Cython.CodeWriter.LinesResult at 0x121704a90>

>>> writer.write(TreeFragment("cdef fn(): \n    pass").root)
Compiler crash traceback from this point on:
  File "Cython/Compiler/Visitor.py", line 180, in Cython.Compiler.Visitor.TreeVisitor._visit
  File "/usr/local/lib/python3.7/site-packages/Cython/CodeWriter.py", line 243, in visit_FuncDefNode
    self.startline(u"def %s(" % node.name)
AttributeError: 'CFuncDefNode' object has no attribute 'name'
@scoder scoder added the defect label Apr 14, 2020
@scoder
Copy link
Contributor

scoder commented Apr 14, 2020

Interesting to see that people are actually using this. :)

PR welcome.

@sighingnow
Copy link
Contributor Author

Interesting to see that people are actually using this. :)

Is the CodeWriter the only way to dump Cython AST into syntastically-correct Cython code?

PR welcome.

PR #3514 will fix that.

@scoder
Copy link
Contributor

scoder commented Apr 14, 2020

Is the CodeWriter the only way to dump Cython AST into syntastically-correct Cython code?

The intended way, yes.

@sighingnow
Copy link
Contributor Author

sighingnow commented Apr 15, 2020

@scoder It is quite wired that CodeWriter cannot handle some kinkds of experssions, for example, the PrimaryCmpNode, however we have a visit_PrimaryCmpNode in ExpressionWriter.

The CodeWriter seems never been used at other place in Cython repo, but due to missing such visitors we cannot have a Writer that can print whole program. Should we make CodeWriter to inherits from ExpressionWriter as well?

Edit: to make it more clear, I mean, should we treat CodeWriter as the "union" of DeclarationWriter and ExpressionWriter then we get a full-functionality "Writer" ?

@sighingnow
Copy link
Contributor Author

@scoder Any comments? (polite ping 😆

@scoder
Copy link
Contributor

scoder commented Apr 18, 2020

@sighingnow good idea. I just pushed #3528.

@sighingnow
Copy link
Contributor Author

good idea. I just pushed #3528.

Thanks a lot! Visitor for some kinds of ast Node are still missing, I will continue to push to #3514 to make the CodeWriter more complete. Will ping you when it ready for review and merging.

@scoder scoder added this to the 3.0 milestone Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants