Skip to content

Option to not use new in C++ #293

Open

Description

@s5bug

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.

Activity

  1. andreasabel commented on Apr 29, 2020

    @andreasabel
    Member

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

  2. s5bug commented on Apr 29, 2020

    @s5bug
    Author

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

  3. andreasabel commented on Oct 8, 2020

    @andreasabel
    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.

  4. added
    parser
    on Oct 8, 2020
  5. added
    help wanted
    on Oct 29, 2020
  6. bbyalcinkaya commented on Dec 16, 2020

    @bbyalcinkaya

    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?

  7. andreasabel commented on Dec 28, 2020

    @andreasabel
    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.

  8. hangingman commented on Aug 27, 2021

    @hangingman

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

  9. andreasabel commented on Aug 27, 2021

    @andreasabel
    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.

  10. hangingman commented on Oct 9, 2021

    @hangingman

    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);
    }
  11. added a commit that references this issue on Oct 11, 2021
  12. hangingman commented on Jan 29, 2022

    @hangingman

    @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.

  13. added 3 commits that reference this issue on Feb 10, 2022
  14. hangingman commented on May 6, 2022

    @hangingman

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

  15. hangingman commented on Jun 19, 2023

    @hangingman

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C++enhancementhelp wantedparser

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions