help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to correctly deallocate some token types ...


From: Ricardo Rafael
Subject: Re: How to correctly deallocate some token types ...
Date: Mon, 12 May 2003 15:02:20 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312

Hi,

Hans Aberg wrote:
At 00:27 +0100 2003/05/12, Ricardo Rafael wrote:
     given the following declarations:

%union
{
  BOOL        boolean_val;
  int         integer_val;
  char      * string_val;
  SomeClass * action;

  struct
  {
    SomeClass * items;
    int         length;
  } n_list;

  struct expression
  {
    SomeClass * a,
              * b,
              * c;
  } expression;
} // YYSTYPE
...
%destructor { delete $$; } arg_list
%destructor { delete $$; } expr

      excuse me by my previous example. It should read as the following:

%destructor { delete $$.items; } arg_list /* is a n_list */
%destructor {
               if ( $$.a ) delete $$.a;
               if ( $$.b ) delete $$.b;
               if ( $$.c ) delete $$.c;
            } expr                        /* is an expression */

> C++ is doing this recursion automatically. But with C++, one
> cannot use %union, as that is implemented using a C/C++ union,
> which does not admit data types with non-trivial constructors.

That is the case, isn't it!? I just use primitive data types in the union (BOOL is a typedef for int just used for compatibility issues of one legacy library I use). The non-trivial constructors from class SomeClass are dealt indirectly in my code when I call new SomeClass(); and the memory deallocation is done using delete (there is no recursive data structures pointed by SomeClass *).

   I was just trying to confirm the correctness of the code above.


Thanks,

Ricardo Rafael.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]