-
Notifications
You must be signed in to change notification settings - Fork 165
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
Improve generated CPP code to trace function calls #445
Comments
Hello @agharish17, void Skeleton::visitEAdd(EAdd *e_add)
{
/* Code For EAdd Goes Here */
if (e_add->exp_1) e_add->exp_1->accept(this);
if (e_add->exp_2) e_add->exp_2->accept(this);
} I think it would be ok to add an option to BNFC that inserts something like
at the beginning of each such visit method, if that would help to understand the control-flow. I am not sure about this suggestion:
Overall, my impression is somehow that your suggested changes would be good for the beginner, but could be annoying to a more senior user that has a good grip on the visitor pattern and then has to delete the extra print statements that only output the function name. Maybe instead of just printing the function name, also printing the arguments could be more useful in general. Have you already implemented this?
If yes, you can open a PR so I can form a more clear opinion. |
Hello @andreasabel |
So the skeleton files are created in the backends, e.g. for C++: https://github.com/BNFC/bnfc/blob/742b9fb0ae78594936473a71738e0a90b53ff381/source/src/BNFC/Backend/CPP/STL/CFtoCVisitSkelSTL.hs You will probably have to learn a bit about the BNFC code base to carry out the change. In general, please understand that I am not available for a supervision-intensive process here, as I think the proposed feature isn't in the core functionality of BNFC. |
Thank you for the hints. So, I feel that it will take sometime to understand and contribute. So, I would pick this task during summer when I will have enough time :) I hope that is fine (as its also not really a core functionality of BNFC). Maybe this ticket / task can be put as on-hold or something until I take it up again. |
I have worked on C++ programming for quite sometime and I understand the basics. I am very much new to compiler area and I found it very easy to get started with BNFC to generate a C++ Lexer, parser (additionally a Skeleton class for Visitor design pattern) and a makefile. However, I had some trouble to visualize the visitor pattern in the applied context as there was quite less documentation about it.
So, I prepared an UML diagram (not too accurate though, but fairly conveys the idea, the blue boxes are abstract classes). PFA.
Can I provide this as a small contribution to the BNFC after it goes through a review ?
Also, I made the skeleton pattern work by adding minor code to the generated Test.C, Skeleton.H and Skeleton.C files. With this, it becomes more easier to trace the order in which different methods get called and becomes easy to proceed further with type-checking etc..
Since I am unable to upload SRC files, below is the summary: I have also attached the generated output in my following comment refer here
Skeleton.H
: provide destructor and add a method to accept a parse-treeSkeleton.C
: just add print() statements to get a call trace!Test.C
: instantiate skeleton and invoke showSkeleton() method by providing a parse-tree.Note: Since all the 3 files are generated automatically by running
$bnfc -m --cpp <language-file>.cf
I was wondering if my above implementation can also be considered and included while generating the files ?
Is this acceptable ? If so, please mention the next steps (as I haven't contributed to any open-source projects till now).
The text was updated successfully, but these errors were encountered: