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

Option to not use new in C++ #293

Open
s5bug opened this issue Apr 29, 2020 · 11 comments
Open

Option to not use new in C++ #293

s5bug opened this issue Apr 29, 2020 · 11 comments
Labels
C++ enhancement help wanted Please contribute if you can parser Issues concerning parser generating

Comments

@s5bug
Copy link

s5bug commented Apr 29, 2020

I would love it if there was an option on BNFC to parse into either a std::shared_ptr/std::unique_ptr or to stack allocate classes because it's been a chore to track down everything that's been parsed and properly delete it.

@andreasabel
Copy link
Member

I am not proficient enough in C++ to attempt an implementation, but PRs are welcome!

@s5bug
Copy link
Author

s5bug commented Apr 29, 2020

I don't know that much about the tools BNFC uses to generate C++ code, but I'll do my best.

@andreasabel
Copy link
Member

BNFC does not use a lot of tools; it simply prints concrete syntax, maybe with the help of the Text.Pretty pretty printing library.

@andreasabel andreasabel added C++ enhancement parser Issues concerning parser generating labels Oct 8, 2020
@andreasabel andreasabel added the help wanted Please contribute if you can label Oct 29, 2020
@bbyalcinkaya
Copy link

Makefiles for C++ backend have --ansi flag and C++98 does not support shared_ptr/unique_ptr. Is it safe to switch to C++11?

@andreasabel
Copy link
Member

Makefiles for C++ backend have --ansi flag and C++98 does not support shared_ptr/unique_ptr. Is it safe to switch to C++11?

Well, if there is an option

to parse into either a std::shared_ptr/std::unique_ptr

then this option would output a Makefile with the appropriate flags (like picking the necessary C++ version).

So, short answer: yes.

@hangingman
Copy link

I would like to do this issue if I have time...
Currently BNFC generates C++ codes like delete someInstance instead of std::unique_ptr

@andreasabel
Copy link
Member

I would like to do this issue if I have time...

Great!

A first step could be to write up an example how the product should look like (e.g. by modifying some BNFC-generated C++ output). I cannot help here much since I am not an active C++ programmer.

Once the design is complete, it should not be hard to get it into BNFC. I can help with the Haskell part, if needed.

@hangingman
Copy link

I created a PR.
If it's no problem, I would like to try to modify Absyn.C/H to use smart-pointer.
bnfc generating C++ code using inheritance, so this maybe a bit difficult. However, if it's successfully done, no need to use delete() function.

Clone pattern for std::shared_ptr in C++

following part will be changed.

Prog *Prog::clone() const
{
  return new Prog(*this);
}

@hangingman
Copy link

hangingman commented Jan 29, 2022

@andreasabel I created second pull-request at #410
I gave up using std::unique_ptr, then use std::shared_ptr. Because it's more applicable for bnfc usecase.
Please take a look it.

EDIT:
I would like to ask about what unit tests should be added in the bnfc code-base, because I'm afraid of breaking bnfc current behavior. We all don't like regression bug.

andreasabel added a commit that referenced this issue Feb 10, 2022
andreasabel added a commit that referenced this issue Feb 10, 2022
andreasabel added a commit that referenced this issue Feb 10, 2022
@hangingman
Copy link

@andreasabel Hi, I updated PR again.
It took much time, sorry.
#410

@hangingman
Copy link

hangingman commented Jun 19, 2023

@andreasabel
Hi, long time no see.
Is there a chance that my pull request (#410) will be merged?
If regression is a problem, I can divide the pull request into small ones or make a pull request to be test functions only.

If additional function is not necessary, or it can not be maintained. Anyway, I wish to close or merge that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ enhancement help wanted Please contribute if you can parser Issues concerning parser generating
Projects
None yet
Development

No branches or pull requests

4 participants