[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: About %destructor is c++ mode
From: |
Hans Åberg |
Subject: |
Re: About %destructor is c++ mode |
Date: |
Thu, 18 Aug 2016 10:59:55 +0200 |
> On 18 Aug 2016, at 01:20, Min Wang <address@hidden> wrote:
> so if I have something like that ( pointer) in as token type:
>
> %type <PROG*> PROG
>
> %type <ListExp*> ListExp
>
> My thinking about using PROG* instead of PROG is because I do not want to
> copy constructor a big PROG, is it correct?
>
> In this case of pointer, do I need to have a %destructor?
>
> %destructor { delete $$; } PROG
> %destructor { delete $$; } ListExp
Yes, if your pointers have explicit allocators in the actions, then if you want
to avoid memory leaks during error recovery, the corresponding deallocator
should be called as you indicate.
> (2) when %destructor is called?
>
> Assuming I need those %destructor, it seems that %destructor was called
> even for a every successful parse. I thought it should only called during
> During error recovery.
It is called only during error recovery. For a normal parse, without errors,
the corresponding deallocator should be in the actions. So you need to keep
track in the grammar of where an object becomes obsolete.
So if your program is not doing much of error recovery, some memory leaks
during that process might be acceptable.
- About %destructor is c++ mode, Min Wang, 2016/08/18
- Re: About %destructor is c++ mode,
Hans Åberg <=
- Re: About %destructor is c++ mode, Min Wang, 2016/08/18
- Re: About %destructor is c++ mode, Hans Åberg, 2016/08/18
- Re: About %destructor is c++ mode, Min Wang, 2016/08/18
- Re: About %destructor is c++ mode, Hans Åberg, 2016/08/18
- Re: About %destructor is c++ mode, Min Wang, 2016/08/18
- Re: About %destructor is c++ mode, Hans Åberg, 2016/08/18
- Re: About %destructor is c++ mode, Min Wang, 2016/08/18
- Re: About %destructor is c++ mode, Hans Åberg, 2016/08/18
- Re: About %destructor is c++ mode, Min Wang, 2016/08/18
- Re: About %destructor is c++ mode, Min Wang, 2016/08/18